//创建ajax对象
var name_re = false; 
   function name_xml()
   {
   try { 
     name_re = new XMLHttpRequest(); 
   } catch (trymicrosoft) { 
     try { 
       name_re = new ActiveXObject("Msxml2.XMLHTTP"); 
     } catch (othermicrosoft) { 
       try { 
         name_re = new ActiveXObject("Microsoft.XMLHTTP"); 
       } catch (failed) { 
         name_re = false; 
       }   
     } 
   } 
   if (!name_re) 
     alert("Error initializing XMLHttpRequest!"); 
}



var name_use;
var mail_use;

//ajax密码强度验证
function allNumber(v)
	{
		var reg = /^[0-9]*$/;
		if(reg.test(v))
		{	
			return true;
		}
		return false;
	}
	
	function CharMode(iN){
		if(iN>=48 && iN<=57)//数字
			return 1;
		if(iN>=65 && iN<=90)//大写字母
			return 2;
		if(iN>=97 && iN<=122)//小写
			return 4;
		else
			return 8;//特殊字符
	}

	//计算出当前密码当中一共有多少种模式
	function bitTotal(num){
		var modes=0;
		for(i=0;i<4;i++){
			if(num&1)
				modes++;
			num >>=1;
		}
		return	modes;
	}
		
	//返回密码的强度级别
	function checkStrong(sPW){
		if(sPW.length<6)
			return 0;//密码太短 
		var Modes=0;
		for(i=0;i<sPW.length;i++){
		//测试每一个字符的类别并统计一共有多少种模式.
		Modes|=CharMode(sPW.charCodeAt(i));
		}
	//	alert(bitTotal(Modes));
		return bitTotal(Modes);
	}

	
	function showStrongPic()
	{
		var v = document.getElementById('u_pass').value;
		var m = checkStrong(v);
		if(m < 2)
		{
			document.getElementById('lowPic').style.display="";
			document.getElementById('midPic').style.display="none";
			document.getElementById('highPic').style.display="none";
		}
		else if(m==2)
		{
			document.getElementById('lowPic').style.display="none";
			document.getElementById('midPic').style.display="";
			document.getElementById('highPic').style.display="none";
		}
		else 
		{
			document.getElementById('lowPic').style.display="none";
			document.getElementById('midPic').style.display="none";
			document.getElementById('highPic').style.display="";
		}
	}
	


//ajax验证码验证
function isCheckCode(){
var CheckCode = document.getElementById('CheckCode').value;
if (CheckCode==""){
document.getElementById('CheckCode_re').innerHTML='<img src=check_error.gif>';
document.getElementById('CheckCode_re_m').innerHTML='<span class=msg>验证码不能为空！</span>';
return false;
}else{
Code_ajax(CheckCode)
}
}

function Code_ajax(CheckCode){
var Code=CheckCode;
var url="code_ajax.asp?Code="+ escape(Code); 
     name_xml();
     name_re.open("GET", url, true); 
     name_re.setRequestHeader("content-type","text/xml");
     name_re.onreadystatechange = Code_requst; 
name_re.setRequestHeader("If-Modified-Since","0");
     name_re.send(null); 
}

function Code_requst(){
if(name_re.readyState==4 && name_re.status==200)//返回完成
{
var msg=name_re.responseText;
if (msg=="yes"){
document.getElementById('CheckCode_re').innerHTML='<img src=check_error.gif>';
document.getElementById('CheckCode_re_m').innerHTML='<span class=msg>验证码错误！</span>';
Code_msg(0);
return false;
}
else{
document.getElementById('CheckCode_re').innerHTML='<img src=check_right.gif>';
document.getElementById('CheckCode_re_m').innerHTML='<span class=msg2>输入正确！</span>';
Code_msg(1);
return true;
}
}
}
function Code_msg(n){
var n=n;
if(n==0){
Code_use=true;
}
else{
Code_use=false;
}
}





