// declare a global  XMLHTTP Request object
var XmlHttpObj;

// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla
function CreateXmlHttpObj()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox) 
	if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpObj = new XMLHttpRequest();
	}
}


// called from onChange or onClick event of the continent dropdown list
function getPhoneNumber(val,oid) 
{

   document.getElementById("loading").innerHTML='Please wait call is in progress... <img src="images/loading.gif">';
   var requestUrl;
	 requestUrl = "Confirmation-HTTP.php" + "?PhoneNumber="+val+"&orderID="+oid;
	 
	 CreateXmlHttpObj();
	if(XmlHttpObj)
	{
		XmlHttpObj.onreadystatechange = StateChangeHandler;
  		XmlHttpObj.open("GET",requestUrl,true);
		XmlHttpObj.send(null);		
	}

}

function StateChangeHandler()
{
     var success=new Array();
     var expression1='window.location="thankyou.html"';
     var expression2='window.location="error.html"';  
     var timeout=3000;  
	if(XmlHttpObj.readyState == 4)
	{ 
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{ 
		      success=XmlHttpObj.responseText.split(',');	
                      document.getElementById("msg").innerHTML=success[0];
		      document.getElementById("loading").style.display='none';
                      if(success[1]==1){
                      setTimeout( expression1, timeout );
		      }else{
     			   setTimeout( expression2, timeout );
			   }


		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
			
		}
	}
}
