var semi_setting = .6;

/* ****not used for centered page****
if (window.XMLHttpRequest) {// lazy, cheap way of texting if IE (<7) (& therefore if div#menu's position is fixed or absolute)
	window.onscroll = function menuleft() {
		document.getElementById('menu').style.left = 18 - document.documentElement.scrollLeft + 'px';
	}
}*/

//////////  show/hide functions  ////////////

var sh = new Array();

function showhide(eid) {
	if(sh[eid]) hide(eid);
	else show(eid);
}
	
function hide(eid) {
	document.getElementById("h"+eid).style.display = 'none';
	if (document.getElementById("arrow"+eid)) document.getElementById("arrow"+eid).src= '/shared/arrow.gif';
	sh[eid] = 0;
	if (!document.height) iefooterfix();
}

function show(eid) {
	document.getElementById("h"+eid).style.display = 'block';
	if (document.getElementById("arrow"+eid)) document.getElementById("arrow"+eid).src= '/shared/arrowdown.gif';
	sh[eid] = 1;
	if (!document.height) iefooterfix();
}
	
function iefooterfix() {
	/*if (!document.height) {
		if (footer = document.getElementById('footer') || top.document.getElementById('footer')) {
			footer.style.display = 'none';
			footer.style.bottom = -1 + 'px';
			footer.style.display = 'block';
		}
	}
*/
}

function hideRange(start,end) {
	for(eid = start; eid <= end ; eid++) {
		document.getElementById("h"+eid).style.display = 'none';
		if (document.getElementById("arrow"+eid)) document.getElementById("arrow"+eid).src= '/shared/arrow.gif';
		sh[eid] = 0;
	}
	if (!document.height) iefooterfix();
}
	
function showRange(start,end) {
	for(eid = start; eid <= end ; eid++) {
		document.getElementById("h"+eid).style.display = 'block';
		if (document.getElementById("arrow"+eid)) document.getElementById("arrow"+eid).src= '/shared/arrowdown.gif';
		sh[eid] = 1;
	}
	if (!document.height) iefooterfix();
}

/////////////////////////////////////////////




function cse() {
	var sFormDiv = document.getElementById("searchForm");
	var leftScDiv = document.getElementById("searchControl");

	this.leftControl = new GSearchControl();
	this.searchForm = new GSearchForm(true, sFormDiv);

	// bind clear and submit functions
	this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
	this.searchForm.setOnClearCallback(this, cse.prototype.onClear);

	// set up for small result sets
	this.leftControl.setResultSetSize(GSearch.SMALL_RESULTSET);
	this.leftControl.setLinkTarget(GSearch.LINK_TARGET_SELF);

	var searcher;
	var options;

	searcher = new GwebSearch();
	options = new GsearcherOptions();
	searcher.setSiteRestriction("014101120621721815484:vxq8ewdyhqa");
	options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	this.leftControl.addSearcher(searcher, options);

	var drawOptions = new GdrawOptions();
	drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

	this.leftControl.draw(leftScDiv, drawOptions);


}

cse.prototype.onSubmit = function(form) {
	var q = form.input.value;
	if (q && q!= "") {
		this.leftControl.execute(q);
		document.getElementById('grey-outS').style.display = 'block';
		document.getElementById('searchResults').style.display='block';
		document.getElementById('menu').style.opacity=1;
		semi_setting = 1; //prevents above divs, which are part of #menu, from being .6 opaque if mouse is out of window
	}
	return false;
}

cse.prototype.onClear = function(form) {
	this.leftControl.clearAllResults();
	form.input.value = "";
	return false;
}

function OnLoad() {
	new cse();
}

GSearch.setOnLoadCallback(OnLoad);
  
 ////////////////////////////////////////////////////////////////////
 
 
