/*---------------------------------------------------------------
// File name:   filldrops.js
// Authorship:  hari n g
// Author email: hari.kiliroor@gmail.com
// Date created:Thursday,2006-09-07 14:06:32
//
// This script file is used to implement ajax and fill the search page's dropdowns (Location and Places)
//--------------------------------------------------------------*/
var xmlHttp;

function getPlaces(Loc)
{
	var dropLoc=document.forms["frm1"].elements[Loc];
	if(dropLoc.options[dropLoc.selectedIndex].value==0)
		return;
	else
	{
		xmlHttp=GetXmlHttpObject();
		var url="searchGet.asp";
		url=url+"?table=tb_Village";
		url=url+"&Id=Location_Id="+dropLoc.options[dropLoc.selectedIndex].value;
url=url+"&tname=Village_Name";
		xmlHttp.onreadystatechange=handleResponse2;
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
}

function getLocations(Dist)
{
	var dropDist=document.forms["frm1"].elements[Dist];
	if(dropDist.options[dropDist.selectedIndex].value==0)
		return;
	else
	{
	
		xmlHttp=GetXmlHttpObject();
		var url="searchGet.asp";
		url=url+"?table=tb_Location";
		url=url+"&Id=District_Id="+dropDist.options[dropDist.selectedIndex].value;
url=url+"&tname=location_name";
		var dropLoc;
		xmlHttp.onreadystatechange=handleResponse1
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
}

function fillList(str,drop)   //fills the destination drop down
{
	//str=str.substring(0,str.indexOf("<"));
	var ddList=document.forms["frm1"].elements[drop];
	ddList.options.length=0;
	var a=null;
	var b;
	
	a=str.split(",");
ddList.options[0]=new Option("Any","0");
	for(i=0;i<a.length-1;i++)
	{
		b=a[i].split("-");
		ddList.options[i+1]=new Option(b[1],b[0]);
	}
	if(a.length<=1)
	{
		ddList.options[0]=new Option("--No Items--","0");
	}
}


function handleResponse1() //This function handles the Response from the server Page for selecting Locations
{
	drop="selectLocation";
	if (xmlHttp.readyState==4)
	{
		var str;
		str=xmlHttp.responseText;
		fillList(str,drop);
	}
}

function handleResponse2() //This function handles the Response from the server Page for selecting Places
{
	drop="selectPlace";
	if (xmlHttp.readyState==4)
	{
		var str;
		str=xmlHttp.responseText;
		fillList(str,drop);
	}
}

function GetXmlHttpObject()  // This function returns the Xml HTTP Object which makes the request.
{
	try
	{
		xmlHttp=new ActiveXObject("msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			xmlHttp=null;
		}
	}
	if((!xmlHttp) && (typeof XMLHttpRequest != "undefined"))
	{
		xmlHttp=new XMLHttpRequest();
	}
	return xmlHttp;
}
