$(document).ready(function() {
						   
	jQuery.validator.addMethod("phone", function(value, element) {
    return value==''||/^\d{3}\-\d{3}\-\d{4}/.test(value);
    }, "Doesn't match with the correct format (xxx-xxx-xxxx)");
	
	// validate signup form on keyup and submit
	var validator = $("#frm_edit").validate({
		rules: {
			first_name: "required",
			last_name: "required",
			"00N800000031hjv": "required phone", /*Day phone*/
			"00N800000031hjw": "phone", /*Eve phone*/
			"00N800000031h3E": "required", /*best time*/
			state: "required",
			email: {
				required: true,
				email: true
			},
			"00N800000031h53": "required" /*Legal problem 1*/
		},
		messages: {
			first_name: "Please enter your first name.",
			last_name: "Please enter your last name.",
			"00N800000031h3E": "Please select the best time for us to contact you.", 
			state: "Please select which State or Province you are currently living in.",
			email: {
				required: "Please enter a valid email address"
			},
			"00N800000031h53": "Please select a first legal problem."
		},
		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			error.appendTo( element.parent().next() );
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("").addClass("checked");
		}
	});
	$("#state").change(function() {
		if($("#state").val()=="NC"){				
			alert("Sorry - About The Children services are not available to residents of North Carolina.");
			//$("#state").selectedIndex = -1;
			document.forms['frm_edit'].elements['state'].selectedIndex = 0;
		}
		else if($("#state").val()=="KY"){				
			alert("Sorry - About The Children services are not available to residents of Kentucky.");
			//$("#state").selectedIndex = -1;
			document.forms['frm_edit'].elements['state'].selectedIndex = 0;
		}
		else if($("#state").val()=="OH"){				
			alert("Sorry - About The Children services are not available to residents of Ohio.");
			//$("#state").selectedIndex = -1;
			document.forms['frm_edit'].elements['state'].selectedIndex = 0;
		}
	});
});

