/* 
Web-Innova AJAX Lookup scripts
Copyright 2006 - Web-Innova, LLC
lookups.js
6/2006
*/

//  Function to check if username is already been taken
function lookupZip() {
	var zip;
	var msg;
	
	//  Get the username value from the register form
	zip = document.getElementById("zip");

	//  Generate unique URL to solve IE caching issue
	url = "/util/zips.php?zip=" + zip.value + "&key=" + Math.random() * Date.parse(new Date());

	//  Create AJAX object
	createXMLHttpRequest();
	
	//  Process AJAX request
	xmlHttp.onreadystatechange = handleZipLookup;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	
	return true;
	

}

//  Function to handle the AJAX return message
function handleZipLookup() {
	var results;
	var city;
	var state;
	
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			//  Get results from zip query
			results = xmlHttp.responseText.split('|');
			city = results[0];
			state = results[1];
			
			//  Set fields with values
			document.getElementById("city").value = city;
			//document.getElementById("state").value = state;
			document.forms.register.elements.state.value = state;
		}
	}
}

//  Function to check if username is already been taken
function lookupMailingZip() {
	var zip;
	var msg;
	
	//  Get the username value from the register form
	zip = document.getElementById("mailing_zip");

	//  Generate unique URL to solve IE caching issue
	url = "/util/zips.php?zip=" + zip.value + "&key=" + Math.random() * Date.parse(new Date());

	//  Create AJAX object
	createXMLHttpRequest();
	
	//  Process AJAX request
	xmlHttp.onreadystatechange = handleMailingZipLookup;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	
	return true;
	

}

//  Function to handle the AJAX return message
function handleMailingZipLookup() {
	var results;
	var city;
	var state;
	
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			//  Get results from zip query
			results = xmlHttp.responseText.split('|');
			city = results[0];
			state = results[1];
			
			//  Set fields with values
			document.getElementById("mailing_city").value = city;
			//document.getElementById("state").value = state;
			document.forms.register.elements.mailing_state.value = state;
		}
	}
}



