// JavaScript Document

function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }

function checkuser(uname)
{	
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		nam=encodeURIComponent(document.getElementById("username").value);
		
		xmlHttp.open("GET","files/sqlcheckuser.php?uname=" + nam,true);
		xmlHttp.onreadystatechange=getdata;
		xmlHttp.send(null);
	}
}

function getdata()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200)
		{
			xmlresponse=xmlHttp.responseXML;
			xmlelement=xmlresponse.documentElement;
			msg=xmlelement.firstChild.data;
			document.getElementById("ytmsguser").innerHTML=msg;
			document.getElementById("submit").disabled = true;
			if (msg == '0')
				{
					document.getElementById("ytmsguser").innerHTML=" ";
					document.getElementById("submit").disabled = false;
				}
		}
		else
			alert("Error: " + xmlHttp.statusText);
	}
}


	function getState(countryId) {	
		document.getElementById('statediv').innerHTML= '<img src="images/ajax-loader.gif" width="128" height="15" />';
		var strURL="findState.php?country="+countryId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	function getCity(countryId,stateId) {
		document.getElementById('citydiv').innerHTML= '<img src="images/ajax-loader.gif" width="128" height="15" />';		
		var strURL="findCity.php?country="+countryId+"&state="+stateId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('citydiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
				
	}

