﻿ugg.register("site"); //此处注册


site={

   //添加标签
    AddFavorite:function(){
        var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL'; 
        if(jQuery.browser.msie){ 
            window.external.addFavorite(ugg.siteinfo.domain,ugg.siteinfo.shortSiteName);
        }
        else if (document.all){
            window.external.addFavorite(ugg.siteinfo.domain,ugg.siteinfo.shortSiteName); 
        }
       else if (window.sidebar){ 
            window.sidebar.addPanel(ugg.siteinfo.shortSiteName,ugg.siteinfo.domain, ""); 
       }
      },
      
      
   //查询产品
   Search:function(){
    var sertxt=$("#q").val();
   if(sertxt!="Search..." && sertxt.length>0)
       {
         if(checkForms(sertxt)==true)
         {
           location.href = 'search.html?q='+ escape(sertxt) +'';
         }
        }
        else
        {
         alert('At least one of the fields in the search form must be entered.');
        }
      },
      
      
      //产品评论列表
   GetProductRewiteViewList:function(pagenum){
        var sUrl  =  location.href.split('.html')[0];
        var i=sUrl.lastIndexOf('-');
        var proid=sUrl.substring(i+1,sUrl.length);
       $.post(""+ ugg.siteinfo.domain+"/Ajax/ProductRewriteAjax.ashx", {current:pagenum, productid:proid},function(msg){
         $("#proview").html(msg);
       });
   },
   

   
  //添加产品评论
   AddProductComment:function(){
      
   var rad=$("#selrate").val();
    if($.trim($("#txtname").val())=="")
    {
      alert('* Please Write Your Name!');
      return;
    }
    if($.trim($("#TextArea1").val())=="")
    {
      alert('* Please Write Your Review!');
      return;
    }
      var sUrl  =  location.href.split('.html')[0];
       var i=sUrl.lastIndexOf('-');
        var proid=sUrl.substring(i+1,sUrl.length);
        $.post(""+ ugg.siteinfo.domain+"/Ajax/AddProductComment.ashx",{name:$("#txtname").val(),productid:proid,rate:rad,content:$("#TextArea1").val()},function(msg){
         switch (msg) {
            case "-1":
                 location.href=ugg.siteinfo.domain+"/LogIn.html?from="+location.href;
            break;
            case "1":
                alert("Success!");
                site.GetProductRewiteViewList(1);
                $("#star").attr("checked",false);
                $("#TextArea1").val("");
                break;
            case "0":
                alert("Failure!");
                break;
                }
        });
   },
   
   
   //控制评论显示效果
    chg:function(p)
    {
      $("#"+p.toString()).toggle(100);
    },
    
    //添加到购物车
    AddShopCart:function()
    {
       var flag=true;
       if($("#ddlSize").val()=="0"){
       alert("Please Select Size!");
       flag = false;
       }
       if(flag)
       {
          document.AddCart.action=ugg.siteinfo.domain+"/ShopCart.html";
          document.AddCart.submit();
       }
    },
    
    
     //显示购物车
    ShopCartProduct:function()
    {
    $.post(ugg.siteinfo.domain+"/Ajax/ShopAjax.aspx",function(msg){
      if(msg.toString().length>0)
      {
        $("#shopcart").html(msg.toString());  
      }
    })
    },
    
    
    //修改购物车
    EditShopCart:function(txtid,id){
      var num=$("#"+txtid.toString()).val();
      $.post(ugg.siteinfo.domain+"/Ajax/EditShopCart.aspx",{number:num,pid:id.toString()},function(msg){
        switch(msg)
        {
          case "1":
          site.ShopCartProduct();
          site.ShopCartItem();
          break;
          case "-1":
          alert('Error:Enter the number of wrong.');
          break;
        }
      })
    },
    
    //删除购物车产品
    DelShopCart:function(id)
    {
        $.post(ugg.siteinfo.domain+"/Ajax/DelShopCart.aspx",{pid:id.toString()},function(msg){
       if(msg.toString()=="1")
       {
         site.ShopCartProduct();
         site.ShopCartItem();
       }
      })
    },
    
    
    //购物车下一步  continue checkout
    ShopNext:function(){
       $.post(ugg.siteinfo.domain+"/Ajax/ShopCartNext.aspx",function(msg){
        switch(msg)
        {
         case "1":
          location.href=ugg.siteinfo.domain+"/CheckOut.html";
          break;
          default:
          alert(msg.toString());
          break;
        };
      })
    },
    
    
  
  /*******购物车统计******/
   ShopCartItem:function()
   {
      $.post(ugg.siteinfo.domain+"/Ajax/ShopCartItem.aspx",function(msg){
      $("#itemtab tbody tr:eq(0) td:eq(0)").html(msg);
     });
   },
    
  /********************Continue CheckOut*************************/
  firststep:function(){
     $.post(ugg.siteinfo.domain+"/Ajax/CheckOut/Firststep.aspx",function(msg){
      $("#checkout").html(msg);
     });
   },
  
   billandship:function(p,m){
   
    //支付地址
    if(m=="bill")
    {
         if($(p).val()=="openbill")
         {
           $("#billaddress").css("display","block");
         }
         else
         {
            $("#billaddress").css("display","none");
         }
     }
     if(m=="ship")
     {
         //收货地址
        if($(p).val()=="openship")
         {
           $("#shipaddress").css("display","block");
         }
         else
         {
            $("#shipaddress").css("display","none");
         }
     }
   },
   
   //添加支付地址
   AddBillAddress:function()
   {  
      var i=0;
      var rad=$(".from_dis input[@type=radio][checked]").val();
      var shipaddress="";  var billaddress="";
      if($("#selbilladdress").val()=="closebill")
      {
        billaddress=$("#selbilladdress").find("option:selected").text();
      }
      else
      {
            var firstname=filterstr($.trim($("#fname").val()));
            var lastname=filterstr($.trim($("#lname").val()));
            var streeaddress=filterstr($.trim($("#address").val()));
            var city=filterstr($.trim($("#city").val()));
            var province=filterstr($.trim($("#province").val()));
            var zipcode=filterstr($.trim($("#zipcode").val()));
            var country=$("#bcountry").val();
            var phone=filterstr($.trim($("#phone").val()));
            if(firstname.length<2)
            {
              alert('Is your first name correct? Our system requires a minimum of 2 characters.Plase try again');
              return;
            }
             if(lastname.length<2)
            {
              alert('Is your last name correct? Our system requires aminimum of 2 characters.Please try again.');
              return;
            }
             if(streeaddress.length<5)
            {
              alert('Your Street Address must contain a minimum of 5 characters.');
              return;
            }
            if(city.length<2)
            {
              alert('Your City must contain a minimum of 2 characters');
              return;
            }
              if(zipcode.length<4)
            {
              alert('Your Post/ZIP Code must contain aminimum of 4 characters');
              return;
            }
             if(country=="0")
            {
              alert('You must select a country from the Countries pull down menu');
              return;
            }            
             if(phone.length<3)
            {
              alert('Your Telephone Number must contain a minimum of 3 characters');
              return;
            }
          i=1;
          billaddress=firstname+"|"+lastname+"$"+streeaddress+"$"+city+"$"+province+"|"+zipcode+"$"+$("#bcountry").find("option:selected").text()+"$"+phone;
      }
      if(rad=="0"){shipaddress=billaddress;}else{shipaddress="";}
        $("#a2").css("display","block");
        $("#billbutton").attr("disabled","disabled");
        $.getJSON(ugg.siteinfo.domain+"/Ajax/CheckOut/Secondstep.aspx",{billAddress:billaddress,shipAddress:shipaddress,step:rad,m:i,countryid:country},function(msg){
        $("#a2").css("display","none");
        $("#billbutton").attr("disabled","");
        $("#menu3").html(msg.m3);
        $("#menu2").html(msg.m2);
          if(rad=="0")
          { site.controlstyle(3);}
          else
          { site.controlstyle(2);}
        });
   },
   
   //控制样式
   controlstyle:function(t)
   {
     $("#menu"+t.toString()).css("display","block");
     for(i=1;i<t;i++)
     {
          $("#menu"+i.toString()).css("display","none");
          $("#t"+i.toString()).css("cursor","pointer");
          $("#t"+i.toString()).bind("click",{foo:i.toString()},site.controlmenu);
          $("#k"+i.toString()).bind("click",{foo:i.toString()},site.controlmenu);
     }
   },
   
    //控制模块的显示与隐藏
   controlmenu:function(event)
   {
     var l=7;
     for(i=1;i<=l;i++)
     {
        $("#menu"+i.toString()).css("display","none");
     }
     $("#menu"+event.data.foo).css("display","block");
     
     for(j=event.data.foo;j<=l;j++)
     {
        $("#t"+j.toString()).unbind("click");
        $("#t"+j.toString()).css("cursor","");
     }
   },
   
   
   //添加送货地址 shippingaddress
   AddShippingAddress:function(p)
   {
    var shippingaddress="";
     if($("#selshipaddress").val()=="closeship")
     {
       shippingaddress=$("#selshipaddress").find("option:selected").text();
     }
     else
     {
            var firstname=filterstr($.trim($("#sfname").val()));
            var lastname=filterstr($.trim($("#slname").val()));
            var streeaddress=filterstr($.trim($("#saddress").val()));
            var city=filterstr($.trim($("#scity").val()));
            var province=filterstr($.trim($("#sprovince").val()));
            var zipcode=filterstr($.trim($("#szipcode").val()));
            var country=$("#sbcountry").val();
            var phone=filterstr($.trim($("#sphone").val()));
            if(firstname.length<2)
            {
              alert('Is your first name correct? Our system requires a minimum of 2 characters.Plase try again');
              return;
            }
             if(lastname.length<2)
            {
              alert('Is your last name correct? Our system requires aminimum of 2 characters.Please try again.');
              return;
            }
             if(streeaddress.length<5)
            {
              alert('Your Street Address must contain a minimum of 5 characters.');
              return;
            }
            if(city.length<2)
            {
              alert('Your City must contain a minimum of 2 characters');
              return;
            }
              if(zipcode.length<4)
            {
              alert('Your Post/ZIP Code must contain aminimum of 4 characters');
              return;
            }
             if(country=="0")
            {
              alert('You must select a country from the Countries pull down menu');
              return;
            }            
             if(phone.length<3)
            {
              alert('Your Telephone Number must contain a minimum of 3 characters');
              return;
            }
         shippingaddress=firstname+" "+lastname+","+streeaddress+","+city+","+province+" "+zipcode+","+$("#sbcountry").find("option:selected").text()+","+phone;   
     }
         $("#a3").css("display","block");
         $("#shipbutton").attr("disabled","disabled");
       $.post(ugg.siteinfo.domain+"/Ajax/CheckOut/Thirdstep.aspx",{address:shippingaddress,countryid:country},function(msg){
         $("#a3").css("display","none");
         $("#shipbutton").attr("disabled","");
         $("#sendType").html(msg.toString());
         site.controlstyle(3);
     });
   },
   
  
  //送货方式
  ShippingMethod:function(){
    var sendid=$("#sendType input[@type=radio][checked]").val();
         $("#a4").css("display","block");
         $("#shipmethbutton").attr("disabled","disabled");
      $.post(ugg.siteinfo.domain+"/Ajax/CheckOut/Fourthstep.aspx",{sendid:sendid},function(msg){
         $("#a4").css("display","none");
         $("#shipmethbutton").attr("disabled","");
       $("#menu4").html(msg);
        site.controlstyle(4);
     });
  },
   
  //提交支付方式并提取优惠券输入框
  SavePayandCoupon:function(){
     var payid=$("#rpaymeth input[@type=radio][checked]").val();
      $("#a5").css("display","block");
      $("#paybutton").attr("disabled","disabled");
      $.post(ugg.siteinfo.domain+"/Ajax/CheckOut/Fifthstep.aspx",{payid:payid},function(msg){
      $("#a5").css("display","none");
      $("#paybutton").attr("disabled","");
       $("#menu5").html(msg);
        site.controlstyle(5);
     });
  },
  
  //提交优惠卷编号并获取用户留言模块
    SaveCouponandSpecial:function(){
     var coupon=$("#coupon").val();
      $("#a6").css("display","block");
      $("#couponbutton").attr("disabled","disabled");
      $.post(ugg.siteinfo.domain+"/Ajax/CheckOut/Sixthstep.aspx",{coupon:coupon},function(msg){
      $("#a6").css("display","none");
      $("#couponbutton").attr("disabled","");
      if(msg == "0")
      {
        alert('Invalid Coupon Code.');
        return;
      }
      else
      {
        $("#menu6").html(msg);
        site.controlstyle(6);
       }
     });
  },
  
  
  //提交用户留言并取出购买产品信息
  SaveSpecialandProduct:function(){
   var abouts=$("#txtabout").val();
      $("#a7").css("display","block");
      $("#btn_Continue").attr("disabled","disabled");
     $.post(ugg.siteinfo.domain+"/Ajax/CheckOut/Seventhstep.aspx",{abouts:abouts},function(msg){
      $("#a7").css("display","none");
      $("#btn_Continue").attr("disabled","");
        $("#menu7").html(msg);
        site.controlstyle(7);
     });
  },
  
  //将订单插入数据库
  SaveOrder:function(){
      $("#a8").css("display","block");
      $("#saveorder").attr("disabled","disabled");
      $.post(ugg.siteinfo.domain+"/Ajax/CheckOut/Eighthstep.aspx",function(msg){
      $("#a8").css("display","none");
       location.href=msg;
     });
  }
}
    
    
    //验证文本不能含有非法字符
