﻿var mail_re =/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/g; //邮箱正则
var userid_re=/^[0-9a-z][\w-.]*[0-9a-z]$/i; //用户ID正则
var phone_reg=/^(((\()?\d{2,4}(\))?[-(\s)*]){0,2})?(\d{7,8})$/; //电话号码正则

/*
==================================================================
ResumeError():屏敝JS错误信息
==================================================================
*/

function ResumeError(){
	return true;
}
window.onerror = ResumeError;

/*
==================================================================
Trim(string):去除前后空格
==================================================================
*/

function Trim(obj)
{
	var str=obj.value;
    return str.replace(/(^\s*)|(\s*$)/g,"");
}

/*
====================================================================
XMLEncode(string):对字符串进行XML编码
====================================================================
*/

function XMLEncode(obj)
{
	str=Trim(obj);
	str=str.replace("&","&amp;");
	str=str.replace("<","&lt;");
	str=str.replace(">","&gt;");
	str=str.replace("'","&apos;");
	str=str.replace("\"","&quot;");
	return str;
}

/*
====================================================================
SetFocus(Obj):设置控件焦点
====================================================================
*/

function SetFocus(obj)
{
	if(obj.disabled==false && obj.readOnly==false)
	{
		obj.focus();
	}
}

/*
=======================================================================
Checkmail(obj):判断邮件地址格式是否正确
=======================================================================
*/

function Checkmail(obj)
{
    var email=document.getElementsById(obj).value
    var pattern=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    flag=pattern.test(email);
    if (flag)
    {
		return true;
	}
    else
    {
    return false;
    }
}

/*
========================================================================
ValCode(ImgCode):判断输入的日期格式是否正确
========================================================================
*/

function ValCode(ImgCode)
{
	document.getElementById(ImgCode).src='/Inc/ValidateCode.aspx?id=' + Math.random();
}

/*
========================================================================
密码强度检测函数
========================================================================
*/

//正则表达式字符内容
var pattern=/^(\w|[\u4E00-\u9FA5])*$/;
var epattern=/\w+@\w+\.[a-z]+/; 

