﻿//搜索关键词的111校验
	function check(){
		if($j('#keyNews').val()==''){
			window.alert("请输入要查询的关键词!");
			return false;
		}else{
			return true;
		}
	}
//信息中心页面的关键词校验
function checkInfo(){
	if($j('#keyNews_info').val()==''){
		window.alert("请输入要查询的关键词!");
		return false;
	}else{
		return true;
	}
}
//关键字提交查询
function key_click(obj){
	var key_news=$j(obj).html();
	$j('#keyNews').val(key_news);
	$j('#searchKeyNewsUI').submit();
}

//根据随机种子生成一个随机数，用来清空Ajax请求时缓存
function getRandom(seed){
	return Math.random(seed);
}
//	//初始化加载页面时，判断用户是否已经登录
	$j(function(){
	 LoginCheck.loginCheck(loginCheckRes);
	 loadLeftNews();
	})	
	function loginCheckRes(data){
		if(typeof(data)=="string")
		{
		   if(data == "0"){
		    document.getElementById("divLogin").show;
		    document.getElementById("name").focus();
		   }
		}else if(typeof(data)=="object"){
		     if(data != null){
		      var data  = data.loginTip==null?"":data.loginTip;
		      data=replaceStr(data,"&lt;","<");
			  data=replaceStr(data,"&gt;",">");
			  document.getElementById("name").innerHTML=data;
		      document.getElementById("name").show;
		     }
		   }

	}	
	
	//用户登录
	function login(){
		var date=new Date();
		var userCode = document.getElementById("userCode").value;
		if(userCode == '' || userCode == null || userCode == "请输入用户名"){
			alert("用户名不能为空");
		    return;
		}
		var userPass = document.getElementById("userPass").value;
		if(userPass == '' || userPass == null || userPass == "请输入密码"){
			alert("密码不能为空");
		    return;
		}
		var mask = document.getElementById('mask').value;
	    if(mask == '' || mask == null){
	    	alert("验证码不能为空");
	       return;
	    }
		Login.login(userCode,userPass,mask,dologin);
	}
	function dologin(data){
		if(typeof(data)=="string")
		{
			if(data == "0")
			{
				alert("用户号不能为空！");
			}
			else if(data == "1")
			{
				alert("用户不存在！");
			}
			else if(data == "2")
			{
				alert("验证码不正确！");
			}else if(data == "3")
			{
			   alert("用户名或密码不正确！");
			}else if(data == "4")
			{
			}else if(data == "5")
			{
			}
		}else if(typeof(data)=="object"){
		   if( data != null){
		      var loginError =  data.loginError==null?"":data.loginError;
		      var loginTip = data.loginTip==null?"":data.loginTip;
		     loginSuccess(loginTip)
		   }
		}
	}
	
	function loginSuccess(loginTip){
		if(loginTip !=''){
		    document.getElementById("divLogin").hidden;
			var data=loginTip;
			data=replaceStr(data,"&lt;","<");
			data=replaceStr(data,"&gt;",">");
		
			document.getElementById("name").innerHTML=data;
			document.getElementById("divLogin").show;
			document.getElementById("name").show;
		}
		
	}
	
	//用户退出
	function logout(){
		LoginOut.logout(logoutSuccess);
	}
	function logoutSuccess(msg){
	    if(typeof(msg)=="string"){
	       if(msg == "0"){
	         window.location.href=rootpath + '/index.htm';
	       }
	    }else if(typeof(msg)=="object"){
	        var loginError =  msg.loginError==null?"":msg.loginError;
		    var loginType = msg.loginType==null?"":msg.loginType;
	    	if(loginError==''&&loginType=='logout'){
			document.getElementById("msg").style.display="none";
			document.getElementById("divLogin").style.display="";
			window.location.href=rootpath + '/index.htm';
		  }
	    }
	}
	/**
	* 更新用户信息
	*/
	function updateInfo(){
		window.location.href=rootpath+'/updateInfoUI.action';
	}
	/***
	* 更新校验码
	*/
	function refresh(obj){
        var url = obj.src;
		var date=new Date();
		url=url+"?t="+getRandom(date.getSeconds());
		obj.src= url;
	}
	/**
	* 注册
	*/
	function regist(){
		window.location.href=rootpath+'/registUI.action';
	}
	/*****
	*将str中的src字符串全部替换成dest字符串
	*
	****/
	function replaceStr(str,src,dest){
		while(str.indexOf(src)!=-1){
			str=str.replace(src,dest);
		}
		return str;
	}
