var httpObjClient;
	var allddlDistricts, allCities;
	function addddlDistrict()
	{
		if(allddlDistricts.indexOf(",")>0)
		{
			var currddlDistricts, allValues;
			removeAllOptions(document.getElementById("ddlDistrict"));
			addOption(document.getElementById("ddlDistrict"), 0, "Select One");
			currddlDistricts = allddlDistricts.split(",");
			for(i=0; i<currddlDistricts.length; i++)
			{
				allValues = "";
				allValues = currddlDistricts[i].split("-");
				addOption(document.getElementById("ddlDistrict"), allValues[0], allValues[1]);
			}
		}
		else
		{
		   
			    var allValues;
			    removeAllOptions(document.getElementById("ddlDistrict"));
			    addOption(document.getElementById("ddlDistrict"), 0, "Select One");
			 if(allddlDistricts != "")
		    {
			    allValues = allddlDistricts.split("-");
			    addOption(document.getElementById("ddlDistrict"), allValues[0], allValues[1]);
			}
		}
	}
	function addddlcity()
	{
		if(allCities.indexOf(",")>0)
		{
			var currCities, allValues;
			removeAllOptions(document.getElementById("ddlcity"));
			addOption(document.getElementById("ddlcity"), 0, "Select One");
			currCities = allCities.split(",");
			for(i=0; i<currCities.length; i++)
			{
				allValues = "";
				allValues = currCities[i].split("-");
				addOption(document.getElementById("ddlcity"), allValues[0], allValues[1]);
			}
		}
		else
		{
			var allValues;
			removeAllOptions(document.getElementById("ddlcity"));
			addOption(document.getElementById("ddlcity"), 0, "Select One");
			allValues = allCities.split("-");
			addOption(document.getElementById("ddlcity"), allValues[0], allValues[1]);
		}
	}
	if(window.XMLHttpRequest)
	{
		httpObjClient = new XMLHttpRequest;
	}
	else if(window.ActiveXObject)
	{
		httpObjClient = new ActiveXObject("Microsoft.XMLHTTP");
	}
	function _showDistrict(stateid)
	{
		//alert(stateid);
		var myRandom = parseInt(Math.random()*99999999);
		httpObjClient.open("GET", "./showdistrict.asp?stateid=" + stateid + "&rand=" + myRandom, true);
		httpObjClient.onreadystatechange = hldHttpShowDistrict;
		httpObjClient.send(null);
	}
	function hldHttpShowDistrict()
	{
		if(httpObjClient.readyState == 1)
		{
			removeAllOptions(document.getElementById("ddlDistrict"));
			removeAllOptions(document.getElementById("ddlcity"));
			addOption(document.getElementById("ddlcity"), 0, "Select One");
			addOption(document.getElementById("ddlDistrict"), 0, "Please wait");

		}
		if(httpObjClient.readyState == 4)
		{
			allddlDistricts = httpObjClient.responseText;
			//alert(allddlDistricts);
			addddlDistrict();
		}
	}

	function _showCity(ddlDistrictid)
	{
	    document.getElementById("txtDistrict").value=ddlDistrictid;
		var myRandom = parseInt(Math.random()*99999999);
		httpObjClient.open("GET", "./showcity.asp?districtid=" + ddlDistrictid + "&rand=" + myRandom, true);
		httpObjClient.onreadystatechange = hldHttpShowCity;
		httpObjClient.send(null);
	}
	function hldHttpShowCity()
	{
		if(httpObjClient.readyState == 1)
		{
			removeAllOptions(document.getElementById("ddlcity"));
			addOption(document.getElementById("ddlcity"), 0, "Please wait");

		}
		if(httpObjClient.readyState == 4)
		{
			allCities = httpObjClient.responseText;
			addddlcity();
		}
	}
	function _setCity(ddlcityid)
	{
	     document.getElementById("txtCity").value=ddlcityid;
	}
// AJAX functions ends here
function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}
function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}

function _setFirstAnswerTimeHP()
{
    var lastOpenTime = document.getElementById("hdOpenTime").value;
    if(lastOpenTime != "")
    {
        var dt = new Date();
        var openTime = document.getElementById("hdFrstAnsTime").value;
        if(openTime !="")
            document.getElementById("hdFrstAnsTime").value = openTime + "," + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
        else
            document.getElementById("hdFrstAnsTime").value = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
     }
     else
     {
        document.getElementById("ddl_SpeedHomeP").selectedIndex = 0;
        alert("It seems you have not checked the website before answering the questions.\n Please click on the button \"Click to open website\".\n Check the home page properly & completely only then answer the questions that follow.\n\n Please note that you will not be eligible for the prize if you do not do so.");
     }
}
function _setFirstAnswerTimeTP()
{
    var lastOpenTime = document.getElementById("hdOpenTime").value;
    if(lastOpenTime != "")
    {
        var dt = new Date();
        var openTime = document.getElementById("hdFrstAnsTime").value;
        if(openTime !="")
            document.getElementById("hdFrstAnsTime").value = openTime + "," + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
        else
            document.getElementById("hdFrstAnsTime").value = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
     }
     else
     {
        document.getElementById("ddl_LocateInfo").selectedIndex = 0;
        alert("It seems you have not checked the website before answering the questions.\n Please click on the button \"Click to open website\".\n Complete the task properly & completely only then answer the questions that follow.\n\n Please note that you will not be eligible for the prize if you do not do so.");
     }
}