
function switchCounties()
{
	var j = eval("arCounty" + jQuery('#stateselect').val());
	var options = '';
	options = '<option value=""> -- Select a County -- </option>';
	for (var myKey in j) {
		options += '<option value="' + j[myKey] + '">' + j[myKey] + '</option>';
	}
	jQuery('#countyselect').html(options);
}

function submitForm()
{
	jQuery('#searchingdiv').css('display', 'block');
	var t=setTimeout("doIt()",3000);
}
function doIt() {

	document.location = "/property-search/?state=" + GetStateNameFromID() + "&county=" + jQuery('#countyselect').val();
}

function GetStateNameFromID()
{
	for (var myKey in arState) {
		if(myKey == jQuery('#stateselect').val()) {
			return arState[myKey][1]
		}
	}
}

function verifyForm()
{
	if(validForm())
	{
	jQuery.post("/send-email.php", {
		name: jQuery('#name').val(),
		email: jQuery('#email').val(),
		phone: jQuery('#phone').val(),
		county: jQuery('#county').val(),
		address: jQuery('#address').val(),
		state: jQuery('#state').val(),
		acres: jQuery('#acres').val(),
		location: jQuery('#location').val(),
		submittedfrom: jQuery('#submittedfrom').val(),
		comments: jQuery('#comments').val(),
	},
		function(data){

			if (jQuery('#responsemessage').length == 0) {
				jQuery('#contactform').before('<br /><p id="responsemessage" style="color:red;"></p>');
			}
			if(data.indexOf("success") > -1){
				jQuery('#responsemessage').html("Thank you for your submission! A representative of CustomRanchMaps.com can contact you shortly to discuss creating a map for your property.");
				jQuery('#responsemessage').slideDown();
				jQuery('#contactform').slideUp();
			} else {
				jQuery('#responsemessage').html(data);
				jQuery('#responsemessage').slideDown();
			}
		});
	} else {
		if (jQuery('#responsemessage').length == 0) {
			jQuery('#contactform').before('<br /><p id="responsemessage" style="color:red;"></p>');
		}
		jQuery('#responsemessage').html("Name, Email Address and Phone Number are required fields.");
		jQuery('#responsemessage').slideDown();
	}
	return false;
}

function validForm()
{

	if(jQuery('#name').val() != "" && jQuery('#email').val() != "" && jQuery('#phone').val() != "")
	{
		return true;
	} else {
		return false;
	}
}
