// 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=="upload"){     
	    //var r = document.referrer;
            window.location.href = '/';
          } 
        }
      }
    }
    var remember = '';
    if(mem==true) { remember = 'y'; }
    if(action=="up") { 
//alert(cancle);
    }

    req.open("POST", "/check_user_index.php"); //????? connection
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //header
    req.send("mobile="+encodeURIComponent(username)+"&code="+encodeURIComponent(passwd)+"&remember="+encodeURIComponent(remember)+"&action="+encodeURIComponent(action)); //??????
  }
  return false;
}

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