// JavaScript Document
function opennewWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function createXMLHttpReq() {
  var xmlHttp = false;
  if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  return xmlHttp;
}

function myAjax(url, callback, display) {
  var xmlHttp = createXMLHttpReq();
  if (xmlHttp) {
    xmlHttp.open("get",url);

    xmlHttp.onreadystatechange = function() {
          if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            if (callback) callback(xmlHttp.responseText,display);
          }
      };
    xmlHttp.send(null);
  }
}


function showEle(divname){
	if(document.getElementById(divname).style.display == 'none'){
		document.getElementById(divname).style.display = 'block';
 	}else{  
		document.getElementById(divname).style.display = 'none';
	 }
}
function ShowboxComment(divname){
	if(document.getElementById(divname).style.display == 'none'){
		document.getElementById(divname).style.display = 'block';
 	}else{  
		document.getElementById(divname).style.display = 'none';
	 }
}
function add_rate(parturl,path,urlPath){
	idtp=document.getElementById('idrate_tp');
	userID=document.getElementById('UserID');
	ArId=document.getElementById('ArticleID');
	if(userID.value == ""){
		alert("Please login before rate this article");
		return false;
	}else{		
		if(idtp.value==""){
			alert("Please select topic rate");
			return false;
		}else{
			
			document.getElementById('xshow').style.display = 'block';
			document.getElementById('xshow').innerHTML="<div style='height:60px; text-align:center; padding-top:20px;width:200px;color:#FF6600;'>System working..<img src=\""+path+"working.gif\" /></div>"
			var c= idtp.value+"##"+ArId.value+"##"+parturl+"##"+urlPath+"##"+userID.value+"##"+path;
			setTimeout("urlrateadd('"+c+"')",3000);
		}//End idtp.value==""
	}
}
function urlrateadd(d){
		var tx=d.split("##");
		var url = tx[2]+"add_rate.php?idrate="+tx[0]+"&idar="+tx[1]+"&UrLPath="+tx[3]+"&UserNo="+tx[4]+"&pathimg="+tx[5];
		myAjax(url, show_re, false);	
}
function show_re(responseText, display){
	var shrate=responseText.split("#");
	var txtInnerHTML="<div style='height:60px;color:#FF6600;width:200px;padding-top:20px;text-align:center;'>"+shrate[0]+"<br/>\n<em>Please wait..</em><img src=\""+shrate[3]+"/working.gif\" /></div>";
	document.getElementById('xshow').style.display = 'block';
	document.getElementById('xshow').innerHTML=txtInnerHTML;
	UrlRedirect=shrate[2]+"&idar="+shrate[1];
	setTimeout("Redirect('"+UrlRedirect+"')",3000);
}
function Redirect(RturnTo){
	location.href=RturnTo;
}

function add_ratetohidden(td){
	idtp=document.getElementById('idrate_tp');
	idtp.value=idtp.value;
	if(td.checked==true){
		idtp.value+="::"+td.value;
	}else{
		txc=idtp.value;
		ct=txc.replace("::"+td.value,"");
		idtp.value=ct;
	}
}


///ฟังชันตรวจสอบ ส่วนของ การติดต่อ กับ admin หรือกับทางเว็บไซต์
//ฟังชันตรวจสอบการกรอกข้อมูลจากฟอร์มของ Contact  ก่อนจะทำการส่งอีเมล์และเก็บลง ฐานข้อมูล******************************/
function checkContact(){
	var pro_topic=document.getElementById('problem_topic');	
	var txtboxtopic=document.getElementById('topic_prob');
	var contact_topic=document.getElementById('contact_topic');	
	var contact_de=document.getElementById('contact_detail');
	var name=document.getElementById('name');	
	var email=document.getElementById('email');
	
	if(pro_topic.value=="0"){
		alert('select  problem topic');
		pro_topic.focus();
		return false;
	}else if(pro_topic.value=="other" &&txtboxtopic.value=="" ){
		alert('Please enter problem topic in textbox');
		txtboxtopic.focus();
		return false;
	}else if(contact_topic.value==""){
		alert('Please enter contact topic');
		contact_topic.focus();
		return false;
	}else if(contact_de.value==""){
		alert("Please enter contact detail");
		contact_de.focus();
		return false;
	}else if(name.value==""){
		alert("Please enter your name");
		name.focus();
		return false;
	}else if(email.value==""){
		alert("Please enter your email ");
		email.focus();
		return false;
	}else if(email.value !=""){
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email.value)){alert("Please provide a valid email address.");email.select();	return false;}else{if(confirm('Confirm submit?')==true){return true;	}else{return false;}}	
	}else{
		return true;
	}

}//**************end function *****************/

function select_problem(pro){
	var txtboxtopic=document.getElementById('topic_prob');
	var div_prob=document.getElementById('div_prob');
	if(pro=="other"){
		div_prob.style.display='block';
	}else{
		div_prob.style.display='none';
		txtboxtopic.value='';
	}
}//end function 
/*******************FUNCTION CHECK FORM  Testimonial ************/
function check_testimonail(){
	var test_topic= document.getElementById('test_topic');	
	var test_detail= document.getElementById('test_detail');	
	var name= document.getElementById('name');	
	var email= document.getElementById('email');	
	var star= document.getElementById('star');	
	var rest_start= document.getElementById('rest_start');	
	var branch_id= document.getElementById('branch_id');	
	//เริ่มตรวจสอบ การกรอกข้อมูล
	if(test_topic.value==""){
		alert('please enter testimonial topic');
		test_topic.focus();
		return false;
	}else if(test_detail.value==""){
		alert('please enter testimonial detail');
		test_detail.focus();
		return false;		
	}else if(name.value==""){
		alert("Please enter your name");
		name.focus();
		return false;
	}else if(email.value==""){
		alert("Please enter your email ");
		email.focus();
		return false;
	}else if(star.value=="0"){
		alert("Please select star ");
		star.focus();
		return false;
	}else if(rest_start.value=="00"){
		alert("Please select  start date ");
		rest_start.focus();
		return false;		
	}else if (branch_id.value=="0"){
		alert("Please select branch ");
		branch_id.focus();
		return false;		
	}else if(email.value !=""){
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email.value)){alert("Please provide a valid email address.");email.select();	return false;}else{if(confirm('Confirm submit?')==true){return true;	}else{return false;}}	
	}else{
		return true;
	}
}




