﻿// 顶部提示
function GuidePop(){
	$("<div/>").appendTo(".header").addClass("tip-pop");
	$("<span/>").appendTo(".tip-pop").addClass("t-pop1");
	$("<span/>").appendTo(".tip-pop").addClass("t-pop2");
}
// cookie
function GetCookieVal(offset)
//获得Cookie解码后的值
{
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}


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;
    //domain = "sn110.cn";
    //path = "/";
    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 DelCookie(name)
//删除Cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = GetCookie(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;
}







//cookie end





function topSearch(formDom,inputDom,searchValue){
	//顶部搜索条
	var tip="请输入关键字...";
	var searchKey=$(inputDom);
	$(formDom).submit(function(){
		if (searchKey.val()=="" || searchKey.val()==tip){
			searchKey.val(tip);
			searchKey.select();
			return false;
		}else{
			searchAllPage('0',searchValue);
			return false;
		}
	});
	searchKey.mouseover(function(){
		$(this).select();
	});
}
/*交替行
	d(字符)：对象位置
	m(字符)：交替行方式，odd奇数行，even偶数行
	s(字符)：交替样式名
*/
function switchLine(d,m,s){
	$(d+":"+m).addClass(s);
}

/*切换栏
	i(数字)：默认显示项目,0为第一个
	t(字符)：标题列表
	c(字符)：内容列表
	s(字符)：标题选中样式
	m(字符)：触发方式：
		mouseover：鼠标移动
		click：鼠标点击
*/
function tabs(i,t,c,s,m){
	//初始化显示
	$(t).eq(i).addClass(s);
	$(c).eq(i).show().siblings().hide();
	//切换
	var _index;
	$(t).bind(m,function(){
		$(this).addClass(s).siblings().removeClass(s);
		_index=$(t).index($(this));
		$(c).eq(_index).show().siblings().hide();
	});
}
//文字大小缩放
function ZoomText(dom,textclass){
	$(dom).removeClass();
	$(dom).addClass(textclass);
}

//替换无效图片
function SwitchNullPic(dom,mode){
	switch (mode){
	   case 0: //隐藏
			$(dom).hide();
	   case mode: //使用图片替换
			this.src=mode;
	}
}

//滚动插件
(function($){
	$.fn.extend({
		Scroll:function(opt,callback){
			//参数初始化
			if(!opt) var opt={};
			var _this=$(this).eq(0).find("ul:first");
			var lineH=_this.find("li:first").height(), //获取行高
				line=opt.line?parseInt(opt.line,10):parseInt($(this).height()/lineH,10), //每次滚动的行数，默认为一屏，即父容器高度
				speed=opt.speed?parseInt(opt.speed,10):500, //卷动速度，数值越大，速度越慢（毫秒）
				timer=opt.timer?parseInt(opt.timer,10):3000; //滚动的时间间隔（毫秒）
			if(line==0) line=1;
			var upHeight=0-line*lineH;
			//滚动函数
			scrollUp=function(){
				_this.animate({
					marginTop:upHeight
				},speed,function(){
					for(i=1;i<=line;i++){
						_this.find("li:first").appendTo(_this);
					}
					_this.css({marginTop:0});
				});
			}
			//鼠标事件绑定
			_this.hover(function(){
				clearInterval(timerID);
			},function(){
				timerID=setInterval("scrollUp()",timer);
			}).mouseout();
		}        
	})
})(jQuery);


(function($) { 
$.fn.jMarquee = function(o) {
	o = $.extend({
	speed:30,
	step:1,//滚动步长
	direction:"up",//滚动方向
	visible:1//可见元素数量
	}, o || {});
	//获取滚动内容内各元素相关信息
	var i=0;
	var div=$(this);
	var ul=$("ul",div);
	var tli=$("li",ul);
	var liSize=tli.size();
	if(o.direction=="left")tli.css("float","left");
	var liWidth=tli.innerWidth();
	var liHeight=tli.height();
	var ulHeight=liHeight*liSize;
	var ulWidth=liWidth*liSize;
	
	//如果对象元素个数大于指定的显示元素则进行滚动，否则不滚动。
	if(liSize>o.visible){
		ul.append(tli.slice(0,o.visible).clone())  //复制前o.visible个li，并添加到ul的最后
		li=$("li",ul);
		liSize=li.size();
		
		//给滚动内容添加相关CSS样式
		div.css({"position":"relative",overflow:"hidden"});
		ul.css({"position":"relative",margin:"0",padding:"0","list-style":"none"});
		li.css({margin:"0",padding:"0","position":"relative"});
		
		switch(o.direction){
			case "left":
				div.css("width",(liWidth*o.visible)+"px");
				ul.css("width",(liWidth*liSize)+"px");
				li.css("float","left");
				break;
			case "up":
				div.css({"height":(liHeight*o.visible)+"px"});
				ul.css("height",(liHeight*liSize)+"px");
				break;
		}
		
	   
		var MyMar=setInterval(ylMarquee,o.speed);
		ul.hover(
			function(){clearInterval(MyMar);},
			function(){MyMar=setInterval(ylMarquee,o.speed);}
		);
	};
	function ylMarquee(){
		 
		if(o.direction=="left"){
			if(div.scrollLeft()>=ulWidth){
				div.scrollLeft(0);
			}
			else
			{
				var leftNum=div.scrollLeft();
				leftNum+=parseInt(o.step);
				div.scrollLeft(leftNum)
			}
		}
		
		if(o.direction=="up"){
			if(div.scrollTop()>=ulHeight){
			   div.scrollTop(0);
				
			}
			else{
			   var topNum=div.scrollTop();
			   topNum+=parseInt(o.step);
			   div.scrollTop(topNum);
			}
		}};
	}; 
})(jQuery);


