var xmlHttp;

/////////////////////////////////////////////////购物车
function createXMLHTTP()
{
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();//mozilla浏览器
    }
    else if(window.ActiveXObject)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {}
        try
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e)
        {}
        if(!xmlHttp)
        {
            window.alert("不能创建XMLHttpRequest对象实例！");
            return false;
        }
    }
}

function AjaxCheckUserName(username)
{
    createXMLHTTP();
    var url="Ajax.aspx?username="+username+"&cmd=check&temp="+Math.random()+"";   
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    xmlHttp.onreadystatechange=GetAjaxCheckUserName;
    xmlHttp.send(null);
}
function GetAjaxCheckUserName()
{
    if(xmlHttp.readyState==4)//判断对象状态
    {  
        if(xmlHttp.status==200)
        {  
           if(xmlHttp.responseText=="true")
           {
                document.getElementById("drop_3").innerHTML="<span style=color:#5A8F00;>该用户名可以注册</span>";               
           }
           else
           {
                document.getElementById("drop_3").innerHTML="<span style=color:#ff0000;>该用户名已被使用</span>";
                return false;
           }
        }
    }
}

function DeleteCartProduct(gid,xfjf,vipPrice)
{
    createXMLHTTP();
    var url="Ajax.aspx?gid="+gid+"&xfjf="+xfjf+"&vipPrice="+vipPrice+"&cmd=delcartproduct&temp="+Math.random()+"";
    xmlHttp.open("POST",url,true);
    xmlHttp.onreadystatechange=GetDeleteCartProduct;
    xmlHttp.send(null);
}
function GetDeleteCartProduct()
{
    if(xmlHttp.readyState==4)//判断对象状态
    {  
        if(xmlHttp.status==200)
        {  
            location.href="ShopCart.aspx";
        }
    }
}


function update()
{
    document.getElementById("code").src = "VerifyCode/GetVerifyCode.aspx?a="+ Math.random();
}
function update1()
{
    document.getElementById("code1").src = "VerifyCode/GetVerifyCode_1.aspx?a="+ Math.random();
}
function username_on()
{
    document.getElementById("drop").innerHTML="<span style=color:#ff0000;>&nbsp;</span>";
}
function username_off()
{
    var username=document.getElementById("TextBox1").value;
    if(username=="")
    {
        document.getElementById("drop").innerHTML="<span style=color:#ff0000;>请填写用户名</span>";
    }
    else
    {
        document.getElementById("drop").innerHTML="<span style=color:#5A8F00;>&nbsp;</span>";
    }
}
function password_on()
{
    document.getElementById("drop_1").innerHTML="<span style=color:#ff0000;>&nbsp;</span>";
}
function password_off()
{
    var password=document.getElementById("TextBox2").value;
    if(password=="")
    {
        document.getElementById("drop_1").innerHTML="<span style=color:#ff0000;>请填写密码</span>";
    }
    else
    {
        document.getElementById("drop_1").innerHTML="<span style=color:#5A8F00;>&nbsp;</span>";
    }
}
function checkcode_on()
{
    document.getElementById("drop_2").innerHTML="<span style=color:#ff0000;></span>";
}
function checkcode_off()
{
    var checkcode=document.getElementById("TextBox3").value;
    if(checkcode=="")
    {
        document.getElementById("drop_2").innerHTML="<span style=color:#ff0000;>请填写验证码</span>";
    }
    else
    {
        document.getElementById("drop_2").innerHTML="<span style=color:#5A8F00;></span>";
    }
}

function boollogin()
{
    var username=document.getElementById("TextBox1").value;
    var password=document.getElementById("TextBox2").value;
    var checkcode=document.getElementById("TextBox3").value;
    if(username=="")
    {
        document.getElementById("drop").innerHTML="<span style=color:#ff0000;>请填写用户名</span>";
        return false;
    }
    else if(password=="")
    {
        document.getElementById("drop_1").innerHTML="<span style=color:#ff0000;>请填写密码</span>";
        return false;
    }
    else if(checkcode=="")
    {
        document.getElementById("drop_2").innerHTML="<span style=color:#ff0000;>请填写验证码</span>";
        return false;
    }
    else
    {
        return true;
    }
}