function createXMLHttpReq() {
		  var xmlHttp = false;
		  if (window.XMLHttpRequest) {
				xmlHttp = new XMLHttpRequest();
		  }else if (window.ActiveXObject) {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  return xmlHttp;
}

function save_favorites(idar,userID,RootPath){
	if(userID==""){
		alert("Plase login befor save this article");
		return false;
	}else{
	var xmlHttp = createXMLHttpReq();
	var url=RootPath+"add_favorites.php?idar="+idar+"&userID="+userID;
	 xmlHttp.open("get",url);
	xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				strRequest=xmlHttp.responseText;
				if(strRequest=="NOTEMPTY"){
					alert("You have successfully this article. Thank you for joining us.");
					return false;
				}else{
					alert("You have successfully  this article. Thank you for joining us.");
					return true;
				}
			 }
	 }
	  xmlHttp.send(null);
	}//End ตรวจสอบการ login
}
///ฟังัชัน waiting addcomment
function waitingForAdd(pathimg,pathfile,pathlink){
			comment=document.getElementById('arcomment');	
		
			if(comment.value==""){
				alert('Please  enter  your  comment  in a textbox');
				comment.focus();
				return false;
			}else{			
			articleNo=document.getElementById('noarticle');
			UserNo=document.getElementById('User');
			comment=document.getElementById('arcomment');
			var parameter=articleNo.value+"##"+comment.value+"##"+UserNo.value+"##"+pathfile+"##"+pathlink;
			document.getElementById('fcomment').style.display = 'block';
			document.getElementById('fcomment').innerHTML="<div style='height:80px; text-align:center; padding-top:50px;color:#FF6600;'><img src=\""+pathimg+"working.gif\" /></div>";
			setTimeout("addComment('"+parameter+"')",1000);
			}
}
function addComment(str){
		var tx=str.split("##");
		var UrlFile = tx[3]+"add_articlecmt.php?idart="+tx[0]+"&cmt="+tx[1]+"&UserNo="+tx[2]+"&pathLink="+tx[4];
		myAjax(UrlFile, showRsCmp, false);	
}
function showRsCmp(responseText,display){
		var Result=responseText;
		rst=Result.split("@");
		//var textshowResult="<img src=\""+pathimg+"working.gif\" />";
		document.getElementById('fcomment').innerHTML="<div style='height:80px; text-align:center; padding-top:30px;color:#FF6600;'>"+rst[0]+"<br/>Please wait.!..<img src=\""+rst[2]+"working.gif\" /></div>";
		UrlReturn =rst[1];
		setTimeout("Redirect('"+UrlReturn+"')",3000);
}
//ส่วนของการโหวด poll
function votPoll(idA,Uid,Url,path,idQ,Rootpath){
	if(confirm("Confirm vote?")==true){	
				pb=document.getElementById('pollbox');
				pb.innerHTML="<div style='height:60px; text-align:center; padding-top:20px;width:200px;color:#FF6600;'>System working..<img src=\""+path+"working.gif\" /></div>";	
				var Para=idA+"##"+Uid+"##"+Url+"##"+idQ+"##"+Rootpath;
				setTimeout("Addvote('"+Para+"')",1000);	
	}
}

function Addvote(parameter){
		var tx=parameter.split("##");
		//alert(parameter)
		var UrlFile =tx[4]+"add_poll.php?idpoll="+tx[3]+"&User="+tx[1]+"&Urlpath="+tx[2]+"&answer="+tx[0];
		myAjax(UrlFile, sHowResult, false);	
}
function sHowResult(responseText,display){
		var Result=responseText;
		rst=Result.split("#");
		document.getElementById('pollbox').innerHTML="<div style='height:80px; padding-top:30px;color:#FF6600;'>"+rst[0]+"<br/>Please wait.!..<img src=\""+rst[3]+"working.gif\" /></div>";
		UrlReturn = rst[1]+"&idar="+rst[2];
		setTimeout("Redirect('"+UrlReturn+"')",3000);
	}

function ChkformRegister(){
	if($("select#prefix").val()=="0"){
		alert("Select your prefix.");
		$("#prefix").focus();
		return false;
	}else if($("#firstname").val()==""){
		alert("Enter your name.");
		$("#firstname").focus();
		return false;
	}else if($("#lastname").val()==""){
		alert("Enter your last name.");
		$("#lastname").focus();
		return false;
	}else if($("#country").val()=="0"){
		alert("Select your country.");
		$("#country").focus();
		return false;
	}else if($("#pri_email").val()==""){
		alert("Enter your email.");
		$("#pri_email").focus();
		return false;
	}else if($("#tel_no").val()==""){
		alert("Enter your telephone number");
		$("#tel_no").focus();
		return false;
	}else if($("#pwd").val()==""){
		alert("Enter your password.");
		$("#pwd").focus();
		return false;	
	}else if($("#pwd").val().length<6){
		alert("-	Enter password minimum of 6 characters in length.");
		$("#pwd").focus();
		return false;			
	}else if($("#pwd").val()!=$("#cfpwd").val()){
		alert("Please check  your confirm password.");
		$("#cfpwd").focus();
		return false	
	}else if($("#hint").val()==""){
		alert("Enter your hint.");
		$("#hint").focus();
		return false	
	}else if($("#hint").val()==$("#pwd").val()){
		alert("The hint must be different from your password.") ;
		$("#hint").focus();
		return false;
	}else if($("#captchatxt").val()==""){
		alert("Enter captcha.");
		$("#captchatxt").focus();
		return false	;		
	}else if($("#captchatxt").val() !=""){		
	
		var xmlHttp = createXMLHttpReq();
		var url=$("#urlpath").val()+"check_captcha.php?cptxt="+$("#captchatxt").val();
		 xmlHttp.open("get",url);
		xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				txt=xmlHttp.responseText;
				var txtc=parseInt(txt)+1;
				if(txtc=='2'){
					alert("The characters you entered didn't match the word verification.Please try again.");
					$("#captchatxt").select();
					return false;
				}else{
					if(confirm("Submit your information now!")==true){
						document.register.submit();
						return true;
					}else{
					return false;
					}
				}
			 }
	 }
	  xmlHttp.send(null);
	}
}//End function 


function check_email(){
if($("#pri_email").val()==""){
		alert("Enter your email.");
		$("#pri_email").focus();
		return false;
}else if($("#pri_email").val() !=""){
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test($("#pri_email").val())){
			alert("Please provide a valid email address.");
			$("#pri_email").select();	
			return false;
		}else{	
		var xmlHttp = createXMLHttpReq();
		var url=$("#urlpath").val()+"check_email.php?premail="+$("#pri_email").val();
		 xmlHttp.open("get",url);
		 xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				txt=xmlHttp.responseText;
					var txtc=parseInt(txt)+1;
					if(txtc==2){
						alert("This email already exist.");
						$("#pri_email").select();
						return false;
					}else{
						check_dispname();
					}
				}
			}	
	 xmlHttp.send(null);
	}//End lter.tes
 }//End if($("#pri_email").val() !="")
}


function check_emailForget(){
if($("#emailsend").val() ==""){	
	//alert("Enter your email ");
	$("#emailsend").focus();
	$("#showtxt").html("Enter your email address.");
	return false;	
} else if($("#emailsend").val() !=""){
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test($("#emailsend").val())){
			$("#showtxt").html("Please provide a valid email address.");
			$("#emailsend").select();		
			return false;
		}else{	
		var xmlHttp = createXMLHttpReq();
		var url=$("#pathSend").val()+"check_forgetemail.php?premail="+$("#emailsend").val();
		 xmlHttp.open("get",url);
		 xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				txt=xmlHttp.responseText;
					if(txt=="complete"){
					alert("Confirm your password reset.\n Please check your inbox for a message from noreply@rarinjinda.com");	
					}else{
					$("#showtxt").html("Your email not found");
					}
				}
			}	
	 xmlHttp.send(null);
	}
 }//End if($("#pri_email").val() !="")
}



