/**
 * Ajax用户注册验证 JS
*/
//XMLHttpRequest
	var xmlhttp = false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	function Ajax(data){
		xmlhttp.open("GET","user_app.php?name="+document.getElementById("name").value,true);
		xmlhttp.send(null);
	   document.getElementById('username_notice').innerHTML = process_request;//显示状态
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4){
				if (xmlhttp.status==200){
				var responseText = xmlhttp.responseText;
				   if (responseText=="true" ){
				       ck_user("true");
				   }
				   else
                   {
				       ck_user("false");
				   }
				}else{
					alert("发生错误!");
				}
			}
		}
	}
	function chkUserName(obj){
	     if (checks(obj.value)== false)
		  {
			//obj.className = "FrameDivWarn";
			showInfo("username_notice",msg_un_format);
            change_submit("true");
		  }
		else if(obj.value.length<1){
			//obj.className = "FrameDivWarn";
			showInfo("username_notice",msg_un_blank);
            change_submit("true");
		}

		else if(obj.value.length<3){
			//obj.className = "FrameDivWarn";
			showInfo("username_notice",username_shorter);
            change_submit("true");
		}
        else if(obj.value.length>16)
        {
			showInfo("username_notice",username_chang);
            change_submit("true");
        }
		else{
			//调用Ajax函数,向服务器端发送查询
			Ajax(obj.value);
		}

	}
//--------------用户名检测---------------------//
function ck_user(result)
{
  if ( result == "true" )
  {
    //document.getElementById('name').className = "FrameDivWarn";
	showInfo("username_notice",msg_un_registered);
    change_submit("true");//禁用提交按钮
    //document.ent.name.focus();
     //return false;
  }
  else
  {
    //document.getElementById('name').className = "FrameDivPass";
	showInfo("username_notice",msg_can_rg);
    change_submit("false");//可用提交按钮
    //return false;
  }
}

function checks(t){
    szMsg="[#%&'\",;:=!^@]";
     //alertStr="";
    for(i=1;i<szMsg.length+1;i++){
     if(t.indexOf(szMsg.substring(i-1,i))>-1){
      //alertStr="请勿包含非法字符如[#_%&'\",;:=!^]";
      return false;
     }
    }
    return true;
   }


//--------------------密码检测-----------------------------//
function check_password(password)
{
    if ( password.value.length < 6 )
    {
		showInfo("password_notice",password_shorter_s);

    }
	else if(password.value.length > 30){
		showInfo("password_notice",password_shorter_m);
	}
    else
    {
		showInfo("password_notice",info_right);
    }
}


//--------------------检测密码强度-----------------------------//

function checkIntensity(pwd)
{
  var Mcolor = "#FFF",Lcolor = "#FFF",Hcolor = "#FFF";
  var m=0;

  var Modes = 0;
  for (i=0; i<pwd.length; i++)
  {
    var charType = 0;
    var t = pwd.charCodeAt(i);
    if (t>=48 && t <=57)
    {
      charType = 1;
    }
    else if (t>=65 && t <=90)
    {
      charType = 2;
    }
    else if (t>=97 && t <=122)
      charType = 4;
    else
      charType = 4;
    Modes |= charType;
  }

  for (i=0;i<4;i++)
  {
    if (Modes & 1) m++;
      Modes>>>=1;
  }

  if (pwd.length<=5)
  {
    m = 1;
  }

  switch(m)
  {
    case 1 :
      Lcolor = "2px solid red";
      Mcolor = Hcolor = "2px solid #DADADA";
    break;
    case 2 :
      Mcolor = "2px solid #f90";
      Lcolor = Hcolor = "2px solid #DADADA";
    break;
    case 3 :
      Hcolor = "2px solid #3c0";
      Lcolor = Mcolor = "2px solid #DADADA";
    break;
    case 4 :
      Hcolor = "2px solid #3c0";
      Lcolor = Mcolor = "2px solid #DADADA";
    break;
    default :
      Hcolor = Mcolor = Lcolor = "";
    break;
  }
  document.getElementById("pwd_lower").style.borderBottom  = Lcolor;
  document.getElementById("pwd_middle").style.borderBottom = Mcolor;
  document.getElementById("pwd_high").style.borderBottom   = Hcolor;

}

