﻿
 //登录
 function Login()
 {
     var u = trim($("UserID").value);
     var p = trim($("Password").value);
     
     if(u=="" || p=="")
     {
     alert("用户编号或用户密码不能为空!"); 
     }
     else
     {
     this.ExecFun = "_Login";
     this.Query = new Array(u,p);
     ExecAJ("Login");
     }
 }
 
function Loginic() //ic系统登录
 {
     var u = trim($("UserID").value);
     var p = trim($("Password").value);
     
     if(u=="" || p=="")
     {
     alert("用户编号或用户密码不能为空!"); 
     }
	 else if (u.substring(0,3)!="626")
	 {
		  //alert("请输入商家编号!"); 
		  form1.UserID.focus();
		  document.getElementById('usererror').style.display="block";
	 }
     else
     {
     document.getElementById('usererror').style.display="none";
     document.getElementById('userright').style.display="block";
     this.ExecFun = "_Loginic";
     this.Query = new Array(u,p);
     ExecAJ("Login");
     }
 }
 
  function _Loginic() 
 {
	 var u = trim($("UserID").value);
	 
     if( this.ReStr=="0" || u.substring(0,3)!="626" )
     {
      //location.href="/member/default.aspx"
       //alert("用户编号或用户密码错误!");
	   form1.Password.focus();
	   document.getElementById('passerror').style.display="block";
	   document.getElementById('usereerror').style.display="none";
	   document.getElementById('usereright').style.display="block";
	   
	   
      
     }
     else if (this.ReStr=="-1")
     {
       alert("你的账号还没审核成功,请等我们的审核结果!"); 
	   document.getElementById('passerror').style.display="none";
	   document.getElementById('passright').style.display="none";
	   document.getElementById('usereerror').style.display="none";
	   document.getElementById('usereright').style.display="none";
	   document.getElementById('stanterror1').style.display="block";
     }
     else
     {
     try
     {
       var result = eval(this.ReStr);
             
      $("LoginTD1").style.display="none";
      $("LoginTD2").style.display="";
      $("LoginTD3").style.display="none";
      $("LoginTD4").style.display="";
     if (result[3]["CompanyName"]!="")
	  {
	  $("RealName").innerHTML=result[3]["CompanyName"];
	  }
		  else
	  {
      $("RealName").innerHTML="会员:"+result[0]["RealName"];
	  }

      $("UserNo").innerHTML=result[1]["UserNo"];
      
      if(result[2]["ClassID"]=="1")
      {
       $("CartID").innerHTML="[<a href=\"/member/Default.aspx?ID=5\">我的购物车</a>]";
      }
      
      form1.PayPassWord.focus();
	  
      }
      catch(e)
      {
       location.href="login.aspx"
      }
      
     }
     
 
 } 
 
 function Login2()
 {
   if(event.keyCode==13)
   {
   event.keyCode=9
   Login();
   }
 }

 function _Login() 
 {
     if(this.ReStr=="0")
     {
      //location.href="/member/default.aspx"
       alert("用户编号或用户密码错误!"); 
      
     }
     else if (this.ReStr=="-1")
     {
       alert("你的账号还没审核成功,请等我们的审核结果!"); 
     }
     else
     {
     try
     {
       var result = eval(this.ReStr);
             
      $("LoginTD1").style.display="none";
      $("LoginTD2").style.display="";
        $("LoginTD3").style.display="none";
      $("LoginTD4").style.display="";
     if (result[3]["CompanyName"]!="")
	  {
	  $("RealName").innerHTML="商家:"+result[3]["CompanyName"];
	  }
		  else
	  {
      $("RealName").innerHTML="会员:"+result[0]["RealName"];
	  }

      $("UserNo").innerHTML=result[1]["UserNo"];
      
      if(result[2]["ClassID"]=="1")
      {
       $("CartID").innerHTML="[<a href=\"/member/Default.aspx?ID=5\">我的购物车</a>]";
      }
       form1.PayPassWord.focus();
      
      }
      catch(e)
      {
       location.href="/default.aspx"
      }
      
     }
     
 
 }
 
 //忘记密码
 function GetPassWord()
 {

 }
 
 //搜索
 var SearchIndex=1;
 function AllSearch()
 {
   var Key=trim($("_SearchKey").value);
   
   if(Key!="")
   {
       var SUrl="";
       
       switch(SearchIndex)
       {
         case 1:
            SUrl="/ProductList.aspx?Key="+Key;
         break;
         case 2:
            SUrl="/CompanyList.aspx?Key="+Key;
         break;
         case 3:
            SUrl="/News.aspx?Key="+Key;
         break;
         case 4:
            SUrl="/CompanyList.aspx?ID="+$("SearchKey").value;
         break;
       }
       
       window.open(SUrl);
    }
    else
    {
      alert("请输入关键词!");
    }
  
   
 }
 
 function SearchC()
 {

    var Key=trim($("_SearchKey").value);
    var SUrl="";
    SUrl="/CompanyList.aspx?Key="+Key;
    location.href=SUrl;
 }
 
 function OpenArea()
 {
  if(SearchIndex==4)
  {
   ShowArea("SearchKey");
  }
  
 }
 
 function focusCss(obj,css)
 {
  obj.className=css;
  obj.value=obj.value.replace("请输入商家关键字","");
 }


 //更多
 function More1() 
 {
     switch (MoreT) 
     {
         case 19:
             location.href = "/News.aspx";
             break;
         case 20:
             location.href = "/Cub.aspx";
             break;
     }
 }
 
    function InsertCompanyMsg()
    {
        this.ExecFun="_InsertCompanyMsg";

        this.Query=new Array
            (
              "",
              trim($("Content").value),
			  parseInt($("score").value),
              "",
              0,
              this.Other
            );
            
           if(this.Query[1]=="")
           {
            alert("留言内容不能为空!");
           }
		   else if (this.Query[2]==0)
		   {
			   alert("请给店铺评分,谢谢!");
		   }
           else
           {
            ExecAJ("InsertCompanyMsg");
           }

         
    }

    function _InsertCompanyMsg()
    {
      if(this.ReStr=="1")
      {
        alert("留言发送成功!");
        $("Content").value="";
        this.IsLoad=false;
        LoadCompanyMsgList(1);
      }
      else if (this.ReStr=="-1")
      {
       alert("您还没有登陆或您还不是会员，不能留言!");
      }
    }
    
    //现在购卖
    function NowBuy(ProductID)
    {
      AddCart(ProductID);
    }
    
    //添加到购物车
    function AddCart(ProductID)
    {
           
      this.ExecFun="_AddCart";

      this.Query=new Array(ProductID,$("BuyCount").value);
            
      ExecAJ("InsertOrderProduct");
    }
    
    function _AddCart()
    {
      if(this.ReStr=="1")
      {
        alert("已放入购物车");
        location.href="/member/Default.aspx?ID=5";
      }
      else if(this.ReStr=="-1")
      {
       location.href="/LoginAndReg.aspx";
      }
      else if(this.ReStr=="0")
      {
       alert("您是商家会员,不能购买产品!");
      }
      else if(this.ReStr=="2")
      {
       alert("对不起,你购买的数量已经超出了商家的库存量!");
      }
      else
      {
       alert(this.ReStr);
      }
    }
    
    //收藏产品
    function AddProduct(ProductID)
    {
    
    }
    
    //出价
    var NID=0;
    function SetPrice(ID)
    {      
        this.ExecFun = "_SetPrice";
        this.Query = new Array
	            (
                  ID,
                  0
		        );
        this.NID=ID;
        ExecAJ("MyVendueBid");
    }

    function _SetPrice() 
    { 
      
      if(this.ReStr=="0")
      {
       alert("您还没有登陆!");
       location.href="/LoginAndReg.aspx";
      }
      else if(this.ReStr=="-1")
      {
       alert("该产品已拍卖结束!");
      }
      else if(this.ReStr=="-2")
      {
       alert("商家不能参与拍卖!");
      }
      else
      {
       $("NewPrice").innerHTML=this.ReStr;
       //GetPrice(this.NID);
      }
    }
    
    //刷新价格
    function GetPrice(ID) 
    {
        $("NewPrice").innerHTML = "Load...";
        this.ExecFun = "_GetPrice";
        this.Query = new Array
	            (
                  ID+""
		        );

        ExecAJ("GetVendueBid");
    }

    function _GetPrice()
    {
         $("NewPrice").innerHTML = this.ReStr;
    }

    function Reg() 
    {
    
    
     if(!CK.CheckForm())
            return;
            
        this.ExecFun = "_Reg";
		  this.pv=0; 
        if ($("Mobile").value.charAt(0) == 1)
		          {
		          this.pv=1;
		          }  
        this.Query = new Array
	            (
                  $("RealName").value,
                  GetSelectValue("Cate"),
                  $("Mobile").value,
                  $("Phone").value,
                  $("Email").value,
                  $("ParentID").value,
                  "",
                  "",
                  $("EName").value,
                  $("CompanyName").value,
                  $("_Phone").value,
                  $("WorkMode").value,
                  "",
                  0,
                  GetAreaID(),//$("Area2").value,
                  GetSelectValue("CompanyClassID"),
                  $("Address").value,
                  $("Branchmember").value,
                  this.pv
		        );

		        var doFun=true;	        
		        
		        doFun=CheckM();
		        
		        if(this.Query[1]!="1") 
		        {
		         doFun=CheckCompany();
		        }
		        
		        if(doFun)
		        {
		        ExecAJ("Member_Reg");
		        }
		        

        
    }
    
    function GetAreaID()
    {
      var AID1=GetSelectValue("Branch1_Province");
      var AID2=GetSelectValue("Branch1_City");
      var AID3=GetSelectValue("Branch1_Area");
      var AID4=GetSelectValue("Branch1_Town");
      
      var AID=AID1;
      
      if(AID2!=0)
      {
       AID=AID2;
      }
      
      if(AID3!=0)
      {
       AID=AID3;
      }
      
      if(AID4!=0)
      {
       AID=AID4;
      }
      
      return AID;
    }
    
    function CheckM()
    {
        var doFun=true;	
           
		        if(trim($("RealName").value).length<2 || trim($("RealName").value).length>20)
		        {
		         alert("用户名长度就在3~20个字符之间");
		         doFun=false;
		         
		        }
		        
		        else if(trim($("Mobile").value)=="" && trim($("Phone").value)=="")
		        {
		         alert("手机号码和身份证号至少填写一项!");
		         doFun=false;
		         
		        }
		        else
		        {
		          if(trim($("Mobile").value)!="" && trim($("Mobile").value).length!=11)
		          {
		            alert("请输入11位手机号码,固话请加区号例：三水,75781234567");
		            doFun=false;
		          }
		         
		          else if(trim($("Phone").value)!="" && trim($("Phone").value).length!=18)
		          {
		            alert("请输入18位的身份证号码!");
		            doFun=false;
		          }
		        }
		        
		        return doFun;
    }

    function CheckCompany()
    {
      if(trim(this.Query[8]).length<8)
      {
       alert("运营编号不能为空,且长度不能少于8位!");
       $("EName").focus();
       return false;
      }
      else  if(trim(this.Query[9])=="")
      {
       alert("公司名称不能为空!");
       $("CompanyName").focus();
       return false;
      }
       else  if(trim(this.Query[14])=="")
      {
       alert("所属区域不能为空!");
       $("_Area2").focus();
       return false;
      }
       else  if(trim(this.Query[10])=="")
      {
       alert("联系电话不能为空!");
       $("_Phone").focus();
       return false;
      }
       
      else
      {
       return true;
      }
    }

    function _Reg()
    {
        var result = eval(this.ReStr);
        
        var Value=result[0]["Value"];

        var _Msg=result[1]["Msg"].split("$");
        
        var Msg="";
        for(var i=0;i<_Msg.length;i++)
        {
         Msg+=_Msg[i]+"\n";
        }
       
        if(Value=="-1")
        {
          if(GetSelectValue("Cate")=="1")
          {
        　    if(trim($("Mobile").value)!="")
        　    {
               alert("该手机号已被注册,\n请更改其它手机号进行注册!");
              }
              else
              {
              alert("该身份证号已被注册,\n请更改其它身份证号进行注册!");
              }
          }
          else
          {
           alert("该加盟编号已被注册,\n不必重新注册!");
          }
        }
        else if (Value=="-2")
        {
          alert("不存在该推荐人,请检查你的推荐人的编号是否正确!");
        }
        else if (Value=="-3")
        {
          alert("不能越位推荐,只能普通会员编号推荐普通会员，企业会员编号推荐企业会员!");
        }
         else if (Value=="-4")
        {
          alert("只有普通会员及企业会员才能推荐其下级会员!");
        }
        else if (Value=="-5")
        {
          alert("该地区已经注册了代理商，每个地区只能有一个代理商!");
        }
        else if(Value=="1")
        {
         alert(Msg);
         location.href = "/Default.aspx";
        }
        else
        {
         alert("注册失败,请重新注册!");

        }
        
    
    }
    
    function Regnext(t)
    {  
       if(t==1)
       {
       
            if(!CK.CheckForm())
            return;
            
            if(!CheckM())
            return;
            
       
       $("Reg1").style.display="none";
       $("Reg2").style.display="";
       $("NextA").style.display="none";
       $("NextB").style.display="";
       $("RegA").style.display="";
	   $("textimgA").style.display="none";
       $("textimgB").style.display="none";
	    $("textimgC").style.display="";
	   
       }
       else
       {

       $("Reg1").style.display="";
       $("Reg2").style.display="none";
       $("NextA").style.display="";
       $("NextB").style.display="none";
       $("RegA").style.display="none"; 
	   $("textimgA").style.display="none";
       $("textimgB").style.display="";
	   $("textimgC").style.display="none";

       }
       
        
       
       

    }
    
    function SelectCate()
    {
      var index=GetSelectValue("Cate");
      
      if(index==1)
      {
       $("RegA").style.display="";
       $("NextA").style.display="none";
       $("NextB").style.display="none";
       $("ParentID").value="150168";
	   $("textimgA").style.display="";
       $("textimgB").style.display="none";
	   $("textimgC").style.display="none";
      }
      else
      {
       $("RegA").style.display="none";
       $("NextA").style.display="";
       $("NextB").style.display="none";
       $("ParentID").value="626100001";
	   $("textimgA").style.display="none";
       $("textimgB").style.display="";
	   $("textimgC").style.display="none";
      }
    }
    
    
     function SetHome(obj) {
     obj.style.behavior = "url(#default#homepage)";
     obj.setHomePage("http://www.bbyt.com.cn/");
     return (false);
 }

 function AddFavorite() {

     window.external.addFavorite('http://www.bbyt.com.cn/', '欢迎光临天颖通');

 }
 
 function PayGo()
 {
   var _PayPassWord=trim($("PayPassWord").value);
   
   if(_PayPassWord=="")
   {
    alert("请输入支付密码!");
    form1.PayPassWord.focus();
   }
   else
   {
     this.ExecFun = "_PayGo";
     this.Query = new Array(_PayPassWord);
     ExecAJ("CheckPayPassWord");

   }

 }
 
 function _PayGo()
 {
  if(this.ReStr=="1")
  {
   location.href="/member/default.aspx"
  }
  else
  {
   alert("支付密码错误!");
   form1.PayPassWord.focus();
  }
 }
 
  ///ic卡平台   function PayGoic() {   var _PayPassWord=trim($("PayPassWord").value);      if(_PayPassWord=="")   {    //alert("请输入支付密码!");		form1.PayPassWord.focus();	document.getElementById('paypasserror').style.display="block";   }   else   {     this.ExecFun = "_PayGoic";     this.Query = new Array(_PayPassWord);     ExecAJ("CheckPayPassWord");   } }  function _PayGoic() {  if(this.ReStr=="1")  {   location.href="GetOrder.aspx";  }  else  {   //alert("支付密码错误!");   form1.PayPassWord.focus();   document.getElementById('paypasserror').style.display="block";  } }
 
 //拍卖类别
 function Vendue(id)
 {
 
 alert(id);
 
 }
 
 function GoUser()
 { 
     this.ExecFun = "_GoPayPassWord";
     this.Query = new Array("");
     ExecAJ("GoPayPassWord");  

 }
 function _GoPayPassWord()
 {
   if(this.ReStr=="1")
   {
    location.href="/member/default.aspx"
   }
   else
   {
     $("Login1").style.display="none";
     $("Login2").style.display="";
   }
 }
 
 function CheckInputInt(oInput)
{
    if  ('' != oInput.value.replace(/\d/g,''))
    {
        oInput.value = oInput.value.replace(/\D/g,'');
    }
}

function AddActivities(id)
{
   this.ExecFun="_AddActivityMember";
        
        this.Query=new Array
            (
              id+""
	        );
	        	        
	    ExecAJ("AddActivityMember");
}

    function _AddActivityMember()
     {
       if(this.ReStr=="1")
       {
         alert("参加活动成功!");
		// alert(this.url);
		 //alert(this.type);
		 if(this.type=="促销活动" && this.pv==1)
		 {
			 //alert(this.type);
			 Sendsms();
		 }
		 
		 if(this.url=="")
		 {
         location.reload();
		 
		 }
		 else
		 {
		 location.href=this.url;
		 }
       }
       else if(this.ReStr=="-1")
       {
         alert("您还没有登陆!");
        location.href="/LoginAndReg.aspx";
       }
        else if(this.ReStr=="0")
       {
         alert("您已经参加了该活动!");
        //location.href="/";
       }
       else
       {
        alert(this.ReStr);
       }
     }
