﻿
/**
**获取浏览器类型
**/
function GetBrowserType()
{	
    var retValue="";
	var sAgent = navigator.userAgent.toLowerCase();
	
	if(sAgent.indexOf("msie")!=-1)
	    return "ie";
	if(sAgent.indexOf("firefox")!=-1)
	   return "firefox";

    if(sAgent.indexOf("opera")!=-1)
	    return "opera";
	if(sAgent.indexOf("netscape")!=-1)
	    return "netscape";
}

/****************************************************************************空间显示,隐藏,选中,索引*****************************/
// 将空间组中的一个控件显示,其他的隐藏
/* divarray 空间的名称数组["ddfd","adfadsfdsaf","adfadsf"]
*  showdiv  要显示的控件的名称
*/
function ShowSingleElement(divarray,showdiv)
{
    var arraylist=divarray.toArray();
    var divobj=null;
     arraylist.each
     (
         function(divid)
         {
             if($(divid)!=null)
             {
                 divobj=$(divid);
                 if(divid==showdiv)
                 { 
                        divobj.show();
                 }   
                 else
                 {
                        divobj.hide();
                 }
            }
         }
     );
}

// 将空间组中的一个控件样式改变成新样式,其他改变为原样式
/* divarray divarray 空间的名称数组["ddfd","adfadsfdsaf","adfadsf"]
*  showdiv  要显示的控件的名称
*  originclass 控件原有的样式(class name)
*  newclass 控件的新样式(class name)
*/
function ModifySingleElementClass(divarray,showdiv,originclass,newclass)
{
    var arraylist=divarray.toArray();
    var divobj=null;
     arraylist.each
     (
         function(divid)
         {
        
             divobj=$(divid); 
             if(divid==showdiv)
             { 
                   divobj.removeClassName(originclass);
                   divobj.addClassName(newclass);
             }   
             else
             {
                   divobj.removeClassName(newclass);
                   divobj.addClassName(originclass);
             }
         }
     );
}
/**
**单选指定容器控件对象内的复选框
** div_container容器控件对象
** currentCheckbox当前复选框对象
**/
function SingleCheckedByElement(div_container,currentCheckbox)
{
    if(currentCheckbox.checked)
    {
        var chekArray=$A(div_container.getElementsByTagName('input'));
        chekArray.each
        (
            function(checkElement)
            {
                if(checkElement.type=="checkbox" )
                {
                    if(checkElement.id==currentCheckbox.id)
                        checkElement.checked=true;
                    else
                        checkElement.checked=false;
                }
            }
        );
    }
} 

/**
** 全选指定容器控件内的复选框
** div_container 容器控件对象
** isChecked选中,还是取消
**/
function MultiCheckedByElement(div_container,isChecked)
{
    var chekArray=$A(div_container.getElementsByTagName('input'));
    chekArray.each
    (
        function(checkElement)
        {
            if(checkElement.type=="checkbox" )
            {
                checkElement.checked=isChecked;
             }   
        }
    );
} 

/**
** 全选指定容器控件内的复选框
** div_container 容器控件对象
** suffix 复选框的id前缀
** isChecked选中,还是取消
**/
function MultiCheckedByElementBySuffix(div_container,suffix,isChecked)
{
    var chekArray=$A(div_container.getElementsByTagName('input'));
    var suffixlength=suffix.length;
    chekArray.each
    (
        function(checkElement)
        {
            if(checkElement.type=="checkbox" )
            {
                var tempsffix=checkElement.id.substr(0,suffixlength);
                if(suffix!=tempsffix)
                    return ;
                checkElement.checked=isChecked;
             }   
        }
    );
} 

/****
 ** 获取指定控件容器对象中的所有选中的复选框的value,组成字符串
 ** div_container 容器控件对象
 ** valueType 0:ID,1:Value,2:Name
 ** isChecked选中,还是取消,-1不限制,0未选中,1选中
 ** Separator: 分割符号
 **/