function check_conform_password(pit)
{
    password = document.getElementById('password').value;
    if ( pit.value.length < 6 )
    {
		showInfo("conform_password_notice",password_shorter_s);
    }
    if ( pit.value!= password)
    {
		showInfo("conform_password_notice",confirm_password_invalid);
    }
    else
    {
		showInfo("conform_password_notice",info_right);
    }
}


//-------------处理电话号码程序-----------------------------//
function check_tel(tell){
    if (check_tel_z(tell.value)==false)
    {
        showInfo("tel_notice",tel_un_error);
    }
    else
    {
       showInfo("tel_notice",tel_right);
    }
}

//-------------处理手机号码程序-----------------------------//
function check_sell(sell){
    if (check_sell_z(sell.value)==false)
    {
        showInfo("sell_notice",sell_un_error);
    }
    else
    {
       showInfo("sell_notice",sell_right);
    }
}


	function Eajax(data){
		xmlhttp.open("GET","e_mail_app.php?e_mail="+document.getElementById("e_mail").value,true);
		xmlhttp.send(null);
	    document.getElementById('email_notice').innerHTML = process_request;//显示状态
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4){
				if (xmlhttp.status==200){
				var responseText = xmlhttp.responseText;
				   if (responseText=="true" )
                   {
                       ck_Email("true");
				   }
				   else
                   {
                       ck_Email("false");
				   }
				}else{
					alert("发生错误!");
                    //return false;
				}
			}
		}
	}
//-----------EMAIL检测--------------------------------//
function checkEmail(e_mail)
{
 if (chekemail_z(e_mail.value)==false)

  {
	showInfo("email_notice",msg_email_format);
  }
 else
 {
      Eajax(e_mail.value);
   //showInfo("email_notice",info_right);
  }
}

function ck_Email(result)
{
  if ( result == "true" )
  {
    //document.getElementById('name').className = "FrameDivWarn";
       showInfo("email_notice",msg_email_registered);
       //return false;
    //document.ent.name.focus();
     //return false;
  }
  else
  {
    //document.getElementById('name').className = "FrameDivPass";
       showInfo("email_notice",info_right);
       //return true;
    //return false;
  }
}



//--------------公司名检测---------------------//
function check_addname(addname){
    if(ent.addname.value =="")
    {
        showInfo("addname_notice",addname_un_blank);
    }
    else
    {
       showInfo("addname_notice",addname_right);

    }

}

//--------------姓名检测---------------------//
function check_truename(truename){
    if(ent.truename.value =="")
    {
        showInfo("truename_notice",truename_un_blank);

    }
    else
    {
       showInfo("truename_notice",truename_right);
    }

}
//--------------行业检测---------------------//
function check_Categories(Categories){
    if(ent.Categories.value !="")
    {
        showInfo("categories_notice", categories_un_blank);
    }
}

//--------------地区检测---------------------//
/*function check_selProvince(province){
    if(ent.province.value =="")
    {
        //province.className = "FrameDivPass";
        showInfo("selProvince_notice",selProvince_un_blank);
        change_submit("true");
    }
    else
    {
       showInfo("selProvince_notice",selProvince_right);
       //province.className = "FrameDivPass";
       change_submit("false");
    }

}*/

//--------------注册协议复选框状态检测---------------------//
/*function check_agreement(){
  if (document.ent.agreement.checked==false)
  {
	 showInfo("agreement_notice",agreement);
     change_submit("true");//允许提交
}
  else
  {
	showInfo("agreement_notice",info_right);
	change_submit("false");//允许提交按
  }
}*/

//alert(UserName);

/*function change_submit()
{
     if (chkUserName(obj) == true || ck_user(result) == true || check_password(password) == true || check_conform_password(pit) == true || check_tel(tell) == true || check_sell(sell) == true || checkEmail(e_mail) == true)
     {
         //alert(zt);
        // document.forms['ent'].elements['Submit1'].disabled = 'disabled';
         document.ent.Submit1.focus();
         return false;
     }
     else
     {
        // alert(zt);
        // document.forms['ent'].elements['Submit1'].disabled = '';
         return  true;

     }
}*/

