// 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.HomePhone.value == "") && (document.book.MobilePhone.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.Adults.value == "") && (document.book.Children.value == "")) {
    window.alert("You must enter number of Adults & Children(enter '0' if no children)!");
	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 ; }
   if (checkDay(document.book.toyear.value,document.book.tomonth.value,document.book.today.value)==false) { return false ; }
  
  
 var t = new Date();
 var startDate = new Date(document.book.year.value,document.book.month.value-1,document.book.day.value);   //  var startDate = new Date(document.forms[0].year.value,document.forms[0].month.value,document.forms[0].day.value);
 var endDate = new Date(document.book.toyear.value,document.book.tomonth.value-1,document.book.today.value);   //  var endDate = new Date(document.forms[0].toyear.value,document.forms[0].tomonth.value,document.forms[0].today.value);
 var startDateOff = new Date(document.book.year.value,document.book.month.value-1,document.book.day.value);   //  var startDate = new Date(document.forms[0].year.value,document.forms[0].month.value,document.forms[0].day.value);
 if (startDateOff.getTime() < t.getTime()) {   //  17+1 < 17  startDate.valueof() > t.valueof()
    window.alert("You must enter Start Date bigger than today to submit form!");
	return false;
 }
 if (startDate.getTime() > endDate.getTime()) {   //  startDate.valueof() > endDate.valueof()
    window.alert("You must enter Start Date prior End Date to submit form!");
	return false;
 }
 else 
    return true;
}  // end function   p261 gosselin book