function GetCheckStrByCheckedFromElement(div_container,valueType,isChecked,Separator)
{
    if(isChecked==true)
        isChecked="1";
    else if(isChecked==false)
        isChecked="0";
        
    if(Separator==null || Separator=="undefined")
        Separator=",";
    var chekArray=$A(div_container.getElementsByTagName('input'));
    var codeString="";
    chekArray.each
    (
        function(checkElement)
        {
            if(checkElement.type=="checkbox" )
            {
                if(isChecked=="1")
                {
                    if(checkElement.checked)
                    {
                        if(valueType==0)
                            codeString+=checkElement.id+Separator;
                        else if(valueType==1)
                            codeString+=checkElement.value+Separator;
                        else if(valueType==2)
                            codeString+=checkElement.name+Separator;
                    }
                }
                else if(isChecked=="0")
                {
                    if(!checkElement.checked)
                    {
                        if(valueType==0)
                            codeString+=checkElement.id+Separator;
                        else if(valueType==1)
                            codeString+=checkElement.value+Separator;
                        else if(valueType==2)
                            codeString+=checkElement.name+Separator;
                    }
                }
                else if(isChecked=="-1")
                {
                    if(valueType==0)
                        codeString+=checkElement.id+Separator;
                    else if(valueType==1)
                        codeString+=checkElement.value+Separator;
                    else if(valueType==2)
                        codeString+=checkElement.name+Separator;
                }
            }
        }
    );
    if(codeString.length>0)
    {
	    codeString=codeString.substr(0,codeString.length-1);
    }
    return codeString;
}

/****
 ** 获取指定控件容器对象中的所有选中的复选框的value,组成字符串
 ** div_container 容器控件对象
 ** suffix 复选框的id前缀
 ** valueType 0:ID,1:Value,2:Name
 ** isChecked选中,还是取消
 ** Separator: 分割符号
 **/
function GetCheckStrByCheckedFromElementBySuffix(div_container,suffix,valueType,isChecked,Separator)
{
    if(isChecked==true)
        isChecked="1";
    else if(isChecked==false)
        isChecked="0";
        
     if(Separator==null || Separator=="undefined")
        Separator=",";
    var chekArray=$A(div_container.getElementsByTagName('input'));
    var codeString="";
    var suffixlength=suffix.length;
    chekArray.each
    (
        function(checkElement)
        {
            if(checkElement.type=="checkbox" )
            {
                var tempsffix=checkElement.id.substr(0,suffixlength);
                if(suffix!=tempsffix)
                    return ;
                if(isChecked=="1")
                {
                    if(checkElement.checked)
                    {
                        if(valueType==0)
                            codeString+=checkElement.id+Separator;
                        else if(valueType==1)
                            codeString+=checkElement.value+Separator;
                        else if(valueType==2)
                            codeString+=checkElement.name+Separator;
                    }
                }
                else if(isChecked=="0")
                {
                    if(!checkElement.checked)
                    {
                        if(valueType==0)
                            codeString+=checkElement.id+Separator;
                        else if(valueType==1)
                            codeString+=checkElement.value+Separator;
                        else if(valueType==2)
                            codeString+=checkElement.name+Separator;
                    }
                }
                else if(isChecked=="-1")
                {
                    if(valueType==0)
                        codeString+=checkElement.id+Separator;
                    else if(valueType==1)
                        codeString+=checkElement.value+Separator;
                    else if(valueType==2)
                        codeString+=checkElement.name+Separator;
                }
            }
        }
    );
    if(codeString.length>0)
    {
	    codeString=codeString.substr(0,codeString.length-1);
    }
    return codeString;
}
/**
**反选指定控件容器内对象中的复选框
** div_container控件容器对象
**/
function RefactorCheckboxByElement(div_container)
{
    var chekArray=$A(div_container.getElementsByTagName('input'));
    chekArray.each
    (
        function(checkElement)
        {
            if(checkElement.type=="checkbox" )
            {
                checkElement.checked=!checkElement.checked;
            }   
        }
    );
}

/**
**反选指定控件容器内对象中的复选框
** div_container控件容器对象
** 复选框id的前缀
**/
function RefactorCheckboxByElement(div_container,suffix)
{
    var chekArray=$A(div_container.getElementsByTagName('input'));
    var suffixlength=suffix.length;
    chekArray.each
    (
        function(checkElement)
        {
            if(checkElement.type=="checkbox" )
            {
                var tempsffix=checkElement.id.substr(0,suffixlength);
                if(suffix!=tempsffix)
                    return ;
                    
                checkElement.checked=!checkElement.checked;
            }   
        }
    );
}