//性别是否选择检测
function sex(){
if(document.form2.u_sex[0].checked==false && document.form2.u_sex[1].checked==false && document.form2.u_sex[2].checked==false) {
document.getElementById('sex_re').innerHTML='<img src=check_error.gif>';
document.getElementById('sex_re_m').innerHTML='<span class=msg>没有选择性别</span>';
return false;
} 
else{
document.getElementById('sex_re').innerHTML='<img src=check_right.gif>';
document.getElementById('sex_re_m').innerHTML='<span class=msg2>已选择</span>';
return true;
}
}

//密码是否为空检测
function password(){
var u_pass = document.getElementById('u_pass').value;
if(u_pass=="" || u_pass.length<6){
document.getElementById('pass_re').innerHTML='<img src=check_error.gif>';
return false;
}
else{
document.getElementById('pass_re').innerHTML='<img src=check_right.gif>';
return true;
}
}

//确认密码检测
function pass_re(){
var u_pass=document.getElementById('u_pass').value;
var pass_re=document.getElementById('u_pass_re').value;
if(u_pass != pass_re){
document.getElementById('pass_re_re').innerHTML='<img src=check_error.gif>';
document.getElementById('pass_re_re_m').innerHTML='<span class=msg>两次密码不一致，请重新输入</span>';
return false;
}
else{
document.getElementById('pass_re_re').innerHTML='<img src=check_right.gif>';
document.getElementById('pass_re_re_m').innerHTML='<span class=msg2>填写正确</span>';
return true;
}
}

//密码保护问题检测
function answer(){
var u_answer=document.getElementById('u_answer').value; 
if(u_answer==""){
document.getElementById('answer_re').innerHTML='<img src=check_error.gif>';
document.getElementById('answer_re_m').innerHTML='<span class=msg>请填写问题答案</span>';
return false;
}
else{
document.getElementById('answer_re').innerHTML='<img src=check_right.gif>';
document.getElementById('answer_re_m').innerHTML='<span class=msg2>填写正确</span>';
return true;
}
}

//邮箱格式验证
function isEmail() {
var u_mail=document.getElementById('u_mail').value;
if (u_mail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
email_ajax(u_mail);
}
else{
document.getElementById('mail_re').innerHTML='<img src=check_error.gif>';
document.getElementById('mail_re_m').innerHTML='<span class=msg>请输入正确的邮箱地址，格式为：123456@qq.com</span>';
return false;
}
}

function email_ajax(u_mail){
var email=u_mail;
var url="ajax.asp?action=email&mail="+ escape(email); 
     name_xml();
     name_re.open("GET", url, true); 
     name_re.setRequestHeader("content-type","text/xml");
     name_re.onreadystatechange = mail_requst; 
name_re.setRequestHeader("If-Modified-Since","0");
     name_re.send(null); 
}

function mail_requst(){
if(name_re.readyState==4 && name_re.status==200)//返回完成
{
var msg=name_re.responseText;
if (msg=="yes"){
document.getElementById('mail_re').innerHTML='<img src=check_error.gif>';
document.getElementById('mail_re_m').innerHTML='<span class=msg>该邮箱已被使用，请换一个</span>';
mail_msg(0);
return false;
}
else{
document.getElementById('mail_re').innerHTML='<img src=check_right.gif>';
document.getElementById('mail_re_m').innerHTML='<span class=msg2>可以使用</span>';
mail_msg(1);
return true;
}
}
}
function mail_msg(n){
var n=n;
if(n==0){
mail_use=true;
}
else{
mail_use=false; 
}
}

//真实姓名检测
function name_zs(){
var name_zs=document.getElementById('u_name_zs').value; 
if (name_zs != name_zs.replace(/[^\u4E00-\u9FA5]/g,'')|| name_zs=="" || name_zs.length<2){
document.getElementById('name_zs_re').innerHTML='<img src=check_error.gif>';
document.getElementById('name_zs_re_m').innerHTML='<span class="msg">请输入真实的中文名字</span>';
return false;
}
else{
document.getElementById('name_zs_re').innerHTML='<img src=check_right.gif>';
document.getElementById('name_zs_re_m').innerHTML='<span class="msg2">填写正确</span>';
return true;
}
}

