﻿function check_cnname(str){if (str.search(/^[\u0391-\uFFE5]+$/)==-1){return false;}else{return true;}}
function isEmail(str) {if (str.search(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/) == -1){return false;}else{return true;}}
function check_tel(str) {if (str.search(/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$|^((\(\d{2,3}\))|(\d{3}\-))?1\d{10}$/) == -1){return false;}else{return true;}}
function check_zip(str){if (str.search(/^[1-9]\d{5}$/)==-1){return false;}else{return true;}}
function check_zip2(str){if (str.search(/^[1-9]\d{3}$/)==-1){return false;}else{return true;}}
function check_qq(str){if (str.search(/^[1-9]\d{4,11}$/)==-1){return false;}else{return true;}}
function check_age(str){if (str.search(/^[1-9]\d{1}$/)==-1){return false;}else{return true;}}
function check_num(str){if (str.search(/^((\(\d{2,3}\))|(\d{3}\-))?1\d{10}$/)==-1 && str!="") {return false;}else{return true;}}
function check_time(str){if (str.search(/^(\d{4})\-(\d{2})\-(\d{2})$/)==-1){return false;}else{return true;}}
function check_chinese(str){if (str.search(/^([\u4E00-\uFA29]|[\uE7C7-\uE7F3])*$/)==-1){return false;}else{return true;}}
function len(s){var l=0;var a=s.split("");for (var i=0;i<a.length;i++){if (a[i].charCodeAt(0)<299) { l++; }else{l+=2;}}return l;}
//身份证号验证 支持15和18位验证
function isIdCardNo(num)    
{      
	  num = num.toUpperCase();     
	 //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。      
	  if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num)))      
	  {    
		  alert('输入的身份证号长度不对，或者号码不符合规定！\n15位号码应全为数字，18位号码末位可以为数字或X。');    
		  return false;    
	 }    
	//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。    
	//下面分别分析出生日期和校验位    
	var len, re;    
	len = num.length;    
	if (len == 15)    
	{    
	re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);    
	var arrSplit = num.match(re);    
	  
	//检查生日日期是否正确    
	var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);    
	var bGoodDay;    
	bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));    
	if (!bGoodDay)    
	{    
			  alert('输入的身份证号里出生日期不对！');      
			   return false;    
	}    
	else    
	{    
	//将15位身份证转成18位    
	//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。    
			  var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);    
			   var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');    
			   var nTemp = 0, i;      
				num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);    
			   for(i = 0; i < 17; i ++)    
			  {    
					nTemp += num.substr(i, 1) * arrInt[i];    
			   }    
			   num += arrCh[nTemp % 11];      
				return num;      
	}      
	}    
	if (len == 18)    
	{    
	re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);    
	var arrSplit = num.match(re);    
	  
	//检查生日日期是否正确    
	var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);    
	var bGoodDay;    
	bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));    
	if (!bGoodDay)    
	{    
	alert(dtmBirth.getYear());    
	alert(arrSplit[2]);    
	alert('输入的身份证号里出生日期不对！');    
	return false;    
	}    
	else    
	{    
	//检验18位身份证的校验码是否正确。    
	//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。    
	var valnum;    
	var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);    
	var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');    
	var nTemp = 0, i;    
	for(i = 0; i < 17; i ++)    
	{    
	nTemp += num.substr(i, 1) * arrInt[i];    
	}    
	valnum = arrCh[nTemp % 11];    
	if (valnum != num.substr(17, 1))    
	{    
	alert('18位身份证的校验码不正确！应该为：' + valnum);    
	return false;    
	}    
	return num;    
	}    
	}    
	return false;    
}      
    
  
function cidInfo(sId)
{ 
	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:"国外 "};
	var iSum=0; 
	var info="";   
	if(!/^d{17}(d|x)$/i.test(sId)){return false;}   
	sId=sId.replace(/x$/i,"a");   
	if(aCity[parseInt(sId.substr(0,2))]==null){alert("非法地区");return false;}   
	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())){alert("非法生日");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){alert("非法证号");return false;} 
	}
}
//message
function TO_msg()
{
var name=$("#lname").val();
var tel=$("#tel").val();
var tel2="010-"+tel;
//var sex=$("input[name=sex]:checked").val();
//var phone=$("#qq").val();
var content=$("#cont").val();
var mail=$("#email").val();
var yzm=$("#code").val();
//var address=$("#address").val();
var sex="";
var phone="";
var address="";

if (name==""){alert("请输入您的名字！");$("#lname").focus();return false;}
if (len(name)<2){alert("您的名字也太短了吧！");$("#lname").focus();return false;}
if(tel==""){alert("请输入电话号码");$("#tel").focus();return false;}
if(tel!="" && check_tel(tel)==false && check_tel(tel2)==false){alert("请输入正确电话号码");$("#tel").focus();return false;}
//else if(phone!="" && check_num(phone)==false ){alert("请输入正确手机号码");$("#qq").focus();return false;}
//else if(phone=="" && tel=="" ){alert("请留下您的电话号码或手机号码！");$("#tel").focus();return false;}
if(mail==""){alert("请输入电子邮件");$("#email").focus();return false;}
if(mail!="" && isEmail(mail)==false){alert("请输入正确电子邮件");$("#email").focus();return false;}
//else if (address==""){alert("请输入您的联系地址！");$("#address").focus();return false;}
if (content==""){alert("请输入留言内容！");$("#cont").focus();return false;}
if (len(content)<15){alert("留言内容不少于15个字符！");$("#cont").focus();return false;}
if(yzm==""){alert("请输入验证码！");$("#code").focus();return false;}
if(len(yzm)!=4){alert("验证码格式错误！");$("#code").focus();return false;}
else{
	urls="do.php?act=msg&lname="+escape(name)+"&sex="+escape(sex)+"&tel="+escape(tel)+"&phone="+escape(phone)+"&email="+escape(mail)+"&content="+escape(content)+"&Code="+escape(yzm)+"&address="+escape(address);
	//alert(urls);return false;
	//location.href=urls;return false;
	$.ajax({
	   type: "POST",
	   url: "/do.php",
	   data: "act=msg&lname="+escape(name)+"&sex="+escape(sex)+"&tel="+escape(tel)+"&phone="+escape(phone)+"&email="+escape(mail)+"&content="+escape(content)+"&Code="+escape(yzm)+"&address="+escape(address),
	   success: function(html){
			 if (html=="ok"){alert('您的信息已提交,我们会尽快与您联系！');location.reload();}
			 if (html=="a"){window.close();}
			 if (html=="b"){alert("验证码错误！");$("#code").focus();}
		   }
		}); 
		return false;
	}

}
//加载课程列表
function load_course()
{
	$.ajax({
	   type: "POST",url: "/do.php",data: "act=course",
	   success: function(html){$("#bz1").empty().append(html);}}); return false;	
}

