//   var oExpire = expdate.setTime(expdate.getTime() + ( 1 * 3600000 ));

//function setCookie(name, value)
////设定Cookie值
//{
//var expdate = new Date();
//var argv = setCookie.arguments;
//var argc = setCookie.arguments.length;
//var expires = (argc > 2) ? argv[2] : null;
//var path = (argc > 3) ? argv[3] : null;
//var domain = (argc > 4) ? argv[4] : null;
//var secure = (argc > 5) ? argv[5] : false;
//if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
//document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
//+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
//+((secure == true) ? "; secure" : "");
//}
//function deleteCookie(name)
////删除Cookie
//{
//var exp = new Date();
//exp.setTime (exp.getTime() - 1);
//var cval = setCookie (name);
//document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
//}
//function getCookie(name)
////获得Cookie的原始值
//{
//var arg = name + "=";
//var alen = arg.length;
//var clen = document.cookie.length;
//var i = 0;
//while (i < clen)
//{
//var j = i + alen;
//if (document.cookie.substring(i, j) == arg)
//return GetCookieVal (j);
//i = document.cookie.indexOf(" ", i) + 1;
//if (i == 0) break;
//}
//return null;
//}

function setCookie(sName, sValue, oExpires,sPath, sDomain, bSecure) 
{
    var expdate = new Date();
    expdate.setTime(expdate.getTime() + (2*60*60*1000));
    var sCookie = sName + "=" + encodeURIComponent(sValue);    
    
    sCookie += ";expires=" + expdate.toUTCString();
    sCookie += ";path=/";
    
    if (sDomain) {
        sCookie += ";domain=" + sDomain;
    }
    if (bSecure) {
        sCookie += "; secure";

    }
    //window.alert(sCookie);
    document.cookie = sCookie;
}                           
function getCookie(sName) 
{

    var sRE = "(?:; )?" + sName + "=([^;]*);?";
    var oRE = new RegExp(sRE);
    if (oRE.test(document.cookie)) {
        return decodeURIComponent(RegExp["$1"]);
    } else {
        return null;
    }
//    
//    
//    
//var arg = sName + " ";
//var alen = arg.length;
//var clen = document.cookie.length;
//var i = 0;
//while (i < clen)
//{
//var j = i + alen;
//if (document.cookie.substring(i, j) == arg)
//return GetCookieVal (j);
//i = document.cookie.indexOf(" ", i) + 1;
//if (i == 0) break;
//}
//return null;

}

//function GetCookieVal(offset) {     
//var endstr=document.cookie.indexOf (" ",offset);     
//if(endstr==-1) //没有指定其他元素       
//endstr=document.cookie.length;     
//return unescape(document.cookie.substring (offset,endstr));  }  

function deleteCookie(sName, sPath, sDomain) 
{
    var sCookie = sName + "=; expires=" + (new Date(0)).toGMTString();
    
        sCookie += "; path=/";
    

    if (sDomain) {
        sCookie += "; domain=" + sDomain;
    }
    
    document.cookie = sCookie;
}
function Request(key)
{

	var tempStr = ""
	var QueryString = location.search;
	if(QueryString.indexOf("?")>=0)
	{
		QueryString=QueryString.substr(QueryString.indexOf("?")+1)
		
		QueryString = QueryString+"&";
		if(QueryString.indexOf(key)>=0)
		{
			tempStr = QueryString.substr(QueryString.indexOf(key)+key.length+1);
			tempStr = tempStr.substr(0,tempStr.indexOf("&")).replace(/,/g,"&");
		}
		
	}
   return tempStr;
}
	
function SignIn()
{
     var n = document.getElementById("txtName").value.replace(/\s/g,"");
     var p = document.getElementById("txtPassword").value.replace(/\s/g,"");
     if(n == "")
     {
         window.alert("请输入用户名！");
         document.getElementById("txtName").focus();
     }
     else if(p == "")
     {
         window.alert("请输入密码！");
         document.getElementById("txtPassword").focus();
     }
     else
    // SouCaiCN.BLL.Ajax.Login(n,p,CallBack_SignIn);
     CallBack_SignIn(SouCaiCN.BLL.Ajax.Login(n,p));
}

