// JavaScript Document
//-->
// check if Check Out happened before Check In and Check In happen after today.
function checkDate(dateIn,dateOut) {
var error = "";
var today = new Date();
var month = today.getMonth() + 1
var day = today.getDate()
var year = today.getFullYear()
var s = "-"
if(day<10) day = "0" + day
if(month<10) month= "0" + month 
today = year + s + month + s + day;
	if (dateIn >= dateOut) {
		error = "- Check In and Check Out Date mis-match.\n";
	}
	if (today >= dateIn) {
		error = "- Your Check In Date was pass.\n";
	}
return error;
}

// Check if Check Out happended after the lastest date in Room Price.
function maxDate(dateOut,endDate) {
var error = "";
	if (dateOut > endDate) {
		error = "- Booing Date is out of our date range.\n";
	}
return error;
}

// valid selector from dropdown list
function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "- The Villa is required to select.\n";
	//return error;
    }    
return error;
}    

// non-empty textbox
function isEmptyname(strng) {
var error = "";
  if (strng.length == 0) {
     error = "- Name is required.\n";
	 //return error;
  }
return error;	  
}
function isEmptycountry(strng) {
var error = "";
  if (strng.length == 0) {
     error = "- Country is required.\n";
	 //return error;
  }
return error;	  
}

// email
function checkEmail (strng) {
var error="";
	if (strng == "") {
	   error = "- Email Address is required.\n";
	   return error;    
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
	   error = "- Please enter a valid email address.\n";
	   //return error;
	} else {
//test email for illegal characters
	   var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
	   if (strng.match(illegalChars)) {
		  error = "- The email address contains illegal characters.\n";
		  //return error;
	   }
	} 
return error;
}

// phone number - strip out delimiters and check for 10 digits
function checkPhone (strng) {
	var error = "";
	if (strng == "") {
	   error = "- Phone No is required.\n";
	   return error;    
	}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "- The phone number contains illegal characters.";
       //return error;    
    }
    if (!(stripped.length >= 9)) {
	   error = "- The phone number is the wrong length.\n";
       //return error;    
    } 
return error;
}




