document.write('<div id="loadTable" style="display:none;position:absolute;opacity: 1;filter:alpha(opacity=100);z-index:2;background-color:#FFFFFF;border:3px solid #DD0000;"><table><tr><td align="center"><img src="images/wait.gif" alt="" /></td></tr><tr><td><input type="button" onclick="unloadScreen();" value="Cancel" /></td></tr></table></div><div id="loadScreen" style="display:none;position:absolute;width:100%;height:100%;background-color:#CCCCCC;top:0px;left:0px;opacity: 0.7;filter:alpha(opacity=70);z-index:1;">&nbsp;</div>');
var xmlHttp;
try{ // Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
}
catch (e){ // Internet Explorer
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e){
		try{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e){
			alert("Your browser does not support AJAX!\r\nPlease make hotel's reservation manually via email (reservation@go-exploreasia.com)");
		}      
	}    
}  

function dataRequest(task,id,target){
	var link = window.location.protocol+"//"+window.location.hostname+"/index.php?com=request&task="+task+"&id="+id+"&target="+target;
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==1){
			//loadScreen();
		}
		if(xmlHttp.readyState==4){
			switch(task){
				case "request":
					changeOption(xmlHttp.responseText,target);
					break;
				case "username":
					username_avai(xmlHttp.responseText,target);
					break;
				case "price":
					price(xmlHttp.responseText,target);
					break;
				default:
					break;
			}
			//unloadScreen();
			xmlHttp.abort();
		}
	}
    xmlHttp.open("GET",link,true);
    xmlHttp.send(null);
}

function dataRequest2(link, target){
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==1){
			//loadScreen();
		}
		if(xmlHttp.readyState==4){
			document.getElementById(target).innerHTML = xmlHttp.responseText;
			//unloadScreen();
			xmlHttp.abort();
		}
	}
    xmlHttp.open("GET",link,true);
    xmlHttp.send(null);
}

function loadScreen(){
	//document.getElementById("testdis").innerHTML=("x : "+((getSize("x")/2)+getPosition("x")+"px")+"<br />pos : "+getPosition("x")+"px<br />y : "+((getSize("y")/2)+getPosition("y")+"px")+"<br />pos : "+getPosition("y")+"px");
	document.getElementById("loadScreen").style.width = document.body.scrollWidth+"px";
	document.getElementById("loadScreen").style.height = document.body.scrollHeight+"px";
	document.getElementById("loadTable").style.left = (getSize("x")/2)+getPosition("x")+"px";
	document.getElementById("loadTable").style.top = (getSize("y")/2)+getPosition("y")+"px";
	document.getElementById("loadScreen").style.display = "block";
	document.getElementById("loadTable").style.display = "block";
}

function unloadScreen(){
	xmlHttp.abort();
	document.getElementById("loadTable").style.display = "none";
	document.getElementById("loadScreen").style.display = "none";
}

function getSize(axis) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight/2;
  }
  if(axis=="x"){
	  return myWidth;
  }else{
	  return myHeight;
  }
}

function getPosition(axis) {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  if(axis=="x"){
	  return scrOfX;
  }else{
	  return scrOfY;
  }
}

function changeOption(string,target){
	if(target=="sel_city"){
		document.getElementById('sel_area').innerHTML = '<option value="-1">All</option>';
		document.getElementById(target).innerHTML = string;
	}else if(target=="cityid"){
		document.getElementById('cityid').innerHTML = '<option value="-1">All</option>';
		document.getElementById(target).innerHTML = string;
	}else{
		if(string.length>0){
			if(target=="sel_location"){
				clearOption("sel_hotel");
			}
			if(string=="0"){
				clearOption(target);
			}else{
				string = string.split("~");
				value = string[0].split("#");
				text = string[1].split("#");
				clearOption(target);
				if(value.length>0){
					for(i=0;i<value.length-1;i++){
						addOption(target,value[i],text[i]);
					}
				}
			}
		}else{
			clearOption(target);
		}
		if(target=="sel_location"){
			if(document.getElementById("sel_state").selectedIndex=="1"){
				document.getElementById("sel_location").selectedIndex="1";
			}
		}else if(target=="sel_location_com"){
			if((document.getElementById("sel_state_com").selectedIndex=="1")||(document.getElementById("sel_state_com").selectedIndex=="2")){
				document.getElementById("sel_location_com").selectedIndex="1";
			}
		}else{
		}
	}
}

