
// MAIN Form function =================================================================

function IsEmailFormat(strEmail){
	if (isEmpty(strEmail)==false){
		if (strEmail=="" || strEmail.indexOf('@', 0)==-1 || strEmail.indexOf('.')==-1){return false;}
		else {return true;}
	}
}

//Not allow email with domain @tourismcambodia.com
function IsNotTourismCambodia(strEmail){
	if (isEmpty(strEmail)==false){
		if (strEmail.toLowerCase().indexOf('@tourismcambodia.com') != -1){return false;}
		else {return true;}
	}
}

//Returns true if the field not empty
function isEmpty(s){   
	return ((s==null) || (s.length==0))
}

//Returns true if the length of s is less than maxLength
function chkLength(s, maxLength){
	if (s.length > maxLength){return false;}
	else {return true;}	

}

function isNotSelect(objForm){
	if((objForm=="0") || (isEmpty(objForm))){return false;}
	else {return true;}
}

function ctMatch(cts1, cts2){
	if(cts1==cts2){return false;}
	else {return true;}
}

//Returns true if v2 greater than v1
function chkValue(v1, v2){
	if (v1 > v2){return false;}
	else {return true;}

}

//validates that the entry is number 
function isNumber(nm) {
  var str = nm.value;
    var re = /^[-]?\d*\.?\d*$/;
    str = str.toString();
    if (!str.match(re)) {return true;}  
}


// Flights - Flight Search Left function =================================================================
function VFlightSearch(form){

	if(isNotSelect(form.txtorigin.value)==false){
		alert("Please select Original City");
		form.txtorigin.focus();
		return false;
	}

	if(isNotSelect(form.txtdestination.value)==false){
		alert("Please select Destination City");
		form.txtdestination.focus();
		return false;
	}

	if(ctMatch(form.txtorigin.value, form.txtdestination.value)==false){
		alert("Original City and Destination City cannot be the same, please select again");
		form.txtdestination.focus();
		return false;
	}

			form.submit();								
}


// Hotels - Hotels Search Left function =================================================================
function VSearchHotel(form){

	if(isEmpty(form.txtrate1.value)){
		alert("Please enter Minimum Rate");
		form.txtrate1.focus();
		return false;
	} else {
	
	if(isNumber(form.txtrate1)) {
		alert("Please enter only number in Minimum Rate");
		form.txtrate1.focus();
	    return false;
		}	
	}

	if(isEmpty(form.txtrate2.value)){
		alert("Please enter Maximum Rate");
		form.txtrate2.focus();
		return false;
	} else {
	
	if(isNumber(form.txtrate2)) {
		alert("Please enter only number in Maximum Rate");
		form.txtrate2.focus();
	    return false;
		}	
	}

	if (form.txtrate2.value - form.txtrate1.value < 0){
			alert ("Maximum Rate must be greater than Minimum Rate")
			form.txtrate2.focus();
			return ;
			}

	if(isNotSelect(form.city.value)==false){
		alert("Please select City");
		form.city.focus();
		return false;
	}

			form.submit();								
}