function CallBack_SignIn(res)
{
   if(res != null && res.value != null)
   {
      if(res.value[2]!="false")
      {
          document.getElementById("divLogin").style.display="none";
          if(res.value[1]=="厂商会员"||res.value[1]=="VIP会员")
          {
               document.getElementById("divLogin1").style.display="";
               document.getElementById("lblUserInfo").innerHTML = res.value[0]+"&nbsp;|&nbsp;"+res.value[1];
               
                 if(res.value[3]!="2")
               window.location.href='/Factory/Factory_information.aspx';
               else window.location.href='/Henan/Factory/Factory_information.aspx';
          }
          else
          {
                document.getElementById("divLogin2").style.display="";
               document.getElementById("lblUserInfo2").innerHTML = res.value[0]+"&nbsp;|&nbsp;"+res.value[1];
               
                if(res.value[3]!="2")
               window.location.href='/XinxiHuiyuan/huiyuan_information.aspx';
               else window.location.href='/Henan/XinxiHuiyuan/huiyuan_information.aspx';     
          }
          setCookie("UserName", res.value[0]);
          setCookie("UserRole" , res.value[1]);
          
          setCookie("AccountCategoryID" , res.value[3]);
          
          if(Request("URL"))
              window.location.href = Request("URL")
      }
      else
          window.alert("帐号已被禁止！");
   }
   else
   {
    window.alert("用户帐号或密码错误！");
   }
	
}
function SignOut()
{
   SouCaiCN.BLL.Ajax.Exit();
   document.getElementById("divLogin").style.display="";
   if(getCookie("UserRole")=="厂商会员"||getCookie("UserRole")=="VIP会员")
   {
   document.getElementById("divLogin1").style.display="none";
   document.getElementById("lblUserInfo").innerHTML = null;
   }
   else
   {
   document.getElementById("divLogin2").style.display="none";
   document.getElementById("lblUserInfo2").innerHTML = null;
   }
   deleteCookie("UserName");
   deleteCookie("UserRole");
   window.alert("您已经成功退出个人系统！");
    if(getCookie("AccountCategoryID")!="2")
     window.location.reload("/Default.aspx");
     else  window.location.reload("/Henan/Default.aspx");
     
     deleteCookie("AccountCategoryID");
}
function SignManager()
{
    //window.location.href = '/Account/default.aspx';
    alert("暂不开放！");
    return false;
}
function isLogin()
{
   SouCaiCN.BLL.Ajax.isLogin(CallBack_isLogin);
}
function CallBack_isLogin(res)
{
   if(res != null && res.value == true)
   {
      document.getElementById("divLogin").style.display="none";
      if(getCookie("UserRole")=="厂商会员"||getCookie("UserRole")=="VIP会员")
      {    
      document.getElementById("divLogin1").style.display="";
      document.getElementById("lblUserInfo").innerHTML = getCookie("UserName")+"&nbsp;|&nbsp;"+ getCookie("UserRole");
      }
      else
      {
      document.getElementById("divLogin2").style.display="";
      document.getElementById("lblUserInfo2").innerHTML = getCookie("UserName")+"&nbsp;|&nbsp;"+ getCookie("UserRole");
      }
   }
}
function RegAccount()
{
   window.location.href = '/Register/step1.aspx';
}

//检查用户名
function CheckUserName()
{
    var name = document.getElementById("ctl00_cphPage_txtName").value.replace(/(^\s*)|(\s*$)/g,"");
    if(RequiredFieldValidatorEvaluateIsValid(ctl00_cphPage_RF1)&&RegularExpressionValidatorEvaluateIsValid(ctl00_cphPage_RE1))
    {
       var res = SouCaiCN.BLL.Ajax.IsExitsUser(name);
       if(res!=null&&res.value==false)
          alert("该用户名不存在！您可以注册！");
       else
          alert("该用户名已经存在！请换个用户名！")
    }
    else
       window.alert("请输入用户名(4～20个字符，由英文字母、数字组成)！");
}
function SignPress()
{
    if(event.keyCode==13)
    {   
        event.keyCode=0;
        document.getElementById("ibtnlogin").click();
    }
}