//QQ号码检测
function qq(){
var qq=document.getElementById('u_qq').value;
if(qq=="" || qq.length<5){
document.getElementById('qq_re').innerHTML='<img src=check_error.gif>';
document.getElementById('qq_re_m').innerHTML='<span class="msg">正确的QQ是5-10位哦</span>';
return false;
}
else{
document.getElementById('qq_re').innerHTML='<img src=check_right.gif>';
document.getElementById('qq_re_m').innerHTML='<span class="msg2">填写正确</span>';
return true;
}
}

//检测支付宝帐号
function alipay(){
var alipay=document.getElementById('u_alipay').value;
if (alipay.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
document.getElementById('alipay_re').innerHTML='<img src=check_right.gif>';
document.getElementById('alipay_re_m').innerHTML='<span class=msg2>填写正确</span>';
return true;
}
else{
document.getElementById('alipay_re').innerHTML='<img src=check_error.gif>';
document.getElementById('alipay_re_m').innerHTML='<span class=msg>错误的支付宝帐号</span>';
return false;
}
}

//身份证号码检测
function nunber(){
var idcard=document.getElementById('u_nunber').value;
var Errors=new Array("验证通过!","身份证号码位数不对!","出生日期超出范围或含有非法字符!","身份证号码校验错误!","身份证地区非法!");
var area={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 idcard,Y,JYM;
var S,M;
var idcard_array = new Array();
idcard_array = idcard.split("");
if(area[parseInt(idcard.substr(0,2))]==null) 
{
document.getElementById('nunber_re').innerHTML='<img src=check_error.gif>';
     document.getElementById('nunber_re_m').innerHTML="<span class=msg>"+Errors[4]+"</span>";
return false;
}

switch(idcard.length){
   case 15:
   if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){
    ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;
   } else {
    ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;
   }
   if(ereg.test(idcard)){
document.getElementById('nunber_re').innerHTML='<img src=check_right.gif>';
     document.getElementById('nunber_re_m').innerHTML="<span class=msg2>"+Errors[0]+"</span>";
return true;
    }
   else {
document.getElementById('nunber_re').innerHTML='<img src=check_error.gif>';
     document.getElementById('nunber_re_m').innerHTML="<span class=msg>"+Errors[2]+"</span>";
return false;
     }
   break; 
   case 18:
   //18位身份号码检测
   if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){
   ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;
   } else {
   ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;
   }
   if(ereg.test(idcard)){
    S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
    + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
    + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
    + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
    + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
    + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
    + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
    + parseInt(idcard_array[7]) * 1 
    + parseInt(idcard_array[8]) * 6
    + parseInt(idcard_array[9]) * 3 ;
    Y = S % 11;
    M = "F";
    JYM = "10X98765432";
    M = JYM.substr(Y,1);
    if(M == idcard_array[17]){
document.getElementById('nunber_re').innerHTML='<img src=check_right.gif>';
     document.getElementById('nunber_re_m').innerHTML="<span class=msg2>"+Errors[0]+"</span>";
     return true;
    }
    else {
document.getElementById('nunber_re').innerHTML='<img src=check_error.gif>';
     document.getElementById('nunber_re_m').innerHTML="<span class=msg>"+Errors[3]+"</span>";
     return false;
    }
   }
   else {
document.getElementById('nunber_re').innerHTML='<img src=check_error.gif>';
    document.getElementById('nunber_re_m').innerHTML="<span class=msg>"+Errors[2]+"</span>";
    return false;
   }
   break;
   default: 
document.getElementById('nunber_re').innerHTML='<img src=check_error.gif>';
    document.getElementById('nunber_re_m').innerHTML="<span class=msg>"+Errors[1]+"</span>";
    return false;
}
}













//全表单提交验证
function tijiao(){




if (isCheckCode()==false){
alert("验证码不能为空！");
return false;
}
if (Code_use==true){
alert("验证码输入错误，请输入正确的验证码！");
return false;
}


document.frmAnnounce.submit();
return true;
}