function username_avai(string,target){
	if(string=="yes"){
		document.getElementById(target).value="1";
		document.getElementById(target+"_span").style.color="#00FF00";
		document.getElementById(target+"_span").innerHTML="Yes";
	}else{
		document.getElementById(target).value="0";
		document.getElementById(target+"_span").style.color="#FF0000";
		document.getElementById(target+"_span").innerHTML="No";
	}
}

function price(string,target){
	var string = string.split("~");
		document.getElementById("div_"+target).innerHTML=string[0];
	if(string[1]=="valid")
		document.order_form.room_avai.value="1";
	else
		document.order_form.room_avai.value="-1";
}

function clearOption(target){
	var obj = document.getElementById(target);
	while(obj.length>1){
		obj.remove(obj.length-1);
	}
}

function addOption(target,value,text){
	var obj = document.getElementById(target);
	var option = document.createElement("option");
	option.value = value;
	option.text = text;
	try{
		obj.add(option,null); // standards compliant
	}catch(ex){
		obj.add(option); // IE only
	}
}

function makePriceRequestLink(hotelid){
	var validcount = 0;
	var link = hotelid;
	link += "&checkin="+document.order_form.checkin.value;
	link += "&days="+document.order_form.days.value;

	for(i=0;i<roomtype.length;i++){
		if((parseInt(document.getElementById("quantity"+roomtype[i]).value)>0)&&(document.getElementById("market"+roomtype[i]).value)=="-1"){
			return "&error=market";
		}else{
			if(parseInt(document.getElementById("quantity"+roomtype[i]).value)>0){
				validcount++;
				link += "&market"+roomtype[i]+"="+document.getElementById("market"+roomtype[i]).value;
				link += "&quantity"+roomtype[i]+"="+document.getElementById("quantity"+roomtype[i]).value;
				link += "&bed"+roomtype[i]+"="+document.getElementById("bed"+roomtype[i]).value;
			}
		}
	}
	if(validcount)
		return link;
	else
		return "&error=rooms";
}

function submit_qs(event, com, task, stateid, locationid, keyword, star, startdate, enddate){
	if(document.getElementById("sel_keyword").value=="Hotel Name"){
		document.getElementById("sel_keyword").value="";
	}
	if(event.keyCode == 13){
		search(com, task, stateid, locationid, keyword, star, startdate, enddate);
	}
}

function search(com, task, cityid, areaid, keyword, star, startdate, enddate){
	if(keyword=="Hotel Name"){
		keyword="";
		document.getElementById("sel_keyword").value="";
	}
	if(com=="reservation"){
		html = "hotels";
	}else{
		html = "tours";
	}
	if(keyword.length!=0){
		keyword = trim(keyword).replace(/ /g,"_");
		keyword = keyword.replace(/[^a-zA-Z0-9_-]/g,"");
		keyword = keyword;
	}else{
		keyword = "nokey";
	}
	//window.location.href=window.location.protocol+"//"+window.location.hostname+"/malaysia/"+com+"/"+task+"/"+keyword+stateid+"/"+locationid+"/1/"+html+".html";
	window.location.href=window.location.protocol+"//"+window.location.hostname+"/index.php?com="+com+"&task="+task+"&cityid="+cityid+"&areaid="+areaid+"&star="+star+"&startdate="+startdate+"&enddate="+enddate+"&page=1";
}