//-------------处理注册程序-----------------------------//
function register() {
    passwords = document.getElementById('password').value;
    pits = document.getElementById('pit').value;
    tells = document.getElementById('tell').value;
    sells = document.getElementById('sell').value;
    e_mails = document.getElementById('e_mail').value;
   // Categories  = document.getElementById('Categories').value;

    if(document.ent.name.value=="")
    {
        //showclass("name","FrameDivWarn");
        showInfo("username_notice",msg_un_blank);
        document.ent.name.focus();
        return false;
     }

    if(document.ent.password.value=="")
    {
        //showclass("password","FrameDivWarn");
        showInfo("password_notice",password_empty);
        document.ent.password.focus(); 
        return false;
     }

     else if(document.ent.password.value.length < 6)
     {
         showInfo("password_notice",password_shorter_s);
         document.ent.password.focus();
         return false;
     }
     else if(document.ent.password.value.length > 30)
     {
         showInfo("password_notice",password_shorter_m);
         document.ent.password.focus();
         return false;
     }


    if(document.ent.pit.value=="")
    {
        //showclass("pit","FrameDivWarn");
        showInfo("conform_password_notice",confirm_password_invalid);
        document.ent.pit.focus();
        return false;
     }
     else if(document.ent.pit.value.length < 6)
     {
         showInfo("conform_password_notice",password_shorter_s);
         document.ent.pit.focus();
         return false;
     }
     else if(document.ent.pit.value.length > 30)
     {
         showInfo("conform_password_notice",password_shorter_m);
         document.ent.pit.focus();
         return false;
     }
     else if(pits != passwords)
     {
         showInfo("conform_password_notice",confirm_password_invalid);
         document.ent.pit.focus();
         return false;
     }

     if(document.ent.tell.value=="")
     {
        //showclass("tell","FrameDivWarn");
        showInfo("tel_notice",tel_un_blank);
        document.ent.tell.focus();
        return false;
     }
     else if(check_tel_z(tells)==false)
     {
         showInfo("tel_notice",tel_un_error);
         document.ent.tell.focus();
         return false;
     }

     if(document.ent.sell.value !="" && check_sel_z(sells)==false)
     {

         showInfo("sell_notice",sell_un_error);
         document.ent.sell.focus();
         return false;
     }

     if(document.ent.e_mail.value=="")
    {
        //showclass("email","FrameDivWarn");
        showInfo("email_notice",msg_email_blank);
        document.ent.e_mail.focus();
        return false;
     }
     else if(chekemail_z(e_mails)==false)
     {
         showInfo("email_notice",msg_email_format);
         document.ent.e_mail.focus();
         return false;
     }



     if(document.ent.addname.value=="")
     {
        //showclass("addname","FrameDivWarn");
        showInfo("addname_notice",addname_un_blank);
        document.ent.addname.focus();
        return false;
     }


     if(document.ent.truename.value=="")
     {
        //showclass("truename","FrameDivWarn");
        showInfo("truename_notice",truename_un_blank);
        document.ent.truename.focus();
        return false;
     }

     if(document.ent.Categories.value=="")
     {
        showInfo("categories_notice",categories_blank);
        document.ent.Categories.focus();
        return false;
     }


     if(document.ent.selProvince.value=="")
     {
         //showInfo("selProvince_notice",selProvinec_un_blank);
         document.ent.selProvince.focus();
         return false;
     }



     if(document.ent.agreement.checked==false)
     {
        //showclass("agreement","FrameDivWarn");
        showInfo("agreement_notice",agreement_blank);
        document.ent.agreement.focus();
        return false;
     }
     if(ck_Email(result) != "false")
     {
         showInfo("email_notice",msg_email_registered);
         document.ent.e_mail.focus();
         return false;
     }
}

function check_tel_z(ctel) {
    var pattern = /^([\d]{3,4}[-][\d]{8}|[\d]{4}[-][\d]{7}|[\d]{3,4}[-][\d]{8}[-][\d]{1,4}|[\d]{4}[-][\d]{7}[-][\d]{1,4})$/i;
    //var pattern =/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,4}$/i;
    if(pattern.test(ctel)){
        return true;
    }
    else {
        return false;
    }
}

function check_sell_z(csell) {
    if(csell != "")
    {
        var pattern = /^(13[0-9]|15[0|1|3|6|7|8|9]|18[6|8|9])\d{8}$/;
        //var pattern =/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,4}$/i;
        if(pattern.test(csell)){
            return true;
        }
        else {
            return false;
        }
    }
}

function chekemail_z(temail) {
 var pattern = /^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,4}$/i;
 if(pattern.test(temail)) {
  return true;
 }
 else {
  return false;
 }
}


