function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

var zipSearch = {
	init : function() {
		YAHOO.ext.EventManager.addListener(document.getElementById('zip_search'),'click',this.search,this,true);
		YAHOO.util.Event.on(document.getElementById('zip_code'),'keypress',this.keypress);
	},
	search : function() {
		document.body.style.cursor = "wait";
		var zip = document.getElementById('zip_code').value;
		var distance = document.getElementById('distance').value;
		var firstname = document.getElementById('firstname').value;
		var lastname = document.getElementById('lastname').value;
		var state = document.getElementById('state').value;
		var phone = document.getElementById('phone').value;
		var email = document.getElementById('email').value;
		var reemail = document.getElementById('reemail').value;
		var data = 'zip='+zip+'&distance='+distance+'&firstname='+firstname+'&lastname='+lastname+
			'&state='+state+'&phone='+phone+'&email='+email+'&service='+getCheckedValue(document.forms['searchform'].elements['service']);
		if (email == reemail) {
			YAHOO.util.Connect.asyncRequest('post','../searchzip/query.php',this.returnSearch,data); 
		} else {
			alert('The Email address fields do not match.');
		}
	},
	returnSearch : {
		success: function(o) {
			document.getElementById('zip_results').innerHTML = o.responseText;
			document.body.style.cursor = "auto";
		}
	},
	keypress: function(e) {
		if( 13 == YAHOO.util.Event.getCharCode(e) ) 
		{ 
			zipSearch.search();
		}
	}
};

YAHOO.ext.EventManager.onDocumentReady(zipSearch.init, zipSearch, true);
