// JScript source code
  function ajaxRead(file,fun){
  // alert(file);
   var xmlObj = null;
   if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
   } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      return;
   }

   xmlObj.onreadystatechange = function(){
    if(xmlObj.readyState == 4){
		if (xmlObj.status ==200){
			obj = xmlObj.responseXML;
			eval(fun);
		}
		else{
			alert("read file error,the errorid is: [" + xmlObj.status  + "]");
		}
    }
   }
   xmlObj.open ('GET', file, true);
   xmlObj.send (null);
  }
  
  // 
function expandoptions(id)
{
	if(document.getElementById(id).style.display=='block')
	{
		document.getElementById(id).style.display='none';
	}
	else
	{
		document.getElementById(id).style.display='block';
	}
}


// 密码处理
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(pwdu)
{
	var strengthValue = 0;
	var ComposedKind = 0;
	for(var i = 0 ; i < this.Regex.length;i++)
	{
		var chars = pwdu.match(this.Regex[i]);
		if(chars != null)
		{
			strengthValue += chars.length * this.Factor[i];
			ComposedKind ++;
		}
	}
	strengthValue += this.KindFactor[ComposedKind];
	return strengthValue;
} 
PasswordStrength.StrengthLevel = function(pwdu)
{
	var value = this.StrengthValue(pwdu);
	for(var i = 0 ; i < this.LevelValue.length ; i ++)
	{
		if(value >= this.LevelValue[i] )
			return this.Level[i];
	}
}
function loadinputcontext(o,mid)
{
	var showmsg=PasswordStrength.StrengthLevel(o.value);
	switch(showmsg)
	{
		case "太短": showmsg+=" <img src='" + path + "1.gif' width='88' height='11' />";break;
		case "较弱": showmsg+=" <img src='" + path + "2.gif' width='88' height='11' />";break;
		case "一般": showmsg+=" <img src='" + path + "3.gif' width='88' height='11' />";break;
		case "极佳": showmsg+=" <img src='" + path + "4.gif' width='88' height='11' />";break;
	}
	document.getElementById(mid).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)
	{
		// formatu 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;');
	}
	// specialu characters
	result = special(result);
	// tada!
	return result;
}

// 用户名处理
var profile_username_toolong = '对不起，您的用户名超过 20 个字符。';
var profile_username_tooshort = '对不起，您输入的用户名小于3个字符。';
var profile_username_pass = "可用";
function checkusername(username,mid) {

  //  alert(mid);

    var resultid = mid;
   // alert(resultid);

	var unlen = username.replace(/[^\x00-\xff]/g, "**").length;
	if(unlen < 3 || unlen > 20) 
	{
		document.getElementById(resultid).innerHTML = "<font color='red'>" + (unlen < 3 ? profile_username_tooshort : profile_username_toolong) + "</font>";
		return;
    }
	ajaxRead(vpath +"ajax.aspx?t=checkusername&username=" + escape(username), "showcheckresult(obj,'" + username + "','" + resultid+ "');");
}
function checktruename(username,mid)
{
	var resultid = mid;
	ajaxRead(vpath +"ajax.aspx?t=checktruename&username=" + escape(username), "showcheckresult(obj,'" + username + "','" + resultid+ "');");
}
function checkidcard(username,mid)
{
	var resultid = mid;
	ajaxRead(vpath +"ajax.aspx?t=checkidcard&username=" + escape(username), "showcheckresult(obj,'" + username + "','" + resultid+ "');");
}
function checkallycard(username,mid)
{
	var resultid = mid;
	ajaxRead(vpath +"ajax.aspx?t=checkallycard&username=" + escape(username), "showcheckresult(obj,'" + username + "','" + resultid+ "');");
}
					
function checknickname(username,mid)
{
	var resultid = mid;
	//alert(resultid);
	ajaxRead(vpath+"ajax.aspx?t=checknickname&username=" + escape(username), "showcheckresult(obj,'" + username + "','" + resultid+ "');");
}
function checkemail(username,mid)
{
	var resultid = mid;
	//alert(resultid);
	ajaxRead(vpath + "ajax.aspx?t=checkemail&username=" + escape(username), "showcheckresult(obj,'" + username + "','" + resultid+ "');");
}
function showcheckresult(obj, username,resultid)
{
	//alert(resultid);
	var res = obj.getElementsByTagName('result');
	var resContainer = document.getElementById(resultid);
	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'>对不起，您的输入 \"" + htmlEncode(username, true, 4) + "\" 已经被他人使用或被禁用，请重新输入。</font>";
	}
	else
	{
		resContainer.innerHTML = profile_username_pass;
	}
}

var profile_username_nopass = "用户名存在";
function checkusername1(username, mid) {
    var resultid = mid;
    ajaxRead(vpath + "ajax.aspx?t=checkusername&username=" + escape(username), "showcheckresult1(obj,'" + username + "','" + resultid + "');");
}


function showcheckresult1(obj, username,resultid)
{
	//alert(resultid);
	var res = obj.getElementsByTagName('result');
	var resContainer = document.getElementById(resultid);
	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 = profile_username_nopass;
	}
	else
	{
		resContainer.innerHTML = "<font color='red'>对不起，用户名 \"" + htmlEncode(username, true, 4) + "\" 不存在，请重新输入。</font>";
	}
}

var profile_allycard_pass = "卡号存在";
function checkallycard1(username,mid)
{
	var resultid = mid;
	ajaxRead(vpath+"ajax.aspx?t=checkallycard&username=" + escape(username), "showcheckresult2(obj,'" + username  + "','" + resultid+ "');");
}
function showcheckresult2(obj, username,resultid)
{
	var res = obj.getElementsByTagName('result');
	var resContainer = document.getElementById(resultid);
	var resulta = "";
	if (res[0] != null && res[0] != undefined)
	{
		if (res[0].childNodes.length > 1) {
			resulta = res[0].childNodes[1].nodeValue;
		} else {
			resulta = res[0].firstChild.nodeValue;    		
		}
	}
	if (resulta == "1")
	{
		resContainer.innerHTML = profile_allycard_pass;
	}
	else
	{
		resContainer.innerHTML = "<font color='red'>对不起，卡号 \"" + htmlEncode(username, true, 4) + "\" 不存在，请重新输入。";
	}
}
