var oXmlHttp;
var tObjectName;
var sObjectName;

function GetHttpRequestObject()
{
    if(window.XMLHttpRequest)
    {   
       // code for all new browsers
        oXmlHttp=new XMLHttpRequest();
       // oXmlHttp.overrideMimeType('text/xml');
    }
    else if (window.ActiveXObject)
    {   
        // code for IE5 and IE6
	    try
	    {
		    oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    catch(e)
	    {
		    try
		    {
			    oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		    } 
		    catch(oc)
		    {
			    oXmlHttp = null;
		    }
	    }
    }

    if(oXmlHttp==null)
    {
      alert("Your browser does not support XMLHTTP.");
    }
    	
    return oXmlHttp;
}

function GetCitiesOfTheCountry(sourceObjectName,targetObjectName)
{    
    tObjectName=targetObjectName;
    sObjectName=sourceObjectName;
	GetHttpRequestObject();  
	if(!oXmlHttp)
		alert("oXmlHttp = null down");  

	try
	{
		oXmlHttp.open("GET","Form_AjaxGetCitiesOfTheCountry.aspx?Cid="+document.getElementById(sObjectName).value,true);
		oXmlHttp.onreadystatechange = GetCitiesProcess;
		oXmlHttp.send(null);
	}
	catch(Exc)
	{
		alert(Exc);
	}
}

function GetCitiesProcess()
{
    if (oXmlHttp.readyState == 4)
	{
		if (oXmlHttp.status == 200)
		{   
	        document.getElementById(tObjectName).selectedIndex=0;
		    var Cities=oXmlHttp.responseText;
		    if(Cities)
		    {
		        ClearSelectOptions();
		        var Content=Cities.split(";");
		        for(i=0;i<Content.length;i++)
		        {
		            var TexVal=Content[i].split(",");
		            
		            var OptNew = document.createElement("option");
                    OptNew.text = TexVal[0];
                    OptNew.value = TexVal[1];
                    var SelObj = document.getElementById(tObjectName);

                    try 
                    {
                        // standards compliant; doesn't work in IE
                        SelObj.add(OptNew, null); 
                    }
                    catch(ex) 
                    {
                        // IE only
                        SelObj.add(OptNew); 
                    }
		        }
		    }
		}
	}
}

function GetCountiesOfTheCity(sourceObjectName,targetObjectName)
{    
    tObjectName=targetObjectName;
    sObjectName=sourceObjectName;
	GetHttpRequestObject();  
	if(!oXmlHttp)
		alert("oXmlHttp = null down");  

	try
	{
		oXmlHttp.open("GET","Form_AjaxGetCountiesOfTheCity.aspx?Cid="+document.getElementById(sObjectName).value,true);
		oXmlHttp.onreadystatechange = GetCountiesProcess;
		oXmlHttp.send(null);
	}
	catch(Exc)
	{
		alert(Exc);
	}
}

function GetCountiesProcess()
{
    if (oXmlHttp.readyState == 4)
	{
		if (oXmlHttp.status == 200)
		{   
		    var Counties=oXmlHttp.responseText;
		    if(Counties)
		    {
		        ClearSelectOptions();
		        var Content=Counties.split(";");
		        for(i=0;i<Content.length;i++)
		        {
		            var TexVal=Content[i].split(",");
		            
		            var OptNew = document.createElement("option");
                    OptNew.text = TexVal[0];
                    OptNew.value = TexVal[1];
                    var SelObj = document.getElementById(tObjectName);

                    try 
                    {
                        // standards compliant; doesn't work in IE
                        SelObj.add(OptNew, null); 
                    }
                    catch(ex) 
                    {
                        // IE only
                        SelObj.add(OptNew); 
                    }
		        }
		    }
		}
	}
}

function SendPassword(CardNo)
{    
	GetHttpRequestObject();  
	if(!oXmlHttp)
		alert("oXmlHttp = null down");  

	try
	{
		oXmlHttp.open("GET","Form_AjaxSendPassword.aspx?CardNo="+CardNo,true);
		oXmlHttp.onreadystatechange = SendPasswordProcess;
		oXmlHttp.send(null);
	}
	catch(Exc)
	{
		alert(Exc);
	}
}

function SendPasswordProcess()
{
    if (oXmlHttp.readyState == 4)
	{
		if (oXmlHttp.status == 200)
		    alert(oXmlHttp.responseText);
	}
}

function ClearSelectOptions()
{
    for (var loop=0; loop < document.getElementById(tObjectName).options.length; loop++)
        document.getElementById(tObjectName).options[loop] = null;

    document.getElementById(tObjectName).options.length=0;
}

