
//Global XMLHTTP Request object
var XmlHttp;
var currentCntrl = 0
var firstgo = 0
//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{	firstgo = 0
	//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() 
{   
	show1(100,100);
	currentCntrl = 0
	
	//document.getElementById("LeftControls1_tdSate").style.display="None";
	//document.getElementById("LeftControls1_tdSateimages").style.display="Block";
	//document.getElementById("LeftControls1_tdSate").innerHTML="<img src='images/loading.gif' hspace=0 vspace=0 border=0>" ;
	
	var countryList = document.getElementById("LeftControls1_ddlCountry");
	////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 = 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);		
	}
	
	//document.getElementById("LeftControls1_tdSate").innerHTML= document.getElementById("LeftControls1_tdSate").innerHTML;
	
}



//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)
		{			
			ClearAndSetStateListItems(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 ClearAndSetStateListItems(countryNode)
{
	
	if(currentCntrl < 1)
	{
	    stateList = document.getElementById("LeftControls1_ddlState");
	    document.getElementById("LeftControls1_ddlCity").options.length= 0 ;
	}
	else
	{	
		stateList = document.getElementById("LeftControls1_ddlCity");
	}
		
	//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('All City' ,0 ,  false, false);
	    document.getElementById("LeftControls1_ddlCity").options[0] = option1;
	var option2 = new Option('All State' ,0 ,  false, false);
	document.getElementById("LeftControls1_ddlState").options[0] = option2;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
   		var value1 = stateNodes[count].getAttribute('value');
   		optionItem = new Option(textValue ,value1 ,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
	remove_loading();
	//document.getElementById("LeftControls1_tdSate").style.display="Block";
	//document.getElementById("LeftControls1_tdSateimages").style.display="None";
}

//Returns the node text value 
function GetInnerText (node)
{	
	 return (node.textContent || node.innerText || node.text) ;
}

function followmouse1(e){

	//gettrailobj().left=xcoord+"px"
	//gettrailobj().top=ycoord+"px"
	
		
	gettrailobj().left="80px"
	gettrailobj().top="530px"

}

function show1(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=followmouse1;
		
		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";
	}
}


function StateListOnChange() 

{
    show1(100,100);
	currentCntrl = 1
    var countryList = document.getElementById("LeftControls1_ddlCountry");
	var stateList = document.getElementById("LeftControls1_ddlState");
	//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 = 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);		
	}
	document.getElementById("LeftControls1_ddlState1").value =  document.getElementById("LeftControls1_ddlState").options[document.getElementById("LeftControls1_ddlState").selectedIndex].value;
	
}

function CityListOnChange()
{
   document.getElementById("LeftControls1_ddlState1").value =  document.getElementById("LeftControls1_ddlState").options[document.getElementById("LeftControls1_ddlState").selectedIndex].value;
   document.getElementById("LeftControls1_ddlCity1").value =  document.getElementById("LeftControls1_ddlCity").options[document.getElementById("LeftControls1_ddlCity").selectedIndex].value;
}


function sendmails() 
{   
    var requestUrl = "EmailSending.aspx" ;
	CreateXmlHttp();
	if(XmlHttp)
	{
		XmlHttp.open("GET", requestUrl,  true);
		XmlHttp.send(null);		
	}
}


