/*	Please do not duplicate this document with out prior permission.
	This unique combination of styles, properties, font-families and poistioning are copyright of ohioseagrant.osu.edu */

/*	SL Web Request Form Example Values
	This includes values to be inserted into the form
		
	George Oommen (oommen.6@osu.edu)
	January 17 2009 */
	
$( function() {
	
	$('#firstname').example('First*');
	$('#middlename').example('Middle');
	$('#lastname').example('Last*');
	$('#email').example('Email*');
	$('#phone').example('Phone US');
	$('#fax').example('Fax US');
	$('#street').example('Steet*');
	$('#city').example('City*');
	$('#zipcode').example('Zip*');
	$('#state').example('State*');
	$('#schoolName').example('School Name');
	$('#schoolState').example('School State');
	$('#schoolCity').example('School City');
 
 } );
 
 $(document).ready( function() {
	
	$('form#sl-web-requests select').styledSelect();
} );

$(document).ready(function() {

	// Must Match PHP Validate Array
	var statesUS = new Array(
						"al", "ak", "as", "az", "ar", "ca", "co", "ct", "de", "dc", "fm", "fl", "ga", "gu", "hi", "id", "il", "in", "ia", 
						"ks", "ky", "la", "me", "mh", "md", "ma", "mi", "mn", "ms", "mo", "mt", "ne", "nv", "nh", "nj", "nm", "ny", "nc", 
						"nd", "mp", "oh", "ok", "or", "pw", "pa", "pr", "ri", "sc", "sd", "tn", "tx", "ut", "vt", "vi", "va", "wa", "wv", 
						"wi", "wy", "ab", "bc", "mb", "nb", "nl", "nt", "ns", "nu", "on", "pe", "qc", "sk", "yt", 
						"alabama", "alaska", "american samoa", "arizona", "arkansas", "california", "colorado", "connecticut", "delaware", "district of columbia", 
						"federated states of micronesia", "florida", "georgia", "guam", "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas", "kentucky", 
						"louisiana", "maine", "marshall islands", "maryland", "massachusetts", "michigan", "minnesota", "mississippi", "missouri", "montana", 
						"nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york", "north carolina", "north dakota", "northern mariana islands", 
						"ohio", "oklahoma", "oregon", "palau", "pennsylvania", "puerto rico", "rhode island", "south carolina", "south dakota", "tennessee", "texas", 
						"utah", "vermont", "virgin islands", "virginia", "washington", "west virginia", "wisconsin", "wyoming", "alberta", "british columbia", 
						"manitoba", "new brunswick", "labrador", "newfoundland", "northwest territories", "nova scotia", "nunavut", "ontario", 
						"prince edward island", "quebec", "saskatchewan", "yukon");
	
	jQuery.validator.addMethod("stateUS", function(state, element) {
		if (this.optional(element))
			return true
		else {
			if (jQuery.inArray(state.toLowerCase(), statesUS) == -1)
				return false
			else
				return true
		}
	}, "" );
	
	jQuery.validator.addMethod("zipcodeUS", function(zip, element) {
		// matches US ZIP code
		// allow either five digits or nine digits with an optional '-' between
		if (this.optional(element))
			return true
		else {
			zip = zip.replace(/^\s+/, "");
			zip = zip.replace(/\s+$/, "");
			if (zip.match(/^\d{5}([- ]?\d{4})?$/))
				return true;
		}
	}, "");
	
	jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
		phone_number = phone_number.replace(/\s+/g, ""); 
		return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?[2-9]\d{2}[- .]?\d{4}$/);
	}, "" );
	
	jQuery.each(jQuery.validator.messages, function(i) {
		jQuery.validator.messages[i] = "";
	} );

	$("#sl-web-requests").validate({
		rules: {
			field: {
				required: true,
				phoneUS: true,
				email: true,
				stateUS: true,
				zipcodeUS: true
			}
		}
	} );
} );