function checkForm(form)
{
	box = form.HotelCode;
	
	if (box.type != "hidden" && box.selectedIndex == 0) 
	{
		alert ("Please select a resort.");
		return false;
	}
//alert (input);
hotelPosition = form.HotelCode.selectedIndex;	
//alert (form.ArrivalD.value);
//alert ($("#ArrivalD").datepicker.formatDate('dd', input)); form.ArrivalD.value;
testdate = form.ArrivalD.value; //$("#ArrivalD").datepicker.formatDate('m/d/yy',form.ArrivalD.value);

//alert (testdate);
test2date = new Date (testdate);
var curr_date = test2date.getDate();
var curr_month = test2date.getMonth();
var curr_year = test2date.getFullYear();
//alert (curr_date);
//alert (curr_month);
//alert (curr_year);
//m = parseInt(testdate.substring(0,2));
//d = parseInt(testdate.substring(3,5));
//y = (testdate.substring(6,10));
//if (hotelPosition == 3 || hotelPosition == 7 || hotelPosition == 9) {
//alert (y);
//alert (d);
//alert (m);
//if(curr_year < 2000) { curr_year = curr_year + 1900; }
//if (curr_year==2009) {
//	if (curr_month<10) {
//		if ( (curr_date>0 && curr_date<32) ) {
//			alert ("You must select an arrival date starting on or after November 1, 2009 to book this resort."); return false;
//		}
//	}
//}
//}
	
 if(!checkDate(form.ArrivalD)) return false; 
 if(!checkDate(form.DepartureD)) return false; 
 // make sure start date is before the end date
 
 if (Date.parse(form.ArrivalD.value) > Date.parse(form.DepartureD.value)) {
 alert("Invalid Date Range!\nStart Date cannot be after End Date!")
 return false;
 }
 if ((Date.parse(form.ArrivalD.value)+172800000) > Date.parse(form.DepartureD.value)) {
 alert("Departure and Returning Dates must be at least 2 days apart.")
 return false;
 } 
 
 if (form.email) {
	var emailID=form.email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}

}
 
 return true;	
}

function checkFormNoEmail(form)
{
	
//alert (input);
hotelPosition = form.HotelCode.selectedIndex;	
//alert (form.ArrivalD.value);
//alert ($("#ArrivalD").datepicker.formatDate('dd', input)); form.ArrivalD.value;
testdate = form.ArrivalD.value; //$("#ArrivalD").datepicker.formatDate('m/d/yy',form.ArrivalD.value);

//alert (testdate);
test2date = new Date (testdate);
var curr_date = test2date.getDate();
var curr_month = test2date.getMonth();
var curr_year = test2date.getFullYear();
//alert (curr_date);
//alert (curr_month);
//alert (curr_year);
//m = parseInt(testdate.substring(0,2));
//d = parseInt(testdate.substring(3,5));
//y = (testdate.substring(6,10));
//if (hotelPosition == 3 || hotelPosition == 7 || hotelPosition == 9) {
//alert (y);
//alert (d);
//alert (m);
//if(curr_year < 2000) { curr_year = curr_year + 1900; }
//if (curr_year==2009) {
//	if (curr_month<10) {
//		if ( (curr_date>0 && curr_date<32) ) {
//			alert ("You must select an arrival date starting on or after November 1, 2009 to book this resort."); return false;
//		}
//	}
//}
//}
	
 if(!checkDate(form.ArrivalD)) return false; 
 if(!checkDate(form.DepartureD)) return false; 
 // make sure start date is before the end date
 
 if (Date.parse(form.ArrivalD.value) > Date.parse(form.DepartureD.value)) {
 alert("Invalid Date Range!\nStart Date cannot be after End Date!")
 return false;
 }
 if ((Date.parse(form.ArrivalD.value)+172800000) > Date.parse(form.DepartureD.value)) {
 alert("Departure and Returning Dates must be at least 2 days apart.")
 return false;
 } 
 

 return true;	
}

function addTwo(dateValue)
{

    dateParts = document.getElementById('ArrivalD').value.split('/');
    newDays   = 2;
    year  = dateParts[2];
    month = parseInt(dateParts[0], 10)-1;
    day   = parseInt(dateParts[1]) + parseInt(newDays);

    newDate = new Date ( year, month, day );
	
    year  = newDate.getFullYear();
    month = newDate.getMonth()+1;
    month = (month<10)?'0'+month:month;
    day   = newDate.getDate();
    day   = (day<10)?'0'+day:day;

    formattedDate = month + '/' + day + '/' + year;
	
	return formattedDate;
	//document.SubmitForm.DepartureD.value = formattedDate;

}

function checkArrival(dateValue)
{
 if(!checkDate(dateValue)) {
	 return false; 	
 } else {
    dateParts = document.getElementById('ArrivalD').value.split('/');
    newDays   = 2;
    year  = dateParts[2];
    month = parseInt(dateParts[0], 10)-1;
    day   = parseInt(dateParts[1]) + parseInt(newDays);

    newDate = new Date ( year, month, day );
	
    year  = newDate.getFullYear();
    month = newDate.getMonth()+1;
    month = (month<10)?'0'+month:month;
    day   = newDate.getDate();
    day   = (day<10)?'0'+day:day;

    formattedDate = month + '/' + day + '/' + year;
	
	document.SubmitForm.DepartureD.value = formattedDate;
 }
}

function checkDate(field)
  {
    var allowBlank = true;
    var minYear = 2005;
    var maxYear = (new Date()).getFullYear() + 2;

    var errorMsg = "";

    // regular expression to match required date format
    re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
    
    if(field.value != '') {
      if(regs = field.value.match(re)) {
        if(regs[2] < 1 || regs[2] > 31) {
          errorMsg = "Invalid value for day: " + regs[2];
        } else if(regs[1] < 1 || regs[1] > 12) {
          errorMsg = "Invalid value for month: " + regs[1];
        } else if(regs[3] < minYear || regs[3] > maxYear) {
          errorMsg = "Invalid value for year: " + regs[3] + " - must be between " + minYear + " and " + maxYear;
        }
      } else {
        errorMsg = "Invalid date format: " + field.value;
      }
    } else if(!allowBlank) {
      errorMsg = "Empty date not allowed!";
    }
    
    if(errorMsg != "") {
      alert(errorMsg);
      field.focus();
      return false;
    }
    
    return true;
  }
  
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}
