// JavaScript Document
function Inint_AJAX() {
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
};

function check_user(username, passwd, mem, action) {
  var cancle=false;
  if (action=='sms') {
    if (username.length==0) {
      alert('กรุณาใส่เบอร์มือถือ');
      document.form_vip.mobile.focus(); 
      cancle=true;
    } else if (passwd.length==0) {
      alert('กรุณาใส่ code') ;
      document.form_vip.code.focus();
      cancle=true;
    }
	else {
		var Data = "กำลังตรวจสอบ...";
		document.getElementById("vip").innerHTML=Data;
		//cancle=true;
	}
  }
  if (cancle==false) {
    var req = Inint_AJAX();
	req.onreadystatechange = function () {
      if (req.readyState==4) {
        if (req.status==200) {
          var ret=req.responseText; //รับค่ากลับคืนมา
          datas=ret.split('||');
          var aAction = datas[0];          
          var aData = datas[1];  
          //alert(aData);
          document.getElementById("vip").innerHTML=aData;
          if (aAction=="download"){
	    document.getElementById("count").style.display="none";
            document.getElementById("wait").style.display="none";
            document.getElementById("fileinfo").style.display="none";
            document.getElementById("sfileinfo").style.display="block";

            document.download_form.action = "http://download.tempfiles.net/getfiles.php";
            document.download_form.method = "get";
          } 
        }
      }
    }
    var remember = '';
    if(mem==true) { remember = 'y'; }
    req.open("POST", "/check_user.php"); //????? connection
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //header
    req.send("mobile="+encodeURIComponent(username)+"&code="+encodeURIComponent(passwd)+"&remember="+encodeURIComponent(remember)+"&action="+action); //??????
  }
  return false;
}

//????????????
window.onload = function()
{
  check_user( '', '', '' );
};

