﻿var Events=new Object();
Events.ajaxTxt="temp";
Events.UserLoad=function()
{
    var GetVal = AjaxAction.IsLoad();
    var items = GetVal.value; 
    if(items!="1")//表示没有登录
    {
       location.href = "/SignIn.html?url=" + items;
       return;
    }
    else//已登录
    {
       document.body.style.display = "block";
    }   
}

Events.BillingInfoLoad=function()
{
    ShopCart.ShowCounts();//显示购物车信息,add by 袁之梅 2010-11-12 11:57
    var AjaxIsLoging = AjaxAction.GetIsNoLogin();
    if(AjaxIsLoging.value != "1")//表示会员才可以下订单
    {
        var getSignIn = AjaxAction.IsLoad();
        if(getSignIn.value != "1")//表示没有登录
        {
           location.href = "/SignIn.html?url=/BillingInfo.html";
           return;
        }
    }
    var GetVal = AjaxAction.getEmployeeModel();
    var returnSTR = GetVal.value;
    if(returnSTR!="")
    {
        var obj=eval(returnSTR);
        document.getElementById("Eid").value = obj.ID;
        document.getElementById("qty").innerHTML = obj.counts;
        document.getElementById("weight").innerHTML = obj.weight;
        document.getElementById("cmoney").innerHTML = AjaxAction.getExchangePrice(obj.curren + obj.money).value;
        document.getElementById("s_firstname").value = obj.Name;
        document.getElementById("s_phone").value = obj.Telephone;
        document.getElementById("s_postcode").value=obj.PostCode;
        document.getElementById("email").value=obj.EMail;
//        document.getElementById("curren").innerHTML = obj.curren;
//        document.getElementById("curren1").innerHTML = obj.curren;
        document.getElementById("Gtmoney").innerHTML = AjaxAction.getExchangePrice(obj.curren + obj.money).value;
        
        var arrayL = obj.Address.split("|");
        if(arrayL[0]!=null)
        {
            document.getElementById("s_street").value = arrayL[0];
            if(arrayL[1]!=null)
            {
                document.getElementById("s_city").value = arrayL[1];
                if(arrayL[2]!=null)
                {
                    document.getElementById("s_province").value = arrayL[2];
                }
            }
        }
        var URI = window.location.toString();
        var Country = Utils.request(URI,"Country");
        
        if(obj.CountryID != null && obj.CountryID != "")
        {
            Country = obj.CountryID;
        }
        var select=document.getElementById("send_country");
        var i=0;
        for(i=0;i<select.options.length;i++)
        {
            if(Country==select.options[i].value)
            {
                select.options[i].selected=true;
            }
        }
        var str = AjaxAction.GetPid();
        if(str.value!="0")
        {
            document.getElementById("Promotion").value = str.value;
        }
        Events.shipfeeload(Country);
        Events.CheckAllt();
    }
}

Events.shipfeeload=function(obj)
{
  var GetVal = AjaxAction.getDeliveryType(obj);
  document.getElementById("shippingment").innerHTML =GetVal.value;
}

Events.getShippingListByCountry=function(obj)
{
   var GetVal = AjaxAction.getDeliveryType(obj.value);
  document.getElementById("shippingment").innerHTML =GetVal.value;
}

Events.ShopCartLoad=function(ObjectId)
{
    try
    {
        var GetVal = AjaxAction.CartLoad();
        document.getElementById(ObjectId).innerHTML = GetVal.value;
        ShopCart.ShowCartInfo();
    }
    catch(e)
    {}
}

Events.IndexLoad=function(ObjectId)
{
    ShopCart.ShowCounts();
}

Events.RemoveCart=function(pid,attribute)
{    
    var GetVal = AjaxAction.ReMoveCart(pid,attribute);
    window.onload();
    ShopCart.GetSpecialOffers();
}

Events.ModifyCart=function(obj,pid,attribute)
{
    var GetVal = AjaxAction.ModifyCart(pid,attribute,obj.value);
    window.onload();
    ShopCart.GetSpecialOffers();
}

Events.CheckAllt=function()
{    
    var name=document.getElementById("s_firstname").value; 
    var email=document.getElementById("email").value;
    var postcode=document.getElementById("s_postcode").value;
    var address= document.getElementById("s_street").value;
    var phone=document.getElementById("s_phone").value;
    var country=document.getElementById("send_country").value;
   
    if(name!="")
    { 
        document.getElementById("t_1").style.color="green";
        document.getElementById("t_1").innerHTML="√";  
    }
      if(email!="")
    {
        document.getElementById("t_2").style.color="green";
        document.getElementById("t_2").innerHTML="√";  
    }
      if(postcode!="")
    {
        document.getElementById("t_7").style.color="green";
        document.getElementById("t_7").innerHTML="√";  
    }
      if(address!="")
    {
        document.getElementById("t_4").style.color="green";
        document.getElementById("t_4").innerHTML="√";  
    }
      if(phone!="")
    {
        document.getElementById("t_3").style.color="green";
        document.getElementById("t_3").innerHTML="√";  
    }
      if(country!="")
    {
        document.getElementById("t_8").style.color="green";
        document.getElementById("t_8").innerHTML="√";  
    }
}