function ajax(dest,docEl) { 
	try {
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP");
	} 
	catch (e) {}
	targetElement = document.getElementById(docEl);
	xmlhttp.onreadystatechange = function () {
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
			targetElement.innerHTML = xmlhttp.responseText;
			var scripts = targetElement.getElementsByTagName('script');
			for (var i=0; i < scripts.length; i++) {
				script = scripts[i].innerHTML;
				if (window.ActiveXObject) {
					//window.execScript(script); //IE
					(window.eval || eval)(script, null);
				} else {
					eval(script); //real browsers
				}
			}
		}
	}
	xmlhttp.open("GET", dest);
	xmlhttp.send(null);
	//iefooterfix();
}

function ajax1(dest,docEl) { 
	try {
		xmlhttp1 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP.2.0");
	} 
	catch (e) {}
	targetElement = document.getElementById(docEl);
	xmlhttp1.onreadystatechange = function () {
		if ((xmlhttp1.readyState == 4) && (xmlhttp1.status == 200)) {
			targetElement.innerHTML = xmlhttp1.responseText;
			var scripts = targetElement.getElementsByTagName('script');
			for (var i=0; i < scripts.length; i++) {
				script = scripts[i].innerHTML;
				if (window.ActiveXObject) {
					window.execScript(script); //IE
				} else {
					eval(script); //real browsers
				}
			}
		}
	}
	xmlhttp1.open("GET", dest);
	xmlhttp1.send(null);
	//iefooterfix();
}
 
	
function ajaxPost(dest,form,url0,docEl0) { //form can be passed an element id or an element
	if (!url0 || !url0 == null) url0 = '';
	if (!docEl0 || !docEl0 == null) docEl0 = '';
	if (typeof(form) == "string") {
		form = document.getElementById(form);	
	}
	inputs = form.getElementsByTagName('input');
	var params = "";
	for ( var i = 0; i < inputs.length; i++ ) {
		if ( i != 0 ) {
			params += '&';
		}
		if (inputs[i].type == 'checkbox') {
			if (inputs[i].checked) {
				params +=inputs[i].name + '=on';
			}
		} else if (inputs[i].type == 'radio') {
			if (inputs[i].checked) {
				params +=inputs[i].name + '=' + inputs[i].value;
			}
		} else {
			params += inputs[i].name + '=' + encodeURIComponent(inputs[i].value);
		}
	}
	inputs = form.getElementsByTagName('textarea');
	for ( var i = 0; i < inputs.length; i++ ) {
		params += '&' + inputs[i].name + '=' + encodeURIComponent(inputs[i].value);
	}
	inputs = form.getElementsByTagName('select');
	for ( var i = 0; i < inputs.length; i++ ) {
		params += '&' + inputs[i].name + '=' + encodeURIComponent(inputs[i].options[inputs[i].selectedIndex].value);
	}
	try {
		xmlhttp2 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (e) {}
	xmlhttp2.open("POST", dest, true);
	xmlhttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp2.setRequestHeader("Content-length", params.length);
	xmlhttp2.setRequestHeader("Connection", "close");
	xmlhttp2.send(params);
	xmlhttp2.onreadystatechange = function() {
		if(xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
			if ((url0 != "") && (docEl0 != "")) {
				ajax(url0,docEl0);
			}
		}
	}
}

function ajaxDirectPost(dest,params,url0,docEl0) { 
	try {
		xmlhttp2 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (e) {}
	xmlhttp2.open("POST", dest, true);
	xmlhttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp2.setRequestHeader("Content-length", params.length);
	xmlhttp2.setRequestHeader("Connection", "close");
	xmlhttp2.send(params);
	xmlhttp2.onreadystatechange = function() {
		if(xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
			if ( (url0 != "") && (docEl0 != "") ) {
				ajax(url0,docEl0);
			}
		}
	}
}


//////////////////////////////////////////////////

function rmClearX() {
	allTds = document.getElementsByTagName("td");
	for(var i=0; i < allTds.length; i++) {
		if (allTds[i].className.match("gsc-clear-button")) {
			allTds[i].parentNode.removeChild(allTds[i]);
		}
	}
}

