var nM = Math.floor(1000 * 60) * 5 //分钟 


$(document).ready(function(){
	nowdatetime = new Date();
	
	//alert(nowdatetime.getTime() - getCookie('time'))
	if(getCookie('uid') != null && getCookie('uid') != "" && nowdatetime.getTime() < getCookie('time'))
	{
		
		if(getCookie('zcm') != null)
		{
		
			$("#iclogin").hide();
			$("#userid").val(getCookie('uid'));
			
			$("#wbm").html(getCookie('wbm') + "，欢迎你！");
			
			_czcmArr = getCookie('zcm').split(",");					
			_cxlhArr = getCookie('xlh').split(",");
			
			for(var i=0;i< _czcmArr.length-1;i++)
			{	
				$("#xlhlist").append("<div style='float:left;width:150px' class='xlhlist'>" + _czcmArr[i] + "</div><div style='float:right;width:230px;color:red;' class='xlhlist'>" +  _cxlhArr[i] + "</div>");
			}
			
			$("#userinfo").show();
			
			$("#head3").hide();
			$("#head5").html( getCookie('wbm') + ",欢迎你！").show();
			
			//$("#serialnumbersarea,#btn_serialnumbers").hide();
			
		}
		
	}
	
	$("#login_top_btn").click(function(){
		if($("#top_username").val() == "")
		{
			alert("请输入用户名!");
		}
		if($("#top_password").val() == "")
		{
			alert("请输入密码!");
		}
		
		if($("#top_username").val() != "" && $("#top_password").val() != "")
		{
			_url = '../servlet/LoginServlet?userName=' + $("#top_username").val() + '&password=' + $("#top_password").val() + '&num=' + Math.round(Math.random()*10000);
			
			$.ajax({
				url:_url,
				type:"Get",
				dataType: "html",
				timeout: 5000,
				error: function(data){
					//alert("错误")
					//alert(data);
				},
				success: function(data){
					
					if(data.indexOf("error") != -1)
					{
						alert("用户名或密码错误！");						
					}else if(data.indexOf("cunzai") != -1)
					{
						
						_arr = data.split(';');
						
						if(getCookie("iLP") == 1)
						{
							$("#iclogin").hide();
							$("#userid").val(_arr[1]);
							$("#wbm").html(_arr[2] + "，欢迎你！");
							
							_zcmArr = _arr[3].split(",");					
							_xlhArr = _arr[4].split(",");
							
							for(var i=0;i< _zcmArr.length-1;i++)
							{	
								$("#xlhlist").append("<div class='xlhlist' style='float:left;width:150px'>" + _zcmArr[i] + "</div><div class='xlhlist' style='float:right;width:230px;color:red;'>" +  _xlhArr[i] + "</div>");
							}
							
							$("#userinfo").show();
							//$("#serialnumbersarea,#btn_serialnumbers").hide();
						}
						
						$("#head3").hide();
						$("#head5").html( _arr[2] + ",欢迎你！").show();
						
						datetime = new Date();
						setCookie('time',datetime.getTime(),new Date(Date.parse('Jan 1,3010')));
						
						setCookie('uid',_arr[1],new Date(Date.parse('Jan 1,3010')));
						setCookie('wbm',_arr[2],new Date(Date.parse('Jan 1,3010')));
						setCookie('zcm',_arr[3],new Date(Date.parse('Jan 1,3010')));
						setCookie('xlh',_arr[4],new Date(Date.parse('Jan 1,3010')));
					}
				}
			});	
		}
	})
	
	
	var i= 1;
	
	$(".r_page").each(function(){
		
		var num = i;
		
		if(i==1)
		{			
			$(this).find('.g_page').append("<a href='#' onclick=goPage("+Math.floor(num+1)+")>下一页</a>");			
		}else if(i==$(".r_page").length)
		{			
			$(this).find('.g_page').append("<a href='#' onclick=goPage("+Math.floor(num-1)+")>上一页</a>");			
		}else{			
			$(this).find('.g_page').append("<a href='#' onclick=goPage("+Math.floor(num-1)+")>上一页</a><a href='#' onclick=goPage("+Math.floor(num+1)+")>下一页</a>");		
		}
		
		i++;		
	})	
	

	
	$('.rjcpnav .left2_1').each(function(){
		
		/*
		var _font = $(this).find("font").text();
		var _title = $(this).attr("title");
		
		$(this).find("font").text(_title);
		$(this).attr("title",_font);
		*/
		
		$(this).mouseover(function(){			
			$(this).find("span").show("normal");
			
			/*
			var _font = $(this).find("font").text();
			var _title = $(this).attr("title");
			
			$(this).find("font").text(_title);
			$(this).attr("title",_font);
			*/
		})		
		
		
		
	})
})


function goPage(_num){
	$(".r_page").each(function(){
		$(this).hide();
	})
	$("#page_" + _num).show();
	
}


function Year_Month() {
		var now = new Date();
		var yy = now.getYear();
		var mm = now.getMonth();
		var mmm = new Array();
		mmm[0] = " 1";
		mmm[1] = " 2";
		mmm[2] = " 3";
		mmm[3] = " 4";
		mmm[4] = " 5";
		mmm[5] = " 6";
		mmm[6] = " 7";
		mmm[7] = " 8";
		mmm[8] = " 9";
		mmm[9] = " 0";
		mmm[10] = "11";
		mmm[11] = "12";
		mm = mmm[mm];
		return (mm);
	}
	function thisYear() {
		var now = new Date();
		var yy = now.getYear();
		return (yy);
	}
	function Date_of_Today() {
		var now = new Date();
		return (now.getDate());
	}
	function CurentTime() {
		var now = new Date();
		var hh = now.getHours();
		var mm = now.getMinutes();
		var ss = now.getTime() % 60000;
		ss = (ss - (ss % 1000)) / 1000;
		var clock = hh + ':';
		if (mm < 10)
			clock += '0';
		clock += mm + ':';
		if (ss < 10)
			clock += '0';
		clock += ss;
		return (clock);
	}
	function refreshCalendarClock() {
		document.getElementById("time").innerHTML = "今天是：" + thisYear()+ "年" + Year_Month() + "月"+ Date_of_Today() + "日";
	}
	setInterval('refreshCalendarClock()',1000);

	function  clockon()  {
		thistime=  new  Date()
		var  hours=thistime.getHours()
		var  minutes=thistime.getMinutes()
		var  seconds=thistime.getSeconds()
		if  (eval(hours)  <10)  {hours="0"+hours}
		if  (eval(minutes)  <  10)  {minutes="0"+minutes}
		if  (seconds  <  10)  {seconds="0"+seconds}
			thistime  =  hours+":"+minutes
		return thistime;
	}