function TO_sign()
{
var bz1=$("#bz1").val();//所报课程
var bz2=$("#bz2").val();//年龄
var name=$("#lname").val();//年龄
var bz3=$("#bz3").val();//民族
var sex=$("#sex").val();//sex
var phone=$("#phone").val();//>
var address=$("#address").val();//现居地址
var email=$("#email").val();//现居地址
var tel=$("#tel").val();//电话

var content=$("#cont").val();//备注
var yzm=$("#code").val();//验证码

if (bz1==""){alert("请选择报名课程！");$("#bz1").focus();return false;}

if (name==""){alert("请输入您的名字！");$("#lname").focus();return false;}
if (len(name)<2){alert("您的名字也太短了吧！");$("#lname").focus();return false;}
if(phone!="" && check_num(phone)==false ){alert("请输入正确手机号码");$("#qq").focus();return false;}
if(tel!="" && check_tel(tel)==false ){alert("请输入正确电话号码");$("#tel").focus();return false;}
if(phone=="" && tel=="" ){alert("请留下您的电话号码或手机号码！");$("#phone").focus();return false;}
if(email!="" && isEmail(email)==false ){alert("请输入正确电子邮件");$("#email").focus();return false;}
if (address==""){alert("请输入您的现居住地址！");$("#address").focus();return false;}
//if (content==""){alert("请输入备注信息！");$("#cont").focus();return false;}
//if (len(content)<15){alert("备注信息不少于15个字符！");$("#cont").focus();return false;}
if(yzm==""){alert("请输入验证码！");$("#code").focus();return false;}
if(len(yzm)!=4){alert("验证码格式错误！");$("#code").focus();return false;}
else{
	  
	$.ajax({
	   type: "POST",
	   url: "/do.php",
	   data: "act=sign&bz1="+escape(bz1)+"&bz2="+escape(bz2)+"&name="+escape(name)+"&bz3="+escape(bz3)+"&sex="+escape(sex)+"&phone="+escape(phone)+"&address="+escape(address)+"&email="+escape(email)+"&tel="+escape(tel)+"&content="+escape(content)+"&yzm="+escape(yzm),
	   success: function(html){
			 if (html=="ok"){alert('您的信息已提交,我们会尽快与您联系！');location.reload();}
			 if (html=="a"){window.close();}
			 if (html=="b"){alert("验证码错误！");$("#Code").focus();}
		   }
		}); 
		return false;
	}

}
//ifranme高度自适应
function iframeHeight(did)
{
	var iframeid=document.getElementById(did); //iframe id
	if (document.getElementById)
	{
		if (iframeid && !window.opera)
		{
			if (iframeid.contentDocument && iframeid.contentDocument.body.offsetHeight)
			{
				iframeid.height = iframeid.contentDocument.body.offsetHeight;
			}
			else if(iframeid.Document && iframeid.Document.body.scrollHeight)
			{
				iframeid.height = iframeid.Document.body.scrollHeight;
			}
		}
	}
}

