﻿/*
525心理网 V2.0
chaochao (C) 2007-2008 PSY525.CN INC
http://psy525.cn
*/
var PasswordStrength ={
    Level : ["极佳","一般","较弱","太短"],
    LevelValue : [15,10,5,0],//强度值
    Factor : [1,2,5],//字符加数,分别为字母，数字，其它
    KindFactor : [0,0,10,20],//密码含几种组成的加数 
    Regex : [/[a-zA-Z]/g,/\d/g,/[^a-zA-Z0-9]/g] //字符正则数字正则其它正则
    }
PasswordStrength.StrengthValue = function(pwd)
{
    var strengthValue = 0;
    var ComposedKind = 0;
    for(var i = 0 ; i < this.Regex.length;i++)
    {
        var chars = pwd.match(this.Regex[i]);
        if(chars != null)
        {
            strengthValue += chars.length * this.Factor[i];
            ComposedKind ++;
        }
    }
    strengthValue += this.KindFactor[ComposedKind];
    return strengthValue;
} 
PasswordStrength.StrengthLevel = function(pwd)
{
    var value = this.StrengthValue(pwd);
    for(var i = 0 ; i < this.LevelValue.length ; i ++)
    {
        if(value >= this.LevelValue[i] )
            return this.Level[i];
    }
}
function loadinputcontext(o)
{
   var showmsg=PasswordStrength.StrengthLevel(o.value);
   switch(showmsg)
   {
	  case "太短": showmsg+=" <img src='/res/images/pwdlevel/1.gif' width='88' height='11' />";break;
	  case "较弱": showmsg+=" <img src='/res/images/pwdlevel/2.gif' width='88' height='11' />";break;
	  case "一般": showmsg+=" <img src='/res/images/pwdlevel/3.gif' width='88' height='11' />";break;
	  case "极佳": showmsg+=" <img src='/res/images/pwdlevel/4.gif' width='88' height='11' />";break;
   }
   document.getElementById('showmsg').innerHTML = showmsg;
}
		
function htmlEncode(source, display, tabs)
{
	function special(source)
	{
		var result = '';
		for (var i = 0; i < source.length; i++)
		{
			var c = source.charAt(i);
			if (c < ' ' || c > '~')
			{
				c = '&#' + c.charCodeAt() + ';';
			}
			result += c;
		}
		return result;
	}
	function format(source)
	{
		// Use only integer part of tabs, and default to 4
		tabs = (tabs >= 0) ? Math.floor(tabs) : 4;
		// split along line breaks
		var lines = source.split(/\r\n|\r|\n/);
		// expand tabs
		for (var i = 0; i < lines.length; i++)
		{
			var line = lines[i];
			var newLine = '';
			for (var p = 0; p < line.length; p++)
			{
				var c = line.charAt(p);
				if (c === '\t')
				{
					var spaces = tabs - (newLine.length % tabs);
					for (var s = 0; s < spaces; s++)
					{
						newLine += ' ';
					}
				}
				else
				{
					newLine += c;
				}
			}
			// If a line starts or ends with a space, it evaporates in html
			// unless it's an nbsp.
			newLine = newLine.replace(/(^ )|( $)/g, '&nbsp;');
			lines[i] = newLine;
		}
		// re-join lines
		var result = lines.join('<br />');
		// break up contiguous blocks of spaces with non-breaking spaces
		result = result.replace(/  /g, ' &nbsp;');
		// tada!
		return result;
	}
	var result = source;
	// ampersands (&)
	result = result.replace(/\&/g,'&amp;');
	// less-thans (<)
	result = result.replace(/\</g,'&lt;');
	// greater-thans (>)
	result = result.replace(/\>/g,'&gt;');
	if (display)
	{
		// format for display
		result = format(result);
	}
	else
	{
		// Replace quotes if it isn't for display,
		// since it's probably going in an html attribute.
		result = result.replace(new RegExp('"','g'), '&quot;');
	}
	// special characters
	result = special(result);
	// tada!
	return result;
}
		
