var objXmlHttpReq;
var intervalID;
var loadDots;

function searchPast(objForm, objField)
{
	loadDots = ".";
	intervalID = setInterval(loadingStatus, 150);
	objXmlHttpReq = createObjXmlHttpReq();
	if (objXmlHttpReq==null)
	{
		if (document.getElementById("searchButton").style.visibility == "hidden")
		{
			document.getElementById("searchButton").style.visibility = "visible";
			alert ("Your browser does not support certain fetures.\nPlease press OK and use the alternative voting system.");
		}
		return;
	} 
	var strURL = "xsearch_ajax.asp?d=" + document.forms[objForm].elements[objField].options[document.forms[objForm].elements[objField].selectedIndex].value;
	//alert(url);
	objXmlHttpReq.onreadystatechange = checkStatus;
	objXmlHttpReq.open("GET", strURL, true);
	objXmlHttpReq.send(null);
}

function loadingStatus() {
	document.getElementById("spanStatus").innerHTML = "Processing Request " + loadDots;
	loadDots >= "...."? loadDots="." :	loadDots+=".";
}

function checkStatus() 
{ 
	if (objXmlHttpReq.readyState==4 || objXmlHttpReq.readyState=="complete")
	{ 
		//alert("state changed");
		clearInterval(intervalID);
		strResponse = objXmlHttpReq.responseText;
		arrResponse = strResponse.split("~");
		
		//Get all the details that were returned
		//alert(strResponse);
		var strStars = arrResponse[0];
		var strVotes = arrResponse[1];
		
		//Process and display the information
		document.getElementById("dateSearchContent").innerHTML = strResponse;
		document.getElementById("spanStatus").innerHTML = "";
	} 
}

function createObjXmlHttpReq()
{ 
	var objTemp=null
	if (window.ActiveXObject)
	{objTemp=new ActiveXObject("Microsoft.XMLHTTP");}
	else if (window.XMLHttpRequest)
	{objTemp=new XMLHttpRequest();}
	return objTemp;
}

// BEGIN testing for AJAX capability
function fallBackTest() 
{
	objXmlHttpReq = createObjXmlHttpReq();
	if (objXmlHttpReq != null)
	{
		//Hide the dropdown box and the "SEARCH" button.
		document.getElementById("searchButton").style.visibility = "hidden";
	}
}

// ===== OnDOMReady Function Call =====
window.addEvent('domready', function(){
	fallBackTest();
});