function getdate(){var enable=0;today=new Date();var day;var date;if(today.getDay()==0){day=" 星期日"}if(today.getDay()==1){day=" 星期一"}if(today.getDay()==2){day=" 星期二"}if(today.getDay()==3){day=" 星期三"}if(today.getDay()==4){day=" 星期四"}if(today.getDay()==5){day=" 星期五"}if(today.getDay()==6){day=" 星期六"}date=(today.getFullYear())+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日 ";document.write("今天是："+date+day)}function showT(){str="time";setInterval("document.getElementById(str).innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);}function msn(){var menuYloc = $("#QQ").offset().top;$(window).scroll(function (){ var offsetTop = menuYloc + $(window).scrollTop() +"px";$("#QQ").animate({top : offsetTop },{ duration:600 , queue:false });});}function getcode(){$("#getcode,#image1").click(function(){var timenow=new Date().getTime();$(this).attr("src","/inc/cmd_code.php?"+timenow)})}function flash(url,width,height){document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='"+width+"' height='"+height+"'><param name='movie' value='"+url+"' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='"+url+"' quality='high' wmode='transparent' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='"+width+"' height='"+height+"'></embed></object>")}function ppRoll(a){this.myA=a;this.myA.IsPlay=1;this.$(a.demo).style.overflow="hidden";this.$(a.demo).style.width=a.width;this.$(a.demo).style.height=a.height;this.$(a.demo2).innerHTML=this.$(a.demo1).innerHTML;this.$(a.demo).scrollTop=this.$(a.demo).scrollHeight;this.Marquee();this.$(a.demo).onmouseover=function(){eval(a.objStr+".clearIntervalpp();")};this.$(a.demo).onmouseout=function(){eval(a.objStr+".setTimeoutpp();")}};ppRoll.prototype.$=function(Id){return document.getElementById(Id)};ppRoll.prototype.getV=function(){alert(this.$(this.myA.demo2).offsetWidth-this.$(this.myA.demo).scrollLeft);alert(this.$(this.myA.demo2).offsetWidth);alert(this.$(this.myA.demo).scrollLeft)};ppRoll.prototype.Marquee=function(){this.MyMar=setTimeout(this.myA.objStr+".Marquee();",this.myA.speed);if(this.myA.IsPlay==1){if(this.myA.direction=="top"){if(this.$(this.myA.demo).scrollTop>=this.$(this.myA.demo2).offsetHeight){this.$(this.myA.demo).scrollTop-=this.$(this.myA.demo2).offsetHeight}else{this.$(this.myA.demo).scrollTop++}}if(this.myA.direction=="down"){if(this.$(this.myA.demo1).offsetTop-this.$(this.myA.demo).scrollTop>=0){this.$(this.myA.demo).scrollTop+=this.$(this.myA.demo2).offsetHeight}else{this.$(this.myA.demo).scrollTop--}}if(this.myA.direction=="left"){if(this.$(this.myA.demo2).offsetWidth-this.$(this.myA.demo).scrollLeft<=0){this.$(this.myA.demo).scrollLeft-=this.$(this.myA.demo1).offsetWidth}else{this.$(this.myA.demo).scrollLeft++}}if(this.myA.direction=="right"){if(this.$(this.myA.demo).scrollLeft<=0){this.$(this.myA.demo).scrollLeft+=this.$(this.myA.demo2).offsetWidth}else{this.$(this.myA.demo).scrollLeft--}}}};ppRoll.prototype.clearIntervalpp=function(){this.myA.IsPlay=0};ppRoll.prototype.setTimeoutpp=function(){this.myA.IsPlay=1}

jQuery.fn.ImageAutoSize=function(width,height){$(this).each(function(){var image=$(this);ywidth=image.width();yheight=image.height();if(yheight>height){image.height(height);image.width(height/yheight*ywidth);}if(image.width()>width){image.width(width);image.height(width/ywidth*yheight);}})};
