var ct='-1' ;
var tp ='0';
function def(st, c, t)
{
if(c!=null)
ct = c;
getStateList(document.getElementById('country'), st);

//alert('CT, c in def is '+ct+','+c);
//alert('TP in def is '+tp+' and t = '+t );
	if(t)
	{tp = t;
		getTypeList(document.getElementById('category'), tp);
	}
	
}


var ajax = new Array();

function getStateList(sel, st)
{
	document.getElementById('un').innerHTML = "...checking database..."; 
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('States').options.length = 0;// Empty States select box
	document.getElementById('Cities').options.length = 2;// Empty CITIES select box
//if(countryCode==1)
	//{
		if(countryCode.length>0){
		
			var index = ajax.length;
			ajax[index] = new sack();
			
			ajax[index].requestFile = '/ajaxphp/getStates.php?countryCode='+countryCode+'&st='+st;	// Specifying which file to get
			ajax[index].onCompletion = function(){ createStates(index) };	// Specify function that will be executed after file has been found
			ajax[index].runAJAX();		
			
		}
//	}
}

function createStates(index)
{
	var obj = document.getElementById('States');
	//document.getElementById('un').innerHTML = "...checking database..."; 
	document.getElementById('un').style.display='none';
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
	//alert('CT is '+ct);
	if(ct!='-1')
	{
		getCityList(document.getElementById('States'), ct) ;
	}
	
}


//**************************************************
/*****************************************************/
//**************************************************


function getCityList(sta, ct)
{
		//alert("Hi City "+ct);
	var stateCode = sta.options[sta.selectedIndex].value;
	
	document.getElementById('Cities').options.length = 0;	// Empty city select box
	if(stateCode==0)
		{	//alert("State is other");
			//document.getElementById('otherstatetd').style.display="block";

		}
	else
		{	//alert("State is other");
			//document.getElementById('otherstatetd').style.display="none";			
		}
	
		
	if(stateCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = '/ajaxphp/getCities.php?stateCode='+stateCode+'&ct='+ct;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createCities(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function createCities(index)
{
	var obj = document.getElementById('Cities');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}



//**************************************************
/*****************************************************/
//**************************************************

function getLocalityList(cti)
{
		//alert("Hi City"+ cti.options[cti.selectedIndex].value);
	var cityCode = cti.options[cti.selectedIndex].value;
	if(cityCode==0)
		{	//alert("State is other");
			//document.getElementById('othercitytd').style.display="block";

		}
	else
		{	//alert("State is other");
			//document.getElementById('othercitytd').style.display="none";			
		}
	document.getElementById('Localities[]').options.length = 0;	// Empty Locality select box
	
	if(cityCode.length>0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = '/ajaxphp/getLocalities.php?cityCode='+cityCode;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createLocalities(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function createLocalities(index)
{
	var obj = document.getElementById('Localities[]');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}










function getTypeList(se, tp)
{
	
	var categoryCode = se.options[se.selectedIndex].value;
	
	document.getElementById('Types').options.length = 0;// Empty States select box
	//document.getElementById('Cities').options.length = 2;// Empty CITIES select box
//if(countryCode==1)
	//{
		if(categoryCode.length>0){
			
		
			var index = ajax.length;
			ajax[index] = new sack();
			
			ajax[index].requestFile = '/ajaxphp/getCategories.php?cCode='+categoryCode+'&tp='+tp;	// Specifying which file to get
			ajax[index].onCompletion = function(){ createCategories(index) };	// Specify function that will be executed after file has been found
			ajax[index].runAJAX();		// Execute AJAX function
		}
//	}
}

function createCategories(index)
{
	
	var obj = document.getElementById('Types');

	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}













function getLocalityChange(loc)
{
		//alert("Hi Locality"+ loc.options[loc.selectedIndex].value);
	var localityCode = loc.options[loc.selectedIndex].value;
	if(localityCode==0)
		{	//alert("Location is other");
		//	document.getElementById('otherlocalitytd').style.display="block";

		}
	else
		{	//alert("Location is not other");
		//	document.getElementById('otherlocalitytd').style.display="none";			
		}
}




