function verifyInput(_selList,_textBox) {
  var SI = eval(_selList+".selectedIndex");
  var SV = eval(_selList+".options[SI].value");
  var Ph;
  
  Ph = SV.split("#",2);
  SV = Ph[1];
  
  eval(_textBox+".value = SV");
} 

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
	if (isNaN(parseInt(num))) return "NULL";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

function updtCost(numPax, tourId, onePrice, twoPrice, threePrice, fourPrice, fivePrice, sixPrice, sevenPrice, eightPrice, ninePrice, tenPrice, elevenPrice, twelvePrice, thirteenPrice, fourteenPrice, fifteenPrice, sixteenPrice, seventeenPrice, eighteenPrice, nineteenPrice, twentyPrice, package, tourday)
{
	var price = 0;
	switch(numPax)
	{
		case "1":
			price = onePrice;
			break;
		case "2":
			price = twoPrice;
			break;
		case "3":
			price = threePrice;
			break;
		case "4":
			price = fourPrice;
			break;
		case "5":
			price = fivePrice;
			break;
		case "6":
			price = sixPrice;
			break;
		case "7":
			price = sevenPrice;
			break;
		case "8":
			price = eightPrice;
			break;
		case "9":
			price = ninePrice;
			break;
		case "10":
			price = tenPrice;
			break;
		case "11":
			price = elevenPrice;
			break;
		case "12":
			price = twelvePrice;
			break;
		case "13":
			price = thirteenPrice;
			break;
		case "14":
			price = fourteenPrice;
			break;
		case "15":
			price = fifteenPrice;
			break;
		case "16":
			price = sixteenPrice;
			break;
		case "17":
			price = seventeenPrice;
			break;
		case "18":
			price = eighteenPrice;
			break;
		case "19":
			price = nineteenPrice;
			break;
		case "20":
			price = twentyPrice;
			break;
		default:
			price = onePrice
			break;
	}
	
	var perPerson	= $(tourId+"per-person");
	var total	= $(tourId+"total");
	
	perPerson.innerHTML	= "Per Person:<br />"+FormatNumber(price,2,true,false,true);
	var cost	= price*numPax;
	var costtotal = cost;
	total.innerHTML	= "<input type=\"hidden\" name=\""+tourId+"_cost\" value=\""+cost+"\" /> Tour Total:<br />"+FormatNumber(cost,2,true,false,true);
	
	if(document.getElementById(package).checked==true)
	{		
		
		document.getElementById("totalall").innerHTML = "<input type=\"hidden\" name=\"totalamount\" value=\""+costtotal+"\" id=\"totalamount\"/><input type=\"hidden\" name=\"tournday\" value=\""+tourday+"\" /><strong>Tour Total:</strong> <span class=\"orangtext\"><strong> "+FormatNumber(costtotal,2,true,false,true)+" </strong></span><span class=\"nntext\">Thai Baht</span>";
		
		var optioncost = 0;
		document.getElementById("totaloption").innerHTML = "<input type=\"hidden\" name=\"totaloption\" value=\""+optioncost+"\" id=\"totaloption\"/><span class=\"nntext\"><strong>Extra Total:</strong></span> <span class=\"orangtext\"><strong> "+FormatNumber(optioncost,2,true,false,true)+" </strong></span><span class=\"nntext\">Thai Baht</span>";
		
	}
	
}
function updtOptionCost(chkbox, numPax, tourId, package ){
	var optioncost = 0;
	
	if(document.getElementById(package).checked==true)
	{
		with(document.frmData) {
			for(var i = 0; i < chkbox.length; i++){ 
				if(chkbox[i].checked) {
					if(chkbox[i].value == "limo"){
						
							optioncost += 1000;
						
					}else{
						optioncost += (chkbox[i].value * numPax) ; 
					}
				} 
			} 
		}
		document.getElementById("totaloption").innerHTML = "<input type=\"hidden\" name=\"totaloption\" value=\""+optioncost+"\" id=\"totaloption\"/><span class=\"nntext\"><strong>Extra Total :</strong></span> <span class=\"orangtext\"><strong> "+FormatNumber(optioncost,2,true,false,true)+" </strong></span><span class=\"nntext\">Thai Baht</span>";
	}
}
function resetOption()
{
	with(document.frmData) {
		for(var i = 0; i < document.frmData.costoption.length; i++){ 
			if(document.frmData.costoption[i].checked) { 
				optioncost += (document.frmData.costoption[i].value * numPax) ; 
			} 
		} 
	}
}

function resetHotelphone()
{
	document.frmData.hotelphone.value = "";
}

