//搜索关键词的校验
	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);
	 loadWebVote();
	 loadLeftNews();
	 loadAdvertisement1();
	  loadAdvertisement2();
	 //loadAdvertisement3();
	 loadAdvertisement4();
	})	
	function loginCheckRes(data){
		if(typeof(data)=="string")
		{
		   if(data == "0"){
		    //document.getElementById("divLogin").show;
		      $j('#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){
		    alert('用户名不能为空！');
		    return;
		}
		var userPass = document.getElementById('userPass').value;
		if(userPass == '' || userPass == null){
		   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")
			{
				//document.getElementById("userName_div").innerText='用户号不能为空！';
				 alert('用户名不能为空！');
			}
			else if(data == "1")
			{
				//document.getElementById("showMessage").innerText='用户不存在！';
				alert('用户不存在！');
			}
			else if(data == "2")
			{
				//document.getElementById("mask_div").innerText='验证码不能为空！';
				alert('验证码不能为空！');
			}else if(data == "3")
			{
			   //document.getElementById("userPass_div").innerText='用户名或密码不正确！';
			   alert('用户名或密码不正确！');
			   
			}else if(data == "4")
			{
			  //document.getElementById("showMessage").innerText='该用户为第一次登陆，请发送邮件后修改密码！';
			  alert('该用户为第一次登陆，请发送邮件后修改密码！');
			  //document.getElementById("sendEmais").style.display ="";
			}else if(data == "5")
			{
			  // document.getElementById("showMessage").innerText='该用户没有激活，请到注册邮箱激活用户！';
			  alert('该用户没有激活，请到注册邮箱激活用户！');
			  //document.getElementById("sendEmais").style.display ="";
			}
		}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;
			window.location.href=rootpath+'/indexUI.action';
		}
		
	}
	//用户退出

	function logout(){
		LoginOut.logout(logoutSuccess);
	}
	function logoutSuccess(msg){
	    if(typeof(msg)=="string"){
	       if(msg == "0"){
	         window.location.href=rootpath;
	       }
	    }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;
		  }
	    }
	}
	/**
	* 更新用户信息
	*/
	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_left')){
	    $j.ajax({
			url:rootpath+"/news!rightGet.action",
			cache:false,
			datatype:"html",
			success:function(data){
				$j("#list_left").html(data);
		   	}
			});
	  	}
	  }

	  /*
* 使用Ajax加载广告位
*/
function loadAdvertisement1(){
	if(document.getElementById('ada1')){
	    $j.ajax({
			url:rootpath+"/adver!MiddleAdSmall.action",
			cache:false,
			datatype:"html",
			success:function(data){
				$j('#ada1').html(data);
		   	}
			});
	  	}
	  }
	  /*
* 使用Ajax加载广告位
*/
function loadAdvertisement2(){
	if(document.getElementById('ada2')){
	    $j.ajax({
			url:rootpath+"/adver!indexMiddleAdBig.action",
			cache:false,
			datatype:"html",
			success:function(data){
				$j('#ada2').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('ada3')){
	    $j.ajax({
			url:rootpath+"/adver!indexBottomAdBig.action",
			cache:false,
			datatype:"html",
			success:function(data){
				$j('#ada3').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(" 邮件发送成功，请查收！");
				}
			}
		);
  }