//密码强度检测开始
function PasswordStrength(showed){	
	this.showed = (typeof(showed) == "boolean")?showed:true;
	this.styles = new Array();	
	this.styles[0] = {backgroundColor:"#EBEBEB",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #BEBEBE",borderBottom:"solid 1px #BEBEBE"};	
	this.styles[1] = {backgroundColor:"#FF4545",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #BB2B2B",borderBottom:"solid 1px #BB2B2B"};
	this.styles[2] = {backgroundColor:"#FFD35E",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #E9AE10",borderBottom:"solid 1px #E9AE10"};
	this.styles[3] = {backgroundColor:"#95EB81",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #3BBC1B",borderBottom:"solid 1px #3BBC1B"};
	
	this.labels= ["弱","中","强"];

	this.divName = "pwd_div_"+Math.ceil(Math.random()*100000);
	this.minLen = 5;
	
	this.width = "150px";
	this.height = "16px";
	
	this.content = "";
	
	this.selectedIndex = 0;
	
	this.init();	
}
PasswordStrength.prototype.init = function(){
	var s = '<table cellpadding="0" id="'+this.divName+'_table" cellspacing="0" style="width:'+this.width+';height:'+this.height+';">';
	s += '<tr>';
	for(var i=0;i<3;i++){
		s += '<td id="'+this.divName+'_td_'+i+'" width="33%" align="center"><span style="font-size:1px">&nbsp;</span><span id="'+this.divName+'_label_'+i+'">'+this.labels[i]+'</span></td>';
	}	
	s += '</tr>';
	s += '</table>';
	this.content = s;
	if(this.showed){
		document.write(s);
		this.copyToStyle(this.selectedIndex);
	}	
}
PasswordStrength.prototype.copyToObject = function(o1,o2){
	for(var i in o1){
		o2[i] = o1[i];
	}
}
PasswordStrength.prototype.copyToStyle = function(id){
	this.selectedIndex = id;
	for(var i=0;i<3;i++){
		if(i == id-1){
			this.$(this.divName+"_label_"+i).style.display = "inline";
		}else{
			this.$(this.divName+"_label_"+i).style.display = "none";
		}
	}
	for(var i=0;i<id;i++){
		this.copyToObject(this.styles[id],this.$(this.divName+"_td_"+i).style);			
	}
	for(;i<3;i++){
		this.copyToObject(this.styles[0],this.$(this.divName+"_td_"+i).style);
	}
}
PasswordStrength.prototype.$ = function(s){
	return document.getElementById(s);
}
PasswordStrength.prototype.setSize = function(w,h){
	this.width = w;
	this.height = h;
}
PasswordStrength.prototype.setMinLength = function(n){
	if(isNaN(n)){
		return ;
	}
	n = Number(n);
	if(n>1){
		this.minLength = n;
	}
}
PasswordStrength.prototype.setStyles = function(){
	if(arguments.length == 0){
		return ;
	}
	for(var i=0;i<arguments.length && i < 4;i++){
		this.styles[i] = arguments[i];
	}
	this.copyToStyle(this.selectedIndex);
}
PasswordStrength.prototype.write = function(s){
	if(this.showed){
		return ;
	}
	var n = (s == 'string') ? this.$(s) : s;
	if(typeof(n) != "object"){
		return ;
	}
	n.innerHTML = this.content;
	this.copyToStyle(this.selectedIndex);
}
PasswordStrength.prototype.update = function(s){
	if(s.length < this.minLen){
		this.copyToStyle(0);
		return;
	}
	var ls = -1;
	if (s.match(/[a-z]/ig)){
		ls++;
	}
	if (s.match(/[0-9]/ig)){
		ls++;
	}
 	if (s.match(/(.[^a-z0-9])/ig)){
		ls++;
	}
	if (s.length < 6 && ls > 0){
		ls--;
	}
	 switch(ls) { 
		 case 0:
			 this.copyToStyle(1);
			 break;
		 case 1:
			 this.copyToStyle(2);
			 break;
		 case 2:
			 this.copyToStyle(3);
			 break;
		 default:
			 this.copyToStyle(0);
	 }
}

/*
========================================================================
Load_Img(ImgSrc):图片预览 ImgSrc 图片路径
========================================================================
*/

function Load_Img(ImgSrc)
{
var t_html;
if(ImgSrc!='')
	{
		t_html="<img src='"+ImgSrc+"' onLoad='javascript:if(this.width>240){this.width=240;}if(this.height>240){this.height=240;}'>"; 
	}
	else
	{
		t_html="";
	}
	ImgVIew.innerHTML=t_html;
}


/*
========================================================================
ReSizeImg(img):重设图片宽高 img 图片Id
========================================================================
*/

function ReSizeImg(img)
{
	if(img.width>130){img.width=130;}
	if(img.height>130){img.height=130;}
}

/*
========================================================================
ReSizeResultImg(img):重设详细内容图片宽高 img 图片Id
========================================================================
*/

function ReSizeResultImg(img)
{
	if(img.width>600){img.width=600;}
}

/*
========================================================================
openWin(file, width, height):弹出窗口
========================================================================
*/

function openWin(file, width, height)
{
dimension = "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=" + width + ",height=" + height;
window.open(file,'',dimension);
}

/*
========================================================================
createXMLHttpRequest():创建XML对象
========================================================================
*/
var xmlHttp = false;
//定义XML对象
function createXMLHttpRequest() {
	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();
	}
}

/*
========================================================================
callServer(ValueID):调用异步检测代码
========================================================================
*/
function callServer(ValueID)
{
    var StrValue = document.getElementById(ValueID).value;
	
	if(!userid_re.test(StrValue))
	{
		alert("用户登录ID格式错误，用户名应该由不区分大小写“a-z 0-9 ._-”字符组成！");
		document.getElementById(ValueID).value="";
		document.getElementById(ValueID).focus();
		return;
	}
	
    if ((StrValue == null) || (StrValue == "")) return;
    url="../Inc/ChkUser.aspx?StrValue="+StrValue;
    xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = updatePageCompany;
    xmlHttp.send();
    return false;
}

//更新用户公司名称检测结果
function updatePageCompany()
{
	Hidden();
  if (xmlHttp.readyState < 4)
  {
	CompMsg.innerHTML=" <font color=red>用户ID检测中...</font>";
  }
  
  if (xmlHttp.readyState == 4)
  {
    var response = xmlHttp.responseText;
	CompMsg.innerHTML=response;
	Show();
  }
  
  if (CompMsg.innerHTML!=" <font color=red>当前企业用户ID号已经存在！</font>")
  {
	Show();
  }
  else
  {
	Hidden();
  }
}

/*
========================================================================
Hidden():按钮失效
========================================================================
*/

function Hidden()
{
	document.getElementById("Btn_Show").style.display="none";
	document.getElementById("Btn_Hidden").style.display="";
}

/*
=========================================================================
Show():按钮生效
=========================================================================
*/

function Show()
{
	document.getElementById("Btn_Show").style.display="";
	document.getElementById("Btn_Hidden").style.display="none";
}
