// JavaScript Document


function submitForm() {

 if ((document.book.Country.value == "none") || (document.book.City.value == "")) {
    window.alert("You must enter Country & City!");
	return false;
 } 

 if ((document.book.title.value == "") || (document.book.Name.value == "")) {
    window.alert("You must enter Title & Full Name!");
	return false;
 } 

 if (document.book.Email.value == "") {
    window.alert("You must enter your email address to submit form!");
	return false;
 }
 		re = /^[a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])+@[a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])+\.[a-zA-Z\.]{2,4}/    
		if(!re.test(document.book.Email.value)) { 
			window.alert("Email must contain only letters, numbers, the 'at' sign or may contain dash, dot, underscores(first part)!");    
			return false;  
		} 
		 if (document.book.Email2.value != "") {
			//re = /^[a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])+@[a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])+\.[a-zA-Z\.]{2,4}/    
			if(!re.test(document.book.Email2.value)) { 
				window.alert("Second Email must contain only letters, numbers, the 'at' sign or may contain dash, dot, underscores(first part)!");    
				return false;  
			} 		
		 }
 if ((document.book.mPhone.value == "") && (document.book.Phone.value == "") && (document.book.radiobutton[0].checked == true)) {
    window.alert("You must enter your Phone No. address to submit form if you choose 'Call me'!");
	return false;
 }


 if (document.book.Photography.checked != true || document.book.Videography.checked != true) {
    window.alert("You must check at least one type, interested service: Photography/Videography!");
	return false;
 }
  
  
     	
   function checkDay(year,month,testDay)
   {
      var daysPerMonth = new Array( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
      var r1=false;
      // check if day in range for month
      if ( testDay > 0 && testDay <= daysPerMonth[ month ] ) 
         r1 = true;
	  
   
      // check for leap year
      if ( month == 2 && testDay == 29 && ( year % 400 == 0 || ( year % 4 == 0 && year % 100 != 0 ) ) )
         r1 = true;  // testDay;
   
   
      if (r1 != true) {
		  window.alert( "Invalid day: " + testDay + " is NOT Valid for month No.: " + month );
		  r1 = false; // invalid day eg 31 february
	  }
	  return r1; 
   } // end method checkDay
   if (checkDay(document.book.year.value,document.book.month.value,document.book.day.value)==false) { return false ; }
  
  
 var t = new Date();
 var startDateOff = new Date(document.book.year.value,document.book.month.value-1,document.book.day.value);   
 if (startDateOff.getTime() < t.getTime()) {   
    window.alert("You must enter Wedding Date bigger than today to submit form!");
	return false;
 } else 
    return true;
}  // end function   p261 gosselin book