//ส่วน login
function Chk_Userlogin(){
	if($("#emaillogin").val()=="" ||  $("#emaillogin").val()=="Username or Email"){
		$("#emaillogin").focus();
	}else if($("#password").val()=="" ||  $("#password").val()=="Enter password"){
		$("#password").focus();
	}else{
			checkLoginnow();
		//$("#form1").submit();
	}
}
function chktxt(tp){
		if(tp=="email"){
		txt="Username or Email";
		idv="#emaillogin";
		idv2="emaillogin";
		}
		else if(tp=="pwd"){
		txt="Enter password";
		idv="#password";
		idv2="password";
		}
	
		if(document.getElementById(idv2).value==txt){
			document.getElementById(idv2).value="";
			$(idv).removeClass("fontxt");
		}else{
			$(idv).removeClass("fontxt");
		}
}
function chktxt02(tp){
		if(tp=="email"){
		txt="Username or Email";
		idv="#emaillogin";
		idv2="emaillogin";
		}
		else if(tp=="pwd"){
		txt="Enter password";
		idv="#password";
		idv2="password";
		}
		if(document.getElementById(idv2).value==""){
		document.getElementById(idv2).value=txt;
		$(idv).addClass("fontxt");
		}
}
function addvaluechkbox(){
		if(document.getElementById("remember").checked==true){
			document.getElementById("remember").value="remember";
		}else{
			$("#remember").val("");
		}
}
function checkLoginnow(){
		var xmlHttp = createXMLHttpReq();
		var url=$("#pathfile").val()+"ajax_chklogin.php?eml="+$("#emaillogin").val()+"&pwd="+$("#password").val()+"&sck="+$("#remember").val();
//		alert(url)
		 xmlHttp.open("get",url);
		 xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				txt=xmlHttp.responseText;
				strresult=txt.split("#");
				if(strresult[0]=="notfound"){//ไม่พบ
					$("#showresult").html(" Your username/email  not found");
					$("#emaillogin").select();
				}else if(strresult[0]=="notallow"){//พบแต่ไม่ได้ activate
					$("#showresult").html("Please activate your account");
				}else if(strresult[0]=="incorect"){//พบ password ผิด
					$("#showresult").html("Your password incorect");
					
					/* hint box */
					$("#showhint").fadeIn().fadeTo("slow",0.9);
					$("#showhint #showhint_body").html("<div class='title'>your password hint</div><p>\""+strresult[1]+"\"</p>");
					
					$("#password").select();
				}else if(strresult[0]=="pass"){
					location.href=$("#pathreturn").val();
				}
				
				}
			}	
	 xmlHttp.send(null);

}//End function 
///ตรวจสอบการ เปลียนเเปลง ส่วน create password
function check_newpwd(){
	if($("#newpwds").val()==""){
		alert("Enter password");
		$("#newpwds").focus();
		return false;
	}else if($("#newpwds").val().length<6){
		alert("-	Enter password minimum of 6 characters in length.");
		$("#newpwds").focus();
	}else if($("#cfnewpwd").val() !=$("#newpwds").val()){
		alert("Please check  your confirm password.");
		$("#cfnewpwd").focus();
		return false;
	}else if($("#activateCode").val()==""){
		alert("Enter  your  activationcode( Check activationcode in  your email )");
		$("#activateCode").focus();
		return false;		
	}else if($("#activateCode").val()!=""){
     		var xmlHttp = createXMLHttpReq();
    		var url=$("#rootpath").val()+"changepwd.php?idac="+$("#activateCode").val()+"&eml="+$("#emlact").val(); 
			 xmlHttp.open("get",url);
		 	xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				txt=xmlHttp.responseText;
				if(txt=="notfound"){
					alert("Please enter new activation code");
					$("#activateCode").select();
					return false;
				}else if(txt=="found"){
					if(confirm("Confirm your password?")==true){
							$("#newpassword").submit();
							return true;
					}else{
						return false;
					}
				}
					
				//alert(txt);
				}
			}	
	 xmlHttp.send(null);

	}
}
function check_dispname(){
if($("#displayname").val()==""){
		alert("Enter your display name.");
		$("#displayname").select();
		return false;
	}else if($("#displayname").val()!=""){
	     	var xmlHttp = createXMLHttpReq();
    		var url=$("#urlpath").val()+"check_displayname.php?dispname="+$("#displayname").val();
			xmlHttp.open("get",url);
		 	xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				txt=xmlHttp.responseText;
					if(txt=="notpass"){
						alert("This display name already exist.");
						$("#displayname").select();
						return false;
					}else{
						ChkformRegister();
					}//alert(txt);
				}
			}	
	 xmlHttp.send(null);
	}//End if*/
}
function Logout(){
		if(confirm("Confirm logout?")==true){
	     	var xmlHttp = createXMLHttpReq();
    		var url=$("#rootpathlogout").val()+"logout.php";
			xmlHttp.open("get",url);
		 	xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				txt=xmlHttp.responseText;	
				if(txt=="COMPLETE"){
					location.href=$("#urlPath").val();
				}
				}
			}	
		 xmlHttp.send(null);
		}
	
}
//ส่วนของการ Edit
function ShowPwddiv(divname){
	if(document.getElementById(divname).style.display == 'none'){
		document.getElementById(divname).style.display = 'block';
		$("#chgpwd").val("cpwd");
 	}else{  
		document.getElementById(divname).style.display = 'none';
		$("#chgpwd").val("");
	 }
}
function ChkEditProfile(){
	if($("#prefix").val()==""){
		alert("Select your prefix.");
		$("#prefix").focus();
		return false;
	}else if($("#firstname").val()==""){
		alert("Enter your name.");
		$("#firstname").focus();
		return false;		
	}else if($("#lastname").val()==""){
		alert("Enter your last name.");
		$("#lastname").focus();
		return false;				
	}else if($("#country").val()=="0"){
		$("#country").focus();
		alert("Select your country.");
		return false;
	}else if($("#tel_no").val()==""){
		alert("Enter your telephone number.");
		$("#tel_no").focus();
		return false;
	}else if($("#userimg").val() !=""){
		var  imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;
		 var path = $("#userimg").val();
   		 if (path.search(imgRe) == -1) { 
			alert("Please upload only .jpg,png  and gif extention file !"); 
			return false;
   		 }	
	}if($("#pwd").val() !=$("#cfpwd").val()){
		alert("Your password and Confirm password not match ");
		$("#cfpwd").focus();
		return false;
	}else if($("#pwd").val() !="" && $("#pwd").val().length<6){
		alert("-	Enter password minimum of 6 characters in length.");
		$("#pwd").focus();
		return false;
	}else if($("#hint").val()==""){
		alert("Enter your hint");
		$("#hint").focus();
		return false;
	}else{
		if(confirm("Confirm submit your information?")==true){
		//$("#editprofleuser").submit();	
		document.editprofileuser.submit();
		return true;
		}
	}
}//End function

function deleteFav(idfav,Url,path){
	if(confirm("Confirm this favorites?")==true ){
		$.get("deletefavorites.php", { Idf: idfav, urlturn: Url },
 		 function(data){
		  $("#favmanage").html(data);
  		});
	}
}

	//ฟอร์มการจองสปา 
	function get_selectTreatment(pson){
		if($("#treat_id").val()!=""){
			$("#objsele").val($("#treat_id").val());
		}else{
			$("#objsele").val('');
		}

		Path=$("#spa_path").val();
		br=$("#b_reserv").val();
		trmt=$("#treat_id").val();
		//pson=$("#spa_path").val();
		$.get(Path+"reserv_person.php", { pno: pson,brch:br,tmt:trmt},
			function(data){ 
			dml=data.split("||");
			$(".reserv_info").html(dml[0]);
			$(".treatmentlist").html(dml[1]);
			//treatment_description('');
			get_treatment_date();
			});
	}
	function addvalue(tx){
 	var n = $("input:checked").length;
	if(n==0){
		document.getElementById("submit").disabled=true;
	}else{
		document.getElementById("submit").disabled=false;
	}
		var datasel=$("#objsele").val();
		var strcheckbox="checkbox_"+tx;
		datachk=document.getElementById(strcheckbox);
			if(datachk.checked== true){
				//ดึงรายละเอียด ของ รายการที่เลือก
			//	treatment_description(datachk.value);
				
				if(datasel==""){
					strsel=datachk.value;
				}else{
				    strsel = datasel+"###"+datachk.value;
				}
				$("#objsele").val(strsel);
			}else{//Uncheck
				//treatment_description('');//รายละเอียดของ แต่ละtreatment
				str=datasel.split("###");
				for(s=0;s<str.length;s++){
					if(str[s]==datachk.value){
						str[s]="";	
					}else if(str[s]=="###"){	
						str[s]="";	
					}else{
						str[s]=str[s];
					}
				}
				sfv=new Array();
				for(s=0;s<str.length;s++){
					if(str[s]!=""){
						sfv.push(str[s]);
					}
				}
				sss=sfv.join("###");
				$("#objsele").val(sss);
			 }
	}

	function showdata(ps,typac){
		
		if(typac!="show"){
			document.getElementById("submit").disabled=true;
		}
		Path=$("#spa_path").val();
		treatsel=$("#objsele").val();
	//	alert(treatsel)
		$.get(Path+"add_session.php", { pno: ps,treatment:treatsel,act:typac},
		function(data){ 
		$(".reserv_info").html(data);
		$(".treatmentlist").html("");
		$(".treatment_desc").html("");
		 //treatment_description('');
		
		/* edit current */
			$('.edit_link').click(function(){
				$('.current_person').removeClass('current_person');		   
				$(this).parent().parent().addClass('current_person');
			});
		});
	}
	
