﻿var SitePath = "/";
var CookiePrefix = "jjw"; 
if (!('trim' in String.prototype)) {
    String.prototype.trim = function() {
        return this.replace(/(^\s*)|(\s*$)/g, "");
    }
};
var Browser={
    IE:!!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/),
    Firefox:navigator.userAgent.indexOf('Firefox/') > 0
  };
function CheckLogin(form)
{
	var UserName=form.UserName.value;
	var UserPassword=form.UserPassword.value;
	var VerifyCode=form.VerifyCode.value;
	if(UserName=="")
	{
		alert("请输入用户名");
		form.UserName.focus();
		return false;
	}
	if(UserPassword=="")
	{
		alert("请输入密码");
		form.UserPassword.focus();
		return false;
	}
	if(VerifyCode=="")
	{
		alert("请输入验证码");
		form.VerifyCode.focus();
		return false;
	}
	form.Submit1.disabled=true;
	$.post(SitePath + "Passport/login.aspx", { Action: "ajax_login", UserName: UserName, UserPassword: UserPassword, VerifyCode: VerifyCode },
		function(data, textStatus) {
		    var c = parseInt(data);
		    if (isNaN(c)) {
		        alert(data);
		    }
		    else {
		        switch (c) {
		            case 0:
		                form.Submit1.disabled = false;
		                form.Submit1.value = " ";
		                InitLogin();
		                return;
		                //document.location.href = SitePath + "Passport/index.aspx";
		                break;
		            case 1:
		                alert("登陆失败,用户名或密码错误");
		                break;
		            case 2:
		                alert("账号已被锁定，请联系管理员。");
		                break;
		            case 3:
		                alert("账号已被删除，请联系管理员。");
		                break;
		            case 10:
		                alert("请输入用户名及密码");
		                break;
		            case 4:
		                form.VerifyCode.focus();
		                alert("验证码错误");
		                break;
		            default:
		                alert(data);
		                break;
		        }
		    }
		    ShowVerifyimg(form, 'userlogin');
		    form.Submit1.disabled = false;
		}, "text");
		return false;
};
var oldloginframe;
function InitLogin() {
    var userid = cookie("Users", "UserID");
    var username = cookie("Users", "UserName");
    var nickname = cookie("Users", "NickName");
    var groupid = cookie("Users", "GroupID");
    var grouptitle = cookie("Users", "GroupTitle");
    var usertype = cookie("Users", "UserType");
    var gender = cookie("Users", "Gender");
    if (!userid || !username || !groupid || !usertype) return;
    var div = document.getElementById("loginframe");
    if (!div) return;
    if (!oldloginframe) oldloginframe = div.innerHTML;
    div.innerHTML = "<ul class=\"iloginok\"><li>" + username + ",欢迎您回来</li>"
        + "<li>会员类型：" + grouptitle + "</li>"
        + "<li><a href=\"/Passport\" target=\"_blank\">登陆会员中心</a></li>"
        + "<li><a href=\"javascript:loginout();\">退出登陆</a></li>"
        + "</ul>";
};
function loginout() {
    $.post(SitePath + "Passport/Loginout.aspx", { Action: "ajax_loginout" },
		    function(data, textStatus) {
		        document.getElementById("loginframe").innerHTML = oldloginframe;
		    }, "text");
};
function cookie(root, name, value, options) {
    root = CookiePrefix + root;
    root = root.toLowerCase();
    if (typeof value != 'undefined') { 
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [root,'=',name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i].trim();

                if (cookie.toLowerCase().substring(0, root.length + 1) == (root + '=')) {
                    var nodes = decodeURIComponent(cookie.substring(root.length + 1)).split('&');
                    for (var j = 0; j < nodes.length; j++) {
                        if (nodes[j].substring(0, name.length + 1) == (name + '=')) {
                            cookieValue = nodes[j].substring(name.length + 1);
                            break;
                        }
                    }                    
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function ShowPic(ImgD,maxwidth,maxheight)
{
	var image=new Image(); 
   image.src=ImgD.src;  
   if(image.width>0 && image.height>0){  
    if(image.width/image.height>=maxwidth/maxheight){  
     if(image.width>maxwidth){    
     ImgD.width=maxwidth;  
     ImgD.height=(image.height*maxwidth)/image.width;  
     }else{  
     ImgD.width=image.width;    
     ImgD.height=image.height;  
     }  
     }  
    else{  
     if(image.height>maxheight){    
     ImgD.height=maxheight;  
     ImgD.width=(image.width*maxheight)/image.height;       
     }else{  
     ImgD.width=image.width;    
     ImgD.height=image.height;  
     }  
     }  
    }  
};
function OpenJST(uinqd,Nick,Group){	
	var rnd=new Date();
	window.open('http://im.711688.net:8004/jst/chatWin.asp?V=1&ImTalk=2&arrCookieId='+rnd+'&Uin='+ uinqd + '&Group='+ Group + '&ShowName=' + Nick + '&Menu=no&GuestId=0',Nick,'height=471, width=611','jst')
};
function ShowVerifyimg(form,sn)
{
	if(typeof(sn)=="undefined") sn="userlogin";
	if(typeof(form)=='string')
	{
		form=document.getElementById(form);
	}
	var obj=form.getElementsByTagName("LI");
	for(var i=0;i<obj.length;i++)
	{
		if(obj[i].id=="VerifyImg")
		{
			obj[i].innerHTML="<img src=\""+SitePath+"Tools/VerifyImage.aspx?sb=1&st=1&w=55&h=20&fs=12&key="+sn+"&"+Math.random()+"\" alt=\"\" width=\"55\" height=\"20\" align=\"absMiddle\" style=\"cursor: pointer;\" />";		
			break;
		}		
	}
	with(form.VerifyCode)
	{
		onclick=null;
		onfocus=null;
		value="";
		focus();
	}
}

function vFlash(URL,width,height)
{
	this.swf=URL;
	this.width=width;
	this.height=height;
	this.Params=new Array();
	this.FlashVars=new Array();
	this.addParam=function(ParamName,ParamValue)
	{
		var obj=new Object();
		obj.name=ParamName;
		obj.value=ParamValue;
		this.Params[this.Params.length]=obj;
	};
	this.AddVars=function(ParamName,ParamValue)
	{
		var obj=new Object();
		obj.name=ParamName;
		obj.value=ParamValue;
		this.FlashVars[this.FlashVars.length]=obj;
	};
	this.write=function(obj)
	{
		var html="<object type=\"application/x-shockwave-flash\" data=\""+this.swf+"\"";
		html+=" width=\""+this.width+"\" height=\""+this.height+"\">\n";
		html+="<param name=\"movie\" value=\""+this.swf+"\" />";
		for(var i=0;i<this.Params.length-1;i++)
		{
			html+="<param name=\""+this.Params[i].name+"\" value=\""+this.Params[i].value+"\" />\n";
		}
		if(this.FlashVars.length>0)
		{
			html+="<param name=\"FlashVars\" value=\"";
			for(var i=0;i<this.FlashVars.length;i++)
			{
				html+=this.FlashVars[i].name+"="+this.FlashVars[i].value;
				if(i<this.FlashVars.length-1)html+="&";
			}
			html+="\">\n";
		}
		html+="</object>";
		if(typeof(obj)=="undefined")
		{
			document.write(html);	
		}
		else
		{
			obj.innerHTML=html;
		}
	};	
};

function ShowAds(url,w,h)
{
	var html="<iframe src=\""+url+"\" width=\""+w+"\" height=\""+h
		+"\" frameborder=\"0\" scrolling=\"no\"></iframe>";
	document.write(html);
};

function ShowHeadMenu(mid)
{
	if(mid==-1)return;
	var obj=document.getElementById("headmenu");
	var j=0;
	for(var i=0;i<obj.childNodes.length;i++)
	{
		if(obj.childNodes[i].tagName=="LI")
		{			
			with(obj.childNodes[i])
			{
				if(className!="first" && className!="hline" && className!="last")
				{
					if(mid==j)className="current";
					else className="";
					j++;
				}
			}
		}
	}
};

function vIFO_Marquee(obj)
{
    this.name="r"+obj; 
    this.Direction=1;
    this.oMarquee = document.getElementById(obj); //滚动对象 
    this.oMarquee.onmouseover=new Function(this.name+".iScrollAmount=0");
    this.oMarquee.onmouseout=new Function(this.name+".iScrollAmount=1");
    this.iLineHeight = parseInt(arguments[1]); //单行高度，像素 
    if(isNaN(this.iLineHeight))this.iLineHeight=30;
    this.iLineCount = parseInt(arguments[2]); //实际行数 
    if(isNaN(this.iLineCount))this.iLineCount=10;
    this.iScrollAmount = 1; //每次滚动高度，像素 
    this.timer = parseInt(arguments[3]); 
    if(isNaN(this.timer))this.timer=3000; 
    this.offsetHeight=this.oMarquee.childNodes[0].offsetHeight
    if(this.iLineHeight<this.offsetHeight) window.setTimeout(this.name+".run()", this.timer);
    this.run=function()
    { 
        this.oMarquee.scrollTop += this.iScrollAmount; 
        if (this.oMarquee.scrollTop+this.iLineHeight >= parseInt(this.offsetHeight))          
        {
        	window.setTimeout(this.name+".reset()", this.timer ); 
        	return;
        }
        if ( this.oMarquee.scrollTop % this.iLineHeight == 0 ) { 
            window.setTimeout(this.name+".run()", this.timer ); 
        } else { 
            window.setTimeout(this.name+".run()",50 ); 
        } 
    };
    this.reset=function()
    {
    	this.oMarquee.scrollTop = 0; 
    	window.setTimeout(this.name+".run()", this.timer ); 
    }
};

function GoToQuery(form) {
    var keyword = form.Keywords.value;
    if (keyword == "" || keyword == "请输入关键字") {
        keyword = "";
        alert("请输入关键字");
        form.Keywords.focus();
        return false;
    }
    var verifycode = form.VerifyCode.value;
    if (verifycode == "") {
        alert("请输入验证码");
        form.VerifyCode.focus();
        return false;
    }
    keyword = escape(keyword);
    var IndustryID = form.IndustryID.value;
    switch (parseInt(form.SearchType.value)) {
        case 0:
            document.location.href = SitePath + "BusinessSearch.aspx?Keywords=" + keyword + "&SearchType=1&ClassID=1&IndustryID=" + IndustryID+"&verifycode="+verifycode;
            break;
        case 1:
            document.location.href = SitePath + "BusinessSearch.aspx?Keywords=" + keyword + "&SearchType=1&ClassID=2&IndustryID=" + IndustryID+"&verifycode="+verifycode;
            break;
        case 2:
            document.location.href = SitePath + "ProductSearch.aspx?Keywords=" + keyword + "&SearchType=1&IndustryID=" + IndustryID+"&verifycode="+verifycode;
            break;
        case 3:
            document.location.href = SitePath + "ExhibitionSearch.aspx?Keywords=" + keyword + "&SearchType=1&IndustryID=" + IndustryID+"&verifycode="+verifycode;
            break;
        case 4:
            document.location.href = SitePath + "NewsSearch.aspx?Keywords=" + keyword + "&SearchType=1&verifycode="+verifycode;
            break;
        case 5:
            document.location.href = SitePath + "CompanySearch.aspx?Keywords=" + keyword + "&SearchType=1&IndustryID=" + IndustryID+"&verifycode="+verifycode;
            break;
        case 6:
            document.location.href = SitePath + "Enterprise.aspx?Keywords=" + keyword + "&SearchType=1&IndustryID=" + IndustryID+"&verifycode="+verifycode;
            break;
    }
    return false;
};

function SelCheck(obj,value)
{
	obj=document.getElementsByName(obj);
	value=','+value+',';
	for(var i=0;i<obj.length;i++)
	{
		if(value.indexOf(','+obj[i].value+',')>=0)obj[i].checked=true;
		else obj[i].checked=false;
	}
};
function SelRadio(obj,value)
{
	obj=document.getElementsByName(obj);
	for(var i=0;i<obj.length;i++)
	{
		if(obj[i].value==value)obj[i].checked=true;
		else obj[i].checked=false;
	}
};