function Map() {
    this.elements=new Array();
　　this.size=function(){
　　return this.elements.length;
　　}
　　this.put=function(_key,_value){
　　this.elements.push({key:_key,value:_value});
　　}
　　
　　this.remove=function(_key){
　　var bln=false;
　　try{
　　for (i=0;i<this.elements.length;i++){
　　if (this.elements[i].key==_key){
　　this.elements.splice(i,1);
　　return true;
　　}
　　}
　　}catch(e){
　　bln=false;
　　}
　　return bln;
　　}
　　
　　this.containsKey=function(_key){
　　var bln=false;
　　try{
　　for (i=0;i<this.elements.length;i++){
　　if (this.elements[i].key==_key){
　　bln=true;
　　}
　　}
　　}catch(e){
　　bln=false;
　　}
　　return bln;
　　}
　　
　　this.get=function(_key){
　　try{
　　for (i=0;i<this.elements.length;i++){
　　if (this.elements[i].key==_key){
　　return this.elements[i];
　　}
　　}
　　}catch(e){
　　return null;
　　}
　　}

}

String.prototype.Trim = function() 
{ 
return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

String.prototype.LTrim = function() 
{ 
return this.replace(/(^\s*)/g, ""); 
} 

String.prototype.RTrim = function() 
{ 
return this.replace(/(\s*$)/g, ""); 
} 

function Trim(str){
 return ((String)(str)).Trim(); 
}

function ValidatorUtil(){
	this.isEmpty=function(str){
		if(str==null || str=="")
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	this.isEmptyOrWhitespace=function(str){
		if(str==null || Trim(str)=="")
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	this.isInteger = function(str){
		if(this.isEmptyOrWhitespace(str))
			return false;
		 var reg = /^\-?[0-9]*$/;
		  return reg.test(str);
	}

	this.isNumber = function(str){
		if(this.isEmptyOrWhitespace(str))
			return false;
		 var reg = /^\-?[0-9]*[\.]?[0-9]*$/;
		  return reg.test(str);
	}

	this.isIntegerScope = function(str,start,end){
		if(!this.isInteger(str)||!this.isInteger(start)||!this.isInteger(end))
			return false;
		if(parseInt(str)>=parseInt(start)&&parseInt(str)<=parseInt(end))
			return true;
		else
			return false;
	}

	this.isIntegerLarger = function(str,start){
		if(!this.isInteger(str)||!this.isInteger(start))
			return false;
		if(parseInt(str)>=parseInt(start))
			return true;
		else
			return false;
	}

	this.isIntegerSmaller = function(str,end){
		if(!this.isInteger(str)||!this.isInteger(end))
			return false;
		if(parseInt(str)<=parseInt(end))
			return true;
		else
			return false;
	}

	this.isNumberScope = function(str,start,end){
		if(!this.isNumber(str)||!this.isNumber(start)||!this.isNumber(end))
			return false;
		if(parseFloat(str)>=parseFloat(start)&&parseFloat(str)<=parseFloat(end))
			return true;
		else
			return false;
	}

	this.isNumberLarger = function(str,start){
		if(!this.isNumber(str)||!this.isNumber(start))
			return false;
		if(parseFloat(str)>=parseFloat(start))
			return true;
		else
			return false;
	}

	this.isNumberSmaller = function(str,end){
		if(!this.isNumber(str)||!this.isNumber(end))
			return false;
		if(parseFloat(str)<=parseFloat(end))
			return true;
		else
			return false;
	}

	this.isEmail = function(str){
		if(this.isEmptyOrWhitespace(str))
			return false;
		 var reg = /^[\w-.]+@[\w-.]+.(com|net|org|cn|mobi|biz|cc|tv|name|info)$/;
		  return reg.test(str);
	}

	this.isLetters = function(str){
		if(this.isEmptyOrWhitespace(str))
			return false;
		 var reg = /^[a-zA-Z]*$/;
		  return reg.test(str);
	}
	
	this.isUsername = function(str){
		if(this.isEmptyOrWhitespace(str))
			return false;
		if(str.length<2||str.length>30)
			return false;
		if(str.indexOf("掌柜")>=0)
			return false;
		 var reg = /^[\_a-z0-9\u4e00-\u9fa5]*$/;
		  return reg.test(str);
	}
	
	this.isPassword = function(str){
		if(this.isEmptyOrWhitespace(str))
			return false;
		if(str.length<6||str.length>32)
			return false;
		 var reg = /^[\w`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]*$/;
		  return reg.test(str);
	}
	
	this.isPasswordWeak = function(str){
		if(this.isEmptyOrWhitespace(str))
			return true;
		var reg = /^[0-9]*$/;
		if(reg.test(str))
		{
			if(str.length<=8)
				return true;
			else 
				return false;
		}
		
		reg = /^[a-z]*$/;
		if(reg.test(str))
		{
			if(str.length<=8)
				return true;
			else 
				return false;
		}
		
		reg = /^[A-Z]*$/;
		if(reg.test(str))
		{
			if(str.length<=8)
				return true;
			else 
				return false;
		}
		
		reg = /^[^a-zA-Z0-9]*$/;
		if(reg.test(str))
		{
			if(str.length<=8)
				return true;
			else 
				return false;
		}
		return false;
	}
	
	this.isSameLetter = function(str){
		if(this.isEmptyOrWhitespace(str))
			return true;
		var ch=str.charAt(0);
		for(var i=0;i<str.length;i++)
		{
			if(ch!=str.charAt(i))
				return false;				
		}
		return true;
	}
	
	this.isSerialNumber = function(str){
		if(this.isEmptyOrWhitespace(str))
			return true;
		var reg = "0123456789";
		if(reg.indexOf(str)>=0)
			return true;
		else
			return false;	
	}
	
	this.isSerialLowCase = function(str){
		if(this.isEmptyOrWhitespace(str))
			return true;
		var reg = "abcdefghijklmnopqrstuvwxyz";
		if(reg.indexOf(str)>=0)
			return true;
		else
			return false;	
	}
	
	this.isSerialUpCase = function(str){
		if(this.isEmptyOrWhitespace(str))
			return true;
		var reg = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		if(reg.indexOf(str)>=0)
			return true;
		else
			return false;	
	}
	
	this.isCheckCode = function(str){
		if(this.isEmptyOrWhitespace(str))
			return false;
		if(str.length!=4)
			return false;
		var reg = /^[a-zA-Z0-9]{4}$/;
		return reg.test(str);
	}
	
	this.isChinaZipcode = function(str){
		if(this.isEmptyOrWhitespace(str))
			return false;
		if(str.length!=6)
			return false;
		var reg = /^[0-9]{1}(\d+){5}$/;
		return reg.test(str);
	}
	
	this.isPhone = function(str)
	{
		if(this.isEmptyOrWhitespace(str))
			return false;
		if(str.length<6)
			return false;
		var reg = /^\+?[0-9\-]*$/;
		return reg.test(str);
	}
}

function getCookie ( pName )	{
	var search;
	search = pName + "=";
	offset = document.cookie.indexOf(search);
	if ( offset != -1 ) {
		offset += search.length;
		end = document.cookie.indexOf(";", offset);
		if ( end == -1 ) end = document.cookie.length;
		return decodeURI(document.cookie.substring(offset, end));		
	} else {
		return "";
	}
}

function showCheckCode(prepath)
{
	$("#checkcode_span").html("<img src=\""+prepath+"checkcode\" id=\"checkcodeimg\" />");
}

function wirteLoginForm(prepath)
{
	if(prepath==null)
		prepath="";
	var userName = getCookie("username");
	var zgCookie = getCookie("zgcookie");
	var newmessage = getCookie("newmessage");
	var lastlogintime = getCookie("lastlogintime");
	if ( userName == 'null' || userName == '' ) 
	{
		document.write('<form name="login_form" action="'+prepath+'signon.do" method="post"><span>用户名：</span><span><input type="text" id="usernameinput" name="username"/></span><span>密码：</span><span><input type="password" id="passwordinput" name="password"/></span><span>校验码：</span><span><input type="text" id="checkcodeinput" name="checkcode" onFocus="javascript:showCheckCode(\''+prepath+'\');"/></span><span id="checkcode_span"></span><span><input type="submit" name="submit" id="login_submit" value="登   陆 "/></span><span><a href="'+prepath+'registerForm.do" target="_blank">免费注册</a></span></form>');
	}
	else
	{
		if ( zgCookie == 'null' || zgCookie == '' ) 
		{
			document.write('<form name="login_form" action="'+prepath+'signon.do" method="post"><span>用户名：</span><span><input type="text" id="usernameinput" name="username"/></span><span>密码：</span><span><input type="password" id="passwordinput" name="password"/></span><span>校验码：</span><span><input type="text" id="checkcodeinput" name="checkcode" onFocus="javascript:showCheckCode(\''+prepath+'\');"/></span><span id="checkcode_span"></span><span><input type="submit" name="submit" id="login_submit" value="登   陆 "/></span><span><a href="'+prepath+'registerForm.do" target="_blank">免费注册</a></span></form>');
		}
		else
		{
			document.write('您好 '+userName+' ！ <a href="'+prepath+'signout.do">退出</a>\n');
			if(newmessage!=null && parseInt(newmessage)>0)
			{
				document.write('<a href="listInSiteMessage.do">您有 '+newmessage+' 条新消息！</a>');
			}
		}
	}
	
	if(lastlogintime!='null' && lastlogintime!='' && zgCookie != 'null' && zgCookie != '')
	{
		document.write("（您最近一次登录时间："+lastlogintime+" ）");
	}
}

function setInputInfo(inputid) {
	$("#"+inputid+"_info").removeClass();
	$("#"+inputid+"_info").addClass("input_info");
	if(msgMap.containsKey(inputid))
	{
		var inputmsg = msgMap.get(inputid).value;
		if(inputmsg)
		{
			$("#"+inputid+"_info").html(inputmsg[0]);
		}
	}
}

function checkInputInfo(inputid,showinfo) {
	
	var str = $("#"+inputid).val();
	try{
	var rev = eval("check"+inputid+"('"+str+"')");
	$("#"+inputid).removeClass("mustinput_text");
	$("#"+inputid).removeClass("inputerror_text");
	$("#"+inputid).removeClass("inputok_text");
	if(parseInt(rev)!=0)
	{
		$("#"+inputid).addClass("inputerror_text");
	}
	else
	{
		$("#"+inputid).addClass("inputok_text");
	}
	if(showinfo)
	{
		if(msgMap.containsKey(inputid))
		{
			var inputmsg = msgMap.get(inputid).value;
			if(inputmsg)
			{
				var curmsg = inputmsg[parseInt(rev)];
				
				$("#"+inputid+"_info").removeClass();
				$("#"+inputid+"_info").html(curmsg);
				
				if(parseInt(rev)==0)
				{
					$("#"+inputid+"_info").addClass("input_info_ok");	
				}	
				else
				{
					$("#"+inputid+"_info").addClass("input_info_error");
				}
			}
		}
	}
	if(rev==0)
	{
		return true;
	}
	else
		return false;
	}catch(e)
	{
		return false;
	}
}

function setErrorInfo(inputid,infoindex)
{
	$("#"+inputid).removeClass("mustinput_text");
	$("#"+inputid).removeClass("inputerror_text");
	$("#"+inputid).removeClass("inputok_text");
	$("#"+inputid).addClass("inputerror_text");
	if(msgMap.containsKey(inputid))
	{
		var inputmsg = msgMap.get(inputid).value;
		if(inputmsg)
		{
			if(parseInt(infoindex)>=inputmsg.length)
			{
				infoindex=inputmsg.size-1;
			}
			var curmsg = inputmsg[parseInt(infoindex)];
			
			$("#"+inputid+"_info").removeClass();
			$("#"+inputid+"_info").html(curmsg);
			$("#"+inputid+"_info").addClass("input_info_error");
		}
	}
}

function checkErrorInfo()
{
	if(errorArray)
	{
		if(errorArray.length>0)
		{
			for(var i=0;i<errorArray.length;i++)
			{
				if(errorArray[i]&&errorArray[i].length==2)
				{
					setErrorInfo(errorArray[i][0],errorArray[i][1]);
				}
			}
		}
	}
}

function   getAbsLeft(e){   
     var   l=e.offsetLeft;     
     while(e=e.offsetParent)     l   +=   e.offsetLeft;     
     return   l;   
 }   
 function   getAbsTop(e)   {   
     var   t=e.offsetTop;       
     while(e=e.offsetParent)     t   +=   e.offsetTop;       
     return   t;   
 }
 
 
function checkAll(srcElement,str)
{
  var a = document.getElementsByName(str);
  var n = a.length;
  for (var i=0; i<n; i++)
  a[i].checked = srcElement.checked;
}

function checkOthers(str)
{
  var a = document.getElementsByName(str);
  var n = a.length;
  for (var i=0; i<n; i++)
  {
  	if(a[i].checked)
  		a[i].checked = false;
  	else
  		a[i].checked = true;
  }
}

function openWin(htmUrl,winName,awidth,aheight)
{
var url=htmUrl; 
if(winName==null)
 winName="newWin"; //给打开的窗口命名
if(awidth==null)
 awidth=700; //窗口宽度,需要设置
if(aheight==null)
	aheight=700; //窗口高度,需要设置 
var atop=(screen.availHeight - aheight)/2; //窗口顶部位置,一般不需要改
var aleft=(screen.availWidth - awidth)/2; //窗口放中央,一般不需要改

var param0="scrollbars=1,status=1,menubar=0,resizable=2,location=0"; 
var params="top=" + atop + ",left=" + aleft + ",width=" + awidth + ",height=" + aheight + "," + param0 ; 
win=window.open(url,winName,params); //打开新窗口
win.focus(); 
}