function checkEmailValid(emailStr,msg)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var errMsg="";   
	var matchArray=emailStr.match(emailPat)

	if (matchArray==null) 
	{
	   errMsg=errMsg+"The "+msg+" email address seems incorrect";
	   return errMsg;
	}
	else
	{
	  var user=matchArray[1]
	  var domain=matchArray[2]
	  if (user.match(userPat)==null) 
	  {
		errMsg=errMsg+"The "+msg+" email address seems incorrect";
		return errMsg;       
	  }
	  var IPArray=domain.match(ipDomainPat)
	  if (IPArray!=null) 
	  {
		  for (var i=1;i<=4;i++) 
			  {
			if (IPArray[i]>255) 
				{
				errMsg=errMsg+"The "+msg+" email address seems incorrect";
				return errMsg;
				}//IF
			  }//for
	   }//IP Array
	   var domainArray=domain.match(domainPat)
	   if (domainArray==null) 
	   {
		 errMsg=errMsg+"The "+msg+" email address seems incorrect";
		 return errMsg;
	   }
	   var atomPat=new RegExp(atom,"g")
	   var domArr=domain.match(atomPat)
	   var len=domArr.length
	   if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
	   {
		 errMsg=errMsg+"The "+msg+" email address seems incorrect";
		 return errMsg;	
	   } 
	   if (len<2) 
	   {
		 errMsg=errMsg+"The "+msg+" email address seems incorrect";
		 return errMsg;	 
	   } 
	 }//End  Match
	return "0";
}

function checkDataEntry(obj)
{
	var mycode
	var count=0;
	if(obj.length!=0)
	{
		for(i=0; i<obj.length; i++)
		{
			mycode = obj.charCodeAt(i);
			if((mycode>47 && mycode<58) || (mycode>64 && mycode<91) || (mycode>96 && mycode<123) || (mycode>3584 && mycode<3631) || (mycode>3647 && mycode<3653))
			{
				count=count+1;
			}
		}
	}
	return count;
}

function checkBookingForm()
{
	if(checkDataEntry(document.frmData.name.value)==0)
	{
		alert("Please enter the contact firstname!");
		return false;
	}
	if(checkDataEntry(document.frmData.lastname.value)==0)
	{
		alert("Please enter the contact lastname!");
		return false;
	}
	var e=document.frmData.email.value;
	if(checkDataEntry(e)==0)
	{
		alert("Please enter a valid email address!");
		return false;
	}
	else
	{
		if (checkEmailValid(e)!="0") 
		{
			alert(checkEmailValid(e,''));
			return false;	
		}
	}
	
	if((checkDataEntry(document.frmData.hotelname.value)==0) && (checkDataEntry(document.frmData.hotelname_other.value)==0))
	{
		alert("Please enter the hotel name!");
		return false;
	}
		var radio_choice = false;
		var rg = (document.forms.frmData.optPackage.length == undefined
                 ? new Array(document.forms.frmData.optPackage)
                 : document.forms.frmData.optPackage);

		
			
			for (counter = 0; counter < rg.length; counter++)
			{
			if (rg[counter].checked)
			radio_choice = true; 
			}
		
		if(radio_choice == false){
			alert("Please select a package tour");
			return false;
		}
		
		if(document.frmData.payment[0].checked==false && document.frmData.payment[1].checked==false)
	{
		alert("Please select a payment method");
		return false;
	}
	if(checkDataEntry(document.frmData.captchacode.value)==0) 
	{
		alert("Please enter the image code!");
		return false;
	}
	
	var days = 0;
	var diff = 0;
	
	var dropdownIndex = document.getElementById('daybook').selectedIndex;
	var dropdownValue = document.getElementById('daybook')[dropdownIndex].value;
	
	var dropdownIndex2 = document.getElementById('monthbook').selectedIndex;
	var dropdownValue2 = document.getElementById('monthbook')[dropdownIndex2].value;
	var bookyear = dropdownValue2.slice(0,4);
	var bookmonth = dropdownValue2.slice(5)-1;
	
	var bookDate = new Date(bookyear,bookmonth,dropdownValue);
	
	var today = new Date();
	
	diff = bookDate - today;
	
	days = Math.round(diff/(1000*60*60*24));
	
	if(days <= 10 && document.frmData.payment[1].checked==true){
			alert("Notice! We only accept credit card online payment for 10 days in advance of requested tour date. Please change option to pay in cash.");
			return false;
	}
	
	
	return true;
}
function $(ID)
{
	return document.getElementById(ID);
}

Array.prototype.inArray = function (value)
{
	var i;
	for (i=0; i < this.length; i++)
	{
		if (this[i] === value){return true;}
	}
	return false;
}