/**
** 反选自己
**/
function refactorSelfCheckbox(obj)
{
    if(obj.type=="checkbox" )
    {
    	if(!obj.checked)
        	obj.checked="checked";
        else
        	obj.checked="";
    }
}
/**
** 反选一组
**/
function refactorCheckbox(myform)
{
	var idstr="";
    for(i=0;i<myform.elements.length;i++)
    {
        var obj=myform.elements[i];
        if(obj.type=="checkbox" )
        {
        	if(!obj.checked)
            	obj.checked="checked";
            else
            	obj.checked="";
        }
    }
}

/**根据类型值(id字符串，name字符串,value字符串),绑定div中的复选框
** div_container 容器控件对象
** data 值字符串
** valueType 0:ID,1:Value,2:Name 
** isChecked选中,还是取消true/false
**/
function SetCheckedByElement(div_container,data,valueType,isChecked)
{
    var array=data.split(",");
    var chekArray=$A(div_container.getElementsByTagName('input'));
    chekArray.each
    (
        function(checkElement)
        {
           if(checkElement.type=="checkbox" )
            {
    	        for(var j=0;j<array.length;j++)
    	        {
    	            if(valueType==0)
    	            {
    	                if(array[j]==checkElement.id)
    	                {
    	                   checkElement.checked=isChecked;
    	                   break;
    	                }
    	            }
    	            else if(valueType==1)
    	            {
    	                if(array[j]==checkElement.value)
    	                {
    	                   checkElement.checked=isChecked;
    	                   break;
    	                }
    	            }
    	            else if(valueType==2)
    	            {
    	                if(array[j]==checkElement.name)
    	                {
    	                   checkElement.checked=isChecked;
    	                   break;
    	                }
    	            }
    	        }
    	    }
        }
    );
}
/**判断容器种的复选框是否时全部选中,或者不全部选中
** div_container容器
**isChecked选中,还是取消true/false
**/
function IsAllCheckBoxSelected(div_container,isChecked)
{
    var retValue=true;
    var chekArray=$A(div_container.getElementsByTagName('input'));
    chekArray.each
    (
        function(checkElement)
        {
           if(checkElement.type=="checkbox" )
            {
                if(checkElement.checked!=isChecked)
                {
                    retValue=false;
                }
    	    }  
        }
    );
    return retValue;
}

/**
* 单选
**/
function SingleCheckBox(myform,value)
{
    var idstr="";
    for(i=0;i<myform.elements.length;i++)
    {
        var obj=myform.elements[i];
        if(obj.type=="checkbox" )
        {
           obj.checked="";
        }
    }
    value.checked="checked";
}

/**根据value值，选中列表某项
* list 列表框或者下来列表框对象
* valueType 1用value绑定,2用text绑定
*/
function CheckedListByValueOrText(list,selectvalueortext,valueType)
{
   
    if(selectvalueortext=="")
        return;
    var array=selectvalueortext.split(",");
    for(var i=0;i<list.length;i++)
    {
        for(var j=0;j<array.length;j++)
    	{
            if(valueType=="1")
            {
	            if(list[i].value==array[j])
	            {
		            list[i].selected="selected";
		            break;
	            }
	        }
	        else if(valueType=="2")
	        {
	            if(list[i].text==array[j])
	            {
		            list[i].selected="selected";
		            break;
	            }
	        }
	    }
    }
}
/**
**获取指定列表框中的选中的值字符串
** list 列表框或者下拉列表框
** valueType 1用value绑定,2用text绑定
** isChecked是否选中
**/
function GetListStrByElement(list,valueType,isChecked)
{
    var returnvalue="";
	for(i=0;i<list.length;i++)
	{
	    var obj=list[i];
	    if(obj.selected==isChecked)
	    {
	        if(valueType==1)
		        returnvalue+=obj.value+",";	
		    else if(valueType==2)
		        returnvalue+=obj.text+",";	
		}
	}
	if(returnvalue.length>0)
    {
         returnvalue=returnvalue.substr(0,returnvalue.length-1);
    }
    return returnvalue;
}