//提示后跳转
function SureDo(src,q){
	var ret;
	ret=confirm(q);
	if(ret!=false)window.location=src;
}

//加入收藏
function AddBookmark(title, url){
var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL'; 
if(jQuery.browser.msie){ 
		window.external.AddFavorite(url, title); 
	}else if (document.all){ 
		window.external.addFavorite(url,title); 
	}else if (window.sidebar){ 
		window.sidebar.addPanel(title, url, ""); 
	}else{ 
		alert("您可以尝试通过快捷键 Ctrl + D 加入到收藏夹"); 
	}
}

//粘贴版，IE，ff下都能使用
function copy_clip(text) {
    if (window.clipboardData) {
        window.clipboardData.setData("Text", text);
    }
    else if (window.netscape) {
         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                .createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;

        // maak een transferable   
        var trans = Components.classes['@mozilla.org/widget/transferable;1']
                  .createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;
        trans.addDataFlavor('text/unicode');

        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"]
                .createInstance(Components.interfaces.nsISupportsString);
        var copytext = text;

        str.data = copytext;

        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;

        if (!clip) return false;
        clip.setData(trans, null, clipid.kGlobalClipboard);

    }
    return false;
} 

//设为首页
function SetHome(obj,url){
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);
	}
	catch(e){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch(e){
				suredo("help.html#sethome","当浏览器无法设置首页，是否查看帮助信息？");
			}
			var prefs=Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',url);
		}
	}
}

//登录
function SNPPLogin(edittype) {
   
    ClosePop('#SNPPRegister');
   mask();
   $("<div id=\"SNPPLogin\"/>").appendTo("body").addClass("snpp-pop").hide();
   $("<div class=\"snpp-pop-title\"><h2>已经是会员，请登录</h2><a href=\"javascript:void(0);\" onclick=\"ClosePop('#SNPPLogin');\">关闭</a></div><div class=\"snpp-pop-main\"><form name=\"PPLoginForm\" id=\"PPLoginForm\"><label><span>用户名：</span><input name=\"PPUser\" id=\"PPUser\"/></label><label><span>密　码：</span><input name=\"PPPwd\" id=\"PPPwd\" type=\"password\"/></label><div class=\"snpp-do\"><input id=\"PPLogin\" name=\"PPLogin\" type=\"submit\" value=\"登录\"/>&nbsp;<input type=\"button\" value=\"注册\" onclick=\"SNPPRegister(" + edittype + ");\"/></div></form></div><div id=\"landdiv\" style=\"display:none\"></div>").appendTo("#SNPPLogin");

	DOMCenter(".snpp-pop");
	
	$("#PPLogin").focus();
	$(function() {
	    $("input").keypress(function(e) {
	        if (e.which == 13) {
	            $("#PPLoginForm").submit();
	        }

	    });

	    $("#PPLoginForm").submit(function() {
	        var n = $("#PPUser");
	        var p = $("#PPPwd");
	        if (n.val() == "") {
	            alert("请输入用户名");
	            n.focus();
	            return false;
	        } else if (p.val() == "") {
	            alert("请输入密码");
	            p.focus();
	            return false;
	        } else {

	        if (edittype == undefined) {
	            
	                request(n.val(), p.val(), 0);
	                if ($("#landdiv").html() == "") {
	                    p.val("");
	                    p.focus();
	                    return false;
	                }
	                landvalid("land", 0);

	            }
	            else {
	                request(n.val(), p.val(), 5);
	                if ($("#landdiv").html() == "") {
	                    p.val("");
	                    p.focus();
	                    return false;
	                }
	                chechland(0);

	            }
	            ClosePop("#SNPPLogin");
	        }
	    });
	});

}

