// JavaScript Document
function getDatetime(){
	var now= new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var day=now.getDate();
	var hour=now.getHours();
	var minute=now.getMinutes();
	var second=now.getSeconds();
	document.getElementById("timers").innerHTML = year + "-" + month + "-" + day + " " + hour + ":" + minute  + ":" + second;
}


function InsertFlash(Flash,Width,Height,ID){
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
	document.write("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" ");
	document.write("width=\"" + Width + "\" height=\"" + Height + "\" id=\"" + ID + "\">");
	document.write("<param name=\"movie\" value=\"" + Flash + "\">");
	document.write("<param name=\"quality\" value=\"high\">");
	document.write("<param name=\"wmode\" value=\"transparent\">");
	document.write("<embed src=\"" + Flash + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" ");
	document.write("type=\"application/x-shockwave-flash\" width=\"" + Width + "\" height=\"" + Height + "\"></embed>");
	document.write("</object>");
}

function insertFlash(Flash,Width,Height){
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
	document.write("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" ");
	document.write("width=\"" + Width + "\" height=\"" + Height + "\">");
	document.write("<param name=\"movie\" value=\"" + Flash + "\">");
	document.write("<param name=\"quality\" value=\"high\">");
	document.write("<param name=\"wmode\" value=\"transparent\">");
	document.write("<embed src=\"" + Flash + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" ");
	document.write("type=\"application/x-shockwave-flash\" width=\"" + Width + "\" height=\"" + Height + "\"></embed>");
	document.write("</object>");
}


function showSubmenu(n){
var mtop;
var mleft;
var menuObj;
mtop = document.getElementById('c'+n).offsetTop;
mleft = document.getElementById('c'+n).offsetLeft;
menuObj = document.getElementById('m'+n);
for(i=1;i<=8;i++ ){
	document.getElementById('m'+i).style.display='none';
}
menuObj.style.display = '';
menuObj.className ='sshow';
menuObj.style.top = mtop+40+"px";
menuObj.style.left = mleft+300+"px";
}

function scoll(){
	var speed=30
	demo2.innerHTML=demo1.innerHTML
	function Marquee(){
	if(demo2.offsetWidth-demo.scrollLeft<=0)
	demo.scrollLeft-=demo1.offsetWidth
	else{
	demo.scrollLeft++
	}
	}
	var MyMar=setInterval(Marquee,speed)
	demo.onmouseover=function() {clearInterval(MyMar)}
	demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
}

function updown() {
var speed=80;
var xemo2=document.getElementById("xemo2");
var xemo1=document.getElementById("xemo1");
var xemo=document.getElementById("xemo");
xemo2.innerHTML=xemo1.innerHTML

var MyMar=setInterval(Marquee,speed);
xemo.onmouseover=function() {clearInterval(MyMar)}
xemo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
}

function Marquee()
{
	if(xemo2.offsetTop-xemo.scrollTop<=0)
		xemo.scrollTop-=xemo1.offsetHeight;
	else
	{
		xemo.scrollTop++;
	}
}

function AutoScroll(obj){
        $(obj).find("ul:first").animate({
                marginTop:"-18px"
        },500,function(){
                $(this).css({marginTop:"0px"}).find("li:first").appendTo(this);
        });
}

$(document).ready(function(){
	setInterval('AutoScroll("#scrollDiv")',2000);
	
	$("#province").change(function(){
		$("#city").empty();
		$.get("getclass.asp?parentid="+$("#province").val()+"&t="+Math.random(), function(data){
			$("#city").html(data);
		});
	});
	
	var fp = window.location.href;
	var fpStr = "index|about|news|grace|info|channel|window|contact|works|diaocha|guest|links";
		fp = fp.substring( fp.lastIndexOf('/')+1, fp.lastIndexOf('.') );
	var fpStrArr = new Array();
	var bj = false;
	fpStrArr = fpStr.split("|");	
		if(fp=="works"){
			fp="news";
		}else if(fp=="diaocha"){
			fp="channel";
		}else if(fp=="guest"){
			fp="window";
		}else if(fp=="links"){
			fp="contact";
		}
		for(var i=0;i<fpStrArr.length;i++){
			if(fp==fpStrArr[i]){
				bj = true;
			}
		}
		if(bj){
			var imgsrc = $("#"+fp).attr("src");
			imgsrc = imgsrc.substring(0,imgsrc.lastIndexOf('.'));
			imgsrc = imgsrc + "o.jpg";		
			$("#"+fp).attr("src",imgsrc);
		}
	
});


function suggtion(objID){
	var obj = document.getElementById(objID + "Sugg");
	obj.style.display = "block";
	}
function suggtionHidden(objID){
	var obj = document.getElementById(objID + "Sugg");
	obj.style.display = "none";
	}
	
function isNumber(objID)
{
	var obj = document.getElementById(objID);
	var k=window.event.keyCode;
	if (k>=48 && k<=57) 
	{
		window.event.returnValue = true;	
	}
	else{
		window.event.returnValue = false;}
		
}
function inputLen(objID,iLen)
{
	var obj = document.getElementById(objID);
	if(obj.value.length >= iLen){
		window.event.returnValue = false;
	}
}

function checkBaom()
{
	if(document.myform.RegNumber.value == "")
	{
		alert("注册号必须填写");
		document.myform.RegNumber.focus();
		return false;	
		}
	
	if(document.myform.username.value == "")
	{
		alert("姓名必须填写");
		document.myform.username.focus();
		return false;
		}
	if(document.myform.certID.value == "")
	{
		alert("身份证必须填写");
		document.myform.certID.focus();
		return false;
		}
	if(!isIDCard(document.myform.certID.value))
	{
		alert("非法身份证号码");
		document.myform.certID.focus();
		return false;
		}
	if(document.myform.studentID.value == "")
	{
		alert("考生号必须填写");
		document.myform.studentID.focus();
		return false;
		}
	if(document.myform.national.value == "")
	{
		alert("民族必须填写");
		document.myform.national.focus();
		return false;
		}
	if(document.myform.politica.value == "")
	{
		alert("政治面貌必须填写");
		document.myform.politica.focus();
		return false;
		}
	if(document.myform.birthday.value == "")
	{
		alert("出生日期必须填写");
		document.myform.birthday.focus();
		return false;
		}
	var birthday = document.myform.birthday.value;
	var certID = document.myform.certID.value;
	if(certID.substring(6,14)!= birthday.replace("-","").replace("-",""))
	{
		alert("身份证和出生日期不符\n请检查您的身份证或者出生日期是否正确！");
		return false;
		}
	if(document.myform.province.value == "")
	{
		alert("省份必须填写");
		document.myform.province.focus();
		return false;
		}
	if(document.myform.city.value == "")
	{
		alert("城市必须填写");
		document.myform.city.focus();
		return false;
		}
	if(document.myform.school.value == "")
	{
		alert("毕业中学必须填写");
		document.myform.school.focus();
		return false;
		}
	if(document.myform.address.value == "")
	{
		alert("详细地址必须填写");
		document.myform.address.focus();
		return false;
		}
	if(document.myform.address.value == "")
	{
		alert("详细地址必须填写");
		document.myform.address.focus();
		return false;
		}
	
	if(document.myform.Recipient.value == "")
	{
		alert("收件人必须填写");
		document.myform.Recipient.focus();
		return false;
		}
	if(document.myform.zipcode.value == "")
	{
		alert("邮政编码必须填写");
		document.myform.zipcode.focus();
		return false;
		}
	if(document.myform.mobile.value == "")
	{
		alert("手机号码必须填写");
		document.myform.mobile.focus();
		return false;
		}
	
	return true;
}

function checkReg()
{
	if(document.myform.UserName.value == "")
	{
		alert("考生姓名必须填写！");
		document.myform.UserName.focus();
		return false;	
		}
	if(document.myform.CertID.value == "")
	{
		alert("考生身份证必须填写！");
		document.myform.CertID.focus();
		return false;	
		}
	if(!isIDCard(document.myform.CertID.value))
	{
		alert("非法身份证号码");
		document.myform.CertID.focus();
		return false;
		}
	return true;
}

function ChkZiReg(){
	if(document.myform.userName.value == "")
	{
		alert("姓名必须填写");
		document.myform.userName.focus();
		return false;
		}
	if(document.myform.Password.value == "")
	{
		alert("密码必须填写");
		document.myform.Password.focus();
		return false;
		}
	if(document.myform.Password2.value != document.myform.Password.value)
	{
		alert("两次密码不相同");
		document.myform.Password2.focus();
		return false;
		}
	if(document.myform.birthday.value == "")
	{
		alert("出生日期必须填写");
		document.myform.birthday.focus();
		return false;
		}
	if(!isIDCard(document.myform.certID.value))
	{
		alert("非法身份证号码");
		document.myform.certID.focus();
		return false;
		}
	var birthday = document.myform.birthday.value;
	var certID = document.myform.certID.value;
	if(certID.substring(6,14)!= birthday.replace("-","").replace("-",""))
	{
		alert("身份证和出生日期不符\n请检查您的身份证或者出生日期是否正确！");
		return false;
		}
	if(document.myform.Tel.value == "")
	{
		alert("电话必须填写");
		document.myform.Tel.focus();
		return false;
		}
//	if(document.myform.Mobile.value == "")
//	{
//		alert("手机必须填写");
//		document.myform.Mobile.focus();
//		return false;
//		}
//	if(document.myform.Email.value == "")
//	{
//		alert("电子邮件必须填写");
//		document.myform.Email.focus();
//		return false;
//		}
	if(document.myform.Email.value != "" && !isEmail(document.myform.Email.value))
	{
		alert("电子邮件格式错误");
		document.myform.Email.focus();
		return false;
		}
	return true;
}
function autoBirthday(){
	var certID = document.myform.certID.value;
	var birthday = certID.substring(6,14);
	document.myform.birthday.value = birthday.substring(0,4)+"-"+birthday.substring(4,6)+"-"+birthday.substring(6,8);
	}
function checkLogin()
{
	if(document.myform.zhunkaoz.value == "")
	{
		alert("考生准考证号必须填写！");
		document.myform.zhunkaoz.focus();
		return false;	
		}
	if(document.myform.CertID.value == "")
	{
		alert("考生身份证必须填写！");
		document.myform.CertID.focus();
		return false;	
		}
	return true;
}

function openNewWin(winUrl,winName,winWidth,winHeight){
window.open(winUrl,winName,"width="+winWidth+",height="+winHeight+",scrollbars=yes,toolbar=no, status=no, menubar=no, resizable=no")	
	}


function isEmail(str)
{
        return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(str);
}

function isIDCard(sId)
{
        var iSum=0;
        var info="";

        var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"};

        if(!/^\d{17}(\d|x)$/i.test(sId))
        {
                return false;
        }
        sId=sId.replace(/x$/i,"a");
        //非法地区
        if(aCity[parseInt(sId.substr(0,2))]==null)
        {
                return false;
        }

        var sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));

        var d=new Date(sBirthday.replace(/-/g,"/"))
        
        //非法生日
        if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))
        {
                return false;
        }
        for(var i = 17;i>=0;i--) 
        {
                iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11);
        }

        if(iSum%11!=1)
        {
                return false;
        }
        return true;

}