/*	function treatment_description(idtm){
		Path=$("#spa_path").val();
		br=$("#b_reserv").val();
		$.get(Path+"description_treatment.php", { id_des:idtm,br_id:br},
		function(data){ 

		//$(".treatment_desc").html(data);
		});	
	}
*/
function getTreatmentDate(){
	treatment_date = $('#reserv_year').val()+"-"+$('#reserv_mon').val()+"-"+$('#reserv_day').val();
	$.get("../ajax.php",{fn : 'gettreatmentdate', treatmentdate : treatment_date});
	//alert(treatment_date);
}
function change_branch(str){
	getTreatmentDate();
	Path=$("#spa_path").val();
	if(str != ''){
		if(confirm('Confirm delete?') == true){
			$.get(Path+"clear_session.php",{id_user:str},
			function(data){ 
				showdata(data,'show');
			});	
		}
	}else{
		$.get(Path+"clear_session.php", { id_user:str},
		function(data){
			get_selectTreatment(1);
		});
	}	
}
///Edit Reserv ตามuser แต่ละคน
function edit_reserv(Pno,valtreat){
	$("#objsele").val(valtreat);
	Path=$("#spa_path").val();
	treatsel=$("#objsele").val();
	br=$("#b_reserv").val();
	$.get(Path+"edit_reserv.php", { pno:Pno,brch:br},
		function(data){ 	
			$(".treatmentlist").html(data);
	});
}
//Check Befor Submit form 
function Check_Sparserv(){
	d=$("#reserv_day").val();
	m=$("#reserv_mon").val();
	y=$("#reserv_year").val();
	dsel=y+m+d;
	today=$("#today").val();
	svday=$("#dservice").val();
	id_pro=$("#idpro").val();

	var todayc=new Date();
 		ccc=(todayc.getUTCFullYear())+"/"+(todayc.getMonth()+1)+"/"+todayc.getDate();
	strDate1=y+"/"+m+"/"+d;
	strDate2=ccc;	
	datDate1= Date.parse(strDate1); 
	datDate2= Date.parse(strDate2); 
	datediff = ((datDate1-datDate2)/(24*60*60*1000)) ;		
	//spa
	if(datediff<3){
		alert('Reservations should be made 3 days in advance.');
		return false;
	}else if(parseInt(dsel)>svday && id_pro !="" ){
		alert("You are out of promotion period");
		return false;
	}else{
		if(confirm("Check your reservation information.\nAre you ready go to next step?")==true){
			document.reserv_step1.submit();
		}
	}
}


////////////////////////////////////////////

///Reserv step2
function showform_datalogin(){
	if(document.getElementById('use_mem').checked==true){
		$("#use_mem").val(1);
		$(".datalogin").css('display','block');
	}else{
		$(".datalogin").css('display','none');
		$("#use_mem").val(0);
		$("#user_pwd").val('');
		$("#user_cmfpwd").val('');
		$("#user_hint").val('');
		$("#user_display").val('');
		
	}
}
//Check form 
function Check_reservStep2(){
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var Path=$("#urlpath").val();
	if($("#userpri_email").val()==""){
		alert("Please enter your email.");
		$("#userpri_email").focus();
	}else if (!filter.test($("#userpri_email").val())){
		alert("Please provide a valid email address.");
		$("#userpri_email").select();
	}else if($("#user_prefix").val()==0){
		alert("Select your prefix.");
		$("#user_prefix").focus();
	}else if($("#user_firstname").val()==""){
		alert("Enter your firstname.");
		$("#user_firstname").focus();		
	}else if($("#user_lastname").val()==""){
		alert("Enter your lastname.");
		$("#user_lastname").focus();		
	}else if($("#user_country").val()==0){
		alert("Select your country.");
		$("#user_country").focus();		
	}else if($("#user_telno").val()==""){
		alert("Enter your telephone number");
		$("#user_telno").focus();		
	}else if($("#user_captchatxt").val()==""){
		alert("Enter captcha.");
		$("#user_captchatxt").focus();		
	}else if($("#user_captchatxt").val()!=""){
			var capt=$("#user_captchatxt").val()
			$.get(Path+"check_captcha.php", { cptxt:capt},
			function(data){ 	
				if(data==1){
					alert("The characters you entered didn't match the word verification.\nPlease try again.");
					$("#user_captchatxt").select();
				}else{
					Usercheck_register();	
				}
			});
	}
}//Enfunction
//cHECK wHEN User Click ยอมรับเป็นสมาชิกด้วย
function Usercheck_register(){
	if(document.getElementById('use_mem').checked==true){
		if($("#user_display").val()==""){
			alert("Enter your display name.");
			$("#user_display").focus();
		}else if($("#user_display").val()!=""){
			var Path=$("#urlpath").val();
			var disname=$("#user_display").val();
			$.get(Path+"check_displayname.php", { dispname:disname},
			function(data){ 	
				if(data=="notpass"){
					alert("This display name already exist.");
					$("#user_display").select();
				}else{
					checkpaasword_login();
				}
			});
		}
	}else{//end check==true
		confirmSubmit();
	}
}
function checkpaasword_login(){
		if($("#user_pwd").val()==""){
			alert("Enter your password.");
			$("#user_pwd").focus();
		}else if($("#user_pwd").val().length<6){
			alert("Enter password minimum of 6 characters in length.");
			$("#user_pwd").select();
		}else if($("#user_pwd").val() !=$("#user_cmfpwd").val()){
			alert("Your password and Confirm password not match ");
			$("#user_cmfpwd").focus();
		}else if($("#user_hint").val()==""){
			alert("Enter your hint.");
			$("#user_hint").focus();
		}else if($("#user_hint").val()==$("#user_pwd").val()){
			alert("The hint must be different from your password.") ;
			$("#hint").focus();
			return false;
		}else{
			var Path=$("#urlpath").val();
			var pemail=$("#userpri_email").val();
			$.get(Path+"check_email.php", { premail:pemail},
			function(data){ 	
				if(data==1){
					alert("This email already exist.");
					$("#userpri_email").select();
				}else {	confirmSubmit();	}});
		}
}
function confirmSubmit(){
	if(confirm("Submit Your Information?")==true){
		document.user_register.submit();
	}
}