function CloseParentPop(dom) {
    $(window.parent.document).find("#SNPPRegister").hide();
    $(window.parent.document).find(".mask").remove();
    $(window.parent.document).find("select").show();
}
//关闭气泡
function ClosePop(dom) {
    $(dom).hide();
    $(dom).empty().remove();
    $(".mask").empty().remove();
    $("select").show();
}

//注册
function SNPPRegister(edittype) {
    var t = new Date().getMilliseconds();
    if (edittype == undefined) {
        edittype = 0;
    }
    ClosePop('#SNPPRegister');
	ClosePop("#SNPPLogin");
	mask();
	$("<div id=\"SNPPRegister\"/>").appendTo("body").addClass("snpp-pop").hide();
	$("<div class=\"snpp-pop-title\"><h2>只需一分钟，即可成为神农网会员！</h2><a href=\"javascript:void(0);\" onclick=\"ClosePop('#SNPPRegister');\">关闭</a></div><div class=\"snpp-pop-main\"><iframe frameborder=\"0\" scrolling=\"no\"></iframe></div>").appendTo("#SNPPRegister");

	$("#SNPPRegister iframe").attr("src", "/register_frame.aspx?EditType=" + edittype + "&Date=" + t.toString());
	DOMCenter(".snpp-pop");
}

//信息替换
function ChangeInfo(obj,oldinfo,newinfo){
	if ($(obj).text()==oldinfo){
		$(obj).html(newinfo);
	}
}

//遮罩层
function mask(){
	$("<div/>").appendTo("body").addClass("mask").height($(document).height());
	$("select").hide();
}

//获取坐标
function PopXY(dom){
	var pX=$(dom).offset().left;
	var pY=$(dom).offset().top;
	var cX=$(window).width()/2-$(dom).width()/2;
	var cY=$(window).scrollTop()+$(window).height()/2-$(dom).height()/2;
	$(dom).css({left:cX,top:cY});
}

//跟随滚动
function DOMScroll(dom){
	var popY=$(dom).offset().top-$(window).scrollTop();
	//alert();
	$(window).scroll(function(){
		var offsetTop=popY+$(window).scrollTop();
		$(dom).css({top:offsetTop});
	});
}

//气泡居中
function DOMCenter(dom){
	PopXY(dom);
	$(dom).fadeIn("fast");

	$(window).resize(function() {
		PopXY(dom);
		$(".mask").height($(document).height())
	});
}

//地区选择气泡 到市州
function AreaPop(dom) {
	mask();
	$(dom).remove();
	$("<div class=" + dom.substring(1,dom.length) + "/>").appendTo("body");
 	$("<div class=\"title\"><h2>请选择您的所在地：</h2><span onclick=\"ClosePop('"+ dom +"');\">关闭</span></div><ul/>").appendTo(dom);
	$.getJSON("../Asy/Place.ashx?ProvinceId=0",function(data){
		$.each(data,function(i,json1){
			$("<li><a href=\"javascript:void(0);\">" + json1.Place_Name + "</a></li>").click(function(){
				$(this).parents("ul").find(".sub-pop").remove();
				$(this).append("<div class=\"sub-pop\"><ul><li class=\"fist-area\"><a href=\"javascript:SetAreaValue('" + dom + "','" + json1.ID + "','" + json1.Place_Name + "');\">" + json1.Place_Name + "</a></li></ul></div>");
				$.getJSON("../Asy/Place.ashx?ProvinceId=" + json1.ID,function(data){
					if(data.length != 0){
						$.each(data,function(j,json2){
							$("<li><a href=\"javascript:SetAreaValue('" + dom + "','" + json2.ID + "','" + json2.Place_Name + "');\">" + json2.Place_Name + "</a></li>").appendTo(dom + ">ul>li>.sub-pop>ul");
						});
					}else{
						SetAreaValue(dom,json1.ID,json1.Place_Name);
						$(".sub-pop").remove();
					}
				});
			}).appendTo(dom + ">ul");
		});
		$(".mask").click(function(){
			$(dom + " .sub-pop").remove();
		});
		DOMCenter(dom);
	});
}

//地区设置参数
function SetAreaValue(dom,id, name) {
	ClosePop(dom);
	$(".area-select").html("<strong>" + name + "</strong> 重新选择");
	$.each(["#hid_place","#ctl00_ContentPlaceHolder1_hid_place"],function(i,n){
		$(n).val(id);
	});
}



