//=========================================================================================
// AJAX Scripts
//=========================================================================================
//***** Check input DATA 
function checkDataYouTube()
{
                               if(document.getElementById("catvideo").value=="")
	                                   {  alert('คุณยังไม่ได้เลือก Category ');
	                                     return false;
                                    	} 
							else if(document.getElementById("url").value=="")
	                                   {  alert('คุณยังไม่ได้ใส่ Address ของคลิปวีดีโอ ');
	                                      return false;
	                                  }
							else {
                                     return true;
							        }

}

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;

function checkmail(e)
{
          var returnval=emailfilter.test(e.value)
          if (returnval==false)
			  {
                      alert("รูปแบบของ email ของคุณไม่ถูกต้องกรุณาตรวจสอบอีกครั้ง\nPlease enter a valid email address.");
              }	
		else	{    return returnval; 	}
}

function checkcode(c1,c2)
{
       if(c1!=c2)
		     {
                      alert("คุณกรอกรหัสภาพไม่ตรงกับข้อความในภาพกรุณาลองใหม่อีกครั้ง\nCode not match picture code please try again.");
              }	
	  else	{    return c1; 	}
}

function checkInputData()
{  var registerData='ok';
    var checkData='ok';
     
// Check Input Data ========================================================

                               if(document.getElementById("username").value=="")
	                                   {  alert('คุณยังไม่ได้กรอกชื่อผู้ใช้งาน\nPlease fill user name. ');
	                                        registerData='nook';	    
                                    	}
                         	 if(document.getElementById("pws").value=="")
	                                   {  alert('คุณยังไม่ได้กำหนดรหัสผ่าน\nPlease fill password. ');
	                                       registerData='nook';	    
	                                  }
							 if(document.getElementById("pws").value != document.getElementById("cpws").value)
	                                   {  alert('ยืนยันรหัสผ่าน ไม่ตรงกับรหัสที่ตั้งไว้กรุณาตรวจสอบอีกครั้ง\nConfirm password not match.');
	                                       registerData='nook';	    
	                                  }	  
                        	 if(document.getElementById("email").value=="")
	                                 {  alert('คุณยังไม่ได้ใส่อีเมลล์\nPlease fill email. ');
	                                      registerData='nook';	    
	                                  }
					//		 if(document.getElementById("email").value!="")
                         //        	{ checkmail(document.getElementById("email"));
	                   //             }
                         	 if(document.getElementById("sex").value=="")
	                                 {  alert('เลือกเพศของคุณด้วยจ้า\nPlease select sex. ');
	                                      registerData='nook';	    
	                                  }
	                        if(document.getElementById("code").value=="")
	                                 {  alert('คุณยังไม่ได้กรอก code รูปภาพ\nPlease fill code. ');
	                                     registerData='nook';	    
	                                 }
								
// Data Input True Case ======================================================

                          if(registerData=='ok')
	                                {
							      				 if(document.getElementById("ch_user").value=="no")
	                                               {  alert('ชื่อผู้ใช้งานนี้มีผู้ใช้แล้ว กรุณาตั้งชื่อใหม่\nCan not use this user please check user name again. ');
	                                                   checkData='nook';	    
	                                               }
												 if(document.getElementById("ch_email").value=="no")
	                                               {  alert('Email นี้ได้ใช้สมัครแล้วกรุณาใช้ email อื่น\nCan not use thsi email please change eamil. ');
	                                                   checkData='nook';	    
	                                               }
                                     if(checkData=='ok')
	                                            {
							                            var returncheckemail=checkmail(document.getElementById("email"));
									           	 if(returncheckemail==true)
										                {
								                               var c1=document.getElementById("code").value;
								                     		  var c2=document.getElementById("codehidden").value;
							                    		      var returncode=checkcode(c1,c2);
										        if(returncode==c1)
										            			registerMember();
										            	}
												}
								}
}      


/*
===================================================
 START AJAX 
===================================================
*/

var xmlHttp;
var querystr="";
var str;


// Requrst XMLHttp
function createXMLHttpRequest()
{

			if (window.XMLHttpRequest){    
			            xmlHttp=new XMLHttpRequest();
				}
			else if (window.ActiveXObject){    
			             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			     }
			 else {  alert("Browser not support"); 
			               return false;
			     }
		
}

