﻿///<reference path="jquery-1.4.1-vsdoc.js" />

/*显示或隐藏div层*/
var _divs = ["signinBox", "helpBox"];
function DisplayDiv(divName) {
    for (var i = 0; i < _divs.length; i++) {
        document.getElementById(_divs[i]).style.display = (_divs[i] == divName) ? "block" : "none";
    }
}

/*显示或隐藏子菜单*/
function DisplayDivMenu(divName) {
    for (var i = 0; i < _divMenus.length; i++) {
        document.getElementById(_divMenus[i]).style.display = (_divMenus[i] == divName) ? "block" : "none";
    }
}

function CheckIsNullOnQuickSignIn(para_account, para_pwd, para_verification, para_msg, accountrequired, pwdrequired, verificationrequired) {
    var account = document.getElementById(para_account).value;
    var pwd = document.getElementById(para_pwd).value;
    var verificationCode = document.getElementById(para_verification).value;
    var msg = "";
    if (account == "" || account == null) {
        msg = accountrequired;
        document.getElementById(para_msg).innerHTML = msg;
        return false;
    }
    if (pwd == "" || pwd == null) {
        msg = pwdrequired;
        document.getElementById(para_msg).innerHTML = msg;
        return false;
    }
    if (verificationCode == "" || verificationCode == null) {
        msg = verificationrequired;
        document.getElementById(para_msg).innerHTML = msg;
        return false;
    }
    return true;
}

/*关闭QuickSignIn*/
function CloseQuickSignIn(account, pwd, verification, msg) {
    document.getElementById(account).value = "";
    document.getElementById(pwd).value = "";
    document.getElementById(verification).value = "";
    document.getElementById(msg).innerHTML = "";
    document.getElementById('signinBox').style.display = "none";
}

function btnSearch_Click(txt) {
    var keyword = txt.value.trim();
    if (keyword != "") {
        return true;
    }
    return false;
}



function join_cart(proid, pronum) {
    var ispassnum = AjaxMethod.IsPassNum(proid, pronum).value;
    if (ispassnum == 1) {
        alert('超过最大购买上限，请重新输入购买数量！');
        event.returnValue = false;
        return;
    }
    var str = AjaxMethod.InsertCart(proid, pronum).value;

    document.getElementById("div_addshoppingcart_result" + proid).style.display = "block";
    setTimeout(function() { document.getElementById("div_addshoppingcart_result" + proid).style.display = "none"; }, 3000);
    
    document.getElementById("font_itemsincart").innerHTML=str[0];
    document.getElementById("font_totalincart").innerHTML=str[1];
    //JQuery("#font_totalincart").html(str[1]);
   //saveCartInCookie(str[2]);

}

 function saveready(){  
    }  

function saveCartInCookie(cartliststring)
{
     var url = "SaveCookie.aspx?cookiename=B2CECCART&cookievalue="+cartliststring+"";               
        //1.创建XMLHttpRequest组建  
    xmlHttpRequest = createXmlHttpRequest();  
          
        //2.设置回调函数  
    xmlHttpRequest.onreadystatechange = saveready;  
          
        //3.初始化XMLHttpRequest组建  
    xmlHttpRequest.open("POST",url,true);  
          
        //4.发送请求  
    xmlHttpRequest.send(null);    
}

function createXmlHttpRequest(){  
        if(window.ActiveXObject){ //如果是IE浏览器  
            return new ActiveXObject("Microsoft.XMLHTTP");  
        }else if(window.XMLHttpRequest){ //非IE浏览器  
            return new XMLHttpRequest();  
        }  
    }  


function delete_cart(proid) {
    var str = AjaxMethod.DeleteCart(proid).value;
     //saveCartInCookie(str[2]);
    window.location = 'ShoppingCart.aspx';
    
    $("#font_itemsincart").html(str[0]);
    $("#font_totalincart").html(str[1]);
    
}

function update_cart() {
    $(".CartTable input[type=text]").each(function(i) {
        var str = AjaxMethod.UpdateCart($(this).attr("id"), $(this).val()).value;
        
        $("#font_itemsincart").html(str[0]);
        $("#font_totalincart").html(str[1]);
        //saveCartInCookie(str[2]);
    });
}


//UpdatePanel更新时候的Js操作
function OnUpdating() {
    $("#loading").show();
    $("form input[type=submit]").attr("disabled", true);
}

//UpdatePanel更新完成后的Js操作
function OnUpdated() {
    $("#loading").hide();
    $("form input[type=submit]").attr("disabled", false);
}


//修改运费值
function SetPaymentMethod(isfee,fee,real_amount,fee0)
{
    if(isfee==1)
    {
        $("#Order_Freight_fee").text(fee);
        $("#Order_REAL_AMOUNT").text(real_amount);
    }
    else
    {
        $("#Order_Freight_fee").text(fee0);
        $("#Order_REAL_AMOUNT").text($("#Order_AMOUNT").text());
    }
}


function enterkey(et){
if(et.keyCode){   return et.keyCode;  }
else{return et.which; } 
}  



//以下是PMALL用到的函数


function join_pmallcart(proid, pronum) {

    var ispassnum = AjaxMethod.IsPassNumPMall(proid, pronum).value;
    if (ispassnum == 1) {
        alert('超过最大购买上限，请重新输入购买数量！');
        event.returnValue = false;
        return;
    }
    var str = AjaxMethod.InsertPMallCart(proid, pronum).value;

    document.getElementById("div_addshoppingcart_result" + proid).style.display = "block";
    setTimeout(function() { document.getElementById("div_addshoppingcart_result" + proid).style.display = "none"; }, 3000);
    
    document.getElementById("font_itemsincart").innerHTML=str[0];
    document.getElementById("font_totalincart").innerHTML=str[1];
    //JQuery("#font_totalincart").html(str[1]);
}

function delete_pmallcart(proid) {
    var str = AjaxMethod.DeletePMallCart(proid).value;
    window.location.reload();
    // = 'ShoppingPMallCart.aspx';
    
    $("#font_itemsincart").html(str[0]);
    $("#font_totalincart").html(str[1]);
    
    
}


function delete_newpmallcart(proid) {
    var str = AjaxMethod.DeletenewPMallCart(proid).value;
    window.location = 'Auto_SelectProduct.aspx';

    $("#font_itemsincart").html(str[0]);
    $("#font_totalincart").html(str[1]);
}

function update_newpmallcart() {
    $(".CartTable input[type=text]").each(function(i) {
        var str = AjaxMethod.UpdatePMallCart($(this).attr("id"), $(this).val()).value;

        $("#font_itemsincart").html(str[0]);
        $("#font_totalincart").html(str[1]);
    });
}

function update_pmallcart() {

    $(".CartTable input[type=text]").each(function(i) {
        var str = AjaxMethod.UpdatePMallCart($(this).attr("id"), $(this).val()).value;
        
        $("#font_itemsincart").html(str[0]);
        $("#font_totalincart").html(str[1]);
    });
}





