// JavaScript Document
/*************************************
Module Name		: Registration
Args			: None
Module Type		: Procedure
Created By		: AJ@indopia
Created On		: Sept 26, 2006
Modified By		: 
Modified On		: 
Remarks			:
Description		: This is used for pulling up response asynchronously on submission of registration page
**************************************/

function XMLHTTPObject()
{
	var xmlhttp; 

	if (window.ActiveXObject) 
	{
		// Instantiate the latest Microsoft ActiveX Objects
		if (_XML_ActiveX)
		{
			xmlhttp = new ActiveXObject(_XML_ActiveX);
		
		}
		else
		{ 
			// loops through the various versions of XMLHTTP to ensure we're using the latest
			var versions = ["MSXML2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0"];			

			for (var i = 0; i < versions.length ; i++) 
			{ 
				try
				{
					// Try and create the ActiveXObject for Internet Explorer, if it doesn't work, try again.
					xmlhttp = new ActiveXObject(versions[i]); 
						
					if (xmlhttp) 
					{ 
						var _XML_ActiveX = versions[i];
						break;
					}
				}
				catch (e)
				{
					// TRAP
				};
			}
			;
		}			
	}// Well if there is no ActiveXObject available it must be firefox, opera, or something else

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try 
		{ 
			xmlhttp = new XMLHttpRequest(); 
		} 
		catch (e) 
		{
			xmlhttp = false; 
		}
	}
	
	return xmlhttp;
}

function processRequest(contentId,httpRequest,refreshContentOnFunction,parameterForRefresh)
{ 
	
	if (httpRequest.readyState == 4) 
	{ 
		if(httpRequest.status == 200)
		{ 
			results = httpRequest.responseText; // http.responseXML; which will lead to an XML based response, if we were to have some XML output from a server file
			
			var para = document.getElementById(contentId); //or whatever ID you gave your element. 			
			para.innerHTML = results; 		
			if (refreshContentOnFunction != "null")
			{		
				refreshContent(refreshContentOnFunction,parameterForRefresh);	
							
			}
			
		}
		else 
		{ 
			var results = "Sorry, there was an error finding the server-side file. Please contact support."; 
			var para = document.getElementById(contentId); 
			para.innerHTML = results; 
		}
		
	}	

	
}


function pinStates(countryId)
{
	//alert(countryId);
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	var fields = new Array();
	
	
	
	// Javascript validation block (if any)
	{
		;	
	}
	// End
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
			
	
	if (countryId != "InValid")
	{
		httpRequest = XMLHTTPObject();			
		
		var varContentUrl =  "../resources/classes/ur/mypinprocess.php?processfunction=1&countryId="+countryId;		
		//alert(varContentUrl);
		var contentId = "StateBox";				
		
		var para = document.getElementById(contentId);
		para.innerHTML = "<b style='color:red;'>Loading States<img src='../resources/images/loading.gif'/></b>"; 
	
		httpRequest.open("GET", varContentUrl, true); 
		httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
		httpRequest.setRequestHeader('Cache-Control', 'no-cache');
		httpRequest.setRequestHeader('Cache-Control', 'no-store');
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
		httpRequest.send(null);	
	}	
	
}

function pinCity(stateId)
{
	//alert(stateId);
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	var firstChar = stateId.substr(0,1);
	

	

	
	var objCountry = document.getElementById("country");
	var countryValue = objCountry.value;	
		

	// Javascript validation block (if any)
	{
		;	
	}
	// End
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
	//stateValue = eval("document."+formName+"."+stateId+".value");		
	
	if (stateId != "InValid")
	{
		httpRequest = XMLHTTPObject();	
		
		var varContentUrl =  "../resources/classes/ur/mypinprocess.php?processfunction=2&countryId="+countryValue+"&stateId="+stateId;				
		//alert(varContentUrl);
		var contentId = "CityBox";				
		
		var para = document.getElementById(contentId);
		para.innerHTML = "<b style='color:red;'>Loading Cities<img src='../resources/images/loading.gif'/></b>"; 
	
		httpRequest.open("GET", varContentUrl, true); 
		httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
		httpRequest.setRequestHeader('Cache-Control', 'no-cache');
		httpRequest.setRequestHeader('Cache-Control', 'no-store');
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
		httpRequest.send(null);	
	}	
}

function pinPostalCode(cityId)
{
	var httpRequest=null;

	var refreshContent = "null";
	var result = true;
	var firstChar = cityId.substr(0,1);
	
	var objCountry = document.getElementById("country");
	var countryValue = objCountry.value;	
	
	var objState = document.getElementById("state");
	var stateValue = objState.value;	


	// Javascript validation block (if any)
	{
		;	
	}
	// End
	
	// If there is no javascript error then go thru the processing/request response cycle	
	
	//codeId = eval("document."+formName+"."+cityId+".value");		
	
	if(cityId !="InValid")
	{
		
		httpRequest = XMLHTTPObject();	
		
		var varContentUrl =  "../resources/classes/ur/mypinprocess.php?processfunction=3&countryId="+countryValue+"&stateId="+stateValue+"&cityId="+cityId;				
		var contentId = "PostalBox";				
		//alert(varContentUrl);
		var para = document.getElementById(contentId);
		para.innerHTML = "<b style='color:red;'>Loading Codes<img src='../resources/images/loading.gif'/></b>"; 
	
		httpRequest.open("GET", varContentUrl, true); 
		httpRequest.onreadystatechange = function () {processRequest(contentId,httpRequest,refreshContent,""); } ;
		httpRequest.setRequestHeader('Cache-Control', 'no-cache');
		httpRequest.setRequestHeader('Cache-Control', 'no-store');
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
		httpRequest.send(null);	
	}	
}