function decide_checkout(days){
	var todaydate = new Date();
	var checkindate = new Date();
	var checkoutdate = new Date();
	checkindate.setFullYear(document.getElementById("checkin_Year_ID").value,parseInt(document.getElementById("checkin_Month_ID").value),document.getElementById("checkin_Day_ID").value);
	checkoutdate.setTime(checkindate.getTime()+parseInt(days)*86400000);
	document.getElementById("checkout_Year_ID").value=checkoutdate.getFullYear();
	document.getElementById("checkout_Month_ID").value=checkoutdate.getMonth();
	document.getElementById("checkout_Day_ID").value=checkoutdate.getDate();
	document.order_form.checkout.value=checkoutdate.getFullYear()+"-"+(checkoutdate.getMonth()+1)+"-"+checkoutdate.getDate();
	if(checkoutdate.getTime()>todaydate.getTime())
		document.getElementById("checkoutstatus").innerHTML="&nbsp;";
	else
		document.getElementById("checkoutstatus").innerHTML="Invalid check out date.";
}

function show_changepass(obj){
	if(obj.checked==true){
		document.getElementById("div_changepass").style.display="block";
	}else{
		document.getElementById("div_changepass").style.display="none";
	}
}

function show_join(obj,target){
	if(obj.checked==true)
		document.getElementById(target).style.display = "block";
	else
		document.getElementById(target).style.display = "none";
}

function change_paytype(obj){
	if(obj.value=="1"){
		document.getElementById("card_form").style.display="block";
		document.getElementById("bank_form").style.display="none";
		document.getElementById("cash_form").style.display="none";
	}else if(obj.value=="2"){
		document.getElementById("card_form").style.display="none";
		document.getElementById("bank_form").style.display="block";
		document.getElementById("cash_form").style.display="none";
	}else if(obj.value=="3"){
		document.getElementById("card_form").style.display="none";
		document.getElementById("bank_form").style.display="none";
		document.getElementById("cash_form").style.display="block";
	}else{
		document.getElementById("card_form").style.display="none";
		document.getElementById("bank_form").style.display="none";
		document.getElementById("cash_form").style.display="none";
	}
}

