function $(v) { return(document.getElementById(v)); }
function $S(v) { return($(v).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function isset(v) { return((typeof(v)=='undefined' || v.length==0)?false:true); }
function XYwin(v) { var z=agent('msie')?Array(document.body.clientHeight,document.body.clientWidth):Array(window.innerHeight,window.innerWidth);
return(isset(v)?z[v]:z);
}

function modallclose() {$S('modallbg').display='none'; $S('modallbox').display='none'; document.onclick=function(){};}
function modalltog() { document.onclick=function(){ $S('modallbg').display='none'; $S('modallbox').display='none'; document.onclick=function(){}; }; }
function modallbox(v,c,u,b) { setTimeout("modalltog()",100); $S('modallbg').height=XYwin(0)+'px'; $S('modallbg').display='block'; $('modallbox').innerHTML=v+'<img src="/images/close.gif" onclick="modallclose()" style="position: absolute; right: 4px; top: 1px;" alt="Close Window" /><div class="modallx"><iframe src="'+c+"\" style=\"height: "+u+"px; width: "+c+"px; border: 0px;\">Just turn iframes on already! (You have Javascript... why not iframes? :P)</iframe><\/div>"; $S('modallbox').left=Math.round((XYwin(1)-b)/2)+'px'; $S('modallbox').width=b+'px'; $S('modallbox').display='block'; }

function setCookie( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+'='+escape( value ) +
( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
( ( path ) ? ';path=' + path : '' ) +
( ( domain ) ? ';domain=' + domain : '' ) +
( ( secure ) ? ';secure' : '' );
}

function dkeycro() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = dkeycro();

function dKeyAjax(txt){
    if(http.readyState == 4){
    var txt = http.responseText;
	  if(txt == 'y')
	  {
		document.getElementById('deflocf').readOnly = false;
		$S('deflocf').backgroundColor='#88dfff';
		$S('deftimef').backgroundColor='#88dfff';
		$S('options-dn').display='none';
		document.getElementById('deftimef').readOnly = false;
	  }
	  else
	  {
		$S('options-dn').display='inline';
	  	document.getElementById('deflocf').readOnly = true;
		document.getElementById('deftimef').readOnly = true;
	  }
    }
}

function checkdKey() {
var dKey = document.getElementById('dKeyf').value;

if(dKey.length > 18)
{
    http.open('get', '/api/chkserial/?dKey='+escape(dKey));
    http.onreadystatechange = dKeyAjax;
    http.send(null);
}
else
{
$S('options-dn').display='inline';
document.getElementById('deflocf').readOnly = true;
$S('deflocf').backgroundColor='#ccc';
$S('deftimef').backgroundColor='#ccc';
document.getElementById('deftimef').readOnly = true;
}

}


// ----------------------------------------------
// Default search box text
// ----------------------------------------------

// event handler
function addEventToObject(obj,evt,func) {
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(){oldhandler();func();};
}

var sd8a7ysasd = 'Address';
// search box stuff
var Searchbox = {
	init : function()
		{
		var sBox = document.getElementById('ac_me');
		if (sBox)
			{
			if (sBox.value == '' || sBox.value == ' ') {sBox.value = sd8a7ysasd;}
			addEventToObject(sBox,'onclick',Searchbox.click);
			addEventToObject(sBox,'onblur',Searchbox.blur);
			}	
		},
	click : function()
		{
		var sBox = document.getElementById('ac_me');
		if (sBox.value == sd8a7ysasd)
			{
			sBox.value = '';
			}
	  	},
	blur : function()
		{
		var sBox = document.getElementById('ac_me');
		if (sBox.value == '' || sBox.value == ' ') {sBox.value = sd8a7ysasd;}
		}
	};

// add event onload
addEventToObject(window,'onload',Searchbox.init);

//setCookie( name, value, expires, path, domain, secure )

function saveoptions() {
	var dKey = document.getElementById('dKeyf').value;
	var defloc = document.getElementById('deflocf').value;
	var deftime = document.getElementById('deftimef').value;
	
	setCookie('dKey', dKey, 365, '/', '.dev.whatsthetide.com');
	setCookie('defloc', defloc, 365, '/', '.dev.whatsthetide.com');
	setCookie('deftime', deftime, 365,'/', '.dev.whatsthetide.com');
	return false;
}