////login By Customer
function check_customerLogin(){
	var Path=$("#urlpath").val();
	user=$("#user_namelogin").val();
	pwd=$("#pass_wordlogin").val();
	rmb=$("#rememer_me").val();	
	
	if(user==""){
		alert('Enter username / email.');
		$("#user_namelogin").focus();
	}else if(pwd==""){
		alert('Enter password.');
		$("#pass_wordlogin").focus();
	}else{
		$.get(Path+"ajax_chklogin.php", { eml:user,pwd:pwd,sck:rmb},
		function(data){ 
			strresult=data.split("#");
				if(strresult[0]=="notfound"){//ไม่พบ
					alert(" Your username/email  not found");
					$("#user_namelogin").select();
				}else if(strresult[0]=="notallow"){//พบแต่ไม่ได้ activate
					alert("Please activate your account");
				}else if(strresult[0]=="incorect"){//พบ password ผิด
					alert("Your password incorect");
					$("#pass_wordlogin").select();
				}else if(strresult[0]=="pass"){
					document.loginform.submit();	
				}
		});
	}
}
function addremember(){
		if(document.getElementById("rememer_me").checked==true){
			$("#rememer_me").val("remember");
		}else{
			$("#rememer_me").val("");
		}
}


/////////////////////////////////////////////////////////RESERV STEP2


//function หน้า promotion  
function UPDATE_HOTEL(c){	
    		 CLEAR_SELECT();
			  var secname = document.getElementById("hotel_rest");
			  var results = "NotHotel,Rarinjinda wellness Spa Resort,Grand Centre Point Hotel";
			
			  var option = null;
			  p=results.split(",");
			  //================================================================
			  if(c.value==1){oth=2;}else if(c.value==2){oth=1;}
			  		   option = document.createElement("option");
					   option.setAttribute("value",p[c.value]);
					   option.appendChild(document.createTextNode(p[c.value]));
					   secname.appendChild(option);
					   option = document.createElement("option");
					   option.setAttribute("value",p[oth]);
					   option.appendChild(document.createTextNode(p[oth]));
					   secname.appendChild(option);
	}
	
	function CLEAR_SELECT() 
	{
 		   var secname = document.getElementById("hotel_rest");
   		   while(secname.childNodes.length > 0) 
		   {
              secname.removeChild(secname.childNodes[0]);
           }
	}
	function Calchkout_date(D){
		
		var xmlHttp = createXMLHttpReq();
		var ck_in = document.getElementById("checkin_date");
		var ck_out =document.getElementById("checkout_date");
		var ck_date = document.getElementById("chk_addate");	
		if(D!=""){
		dcheck_in=D;
		//ck_date.checked=false;
		}else{
		dcheck_in=ck_in.value	
		}
		var url = "ajax_calchkout_date.php?date_chkin="+dcheck_in;
		xmlHttp.open("get",url);
		xmlHttp.onreadystatechange = function() {
	    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			strRequest=xmlHttp.responseText;
			ck_out.value=strRequest;
	 	}  
 	}
 	xmlHttp.send(null);	
	}

function chk_date_inout(){
		 var d_in = document.getElementById("reserv_day");
		 var m_in = document.getElementById("reserv_mon");
		 var ck_date = document.getElementById("chk_addate");
		 var y_in = document.getElementById("reserv_year");
		 var ck_in = document.getElementById("checkin_date");
		 var ck_out = document.getElementById("checkout_date");
		 
		// if(ck_date.checked==true){
		 	if(m_in.value<10){
				m_inm=m_in.value;
			}else{
				m_inm=m_in.value;
			}
			if(d_in.value<10){
				d_inm=d_in.value;
			}else{
				d_inm=d_in.value;
			}
			
		 	ck_in.value=d_inm+"-"+m_inm+"-"+y_in.value;
			//alert(ck_in.value)
			Calchkout_date("");
		 //}else if (ck_date.checked==false){
		// 	ck_in.value="";
		//	ck_out.value="";
		 //}else{
		 	
		// }
	}
function registpromotion(){
	d=$("#reserv_day").val();
	m=$("#reserv_mon").val();
	y=$("#reserv_year").val();
	dsel=y+m+d;
	today=$("#today").val();
	var todayc=new Date()
 		ccc=(todayc.getUTCFullYear())+"/"+(todayc.getMonth()+1)+"/"+todayc.getDate();
	strDate1=y+"/"+m+"/"+d;
	strDate2=ccc;	
	datDate1= Date.parse(strDate1); 
	datDate2= Date.parse(strDate2); 
	datediff = ((datDate1-datDate2)/(24*60*60*1000)) ;		
	var date_data=$("#checkin_date").val();
	ck_d=date_data.split("-");
	chkd_in=ck_d[2]+ck_d[1]+ck_d[0];	
	//spa
	if($("#bpromotion_reserv").val()=="0"){
		alert("Please select branch.");
		$("#bpromotion_reserv").focus();
		return false;
	}else if(datediff<4){
		alert('Reservations should be made 4 days in advance.');
		return false;
	}else if(date_data==""){
		alert("Please enter check-in date");
		return false;
	}else if(date_data !=""){
		if(chkd_in<dsel){
			alert("Check-in date not less than reservation date")	;
			return false;
		}else if(chkd_in>20091031){
			alert("You must make reservation before 31-10-2009");
			return false;
		}else if(dsel>20091031){
			alert("You must make reservation before 31-10-2009");
			return false;		
		}else {
			if(confirm("Please confirm your information ?")==true){
				return true;
			}else{
				return false;
			}
		}
		
	}
}

//hotel
///HotelReserv
function getRoomperson(rno){
	Path=$("#hotelpath").val();
	$.get(Path+"getroom_and_person.php", { rno: rno},
	function(data){ 
	//alert(data)
	str=data.split("||");
	$(".roomno").fadeOut(400,function(){
	$(".roomno").html(str[0]).fadeIn(400);});//html(htmltxt);	
	//$(".roomno").html(str[0]);
	
	$(".roomlistselect").slideUp(400,function(){
	$(".roomlistselect").html(str[1]).slideDown(400);});//html(htmltxt);
	
	//$(".roomlistselect").html(str[1]);
	});
}
/*
function search_roomdata(){
	Path=$("#hotelpath").val();	
	//วันที่จะเข้าพัก
	d1=$("#arrival_day").val();
	m1=$("#arrival_mon").val();
	y1=$("#arrival_year").val();
	arDate=y1+"-"+m1+"-"+d1;
	//วันที่ออก
	d2=$("#depart_day").val();
	m2=$("#depart_mon").val();
	y2=$("#depart_year").val();
	deDate=y2+"-"+m2+"-"+d2;
	
	pno=$("#aperson").val();//adout
	//chno=$("#chperson").val();//child
	$.get(Path+"search_roomrelate.php", { ardate: arDate,depdate:deDate,perno:pno},
	function(data){ 
	//alert(data)
	});	
}
*/