//产品类别显示信息
function ShowProductClass(obj, steup, selobj) {

    $.get("../Asy/Place.ashx" + "?" + "ProductID=" + steup, function(data) {
        var ul = document.getElementById(obj);
        if (data.toString() == "") {
            ul.style.display = "none";
            document.getElementById("btn_add").disabled = false;
        }
        else {
            if (selobj != null) {
                selobj.className = "s a";
                document.getElementById("btn_add").disabled = true;
                
            }
            ul.style.display = "block";
            ul.innerHTML = "";
            ul.innerHTML = data.toString();
        }
    });
    
}

//类别点击事件
function ProductCheck(obj, productid) {
    
    for (var i = 0; i < obj.parentNode.children.length; i++) {
        obj.parentNode.children[i].className = "";
    }
    obj.className = "s";
    var ul = obj.parentNode.id;
    var strs = ul.split("_");
    var number = parseInt(strs[1]) + 1;
    var nextobj = strs[0] + "_" + number.toString();
    if (nextobj != "product_5") {

        for (var i = number; i < 5; i++) {
            var pid = "product_" + i.toString();
            document.getElementById(pid).style.display = "none";
            document.getElementById("c" + i).style.display = "none";
        }
        
            document.getElementById("c" + (number - 1)).style.display = "block";
            document.getElementById("c" + (number - 1)).innerText = obj.innerText;
        
        ShowProductClass(nextobj, productid, obj);
    }
    else {
        document.getElementById("btn_add").disabled = false;
        document.getElementById("c4").style.display = "block";
        document.getElementById("c4").innerText = obj.innerText;
    }
    
    document.getElementById("hid_productid").value = productid;
    
    document.getElementById("hid_producttext").value = obj.innerText;
    
}


function SendOffer() {
    window.location = "publish.aspx?ProductId=" + document.getElementById("hid_productid").value + "";

}



function G(id) {
    return document.getElementById(id);
};
function GC(t) {
    return document.createElement(t);
};
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, '');
};
function isIE() {
    return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}

function cancelSign() {
    G("sign_div").style.display = 'none';
    G("cover_div").style.display = 'none';
    document.body.style.overflow = '';
};

function popCoverDiv() {
    if (G("cover_div")) {
        G("cover_div").style.display = '';
    } else {
        var coverDiv = GC('div');
        document.body.appendChild(coverDiv);
        coverDiv.id = 'cover_div';
        with (coverDiv.style) {
            position = 'absolute';
            background = '#CCCCCC';
            left = '0px';
            top = '0px';
            var bodySize = getBodySize();
            width = bodySize[0] + 'px'
            height = bodySize[1] + 'px';
            zIndex = 98;
            if (isIE()) {
                filter = "Alpha(Opacity=60)";
            } else {
                opacity = 0.6;
            }
        }
    }
}
function getBodySize() {
    var bodySize = [];
    with (document.documentElement) {
        bodySize[0] = (scrollWidth > clientWidth) ? scrollWidth : clientWidth;
        bodySize[1] = (scrollHeight > clientHeight) ? scrollHeight : clientHeight;
    }
    return bodySize;
}
function popSign(az_id) {
    var loginDivWidth = 300;
    var sign_in_flow = '<div style="background:#FF9900;">登录</div><div>e-mail:</div><div>'
       + '<input type="text" id="sign_email" maxlength="64" size="30"/>'
       + '</div><div>password:</div><div><input type="password" id="sign_pwd" size="30"/>'
        + '</div><div><input type="button" value="login" id="sign_button"/>   '
        + '<input type="button" value="cancel" onclick="cancelSign();"/></div>';

    if (G("sign_div")) {
        G("sign_div").style.display = '';
    } else {
        var signDiv = GC('div');
        document.body.appendChild(signDiv);
        signDiv.id = 'sign_div';
        signDiv.align = "center";

        with (signDiv.style) {
            position = 'absolute';
            left = (document.documentElement.clientWidth - loginDivWidth) / 2 + 'px';
            top = (document.documentElement.clientHeight - 300) / 2 + 'px';
            width = loginDivWidth + 'px';
            zIndex = 99;
            background = '#FFFFFF';
            border = '#66CCFF solid 1px';
        }
    }
    G("sign_div").innerHTML = sign_in_flow;


}


function KeyDownButClick(butId) {
    if (event.keyCode == 13) {
        document.getElementById(butId).click();
        return false;
    }
}


function popSignFlow(az_id) {
    popCoverDiv();
    //popSign(az_id);
    document.body.style.overflow = "hidden";


}

