/******************** cODING TO CHECK USERNAME AVAILABLITY GIVEN BELOW ***********/
var url = "/ajaxphp/emailid.php?param="; 

function updateEmail() { 
//alert("I am checking");
   //display a quick message while the script is being processed 
 	document.getElementById('un').innerHTML = "...checking database..."; 
  	var name = document.getElementById("emailid").value; 
  	http.open("GET", url + escape(name), true); 
	http.onreadystatechange = handleHttpResponse; 
  	http.send(null); 
} 

function handleHttpResponse() { 
  if (http.readyState == 4) { 
    results = http.responseText; 
    var name = document.getElementById("emailid").value; 
    if(results == "") results = "Email <i>"+name+"</i> Is Available..."; 
    // the div in which the message appears 
    document.getElementById('un').innerHTML = results; 
  } 
} 

function getHTTPObject() { 
  // will store the reference to the XMLHttpRequest object
					var xmlHttp;
					// if running Internet Explorer
					if(window.ActiveXObject)
					{		try
							{	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");		}
							catch (e)
							{			xmlHttp = false;				}
					}
							// if running Mozilla or other browsers
					else
					{		try
							{	xmlHttp = new XMLHttpRequest();			}
							catch (e)
							{	xmlHttp = false;					}
					}
					// return the created object or display an error message
					if (!xmlHttp)
						alert("Error creating the XMLHttpRequest object.");
					else
						return xmlHttp;

} 
var http = getHTTPObject(); // We create the HTTP Object 



/********* cODING TO CHECK USERNAME aVAILABLITY ABOVE **********/
/**************************/

function def()
{
getStateList(document.getElementById('country'));
//getCityList(document.getElementById('States'));

}


var ajax = new Array();

function getStateList(sel)
{
	//alert("Hi"+sel);
	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;	// 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();		// Execute AJAX function
		}
//	}
}

function createStates(index)
{
	var obj = document.getElementById('States');

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


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


function getCityList(sta)
{
		//alert("Hi State"+ sta.options[sta.selectedIndex].value);
	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;	// 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 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";			
		}
}