function Openwindow(rID,action){
	Path=$("#hotelpath").val();

	if(action==""){
			//วันที่จะเข้าพัก
			today=$("#today").val();
			darrival=$("#arrivaldate").val();
			dar=darrival.split("-");
			arDate=dar[2]+"-"+dar[1]+"-"+dar[0];			
			dayarcal=dar[2]+dar[1]+dar[0];
			
			
			//วันที่ออก
		//	alert(arDate)
			depart=$("#departuredate").val();
			dar2=depart.split("-");
			deDate=dar2[2]+"-"+dar2[1]+"-"+dar2[0];	
			daydecal=dar2[2]+dar2[1]+dar2[0];	
			pno=$("#aperson").val();//adout
			chno=$("#chperson").val();//adout
			MaxD=$("#dateCal").val();
			Mind=$("#Mind").val();
			Proid=$("#PRID").val();
			
			//hotel
			if(Proid=="30"){
				//alert(dayarcal+" - "+daydecal+" - "+today);
				TXTalert='Reservations date must greater than today.';
			}else if(Proid=="12"){
				TXTalert='Reservations should be made 30 days in advance.';	
			}else{
				TXTalert='Reservations should be made 3 days in advance.';
			}
			if(MaxD>1 && Proid!=""){
				propa="&PROID="+Proid;
			}else if (MaxD<=1 && Proid!=""){
				propa="&PROID="+Proid;
			}else {
				propa="";
			}
			if(dayarcal<today){
				alert(TXTalert);
				return false;
			}else if (dayarcal>=daydecal){
				alert("Daparture date not less  than  arrival date");
				return false;
			}
			else if(pno==0){
				alert("Please select  amount of person.");
				return false;
			}else if(Proid!="" && (daydecal-dayarcal)<Mind){
				alert("Number of night must at least "+Mind+" nights \n to receive this promotion");
				return false;
			}else{
				Path=$("#hotelpath").val();	
				url=Path+"select_room.php?ardate="+arDate+"&depdate="+deDate+"&perno="+pno+"&chno="+chno+propa;
				window.open(url,'_blank');
				//document.getElementById('butchkroom').disabled=true;
			}
	}else{//ACTION EDIT 
				Path=$("#hotelpath").val();	
				url=Path+"select_room.php?ACT=EDIT&roomid="+rID;
				window.open(url,'_blank');		
	}
}
function getroom_description(id){
	Path=$("#hotelpath").val();	
	//$("#hotelpath").val();	
	var str=id;
	Objtxt=str.split("::");
	typetbl=Objtxt[0];
	roomType=Objtxt[1];
	idproduct=Objtxt[2];
	numdate=Objtxt[3];
	$("#roomselect").val(str);	
	document.getElementById('buttonchange').disabled=false;
	$.get(Path+"product_description.php", {typepd: typetbl,rtype:roomType,pdid:idproduct,ndate:numdate},
	function(data){   
		$(".product_description").fadeOut(400,function(){
		$(".product_description").html(data).fadeIn(400);});//html(htmltxt);
		});
}
function addroomInsession(){
			ACT=$("#Actselectroom").val();
			if(confirm('Confirm selected room?')==true){
			//$("#buttonchange").disabled;
			document.getElementById('buttonchange').disabled=true;
			exb=document.getElementById('exbed');	
			if(exb.checked==true){
				optionget=exb.value;	
			}else if(exb.checked==false){
				optionget="";
			}
		//	trf=document.getElementById('transfer');	
			//if(exb.checked==true && trf.checked==true)	{
			//	optionget=exb.value+"::"+trf.value;
		//	}else if(exb.checked==true && trf.checked==false){
			//	optionget=exb.value+"::"+"";
			//}else if(exb.checked==false && trf.checked==true){
			//	optionget=trf.value+"::"+"";
		//	}else{optionget="";}	
			Path=$("#hotelpath").val();	
			stdata=$("#roomselect").val();
			if(ACT==""){
					
					numroom=$("#amountroom").val();
					chamount=$("#childamount").val();
					arRival=$("#arrival").val();		
					deParture=$("#departure").val();
					amperson=$("#amountperson").val();
					$.get(Path+"room_tosession.php",{roomamount: numroom,strsess:stdata,nperson:amperson,optionroom:optionget,countchild:chamount,arrivaldate:arRival,departdate:deParture},
					function(data){
						//alert(data)
						str=data.split("||");
						opener.top.$('.roomno').html(str[0]);
						opener.top.$('.roomlistselect').html(str[1]);
						window.close();
					});	
			}else{///EDIT
		
					NoEdit=$("#numberroomedit").val();
					$.get(Path+"room_tosession.php",{noroomedit:NoEdit,optional:optionget,actionedit:'EDIT',strsess:stdata},
					function(data){
						str=data.split("||");
						opener.top.$('.roomno').html(str[0]);
						opener.top.$('.roomlistselect').html(str[1]);
						window.close();
					});	
			}
	}	//End Confirm
}
function deletesession_room(rID){
		Path=$("#hotelpath").val();	
		if(rID!=""){datacmf="Confirm delete?";//else{datacmf="หากว่าคุณทำการเปลียนวันที่  \n รายการที่คุณได้ทำไว้จะถูกรีเซ็ตใหม่ \nคุณต้องการเปลียนหรือไม่ ?";}
			if(rID!="Yes"){
				if(confirm(datacmf)==true){
						$.get(Path+"delete_roomsession.php",{noroomdel:rID},
						function(data){
							getRoomperson(data);
						});
					 } 
			}
	   }else {
			CaldepartureDate();
	   }
}
function CaldepartureDate(){
			Path=$("#hotelpath").val();	
			darrival=$("#arrivaldate").val();
			numD=$("#dateCal").val();
			//depart=$("#departuredate").val();
			dar=darrival.split("-");
			arDate=dar[2]+"-"+dar[1]+"-"+dar[0];
/*			d2=document.getElementById('depart_day');
			m2=document.getElementById('depart_mon');
			y2=document.getElementById('depart_year');
			option = document.createElement("option");
			var option = null;*/
		//alert(arDate)
	//	ajax_calchkout_date.php?date_chkin="+dcheck_in
	   	$.get(Path+"ajax_departure_date.php",{date_chkin:arDate,numdateadd:numD},
		function(data){
					   dx=data.split("-");
					  // d2.selectedIndex = (dx[0]-1);
					  // m2.selectedIndex = (dx[1]-1);
					   $("#departuredate").val(dx[0]+"-"+dx[1]+"-"+dx[2]);
						//getRoomperson(data);
		});
}

function get_forcheckalert(db){
		
		darrival=$("#arrivaldate").val();
		depart=$("#departuredate").val();
		Path=$("#hotelpath").val();
		dar=darrival.split("-");
		dar2=depart.split("-");
		arDate=dar[2]+"-"+dar[1]+"-"+dar[0];
		deDate=dar2[2]+"-"+dar2[1]+"-"+dar2[0];
		$.get(Path+"getcountsession.php",{archk:arDate,dpchk:deDate,cds:db},
		function(data){	
			sx=data.split("|||");
			if(sx[0]==""){
				if(confirm("If you will change your Reservation Date, all entered \n Reservation Information will be deleted. \nWould you like to continue changing your Arrival or Departure Date?")==true){
					ClearSessionReal('');
				}else{
					ad=sx[1].split("-");
					dd=sx[2].split("-");
					$("#arrivaldate").val(ad[2]+"-"+ad[1]+"-"+ad[0]);
					$("#departuredate").val(dd[2]+"-"+dd[1]+"-"+dd[0]);					
/*					d1.selectedIndex=(ad[2]-1);
					m1.selectedIndex=(ad[1]-1);
					d2.selectedIndex=(dd[2]-1);
					m2.selectedIndex=(dd[1]-1);*/
				}
			}else{
				if(sx[3]=="a"){CV="";}else{CV="Yes";}
				deletesession_room(CV);
			}
		});
}
function ClearSessionReal(rID){
		Path=$("#hotelpath").val();	
		$.get(Path+"delete_roomsession.php",{noroomdel:rID},
		function(data){
			CaldepartureDate();
			getRoomperson(data);
		});
}
function checkMinRoom(){
	room_total = $('#total_room').val();
	room_min = $('#pro_min_room').val();
	if(room_min != 0){
		if(room_total < room_min){
			alert("You must reserve at least "+ room_min +" rooms.");
			return false;
		}else{
			return true;
		}
	}else{
		return true;
	}
}
function Nextstep(){
	if(checkMinRoom()){
		if(confirm("Check your reservation information.\nAre you ready go to next step?")==true){
			document.hreserv_step1.submit();
		}
	}
}