function landvalid(obj,type) {
    var url = escape(document.location.href);
    if (top.location.href != document.location.href) {
        url = escape(top.location.href);
    }
    
   
    
    var id = GetCookie(COOKIE_Id);
    var name = GetCookie(COOKIE_UserName);
    var innerhtml;
    if (id == null) {
        if (url.indexOf("login.aspx") >= 0) {
            innerhtml = "您好，欢迎来神农网！<a href=\"" + document.location.href + "\" class=\"i-login\">[请登录]</a><a href=\"/Register.aspx\" class=\"i-reg\">[免费注册]</a>";
        }
        else {
            innerhtml="您好，欢迎来神农网！<a href=\"/login.aspx?returnUrl=" + url + "\" class=\"i-login\">[请登录]</a><a href=\"/Register.aspx\" class=\"i-reg\">[免费注册]</a>";
          
        }
        
    }
    else {
        innerhtml="您好，<a href=\"#\" class=\"i-home\">" + name + "</a>！<a href=\"#\"  class=\"i-quit\" onclick=\"exitlands('" + url + "')\">[退出]</a><a href=\"/i/MemberReceive.aspx\" class=\"i-msg\">站内信</a>&nbsp;<a href=\"/i/index.aspx\">会员中心</a>";
     
    }
    if (type == 0) //head
    {
        document.getElementById(obj).innerHTML = innerhtml;
    }
    else {
        top.document.getElementById(obj).innerHTML = innerhtml;

    }
}


function chechland(type) {
    var url = escape(document.location.href);
    if (top.location.href != document.location.href) {
        url = escape(top.location.href);
    }
    var id = GetCookie(COOKIE_Id);
    var name = GetCookie(COOKIE_UserName);
    var headhtml;
 
    if (id == null) {
        headhtml = "欢迎参加神农报价活动，请先 <a href=\"javascript:void(0)\" onclick=\"loginprice();\">登录</a> 或 <a href=\"javascript:void(0);\" onclick=\"registerprice()\">注册</a>";
        
    } else {
    headhtml = name + "您好，欢迎参加神农报价活动 ！<a href=\"javascript:void(0);\" onclick=\"exitland()\">退出</a>";
  
      

    }
    if (type == 0) {
        $("#headDiv").html(headhtml);
       
    }
    else {
        top.document.getElementById("headDiv").innerHTML = headhtml;
      
    }
}


function exitlands(url) {
    exitrequest();
    document.location.href = "/login.aspx?returnUrl=" + url;
}

//gettablefrom

function getTableForm() {
    var rawurl = window.location.href;
    var tablefrom;
    if (rawurl.toLowerCase().indexOf("news") > 0) {
        tablefrom = "article";
    }
    else if (rawurl.toLocaleLowerCase().indexOf("video") > 0) {
        tablefrom = "video";
    }
    else if (rawurl.toLocaleLowerCase().indexOf("offer") > 0) {
        tablefrom = "offer";
    }
    else if (rawurl.toLocaleLowerCase().indexOf("enterprise") > 0) {
        tablefrom = "enterprise";
    }
    else if (rawurl.toLocaleLowerCase().indexOf("product") > 0) {
        tablefrom = "eproduct";
    }
    else if (rawurl.toLocaleLowerCase().indexOf("serv") > 0 || rawurl.toLocaleLowerCase().indexOf("info") > 0) {
        tablefrom = "serv";

    }
    else if (rawurl.toLocaleLowerCase().indexOf("price") > 0) {
        tablefrom = "price";
    }
    return tablefrom;
}


function getChannel() {
    var rawurl = window.location.href;
    var channel;
    if (rawurl.toLowerCase().indexOf("pig") > 0) {
        channel = "pig";
    }
    else if (rawurl.toLocaleLowerCase().indexOf("chicken") > 0) {
        channel = "chicken";
    }
    else if (rawurl.toLocaleLowerCase().indexOf("feed") > 0) {
        channel = "feed";
    }
    //    else if (rawurl.toLocaleLowerCase().indexOf("corn") > 0) {
    //        channel = "corn";
    //    }
    else if (rawurl.toLocaleLowerCase().indexOf("fertilizer") > 0) {
        channel = "fertilizer";
    }
    else if (rawurl.toLocaleLowerCase().indexOf("food") > 0) {
        channel = "food";
    }
    else if (rawurl.toLocaleLowerCase().indexOf("cotton") > 0) {
        channel = "cotton";
    }
    return channel;

}

//RediectUrl();

function RediectUrl() {
   
    var url = window.location.href;
//    if (url.indexof("?") > 0) {
//     
//    }
}