/*
document.addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);
function hideURLbar(){
	window.scrollTo(0,1);
}
*/

$(document).ready(init);

function init(){

	window.scrollTo(0,1);

	jQuery.validator.addMethod("defaultInvalid", defaultHandler, "Please enter your full name.");
	jQuery.validator.addMethod("validateZip", validZipHandler, "Please enter a valid zip code.");


	$("#petitionForm input").focus(onFocusHandler);
	$("#petitionForm input").blur(onBlurHandler);
	$("#petition").validate();
	
	//$("#accordion").accordion({header:"> h4", autoHeight: false, collapsible: false});
}

function defaultHandler(value, element) {
	if(value == element.defaultValue){
		return false;
	} else if(value.indexOf(" ") == -1 || value.lastIndexOf(" ") == (value.length - 1)){
		return false;
	} else {
		return true;
	}
	
}

function validZipHandler(value) {
	return value.match(/^\d{5}$|^\d{5}-\d{4}$/);
}

function onFocusHandler(e) {
	$(this).val("");
}

function onBlurHandler(e) {
	if($(this).val() != "") return;

	switch($(this).attr("id")) {
		case "name":
			$(this).val("First and Last Name");
		break;

		case "email":
			$(this).val("Email Address");
		break;

		case "zip":
			$(this).val("Zip Code");
		break;
	}
}

