/*********************************************************************************/
/* Homepage Tabs / DHTML JavaScript.  (some might get reused on advanced page??) */
/*********************************************************************************/
function changemainpagetabsto(totab) {
	var today = new Date();
	var exp = new Date();
	exp.setTime(today.getTime() + 1000*60*24*60*365);
	document.cookie='totab='+totab+'; expires=' + exp.toGMTString();
	
	totab = totab.toLowerCase();
	var alltabs = new Array("glossary","encyclopedia","dictionary","reference","web");
	var alltabw = new Array(94,124,96,96,56);
	var allshor = new Array("","enc:","dict:","ref:","web:");
	var allsuma = new Array("Build a custom glossary about the following term","Get detailed encyclopedic information about","Lookup dictionary definitions and information for","Get comprehensive reference information on","Get web definitions and web results about");
	var newtabcon = "";
	for (i=0; i<alltabs.length; i++) {
		var whele = document.getElementById('mt'+i);
		var whelea = document.getElementById('mta'+i);
		whele.src="images/ds_"+alltabs[i]+".gif";
		whelea.style.cursor='pointer';
	}
	for (i=0; i<alltabs.length; i++) {
		var whele = document.getElementById('mt'+i);
		var whelea = document.getElementById('mta'+i);
		if (alltabs[i] == totab) {
			document.getElementById("getdetailedonwhat").innerHTML = allsuma[i];
			//alert(alltabs[i]);
			whele.src="images/ds_"+alltabs[i]+"_on.gif";
			whelea.style.cursor='default';
			var curinpcook = "";
			if (typeof readCookie("sq") == "string") {
				curinpcook = readCookie("sq");
			}
			document.getElementById("aform").searchquery.value = allshor[i] + curinpcook;
			if (fullyloaded) {
				ajglossary('inp_teal', 284, 557);
				checkIt(document.getElementById('aform').searchquery.value);
				//alert('c');
			}
			//alert('d');
		//} else {
			//whele.src="images/transparent.gif";
			//var ran_number=Math.floor(Math.random()*500);
			//alert("turning off: "+alltabs[i]);
		//	whele.src="images/ds_"+alltabs[i]+".gif";
		//	whelea.style.cursor='pointer';
		//	document.getElementById("getdetailedonwhat").innerHTML=allsuma[i];
		}
	}
	//onResizeFixAllElements();
	document.getElementById("aform").searchquery.focus();
}

if(document.images) {
	var alltabs = new Array("glossary","encyclopedia","dictionary","reference","web");
	imageObj = new Image();
	for (i=0; i<alltabs.length; i++) {
		imageObj.src = "images/ds_"+alltabs[i]+".gif";
		imageObj.src = "images/ds_"+alltabs[i]+"_on.gif";
	}
}

var curtab = readCookie('totab');
if (curtab == null) {
	changemainpagetabsto('glossary');
} else {
	changemainpagetabsto(curtab);
}

/*
if (typeof readCookie("sq") == "string") {
	document.getElementById('aform').searchquery.value = readCookie("sq");
	showGoButton();
	loadIt(document.getElementById('aform').searchquery.value, false);
} else {
}
*/



//// move this off the button to the on submit, to get it when someone presss return
function submitHomePageAjaxSearch() {
	//this will submit the homepage search box, and remove any xxx: in front of the search term
	
	 v = window.document.aform.q.value;
	
	
	ajaxList = Array('top', 'local', 'zip', 'zipcode', 'url', 'glos', 'rel', 'enc', 'encyclopedia', 'tm', 'trademark', 'dict', 'dic', 'dictionary', 'def', 'name', 'people', 'person', 'web', 'internet', 'spons', 'sponsored', 'phone', 'ques', 'question', 'answer', 'news', 'tv', 'guide', 'street', 'email', 'movie', 'actor', 'actress', 'artist', 'music', 'cd', 'album', 'song');
	
	//alert(ajaxList.length);
	for (i = 0; i < ajaxList.length; i++) {
		c = ajaxList[i].length;
		c++;
		if (Left(v, c) ==  ajaxList[i] + ':') {
			window.document.aform.q.value = Right(v, v.length - c)
			window.document.aform.submit();	
		}
	}
	
	
	window.document.aform.submit();
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

