﻿// JScript 文件
var xmlHttp;
    //创建XMLHttpRequest对象
function createXMLHttpRequest(){
	// (@_jscript_version >= 5)
    try{
	    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
	    try {
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e2) {
		    xmlHttp = false;
	    }
    }

    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	    xmlHttp = new XMLHttpRequest();
    }
}

var phoneNumber;
function chocolatePhone(phone,state)
{
    createXMLHttpRequest();
    if(state==2)
    {alert("对不起！"+phone+"已被预占！");return false;}
    if(state==3)
    {alert("对不起！"+phone+"已开通！");return false;}
    else{
        if(confirm("是否确定预占"+phone))
        {
            window.location.href="AgentEnrollment.aspx?phone="+phone;
        }
    }
    //window.open("AgentEnrollment.aspx?phone="+phone,"");
    
    
//    phoneNumber=phone;
//    
//    //alert("createXMLHttpRequest");
//    xmlHttp.onreadystatechange = handleStateChangeName;
//    
//    var path = "Default.aspx?phone="+phone;  //小写value
//    //alert(path);
//    
//    xmlHttp.open("GET",path,true);　//GET传递值的方法．
//	xmlHttp.send();
	
    //return true;
}

function showHintInfo(){
    var res = xmlHttp.responseText;
    //alert(res);
    if(res=="1")
    {   
        if(confirm("您还没有注册代理商信息，是否先注册！"))
        {
            window.open("AgentEnrollment.aspx","")
        }
    }
    else
    if(res=="no")
    {
        alert("您还没有登录，请先登录！");
    }else
    if(res=="3")
    {
        alert(phoneNumber+"已被占用！");
    }else
    if(res=="4")
    {
        alert("恭喜，预占"+phoneNumber+"成功！");
    }else
    if(res=="5")
    {
        alert("预占"+phoneNumber+"失败！");
    }
}

//回调函数
function handleStateChangeName(){
    //alert(xmlHttp.readyState+" "+xmlHttp.status);	
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){					
		    showHintInfo();
		}else
		{
		    alert(xmlHttp.status);
		    alert("服务器繁忙请稍后再试!");   
		}
	}
}