function regusername_on()
{
    document.getElementById("drop_3").innerHTML="<span style=color:#999999;>4-20位字符，可由中英文、数字及“_”、“-”组</span>";
}
function regusername_off()
{
    var username=document.getElementById("TextBox4").value;
    if(username=="")
    {
        document.getElementById("drop_3").innerHTML="<span style=color:#ff0000;>请填写用户名</span>";
    }
    else if(username.length<4 || username.length>20)
    {
        document.getElementById("drop_3").innerHTML="<span style=color:#ff0000;>用户名长度只能在4-20位字符之间</span>";
    }
    else
    {
        AjaxCheckUserName(username);
    }
}

function regpassword_on()
{
    document.getElementById("drop_4").innerHTML="<span style=color:#999999;>6-16位字符，可由英文、数字及“_”、“-”组成</span>";
}
function regpassword_off()
{
    var password=document.getElementById("TextBox5").value;
    if(password=="")
    {
        document.getElementById("drop_4").innerHTML="<span style=color:#ff0000;>请填写密码</span>";
    }
    else if(password.length<6 || password.length>16)
    {
        document.getElementById("drop_4").innerHTML="<span style=color:#ff0000;>密码长度只能在6-16位字符之间</span>";
    }
    else
    {
        document.getElementById("drop_4").innerHTML="<span style=color:#5A8F00;>填写正确</span>";
    }
}

function qrpassword_on()
{
    document.getElementById("drop_7").innerHTML="<span style=color:#999999;>&nbsp;</span>";
}
function qrpassword_off()
{
    var password=document.getElementById("TextBox5").value;
    var qrpassword=document.getElementById("TextBox7").value;
    if(qrpassword=="")
    {
        document.getElementById("drop_7").innerHTML="<span style=color:#ff0000;>请填写确认密码</span>";
    }
    else if(qrpassword!=password)
    {
        document.getElementById("drop_7").innerHTML="<span style=color:#ff0000;>两次输入的密码不一致</span>";
    }
    else
    {
        document.getElementById("drop_7").innerHTML="<span style=color:#5A8F00;>填写正确</span>";
    }
}

function email_on()
{
    document.getElementById("drop_5").innerHTML="<span style=color:#999999;>接收订单通知、促销活动、找回密码，填写后<span style='color:Red;'>不能修改</span></span>";
}
function email_off()
{
    var email=document.getElementById("TextBox8").value;
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if(email=="")
    {
        document.getElementById("drop_5").innerHTML="<span style=color:#ff0000;>请填写邮箱地址</span>";
    }
    else if(!myreg.test(email))
    {
        document.getElementById("drop_5").innerHTML="<span style=color:#ff0000;>邮箱地址格式不正确</span>";
    }
    else
    {
        document.getElementById("drop_5").innerHTML="<span style=color:#5A8F00;>填写正确</span>";
    }
}

function regcheckcode_on()
{
    document.getElementById("drop_6").innerHTML="<span style=color:#999999;></span>";
}
function regcheckcode_off()
{
    var checkcode=document.getElementById("TextBox6").value;
    if(checkcode=="")
    {
        document.getElementById("drop_6").innerHTML="<span style=color:#ff0000;>请填写验证码</span>";
    }
    else
    {
        document.getElementById("drop_6").innerHTML="<span style=color:#5A8F00;></span>";
    }
}

function boolreg()
{
    var username=document.getElementById("TextBox4").value;
    var password=document.getElementById("TextBox5").value;
    var qrpassword=document.getElementById("TextBox7").value;
    var email=document.getElementById("TextBox8").value;
    var checkcode=document.getElementById("TextBox6").value;
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    
    if(username=="")
    {
        document.getElementById("drop_3").innerHTML="<span style=color:#ff0000;>请填写用户名</span>";
        return false;
    }
    else if(username.length<4 || username.length>20)
    {
        document.getElementById("drop_3").innerHTML="<span style=color:#ff0000;>用户名长度只能在4-20位字符之间</span>";
        return false;
    }
    else if(password=="")
    {
        document.getElementById("drop_4").innerHTML="<span style=color:#ff0000;>请填写密码</span>";
        return false;
    }
    else if(password.length<6 || password.length>16)
    {
         document.getElementById("drop_4").innerHTML="<span style=color:#ff0000;>密码长度只能在6-16位字符之间</span>";
         return false;
    }
    else if(qrpassword=="")
    {
        document.getElementById("drop_7").innerHTML="<span style=color:#ff0000;>请填写确认密码</span>";
        return false;
    }
    else if(qrpassword!=password)
    {
        document.getElementById("drop_7").innerHTML="<span style=color:#ff0000;>两次输入的密码不一致</span>";
        return false;
    }
    else if(email=="")
    {
        document.getElementById("drop_5").innerHTML="<span style=color:#ff0000;>请填写邮箱地址</span>";
        return false;
    }
    else if(!myreg.test(email))
    {
        document.getElementById("drop_5").innerHTML="<span style=color:#ff0000;>邮箱地址格式不正确</span>";
        return false;
    }
    else if(checkcode=="")
    {
        document.getElementById("drop_6").innerHTML="<span style=color:#ff0000;>请填写验证码</span>";
        return false;
    }
    else
    {
        return true;
    }
}