/**
**添加选项到指定列表框
** list下来框或者列表框
** value选项值
** text选项文本
**/
function AddItemsToList(list,value,text)
{
    var op=document.createElement("Option");
	op.text=text;
	op.value=value;
	list.add(op);
}
/**
**从指定的列表框中删除指定值或者文本的项目
** list下来框或者列表框
** value 选项值或者文本
** valueType 1用value绑定,2用text绑定
**/
function DeleteItemsFromList(list,value,valueType)
{
   for(var i=0;i<list.length;i++)
   {
        if(valueType==1)
        {
            if(list[i].value==value)
            {
                list.remove(i);
                break;
            }
        }
        else
        {
            if(list[i].text==value)
            {
               list.remove(i);
                break;
            }
        }
   }
}
var timeChange;
/**
*mouse over移动时显示控制层,包括位置
*srcElement 发起over事件的元素
*tagElementId 需要控制的元素对对象Id
*timeout 延时时长(秒)
*/
function ShowTipMessageBymouseover(srcElement,tagElementId,timeout,offsetX,offsetY)
{
    var pointerXY=clientXY(srcElement);
    if(offsetX=="undefined" || offsetX==null)
        offsetX=0;
    if(offsetY=="undefined" || offsetY==null)
        offsetY=0;
    var funstr="showTipMessage('"+tagElementId+"','"+(pointerXY.x-offsetX)+"px','"+(pointerXY.y-offsetY)+"px')";
    timeChange=setTimeout(funstr,timeout);     
}
/**
**mouse out移动时显示控制层
* 需要控制的元素对对象名称
**/
function HideTipMessageBymouseout(tagElementId)
{
    clearTimeout(timeChange);   
    $(tagElementId).hide();
}
/*
*显示指定的元素到指定的位置
*tagElementId 需要控制的元素对对象Id
* x 坐标x
* y 坐标y
*/
function ShowTipMessage(tagElementId,x,y)
{
    $(tagElementId).setStyle({left:x,top:y});
    $(tagElementId).showBlock();
}


/****************************************************************************空间显示,隐藏,选中,索引*****************************/



/******************************************************************坐标********************************************************/
/**
**指定对象的x,y坐标
**/
function GetElementPosition(element) 
{
    var result = new Object();
    result.x = 0;
    result.y = 0;
    result.width = 0;
    result.height = 0;
    if (element.offsetParent) {
        result.x = element.offsetLeft;
        result.y = element.offsetTop;
        var parent = element.offsetParent;
        while (parent) {
            result.x += parent.offsetLeft;
            result.y += parent.offsetTop;
            var parentTagName = parent.tagName.toLowerCase();
            if (parentTagName != "table" &&
                parentTagName != "body" && 
                parentTagName != "html" && 
                parentTagName != "div" && 
                parent.clientTop && 
                parent.clientLeft) {
                result.x += parent.clientLeft;
                result.y += parent.clientTop;
            }
            parent = parent.offsetParent;
        }
    }
    else if (element.left && element.top) {
        result.x = element.left;
        result.y = element.top;
    }
    else {
        if (element.x) {
            result.x = element.x;
        }
        if (element.y) {
            result.y = element.y;
        }
    }
    if (element.offsetWidth && element.offsetHeight) {
        result.width = element.offsetWidth;
        result.height = element.offsetHeight;
    }
    else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
        result.width = element.style.pixelWidth;
        result.height = element.style.pixelHeight;
    }
    return result;
}
/******************************************************************坐标********************************************************/


/****************************************************************************异步提交*********************************************/
//访问异步页面
function AsynPostData(url,data,dealFunction)
{
     new Ajax.Request(url ,
     { method: 'post',
        postBody:'data='+data, 
        onSuccess:dealFunction
    });
}
/****************************************************************************异步提交********************************************/

/************************************************************弹出窗口************************************************************/
function ShowDialog(sUrl,iWidth,iHeight)
{
	if(!iWidth)	iWidth=400;
	if(!iHeight) iHeight=300;
	var feature = 'dialogWidth:'+iWidth+'px;dialogHeight:'+iHeight+'px;scroll:auto;status:no;resizeable:no;';
	var reObj = window.showModalDialog(sUrl,'',feature)
	return reObj;
}

