// JavaScript Document

var formSel = "#introform"
function submitForm()
{
	$(formSel).ajaxSubmit(
										  {
											  target : '#response',
											  clearForm : false
										  }
										);
}


var myDays=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
var allowedDays = "36";
// 3 means allow Wednesday and 6 means allow Saturday

		
function showIntroDays(date) {
	var thisDay=date.getDay()+"";
	if ( allowedDays.indexOf( thisDay ) == -1 )
	   return [ false, "invalidday" ];
   return [ true, '' ];
}


function scheduleDateSelected( dp )
{
	var d = $("#schedule").datepicker( "getDate" );	
	alert('date selected ' + d );
}

function contactusInit()
{
	 var d = new Date();
	 $("#date").val( "{0}/{1}/{2}".format( d.getMonth(), d.getDate(), d.getFullYear() ) );
	 //$("#contactform").ajaxForm();
	 $(formSel).validate( 
										  {											  
											  rules: {
													  name: "required",
													  phone : { required : false, phoneUS : true },														       
													  returnemail: {
														 required: true,
														 email: true
													  },
													  startday : "required",
													  startdate : "required"
													},
											  messages: {
												  name: "Please enter your name",
												  phone: {  phoneUS: "Please format your phone number with (xxx) yyy-zzzz" },
												  returnemail : {
													 required: "We need your email address to respond",
													 email: "Your email address must be in the format of name@domain.com"
												  }
												},
											   errorClass: "invalid",
												submitHandler: function(form) {
													submitForm();
													return false;
												}
										  }
										);

	 //$("#when").datepicker({ minDate: new Date(), beforeShowDay: showIntroDays }).
	 var dateOptions = { minDate: new Date(), 
                        beforeShowDay: showIntroDays,
								maxDate: '+1m',
								onSelect : function() { scheduleDateSelected( $(this) ) } }
	 $("#schedule").datepicker( dateOptions );	 
	 reinitScrollPane();
}

$contentReady.add( contactusInit );