var profile_username = '用户名字符长度必须在4和20个字符之间';
var profile_username2 = '用户名不能包含空格';
var profile_username_pass = "恭喜，该用户名可以使用";
var img_true="<img src='/res/images/true.gif' alt='' style='vertical-align:middle;'/>";
var img_false="<img src='/res/images/false.gif' alt='' style='vertical-align:middle;'/>";
function checkusername(username)
{
    var unlen = username.replace(/[^\x00-\xff]/g, "**").length;
    if(unlen < 4 || unlen > 20) {
	    document.getElementById("checkname").innerHTML = "<font color='red'>"+ img_false + profile_username + "</font>";
	    return false;
	}else if(username.indexOf(" ")!=-1){
	    document.getElementById("checkname").innerHTML = "<font color='red'>"+ img_false + profile_username2 + "</font>";
	    return false;
	}
	ajaxRead("/tools/ajax.aspx?t=checkusername&username=" + escape(username), "showcheckresult(obj,'" + username + "');",true,false);
}
function showcheckresult(obj, username)
{
	var res = obj.getElementsByTagName('result');
	var resContainer = document.getElementById("checkname");
	var result = "";
	if (res[0] != null && res[0] != undefined)
	{
		if (res[0].childNodes.length > 1) {
			result = res[0].childNodes[1].nodeValue;
		} else {
			result = res[0].firstChild.nodeValue;    		
		}
	}
	if (result == "1")
	{
		resContainer.innerHTML = "<font color='red'>"+ img_false+"很遗憾，该用户名 \"" + htmlEncode(username, true, 4) + "\" 已经被注册或禁用，请您另选一个</font>";
	}
	else
	{
		resContainer.innerHTML = img_true+profile_username_pass;
	}
}

var profile_password = '密码长度必须为6～20位，字母区分大小写';
var profile_password_pass = "登录密码设置正确";
function checkpassword(pwd)
{
    var unlen = pwd.replace(/[^\x00-\xff]/g, "**").length;
    if(unlen < 6 || unlen > 20) {
	    document.getElementById("checkpwd").innerHTML = "<font color='red'>"+ img_false + profile_password + "</font>";
	    return false;
	}else{
	    document.getElementById("checkpwd").innerHTML = img_true + profile_password_pass;
	    return false;
	}
}
var profile_password_repeat = '您两次输入的登录密码不一致';
var profile_password_repeat_pass = "重复登录密码设置正确";
function checkpassword_repeat(pwdrepeat)
{
    var pwd=document.getElementById("password").value;
    if(pwdrepeat!=pwd)
    {
        document.getElementById("checkpwd_repeatinfo").innerHTML = "<font color='red'>"+ img_false + profile_password_repeat + "</font>";
	    return false;
    }else{
	    document.getElementById("checkpwd_repeatinfo").innerHTML = img_true + profile_password_repeat_pass;
	    return false;
	}
}

var profile_birth_y = '请输入正确年份';
var profile_birth_y_pass = "";
function checkbirth(birth_y)
{
    if(getStringBytes(birth_y)!=4 || (!isInteger(birth_y)))
    {
        document.getElementById("checkbirthinfo").innerHTML = "<font color='red'>"+ img_false + profile_birth_y + "</font>";
	    return false;
    }else{
	    document.getElementById("checkbirthinfo").innerHTML = img_true + profile_birth_y_pass;
	    return false;
	}
}

