<!--Created on 2009-8-18 By HenBo-->

$(function(){
	//导航菜单点击时样式变化
	var x;
	var nowurl = window.location.pathname.slice(1);
	var pathArr = new Array("index.php","report.php","record.php","agent/locationmanager.php","fmt_code.php","notice.php","noticex.php");	
	for (x in pathArr)
	{
		if(pathArr[x] == nowurl){
			$("#topmenu a[href*='"+nowurl+"']").addClass("s");
		}
	}
	
	//时间判断say hi.
	var sayhi = $("#timeHi");
	now = new Date(),hour = now.getHours() 
	if(hour < 6){sayhi.html("凌晨好！")} 
	else if (hour < 9){sayhi.html("早上好！")} 
	else if (hour < 12){sayhi.html("上午好！")} 
	else if (hour < 14){sayhi.html("中午好！")} 
	else if (hour < 17){sayhi.html("下午好！")} 
	else if (hour < 19){sayhi.html("傍晚好！")} 
	else if (hour < 22){sayhi.html("晚上好！")} 
	else {sayhi.html("夜里好！")} 
	
	
	//顶部推荐代码的轮换
	$("#topcode .object:not(:first)").css("display","none");
	var B=$("#topcode .object:last");
	var C=$("#topcode .object:first");
	setInterval(
	function(){
		if(B.is(":visible")){
		B.hide(300);
		C.slideDown(500).addClass("in");
		}else{
		$("#topcode .object:visible").addClass("in");
		$("#topcode .in").next().show(500);
		$(".in").hide(300).removeClass("in")}

	},3000)	


});
	
	
	var pstxt = new Array();
	pstxt[0] = "请输入正确格式的用户名(字母开头非中文).\r";
	pstxt[1] = "请输入由数字和字母组成的6至12位的密码.\r";
	pstxt[2] = "两次输入的密码不一致，请重新输入.\r";
	pstxt[3] = "网站名称不能为空";
	pstxt[4] = "请正确输入网址，例如：\r http://u.my4399.com";
	pstxt[5] = "请选择开户银行."
	pstxt[6] = "请输入收款人对应的中文名称.\r";
	pstxt[7] = "请输入银行帐号.";
	pstxt[8] = "请输入正确的手机号";
	pstxt[9] = "请输入正确的QQ号码\r";
	pstxt[10] = "请输入正确格式的邮箱地址.\r";
	pstxt[11] = "请先阅读并接受4399广告联盟用户协议.\r";
	pstxt[12] = "请选择站点分类.\r";

	
	//注册框输入信息的判断
	function checkAll(){
			//用户名
			var username = $("#username").val();
			var needstr1 = /^[a-zA-Z]\w{3,19}$/i;
			if(!needstr1.test(username)){
				alert(pstxt[0]);
				return false;
			}
			//密码
			var password = $("#passwd").val();
			var needstr2 = /^[\w\d]{6,12}$/;
			if(!needstr2.test(password)){
				alert(pstxt[1]);
				return false;
			}
			//重输密码
			var repasswd = $("#repasswd").val();			
			if(!(password == repasswd)){
				alert(pstxt[2]);
				return false;
			}
			//站点类型
			var webtype = $("#webtype").val();
			if(webtype == 0){
				alert(pstxt[12]);
				return false;
			}
			//网站名称
			var sitename = $("#sitename").val();			
			if(sitename==""){
				alert(pstxt[3]);
				return false;
			}
			//网址地址			
			var web = $("#web").val();
			var web2 = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"])*$/;
			if(!web2.test(web)){
				alert(pstxt[4]);
				return false;
			}
			//开户银行
			var bank = $("#bank").val();			
			if(bank == 0){
				alert(pstxt[5]);
				return false;
			}			
			//收款人
			var nickname = $("#person").val();
			var needcn = /^[\u0391-\uFFE5]{2,5}$/;
			if(!needcn.test(nickname)){
				alert(pstxt[6]);
				return false;
			}
			//银行帐号
			var account = $("#account").val();			
			var account2 = /^[\d]+/;
			if(!account2.test(account)){
				alert(pstxt[7]);
				return false;
			}
			//身份证
			var idcard = $("#idcard").val();			
			if(!isIdCardNo(idcard)){
				return false;	
			}
			//手机号码
			var mobile = $("#mobile").val();			
			var mobile2 = /^((\(\d{2,3}\))|(\d{3}\-))?((1(3|5|8)\d{9}))$/;
			if(!mobile2.test(mobile)){
				alert(pstxt[8]);
				return false;
			}
			//QQ
			var agentqq = $("#agentqq").val();			
			var agentqq2 = /^[\d]+/;
			if(!agentqq2.test(agentqq)){
				alert(pstxt[9]);
				return false;
			}
			//邮箱地址
			var email = $("#email").val();
			var email2 =  /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
			if(!email2.test(email)){
				alert(pstxt[10]);
				return false;
			}
			//用户协议
			var takeoff = $("input:checked").val();			
			if(!(takeoff == 1)){
				alert(pstxt[11]);
				return false;
			}	
			
			return true;
	}
	
	
	//检查身份证
	function   isIdCardNo(num)
	{
		var ifright = /([a-z]|[0-9])$/i;
		if   (!ifright.test(num))   {alert("输入的身份证格式不正确！");return   false;}
		var   len   =   num.length,   re;   
		if   (len   ==   15)
			re   =   new   RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
		else   if   (len   ==   18)
			re   =   new   RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d|\w)$/);
		else   {alert("输入的身份证数字位数不对！");   return   false;}
		var   a   =   num.match(re);
		if   (a   !=   null)
		{
			if   (len==15)
			{
				var   D   =   new   Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
				var   B   =   D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
			}
			else
			{
				var   D   =   new   Date(a[3]+"/"+a[4]+"/"+a[5]);
				var   B   =   D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
			}
			if   (!B)   {alert("输入的身份证号   "+   a[0]   +"   里出生日期不对！");   return   false;}
		}
		return   true;
	}



	//登陆框js验证
	
	function isLegal(ch)
	{
		if(ch >= '0' && ch <= '9')return true;
		if(ch >= 'a' && ch <= 'z')return true;
		if(ch >= 'A' && ch <= 'Z')return true;
		if(ch == '_')return true;
		return false;
	}
	function isAllLegal(str1)
	{
		for (i=0; i<str1.length; i++) {
			if (!isLegal(str1.charAt(i)))
			{
				return false;
			}
		}
		return true;
	}
	function valid_login(){
	
		str = login_form.username.value;
		if(!isAllLegal(str)){
			alert("名字含有非法字符（只能含有字母和数字）");
			login_form.username.focus();
			return false;
		}else if(login_form.username.value == ""){
			alert("请输入用户名！");
			login_form.username.focus();
			return false;
		}else if(login_form.password.value == ""){
			alert("请输入密码！");
			login_form.password.focus();
			return false;
		}else if(login_form.vcode.value == ""){
			alert("请输入验证码！");
			login_form.vcode.focus();
			return false;
		}
		return true;
	}