function checkorder()
{
    var nickname=document.getElementById("TextBox1").value;
    var mobile=document.getElementById("TextBox2").value;
    var email=document.getElementById("TextBox3").value;
    var address=document.getElementById("TextBox5").value;
    if(nickname=="")
    {
        alert("请务必输入收货人姓名！");
        return false;
    }
    else if(mobile=="")
    {
        alert("请填写正确的联系电话！");
        return false;   
    }
    else if(email=="")
    {
        alert("请填写邮箱地址！");
        return false;   
    }
    else if(address=="")
    {
        alert("请填写收货地址！");
        return false;   
    }
    else
    {
        return true;
    }
}

function SelectFP()
{
    var pwtype=document.getElementById("DropDownList1").value;
    if(pwtype=="收据")
    {
        document.getElementById("fptt").style.display="none";
    }
    else
    {
        document.getElementById("fptt").style.display="block";
    }
}

function AjaxDuibi(productid,productname)
{
    createXMLHTTP();
    var url="Ajax.aspx?productid="+productid+"&productname="+productname+"&cmd=duibi&temp="+Math.random()+"";
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=GetAjaxDuibi;
    xmlHttp.send(null);
}
function GetAjaxDuibi()
{
    if(xmlHttp.readyState==4)//判断对象状态
    {  
        if(xmlHttp.status==200)
        {  
           document.getElementById("xixi").style.display="block";
           arraylist=xmlHttp.responseText.split("$");
           if(arraylist[0].toString()=="yes")
           {
                document.getElementById("duibilan").innerHTML=arraylist[1].toString();
           }
           else
           {
                alert("最多允许3个商品进行对比!");
                document.getElementById("duibilan").innerHTML=arraylist[1].toString();
           }
          
        }
    }
}

function AjaxDelDuibi(productid)
{
    createXMLHTTP();
    var url="Ajax.aspx?productid="+productid+"&cmd=delduibi&temp="+Math.random()+"";
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=GetAjaxDelDuibi;
    xmlHttp.send(null);
}
function GetAjaxDelDuibi()
{
    if(xmlHttp.readyState==4)//判断对象状态
    {  
        if(xmlHttp.status==200)
        {  
           if(xmlHttp.responseText=="no")
           {
                document.getElementById("xixi").style.display="none";
           }
           else
           {
                document.getElementById("duibilan").innerHTML=xmlHttp.responseText;
           }
        }
    }
}


function AjaxZFBName()
{
    createXMLHTTP();
    var url="../Ajax.aspx?cmd=zfbname&temp="+Math.random()+"";   
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    xmlHttp.onreadystatechange=GetAjaxZFBName;
    xmlHttp.send(null);

}
function GetAjaxZFBName()
{
    if(xmlHttp.readyState==4)//判断对象状态
    {  
        if(xmlHttp.status==200)
        {  
           document.getElementById("Label2").innerHTML=xmlHttp.responseText;
        }
    }
}
function AjaxShopCartCount()
{
    createXMLHTTP();
    var url="Ajax.aspx?cmd=shopcartcount&temp="+Math.random()+"";   
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    xmlHttp.onreadystatechange=GetAjaxShopCartCount;
    xmlHttp.send(null);
}
function GetAjaxShopCartCount()
{
    if(xmlHttp.readyState==4)//判断对象状态
    {  
        if(xmlHttp.status==200)
        {  
           document.getElementById("shopcartstate").innerHTML=xmlHttp.responseText;   
        }
    }
}