var smallwindow;
function newWin(link){
	smallwindow = window.open(link,'smallwindow','channelmode=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
	smallwindow.focus();
}

function changeDesc(target){
	if(target == "long"){
		document.getElementById("hotelinfo").innerHTML = fulldescription;
		document.getElementById("div_long").style.display = "none";
		document.getElementById("div_short").style.display = "block";
	}else{
		document.getElementById("hotelinfo").innerHTML = shortdescription;
		document.getElementById("div_long").style.display = "block";
		document.getElementById("div_short").style.display = "none";
	}
}

function addinsurer(){
	var obj = document.getElementById("insurance_form");
	if((obj.insurer_name.value=="") || (obj.insurer_passport.value=="") || (obj.insurer_address.value=="") || (obj.nominee_name.value=="") || (obj.nominee_passport.value=="") || (obj.nominee_address.value=="")){
		alert("Incomplete Form.");
	}else{
		addOption("list", "#"+obj.insurer_name.value+"#"+obj.insurer_passport.value+"#"+obj.insurer_address.value+"#"+obj.nominee_name.value+"#"+obj.nominee_passport.value+"#"+obj.nominee_address.value+"#", obj.insurer_name.value+" ("+obj.nominee_name.value+")");
		obj.insurer_name.value = obj.insurer_passport.value = obj.insurer_address.value = obj.nominee_name.value = obj.nominee_passport.value = obj.nominee_address.value = "";
	}
}

function removeinsurer(){
	var obj = document.getElementById("insurance_form");
	if(obj.list.selectedIndex!="-1"){
		obj.list.remove(obj.list.selectedIndex);
	}
}

function genInsList(sel){
	var name = new Array("", "insurer_name", "insurer_passport", "insurer_address", "nominee_name", "nominee_passport", "nominee_address");
	var string = '<input type="hidden" name="listcount" id="listcount" value="'+sel.length+'" />\r\n';
	for(i=0;i<sel.length;i++){
		var temp = sel.options[i].value.split("#");
		//var temp = temp.split("#");
		for(j=1;j<7;j++){
			string += '<input type="hidden" name="'+name[j]+'_'+(i+1)+'" id="'+name[j]+'_'+(i+1)+'" value="'+temp[j]+'" />\r\n';
		}
	}
	document.getElementById("div_list").innerHTML = string;
}

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function listTblSetRoom(hotelid){
	if(document.getElementById("temp"+hotelid).value){
		document.getElementById("quantity_"+document.getElementById("temp"+hotelid).value).value="0";
	}
	document.getElementById("quantity_"+document.getElementById("roomid"+hotelid).value).value = document.getElementById("quantity"+hotelid).value;
	document.getElementById("temp"+hotelid).value = document.getElementById("roomid"+hotelid).value;
}

function hotelListCheckPrice(website, hotelid){
	roomid = $('roomid'+hotelid)?$('roomid'+hotelid).value:"";
	count = $('quantity'+hotelid)?$('quantity'+hotelid).value:"";
	startdate = document.getElementsByName('startdate')[0]?document.getElementsByName('startdate')[0].value:"";
	enddate = document.getElementsByName('enddate')[0]?document.getElementsByName('enddate')[0].value:"";
	dataRequest2(website+'/index.php?com=ajax&task=loadListPrice&hotelid='+hotelid+'&roomid='+roomid+'&count='+count+'&startdate='+startdate+'&enddate='+enddate, 'price_'+hotelid);
}

function $(id){
	if(document.getElementById(id)){
		return document.getElementById(id);
	}else{
		return false;
	}
}

function login_form_check(obj){
	if(obj.login_username.value==""){
		alert("Please fill in username.");
		obj.login_username.focus();
		return false;
	} else if(obj.login_password.value==""){
		alert("Please fill in password.");
		obj.login_password.focus();
		return false;
	} else{
		return true;
	}
}

function signup_form_check(obj){
	if(trim(obj.firstname.value)==""){
		alert("Please fill in first name.");
		obj.firstname.focus();
		return false;
	} else if(trim(obj.lastname.value)==""){
		alert("Please fill in last name.");
		obj.lastname.focus();
		return false;
	} else if(obj.nationality.value=="-1"){
		alert("Please choose nationality.");
		return false;
	} else if(trim(obj.username.value)==""){
		alert("Please fill in username.");
		obj.username.focus();
		return false;
	} else if(document.getElementById("username_avai").value=="0"){
		alert("Username is not available.\nPlease fill in another username.");
		obj.username.focus();
		return false;
	} else if(obj.password.value==""){
		alert("Please fill in password.");
		obj.password.focus();
		return false;
	} else if(obj.password2.value==""){
		alert("Please retype password to verify.");
		obj.password2.focus();
		return false;
	} else if(obj.password.value!=obj.password2.value){
		alert("Password missmatch.");
		obj.password2.focus();
		return false;
	} else if(trim(obj.email.value)==""){
		alert("Please fill in email.");
		obj.email.focus();
		return false;
	} else if(!validateEmailv2(trim(obj.email.value))){
		alert("Invalid email.");
		obj.email.focus();
		return false;
	} else if(trim(obj.contact.value)==""){
		alert("Please fill in contact number.");
		obj.contact.focus();
		return false;
	} else if(trim(obj.address.value)==""){
		alert("Please fill in corresponding address.");
		obj.address.focus();
		return false;
	} else if(trim(obj.city.value)==""){
		alert("Please fill in city.");
		obj.city.focus();
		return false;
	} else if(trim(obj.postcode.value)==""){
		alert("Please fill in postal code.");
		obj.postcode.focus();
		return false;
	} else if(trim(obj.state.value)==""){
		alert("Please fill in state.");
		obj.state.focus();
		return false;
	} else if(obj.country.value=="-1"){
		alert("Please select a country.");
		return false;
	} else{
		return true;
	}
}

function asignup_form_check(obj){
	if(trim(obj.firstname.value)==""){
		alert("Please fill in first name.");
		obj.firstname.focus();
		return false;
	} else if(trim(obj.lastname.value)==""){
		alert("Please fill in last name.");
		obj.lastname.focus();
		return false;
	} else if(obj.nationality.value=="-1"){
		alert("Please choose nationality.");
		return false;
	} else if(trim(obj.username.value)==""){
		alert("Please fill in username.");
		obj.username.focus();
		return false;
	} else if(document.getElementById("username_avai").value=="0"){
		alert("Username is not available.\nPlease fill in another username.");
		obj.username.focus();
		return false;
	} else if(obj.password.value==""){
		alert("Please fill in password.");
		obj.password.focus();
		return false;
	} else if(obj.password2.value==""){
		alert("Please retype password to verify.");
		obj.password2.focus();
		return false;
	} else if(obj.password.value!=obj.password2.value){
		alert("Password missmatch.");
		obj.password2.focus();
		return false;
	} else if(trim(obj.email.value)==""){
		alert("Please fill in email.");
		obj.email.focus();
		return false;
	} else if(!validateEmailv2(trim(obj.email.value))){
		alert("Invalid email.");
		obj.email.focus();
		return false;
	} else if(trim(obj.contact.value)==""){
		alert("Please fill in contact number.");
		obj.contact.focus();
		return false;
	} else if(trim(obj.address.value)==""){
		alert("Please fill in corresponding address.");
		obj.address.focus();
		return false;
	} else if(trim(obj.city.value)==""){
		alert("Please fill in city.");
		obj.city.focus();
		return false;
	} else if(trim(obj.postcode.value)==""){
		alert("Please fill in postal code.");
		obj.postcode.focus();
		return false;
	} else if(trim(obj.state.value)==""){
		alert("Please fill in state.");
		obj.state.focus();
		return false;
	} else if(obj.country.value=="-1"){
		alert("Please select a country.");
		return false;
	} else if(obj.companyname.value==""){
		alert("Please fill in company name.");
		return false;
	} else{
		return true;
	}
}

function edit_form_check(obj){
	if(trim(obj.firstname.value)==""){
		alert("Please fill in first name.");
		obj.firstname.focus();
		return false;
	} else if(trim(obj.lastname.value)==""){
		alert("Please fill in last name.");
		obj.lastname.focus();
		return false;
	} else if(obj.nationality.value=="-1"){
		alert("Please choose nationality.");
		return false;
	} else if(trim(obj.username.value)==""){
		alert("Please fill in username.");
		obj.username.focus();
		return false;
	} else if(document.getElementById("username_avai").value=="0"){
		alert("Username is not available.\nPlease fill in another username.");
		obj.username.focus();
		return false;
	} else if((obj.changepass.checked==true)&&(obj.old_password.value=="")){
		alert("Please fill in old password.");
		obj.old_password.focus();
		return false;
	} else if((obj.changepass.checked==true)&&(obj.new_password.value=="")){
		alert("Please fill in new password.");
		obj.new_password.focus();
		return false;
	} else if((obj.changepass.checked==true)&&(obj.new_password2.value=="")){
		alert("Please retype password to verify.");
		obj.new_password2.focus();
		return false;
	} else if((obj.changepass.checked==true)&&(obj.new_password.value!=obj.new_password2.value)){
		alert("Password missmatch.");
		obj.new_password2.focus();
		return false;
	} else if(trim(obj.email.value)==""){
		alert("Please fill in email.");
		obj.email.focus();
		return false;
	} else if(!validateEmailv2(trim(obj.email.value))){
		alert("Invalid email.");
		obj.email.focus();
		return false;
	} else if(trim(obj.contact.value)==""){
		alert("Please fill in contact number.");
		obj.contact.focus();
		return false;
	} else if(trim(obj.address.value)==""){
		alert("Please fill in corresponding address.");
		obj.address.focus();
		return false;
	} else if(trim(obj.city.value)==""){
		alert("Please fill in city.");
		obj.city.focus();
		return false;
	} else if(trim(obj.postcode.value)==""){
		alert("Please fill in postal code.");
		obj.postcode.focus();
		return false;
	} else if(trim(obj.state.value)==""){
		alert("Please fill in state.");
		obj.state.focus();
		return false;
	} else if(obj.country.value=="-1"){
		alert("Please select a country.");
		return false;
	} else{
		return true;
	}
}

function order_form_check(obj){
	if(obj.validdatein.value!="1"){
		alert(obj.validdatein.value);
		return false;
	}else if(obj.validdateout.value!="1"){
		alert(obj.validdateout.value);
		return false;
	}else if(check_roomselect()!=""){
		alert(check_roomselect());
		return false;
	}else if(obj.room_avai.value=="0"){
		alert("Please check room price.");
		return false;
	}else if(obj.room_avai.value=="-1"){
		alert("Rooms are not available on selected date.");
		return false;
	}else if(trim(obj.firstname.value)==""){
		alert("Please fill in first name.");
		obj.firstname.focus();
		return false;
	}else if(trim(obj.lastname.value)==""){
		alert("Please fill in last name.");
		obj.lastname.focus();
		return false;
	}else if(trim(obj.contactno.value)==""){
		alert("Please fill in contact number.");
		obj.contactno.focus();
		return false;
	}else if(trim(obj.email.value)==""){
		alert("Please fill in email.");
		obj.email.focus();
		return false;
	}else if(!validateEmailv2(trim(obj.email.value))){
		alert("Invalid email.");
		obj.email.focus();
		return false;
	}else if(obj.nationality.value=="-1"){
		alert("Please select nationality.");
		return false;
	}else if(trim(obj.passport.value)==""){
		alert("Please fill in passport.");
		obj.passport.focus();
		return false;
	}else if(trim(obj.address.value)==""){
		alert("Please fill in address.");
		obj.address.focus();
		return false;
	}else if(trim(obj.city.value)==""){
		alert("Please fill in city.");
		obj.city.focus();
		return false;
	}else if(trim(obj.zip.value)==""){
		alert("Please fill in postal code.");
		obj.zip.focus();
		return false;
	}else if(trim(obj.state.value)==""){
		alert("Please fill in state.");
		obj.state.focus();
		return false;
	}else if(obj.country.value=="-1"){
		alert("Please select country.");
		return false;
	}else if(obj.payment_method.value=="-1"){
		alert("Please select payment method.");
		return false;
	}else if((obj.payment_method.value=="1")&&(obj.cardtype.value=="-1")){
		alert("Please select card type.");
		return false;
	}else if((obj.payment_method.value=="1")&&(trim(obj.cardname.value)=="")){
		alert("Please fill in name on card.");
		obj.cardname.focus();
		return false;
	}else if((obj.payment_method.value=="1")&&(trim(obj.cardno.value)=="")){
		alert("Please fill in card number.");
		obj.cardno.focus();
		return false;
	}else if((obj.payment_method.value=="1")&&(trim(obj.cvv.value)=="")){
		alert("Please fill in cvv.");
		obj.cvv.focus();
		return false;
	}else if((obj.payment_method.value=="1")&&(obj.expirymonth.value=="-1")){
		alert("Please select expiry month.");
		return false;
	}else if((obj.payment_method.value=="1")&&(obj.expiryyear.value=="-1")){
		alert("Please select expiry year.");
		return false;
	}else if((obj.payment_method.value=="2")&&(trim(obj.bankname.value)=="")){
		alert("Please fill in bank.");
		obj.bankname.focus();
		return false;
	}else if((obj.payment_method.value=="2")&&(trim(obj.bankno.value)=="")){
		alert("Please fill in bank account number.");
		obj.bankno.focus();
		return false;
	}else if(obj.tnc.checked==false){
		alert("Please check the terms & condition.");
		return false;
	}else if((obj.join.checked)&&(trim(obj.order_username.value)=="")){
		alert("Please fill in user name.");
		obj.order_username.focus();
		return false;
	}else if((obj.join.checked)&&(obj.username_avai.value=="0")){
		alert("Please check username availability.");
		obj.order_username.focus();
		return false;
	}else if((obj.join.checked)&&(trim(obj.order_password.value)=="")){
		alert("Please fill in password.");
		obj.order_password.focus();
		return false;
	}else if((obj.join.checked)&&(trim(obj.order_password2.value)=="")){
		alert("Please retype password to verify.");
		obj.order_password2.focus();
		return false;
	}else if(trim(obj.order_password.value)!=trim(obj.order_password2.value)){
		alert("Password missmatch.");
		obj.order_password2.focus();
		return false;
	}else{
		return true;
	}
}

function tour_form_check(obj){
	if(trim(obj.firstname.value)==""){
		alert("Please fill in first name.");
		obj.firstname.focus();
		return false;
	}else if(trim(obj.lastname.value)==""){
		alert("Please fill in last name.");
		obj.lastname.focus();
		return false;
	}else if(trim(obj.contactno.value)==""){
		alert("Please fill in contact number.");
		obj.contactno.focus();
		return false;
	}else if(trim(obj.email.value)==""){
		alert("Please fill in email.");
		obj.email.focus();
		return false;
	}else if(!validateEmailv2(trim(obj.email.value))){
		alert("Invalid email.");
		obj.email.focus;
		return false;
	}else if(obj.nationality.value=="-1"){
		alert("Please select nationality.");
		return false;
	}else if(trim(obj.passport.value)==""){
		alert("Please fill in passport.");
		obj.passport.focus();
		return false;
	}else if(trim(obj.address.value)==""){
		alert("Please fill in address.");
		obj.address.focus();
		return false;
	}else if(trim(obj.city.value)==""){
		alert("Please fill in city.");
		obj.city.focus();
		return false;
	}else if(trim(obj.zip.value)==""){
		alert("Please fill in postal code.");
		obj.zip.focus();
		return false;
	}else if(trim(obj.state.value)==""){
		alert("Please fill in state.");
		obj.state.focus();
		return false;
	}else if(obj.country.value=="-1"){
		alert("Please select country.");
		return false;
	}else if(trim(obj.pickup.value)==""){
		alert("Plese fill in hotel name / location.");
		obj.pickup.focus();
		return false;
	}else if(trim(obj.local_contact.value)==""){
		alert("Please fill in local contact.");
		obj.local_contact.focus();
		return false;
	}else if(obj.payment_method.value=="-1"){
		alert("Please select payment method.");
		return false;
	}else if((obj.payment_method.value=="1")&&(obj.cardtype.value=="-1")){
		alert("Please select card type.");
		return false;
	}else if((obj.payment_method.value=="1")&&(trim(obj.cardname.value)=="")){
		alert("Please fill in name on card.");
		obj.cardname.focus();
		return false;
	}else if((obj.payment_method.value=="1")&&(trim(obj.cardno.value)=="")){
		alert("Please fill in card number.");
		obj.cardno.focus();
		return false;
	}else if((obj.payment_method.value=="1")&&(trim(obj.cvv.value)=="")){
		alert("Please fill in cvv.");
		obj.cvv.focus();
		return false;
	}else if((obj.payment_method.value=="1")&&(obj.expirymonth.value=="-1")){
		alert("Please select expiry month.");
		return false;
	}else if((obj.payment_method.value=="1")&&(obj.expiryyear.value=="-1")){
		alert("Please select expiry year.");
		return false;
	}else if((obj.payment_method.value=="2")&&(trim(obj.bankname.value)=="")){
		alert("Please fill in bank.");
		obj.bankname.focus();
		return false;
	}else if((obj.payment_method.value=="2")&&(trim(obj.bankno.value)=="")){
		alert("Please fill in bank account number.");
		obj.bankno.focus();
		return false;
	}else if((obj.join.checked)&&(trim(obj.order_username.value)=="")){
		alert("Please fill in user name.");
		obj.order_username.focus();
		return false;
	}else if((obj.join.checked)&&(obj.username_avai.value=="0")){
		alert("Please check username availability.");
		obj.order_username.focus();
		return false;
	}else if((obj.join.checked)&&(trim(obj.order_password.value)=="")){
		alert("Please fill in password.");
		obj.order_password.focus();
		return false;
	}else if((obj.join.checked)&&(trim(obj.order_password2.value)=="")){
		alert("Please retype password to verify.");
		obj.order_password2.focus();
		return false;
	}else if(trim(obj.order_password.value)!=trim(obj.order_password2.value)){
		alert("Password missmatch.");
		obj.order_password2.focus();
		return false;
	}else{
		return true;
	}
}

function insurance_form_check(obj){
	if(obj.list.length<1){
		alert("Please add in insurer and nominee.");
		return false;
	}else if(obj.payment_method.value=="-1"){
		alert("Please select payment method.");
		return false;
	}else if((obj.payment_method.value=="1")&&(obj.cardtype.value=="-1")){
		alert("Please select card type.");
		return false;
	}else if((obj.payment_method.value=="1")&&(trim(obj.cardname.value)=="")){
		alert("Please fill in name on card.");
		obj.cardname.focus();
		return false;
	}else if((obj.payment_method.value=="1")&&(trim(obj.cardno.value)=="")){
		alert("Please fill in card number.");
		obj.cardno.focus();
		return false;
	}else if((obj.payment_method.value=="1")&&(trim(obj.cvv.value)=="")){
		alert("Please fill in cvv.");
		obj.cvv.focus();
		return false;
	}else if((obj.payment_method.value=="1")&&(obj.expirymonth.value=="-1")){
		alert("Please select expiry month.");
		return false;
	}else if((obj.payment_method.value=="1")&&(obj.expiryyear.value=="-1")){
		alert("Please select expiry year.");
		return false;
	}else if((obj.payment_method.value=="2")&&(trim(obj.bankname.value)=="")){
		alert("Please fill in bank.");
		obj.bankname.focus();
		return false;
	}else if((obj.payment_method.value=="2")&&(trim(obj.bankno.value)=="")){
		alert("Please fill in bank account number.");
		obj.bankno.focus();
		return false;
	}else{
		genInsList(obj.list);
		return true;
	}
}

function check_roomselect(){
	var roomcount = 0;
	for(i=0;i<roomtype.length;i++){
		//alert(document.getElementById("quantity"+roomtype[i]).value+":"+document.getElementById("market"+roomtype[i]).value);
		roomcount += parseInt(document.getElementById("quantity"+roomtype[i]).value);
		if((parseInt(document.getElementById("quantity"+roomtype[i]).value)>=1)&&(document.getElementById("market"+roomtype[i]).value=="-1")){
			return "Please select market.";
		}
	}
	if(roomcount<=0)
		return "Please select roomtype and number of room.";
	else
		return "";
}

function showthis(obj,target){
	document.getElementById(document.getElementById("curr_span").value).style.display = "none";
	document.getElementById(target).style.display = "block";
	document.getElementById(document.getElementById("curr_span").value+"_cat").style.background = "#c0e2fb";
	document.getElementById(document.getElementById("curr_span").value+"_cat").style.color = "";
	document.getElementById("curr_span").value = target;
	document.getElementById(document.getElementById("curr_span").value+"_cat").style.background = "#1677d6";
	document.getElementById(document.getElementById("curr_span").value+"_cat").style.color = "#FFFFFF";
}

function search_for_action(form,action){
	document.getElementById(form).action = "index.php?com="+action+"&task=quick";
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}
