
// Custom For Form
/*
wFORMS.behaviors['validation'].isDate = function(s) {
  var cYEAR = 2, cMONTH = 0, cDAY = 1;
            var aDate;
            aDate = s.split("\-"); 
           var testDate = new Date(aDate[cYEAR], aDate[cMONTH] - 1, aDate[cDAY]);
            if ((aDate[cYEAR] != testDate.getFullYear() ) || (aDate[cMONTH] != 1 + testDate.getMonth()) 
			||(aDate[cDAY] != testDate.getDate()))
               var testDate = new Date('onzin');
            else if (testDate.getMonth() == 4 && testDate.getFullYear() == 2007)
				alert ('Sorry, but we are completely booked for the month of March');
			   
            return wFORMS.behaviors['validation'].isEmpty(s) || !isNaN(testDate); 
}*/
// overwrite the default form submission handler with a custom one.
 wFORMS.functionName_formValidation = "doPostBack";
  function doPostBack(e) { 
    if(!e) e = window.event;    
    
    //  call the default error management.  
    if(wFORMS.behaviors['validation'].run(e)) {            
      //  doing our custom validation here:
	 // if needed, the form element can be obtained with:
      // var f = wFORMS.helpers.getSourceElement(e);

      var DateField = document.getElementById('EventDate');
      var cYEAR = 2, cMONTH = 0, cDAY = 1;
      var aDate;
      aDate = DateField.value.split("\/"); 
      var testDate = new Date(aDate[cYEAR], aDate[cMONTH], aDate[cDAY]);
	/*  alert (testDate.getMonth());
	  alert(testDate.getFullYear());*/
	  if (testDate.getFullYear() < 2000) {
	  	   var errorMessage = "Year must be in YYYY format i.e. 2007";
		   wFORMS.behaviors['validation'].showAlert(1);
		   wFORMS.behaviors['validation'].showError(DateField, errorMessage);
        	// we need to prevent the submission:
        	return wFORMS.helpers.preventEvent(e); 
		}
      if (testDate.getMonth() == 5 && testDate.getFullYear() == 2007) {
	  		var errorMessage = "Sorry, we are completely booked for May 2007";
			wFORMS.behaviors['validation'].errMsg_notification = errorMessage;
			wFORMS.behaviors['validation'].showAlert(1);
			wFORMS.behaviors['validation'].showError(DateField, errorMessage);
        	// we need to prevent the submission:
        	return wFORMS.helpers.preventEvent(e);     
      			}
	  else if (testDate.getMonth() == 6 && testDate.getFullYear() == 2007) {
	  		var errorMessage = "Sorry, we are completely booked for June, 2007";
			wFORMS.behaviors['validation'].errMsg_notification = errorMessage;
			wFORMS.behaviors['validation'].showAlert(1);
			wFORMS.behaviors['validation'].showError(DateField, errorMessage);
        	// we need to prevent the submission:
        	return wFORMS.helpers.preventEvent(e);     
      			}
      else
      return true;                        
     }
}