// JavaScript Document

<!-- 

// JavaScript Document
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- # , +";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 9;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}



		function getCheckedValue(radioObj) {
			if(!radioObj)
			   {
			    alert(radioObj);
				return "";
			   }
			var radioLength = radioObj.length;
			if(radioLength == undefined)
				if(radioObj.checked)
					return radioObj.value;
				else
					return "";
			for(var i = 0; i < radioLength; i++) {
				if(radioObj[i].checked) {
					return radioObj[i].value;
				}
			}
			return "";
		}
		
		
		
		

	function Checkform() {

            if (document.form_sampling.name.value == "")
										
               {
			   
			   alert("กรุณากรอกชื่อค่ะ"); 
			   document.form_sampling.name.focus(); 
			   return false; 
			   
			   }
			   

			   
			 if (document.form_sampling.phone.value == "")
										
               {
			   
			   alert("กรุณากรอก เบอร์โทรศัพท์ที่ติดต่อได้สะดวกค่ะ และคุณจะได้รับการวิเคราะห์น้ำหนักจากผู้เชี่ยวชาญเฉพาะผู้ที่ติดต่อได้ทางโทรศัพท์เท่านั้น"); 
			   document.form_sampling.phone.focus(); 
			   return false; 
			   
			   }
		var Phone=document.form_sampling.phone.value;	
			
			   	if ((Phone==null)||(Phone=="")){
		alert("กรุณากรอก เบอร์โทรศัพท์ที่ติดต่อได้สะดวกค่ะ");
		document.form_sampling.phone.focus();
		return false;
	}
	if (checkInternationalPhone(Phone)==false){
		alert("กรุณากรอก เบอร์โทรศัพท์ของคุณ ให้ถูกต้องค่ะ หากมีมากกว่า 1 เบอร์ให้คั่นด้วยเครื่องหมาย , หรือหากมีเบอร์ต่อ ให้คั่นด้วยเครื่องหมาย # เช่น 027777777ต่อ102 ให้เขียนเป็น 027777777#102");
		Phone="";
		document.form_sampling.phone.focus();
		return false;
	}
			   
			     if (document.form_sampling.email.value == "")
										
               {
			   
			   alert("กรุณากรอกอีเมล์ของคุณค่ะ หากไม่มี กรุณากรอกคำว่า \" ไม่มี \" "); 
			   document.form_sampling.email.focus(); 
			   return false; 
			   
			   }
			  

			   if (document.form_sampling.weight.value == "")
										
               {
			   
			   alert("กรุณากรอกน้ำหนัก เป็นกิโลกรัมนะคะ เพื่อที่ผู้เชี่ยวชาญของเราจะนำไปวิเคราะห์และให้คำแนะนำค่ะ"); 
			   document.form_sampling.weight.focus(); 
			   return false; 
			   
			   }
			   
			   if (document.form_sampling.height.value == "")
										
               {
			   
			   alert("กรุณากรอกส่วนสูง เป็นเซนติเมตรค่ะ เพื่อที่ผู้เชี่ยวชาญของเราจะนำไปวิเคราะห์และให้คำแนะนำค่ะ");
			   document.form_sampling.height.focus(); 
			   return false; 
			   
			   }
			   
			   
			   
			   if (document.form_sampling.age.value == "")
										
               {
			   
			   alert("กรุณากรอกอายุ เพื่อที่ผู้เชี่ยวชาญของเราจะนำไปวิเคราะห์และให้คำแนะนำค่ะ");
			   document.form_sampling.age.focus(); 
			   return false; 
			   
			   }
			   
			   
			    if (document.form_sampling.cus_reason.value == "")
										
                                     { alert("กรุณากรอกเหตุผล หรือแรงบันดาลใจว่าทำไมคุณจึงต้องการแก้ปัญหาในครั้งนี้ค่ะ"); document.form_sampling.cus_reason.focus(); return false; }
									 
				
							
			if (document.form_sampling.provincelist.value=="noneprovince")
	  {
		alert("คุณยังไม่ได้เลือกที่อยู่นะคะ \"กรุณาเลือกเลือกจังหวัดค่ะ\" ");
		document.form_sampling.provincelist.focus();
		return (false);
	  }
			
				
				
				
				var gsubscribe;
			for (i=0;i<document.form_sampling.subscribe.length;i++)
				   {
			      if(document.form_sampling.subscribe[i].checked)
			       gsubscribe=document.form_sampling.subscribe[i].value;
				 }
                   
			if (gsubscribe!="yes" && gsubscribe!="no")
			
			{
				alert("ต้องการรับข่าวสารจากเราหรือไม่คะ");
				return false;
				
			}

			
			
			
			if (document.form_sampling.want_to.value=="noprogram")
	  {
		alert("คุณยังไม่ได้เลือกโปรแกรมที่คุณต้องการวิเคราะห์ค่ะ \"กรุณาเลือกว่าคุณต้องการ ลดน้ำหนัก เพิ่มน้ำหนัก หรือดูแลสุขภาพ\" ");
		document.form_sampling.want_to.focus();
		return (false);
	  }
				
			if (document.form_sampling.serious_tolose.value=="")
	  {
		alert("คุณจริงจังกี่เปอร์เซ็นต์คะ \"กรุณากรอกตัวเลขความจริงจังของคุณค่ะ\" ");
		document.form_sampling.serious_tolose.focus();
		return (false);
	  }		
				
				
		if (document.form_sampling.cus_budget.value=="none_budget")
	  {
	alert("คุณยังไม่ได้เลือกงบประมาณค่ะ \"โดยปรกติคุณใช้งบประมาณในการดูแลตัวคุณเองเดือนละเท่าไหร่คะ\" ");
		document.form_sampling.cus_budget.focus();
		return (false);
	  }
		
		
		
			 /*  var accept_condi="";
			   var num_accept_con =document.form_sampling.elements['accept_con'].length;
			   for (i=0; i <= num_accept_con;i++)
				   {
					   
						   var accept_con =document.form_sampling.elements['accept_con'][i];
						   
						   if(accept_con.checked)
							  {
								   
							    accept_condi = accept_con.value;
								break;
							  }
							  
				   }
			   
			   if (accept_condi != "iaccept")
										
               {
			   
			   alert("คุณต้องยอมรับเงื่อนไขและข้อตกลงของเราก่อน จึงจะสามารถรับโปรโมชั่นนี้ได้ค่ะ");
			 
			   return false; 
			   
			   
			   }*/
			   

				 
				 var cus_name = document.form_sampling.name.value;
				var cus_age = document.form_sampling.age.value;
				var cus_high = document.form_sampling.height.value;
				var cus_weight = document.form_sampling.weight.value;
				var cus_tel = document.form_sampling.phone.value;
				var  cus_reason = document.form_sampling.cus_reason.value;
					
                
			   
			   // alert(cus_name);
			   
			   
			     Set_Cookie( 'cook_name', cus_name, '', '/ltc', '', '' );
				 Set_Cookie( 'cook_set', '1', '', '/ltc', '', '' );
			     writeCookie("cook_name", cus_name); 
				 writeCookie("cook_tel", cus_tel);
				 writeCookie("cook_age", cus_age);
				 writeCookie("cook_high", cus_high);
				 writeCookie("cook_weight", cus_weight);
				 writeCookie("cook_cus_reason", cus_reason);
				 
                 return true;
									
									
				}

				//End Of CheckformFunction
				
	function CheckformSlide() {

            if (document.form_sampling.name.value == "")
										
               {
			   
			   alert("กรุณากรอกชื่อค่ะ"); 
			   document.form_sampling.name.focus(); 
			   return ; 
			   
			   }
			   

			   
			 if (document.form_sampling.phone.value == "")
										
               {
			   
			   alert("กรุณากรอก เบอร์โทรศัพท์ที่ติดต่อได้สะดวกค่ะ"); 
			   document.form_sampling.phone.focus(); 
			   return ; 
			   
			   }
			  

			   if (document.form_sampling.weight.value == "")
										
               {
			   
			   alert("กรุณากรอกน้ำหนัก เป็นกิโลกรัมนะคะ เพื่อที่ผู้เชี่ยวชาญของเราจะนำไปวิเคราะห์และให้คำแนะนำค่ะ"); 
			   document.form_sampling.weight.focus(); 
			   return ; 
			   
			   }
			   
			   if (document.form_sampling.height.value == "")
										
               {
			   
			   alert("กรุณากรอกส่วนสูง เป็นเซนติเมตรค่ะ เพื่อที่ผู้เชี่ยวชาญของเราจะนำไปวิเคราะห์และให้คำแนะนำค่ะ");
			   document.form_sampling.height.focus(); 
			   return ; 
			   
			   }
	}
				
				
				
				
				
				
				
				
				
				
				
				
				//Bof CheckformFunctionAjax
				
  function CheckformAjax() {

            if (document.form_sampling.name.value == "")
										
               {
			   
			   alert("กรุณากรอกชื่อค่ะ"); 
			   document.form_sampling.name.focus(); 
			   return false; 
			   
			   }
			   

			   
			 if (document.form_sampling.phone.value == "")
										
               {
			   
			   alert("กรุณากรอก เบอร์โทรศัพท์ที่ติดต่อได้สะดวกค่ะ"); 
			   document.form_sampling.phone.focus(); 
			   return false; 
			   
			   }
			  

			   if (document.form_sampling.weight.value == "")
										
               {
			   
			   alert("กรุณากรอกน้ำหนัก เป็นกิโลกรัมนะคะ เพื่อที่ผู้เชี่ยวชาญของเราจะนำไปวิเคราะห์และให้คำแนะนำค่ะ"); 
			   document.form_sampling.weight.focus(); 
			   return false; 
			   
			   }
			   
			   if (document.form_sampling.height.value == "")
										
               {
			   
			   alert("กรุณากรอกส่วนสูง เป็นเซนติเมตรค่ะ เพื่อที่ผู้เชี่ยวชาญของเราจะนำไปวิเคราะห์และให้คำแนะนำค่ะ");
			   document.form_sampling.height.focus(); 
			   return false; 
			   
			   }
			   

				 
				 cus_name = document.form_sampling.name.value;
				  cus_age = document.form_sampling.age.value;
				   cus_high = document.form_sampling.height.value;
				    cus_weight = document.form_sampling.weight.value;
					
                 writeCookie("cook_name", cus_name);
				 writeCookie("cook_age", cus_name);
				 writeCookie("cook_high", cus_high);
				 writeCookie("cook_weight", cus_weight);
				 
                  
				  var req_user = document.getElementById('req_user').value;
				  //var total_req_user =  document.form_sampling_req.total_req_user.value;
				  var data = "req_user=" + req_user +"&name=" +cus_name;
				  
				  
				  
				  var URL = "mail-submitted.php";
									
				 ajaxLoad("post", URL , data , "ajax_msg");
									
									
				}
				
				
function ComingSoon()
{
	
	alert("Comingsoon! จะเปิดให้บริการเร็วๆนี้ค่ะ");
	
	
}


// -->
