var Path;
function memberlogin(Page){
	if($("txtemail")&&$("txtemail").value!=""&&$("txtpassword").value!=""){
		var txtemail = $("txtemail").value;
		var txtpassword = $("txtpassword").value;
		var url=($("mode") && $("mode").value == 'CMS') ? "../reservation/member/memberloginconnect.php" : "member/memberloginconnect.php";
		var param="txtemail="+$("txtemail").value;
		param+="&txtpassword="+$("txtpassword").value;
		param+="&txthotelcode="+$("txthotelcode").value;
		if ($("mode") && $("mode").value == 'CMS')
		{
			param+="&mode="+$("mode").value;
		}
		var http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var myText=http.responseText;
			if(myText==1){
				if ($("mode") && $("mode").value == 'CMS')
				{
					if (Page == 'reviewpost')
					{
						window.location.reload();
					}
					else
					{
						window.open("/en/reservation/mybookingviewlist.php","_self");
					}
				}
				else
				{
					window.location.reload();
				}
			}else{
				alert(myText);
			}
		};
		http.open("POST", url, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(param+"&"+new Date().getTime());
	}else{
		alert("Please insert e-mail & password");
	}
}
function agentlogin(){
	if($("txtagentid") && $("txtagentid").value!="" && $("txtagentusername").value!="" && $("txtagentpassword").value!=""){
		var txtagentid = $("txtagentid").value;
		var txtagentusername = $("txtagentusername").value;
		var txtagentpassword = $("txtagentpassword").value;
		var url=($("mode") && $("mode").value == 'CMS') ? "../reservation/member/agentloginconnect.php" : "member/agentloginconnect.php";
		var hotelcode = ($("txthotelcode")&&$("txthotelcode").value!="") ? $("txthotelcode").value : hs.myDefault.sHotel;
		var param="txtagentid="+$("txtagentid").value;
		param+="&txtagentusername="+$("txtagentusername").value;
		param+="&txtagentpassword="+$("txtagentpassword").value;
		param+="&txthotelcode="+hotelcode;
		if ($("mode") && $("mode").value == 'CMS')
		{
			param+="&mode="+$("mode").value;
		}
		var http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var myText=http.responseText;
			if(myText==1){
				if ($("mode") && $("mode").value == 'CMS')
				{
					window.open("/en/reservation/search.php?login=1","_self");
				}
				else
				{
					window.location.reload();
				}
			}else{
				alert("Please login again");
			}
		};
		http.open("POST", url, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(param+"&"+new Date().getTime());
	}else{
		alert("Please insert agentid, username & password");
	}
}
function logout(hotelname){
	if(Path=="3"){
		var url="logout.php";
	}else{
		var url="member/logout.php";
	}
	var http = new getXMLHTTPRequest();
	http.onreadystatechange = function() {if (http.readyState != 4) { return; }
		var myText=http.responseText;
		if(Path=="3"){
			window.open("../search.php?HotelName="+hotelname,"_self");
		}else{
			window.open("search.php?HotelName="+hotelname,"_self");
		}
	};
	http.open("POST", url, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send("&"+new Date().getTime());
}
function isemail(string){
	chkMail=string.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) ;
	if(chkMail==-1){
		alert("You have entered an invalid email address. Please try again.");
		string.focus();
		string.value="";
	}
	return(chkMail);
}
function memberforgotpassword(){
	if($("txtemailforgot") && $("txtemailforgot").value!=""){
		if(isemail($("txtemailforgot"))==0){
			var url="member/memberforgotpassword.php";
			var param="Email="+$("txtemailforgot").value;
			param+="&HotelCode="+hs.myDefault.sHotel;
			var http = new getXMLHTTPRequest();
			http.onreadystatechange = function() {if (http.readyState != 4) { return; }
				var mytext=http.responseText;
				gendiv(mytext);
				if($("txtforgotchk").value==1){
					alert("Your username and password send to you email complete.");
				}else{
					alert("This email not have data.Please try again.");
				}
			};
			http.open("POST", url, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			http.send(param+"&"+new Date().getTime());
		}
	}else{
		alert("Please fill up Email !");
	}
}
function dropcity(obj){
	if(Path=="3"){
		var url="dropcity.php";
	}else{
		var url="member/dropcity.php";
	}
	var param="CountryCode="+obj.value;
	var http = new getXMLHTTPRequest();
	http.onreadystatechange = function() {if (http.readyState != 4) { return; }
		var mytext = http.responseXML;
		$("cboCity").length = 1;
		var obj = mytext.getElementsByTagName("Code");
		for(i=0; i<obj.length; i+=1){
			var data = obj[i];
			var Code = data.firstChild.nodeValue;
			var LongName = mytext.getElementsByTagName("LongName")[i].firstChild.nodeValue;
			var objOption = new Option(LongName, Code);
			$("cboCity").options[i] = objOption;
		}
		if($("CityCode")) $("cboCity").value=$("CityCode").value;
	};
	http.open("POST", url, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send(param+"&"+new Date().getTime());
}
function ctlPf(act){
	$("lyViewProfile").style.display="none";
	$("lyEditProfile").style.display="none";
	$("lyChangePassword").style.display="none";
	$("ly"+act).style.display="";
}
function gendiv(mytext){
	var locate=document.location.href;
	var div = document.createElement("div");
	div.id="Debug";
	div.style.display="none";
	if(locate.indexOf("debug=1") != -1){
		div.style.display="";
	}
	if(! $(div.id)) document.body.appendChild(div);
	if($(div.id))$(div.id).innerHTML=mytext;
}
function Member(PathData,Mode){
	Path=PathData+"Mode="+Mode+"&";
	var myurl = "member/member.php", http = new getXMLHTTPRequest();
	http.onreadystatechange = function() {if (http.readyState != 4) { return; }
		var locate=document.location.href;
		var div = document.createElement("div");
		div.id="Debug";
		div.style.display="none";
		if(locate.indexOf("debug=1") != -1){
			div.style.display="";
		}
		if(! $(div.id)) document.body.appendChild(div);
		mytext=http.responseText;
		gendiv(mytext);
		switch(Mode){
			case "DETAIL" :
				if($("Code")){
					if($("Code").value == "" ){
						window.open("search.php","_self");
					}else{
						if($("sPrefix")) $("sPrefix").innerHTML=$("PrefixName").value+"&nbsp;";
						if($("sFirstName")) $("sFirstName").innerHTML=$("Name").value+"&nbsp;";
						if($("sLastName")) $("sLastName").innerHTML=$("Surname").value+"&nbsp;";
						if($("sEmail")) $("sEmail").innerHTML=$("Email").value+"&nbsp;";
						if($("sNationality")) $("sNationality").innerHTML=$("NationalityName").value+"&nbsp;";
						if($("sNationalityCode")) $("sNationalityCode").innerHTML=$("NationalityCode").value+"&nbsp;";
						if($("sAddress")) $("sAddress").innerHTML=$("Address1").value+", "+$("Address2").value+", "+$("Address3").value+"&nbsp;";
//						if($("sState")) $("sState").innerHTML=$("State").value+"&nbsp;";
						if($("sCountry")) $("sCountry").innerHTML=$("CountryName").value+"&nbsp;";
						if($("sCity")) $("sCity").innerHTML=$("CityName").value+"&nbsp;";
						if($("sZip")) $("sZip").innerHTML=$("Zipcode").value+"&nbsp;";
						if($("sPhone")) $("sPhone").innerHTML=$("Telno").value+"&nbsp;";
						if($("sMobile")) $("sMobile").innerHTML=$("Mobileno").value+"&nbsp;";
						if($("cboPrefix")) $("cboPrefix").value=$("PrefixCode").value;
						if($("txtFirstName")) $("txtFirstName").value=$("Name").value;
						if($("txtLastName")) $("txtLastName").value=$("Surname").value;
						if($("txtEmail")) $("txtEmail").value=$("Email").value;
						if($("cboNationality")) $("cboNationality").value=$("NationalityCode").value;
						if($("txtAddress1")) $("txtAddress1").value=$("Address1").value;
						if($("txtAddress2")) $("txtAddress2").value=$("Address2").value;
						if($("txtAddress3")) $("txtAddress3").value=$("Address3").value;
//						if($("txtState")) $("txtState").value=$("State").value;
						if($("cboCountry")) $("cboCountry").value=$("CountryCode").value;
						if($("cboCountry")) dropcity($("cboCountry"));
						if($("txtZipCode")) $("txtZipCode").value=$("Zipcode").value;
						if($("txtPhone")) $("txtPhone").value=$("Telno").value;
						if($("txtMobile")) $("txtMobile").value=$("Mobileno").value;
					}
				}else{
					window.open("search.php","_self");
				}
				break;
		}
	};
	http.open("POST", myurl, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send(Path+new Date().getTime());
}
function ChangePassword(){
	$txtOldPass=$("txtOldPass").value;
	$txtNewPass=$("txtNewPass").value;
	$txtPassCon=$("txtPassCon").value;
	if($txtOldPass=="" || $txtOldPass.length < 6){ alert("Please Insert Current Password 6-12 characters"); $("errOldPass").focus(); }else
	if($txtNewPass=="" || $txtNewPass.length < 6){ alert("Please Insert New Password 6-12 characters"); $("txtNewPass").focus(); }else
	if($txtPassCon != $txtNewPass){
		alert("Retype Again");
		$("txtPassCon").focus();
	}else{
		FileChangePassword();
	}
}
function FileChangePassword(){
	var myurl = "memberchangepassword.php", http = new getXMLHTTPRequest();
	http.onreadystatechange = function() {if (http.readyState != 4) { return; }
		var mytext = http.responseText;
		$("DataChangePassword").innerHTML=mytext;
		if($("ChangeValue").value==1){
			alert("Change Password Complete");
			window.location.reload();
		}else{
			alert("Can not change password. Please try again.");
		}
	};
	http.open("POST", myurl, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send("PfUserCode="+$("PfUserCode").value+"&txtOldPass="+$("txtOldPass").value+"&txtNewPass="+$("txtNewPass").value+"&txtPassCon="+$("txtPassCon").value+"&"+new Date().getTime());
}
function ChangeProfile(){
	var Code=$("Code").value;
	var PfUserCode=$("PfUserCode").value;
	var cboPrefix=$("cboPrefix").value;
	var txtFirstName=$("txtFirstName").value;
	var txtLastName=$("txtLastName").value;
	var txtEmail=$("txtEmail").value;
	var cboNationality=$("cboNationality").value;
	var txtAddress1=$("txtAddress1").value;
	var txtAddress2=$("txtAddress2").value;
	var txtAddress3=$("txtAddress3").value;
//	var txtState=$("txtState").value;
	var cboCountry=$("cboCountry").value;
	var cboCity=$("cboCity").value;
	var txtZipCode=$("txtZipCode").value;
	var txtPhone=$("txtPhone").value;
	var txtMobile=$("txtMobile").value;
	var txtHotelCode=$("txtHotelCode").value;

	//Check error=========
	if(cboPrefix=="" || cboPrefix == "NONE"){ alert("Please fill up Title."); $("cboPrefix").focus(); }else
	if(txtFirstName==""){ alert("Please fill up First name."); $("txtFirstName").focus(); }else
	if(txtLastName==""){ alert("Please fill up Surname."); $("txtLastName").focus(); }else
	if(txtEmail==""){ alert("Please fill up E-mail."); $("txtEmail").focus(); }else
	if(cboNationality=="" || cboNationality=="NONE"){ alert("Please fill up Nationality."); $("cboNationality").focus(); }else
	if(txtAddress1==""){ alert("Please fill up Address 1."); $("txtAddress1").focus(); }else
//	if(txtState==""){ alert("Please fill up State."); $("txtState").focus(); }else
	if(cboCountry=="" || cboCountry=="NONE"){ alert("Please fill up Country."); $("cboCountry").focus(); }else
	if(cboCity=="" || cboCity=="NONE"){ alert("Please fill up City."); $("cboCity").focus(); }else
	if(txtZipCode==""){ alert("Please fill up Zip / Postal Code."); $("txtZipCode").focus(); }else
	if(txtMobile==""){ alert("Please fill up Mobile Number."); $("txtMobile").focus(); }else
	{
		Path="Code="+Code+"&";
		Path+="PfUserCode="+PfUserCode+"&";
		Path+="cboPrefix="+cboPrefix+"&";
		Path+="txtFirstName="+txtFirstName+"&";
		Path+="txtLastName="+txtLastName+"&";
		Path+="txtEmail="+txtEmail+"&";
		Path+="cboNationality="+cboNationality+"&";
		Path+="txtAddress1="+txtAddress1+"&";
		Path+="txtAddress2="+txtAddress2+"&";
		Path+="txtAddress3="+txtAddress3+"&";
//		Path+="txtState="+txtState+"&";
		Path+="cboCountry="+cboCountry+"&";
		Path+="cboCity="+cboCity+"&";
		Path+="txtZipCode="+txtZipCode+"&";
		Path+="txtPhone="+txtPhone+"&";
		Path+="txtMobile="+txtMobile+"&";
		Path+="txtHotelCode="+txtHotelCode+"&";
		var myurl = "member/membereditprofile.php", http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			if(mytext=="complete"){
				alert("Change Profile Complete");
				window.location.reload();
			}else{
				alert("Can not change email. Please try again.");
			}
		}
		http.open("POST", myurl, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(Path+"&"+new Date().getTime());
	}
}
function MemberRegister(){
	var cboPrefix=$("cboPrefix").value;
	var txtFirstName=$("txtFirstName").value;
	var txtLastName=$("txtLastName").value;
	var txtEmail=$("txtEmail").value;
	var cboNationality=$("cboNationality").value;
	var txtAddress1=$("txtAddress1").value;
	var txtAddress2=$("txtAddress2").value;
	var cboCountry=$("cboCountry").value;
	var cboCity=$("cboCity").value;
	var txtZipCode=$("txtZipCode").value;
	var txtPhone=$("txtPhone").value;
	var txtMobile=$("txtMobile").value;

	if(cboPrefix=="" || cboPrefix == "NONE"){ alert("Please fill up Title."); $("cboPrefix").focus(); }else
	if(txtFirstName==""){ alert("Please fill up First name."); $("txtFirstName").focus(); }else
	if(txtLastName==""){ alert("Please fill up Surname."); $("txtLastName").focus(); }else
	if(txtEmail==""){ alert("Please fill up E-mail."); $("txtEmail").focus(); }else
	if(cboNationality=="" || cboNationality=="NONE"){ alert("Please fill up Nationality."); $("cboNationality").focus(); }else
	if(txtAddress1==""){ alert("Please fill up Address 1."); $("txtAddress1").focus(); }else
	if(cboCountry=="" || cboCountry=="NONE"){ alert("Please fill up Country."); $("cboCountry").focus(); }else
	if(cboCity=="" || cboCity=="NONE"){ alert("Please fill up City."); $("cboCity").focus(); }else
	if(txtZipCode==""){ alert("Please fill up Zip / Postal Code."); $("txtZipCode").focus(); }else
	if(txtPhone==""){ alert("Please fill up Phone Number."); $("txtPhone").focus(); }else
	if(txtMobile==""){ alert("Please fill up Mobile Number."); $("txtMobile").focus(); }else
	{
		Path="cboPrefix="+cboPrefix+"&";
		Path+="txtFirstName="+txtFirstName+"&";
		Path+="txtLastName="+txtLastName+"&";
		Path+="txtEmail="+txtEmail+"&";
		Path+="cboNationality="+cboNationality+"&";
		Path+="txtAddress1="+txtAddress1+"&";
		Path+="txtAddress2="+txtAddress2+"&";
		Path+="cboCountry="+cboCountry+"&";
		Path+="cboCity="+cboCity+"&";
		Path+="txtZipCode="+txtZipCode+"&";
		Path+="txtPhone="+txtPhone+"&";
		Path+="txtMobile="+txtMobile+"&";
		var myurl = "member/memberregister.php", http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			if (mytext=="uncomplete"){
				alert("Price not available for your nationality. Please kindly contact us!");
			}else if(mytext=="complete"){
				document.form1.submit();
			}else{
				alert("Username duplicate");
			}
		}
		http.open("POST", myurl, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(Path+"&"+new Date().getTime());
	}
}
function swapmemberandagent(strType){
	if(strType=="member"){
		$("lymember").style.display = "";
		$("lyagent").style.display = "none";
	}else{
		$("lymember").style.display = "none";
		$("lyagent").style.display = "";
	}
}