//检查是否厂商回复
function CheckisFactory()
{
   if(getCookie("UserRole")==null)
   {
    window.alert("您还没有登录，请先登录后再回复。（注：只有厂商身份能回复询价）");
    return false;
    }
   else if(getCookie("UserRole")!="厂商会员"&&getCookie("UserRole")!="VIP会员")
         {  
           window.alert("只有厂商身份才能回复询价信息！请注册为厂商身份后再回复！");
          return false;
         }
         else return true;
  
}
//在用户发布询价前检查是否有登录
function Checkisdenglu()
{
   if(getCookie("UserRole")==null)
   {
    alert("您还没有登录，请先登录后再发布询价信息！");
    } 
    else  if(getCookie("UserRole")=="厂商会员"||getCookie("UserRole")=="VIP会员")
        alert("抱歉！发布询价功能暂时只针对造价会员开通！");
        else
        {
         window.location.href = '/Xunjia/xunjia_add.aspx';
        }
}
//在用户发布招聘信息前检查是否有登录
function CheckZhaopinisdenglu()
{
   if(getCookie("UserRole")==null)
   {
    alert("您还没有登录，请先登录后再发布招聘信息！");
    } 
    else  if(getCookie("UserRole")=="厂商会员"||getCookie("UserRole")=="VIP会员")
         // window.location.href = '/Factory/Add_Factory_zhaopin.aspx';
          var timerID=setTimeout("window.location='/Factory/Add_Factory_zhaopin.aspx'", 100);
        else
        {
         alert("抱歉！该功能只针对厂商会员开通！");
        }
}
//在用户查看招标投标信息前检查是否有登录
function Checkzbtbisdenglu(res)
{
   if(getCookie("UserRole")==null)
   {
    alert("您还没有登录，请先登录后再查看招标投标信息！");
    }
   // else window.location.href = "/Article.aspx?ID="+res;
   else var timerID=setTimeout("window.location='http://www.soucaicn.com/Article.aspx?ID="+res+"'", 100);

}


function Checkzhidaojiaisdenglu(res)
{
   var timerID="";
   if(getCookie("UserRole")=="高级会员"||getCookie("UserRole")=="系统管理员"||getCookie("UserRole")=="网站编辑员"||getCookie("UserRole")=="VIP会员")
   {
        timerID=setTimeout("window.location='http://www.soucaicn.com/Index"+res+"'", 100);
    
    }
   // else window.location.href = "/Article.aspx?ID="+res;
   else alert("本功能现只对高级会员开通，详情请拨打020-38468008咨询。");
}

function IsAccoutCategory()
{
    if(getCookie("AccountCategoryID")=="2")
    {
        if(getCookie("UserRole")=="厂商会员"||getCookie("UserRole")=="VIP会员")
        window.location.href='/Henan/Factory/Factory_information.aspx';
        else
        window.location.href='/Henan/XinxiHuiyuan/huiyuan_information.aspx';
    }
    else 
    {
    if(getCookie("UserRole")=="厂商会员"||getCookie("UserRole")=="VIP会员")
        window.location.href='/Factory/Factory_information.aspx';
        else
        window.location.href='/XinxiHuiyuan/huiyuan_information.aspx';
    }
}

//广东省信息价
function Checkgdsxxj(res)
{
   if(getCookie("UserRole")=="高级会员"||getCookie("UserRole")=="系统管理员")
   {   
    var timerID=setTimeout("window.location='/XinxiHuiyuan/huiyuan_xinxijia_map.aspx'", 100);
    
    }
   // else window.location.href = "/Article.aspx?ID="+res;
   else alert("本功能现只对高级会员开通，详情请拨打020-38468008咨询。");
}