/** 弹出指定的窗口
*** sUrl 弹出窗口的地址 iWidth弹出窗口的宽 iHeight弹出窗口的高
**/
function ShowForm(sUrl,iwidth,iheight)
{
    
    var top = (window.screen.height-iheight)/2;
	var left = (window.screen.width-iwidth)/2;
	top=top-20;
	var feature = 'top='+top+',left='+left+',scroll=auto,width='+iwidth+'resizable=yes,scrollbars=yes,height='+iheight;
	window.open(sUrl,'',feature);
}
/************************************************************弹出窗口************************************************************/


/*********************************************************************************String******************************************/
//获取地址栏查询参数或指定字符串中指定name对应的值
function GetUrlParam( paramName) 
{ 
    var str=document.location.search;
    var oregex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ; 
    var oMatch = oregex.exec( str) ; 
    if ( oMatch && oMatch.length > 1 ) 
        return oMatch[1] ; 
    else 
        return '' ; 
}
//将控件中的值转换成"变量(控件'_'后的字符串)+值的形式"
function GetQueryParms()
{
    var queryParms=$$('select', 'input[type=text]').collect(
         function(element)
         {
            return element.id+'='+escape(element.value);}
         ).join('&') ;
    return queryParms;
} 

function SetQueryParmsToForm(Container)
{
     var elementArray=$A(Container.getElementsByTagName('input'));
     elementArray.each
     (
         function(element)
         {
            var paraValue=GetUrlParam(element.id);
            if(paraValue!=null && paraValue!="")
            {
                 element.value=unescape(paraValue);
            }
         }
     );
     elementArray=$A(Container.getElementsByTagName('select'));
     elementArray.each
     (
         function(element)
         {
            var paraValue=GetUrlParam(element.id);
            if(paraValue!=null && paraValue!="")
                 CheckedListByValueOrText(element,paraValue,1);
         }
     );
}
/**
**判断制定的字符串中(1,2,3,6,abc,def)格式，存在指定值
**/
function CheckTargetIsExistInValue(targetValue,OriginValue,splitChar)
{
    if(OriginValue==null || OriginValue=="")
        return false;
        
    var retValue=false;
    var array=OriginValue.split(splitChar);
    for(i=0;i<array.length;i++)
    {
        if(targetValue==array[i])
        {
            retValue=true;
            break;
        }
    }
    return retValue;
}
/*名称：getStringLength
  功能：获取字符串长度
  参数：s - 字符串

  返回：字节长度
*/
function GetStringLength(s)
{
	var len = 0;
	for(i=0;i<s.length;i++)
	{
		if(s.charCodeAt(i) > 255)
			len = len +2;
		else
			len = len +1;
	} 
	return len;
}
/*名称：toTrim
  功能：去除字串前后空格

  参数：s - 待处理字串

  返回：处理后字串
*/
function ToTrim(s)
{
	return s.replace(/^\s*|\s*$/g,"");
}
/***************************************************************************String******************************************/

