// JavaScript Document
function bookingvalid()
{
	
  if(document.form1.arr_date.value=="")
  {
	  alert("Enter arrival date");
	  document.form1.arr_date.focus();
	  return false;
  }
  if(document.form1.dep_date.value=="")
  {
	  alert("Enter Departure date");
	  document.form1.dep_date.focus();
	  return false;
  }
  value1=document.form1.dep_date.value;
  value2=document.form1.arr_date.value;
  if(compareDates (value1, value2)<0)
  {
	  alert("Departure date<Arrival Date");
	  document.form1.dep_date.focus();
	  return false;
  }
  if(document.form1.noofrooms.value=="")
  {
	  alert("Enter No of rooms");
	  document.form1.noofrooms.focus();
	  return false;
  }
  if(document.form1.email.value==""){
		alert("Enter Your Email");
		document.form1.email.focus();
		return false;
	}
if(!isValidEmail(document.form1.email.value)){
		alert("Enter a valid  email");
		document.form1.email.select()
		return false;
}
if(document.form1.cemail.value==""){
		alert("Retype Email");
		document.form1.cemail.focus();
		return false;
	}
if(document.form1.email.value!=document.form1.cemail.value){
		alert("Email mismatch");
		document.form1.cemail.focus();
		return false;
	}
if(document.form1.firstname.value==""){
		alert("Enter Your firstname");
		document.form1.firstname.focus();
		return false;
	}
if(document.form1.hphone.value==""){
		alert("Enter Your home phone");
		document.form1.hphone.focus();
		return false;
	}

 return true;
}

function compareDates (value1, value2) {
  var date1, date2;
  var month1, month2;
  var year1, year2;

  year1 = value1.substring (0, value1.indexOf ("-"));
  month1 = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));
  date1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);

  year2 = value2.substring (0, value2.indexOf ("-"));
  month2 = value2.substring (value2.indexOf ("-")+1, value2.lastIndexOf ("-"));
  date2 = value2.substring (value2.lastIndexOf ("-")+1, value2.length);
  
  

  if (year1 > year2) return 1;
  else if (year1 < year2) return -1;
  else if (month1 > month2) return 1;
  else if (month1 < month2) return -1;
  else if (date1 > date2) return 1;
  else if (date1 < date2) return -1;
  else return 0;
} 

function IsphoneNumeric(strString)
   	{//  check for valid numeric strings	
      var strValidChars = "0123456789+-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (k = 0; k < strString.length && blnResult == true; k++)
      {
      strChar = strString.charAt(k);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
	  return blnResult;
   } 


//valid email

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}