var j = jQuery.noConflict();
j(document).ready(function(){
    
     var key = Request("key");
     if(key!="")
     {
        j("#txtSearch").val(unescape(key));
     }
     
     var s = j("#txtSearchType").val();
     
     j("#"+s).attr("checked",true);
     GetUser();
     //OpenAxd();

}); 

var OpenAxd = function(){
    j("#btnOpenAxd").bind("onclick", function (event) {
      window.open ('/promotion/defaultpop.html', 'newwindow', 'height=392, width=620, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') 

   });
   
   var now = new Date(); 
    var yy = now.getYear(); //获取年，即2007 
    var mm = now.getMonth() + 1; //获取月，即04 
    var dd = now.getDate(); //获取该天的星期值 
    var Then =  yy +""+ mm +""+ dd;
    var axd = Site.GetCookie("OpenAxd");
  
  
    if(axd == "")
    {
        Site.SetCookie("OpenAxd",yy +""+ mm +""+ dd); 
       j("#btnOpenAxd").trigger("onclick");
       
    }
    else
    {
       if(axd != Then)
         j("#btnOpenAxd").trigger("onclick"); 
    }
   
}






var GetUser = function()
{
    j.post("/Member/regedit.ashx",{med:"hasLogin"},function(data){
     if(data=="" || data==undefined)
     {  
        j("#liLogin").show(); 
        
        j("#lllllllgggggggggggooooooooooo").val("0");
        j("#liUser").hide();
        j("#liSignOut").hide();
     }
     else
     {  
        j("#liLogin").hide(); 
        j("#liUser").show();
        j("#liUser").html("欢迎,"+data+"！<a href='/member/'>会员中心</a>"); 
        j("#liSignOut").show();
        j("#lllllllgggggggggggooooooooooo").val("1");
     }
  });
}

var SingOut = function()
{
   j.post("/Member/regedit.ashx",{med:"signOut"},function(data){
   });
   j("#liLogin").show(); 
   j("#liUser").hide();
   j("#liSignOut").hide();
   j("#lllllllgggggggggggooooooooooo").val("0");
}

var navlist = function(par)
{
   var url = "/supply/list-tid_"+par;
   var key = j.trim(j("#txtSearch").val());
   if(key != "请输入搜索关键字" && key != "")
   {
       url = url+"-key_"+key;
   }
   window.location.href = encodeURI(url) + ".html";
   return false;
}

var navlistN = function(par)
{
   var url = "/news/list.aspx?nc="+par;
   var key = j.trim(j("#txtSearch").val());
   if(key != "找资讯" && key != "")
   {
       url = url+"&key="+escape(key);
   }
   window.location.href = url;
   return false;
}

var search = function()
{
    var tid = j("#txtSTid").val();
    var url="/supply/list";
    if(j("#radSupply").attr("checked")!=undefined)
    {
        url = "/supply/list";
    }
    else if(j("#radStock").attr("checked")!=undefined)
    {
        url = "/stock/list";
    }
    else
    {
        url = "/company/list";
    }
    if(tid!="" && tid!="-1" && tid!=undefined)
    {
        url = url + "-tid_" + tid;
    }
   
    var key = j.trim(j("#txtSearch").val());
    if(key != "请输入搜索关键字" && key != "")
    {
          url = url+"-key_" + key;
    }
    url = encodeURI(url) + ".html";
    window.location.href = url;
}



var searchnews = function()
{
    var url="/news/list.aspx";
   
    var key = j.trim(j("#txtSearch").val());
    if(key != "请输入搜索关键字" && key != "")
   {
       url = url+"?key="+escape(key);
   }
   window.location.href = url;
}


 var SearchHome = function(evt) 
    {    
        evt = evt ? evt : (window.event ? window.event : null);
        if (evt.keyCode == 13) 
         {
            search();
            return true;
         }
         return true;
    }
    
    
    var SeaNews = function(evt) 
    {    
        evt = evt ? evt : (window.event ? window.event : null);
        if (evt.keyCode == 13) 
         {
            searchnews();
            return true;
         }
         return true;
    }


function RefurbishValidateCode()
{
    var img = document.getElementById('imgCode');
    img.src = '/CommonCtrl/ValidateCodeImage.aspx?tmp=' + (new Date()).getSeconds();
}
  
  
  
function Request(str)
{
    var url = location.href;
    var r = "";
    if(url==null||url=="")return r;
    if(str==null||str=="")return r;
    if(url.indexOf('?')<0)return r;
    var sp1 = url.split('?');
    if(sp1.length<1)return r;
    if(sp1[1].indexOf(str)<0)return r;
    var sp2 = sp1[1].split('&');
    if(sp2.length > 1)
    {
        for(var i=0;i<sp2.length;i++)
        {
            if(sp2[i].indexOf('=')<0)continue;
            var sp3=sp2[i].split('=');
            if(sp3.length<1)continue;
            if(sp3[0]==str)
            {
                r = sp3[1];
                break;
            }
        }
        
    }
    else
    {
        if(sp2[0].indexOf('=')<0)return r;
        var sp3=sp2[0].split('=');
        if(sp3.length<1)return r;
        if(sp3[0]==str)
        r = sp3[1];
    }
    return r;
}  

    
var Site={};
Site.ReturnRandNum=function()
{
	var now = new Date();
	var year = now.getYear();
	var month = now.getMonth() + 1;
	var day = now.getDate();
	var hour = now.getHours();
	var minute = now.getMinutes();
	var second = now.getSeconds();
	Num = year+month+day+hour+minute+second+Math.random()*(200-50);
	return Num;
}

Site.resizeImg=function(Images)
{
	if(Images.width>=600)
	{
		Images.style.width="600px";
	}
	else
	{
		Images.style.width="auto";
	}
}
Site.GetCookie=function(key)
{
	var search=key+"=";
	if(document.cookie.length>0)
	{
		var offset=document.cookie.indexOf(search);
		if(offset!=-1)
		{
			offset+=search.length;
			var end=document.cookie.indexOf(";",offset);
			if(end==-1)end=document.cookie.length;
			return unescape(document.cookie.substring(offset,end));
		}
		return "";
	}
	return "";
},

Site.SetCookie=function(key,value,expdate)
{
	if (expdate == ""||typeof(expdate)=="undefined"||expdate=="undefined") {
		var today = new Date();
		var expires = new Date();
		value = value.toString();
		//expires.setTime(today.getTime()+1000*60*60*24*365);
		expires.setTime(today.getTime() + 1000 * 60 * 30);
		document.cookie = key + "=" + escape(value) + ";path=/; expires=" + expires.toGMTString();
	}
	else
	{
		document.cookie = key + "=" + escape(value) + ";path=/; expires=" + expdate.toGMTString();
	}
},
Site.TestCookie=function()
	{
		Site.SetCookie("test","");
		var t = "test";
		Site.SetCookie("test",t);
		return Site.GetCookie("test")==t;
	},
Site.deleteCookie=function (name)
{
    var expdate = new Date();
    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
    Site.SetCookie(name, "", expdate);
}
     