/*
===================================================
LOADING ..........
===================================================
*/
// Download Video

 function stateRequest()
 {           createXMLHttpRequest();

             var url=document.getElementById('url').value;
			 var selectsite=document.getElementById('selectsite').value;
			 var selectcat=document.getElementById('selectcat').value;
			 var downloadvdo=0;

              if(url==""){           
				       alert("คุณยังไม่ได้ใส่ Address สำหรับ Download คลิปวีดีโอ \nPlese input address video clip. ");
					   downloadvdo=1;}

			  if( selectsite == ""){
			           alert("คุณยังไม่ได้เลือกเว็บไซต์ที่คุณต้องการ Download \nPlese select website for download video clip. "); 
					   downloadvdo=1;} 
			  if( selectcat == ""){
			           alert("คุณยังไม่ได้เลือกหมวด Clip video \nPlese select category. ");
					   downloadvdo=1;} 
      
               if(downloadvdo==0){
				        if(selectsite=="mthai"){
								      xmlHttp.onreadystatechange=responseAreaDownload;								  
								      str=Math.random();
									  querystr+="load_mthai.php?rdc="+str;
									  querystr+="&url="+url;
									  querystr+="&website="+selectsite;
									  querystr+="&catvideo="+selectcat;
		                              xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);  
						} else if(selectsite=="dailymotion"){
							            xmlHttp.onreadystatechange=responseAreaDownload;								  
								      str=Math.random();
									  querystr+="load_dailymotion.php?rdc="+str;
									  querystr+="&url="+url;
									  querystr+="&website="+selectsite;
									  querystr+="&catvideo="+selectcat;
		                              xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);  
						} else if(selectsite=="break"){
							            xmlHttp.onreadystatechange=responseAreaDownload;								  
								      str=Math.random();
									  querystr+="load_break.php?rdc="+str;
									  querystr+="&url="+url;
									  querystr+="&website="+selectsite;
									  querystr+="&catvideo="+selectcat;
		                              xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);  
						} else if(selectsite=="sanook"){
							            xmlHttp.onreadystatechange=responseAreaDownload;								  
								      str=Math.random();
									  querystr+="load_sanook.php?rdc="+str;
									  querystr+="&url="+url;
									  querystr+="&website="+selectsite;
									  querystr+="&catvideo="+selectcat;
		                              xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);  
						 } else if(selectsite=="youtube"){
							            xmlHttp.onreadystatechange=responseAreaDownload;								  
								      str=Math.random();
									  querystr+="load_youtube.php?rdc="+str;
									  querystr+="&url="+url;
									  querystr+="&website="+selectsite;
									  querystr+="&catvideo="+selectcat;
		                              xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);  
						}

			   }
			   document.chooser_form_2.url.value="";
}
// Page videos
function pageVideos()
{              createXMLHttpRequest();

                                       xmlHttp.onreadystatechange=responseAreaMain;
                                      str=Math.random();
                                      querystr ="videos.php?rdc="+str;
		                              xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);  

}
//  Load Register
function loadRegister()
{              createXMLHttpRequest();
                var joinnow=document.getElementById('agree').checked;

				if(joinnow ==false){ alert("คุณยังไม่ได้ตกลงยอมรับเงื่อนไข");}
				else {

                                       xmlHttp.onreadystatechange=responseAreaRegister;
                                      str=Math.random();
                                      querystr ="register.php?rdc="+str;
		                              xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null); 
				}

}

// Load Sign In
function checkSignIn()
{              createXMLHttpRequest();

                                      xmlHttp.onreadystatechange=responseAreaSignIn;
                                      str=Math.random();
                                      querystr ="signin.php?rdc="+str;
									  querystr +="&userSignIn="+document.signin.userSignIn.value;
									  querystr +="&pwsSignIn="+document.signin.pwsSignIn.value;
									  querystr +="&autoSignIn="+document.getElementById("autoSignIn").checked;
		                              xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);  

}
// Load Sign Out
function checkSignOut()
{              createXMLHttpRequest();

                                      xmlHttp.onreadystatechange=responseAreaSignIn;
                                      str=Math.random();
                                      querystr ="signout.php?rdc="+str;
		                              xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);  

}

//  Load check user name
function checkusername()
{           
      createXMLHttpRequest();

                                      xmlHttp.onreadystatechange=responseAreaCheckName;
                                      str=Math.random();
                                      querystr ="check-user-name.php?rdc="+str;
									  querystr+="&username="+document.register.username.value;
									  xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);

}

//  Load check email
function checkemail()
{           
      createXMLHttpRequest();

                                      xmlHttp.onreadystatechange=responseAreaCheckEmail;
                                      str=Math.random();
                                      querystr ="check-uniqee-mail.php?rdc="+str;
									  querystr+="&email="+document.register.email.value;
									  xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);

}

//  Load register member

function registerMember()
{           
      createXMLHttpRequest();

                                      xmlHttp.onreadystatechange=responseAreaRegister;
                                      str=Math.random();
                                      querystr ="welcome.php?rdc="+str;
									  querystr+="&username="+document.register.username.value;
									  querystr+="&pws="+document.register.pws.value;
									  querystr+="&email="+document.register.email.value;
									  querystr+="&sex="+document.register.sex.value;
									  
								      xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);

}

// VIP =============================================================================
function registerVIP()
{           
      createXMLHttpRequest();

                                      xmlHttp.onreadystatechange=responseAreaVIP;
                                      str=Math.random();
                                      querystr ="vip-register.php?rdc="+str;
									  querystr+="&username="+document.getElementById("username").value;
									  querystr+="&memberid="+document.getElementById("memberid").value;
									  querystr+="&vipdate="+document.getElementById("vipdate").value;
									  
								      xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);

}