var profile_email = '不是有效的邮箱地址';
var profile_email_pass = "";
function checkemail(email)
{
  var pattern = /^([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)*@([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)+$/;
  flag = pattern.test(email);
  if (trim(email).length == "" || (!flag) ) {
    document.getElementById("checkemailinfo").innerHTML = "<font color='red'>"+ img_false + profile_email + "</font>";
	return false;
  }else{
	    document.getElementById("checkemailinfo").innerHTML = img_true + profile_birth_y_pass;
	    return false;
	}
}

var profile_StudyLevel = '请选择您的文化程度';
var profile_StudyLevel_pass = "";
function checkStudyLevel(StudyLevel)
{
    if(getStringBytes(StudyLevel)<=0)
    {
        document.getElementById("checkstudyinfo").innerHTML = "<font color='red'>"+ img_false + profile_StudyLevel + "</font>";
        return false;
    }else{
        document.getElementById("checkstudyinfo").innerHTML = img_true + profile_StudyLevel_pass;
        return false;
    }
}

var profile_verifycode = '请输入校验码';
var profile_verifycode_pass = "";
function checkverifycode(verifycode)
{
    if(getStringBytes(verifycode)<=0)
    {
        document.getElementById("verifycodeinfo").innerHTML = "<font color='red'>"+ img_false + profile_verifycode + "</font>";
        return false;
    }else{
        document.getElementById("verifycodeinfo").innerHTML = img_true + profile_verifycode_pass;
        return false;
    }
}

var profile_realname='真实姓名不能为空';
var profile_realname_pass = "";
function checkrealname(realname)
{
    if(getStringBytes(realname)<=0)
    {
        document.getElementById("realnamehintinfo").innerHTML = "<font color='red'>"+ img_false + profile_realname + "</font>";
        return false;
    }else{
        document.getElementById("realnamehintinfo").innerHTML = img_true + profile_realname_pass;
        return false;
    }
}
var profile_card='请输入有效的身份证号码';
var profile_card_pass = "";
function checkcard(card)
{
    var unlen = card.replace(/[^\x00-\xff]/g, "**").length;
    if(unlen < 15 || unlen > 18 || unlen==17) {
	    document.getElementById("dr_card_info").innerHTML = "<font color='red'>"+ img_false + profile_card + "</font>";
	    return false;
	}else{
	    document.getElementById("dr_card_info").innerHTML = img_true + profile_card_pass;
	    return false;
	}
}
var profile_psylevel = '请选择您的咨询级别';
var profile_psylevel_pass = "";
function checkpsylevel(psylevel)
{
    if(getStringBytes(psylevel)<=0)
    {
        document.getElementById("psylevel_info").innerHTML = "<font color='red'>"+ img_false + profile_psylevel + "</font>";
        return false;
    }else{
        document.getElementById("psylevel_info").innerHTML = img_true + profile_psylevel_pass;
        return false;
    }
}
var profile_certificate_code='证书或毕业证号码将做为审核咨询师的重要参考,不能为空';
var profile_certificate_code_pass = "";
function checkcertificate_code(certificate_code)
{
    if(getStringBytes(certificate_code)<=0)
    {
        document.getElementById("certificate_code_info").innerHTML = "<font color='red'>"+ img_false + profile_certificate_code + "</font>";
        return false;
    }else{
        document.getElementById("certificate_code_info").innerHTML = img_true + profile_certificate_code_pass;
        return false;
    }
}
var profile_organname='机构名称不能为空';
var profile_organname_pass = "";
function checkorganname(organname)
{
    if(getStringBytes(organname)<=0)
    {
        document.getElementById("organname_info").innerHTML = "<font color='red'>"+ img_false + profile_organname + "</font>";
        return false;
    }else{
        document.getElementById("organname_info").innerHTML = img_true + profile_organname_pass;
        return false;
    }
}
function getStringBytes(val) {
  if ( val == "" )
    return 0;

  var idx = 0 ;
  var totalByte = 0 ;
  for ( ; idx < val.length ; idx ++ )
  {
    if ( val.charCodeAt(idx) < 128 ) {
      totalByte++;
    }else{
      totalByte += 2;
    }
  }
  return totalByte;
}
function isInteger(val) {
  val = trim(val);
  // 检查是否为0 --特殊检查
  if ( val == "0" ) {
    return true;
  }

  var idx = 0 ;
  for ( ; idx < val.length ; idx ++ )
  {
  	if ( val.charCodeAt(idx) < 48 || val.charCodeAt(idx) > 57 )
  	{
  		 return false;
  	}
  }
  return true;
}
function trim(strValue)
{
	if (strValue==null)
	    return "";
	return strValue.replace(/(^\s*)|(\s*$)/g, "");
}

document.writeln("<scr"+"ipt type=\"text/javascript\" src=\"/res/js/textare.js\"></scr"+"ipt>");
document.writeln("<scr"+"ipt type=\"text/javascript\" src=\"/res/js/city.js\"></scr"+"ipt>");