Events.ShowPictures=function(obj)
{
    document.getElementById("medium_img").src=obj;
}

Events.SubmitMessage=function(cook,pid,mail,mg,code)
{
    var ck=document.getElementById(cook);
    var rblCondition =AjaxAction.getCondition().value;
    var productId = document.getElementById(pid);
    if(rblCondition == "2")
    {
        if(ck.value==""|| ck.value==null)
        {
            alert("You must signin first!");
            return;
        }
        var isBuy =AjaxAction.CheckProduct(ck.value,productId.value);
        if(isBuy.value == 0)
        {
            alert("You haven't bought this product,can not add comments");
            return;
        }
        if(ck.value!=document.getElementById(mail).value)
        {
            alert("please enter your email address!");
            document.getElementById(mail).focus();
            return;
        }
        Events.SubmitComments(mail,mg,code);
    }
    if(rblCondition == "1")
    {
        if(ck==""|| ck==null)
        {
            alert("You must signin first!");
            return;
        }
        Events.SubmitComments(mail,mg,code);
    }
    if(rblCondition =="0")
    {
        Events.SubmitComments(mail,mg,code);
    }
}

Events.SubmitComments=function(mail,mg,code)
{
    var txtMail=document.getElementById(mail);
    if(!Utils.isEmail(txtMail.value))
    {
        Span1=document.getElementById("Span1");
        Span1.innerHTML="×";
        alert("The email couldn't be empty");
        return;
    }
    var txtMg=document.getElementById(mg);
    if(Utils.isEmpty(txtMg.value))
    {
        info=document.getElementById("content");
        info.innerHTML="×";
        alert("The content couldn't be empty");
        return;
    }
    var Code=document.getElementById(code);
    if(Code.value!=Utils.GetCookie("Code"))
    {
        info=document.getElementById("code");
        info.innerHTML="×";
        alert("please check the code");
        return;
    }
    var Form=document.getElementById("form1");
    Form.action="/Message.aspx";
    Form.method="post"
    Form.submit();
}

Events.SelectSpec=function(objdiv)
{
    var div=objdiv.name;
    var str;
    var Index=document.getElementById(div).selectedIndex;
    if(Index!="0")
    {   
        var obj=document.getElementById(div).options[document.getElementById(div).options.selectedIndex].value; //获取用户选择的值
        var objs=document.getElementById("Spec");
        var arr=obj.split("_");
        var flag=false;
        if(objs.value.length>0)
        {
            var array=objs.value.split("|");
            var arrtemp=null;

            for(i=0;i<array.length;i++)
            {
              arrtemp=array[i].split("_");

                if(arrtemp[0]==arr[0])
                {
                    array[i]=obj;
                    flag=true;
                    objs.value=array.toString().replace(",","|");
                    break; 
                }
            }
            if(flag==false)
            {
                objs.value+="|";
                objs.value+=obj;
            } 
        }
        else
        {
            objs.value=obj;
        }
    }
 }

Events.history=function()
{
    history.back(-1);
}

Events.JudgeCounpons=function()
{
    var price = document.getElementById("ItemMoney").value;
    var email = document.getElementById("email").value;
    var offamount = document.getElementById("spanOffAmount").innerHTML;
    var tamount = document.getElementById("GrandMoney").innerHTML;
    var num = document.getElementById("TextCouponID").value;
    var GetVal = AjaxAction.JudgeCounpons(num,price,email);
    var str = GetVal.value;
    if(str=="0")
    {
        alert("Sorry , The coupons is invalid !");
    }
    else if(str=="-1")
    {
        alert("Sorry , The coupons has been used !");
    }
    else if(str=="-2")
    {
        alert("Sorry , The coupons do not meet the conditions of use !");
    }
    else if(str=="-3")
    {
        alert("Sorry , You can't use the coupons !");
    }
    else
    {
         alert("OK , you can use it !");
         document.getElementById("spanOffAmount").innerHTML = parseFloat(offamount)+parseFloat(str);
         document.getElementById("GrandMoney").innerHTML = parseFloat(tamount)-parseFloat(str);
    }
}

Events.ShowReviews=function()
{
     var pid=document.getElementById("Pid").value;
     var GetVal = AjaxAction.GetReview(pid);
     document.getElementById("Reviews").innerHTML=GetVal.value;
}
