﻿
//Global XMLHTTP Request object
var XmlHttp;
var currentCntrl = 0

//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();
	}
}
function followmousenew(e){

	//gettrailobj().left=xcoord+"px"
	//gettrailobj().top=ycoord+"px"
	
		
	gettrailobj().left="470px"
	gettrailobj().top="980px"

}
function shownew(width,height)
{
    
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) 
	{
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		document.onmousemove=followmousenew;
		
		newHTML = '<div id="loader_container"><div id="loader"><div align="center">Loading Data...</div><div id="loader_bg"><div id="progress"> </div></div></div>';
		gettrailobjnostyle().innerHTML = newHTML;
		//alert(document.getElementById("preview_div").innerHTML);	
		
		gettrailobj().display="block";
		
	}
	
}
//Gets called when country combo box selection changes
function CountryListOnChange1() 
{   
	shownew(100,100);
	currentCntrl = 0
	var countryList = document.getElementById("ddlCountry_regi");
	//Getting the selected country from country combo box.
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
	// URL to get states for a given country
	
	var requestUrl = AjaxServerPageName + "?SelectedCountry=" + encodeURIComponent(selectedCountry) ;
	
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse1;
		//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 HandleResponse1()
{	
	// 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)
		{			
			ClearAndSetStateListItems1(XmlHttp.responseXML.documentElement);
			
		}
		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 ClearAndSetStateListItems1(countryNode)
{
	
	if(currentCntrl < 1)
	{
	    stateList = document.getElementById("ddlState_regi");
	    document.getElementById("ddlCity_regi").options.length= 0 ;
	}
	else
	{	
		stateList = document.getElementById("ddlCity_regi");
	}
		
	//Clears the state combo box contents.
	
	if(stateList.options.length)
	{	
		stateList.options.length = 0;
	}

	var stateNodes = countryNode.getElementsByTagName('item');
	// alert(countryNode.getElementsByValue('item'));
	
	var textValue; 
	var optionItem;
	var val;
	var option1 = new Option('-Select Area-' ,0 ,  false, false);
	    document.getElementById("ddlCity_regi").options[0] = option1;
	var option2 = new Option('-Select City-' ,0 ,  false, false);
	document.getElementById("ddlState_regi").options[0] = option2;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText1(stateNodes[count]);
   		var value1 = stateNodes[count].getAttribute('value');
   		optionItem = new Option(textValue ,value1 ,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
	remove_loading();
}

//Returns the node text value 
function GetInnerText1 (node)
{	
	 return (node.textContent || node.innerText || node.text) ;
	
}

//Gets called when country combo box selection changes
function StateListOnChange1() 
{	
    shownew(100,100);
    currentCntrl = 1
    var countryList = document.getElementById("ddlCountry_regi");
	var stateList = document.getElementById("ddlState_regi");
	//Getting the selected country from country combo box.
	var selectedCountry = countryList.options[countryList.selectedIndex].value;
	//var SelectedCountry=  stateList.options[stateList.selectedIndex].value;
	var selectedState=  stateList.options[stateList.selectedIndex].value;
	// URL to get states for a given country 
	var requestUrl = AjaxServerPageName + "?SelectedCountry=" + encodeURIComponent(selectedCountry) + "&selectedState=" + encodeURIComponent(selectedState);
	
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse1;
		
		//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);		
	}
	document.getElementById("HdState1").value =  document.getElementById("ddlState_regi").options[document.getElementById("ddlState_regi").selectedIndex].value;
}


function CityListOnChange1()
{
   document.getElementById("HdState1").value =  document.getElementById("ddlState_regi").options[document.getElementById("ddlState_regi").selectedIndex].value;
   document.getElementById("HModel").value =  document.getElementById("ddlCity_regi").options[document.getElementById("ddlCity_regi").selectedIndex].value;
}