function checkForms(texts)
{
   var iu, iuu, regArray=new Array("◎","■","●","№","↑","→","↓"+
   "!","@","#","$","%","^","&","*","+","=","|","","[","]","？","~","`"+
   "!","<",">","‰","→","←","↑","↓","¤","§","＃","＆","＆","＼","≡","≠"+
   "≈","∈","∪","∏","∑","∧","∨","⊥","‖","‖","∠","⊙","≌","≌","√","∝","∞","∮"+
   "∫","≯","≮","＞","≥","≤","≠","±","＋","÷","×","/","Ⅱ","Ⅰ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ","Ⅷ","Ⅹ","Ⅻ","一","二"+
   "╄","╅","╇","┻","┻","┇","┭","┷","┦","┣","┝","┤","┷","┷","┹","╉","╇","【","】"+
   "三","四","五","六","七","八","九","十","①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩","┌","├","┬","┼","┍","┕","┗","┏","┅","—"+
   "〖","〗","←","〓","☆","§","□","‰","◇","＾","＠","△","▲","＃","℃","※",".","≈","￠");
   iuu=regArray.length;
   for(iu=1;iu<=iuu;iu++)
   {  
      if(regArray[iu] !="")
       {
          if (texts.indexOf(regArray[iu])!=-1)
           {
             alert("Sorry,the content must not contain  feature  characters.");
             return false;
          }
        }
   }
   return true;             
}

  //过滤逗号
 function filterstr(text)
 {
   return text.replace(/,/g," ");
 }
 
 
   //获取页面的传值
function getUrlPara(paraName)
{ 
  var sUrl  =  location.href;
  var sReg  =  "(?:\\?|&){1}"+paraName+"=([^&]*)"
  var re=new RegExp(sReg,"gi");
  re.exec(sUrl);
  return RegExp.$1.split('#')[0];
}
    

    
//获取地址栏搜索值
$(function(){

if(unescape(getUrlPara("q")).toString()!="compatible" && unescape(getUrlPara("q")).toString()!="")
{
 $("#q").val(unescape(getUrlPara("q")));
 }
})
    
    
    
    
     

   //产品类别控制
  $(document).ready(function(){
      
     $("#protype ul li").hover(function(){
           $(this).addClass("tt_hover");
           $(this).children("ul").css("display","block");
           $(this).children("span").children("img").attr("src","Style/Images/tt_hover.gif");
         },function(){ 
            $(this).removeClass("tt_hover");
            $(this).children("ul").css("display","none");
            $(this).children("span").children("img").attr("src","Style/Images/tt_link.gif");
       });
   
       $("#protype ul li ul li").hover(function(){
          $(this).children("img").attr("src","Style/Images/tt_hover.gif");
       },function(){
          $(this).children("img").attr("src","Style/Images/tt_link.gif");
       });
   })
