jQuery(document).ready(function(){
	
	// Set the date information.
	var currentTime = new Date();
	var month = currentTime.getMonth(); 
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
		
	jQuery('#eventDate').datepicker(
		{ minDate: new Date(year, month , day), maxDate: new Date((year+2), month , day) }
	);
	
	jQuery.validator.addMethod(
	    "usDate",
	    function(value, element) {
	        // put your own logic here, this is just a (crappy) example
	        return value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/);
	    },
	    "Please enter a date in the format mm/dd/yyyy"
	);

	jQuery.validator.addMethod(
	    "usPhone",
	    function(value, element) {
			value= cleanString(element.value);
			element.value = value;
	        // put your own logic here, this is just a (crappy) example
	        return value.match(/^\d\d\d\d\d\d\d\d\d\d$/);
	    },
	    "Please enter 10 digit phone number without<br /> spaces, dashes or parentheses"
	);
	
	jQuery("#negContactForm").validate({
	        rules : {
	            invite_event_date : {
	                usDate : true
	            },
	            invite_contact_phone : {
	                usPhone : true
	            }
			},
			submitHandler: function(form){
				
				jQuery.ajax({
					url: "/commlink/wp-content/plugins/neg-contact/sendMessage.php",
					type: "POST",
					data: jQuery(form).serialize(),
					dataType: "json",
					success: function(data)
					{
						if(data.success)
						{
							jQuery('#negContactFormArea').empty().text(jQuery("#contactThankYou").text());
						}
						else
						{
							jQuery('#negPostError').html(data.message).show();
						}
					}
				});
				
			}
	    });
});

// Itemize characters to remove
function cleanString (str) {
	str = str.replace(/[\(\)\.\-\s,]/g, "");
	return str.replace(/[^\d]/g, "");
}
