	function login_top(){
		var userPassword = document.getElementById("userPassword2").value;
		var userName = document.getElementById("userName2").value;
		var login_info = document.getElementById("login_info");
		if(userPassword == null || userPassword =="" || userName == null || userName == ""){
			login_info.innerHTML = "用户名或密码不能为空！！！";
		}else{
			userManagerDWR.login(userName ,userPassword,1,
				function(data){
						if(data == 0){
	         				var login_info = document.getElementById("login_info");
	         				document.getElementById("userPassword2").value = "";
	         				login_info.innerHTML = "用户名或密码错误"
	         			}else{
	         				if(data == 9){
	         					alert("用户不能重复登录");
	         				}
	         				var userinfo = document.getElementById("userinfo");
	         				
	         				var html ="";
	         				var id = data;
							userManagerDWR.isBlogUser(
								 function(data){
									if(data == true){
										html +=  "   <div class='blogin'>会员名称："+userName+"&nbsp;&nbsp; <a href='/u/home_"+id+"/index.html'>进入用户中心</a>&nbsp;&nbsp;"
										html += "<a href='/question/add.html'>我要提问<sup><img src='/images/hot.gif' /></sup></a>";
										html += "&nbsp;&nbsp;<a href='/blog/u/"+userName+"'>进入我的博客</a>";
										html += "&nbsp;&nbsp;<a href='javascript:logout_top();'>退出</a><div id='login_info' align='center' style='color: red;size: 12px;'></div>	";
									}else{
										html +=  "   <div class='blogin'>会员名称："+userName+"&nbsp;&nbsp; <a href='/u/home_"+id+"/index.html'>进入用户中心</a>&nbsp;&nbsp;"
										html += "<a href='/question/add.html'>我要提问<sup><img src='/images/hot.gif' /></sup></a>";
										html += "&nbsp;&nbsp;<a href='javascript:logout_top();'>退出</a><div id='login_info' align='center' style='color: red;size: 12px;'></div>	";
									}
									
									userinfo.innerHTML = html;
								}
							);
					    	var refreshi = document.getElementById("refreshi");
					    	if(refreshi == null || refreshi == "undefined"){
					    		
					    	}else{
					    	
						    	if(refreshi.value == 'true'){
						    		document.location.reload();
						    	}
					    	}
	         			}
				}
			);	
		}
	}
	function login_index(){
		document.forms[0].submit();
	}
//	function logout_top(){
	//	userManagerDWR.logout(
	//		function(data){
	//			var userinfo = document.getElementById("userinfo");
				
	//			var html = " <div class='blogin'>会员名称：<input type='text' class='bl_input'  id='userName2'/>&nbsp;&nbsp;密&nbsp;&nbsp;码："+
	//						"<input type='password' class='bl_input' id='userPassword2'/>&nbsp;&nbsp;"+
	//						"<input type='button' value='登录' class='bl_btn' onclick='login_top();'/>&nbsp;&nbsp;"+
	//						"<input type='button' value='免费注册' class='bl_btn2' onclick = 'reg_user();'/>&nbsp;&nbsp;"+
    //						"<div id='login_info' align='center' style='color: red;size: 12px;'></div>	";
    						
 //   			userinfo.innerHTML = html;			
				