function bankVIP()
{           
      createXMLHttpRequest();

                                      xmlHttp.onreadystatechange=responseAreaBankVIP;
                                      str=Math.random();
                                      querystr ="vip-bank.php?rdc="+str;
									  querystr+="&atm="+document.getElementById("atm").value;
									  querystr+="&bank="+document.getElementById("bank").value;
									  querystr+="&location="+document.getElementById("location").value;
									  querystr+="&pay="+document.getElementById("pay").value;
									  querystr+="&datepay="+document.getElementById("datepay").value;
									  querystr+="&timepay="+document.getElementById("timepay").value;
									  querystr+="&memberid2="+document.getElementById("memberid2").value;
									  
								      xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);

}

function updateMember()
{           
      createXMLHttpRequest();

                                      xmlHttp.onreadystatechange=responseAreaVIP;
                                      str=Math.random();
                                      querystr ="vip-member-update.php?rdc="+str;
									  querystr+="&mName="+document.getElementById("mName").value;
									  querystr+="&mSurname="+document.getElementById("mSurname").value;
									  querystr+="&mAddress="+document.getElementById("mAddress").value;
									  querystr+="&telephone="+document.getElementById("telephone").value;
									  querystr+="&vipid="+document.getElementById("vipid").value;
									 									  
								      xmlHttp.open("GET", querystr ,true);
			                          xmlHttp.send(null);

}
// KeepVid
function LoadMthai()
{           
	              if(document.getElementById("catvideo").value==""){           
				       alert("คุณยังไม่ได้เลือกหมวดหมู่ของวีดีโอ. ");
					 } else {

      createXMLHttpRequest();

                                      xmlHttp.onreadystatechange=responseAreaMthaiFLV;
                                      str=Math.random();
                                      querystr ="load_mthai.php?rdc="+str;
									  querystr+="&url="+document.getElementById("url").value;
									  querystr+="&server="+document.getElementById("server").value;
									  querystr+="&catvideo="+document.getElementById("catvideo").value;
									  querystr+="&source="+document.getElementById("source").value;
									 									  
								      xmlHttp.open("GET", querystr ,true);
									  xmlHttp.send(null);
									 // xmlHttp.open("POST", querystr ,true);
			                          
					 }
}
/*
===================================================
 Active Area
===================================================
*/
 function responseAreaSignIn()
{
               if ( xmlHttp.readyState==4){
                           document.getElementById("AreaSignIn").innerHTML=xmlHttp.responseText;
				}
				else {
							document.getElementById("AreaSignIn").innerHTML="<center><img src=/images/loading_animation.gif><br>Please wait...</center>";
 				}
 }
  function responseAreaMain()
{
               if ( xmlHttp.readyState==4){
                           document.getElementById("AreaMain").innerHTML=xmlHttp.responseText;
				}
				else {
							document.getElementById("AreaMain").innerHTML="<center><img src=/images/loading_animation.gif><br>Please wait...</center>";
 				}
 }
 
 function responseAreaCheckName()
{
               if ( xmlHttp.readyState==4){
                           document.getElementById("areaCheckname").innerHTML=xmlHttp.responseText;
				}
				else {
							document.getElementById("areaCheckname").innerHTML="<img src=/images/loading_animation.gif><br>Please wait...<br>";
 				}
 }
  function responseAreaCheckEmail()
{
               if ( xmlHttp.readyState==4){
                           document.getElementById("areaCheckemail").innerHTML=xmlHttp.responseText;
				}
				else {
							document.getElementById("areaCheckemail").innerHTML="<img src=/images/loading_animation.gif><br>Please wait...<br>";
 				}
 }
 
function responseAreaDownload()
{
               if ( xmlHttp.readyState==4){
                           document.getElementById('areaDownload').innerHTML=xmlHttp.responseText;
				}
				else {
							document.getElementById('areaDownload').innerHTML="<img src=/images/loading_animation.gif><br>Please wait...<br>";
 				}
 }

 function responseAreaRegister()
{
               if ( xmlHttp.readyState==4){
                           document.getElementById('areaRegister').innerHTML=xmlHttp.responseText;
				}
				else {
							document.getElementById('areaRegister').innerHTML="<img src=/images/loading_animation.gif><br>Please wait...<br>";
 				}
 }

  function responseAreaVIP()
{
               if ( xmlHttp.readyState==4){
                           document.getElementById('areaVIP').innerHTML=xmlHttp.responseText;
				}
				else {
							document.getElementById('areaVIP').innerHTML="<img src=/images/loading_animation.gif><br>Please wait...<br>";
 				}
 }

   function responseAreaBankVIP()
{
               if ( xmlHttp.readyState==4){
                           document.getElementById('bankVIP').innerHTML=xmlHttp.responseText;
				}
				else {
							document.getElementById('bankVIP').innerHTML="<img src=/images/loading_animation.gif><br>Please wait...<br>";
 				}
 }

    function responseAreaMthaiFLV()
{
               if ( xmlHttp.readyState==4){
                           document.getElementById('mthaiflv').innerHTML=xmlHttp.responseText;
				}
				else {
							document.getElementById('mthaiflv').innerHTML="<img src=/images/loading_animation.gif><br>Please wait...<br>";
 				}
 }
