function Agree(){ $("Submit").disabled=($("Submit").disabled)?false:true; };
function AccNews(){ $("ActiveNews").value=($("ActiveNews").value=="Y")?"N":"Y"; };

function MemberRegister(){
		//Get value==========
		var txtUsername=$("txtUsername").value;
		var txtPassword=$("txtPassword").value;
		var txtPassword2=$("txtPassword2").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 txtFAX=$("txtFAX").value;
		var ActiveNews=$("ActiveNews").value;

		//Hide error==========
		$("errUsername").style.display="none";
		$("errPassword").style.display="none";
		$("errPassword2").style.display="none";
		$("errPrefix").style.display="none";
		$("errFirstName").style.display="none";
		$("errLastName").style.display="none";
		$("errEmail").style.display="none";
		$("errNationality").style.display="none";
		$("errAddress1").style.display="none";
		$("errCountry").style.display="none";
		$("errCity").style.display="none";
		$("errZipCode").style.display="none";
		$("errPhone").style.display="none";
		$("errMobile").style.display="none";

		//Check error=========
		if(txtUsername=="" || txtUsername.length < 6){ $("errUsername").style.display=""; $("txtUsername").focus(); }else
		if(txtPassword=="" || txtPassword.length < 6){ $("errPassword").style.display=""; $("txtPassword").focus(); }else
		if(txtPassword !=txtPassword2){ $("errPassword2").style.display=""; $("txtPassword").focus(); }else
		if(cboPrefix=="" || cboPrefix == "NONE"){ $("errPrefix").style.display=""; $("cboPrefix").focus(); }else
		if(txtFirstName==""){ $("errFirstName").style.display=""; $("txtFirstName").focus(); }else
		if(txtLastName==""){ $("errLastName").style.display=""; $("txtLastName").focus(); }else
		if(txtEmail==""){ $("errEmail").style.display=""; $("txtEmail").focus(); }else
		if(cboNationality=="" || cboNationality=="NONE"){ $("errNationality").style.display=""; $("cboNationality").focus(); }else
		if(txtAddress1==""){ $("errAddress1").style.display=""; $("txtAddress1").focus(); }else
		if(cboCountry=="" || cboCountry=="NONE"){ $("errCountry").style.display=""; $("cboCountry").focus(); }else
		if(cboCity=="" || cboCity=="NONE"){ $("errCity").style.display=""; $("cboCity").focus(); }else
		if(txtZipCode==""){ $("errZipCode").style.display=""; $("txtState").focus(); }else
		if(txtPhone==""){ $("errPhone").style.display=""; $("txtPhone").focus(); }else
		if(txtMobile==""){ $("errMobile").style.display=""; $("txtMobile").focus(); }else
		{
			Mode="REGISTERCHECK";
			Path="txtUsername="+txtUsername+"&";
			Path+="txtPassword="+txtPassword+"&";
			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+="txtFAX="+txtFAX+"&";
			Path+="ActiveNews="+ActiveNews+"&";
			var myurl = "../Member/MemberRegister.php", http = new getXMLHTTPRequest();
			http.onreadystatechange = function() {if (http.readyState != 4) { return; }
				var mytext = http.responseText;
				$("sMemberLogin").innerHTML=mytext;
				if($("MemCode")){
					if($("MemCode").value != ""){
						$("txtLoginUsername").value=$("txtUsername").value;
						$("txtLoginPassword").value=$("txtPassword").value;
						TravFlex.login (); 
					}else{
						alert("You username or email is dupicate. Please try again.");
					}
				}else{
						alert("You username or email is dupicate. Please try again.");
				}
			}
			http.open("POST", myurl, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			http.send(Path+"&"+new Date().getTime());
	}
}

function DropCity(ObjCo,CityCode){
	var myurl = "../Member/dropcity.php", 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;}
	};
	http.open("POST", myurl, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send("CountryCode="+ObjCo.value+"&"+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 ShowMRegis(){
	if($("content-memberregis")){ $("content-memberregis").style.display=($("content-memberregis").style.display=="")?"none":""; }
	if($("c-rg-member")){ $("c-rg-member").style.display=($("c-rg-member").style.display=="")?"none":""; }
}
function MemberProfile(){
	var myurl = "../Member/MemberProfile.php", http = new getXMLHTTPRequest();
	http.onreadystatechange = function() {if (http.readyState != 4) { return; }
		var mytext = http.responseText;
		if($("sMemberProfile")){ 
			$("sMemberProfile").innerHTML = mytext; 
			if($("sUsername")) $("sUsername").innerHTML=$("UserName").value+"&nbsp;";
			if($("sPrefix")) $("sPrefix").innerHTML=$("PrefixName").value+"&nbsp;";
			if($("cboPrefix")) $("cboPrefix").value=$("PrefixCode").value;
			if($("sFirstName")) $("sFirstName").innerHTML=$("Name").value+"&nbsp;";
			if($("txtFirstName")) $("txtFirstName").value=$("Name").value;
			if($("sLastName")) $("sLastName").innerHTML=$("Surname").value+"&nbsp;";
			if($("txtLastName")) $("txtLastName").value=$("Surname").value;
			if($("sEmail")) $("sEmail").innerHTML=$("Email").value+"&nbsp;";
			if($("txtEmail")) $("txtEmail").value=$("Email").value;
			if($("sPhone")) $("sPhone").innerHTML=$("Telno").value+"&nbsp;";
			if($("txtPhone")) $("txtPhone").value=$("Telno").value;
			if($("sMobile")) $("sMobile").innerHTML=$("Mobileno").value+"&nbsp;";
			if($("txtMobile")) $("txtMobile").value=$("Mobileno").value;
			if($("sNationality")) $("sNationality").innerHTML=$("NationalityName").value+"&nbsp;";
			if($("cboNationality")) $("cboNationality").value=$("NationalityCode").value;
			if($("sAddress1")) $("sAddress1").innerHTML=$("Address1").value+"&nbsp;";
			if($("txtAddress1")) $("txtAddress1").value=$("Address1").value;
			if($("sAddress2")) $("sAddress2").innerHTML=$("Address2").value+"&nbsp;";
			if($("txtAddress2")) $("txtAddress2").value=$("Address2").value;
			if($("sAddress3")) $("sAddress3").innerHTML=$("Address3").value+"&nbsp;";
			if($("txtAddress3")) $("txtAddress3").value=$("Address3").value;
			if($("sState")) $("sState").innerHTML=$("State").value+"&nbsp;";
			if($("txtState")) $("txtState").value=$("State").value;
			if($("sCountry")) $("sCountry").innerHTML=$("CountryName").value+"&nbsp;";
			if($("cboCountry")) $("cboCountry").value=$("CountryCode").value;
			if($("cboCity")) DropCity($("cboCountry"),$("CityCode").value);
			if($("sCity")) $("sCity").innerHTML=$("CityName").value+"&nbsp;";
			if($("sZip")) $("sZip").innerHTML=$("Zipcode").value+"&nbsp;";
			if($("txtZipCode")) $("txtZipCode").value=$("Zipcode").value;
			if($("sFAX")) $("sFAX").innerHTML=$("Facsimile").value+"&nbsp;";
			if($("txtFAX")) $("txtFAX").value=$("Facsimile").value;
		}
	};
	http.open("POST", myurl, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send("sAgentCode="+$("sAgentCode").value+"&"+new Date().getTime());
}
function ShowMenuProfile(Mode){
	$("sChangePassword").style.display="none";
	$("sChangeProfile").style.display="none";
	$("sDetailProfile").style.display="none";
	switch(Mode){
		case "CP" : $("sChangePassword").style.display=""; break;
		case "EP" : $("sChangeProfile").style.display=""; break;
		case "P" : $("sDetailProfile").style.display=""; break;
	}
}
function ChangePassword(){
	$("errOldPass").style.display="none";
	$("errPassword").style.display="none";
	$("errPassword2").style.display="none";
//	alert($("txtOldPass").value+"="+$("txtNewPass").value+"="+$("txtPassCon").value);
	$txtOldPass=$("txtOldPass").value;
	$txtNewPass=$("txtNewPass").value;
	$txtPassCon=$("txtPassCon").value;
	if($txtOldPass=="" || $txtOldPass.length < 6){ $("errOldPass").style.display=""; $("errOldPass").focus(); }else
	if($txtNewPass=="" || $txtNewPass.length < 6){ $("errPassword").style.display=""; $("txtNewPass").focus(); }else
	if($txtPassCon != $txtNewPass){ $("errPassword2").style.display=""; $("txtPassCon").focus(); }else{
	FileChangePassword();
	}
}
function FileChangePassword(){
	var myurl = "../Member/MemberChangePassword.php", http = new getXMLHTTPRequest();
	http.onreadystatechange = function() {if (http.readyState != 4) { return; }
		var mytext = http.responseText;
		$("DataChangePassword").innerHTML=mytext;
		if($("ChangeValue").value==1){
			MemberLogin($("ShortName").value,$("UserName").value,$("txtNewPass").value);
		}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 MemberLogin(txtAgentID,txtUserName,txtPassword){
	var myurl = "../booking/LoginConnect.php", http = new getXMLHTTPRequest();
	http.onreadystatechange = function() {if (http.readyState != 4) { return; }
		var mytext = http.responseText;
		if($("URLNext")){
			window.open($("URLNext").value+"?"+new Date().getTime(),"self");
		}else{
		window.location.reload();
		}
	};
	http.open("POST", myurl, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send("txtAgentID="+txtAgentID+"&txtUserName="+txtUserName+"&txtPassword="+txtPassword+"&"+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 txtFAX=$("txtFAX").value;

	//Hide error==========
	$("errPrefix").style.display="none";
	$("errFirstName").style.display="none";
	$("errLastName").style.display="none";
	$("errEmail").style.display="none";
	$("errNationality").style.display="none";
	$("errAddress1").style.display="none";
	$("errCountry").style.display="none";
	$("errCity").style.display="none";
	$("errZipCode").style.display="none";
	$("errPhone").style.display="none";
	$("errMobile").style.display="none";

	//Check error=========
	if(cboPrefix=="" || cboPrefix == "NONE"){ $("errPrefix").style.display=""; $("cboPrefix").focus(); }else
	if(txtFirstName==""){ $("errFirstName").style.display=""; $("txtFirstName").focus(); }else
	if(txtLastName==""){ $("errLastName").style.display=""; $("txtLastName").focus(); }else
	if(txtEmail==""){ $("errEmail").style.display=""; $("txtEmail").focus(); }else
	if(cboNationality=="" || cboNationality=="NONE"){ $("errNationality").style.display=""; $("cboNationality").focus(); }else
	if(txtAddress1==""){ $("errAddress1").style.display=""; $("txtAddress1").focus(); }else
	if(cboCountry=="" || cboCountry=="NONE"){ $("errCountry").style.display=""; $("cboCountry").focus(); }else
	if(cboCity=="" || cboCity=="NONE"){ $("errCity").style.display=""; $("cboCity").focus(); }else
	if(txtZipCode==""){ $("errZipCode").style.display=""; $("txtZipCode").focus(); }else
	if(txtPhone==""){ $("errPhone").style.display=""; $("txtPhone").focus(); }else
	if(txtMobile==""){ $("errMobile").style.display=""; $("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+="txtFAX="+txtFAX+"&";
		var myurl = "../Member/MemberEditProfile.php", http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			if(mytext=="complete"){
				//$("DataChangeProfile").innerHTML=mytext;
			
			MemberLogin($("ShortName").value,$("UserName").value,$("UPassword").value);
	
		}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());
	}
}