var ct='-1' ;
var tp ='0';



function def(st, c)
{
	//alert("Hi I am quick Alert country is ");
	//alert(document.getElementById('country').options[document.getElementById('country').selectedIndex].value);
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 );
	
	
}


var ajax = new Array();

function getStateList(sel, st)
{
	
	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');

	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;
	if(stateCode=='')
	{
	document.getElementById('Cities').options.length = 1;	
	}
	else
	{
		document.getElementById('Cities').options.length = 0;// Empty city select box
		document.getElementById('Cities').options[document.getElementById('Cities').options.length] = new Option('Loading... ','');
	}
	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)
{
	document.getElementById('Cities').options.length = 0;// Empty city select box
	var obj = document.getElementById('Cities');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}



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