/***************************************************************************cookies*****************************************/
/**
**获得Cookie解码后的值
**/
function GetCookieVal(offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

/**
**设定Cookie值
**/
function SetCookie(name, value)
{
    var expireDate=new Date();
   
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    if(expires!=null)
        expireDate.setTime(expires);
    var newvalue= name + "=" + escape (value) +((expireDate == null) ? "" : ("; expires="+ expireDate.toGMTString()))
    +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
    +((secure == true) ? "; secure" : "");

    document.cookie =newvalue;
}

/**
**删除Cookie
**/
function DelCookie(name)
{
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}

/**
**获得Cookie的原始值
**/
function GetCookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return GetCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
/**
**将一个字符串插入到一个字符串中，如果目标串中存在，就不插入。
**/
function MerginStringToString(src,tar)
{
    if(src=="" || src==null)
        return tar;
   
    var retValue="";
    var _tarlist=tar.split(",");
    var _srclist=src.split(",");
    
    retValue=tar;
    var _isExist=false;
    for(var i=0;i<_srclist.length;i++)
    {
       var _srcitem=_srclist[i];
       for(var j=0;j<_tarlist.length;j++)
       {
            var _taritem=_tarlist[j];
            if(_srcitem==_taritem)
                _isExist=true;
       }
       if(!_isExist)
           retValue=retValue+","+_srcitem;
    }
    return retValue;
}

function RemoveStringToString(src,tar)
{
     if(tar=="" || tar==null)
        return src;
   
    var retValue="";
    var _tarlist=tar.split(",");
    var _srclist=src.split(",");
    
    retValue=tar;
    var _isExist=false;
    for(var i=0;i<_srclist.length;i++)
    {
       var _srcitem=_srclist[i];
       for(var j=0;j<_tarlist.length;j++)
       {
            var _taritem=_tarlist[j];
            if(_srcitem==_taritem)
                _isExist=true;
       }
       if(!_isExist)
           retValue=retValue+","+_srcitem;
    }
    return retValue;
}
/***************************************************************************cookies*************************************************/


/***************************************************************************Validate*************************************************/
/**
* 验证mail是否合法
**/
function ValidateEmail(srcStr)
{
    var expr='^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$';
    var Reg= new RegExp(expr);
    if(Reg.test(srcStr))
        return true;
    else
        return false;
}
/**
* 验证是否是由CharOrNum组成
**/
function ValidateChar(srcStr)
{
    var expr='^[a-zA-Z]|[0-9][a-zA-Z0-9_]*$';
    var Reg= new RegExp(expr);
    if(Reg.test(srcStr))
        return true;
    else
        return false;
}
/**
*验证是否合法钱数
**/
function ValidateMoney(srcStr)
{
   return ValidateNum(srcStr);
}
/**
*验证是否合法Url
**/
function ValidateUrl(srcStr)
{
    var expr='[a-zA-z]+://[^s]*';
    var Reg= new RegExp(expr);
    if(Reg.test(srcStr))
        return true;
    else
        return false;
}
/**
*验证是否合法数字
**/
function ValidateNum(srcStr)
{
    var expr='^([1-9][0-9]*)|0$';
    var Reg= new RegExp(expr);
    if(Reg.test(srcStr))
        return true;
    else
        return false;
}
/**验证长度是否合法
**/
function ValidateLength(srcStr,minLength,maxLength)
{
     var length=GetStringLength(srcStr);
     if(length>=minLength && length<=maxLength)
        return true;
     else
        return false;
}
/**
*比较两个的值是否相等
**/
function CompareToObject(srcInput,destInput)
{
    var srcValue=toTrim(srcInput.value);
    var destValue=toTrim(destInput.value);
    var retv=false;
    (srcValue==destValue)?retv=true:retv=false;
    return retv;
}
/*名称:IsInt
  功能:检测是否是整型
  参数:s - 待检测字条符
  返回:true/false
*/
function IsInt(s)
{
	var re=/^[\+|-]{0,1}\d+$/;
	return re.test(s);
}
/***************************************************************************Validate*************************************************/

/***************************************************************************ArrayList*************************************************/
function ArrayList()
 {
      this.map = new Array();
      this.Item=function(key, value)
      {
        this.key = key;
        this.value = value;
      };
      this.setAt=function(key, value)
      {
          for (var i = 0; i < this.map.length; i++)
          {
            if ( this.map[i].key == key )
            {
              this.map[i].value = value;
              return;
            }
          }
          this.map[this.map.length] = new this.Item(key, value);
      };
     this.indexUp=function(index)
     {
         return this.map[index].value;
     };
     this.lookUp=function(key)
     {
          for (var i = 0; i < this.map.length; i++)
          {
            if ( this.map[i].key == key )
            {
              return this.map[i].value;
            }
          } 
          return null;
      };
     this.indexUpItem=function(index)
     {
        return this.map[index];
     };
    
     this.removeKey=function(key)
     {
          var v;
          for (var i = 0; i < this.map.length; i++)
          {
            v = this.map.pop();
            if ( v.key == key )
              continue;
              
            this.map.unshift(v);
          }
      };

    this.getCount=function()
    {
      return this.map.length;
    };

    this.isEmpty=function()
    {
      return this.map.length <= 0;
    };
    this.setEmpty=function()
    {
        this.map.length = 0;
    }
}
/***************************************************ArrayList*************************************************/


/*****************************************根据指定父键值,绑定列表框***********************************************/
/**
**要求异步页面的值格式为code|name,code|name,code|name
**beToBindList 被绑定的列表框;url异步页面地址;
**/
function AsynBindList(beToBindList,url)
{

    new Ajax.Request(url,{method:"get",parameters:null,asynchronous:false,onSuccess:function(resText)
    {
        var text=resText.responseText.strip();
       
        if(text=="" || text==null)
           return ;
        var arr=text.split(',');
        $(beToBindList).length = 0;
        var newOption;
        for(var i=0;i<arr.length;i++)
        { 
            var temp=arr[i].split('|');
            newOption = new Option();
            newOption.value=temp[0];
            newOption.text=temp[1];
            $(beToBindList).options.add(newOption);
        } 
    }});
}

function AsynPostData(url,data,dealFunction)
{
     new Ajax.Request(url ,
     { method: 'post',
        postBody:'data='+data, 
        onSuccess:dealFunction
    });
}
/*****************************************根据指定父键盘值,绑定列表框***********************************************/


/*****************************************对table的行列进行操作***********************************************/
function UmeTable()
{
    this.ColumnList=new ArrayList();
    this.Draw=function(srcTable)
    {
        var newRow=srcTable.insertRow();
        var columnTotal=this.ColumnList.getCount();
        for(var i=0;i<columnTotal;i++)
        {
            newRow.insertCell(i); 
        }
        for(var i=0;i<this.ColumnList.getCount();i++)
        {
              newRow.cells(i).innerText=this.ColumnList.indexUp(i).ColumnId;
              newRow.cells(i).innerHTML=this.ColumnList.indexUp(i).CoumnHtml;
        }
    };
    this.AddColumn=function(col)
    {
        this.ColumnList.setAt(col.ColumnId,col);
    };
    this.Column=function()
    {
        this.ColumnId="";
        this.ColumnClass="";
        this.CoumnHtml="";
    };
    this.DeleteRow=function(srcTable,ColumnIndex,ColumnId)
    {
        var rows=srcTable.getElementsByTagName('tr');
        for(var i=0;i<rows.length;rows++)
        {
            alert(rows(i).cells(ColumnIndex).innerHTML);
            colsId=rows(i).cells(ColumnIndex).innerText;
            if(colsId==ColumnId)
            {
                 srcTable.deleteRow(i);
                 break;
            }
        }
        var table=new umeTable();
       
    }
    
    
}
/*****************************************对table的行列进行操作***********************************************/
/*****************************************TreeView 操作*****************************************************/
function OnTreeNodeChecked(treeId,treeObj)
{
    var eventElement =event.srcElement; 
    if(eventElement.type=='checkbox') 
    {
  
       var subLength=treeObj.id.length+1;
       var nodeIndex=eventElement.id.substring(subLength).substring(0,eventElement.id.substring(subLength).indexOf("C"));
       var parentDivId=eventElement.parentElement.parentElement.parentElement.parentElement.parentElement.id;
       
       var currentParentDiv=$(parentDivId);
       var currentParentCheck=$(parentDivId.replace("Nodes","CheckBox"));
       if(currentParentCheck!=null)
       {
           var brotherSameStatus=IsAllCheckedByElement(currentParentDiv,eventElement.checked);
           
           if(brotherSameStatus)
                currentParentCheck.checked=eventElement.checked;
           else
                currentParentCheck.checked=false;
           CheckedParent(currentParentCheck,treeObj);
       }
        CheckedChildren(eventElement,treeObj);
    }
}
function CheckedParent(eventElement,treeObj)
{
   var subLength=treeObj.id.length+1;
   var nodeIndex=eventElement.id.substring(subLength).substring(0,eventElement.id.substring(subLength).indexOf("C"));
   var parentDivId=eventElement.parentElement.parentElement.parentElement.parentElement.parentElement.id;
   
   var currentParentDiv=$(parentDivId);
   var currentParentCheck=$(parentDivId.replace("Nodes","CheckBox"));
   if(currentParentCheck!=null)
   {
       var brotherSameStatus=IsAllCheckedByElement(currentParentDiv,eventElement.checked);
       
       if(brotherSameStatus)
            currentParentCheck.checked=eventElement.checked;
       else
            currentParentCheck.checked=false;
       CheckedParent(currentParentCheck,treeObj);
   }
}
function CheckedChildren(eventElement,treeObj)
{
   if(eventElement.type=='checkbox') 
   {
      var currentDiv=$(eventElement.id.replace("CheckBox","Nodes"));
      if(currentDiv!=null)
            MultiCheckedByElement(currentDiv,eventElement.checked);
   }
}
/*****************************************TreeView 操作*****************************************************/


