
function LTrim(str)
/*
PURPOSE: Remove leading blanks from our string.
IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}


/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}
/**/
function checkEmail(str){
	var textValue = str.value;
	var err=''
	if (textValue == ''){
		err += "Địa chỉ email không hợp lệ ";
		alert(err);
		str.focus();
		return false
	}
	if (textValue.indexOf('@') <= 0 || textValue.indexOf('@') == textValue.length -1){
		err += "Địa chỉ email không hợp lệ ";		
	} else {
		var substr = textValue.substring(textValue.indexOf('@'),textValue.length);
		if (textValue.indexOf('.') <= 0) {
			err += "Địa chỉ email không hợp lệ \n";
		}
	}
	if (err != '') { 
		alert(err); 
		str.focus();
		return false;
	}
	return true;
}

/**/
function checkRegister (f) {
	companyName = f.txthoten.value;
	if (Trim(companyName) == "") {
		alert('Vui lòng nhập họ tên');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	address = f.txtdiachi.value;
	if (Trim(address) == "") {
		alert('Vui lòng nhập vào địa chỉ');
		f.txtdiachi.focus();
		return false;
	}
	telephone = f.txtdt.value;
	if (Trim(telephone) == "") {
		alert('Vui lòng nhập số điện thoại');
		f.txtdt.focus();
		return false;
	}
	contactPerson = f.txtchude.value;
	if (Trim(contactPerson) == "") {
		alert('Vui lòng nhập chủ đề liên hệ');
		f.txtchude.focus();
		return false;
	}
	catId = f.txtnoidung.value;
	if (catId == "") {
		alert('Vui lòng nhập nội dung liên hệ');
		f.txtnoidung.focus();
		return false;
	}
	
	return true;	
}
// check book tour
/**/
function checkBookTour (f) {
	companyName = f.txthoten.value;
	if (Trim(companyName) == "") {
		alert('Vui lòng nhập họ tên');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	address = f.txtdiachi.value;
	if (Trim(address) == "") {
		alert('Vui lòng nhập vào địa chỉ');
		f.txtdiachi.focus();
		return false;
	}
	telephone = f.txtdt.value;
	if (Trim(telephone) == "") {
		alert('Vui lòng nhập số điện thoại');
		f.txtdt.focus();
		return false;
	}
	contactPerson = f.cmbcategory.value;
	
	if (Trim(contactPerson) == "0") {
		alert('Vui lòng chọn mã chương trình du lịch');
		f.cmbcategory.focus();
		return false;
	}
	
	subCathotel = f.cmbcat.value;
	if (subCathotel == "0") {
		alert('Vui lòng chọn loại khách sạn');
		f.cmbcat.focus();
		return false;
	}

	subCatroom = f.cmbroomcat.value;
	if (subCatroom == "0") {
		alert('Vui lòng chọn loại phòng khách sạn');
		f.cmbroomcat.focus();
		return false;
	}
	
	subCatId = f.txtngaykh.value;
	if (subCatId == "") {
		alert('Vui lòng ngày khởi hành');
		f.txtngaykh.focus();
		return false;
	}
	subrequest = f.txtyeucau.value;
	if (subrequest == "") {
		alert('Vui lòng nhập nội dung yêu cầu');
		f.txtyeucau.focus();
		return false;
	}


	return true;	
}
// check book hotel
/**/
function checkBookHotel (f) {
	companyName = f.txthoten.value;
	if (Trim(companyName) == "") {
		alert('Vui lòng nhập họ tên');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	address = f.txtdiachi.value;
	if (Trim(address) == "") {
		alert('Vui lòng nhập vào địa chỉ');
		f.txtdiachi.focus();
		return false;
	}
	telephone = f.txtdt.value;
	if (Trim(telephone) == "") {
		alert('Vui lòng nhập số điện thoại');
		f.txtdt.focus();
		return false;
	}
		catId = f.cmbhotel.value;
	if (catId == "0") {
		alert('Vui lòng chọn tên khách sạn');
		f.cmbhotel.focus();
		return false;
	}
	
	subCatId = f.txtngaykh.value;
	if (subCatId == "") {
		alert('Vui lòng ngày đăng ký');
		f.txtngaykh.focus();
		return false;
	}
	subCatdateout= f.txtngayve.value;
	if (subCatdateout == "") {
		alert('Vui lòng ngày thanh toán');
		f.txtngayve.focus();
		return false;
	}
	subCatroom = f.cmbroomcat.value;
	if (subCatroom == "0") {
		alert('Vui lòng chọn loại phòng khách sạn');
		f.cmbroomcat.focus();
		return false;
	}
	subCatAdult = f.txtnguoilon.value;
	if (subCatAdult == "0") {
		alert('Vui lòng nhập số lượng thành viên đăng ký');
		f.txtnguoilon.focus();
		return false;
	}
	subrequest = f.txtyeucau.value;
	if (subrequest == "") {
		alert('Vui lòng nhập nội dung yêu cầu');
		f.txtyeucau.focus();
		return false;
	}


	return true;	
}
// check book Flight
/**/
function checkBookFlight (f) {
	companyName = f.txthoten.value;
	if (Trim(companyName) == "") {
		alert('Vui lòng nhập họ tên');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	address = f.txtdiachi.value;
	if (Trim(address) == "") {
		alert('Vui lòng nhập vào địa chỉ');
		f.txtdiachi.focus();
		return false;
	}
	telephone = f.txtdt.value;
	if (Trim(telephone) == "") {
		alert('Vui lòng nhập số điện thoại');
		f.txtdt.focus();
		return false;
	}
	contactPerson = f.txtchuyenbay.value;
	
	if (Trim(contactPerson) == "") {
		alert('Vui lòng nhập chuyến bay');
		f.txtchuyenbay.focus();
		return false;
	}
	catId = f.txtsove.value;
	if (catId == "0") {
		alert('Vui lòng nhập số lượng vé');
		f.txtsove.focus();
		return false;
	}

	subCatdateout= f.txtngaykh.value;
	if (subCatdateout == "") {
		alert('Vui lòng chọn ngày khởi hành');
		f.txtngaykh.focus();
		return false;
	}
	
	subrequest = f.txtyeucau.value;
	if (subrequest == "") {
		alert('Vui lòng nhập nội dung yêu cầu');
		f.txtyeucau.focus();
		return false;
	}


	return true;	
}
// check book Flight
/**/
function checkBookVehicle (f) {
	companyName = f.txthoten.value;
	if (Trim(companyName) == "") {
		alert('Vui lòng nhập họ tên');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	address = f.txtdiachi.value;
	if (Trim(address) == "") {
		alert('Vui lòng nhập vào địa chỉ');
		f.txtdiachi.focus();
		return false;
	}
	telephone = f.txtdt.value;
	if (Trim(telephone) == "") {
		alert('Vui lòng nhập số điện thoại');
		f.txtdt.focus();
		return false;
	}
	contactPerson = f.txtloaixe.value;
	
	if (Trim(contactPerson) == "") {
		alert('Vui lòng nhập loại xe');
		f.txtloaixe.focus();
		return false;
	}
	catId = f.txtsocho.value;
	if (catId == "0") {
		alert('Vui lòng nhập số chổ ngồi');
		f.txtsocho.focus();
		return false;
	}
	
	
	subCatdateout= f.txtngaykh.value;
	if (subCatdateout == "") {
		alert('Vui lòng chọn ngày khởi hành');
		f.txtngaykh.focus();
		return false;
	}
	
	subrequest = f.txtyeucau.value;
	if (subrequest == "") {
		alert('Vui lòng nhập nội dung yêu cầu');
		f.txtyeucau.focus();
		return false;
	}


	return true;	
}
/* book tailor*/
function checkBookTailor(f)
{
companyName = f.txthoten.value;
	if (Trim(companyName) == "") {
		alert('Vui lòng nhập họ tên');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	address = f.txtdiachi.value;
	if (Trim(address) == "") {
		alert('Vui lòng nhập vào địa chỉ');
		f.txtdiachi.focus();
		return false;
	}
	telephone = f.txtdt.value;
	if (Trim(telephone) == "") {
		alert('Vui lòng nhập số điện thoại');
		f.txtdt.focus();
		return false;
	}
	subCatId = f.txtngaykh.value;
	if (subCatId == "") {
		alert('Vui lòng ngày khởi hành');
		f.txtngaykh.focus();
		return false;
	}
	contactPerson = f.txtthoigian.value;
	
	if (Trim(contactPerson) == "0") {
		alert('Vui lòng nhập số ngày');
		f.txtthoigian.focus();
		return false;
	}
	contactPerson = f.txtdiemden.value;
	
	if (Trim(contactPerson) == "") {
		alert('Vui lòng nhập thông tin điểm đến');
		f.txtdiemden.focus();
		return false;
	}
	contactPerson = f.txtpt.value;
	
	if (Trim(contactPerson) == "") {
		alert('Vui lòng nhập phương tiện');
		f.txtpt.focus();
		return false;
	}
	subCathotel = f.cmbcat.value;
	if (subCathotel == "0") {
		alert('Vui lòng chọn loại khách sạn');
		f.cmbcat.focus();
		return false;
	}

	subCatroom = f.cmbroomcat.value;
	if (subCatroom == "0") {
		alert('Vui lòng chọn loại phòng khách sạn');
		f.cmbroomcat.focus();
		return false;
	}
	
	txtnguoilon = f.txtnguoilon.value;
	if (txtnguoilon == "0") {
		alert('Vui lòng nhập số lượng người đi');
		f.txtnguoilon.focus();
		return false;
	}
	subrequest = f.txtyeucau.value;
	if (subrequest == "") {
		alert('Vui lòng nhập nội dung yêu cầu');
		f.txtyeucau.focus();
		return false;
	}


	return true;	
}	
//**/
/*Search tour*/
function checkinputsearchtour(f)
{
	
	subrequest = f.txtdiemden.value;
	if (subrequest == "") {
		alert('Vui lòng nhập thông tin nơi đến');
		f.txtdiemden.focus();
		return false;
	}
	cmbkindtour = f.cmbkindtour.value;
	if (cmbkindtour == "0") {
		alert('Vui lòng chọn loại chương trình tour');
		f.cmbkindtour.focus();
		return false;
	}

	return true;	
}
function checkinputSearchDestination(f)
{
	subrequest = f.txtdestination.value;
	if (subrequest == "") {
		alert('Vui lòng nhập thông tin nơi đến');
		f.txtdestination.focus();
		return false;
	}
	cmbkindtour = f.cmbcountries.value;
	if (cmbkindtour == "0") {
		alert('Vui lòng chọn tên nước');
		f.cmbcountries.focus();
		return false;
	}

	return true;	
}
function ViewHTML(filename){
   if (filename == 0)
   {
   		alert("Please choose hotel!")
    	return
   }
   var newWin1 = window.open("hotelview.php?l=1&id=2&nid=" + filename, "VIEWTOUR", "SCROLLBARS, WIDTH=700, HEIGHT=500")
   newWin1.focus()
}
function checkinputsearchhotel(f)
{
	subrequest = f.txttenks.value;
	if (subrequest == "") {
		alert('Vui lòng nhập khách sạn cần tìm');
		f.txttenks.focus();
		return false;
	}
}
function faqs(f)
{
	txthoten = f.txthoten.value;
	if (txthoten == "") {
		alert('Vui lòng nhập họ tên của bạn');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	txtdoan = f.txtykien.value;
	if (Trim(txtdoan) == "") {
		alert('Vui lòng nhập ý kiến của bạn');
		f.txtykien.focus();
		return false;
	}
	
}