///admin search
///admin search
function SearchInvoice(){
		if($("#srch_fld").val()==""){
			alert("Enter Invoice id.");
			$("#srch_fld").focus();
			return false
		}else if($("#invtype").val()==""){
			alert("Select type of invoice.");
			$("#invtype").focus();
			return false
		}else{
			$("#act").val('searchinv');
			document.updtPay.submit();
		}
}
function addpayment_unit(){
	Deposit=$("#pdeposit").val();
	Curent=$("#payment_curentcy").val();
	Priceall=$("#totalprices").val();

	if($("#payment_type").val()=="kasikorn"){
		var ArUnit=new Array("THB","USD","EUR","JPY","GBP","NZD","HKD","SGD","CHF");
		$("#exchange_rate").val('');
		de=Deposit;
		Pr=Priceall;
		//Un="THB";
	}else if($("#payment_type").val()=="paypal"){
		var ArUnit=new Array("USD");
			$("#exchange_rate").val($("#payment_curentcy").val());
		
	//	$("#payment_unit").val('USD');
		de=(Math.ceil(parseInt(Deposit)/parseInt(Curent)));
		Pr=(Math.ceil(parseInt(Priceall)/parseInt(Curent)));	
		//Un="USD";
	}else{
		$("#payment_unit").val('');
		
	}
	$("#payment_deposit").val(de);
	//$(".unitpment").html("  "+Un);
	//$(".unitpmentfee").html("  "+Un);
			CLEAR_ADMINUNIT("unitpment");
 			var UNIT = document.getElementById("unitpment"); 	
			var UNIT2 = document.getElementById("unitpmentfee"); 	
			  var option = null;
			  for(i=0;i<ArUnit.length;i++){
			   	 option = document.createElement("option");
			  	 option.setAttribute("value",ArUnit[i]);
			   	 option.appendChild(document.createTextNode(ArUnit[i]));
			   	 UNIT.appendChild(option);
			  }
			  	$(".unitpmentfee").html("  "+ArUnit[0]);
			 	 
	  
			  	  
	//$(".depo").html(" "+addCommas(de)+" USD ");
	//$(".tocost").html(" "+addCommas(Pr)+" USD ");
	$("#payment_price").val(de);
}

function AdUnitFEE(Un){
	$(".unitpmentfee").html("  "+Un);
}


	function CLEAR_ADMINUNIT(ID) {
 		   var UNIT = document.getElementById(ID);
   		   while(UNIT.childNodes.length > 0) 
		   {
              UNIT.removeChild(UNIT.childNodes[0]);
           }
	}




function ChkUpdatePayment(){
	//Unit=$("#payment_unit").val();
	Deposit=$("#payment_deposit").val();
	Curent=$("#payment_curentcy").val();
	Totalprice=$("#payment_price").val();
	Exchrate=$("#exchange_rate").val();
	if($("#payment_type").val()==""){
		alert("Select type of payment.");
		$("#payment_type").focus();
		return false;
	}else if($("#payment_price").val()==""){
		alert("Enter price.");
		$("#payment_price").focus();
		return false;
	}else if ($("#payment_fee").val()==""){
		alert("Enter payment fee.");
		$("#payment_fee").focus();
		return false;
	}else if(Exchrate==""){
		alert("Enter exchange rate");
		$("#exchange_rate").focus();
		return false;	
	}else{
			$("#act").val('addPayment');
			if(confirm("Confirm submit?")==true){
				document.updtPay.submit();
			}
	}
}
function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function searchRoomEmpty(){
		arrv=$("#arrivaldate").val();
		dep=$("#departuredate").val();
	if(dep<=arrv){
		alert('Departure  date not less  than  arrival date');
		return false;
	}else{
		$("#raction").val('emptyRoom');
		document.block_room.submit();
	}
}

function AddToroomCheck(){

	
	name=$("#cust_uname").val();	
	Croom=$("#Croomtype").val();
	//alert(Croom)
	tel=$("#cust_utel").val();
	if(name==""){
		alert("Enter customer name.");
		$("#cust_uname").focus();
		return false;
	}else if(tel==""){
		alert("Enter customer telephone.");
		$("#cust_utel").focus();
		return false;		
	}else{
		$("#raction").val('addTochkroom');
		if(confirm("Confirm submit ?")==true){
			document.block_room.submit();	
		}
	}
}

function SearchBySpecialID(){
	if($("#specialID").val()==""){
		alert("Enter special id");
		$("#specialID").focus();
		return false;
	}else{
		$("#actmanage").val('Searchr');
		document.update_rm.submit();
	}
}

function Editchange_roomblock(spid){
			Path=$("#admin_p").val();	
			ardate=$("#arrSdate").val();	
			img=$("#img").val();	
			var img_waiting="<div style='text-align:center;padding-top:50px;'><img src="+img+"working.gif></div>";
			$.get(Path+"ajax_getformedit.php",{Spid:spid,allrdate:ardate},
			function(data){	
				$(".editroom").html(img_waiting);							
				$(".editroom").fadeOut(1500,function(){
				$(".editroom").html(data).fadeIn(400);})
			});
}