/*
* 使用Ajax加载二级页面左侧
*/
function loadLeftNews(){
	if(document.getElementById('list_right')){
	    $j.ajax({
			url:rootpath+"/news!rightGet.action",
			cache:false,
			datatype:"html",
			success:function(data){
				$j("#list_right").html(data);
		   	}
			});
	  	}
	  }

	  /*
* 使用Ajax加载广告位
*/
function loadAdvertisement1(){
	if(document.getElementById('ban')){
	    $j.ajax({
			url:rootpath+"/adver!MiddleAdSmall.action",
			cache:false,
			datatype:"html",
			success:function(data){
				$j('#ban').html(data);
		   	}
			});
	  	}
	  }
	  /*
* 使用Ajax加载广告位
*/
function loadAdvertisement2(){
	if(document.getElementById('ban2')){
	    $j.ajax({
			url:rootpath+"/adver!indexMiddleAdBig.action",
			cache:false,
			datatype:"html",
			success:function(data){
				$j('#ban2').html(data);
		   	}
			});
	  	}
	  }
	  /*
* 使用Ajax加载广告位
*/
function loadAdvertisement3(){
	if(document.getElementById('banner')){
	    $j.ajax({
			url:rootpath+"/adver!indexMiddleAdOne.action",
			cache:false,
			datatype:"html",
			success:function(data){
				$j('#banner').html(data);
		   	}
			});
	  	}
	  }
	  /*
* 使用Ajax加载广告位
*/
function loadAdvertisement4(){
	if(document.getElementById('banner2')){
	    $j.ajax({
			url:rootpath+"/adver!indexBottomAdBig.action",
			cache:false,
			datatype:"html",
			success:function(data){
				$j('#banner2').html(data);
		   	}
			});
	  	}
	  }	  
	/*
	* 使用Ajax加载首页的最新调查
	*/
	function loadWebVote(){
		if(document.getElementById('webVoteInfo')){
			$j.ajax({
				url:rootpath+'/webVoteInfoAction!findNewWebVote.action',
				cache:false,
				type:"get",
				dataType:"html",
				success:function(msg){
					$j('#webVoteInfo').html(msg);
				}
			});
		}
	}
	
function ref(name) {   
  var linkname=name;   
  //iframe.src=linkname; 
  document.getElementsByName("iframe")[0].src=linkname;
  //document.all.ifrme
  //document.iframe.location.reload();   

  }   
  function sendEmail(){
    	var date=new Date();
		var params = $j("#frmLogin").serialize();
		params=params+"&t="+getRandom(date.getSeconds());
		$j.ajax({
				url:rootpath+'/sendEmaisAction.action',
				type:"get",
				data: params,
				dataType:"html",
				success:function(msg){
			     alert(" 邮件发送成功，请查收！");
				}
			}
		);
  }
  
function clearUsername() {
	var usernameValue = document.getElementById("userCode").value;
	if(usernameValue == "请输入用户名") {
		document.getElementById("userCode").value = "";
	}
}

function clearPassword() {
	var usernameValue = document.getElementById("userPassb").value;
	if(usernameValue == "请输入密码") {
		document.getElementById("userPassb").value = "";
		document.getElementById("userPassb").style.display = "none";
		document.getElementById("userPass").style.display = "";
		document.getElementById("userPass").focus();
	}
}

function clearSearch() {
	var searchValue = document.getElementById("searchContent").value;
	if(searchValue == "请输入搜索关键字或关键词") {
		document.getElementById("searchContent").value = "";
	}
}

function keyDown(event){
	if(event.keyCode==13){
		document.getElementById("loginSubmit").click();
	}
}


