﻿// JScript file
var Events=new Object();
// Verify the user is not logged on
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";
    }   
    ShopCart.ShowCounts();//展示购物车信息
    UserOnLine();
}
Events.BillingInfoLoad=function()
{
    Events.UserLoad();//判断是否登录
   var GetVal = AjaxAction.getEmployeeModel();
   var returnSTR = GetVal.value;
   if(returnSTR!="")
    {
        var obj=eval(returnSTR);
        document.getElementById("qty").innerHTML = obj.counts;
        document.getElementById("weight").innerHTML = obj.weight;
        document.getElementById("cmoney").innerHTML = obj.money;
        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 = obj.money;
        
        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;
            }
        }
        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 sid=obj.value;
   var GetVal = AjaxAction.getDeliveryType(sid);
   document.getElementById("shippingment").innerHTML =GetVal.value;
}

Events.ShopCartLoad=function(ObjectId)
{
    try
    {
        var GetVal = AjaxAction.CartLoad();
        document.getElementById(ObjectId).innerHTML = GetVal.value;
        ShopCart.ShowCartInfo();
        ShopCart.ShowCounts();
    }
    catch(e)
    {
        alert("Shopping Cart Information load failure");
    }
}

//网站首页加载
Events.IndexLoad=function(ObjectId)
{
    ShopCart.ShowCounts();
}

Events.RemoveCart=function(pid,attribute)
{    
     var GetVal = AjaxAction.ReMoveCart(pid,attribute);
      window.onload();
}

Events.ModifyCart=function(obj,pid,attribute)
{
    var GetVal = AjaxAction.ModifyCart(pid,attribute,obj.value);
     window.onload();
}

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(mail,mg,code)
{
    var txtMail=document.getElementById(mail);
    if(!Utils.isEmail(txtMail.value))
    {
        info=document.getElementById("mail");
        info.innerHTML="×";
        return;
    }
    var txtMg=document.getElementById(mg);
    if(Utils.isEmpty(txtMg.value))
    {
        info=document.getElementById("content");
        info.innerHTML="×";
        return;
    }
   
    var Form=document.getElementById("form1");
    Form.action="/Message.aspx";
    Form.method="post"
    Form.submit();
}

//函数名：Events.SelectSpec
//生成产品特性参数列表
Events.SelectSpec=function(objdiv,objControl,obj)
{
    var i=0;
    var div=document.getElementById(objdiv);
    
    for(i=0;i<div.childNodes.length;i++)
    {
        div.childNodes[i].className="";
        div.childNodes[i].style.border="#ccc 1px solid";
    }
    objControl.className="SpecSpan";
    objControl.style.border="#ff0000 1px solid";
    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()
{
    //window.history.back(-1);
    history.back(-1);
}
Events.AddToList=function(pid)
{
    var CookieUser=GetCookie("User");

    if(CookieUser!=null)
    {
       var f=AjaxAction.AddToList(CookieUser,pid).value;
       if(parseInt(f)>0)
       {
        alert("OK !");
       }
       else
       {
        alert("Error!");
       }
       
    }
    else
    {
        alert("You must sign in");
    }

}
function ShowExpatSearch(){
    var URI=window.location.toString();
    var classid=Utils.request(URI,"categories_id");
    var key=Utils.request(URI,"keywords");
    var page=Utils.request(URI,"page");
    var obj=AjaxAction.ExpatSearch(classid,key,page).value;
    obj=eval(obj);
    var content=document.getElementById("Slist");
    var pagebut=document.getElementById("pagebut");
     
    content.innerHTML=obj.content;
    pagebut.innerHTML=obj.but;
}