function edit_roomblock(SID,AD){
	if(confirm("Confirm change amount of room ?")==true){
		Path=$("#admin_p").val();	
		allroom=$("#allroomtype").val();
		cusN=$("#cusnames").val();
		cusE=$("#cusemails").val();
		cc="roomslc";
		Rall="";
		for(i=1;i<=allroom;i++){
			cl="#"+cc+i;
			if($(cl).val()!=""){
				Rall =Rall+"#"+$(cl).val();
			}
		}
		$.get(Path+"ajax_editroom.php",{Spid:SID,allrdate:AD,rAll:Rall,Act:'Edit',Cname:cusN,Cemail:cusE},
		function(data){	
			$(".showres").fadeOut(500,function(){
			$(".showres").html(data).fadeIn(800);})
			$(".editroom").fadeOut(300,function(){
			$(".editroom").html('').fadeIn(400);})
		});
	}
}
function DeleteRoomBlock(spID,Dts,E){
	if(E!="" && $("#refund").val() ==""){
		if($("#refund").val()==""){
			alert("Select refund Y or N ");
			return false;
		}
	}else if ( E=="" || $("#refund").val() !=""){
		if($("#refund_by").val()==""){
			alert('Select refund by.');
			$("#refund_by").focus();
			return false;
		}else if($("#refund_amount").val()==""){
			alert('Enter refund amount');
			$("#refund_amount").focus();
			return false;
		}
		//alert($("#refund").val())
		if(confirm('Confirm cancel?')==true){
			//alert($("#refund").val())
			Path=$("#admin_p").val();	
			if($("#refund").val()){
				refres=$("#refund").val();
				Refdate=$("#ref_year").val()+"-"+$("#ref_month").val()+"-"+$("#ref_day").val();
				RefBy=$("#refund_by").val();
				RefAm=$("#refund_amount").val();
				RefRemark=$("#refund_remark").val();
				//if($("#refund").val()=="Yes")
				Refunduser=$("#refund").val();
			}else{
				refres="";	
				Refdate="";
				RefBy=""
				RefAm="";
				RefRemark="";
				Refunduser="";
			}
			allroom=$("#allroomtype").val();
			cusN=$("#cusnames").val();
			cusE=$("#cusemails").val();
			Path=$("#admin_p").val();	
			$.get(Path+"ajax_editroom.php",{Spid:spID,allrdate:Dts,Act:'Delete',Cname:cusN,Cemail:cusE,Ref:refres,Redte:Refdate,Rby:RefBy,Rfam:RefAm,Rremrk:RefRemark,RefUser:Refunduser},
			function(data){	
				$(".showres").fadeOut(500,function(){
				$(".showres").html(data).fadeIn(800);})	
				$(".editroom").fadeOut(300,function(){
				$(".editroom").html('').fadeIn(400);})
			});
		}
	}
}
function checknumkey(evt){
var charCode = (evt.which) ? evt.which : event.keyCode;

	if (charCode ==13){ 
		 return SearchInvoice();
	}
}
function show_descripreserv(inv){
	Path=$("#admin_p").val();	
	Refsel=$("#refund").val();
	img=$("#img").val();
	var img_waiting="<div style='text-align:center;padding-top:50px;'><img src="+img+"working.gif></div>";
	if(Refsel=="yes"){
			$.get(Path+"ajax_getformrefund.php",{invoice:inv},
			function(data){	
				$(".editroom").html(img_waiting);							
				$(".editroom").fadeOut(300,function(){
				$(".editroom").html(data).fadeIn(400);})
			});
	}else{
				$(".editroom").fadeOut(300,function(){
				$(".editroom").html('').fadeIn(400);})						
	}
}
function GetUnitRefund(){
	Reftype=$("#refund_by").val();

	ReftShow=(Reftype=="paypal")?"USD":"THB";
	$(".unitrefund").html(ReftShow);
	//if(Re)
}
function logoutadmin(){
			turn=$("#url").val();
			Admpth=$("#adminpath").val();
		//	alert(Admpth)
			$.get(Admpth+"ajax_adminlogout.php",{logouturl:turn},
			function(data){	
	//	alert(data)
		//	document.execCommand("ClearAuthenticationCache",false);
			window.location=data;
			//location.href=data;
			});
}
function GetUserReservation(Resby,Resdate,Rid){
			$.get("ajax_user_reserv.php",{restby:Resby,restdt:Resdate,roomid:Rid},
			function(data){	
				
				$(".tbl_show").html(data);
			});
}
function GetDesReserv(inv,reststate){
			img=$("#img").val();
			var img_waiting="<div style='text-align:center;padding-top:50px;'><img src="+img+"working.gif></div>";
			$.get("ajax_showdest.php",{invoice:inv,stateRst:reststate},
			function(data){	
			
				$(".right_reserv").html(img_waiting);							
				$(".right_reserv").fadeOut(800,function(){
				$(".right_reserv").html(data).fadeIn(1000);})
			});
}

function ShowDescriptadmin(inv){
			img=$("#img").val();
			var img_waiting="<div style='text-align:center;padding-top:50px;'><img src="+img+"working.gif></div>";
			$.get("ajax_descripton_report1.php",{invoice:inv},
			function(data){	
				$(".descriptshow1").html(img_waiting);							
				$(".descriptshow1").fadeOut(800,function(){
				$(".descriptshow1").html(data).fadeIn(1000);})
			});
}


///INFORM PAYMENT

function getUnitroselectbox(Val){
	 var UNIT = document.getElementById("unit_money"); 
	 CLEAR_Unitroselectbox();
	if(Val!=""){
			if(Val=="kasikorn"){
				var ArUnit=new Array("THB","USD","EUR","JPY","GBP","NZD","HKD","SGD","CHF");
			}else if(Val=="paypal"){
				var ArUnit=new Array("USD");
			}
			
			  var option = null;
			  for(i=0;i<ArUnit.length;i++){
			   	 option = document.createElement("option");
			  	 option.setAttribute("value",ArUnit[i]);
			   	 option.appendChild(document.createTextNode(ArUnit[i]));
			   	 UNIT.appendChild(option);
			  }
	}
}
	function CLEAR_Unitroselectbox() {
 		   var UNIT = document.getElementById("unit_money");
   		   while(UNIT.childNodes.length > 0) 
		   {
              UNIT.removeChild(UNIT.childNodes[0]);
           }
	}
	function check_inform(){
		if($("#payment_type").val()==""){
			alert("Select Payment type");
			$("#payment_type").focus();
			return false;
		}else if($("#am_money").val()==""){
			alert("Input money");
			$("#am_money").focus();
			return false;
		}else {
				if(confirm("Confirm  inform payment")==true){
					return true;
				}else{
					return false;
				}
				
		}
	}

/////Member	Direct message
function GetMemberShowByMenu(pg,LCS){
	
	if(LCS=="m1"){
		$("#m1").addClass("menuactive");
		$("#m2").removeClass("menuactive");
		$("#m3").removeClass("menuactive");
		$("#m4").removeClass("menuactive");
	}else if(LCS=="m2"){
		$("#m2").addClass("menuactive");
		$("#m1").removeClass("menuactive");
		$("#m3").removeClass("menuactive");
		$("#m4").removeClass("menuactive");
	}else if(LCS=="m3"){
		$("#m3").addClass("menuactive");
		$("#m1").removeClass("menuactive");
		$("#m2").removeClass("menuactive");
		$("#m4").removeClass("menuactive");		
	}
		if(pg!="dashboard"){
			$.get("user_inbox.php",{Pgn:pg},
			function(data){
				//$(".box_page").html(data);							
				$(".UserprofileBox").fadeOut(300,function(){
				$(".UserprofileBox").html(data).fadeIn(400);})
			});
			//$(".box_page").html(pg);
		}else{
			//alert(pg)
			URL=$("#url").val();
			//alert(URL)
			location.href=URL;
			//GetMemberShowByMenu('dashboard','m1');
		}
	
}
function swapPg(pid,pg){
			$.get("message_show.php",{qid:pid,Pge:pg},
			function(data){
				B=data.split("||");
				$("#m2").html(B[1]);
				//$(".box_page").html(B[0]);	
				$(".UserprofileBox").fadeOut(300,function(){
				$(".UserprofileBox").html(B[0]).fadeIn(400);})
					});
			
}
function getadminpg(tpg,pid){
	$.get("messageadmin_show.php",{qid:pid,Pge:tpg},
	function(data){
		//B=data.split("||");
		//$("#m2").html(B[1]);
		$(".directmsgbox").fadeOut(300,function(){
		$(".directmsgbox").html(data).fadeIn(400);})
	});
}
function lcateback(URL){
	location.href=URL;
}
/////Replymessage Admin
function Send_replymessage(Qid){
	Ms=encodeURI(document.getElementById('replymsg').value);
	c=Qid+"##"+Ms;
	img=$("#img").val();
	var img_waiting="<div style='height:50px; text-align:center; padding-top:20px;width:200px;color:#FF6600;'>System working..<img src=\""+img+"working.gif\" /></div></div>";
	$(".boxform").html(img_waiting);
	setTimeout("SenMgessage('"+c+"')",3000);
}
function SenMgessage(d){
	sx=d.split("##");
	$.get("reply.php",{Qid:sx[0],Msg:sx[1]},
	function(data){
		if(data=="Complete"){
			txt="Reply message are successfull";
		}else{
			txt="Reply message are unsuccessfull . Please Try again";
		}
		$(".boxform").html(txt);
	});
}