//------------ 按钮状态设置-----------------------------//
function change_submit(zt)
{
     if (zt == "true")
     {
         document.forms['ent'].elements['Submit1'].disabled = 'disabled';       
     }
     else
     {
         document.forms['ent'].elements['Submit1'].disabled = '';
         
     }
}


//------公用程序------------------------------------//
	function showInfo(target,Infos){
    document.getElementById(target).innerHTML = Infos;
	}
	function showclass(target,Infos){
    document.getElementById(target).className = Infos;
	}
var process_request = "<img src='images/loading.gif' width='16' height='16' border='0' align='absmiddle'>正在数据处理中...";

var emailprocess_request = "<img src='images/loading.gif' width='16' height='16' border='0' align='absmiddle'>正在数据处理中...";

var username_empty = "<span style='COLOR:#ff0000'>  × 用户名不能为空!</span>";
var username_shorter = "<span style='COLOR:#ff0000'> × 用户名长度不能少于 3 个字符。</span>";
var username_chang = "<span style='COLOR:#ff0000'> × 用户名长度不能多于 16 个字符。</span>";
var username_invalid = "- 用户名只能是由字母数字以及下划线组成。";
var password_empty = "<span style='COLOR:#ff0000'> × 登录密码不能为空。</span>";
var password_shorter_s = "<span style='COLOR:#ff0000'> × 登录密码不能少于 6 个字符。</span>";
var password_shorter_m = "<span style='COLOR:#ff0000'> × 登录密码不能多于 30 个字符。</span>";
var confirm_password_invalid = "<span style='COLOR:#ff0000'> × 两次输入密码不一致!</span>";
var email_empty = "<span style='COLOR:#ff0000'> × Email 为空</span>";
var email_invalid = "- Email 不是合法的地址";
var agreement_blank = "<span style='COLOR:#ff0000'> × 您没有接受协议</span>";
var msn_invalid = "- msn地址不是一个有效的邮件地址";
var qq_invalid = "- QQ号码不是一个有效的号码";
var home_phone_invalid = "- 家庭电话不是一个有效号码";
var office_phone_invalid = "- 办公电话不是一个有效号码";
var mobile_phone_invalid = "- 手机号码不是一个有效号码";
var msg_un_blank = "<span style='COLOR:#ff0000'> × 用户名不能为空!</span>";
var msg_un_length = "<span style='COLOR:#ff0000'> × 用户名最长不得超过15个字符</span>";
var msg_un_format = "<span style='COLOR:#ff0000'> × 用户名含有非法字符!</span>";
var msg_un_registered = "<span style='COLOR:#ff0000'> × 用户名已经存在,请重新输入!</span>";
var msg_can_rg = "<span style='COLOR:#006600'> √ 可以注册！</span>";
var msg_email_blank = "<span style='COLOR:#ff0000'> × 邮件地址不能为空!</span>";
//var msg_email_registered = " × 邮箱已存在,请重新输入!";
var msg_email_format = "<span style='COLOR:#ff0000'> × 邮件地址不合法!</span>";
var msg_email_registered = "<span style='COLOR:#ff0000'> × 邮件已经存在,请重新输入!</span>";

var username_exist = "用户名 %s 已经存在";
var info_can="<span style='COLOR:#006600'> √ 可以注册!</span>";
var info_right="<span style='COLOR:#006600'> √ 填写正确!</span>";

var tel_un_blank = "<span style='COLOR:#ff0000'> × 电话号码不能为空!</span>";
var tel_un_error = "<span style='COLOR:#ff0000'>× 不是一个有效电话号码!</span>";
var tel_right = "<span style='COLOR:#006600'>√ 填写正确!</span>";

var sell_un_error = "<span style='COLOR:#ff0000'>× 不是一个有效手机号码!</span>";
var sell_right = "<span style='COLOR:#006600'></span>";

var addname_un_blank = "<span style='COLOR:#ff0000'> × 公司名不能为空!</span>";
var addname_right = "<span style='COLOR:#006600'>√ 填写正确!</span>";

var truename_un_blank = "<span style='COLOR:#ff0000'> × 姓名不能为空!</span>";
var truename_right = "<span style='COLOR:#006600'>√ 填写正确!</span>";

var selProvince_un_blank = "<span style='COLOR:#ff0000'></span>";
var selProvince_right = "<span style='COLOR:#006600'></span>";

var categories_blank = "<span style='COLOR:#ff0000'> ×请选择行业!</span>";
var categories_un_blank = "<span style='COLOR:#006600'>√ 填写正确!</span>";