//			}
//		);
//	}
	
		function logout_top(data){
				var userinfo = document.getElementById("userinfo");
				
				var html = " <div class='blogin'>会员名称：<input type='text' class='bl_input'  id='userName2'/>&nbsp;&nbsp;密&nbsp;&nbsp;码："+
							"<input type='password' class='bl_input' id='userPassword2'/>&nbsp;&nbsp;"+
							"<input type='button' value='登录' class='bl_btn' onclick='login_top();'/>&nbsp;&nbsp;"+
							"<input type='button' value='免费注册' class='bl_btn2' onclick = 'reg_user();'/>&nbsp;&nbsp;"+
    						"<div id='login_info' align='center' style='color: red;size: 12px;'></div>	";
    						
    			userinfo.innerHTML = html;			
				
			}
	
	function logout_index(){
		document.location.href = "/u/logout.html";
		document.location.reload();
	}
	function searcharticle(){
		var word = document.getElementById("word").value;
		if(word == null || word == ""){
			alert("查询关键字不能为空");
		}else{
			var words = word.replace("<","").replace(">"," ");
			createA("/search.do?method=searchArticle4Action&word="+words.UrlEncode());
		}
	}
	function searchtitle(){
		var word = document.getElementById("word").value;
		if(word == null || word == ""){
			alert("查询文章标题不能为空");
		}else{
			var words = word.replace("<","").replace(">"," ");
			createA("/search.do?method=searchArticle4Action&word="+words.UrlEncode());
		}
	}
	function searchquestion(){
		var word = document.getElementById("word").value;
		if(word == null || word == ""){
			alert("查询关键字不能为空");
		}else{
			var words = word.replace("<","").replace(">"," ");
			createA("/search.do?method=searchArticle4Action&s_type=2&word="+words.UrlEncode());
		}
	}	
	function searchfile(type){
	    document.getElementById("type").value  = type;
		
		document.forms[0].submit();
	}	
	function AddFavorite(sURL, sTitle)
	{
	    try
	    {
	        window.external.addFavorite(sURL, sTitle);
	    }
	    catch (e)
	    {
	        try
	        {
	            window.sidebar.addPanel(sTitle, sURL, "");
	        }
	        catch (e)
	        {
	            alert("加入收藏失败，请使用Ctrl+D进行添加");
	        }
	    }
	}
	function addHome()
	{
	    if (window.sidebar) 
	    {
	        try {
	            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
	        }
	        catch (e)
	        {
	            alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为true"); 
	        } 
	
	        var prefs =  Components.classes["@mozilla.org/preferences-service;1"].getService( Components.interfaces.nsIPrefBranch );
	        prefs.setCharPref("browser.startup.homepage",'http://www.e-dyer.com/');
	    }
	    else if(document.all)
	    {
	        document.body.style.behavior="url(#default#homepage)";
	        document.body.setHomePage('http://www.e-dyer.com/');
	    }
	    else
	    {
	        ;
	    }
	}

	
	function createA(url){ 
        var vra=document.createElement('a'); 
        vra.target='_blank'; 
        vra.href=url; 
		window.location = vra;
        document.body.appendChild(vra); 
        vra.click(); 
    }
    function simulateEvent(event,value,act) 
	{ 
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if(keyCode == value) {
			if(act == "tab"){
				event.keyCode = 9;
			}else if(act == "login"){
				login_top();
			}else if(act == "ilogin"){
				login_index();
			}else if(act == "search"){
				searcharticle();
			}else if(act == "qsearch"){
				searchquestion();
			}else if(act == "dsearch"){
				searchfile();
			}else if(act == "search_index"){
				search();
			}
		}
	} 
	function reg_user(){
		document.location.href = "/u/reg/index.html";
	}
	function wtaddArticle(){
		userManagerDWR.checkLogin(
				function (data){
					if(data == false){
						alert("要添加专利信息，请先登录");    	
					}
					document.location.href = "/add_zhuanli/index.html";
				}
			);
	}
	function wtaddequestion(){
		userManagerDWR.checkLogin(
				function (data){
					if(data == false){
						alert("要向专家提问，请先登录");    	
					}
					document.location.href = "/question/add.html";
				}
			);		
	}
	function wtaddiequestion(id){
		var userId = document.getElementById("userId");
		if(userId == null || userId == "undefined"){
			alert("要向专家提问，请先登录");  
		}else{
			if(userId.value == "" || userId.value == null){
				alert("要向专家提问，请先登录");  
			}
		}
		document.location.href = "/question_"+id+"/add.html";
	}
	function wtaddequestion(id){
		userManagerDWR.checkLogin(
				function (data){
					if(data == false){
						alert("要向专家提问，请先登录");    	
					}
					document.location.href = "/question_"+id+"/add.html";
				}
			);		
	}
	function showArea(areaId){
		
		if(areaId == -1){
			document.getElementById("area_select").style.display = 'block' ;
		}else{
			document.getElementById("area_select").style.display = 'none'; ;
		}
	}
String.prototype.UrlEncode = function()
{
    var str = this;
    str = str.replace(/./g,function(sHex)
    {
        window.EnCodeStr = "";
        window.sHex = sHex;
        window.execScript('window.EnCodeStr=Hex(Asc(window.sHex))',"vbscript");
        return window.EnCodeStr.replace(/../g,"%$&");
    });
    return str;
}

 

// 顶部用户登录(author:LeitSingChan)
function jqTopUserLogin() {
	var userName = $("#jqTopUserName").val();
	var password = $("#jqTopPassword").val();
	var loginTips = $("#topLoginTips");
	//var state = $("#jaState").val();
	var state = 0;
	
	if (userName === null || userName === "") {
		loginTips.html("用户名不能为空！");
	} else if (password === null || password === "") {
		loginTips.html("密码不能为空");
	} else if (userName.length > 16 || userName.length < 5 ||　password.length > 16 || password.length < 5) {
		loginTips.html("请认真填写用户名或密码!");
	} else {
		userManagerDWR.login(userName ,password,state,
	         		function(data){
							if(data === 0){
		         				loginTips.html("用户名或密码错误！");
		         			}else if(data < 0){
		         				alert("不能重复登录");
		         			}
						else{
							//alert("登录成功");
							var luserId = '';
							$.getJSON("/user.do?method=findUserById",'',function(data) {
								luserId = data.id;
							});
							$("#userinfo").hide(1000, function() {
								var uh = "<div class='banner_3_0'>会员名称：<span>"+userName+"</span>&emsp;&emsp;<span><a href='/u/home_"+luserId+"/index.html'>进入用户中心</a></span>&emsp;&emsp;<span><a href='/question/add.html'>我要提问<sup><img src='/images/hot.gif' /></sup></a></span>&emsp;&emsp;<span><a href='/blog/u/"+userName+"'>进入我的博客</a></span>&emsp;&emsp;<span><a href='javascript:jqUserLogout();'>退出</a></span>&ensp;&ensp;</div><div id='topLoginTips' class='banner_3_1'></div>";
								$("#userinfo").html(uh);
								$("#userinfo").show(2000);	
							}); 
							//window.location.reload();
						}
	         		}
			 );
	}
	
}


// 用户注销(author:LeitSingChan)
function jqUserLogout() {
	userManagerDWR.logout(
			function(data){
				var userinfo = $("#userinfo");
				var html = "<div class='banner_3_0'>会员名称：<input class='bl_input' name='userName2' id='jqTopUserName' onkeydown='' type='text'/>&nbsp;&nbsp;密&nbsp;&nbsp;码：<input class='bl_input' name='userPassword' id='jqTopPassword' onkeypress='' type='password'/>&nbsp;&nbsp;<input value='登录' class='bl_btn' onclick='jqTopUserLogin();' type='button'/>&nbsp;&nbsp;<input value='免费注册' onclick='reg_user();' class='bl_btn2' type='button'/>&nbsp;&nbsp;</div><div id='topLoginTips' class='banner_3_1'></div>";
    			userinfo.html(html);			
				
			}
		);
}
 
