function checkForm(form)
{
 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 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					
	}
