var IE=!!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1);
var FF=!!(navigator.userAgent.indexOf("Firefox")!==-1);
/**
 * getElementById方法的缩写
 */
var $=function(element,doc) {
  doc=doc||document;
  if(!element){
      return null;
  }
  if (!element.nodeType){
    element = doc.getElementById(element+"");
  }
  return element;
}
/**
 * getElementsByName方法简写
 */
var $N=function(name,doc){
    doc=doc||document;
	var es=doc.getElementsByName(name);
	var result=[];
	for(var i=0; i<es.length; i++) {
		if(es[i].name===name){
			result.push(es[i]);	
		}
	}
	
	return result;
};
/**
 * getElementsByTagName方法简写
 */
var $T=function(tagName,e,doc){
    doc=doc||document;
    var es=$(e,doc).getElementsByTagName(tagName);
    if(es.length==1){
        return es[0];
    }
    return es;
    
}
var $F={
    "window":function(id,doc){
         var frame=$(id,doc);
         
  	    if(frame){
  	       return frame.contentWindow;
  	    }
  	    return null;
  	 },
  	 "document":function(id,doc){
  	    var frame=$(id,doc);
  	    if(frame){
  	        if(frame.contentDocument){
  	            return frame.contentDocument;
  	        }
  	        
  	        return this.window(id,doc).document;
  	    }
  	    return null;
  	 },
  	 scrollHeight:function(id,doc){
  	    var frameDoc=this.document(id,doc);
  	   
  	    if(frameDoc.body){
  	        return frameDoc.body.scrollHeight;
        }else{
            return frameDoc.documentElement.scrollHeight;
        }
  	    
  	    return 0;
  	 }
}

/**
 * 获取innherHTML,使用Tool.json2Object转换为js对象
 */
var $$=function(id){
	id=$(id);
	var string=id.innerHTML;
	if(String.isNone(string)){
		return null;
	}
	try{
		var result=Tool.json2Object(string);
	}catch(e){
		throw e;
	}
	return result;
	
}
/**
 * 显示隐藏元素
 */
var $xo=function(target,visibility){
	target=$(target);
	if(Object.isNone(target)){
		return;
	}
	
    if(visibility){
       if(target.style.visibility==="hidden"){
           target.style.visibility="visible";
       }else{
           target.style.visibility="hidden";
       }
    }else{
       if(target.style.display!=="none"){
           target.style.display="none";
       }else{
           target.style.display="";
       } 
    }
}

/**
 * 显示元素
*  
* 
* 
*/
var $o=function(target,visibility){
	target=$(target);
	if(Object.isNone(target)){
		return;
	}
	
    if(visibility){
       if(target.style.visibility!=="visible"){
           target.style.visibility="visible";
       }
    }else{
       if(target.style.display==="none"){
           target.style.display="";
       }
    }
	
}

var $x=function(target,visibility){
	target=$(target);
	if(Object.isNone(target)){
		return;
	}
	
  	 if(visibility){
       if(target.style.visibility!=="hidden"){
           target.style.visibility="hidden";
       }
    }else{
       if(target.style.display!=="none"){
           target.style.display="none";
       }
    }
}

/**
 * 关闭窗口
 */
var windowClose=function(win){
	win=win||window;
	win.opener=false;
	win.close();
}
/**
 * 显示对象详细
 */
var alertIn=function(object){
	var result="";
	var num=0;
	var keys=[];
	for(var i in object){keys.push(i);}
	keys.sort();
	for(var index=0,len=keys.length; index<len; index++) {
		num+=1;
		result+=keys[index]+"="+object[keys[index]]+";\n";
		if(num%20===0){
			window.alert(result);
			result="";
		}
	}
	if(num<20){window.alert(result);}
};
/**alert方法的扩展*/
var alerts=function(){
    var str="";
    for(var index=0,len=arguments.length; index<len; index++) {
        var argument=arguments[index];
    	   str+=argument+" ";     
    }
    window.alert(str);
}
//定义包结构	   	  	
var  	packageJS=function(path){
	   	    var pathArray=path.split("\.");
	   	    var part=pathArray[0];
	   	    if(eval("typeof "+part+"==='undefined'")){
	   	           eval(part+"={}");
	   	    }
   	       for(var index=1; index<pathArray.length; index+=1) {
              part+="."+pathArray[index];
              if(eval("typeof "+part+"==='undefined'")){
   	     	    eval(part+"={}");
         	  }
	   }
}
Function.prototype.extend=function(superFunction){
	if(typeof superFunction!=="function"){
		throw (new Error("the super do not exsits!"));
	}
	
	if(!this.prototype._super_){
		this.prototype._super_=function(){
			var thisFunction=this.constructor;			
			if(!this._super){
				var superMethods={};
				for(var i in thisFunction.prototype){
					if(thisFunction.prototype.hasOwnProperty(i)){
						superMethods[i]=superFunction.prototype[i];
						superFunction.prototype[i]=thisFunction.prototype[i];
					}
				}
				this._super=superFunction.newInstanceWithArguments(arguments);
				thisFunction.prototype.extend(superFunction.prototype);
				superFunction.prototype.extend(superMethods);
				this.extend(this._super);
			}
			return this._super;
		}
	}
	return this;
}
Function.prototype.newInstance=function(){
	return Function.prototype.newInstanceWithArguments.call(this,arguments);
}
Function.prototype.newInstanceWithArguments=function(argus){
	switch(argus.length){
		case 0:return new this();
		case 1:return new this(argus[0]);
		case 2:return new this(argus[0],argus[1]);
		case 3:return new this(argus[0],argus[1],argus[2]);
		case 4:return new this(argus[0],argus[1],argus[2],argus[3]);
		case 5:return new this(argus[0],argus[1],argus[2],argus[3],argus[4]);
		default:{
			var createString="(new this(";
			for(var i=0;i<argus.length;i++){
				createString+="argus["+i+"],";
			}
			createString+="null))";
			return eval(createString);
		}
	}
}
Object._PROTOTYPE_FIELDS_ = [  
  'constructor',  
  'hasOwnProperty',  
  'isPrototypeOf',  
  'propertyIsEnumerable',  
  'toLocaleString',  
  'toString',  
  'valueOf'  
];

Object.prototype.extend=function(source,allProperty) {  
    var key;
    
    for (key in source) {
      if(allProperty||Object.prototype.hasOwnProperty.call(source, key)){
		 this[key] = source[key];
	  }
    }  
    for (var j = 0; j <Object._PROTOTYPE_FIELDS_.length; j++) {  
      key = Object._PROTOTYPE_FIELDS_[j];  
      if (Object.prototype.hasOwnProperty.call(source, key)) {  
        this[key] = source[key];  
      }  
    }  
   
};  

/**
 * 字符串常用方法
 */

String.prototype.trim=function(){
	return this.replace(/^\s+/, '').replace(/\s+$/, '');
}
String.prototype.isInteger=function(){
		var str=this.trim();
    	return new Number(parseInt(str)).toString()===str;
}
String.prototype.isFloat=function(){
		var str=this.trim();
    	
    	var length=str.length;
    	if(str.indexOf(".")===str.lastIndexOf (".")){
    	    while(str.charAt(--length)==='0'||str.charAt(length)==='.'){
    			 str=str.substring(0,length);
    	    }
    	}
    	return new Number(parseFloat(str)).toString()===str;
}
String.prototype.isNone=function(){
	return this.trim().length===0;
}

String.isNone=function(str){
	
	return (typeof str==="undefined")||str===null||str.trim().length===0;
}

/**
 * 对象常用方法
 */
 //获取对象类型字符串
Object.prototype.getType=function(){
	return Object.prototype.toString.call(this).match(/^\[object\s(.*)\]$/)[1];	
}
//是否是数组
Object.prototype.isArray=function(){
	return this instanceof Array;	
}
//是否是Element元素
Object.prototype.isElement=function () {
    return !!(this && this.nodeType == 1);
}
//是否是函数
Object.prototype.isFunction=function () {
    return typeof this === "function";
}
//是否是字符串
 Object.prototype.isString=function () {
    return typeof this === "string";
  }
//是否是数字
Object.prototype.isNumber=function () {
    return  typeof this === "number";
  }
//是否是未定义
 Object.isUndefined=function (object) {
    return typeof object === "undefined";
 }
 Object.isNone=function(object){
   return  Object.isUndefined(object)||object===null;
 }
 
 
/**
 * 工具栏方法
 */ 
 var Tool={};
 Tool.NoneFunction=function(){return true;};
 	//返回不抛出异常的第一个方法的执行结果
 Tool.tryCatch=function(){
        var returnValue;
        var tag=arguments[length-1];
        for (var i = 0, length = arguments.length; i < length; i++) {
        var method = arguments[i];
       
        try {
            returnValue = method();
            break;
        } catch (e) { 
        }
    }
        return returnValue; 
 }
 
 //json字符串转换js对象
 Tool.json2Object=function(json){
 	json=json.trim();
    try{
        var result=eval('('+json+')');
        if(!result){
        	throw "json解析异常:"+json;
        }
        result.toString=function(){
        	return json;
        }
        return result;   
    }catch(e){
        throw e;
    }
 }
 Tool.toArray=function(argu){
 	var array=[];
 	for(var i=0; i<argu.length; i++) {
 		array[i]=argu[i];
 	}
 	return array;
 }
 Tool.toQueryString=function(obj){
		var str="";
		var value=null;
		for(var key in obj){
			if(obj.hasOwnProperty(key)){
				value=obj[key];
				if(!Object.isNone(value)){
					if(value.isArray()){
						for(var i=0; i<value.length; i++) {
							str+=key+"="+value[i]+"&";
						}	
					}else if(value.isFunction(value)){
						continue;
					}else{
						str+=key+"="+value+"&";
					}
			}
			}
		}
		return str;
	}
Tool.composeURL=function(url,name,value){
	if(url.indexOf("?")!=-1){
		if(url.charAt(url.length-1)!=="&"){
			url+="&";
		}
	}else{
		url+="?";
	}
	if(name.length===value.length){
		for(var index=0; index<name.length; index+=1) {
				url+=name[index]+"="+value[index]+"&";
		}
	}
	return encodeURI(url);
};
	
	

/**
 * LIST
 * 
 */
var List=function(){
    this._array=[]; 
}

List.prototype={
	_equals_:function(a,b){
		return a===b;
	},
    add:function(item){
    	if(typeof item!=="undefined"){
   			this._array.push(item);
   		}
    },
    "set":function(index,item){
    		if(typeof item==="undefined"){
    			return;
    		}
    	if(typeof index==="number"&&index<this._array.length){
   			var oldItem=this._array[index];
   			this._array[index]=item;
   			return oldItem;
   		}
    },
    addAll:function(list){
    	var array=this._array;
    	list.each(function(){
    		array.push(this);    		
    	});
    },
    clear:function(){
    	this._array=[];
    },
    contains:function(item,equals){
    	return this.indexOf(item,equals)===-1?false:true;
    },
    get:function(index){
    	if(index<this._array.length){
    		return this._array[index];	
    	}
    },
    first:function(){
    	if(this._array.length!==0){
        	return this._array[0];
    	}
    },
    last:function(){
    	if(this._array.length!==0){
        	return  this._array[this._array.length-1];
    	}
    },
    indexOf:function(item,equals){
       equals=equals||List.prototype._equals_;
    	for(var i=0; i<this._array.length; i++) {
    		if(equals(this._array[i],item)){
    			return i;
    		}
    	}
    	return -1;
    },
    lastIndexOf:function(item,equals){
    	equals=equals||List.prototype._equals_;
    	for(var i=this._array.length; i>=0;) {
    		if(equals(this._array[--i],item)){
    			return i;
    		}
    	}
    	return -1;
    },
    isEmpty:function(){
    	return this._array.length===0;
    },
    removeByIndex:function(index){
    	var remove=null;
    	var len=this._array.length;
    	if(index<len){
    		remove=this._array[index];
    	   	for(var i=index;i<len;){
				this._array[i++]=this._array[i];    		
    		}
			this._array.length--;
    		return remove;
    	}
      },
     removeByIndexs:function(indexArray){
    	var len=this._array.length;
    	var index=-1;
    	var newArray=[];
    	for(var i=0; i<indexArray.length; i++) {
    		if((index=indexArray[i])<len){
    			delete this._array[index];
    		}
    	}
    	for(i=0; i<this._array.length; i++) {
    		if(typeof this._array[i]==="undefined"){
    			continue;
    		}
    		newArray.push(this._array[i]);
    	}
    	this._array=newArray;
     },
    remove:function(item){
        var index=this.indexOf(item);
        if(index!==-1){
            this.removeByIndex(index);
        }
    },
    size:function(){
        return this._array.length;
    },
    each:function(method,startIndex){
        if(typeof startIndex!=="number"){
        	startIndex=0;
        }
        for(var index=startIndex;index<this._array.length; index++) {
      	 if(method.call(this._array[index],index)){
      	     break;
      	 }
        }
    },
    sort:function(method){
        return this._array.sort(method);
    },
    reverse:function(){
    	this._array.reverse();
    },
    toString:function(){
        return this._array.toString();
    }
    
}
/**
 * Map对象
 * 其遍历顺序为其首次插入顺序(若删除后在添加,恢复原先顺序)
 * 若要保证其跌倒顺序,请使用LinkedMap
 */	
 
var Map=function(a,b){
   //这里用数据和对象其实一样,但{}是更底层的对象
   this._map={};
   this._size=0;
   /**
    * 1 修改了getValue方法名为get
    */
	return this;
}
Map.prototype={
	contains:function(key){
       return typeof this._map[key]!=="undefined";
    },
    put:function(key,value){
      if(this.contains(this._map[key])){
      	this._size++;	
      }
      this._map[key]=value;
    },
    putAll:function(map){
    	var oldMap=this._map;
    	map.each(function(key,value){
    		oldMap.put(key,value);
    	});
    },
    remove:function(key){
    	if(this.contains(key)){
       	 	var  remove=this._map[key];
        	delete this._map[key];
        	this._size--; 
        	return remove;
    	}
    },
    get:function(key){
       return this._map[key]; 
    },
    getKeys:function(targetValue,equalsCallBack){
        var keys=[];
        equalsCallBack=equalsCallBack||function(a,b){
        	return a===b;
        };
        this.each(function(key,value){
           		if(equalsCallBack(value,targetValue)){
               		 keys.push(key);
	            }
        });
        return keys;
    },
    keys:function(sortMethod){
        var keys=[];
        for(var key in this._map){
          if(this._map.hasOwnProperty(key)){
               keys.push(key);
          }
        }
        return sortMethod?keys.sort(sortMethod):keys;
    },
    values:function(){
        var values=[];
        for(var key in this._map){
          if(this._map.hasOwnProperty(key)){
             values.push(this._map[key]);
          }
        }
        return values;
    },
    /**
     * method 回调方法,参数1 为key 参数2 为value
     * params 需要在回调方法中使用的参数
     */
    each:function(method){
        for(var key in this._map){
          if(this._map.hasOwnProperty(key)){
                if(method.call(this,key,this._map[key])){
      	              break;
      	        }    
          }
        }
    },
    clear:function(){
        for(var key in this._map){
        	if(this._map.hasOwnProperty(key)){
        		delete this._map[key];
        	}
        }
  	    this._size=0;
    },
    isEmpty:function(){
    	return this._size===0;
    },
    size:function(){
    	return this._size;
    },
    toString:function(){
        var strs=[];
        this.each(function(key,value){
        	strs.push(key+"="+value);
        });
        return "{"+strs.join(",")+"}";
    }
    
}


var LinkedMap=function(){
	this._super_();
	this._keysLinked=[];
}.extend(Map);


LinkedMap.prototype.each=function(method){
	var key=null;
	for(var i=0; i<this._keysLinked.length; i++) {
		key=this._keysLinked[i];
		if(key===false){
			continue;
		}
		if(method(key,this._map[key])){
			break;
		}
	}
}

LinkedMap.prototype.put=function(key,value){
	this._super.put(key,value);
	if(this.contains(key)){
		this._keysLinked.push(key);
	}
}
/**
 *删除某个键是,_keysLinked对应值置为false;在遍历时排除为false的
 *
 */
	

LinkedMap.prototype.remove=function(key){
	if(this.contains(key)){
		this._super.remove(key);	
		var array=this._keysLinked;
		for(var i=0; i<array.length; i++) {
    		if(array[i]===key){
				array[i]=false;
				break;
			}
		}
	}
}
 
 /**
  * Position
  */

var Position=function(target){
 this.target=target;
 this.X;
 this.Y;
 this.Z;
 this.W;
 this.H;  
 this.toString=function(){return "X:"+x+" ;Y:"+y+" ;Z:"+z+" ;W:"+w+" ;H:"+h;} 
 this.__init__();
}

Position.prototype.__init__=function(){
  var x=y=z=w=h=0;
  var target=this.target;
  var parents=[];
  var nextParent=target.parentElement;
  
  while(nextParent!=null&&!Object.isUndefined(nextParent.tagName)&&nextParent.tagName!=="HTML"){
      parents.push(nextParent);
      nextParent=nextParent.parentElement;
  }
  var body=parents[parents.length-1];

  x=target.offsetLeft;
  
  for(var index=0,len=parents.length; index<len; index++) {
      x+=parents[index].offsetLeft;
  }
  y=target.offsetTop;
  for(index=0,len=parents.length; index<len; index++) {
     y+=parents[index].offsetTop;
  }
  z=target.style.zIndex;
  var width=target.style.width;
  if(width.indexOf("%")!=-1){
     w=target.offsetWidth;
  }else{
     w=parseInt(width);
      if(!w){
           w=target.offsetWidth;
      }
  }
  var height=target.style.height;
  if(height.indexOf("%")!=-1){
         h=target.offsetHeight;
  }else{
         h=parseInt(target.style.height);  
         if(!h){
           h=target.offsetHeight;
         } 
  }
  this.X=x;
  this.Y=y;
  this.Z=z;
  this.H=h;
  this.W=w;
};
/**
 * TABLE
 */

var TableManager=function(e){
	this.table=$(e);//table 对象
	this.headBgColor; // 标题栏背景
	this.singleRowBgColor;//单数行背景色
	this.doubleRowColor; //偶数行背景色
	this.showBgColor; //onmouseover背景色
	this.selectedBgColor;//被选中背景色
	this.checkBoxName=null;
	
}
TableManager.prototype={
	//设置样式
	setStyle:function(headRow,singleRow,doubleRow,selectRow){
		
		this.headBgColor=headRow||"#A4DCFB";
		this.singleRowBgColor=singleRow||"#D6ECFA";
		this.doubleRowColor=doubleRow||"#ECF6FF";
		this.selectedBgColor=selectRow||"lightseagreen";
		var rows=this.table.rows;
		var rowlength=rows.length;
		if(rowlength>0){
			rows[0].style.backgroundColor = this.headBgColor;
		}
		
		for (var i = 1; i < rowlength; i+=1) {
			if (i % 2 ===0) {
				rows[i].style.backgroundColor = this.doubleRowColor;
					
			} else {
				rows[i].style.backgroundColor = this.singleRowBgColor;
			}
			rows[i].tempBgColor=rows[i].style.backgroundColor;
			rows[i].tableManager=this;
		}
	},
	setCheckBoxName:function(name){
		this.checkBoxName=name;
		this._addCheckBoxListener_();
	},
	//checkBox选择监听器
	_addCheckBoxListener_:function(){
		var rows=this.table.rows;
		var box=null;
		for (var i = 1; i < rows.length; i+=1) {
				box=this._findCheckBox_(rows[i],this.checkBoxName);
				if(box){
					EventManager.addListener(box,"click",this._checkBoxListener_,rows[i]);
				}	
		}
	},
	_checkBoxListener_:function(){
		var box=this.checkBox;
		var tableManager=this.tableManager;
		if(box.checked){
			//取消mouse监听
			this.style.backgroundColor=tableManager.selectedBgColor;
			this._active=false;
		}else{
			this.style.backgroundColor=this.tempBgColor;
			this._active=true;
		}
	},
	_findCheckBox_:function(tr,name){
		var inputs=tr.getElementsByTagName("input");
		for(var i=0; i<inputs.length; i++) {
			if(inputs[i].name===name){
				tr.checkBox=inputs[i];
				return inputs[i];
			}
		}
	},
	_onmouseoverListener_:function () {
		if(this._active){
			this.style.backgroundColor = this.tableManager.showBgColor;
		}
    },
    _onmouseoutListener_:function () {
		if(this._active){
			this.style.backgroundColor = this.tempBgColor;
		}
	},
	_ondbclickListener_:function(){
		var table=this.tableManager;
				if(table.clickRow){
				  var row=table.clickRow;
				  row.style.backgroundColor =row.actureColor;
				  row.onmouseover =table.onmouseoverListener;
			      row.onmouseout = table.onmouseoutListener;
			      row.ondblclick=table.ondbclickListener;
			     
				}
				table.clickRow=this;
				this.style.backgroundColor = table.clickColor;
				this.onmouseout=null;
				this.onmouseover=null;
				this.ondblclick=null;
				var method=null;
				for(var name in table.clickListeners){
					if(table.clickListeners.hasOwnProperty(name)){
						method=table.clickListeners[name];
						method.call(this,method.params);
					}
				}
	},
	//添加点击监听器
	addSelectListenner:function(name,method,params){
		method.params=params;
		this.clickListeners[name]=method;
	},
	//删除点击监听器
	deleteSelectListenner:function(name){
		delete this.clickListeners[name]
	},
	//样式监听器	
	addStyleListener:function(showColor){
		this.showBgColor=showColor||"#FFffcc";
		var table=this.table;
		var rows=table.rows;
		var rowlength=rows.length;
		
		for (var i = 1; i <rowlength; i+=1) {
			rows[i]._active=true;
			EventManager.addListener(rows[i],"onmouseover",this._onmouseoverListener_);
			EventManager.addListener(rows[i],"onmouseout",this._onmouseoutListener_);
		}
		
	}
}


/*****************************************************************************
*@version 1.0.1
* @fileoverview 处理AJAX相关,主要对象AjaxManager 
* @author ben
* @since javascript 5.5
**************************************************************************** */

/**
 * @param callback 请求完成时候回调函数
 */
 
var AjaxManager=function(okCallBack,failCallBack){
    this.req;
    this.onDone=okCallBack||Tool.NoneFunction;
    this.onFailed=failCallBack||this._defaultFailed_;
    this.init();
  };
//定义错误信息
AjaxManager.error={
    ajax_00:"浏览器不支持Ajax,请检查浏览器版本!",
    ajax_01:"无法连接到指定URL",
    ajax_02:"无法连接服务器,请检查网络!",
    ajax_03:"由于您长时间未进行操作,会话已经失效,请重新登录!"
};
AjaxManager.prototype={
    //提供getXML
    // HttpRequest对象,为req赋值
    init:function(){
    	
        this.req=Tool.tryCatch(
         function() {return new XMLHttpRequest()},
         function() {return new ActiveXObject('Msxml2.XMLHTTP')},
        function() {return new ActiveXObject('Microsoft.XMLHTTP')}
    ) || null;
   
   },
    //处理回调函数
    doCallBack:function(){
    	try{
        var ajaxManager=this;
        var req=this.req;
         if(!req){
            this._canNotGetXMLHttpRequest_();
         }
          req.onreadystatechange=function(){
            var state=req.readyState;
            if(state==4){
                var httpState=req.status;
                 if(httpState==200||httpState==0){
                       ajaxManager.onDone.call(ajaxManager);
                }else {
                	   ajaxManager.onFailed.call(ajaxManager,httpState);
                }
            }
        }
    	}catch(e){
    		alert(e);
    	}
    },
    /**
     * 发送GET类型请求
     * @param url 请求的目标url
     */
    sendByGet:function(url,synchronize,headers){
       if(!url){
        	throw (AjaxManager.error.ajax_01);
        }
        url=encodeURI((url));
        this.doCallBack();
        var req=this.req;
        if(typeof synchronize==="undefined"){
        	synchronize=true;
        }
        req.open("GET",url,synchronize);
        req.setRequestHeader("from","ajax");
       if(headers){
      	 for(var key in headers){
          if(headers.hasOwnProperty(key)){
             req.setRequestHeader(key,headers[key]);       
          }
       	}
       }
       req.send(null); 
    },
    sendByHead:function(url,synchronize,headers){
    	if(!url){
        	throw (AjaxManager.error.ajax_01);
        }
        url=encodeURI((url));
        this.doCallBack();
        var req=this.req;
        if(typeof synchronize==="undefined"){
        	synchronize=true;
        }
        req.open("HEAD",url,synchronize);
        req.setRequestHeader("from","ajax");
       if(headers){
      	 for(var key in headers){
          if(headers.hasOwnProperty(key)){
             req.setRequestHeader(key,headers[key]);       
          }
       	}
       }
       req.send(null); 
    },
   /**
    * 发送POST类型请求
    * @param url 请求的目标url 
    * @param params 
    */
    sendByPost:function(url,params,synchronize,headers){
    	 if(!url){
        	throw (AjaxManager.error.ajax_01);
        }
        this.doCallBack();
         
        var req=this.req;
        
        if(params!=null&&typeof params!=="string"){
        	 params=Tool.toQueryString(params);	
        }
        if(typeof synchronize==="undefined"){
        	synchronize=true;
        }
        req.open("POST",url,synchronize);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
        req.setRequestHeader("from","ajax");
        if(headers){
      		for(var key in headers){
            	if(headers.hasOwnProperty(key)){
              		req.setRequestHeader(key,headers[key]);       
            	}
       		}
        }
        req.send(params);  
    },
    sendByForm:function(form,targetSubmit,synchronize,headers){
        if(form.enctype==="multipart/form-data"){
        	var doc=form.ownerDocument;
        	var frameName="hiddenIFrame";
        	form.target=frameName;
        	var hiddenIFrame=$(frameName+"id",doc);
        	if(!hiddenIFrame){
        		
        		var dom="iframe"
        		if(IE){
        			dom="<iframe name='"+frameName+"'/>"
        		}
        		hiddenIFrame=doc.createElement(dom);
        		hiddenIFrame.id=frameName+"id";
        		hiddenIFrame.name=frameName;
        		doc.body.appendChild(hiddenIFrame);
        		hiddenIFrame.style.display="none";
        	}
        	var ajaxManager=this;
        	EventManager.addListener(hiddenIFrame,"onload",function(){
        			var win=this.contentWindow;
        			var result=$("ajaxResponse",win.document);
        			if(result){
        				 var req={};
        				 result=result.innerHTML;
        				 req.responseText=result;
        				 req.responseXML=result;
        			     ajaxManager.req=req;
        				 ajaxManager.onDone.call(ajaxManager);
        			}else{
        				 req={};
        				 result=win.document.body.innerHTML;
        				 req.responseText=result;
        				 req.responseXML=result;
        			     ajaxManager.req=req;
        				 ajaxManager.onFailed.call(ajaxManager);
        			}
        	},hiddenIFrame);
        	form.submit();
        	return;
        }
        var url=form.action;
        var ajaxForm=new AjaxForm(form);
        var params=ajaxForm.getQueryString(targetSubmit);
        var method=form.method;
        method=method.toLowerCase();
        if(method==="get"){
        	url+="?";
        	url+=params;
        	this.sendByGet(url,synchronize,headers);
        }else{
        	this.sendByPost(url,params,synchronize,headers);
        }
    },
    //获得文本类型结果
    loadText:function(){
        var req=this.req;
        var text=req.responseText;
        if(text.length===0){
        	return null;
        }
	    return text;
    },
    loadHeads:function(){
    	var req=this.req;
    	var heads=req.getAllResponseHeaders();
    	var parts=heads.split("\n");
    	var part=null;
    	var index=-1;
    	var result={};
    	for(var i=0; i<parts.length; i++) {
    		part=parts[i];
    		if((index=part.indexOf(":"))!==-1){
    			result[part.substr(0,index)]=part.substr(index+1);
    		}
    	}
    	return result;
    },
    //获得XML类型结果
    loadXML:function(){
        var req=this.req;
        return req.responseXML;
    },
    loadJson:function(){
    	var json=this.loadText();
    	if(json===null){
    		return null;
    	}
    	var result=null;
    	try{
    	    result=Tool.json2Object(json);
       	}catch(e){
    	     result={fail:true,desc:'json解析异常:->'+json,data:null};
    	}
       	result.toString=function(){
    	     return this.desc;
        }
       	return result;
    },
    //当无法获得XMLHttpRequest对象处理方法
    
    _canNotGetXMLHttpRequest_:function(){
    	throw (AjaxManager.error.ajax_00);
    },

    //默认发生错误回调方法
    _defaultFailed_:function(httpState){
        //后台定义的会话失效
        if(httpState===444){
        	alert(AjaxManager.error.ajax_03);
        }else{
			window.document.body.innerHTML=this.req.responseText;
        }
    }
 
 };
 /**
  * AJAx form
  */
 var AjaxForm=function(form){
	this._form=form;
	this._values={};
}
AjaxForm.prototype={
	_inputValue_:function(input,values){
		var type=input.type;
		type=type.toLowerCase();
		values=this._values[input.name];
		if(typeof values==="undefined"){
			values=[];
			this._values[input.name]=values;
		}
		var value=input.value;
		switch(type){
			case "text":{
				values.push(value);
				break;
			}	
			case "hidden":{
				values.push(value);
				break;
			}
			case "password":{
				values.push(value);
				break;
			}
			case "checkbox":{
				if(input.checked){
					values.push(value);
				}
				break;
			}
			case "radio":{
				if(input.checked){
					values.push(value);
				}
				break;
			}
			case "file":{
				values.push(value);
				break;
			}
			default:{
				
			}
		}
				
	},
	_textAreaValue_:function(textArea){
		var name=textArea.name;
		var values=this._values[name];
		if(typeof values==="undefined"){
			values=[];
			this._values[name]=values;
		}
		var text=textArea.value;
		values.push(text);	
	},
	_selectValue_:function(select){
		var name=select.name;
		var values=this._values[name];
		if(typeof values==="undefined"){
			values=[];
			this._values[name]=values;
		}
		var options=select.options;
		for(var i=0; i<options.length; i++) {
			if(options[i].selected){
				values.push(options[i].value);
			}
		}
	},
	getQueryString:function(targetSubmit){
		var form=this._form;
		var inputs=form.getElementsByTagName("input");
		for(var i=0; i<inputs.length; i++) {
			if(inputs[i].name!==''){
				this._inputValue_(inputs[i]);
			}
		}
		var selects=form.getElementsByTagName("select");
		for(i=0; i<selects.length; i++) {
			if(selects[i].name!==''){
				this._selectValue_(selects[i]);
			}
		}
		var textAreas=form.getElementsByTagName("textarea");
		for(i=0; i<textAreas.length; i++) {
			if(textAreas[i].name!==''){
				this._textAreaValue_(textAreas[i]);
			}
		}
		var values=this._values;
		var result="";
		var value=null;
		var first=true;
		if(targetSubmit){
			values[targetSubmit.name]=[targetSubmit.value];	
		}
		for(var key in values){
			if(values.hasOwnProperty(key)){
 				value=values[key];
				for(i=0; i<value.length; i++) {
					if(first){
					  first=false;
					}else{
						result+="&";
					}
					result+=key;
					result+="=";
					result+=value[i];
				}	
			}
		}
		
		return result;
	}
	
}
 
 
 
 
 
 
 
 
 
 
 /**
  * EVENT
  * 
  */
var EventManager={
	_doEventType_:function(eventType){
		var ieEventType=eventType;
		if(eventType.charAt(0)==='o'&&eventType.charAt(1)==='n'){
			ieEventType=eventType;
			eventType=eventType.substr(2);
		}else{
			ieEventType="on"+eventType;
		}
		return {ie:ieEventType,other:eventType}; 
	},
	deleteListener:function(target,eventType,callback){
		eventType=this._doEventType_(eventType);
		//ie
		var ieEventType=eventType.ie;
		//other
		eventType=eventType.other;
		if(target.detachEvent){
			target.detachEvent(ieEventType,callback.__EventManagerCallBack__);
		}else{
			target.removeEventListener(eventType,callback.__EventManagerCallBack__);
		}
		
	},
	addListener:function(target,eventType,callback,this2who){
		eventType=this._doEventType_(eventType);
		//ie
		var ieEventType=eventType.ie;
		//other
		eventType=eventType.other;
		if(!this2who){
				this2who=target;
		}
		if(target.attachEvent){
				callback.__EventManagerCallBack__=function(){
					callback.call(this2who,window.event);
				};
			target.attachEvent(ieEventType,callback.__EventManagerCallBack__);
		}else{
				callback.__EventManagerCallBack__=function(event){
					callback.call(this2who,event);
				};
			target.addEventListener(eventType,callback.__EventManagerCallBack__,false);
		}
	},
	
    //获得事件源
    getEventSource:function(event){
        event=this.getEvent(event);
        var target=event.srcElement;
        if(!target){
             target=event.target;
        }
        return target;
    },
    //获得事件对象
    getEvent:function(event){
        if(event){
            return event;
        }
         var wins=[];
         wins.push(window.top);
         this.getSonWindows(window.top,wins);
         for(var i=0,len=wins.length; i<len; i++) {
            event=wins[i].event;
         	if(event){
         	    return event;
         	}
         }
   },
   getSonWindows:function(win,wins){
       var sonWins=win.frames;
       for(var i=0,len=sonWins.length; i<len; i++) {
         	wins.push(sonWins[i]);
         	this.getSonWindows(sonWins[i],wins);
       }   
   }
}

/**
 * TREE
 */

/**
 * Tree Object constructor
 */
var Tree=function(container,doc){
			this._doc=doc||document;
			this._multiSelect=true;//可否多选
			this._container=$(container,this._doc);//树容器
			this._rootNode=null; //根节点
			this._id_node=new Map();//所有节点
			this._noFatherNode=[];//在加入时,暂时无法找到父节点的节点集合
			this._maxTier=0;//树最大层数
			this._beSelectedNode=null; //被选中节点
			this._beCheckedNodes=new List();// 被check的节点
			
  /**
   * 1 
   * 4 鼠标在node上移动时,box背景色应改变
   * 5 
   */
}
//Tree ico constants
Tree.IMG={
       I:"/MTSearch/images/I.gif",
       L:"/MTSearch/images/L.gif",
       T:"/MTSearch/images/T.gif",
       Lminus:"/MTSearch/images/Lminus.gif",
       Lplus:"/MTSearch/images/Lplus.gif",
       Tminus:"/MTSearch/images/Tminus.gif",
       Tplus:"/MTSearch/images/Tplus.gif",
       None:"/MTSearch/images/None.gif",
       Node:"/MTSearch/images/node.gif"
};
//Tree error infomation 
Tree._id_=function(id){
	id+="";
	 if((id).indexOf("tree_")!=-1){
            return id;
        }
    return "tree_"+id;
}
Tree.prototype={
	__initNode__:function(node){
			var father=node._parent;
	        var currentTier=father._tier+1;
	        node._tier=currentTier;//设置层为父节点层+1
	        if(currentTier>this._maxTier){
	        	this._maxTier=currentTier;
	        }
	        node._position=father._sons.size()+1;//设置在当前层中位置
	        //设置兄弟节点
	        if(node._position!==1){
	            var previous=father._sons.last();
	            previous._next=node;
	            node._previous=previous;
	        }
	        //添加到父节点子集中
	        father._sons.add(node);
		this._id_node.put(node._id,node);//在树中记录
        return this.__createElement__(node);
	},
     //初始化节点
    __createElement__:function(node){
         var doc=this._doc;
           //节点domid
         var id=Tree._id_(node._id);//节点标识符
         var div=doc.createElement("div");
         var table=doc.createElement("table");
         table.cellSpacing=0;
         table.cellPadding=0;
         table.border=0;
         div.id=id;
         var sonDiv=doc.createElement("div");
         sonDiv.id="son_"+id;
         node._divEL=div;
         node._trEL=table.insertRow(-1);
         node._sonDivEL=sonDiv;
         node=this.__initBasePart__(node);
         div.appendChild(table);
         var father=node._parent//节点父节点对象
         //根节点
         if(father===null){
            this._container.appendChild(div);   
            this._container.appendChild(sonDiv);
            node._open=true;//展开
         }else{
            father._sonDivEL.appendChild(div);
            father._sonDivEL.appendChild(sonDiv);
            sonDiv.style.display=node._open?"":"none";
         }
         node._inTree=true;//已加入树中
         return node;
    },
      //创建前段基本结构
    __initBasePart__:function(node){
        if(node.isRoot()){
        	return node;
        }
        var father=node._parent;
        var xoImg=father._xoEL;
        if(xoImg){
          //父节点存在下一兄弟节点,不是所处层最后节点
       		 if(father._next){
       		 	father._setXOImgsrc_("Tplus");
             }else{
             	father._setXOImgsrc_("Lplus");
             }
        }
        var baseParts=father._baseParts;     
        var part=null;        
        //复制父节点基本Part作为当前节点Part
        for(var i=0;i<baseParts.length;i++) {
          	node._initPart_(baseParts[i].cloneNode(true),true);
        }
        //再决定当前节点最后part
        var img=this._doc.createElement("img");
        //父节点存在下一兄弟节点,不是所处层最后节点
        if(father._next){
            img.src=Tree.IMG.I;
        }else{
            img.src=Tree.IMG.None;
        }
        node._initPart_(img,true);
        
        //当前节点XO默认为最后节点而且无子节点
        img=this._doc.createElement("img");
        img.srcName="L";
        img.src=Tree.IMG.L;
        node._initPart_(img);
        node._xoEL=img;
        //执行节点的展开关闭方法
        EventManager.addListener(img,"click",node._xoImgOnClick_,node);
        
        //修改前一兄弟节点和其子节点(如果存在)    
        var pervious=node._previous;
        if(pervious){   
            //修改前一节点标识
            var xo=pervious._xoEL;
              if(pervious.hasChild()){
              	pervious._setXOImgsrc_("Tplus");
              }else{
           		pervious._setXOImgsrc_("T");
              }
            
            //修改前一兄弟节点的所有其子节点,加入I线
            var changePosition=node._baseParts.length;
            var I=Tree.IMG.I;
            pervious._sons.each(function(){
				this._hasNextSiblingListener_(changePosition,I);	                	
            });
        }
        return node;
    },
        //处理未找到父节点的节点集合
    __initNoFatherNodes__:function(){
    	//先遍历一遍,初始化当前能找到的父节点
    	var newArray=[];
    	var node=null;
    	var father=null;
    	var array=this._noFatherNode;
    	for(var i=0; i<array.length; i++) {
    		//找到父节点
    		node=array[i];
    		father=this.getNode(node._parent);
    		if(father){
    			node._parent=father;
    			this.__initNode__(node);
    			node._cacheOperation.each(function(method,argus){
    				var array=Tool.toArray(argus);
    				node[method].apply(node,array);
    			});
    			node._cacheOperation=null;
    		}else{
    			newArray.push(node);
    		}
    	}
    	this._noFatherNode=newArray;
    	//说明未处理完了
    	if(array.length>newArray.length){
    		//再循环一遍,直到处理完了
    		this.__initNoFatherNodes__();	
    	}
    },
        //init root Node method
    initRootNode:function(id){
        if(Object.isNone(id)){
            throw new Error(1001,"根节点id未定义");
        }
	    var rootNode=new Tree.Node(null,id,this);
	    this._rootNode=rootNode;
	    this._tier=0; //设置层为0;
        this._position=1;//设置在当前层中位置为1 
        this._id_node.put(id,rootNode);//在树中记录
        return this.__createElement__(rootNode);
	},
    //init normal Node
    initNode:function(fid,id){
        //处理未找到父节点的节点集合
        this.__initNoFatherNodes__();
        
        if(Object.isNone(fid)){
            throw new Error(1003,"父节点id未定义");
        }
        if(Object.isNone(id)){
            throw new Error(1004,"节点id未定义");
        }
        if(this.contains(id)){
           throw new Error(1005,"节点id重复:"+id);           
        }
        var node=new Tree.Node(fid,id,this);
        //未找到父节点ID,在_noFatherNode集合中找
        var father=this.getNode(fid);
        if(!father){
        	node._cacheOperation=new Map();
        	this._noFatherNode.push(node);
        	return node;
        }
        node._parent=father;
        return this.__initNode__(node); 
   },
    multiSelect:function(multi){
    	if(arguments.length===0){
    		return this._multiSelect;
    	}
    	this._multiSelect=multi;
    },
    getBeCheckedNodes:function(){
    	return this._beCheckedNodes;
    },
    getBeSelectedNode:function(){
    	return this._beSelectedNode;
    },
    expandByTier:function(tier){
    	if(!tier){
    		tier=this._maxTier;
    	}
    	this._id_node.each(function(key,node){
    		if(node._tier<tier){
    			node.expand();	
    		}
    	});
    },
    reset:function(){
    	var list=this._beCheckedNodes;
    	list.each(function(){
    		this._boxEL.checked=false;
    	});
    	list.clear();
    	if(this._beSelectedNode){
    		this._beSelectedNode.unSelect();
    		this._beSelectedNode=null;
    	}
    	this._id_node.each(function(key,node){
    		if(node._tier!==0){
    			node.collapse();	
    		}
    	})
    	
    },
    contains:function(id){
        return this._id_node.contains(id);
    },
    getNodeAmount:function(){
    	return this._id_node.size();
    },
    getNode:function(id){
        if(id._id){
            return id;    
        }
       return this._id_node.get(id);
    },
   release:function(){
	   	this._beSelectedNode=null;
	   	this._beCheckedNodes.clear();
	   	this._beCheckedNodes=null;
	   	this._id_node.clear();
	   	this._id_node=null;
	   	this._rootNode=null;
	   	this._container.innerHTML="";
   },
   toString:function(){
   	 return "Tree";
   } 
}

/**
 *树节点对象
 */
Tree.Node=function(fid,id,tree){
    this._doc=tree._doc;
      //所属树对象
    this._tree=tree;
    //节点父节点对象
    this._parent=fid;
    //节点id
    this._id=id;
  	//是否已经加入树中
  	this._inTree=false;
    //节点div
    this._divEL=null;
    //节点名称
    this._name=null;
    //节点图标
    this._icoEL=null;
    //节点下一层子节点对象集合    
    this._sons=new List();
    //节点所处层数,在加入树时赋值(从0开始)
    this._tier=0;
    //节点所处层位置,在加入树时赋值(从1开始)
    this._position=1;
    //前一个兄弟节点
    this._previous=null;
    //后一个兄弟节点
    this._next=null;
    //对应TR对象
    this._trEL=null;
    //对应放子节点DIV对象
    this._sonDivEL=null;
    //节点当前展开或关闭状态
    this._open=false;
    //节点前端部分集合
    this._baseParts=[];
   	//是否加入checkBox
   	this._hasBox=false;
    //节点展开关闭图标IMG元素
   	this._xoEL=null;
   	//节点的名称EL
   	this._nameEL=null;
    //节点前段的checkboxEL
    this._boxEL=null;
    //被check的子节点个数
    this._checkedSonsCount=0;
    //级联选中box的过滤方法
    this._boxOnClickListeners=[];
    //绑定的对象
    this._bindValue=null;
    //缓存操作
    this._cacheOperation=new Map();
} 
Tree.Node.prototype={
	_initPart_:function(target,save){
	 	var cell=this._trEL.insertCell(-1);
        cell.appendChild(target);
        if(save){
       		this._baseParts.push(target);
        }else{
       		target._tdEL=cell;
        } 
	},
	_initBoxEL_:function(){
		 var box=this._doc.createElement("input");
         box.type="checkbox";
         box.style.width="19px";
         box.style.height="16px";
         this._boxEL=box;
         EventManager.addListener(box,"click",this._checkBoxListener_,this);
         this._checked=false;
         this.checkCascade(true);
         this._initPart_(box);
    },
	_initNameEL_:function(){
		 //初始化节点名称  
        var lab=this._doc.createElement("lable");
        lab.innerHTML=this._name;
        lab.title=this._name;
        lab.style.fontSize="12px";
        lab.style.cursor="pointer";
        this._nameEL=lab;
        EventManager.addListener(lab,"onclick",this.select,this);
        EventManager.addListener(lab,"onmouseover",this._nameLableOnmouseover_);
        EventManager.addListener(lab,"onmouseout",this._nameLableOnmouseout_);
        this._initPart_(lab);
        lab._tdEL.style.whiteSpace="nowrap";
	},
	_initIcoEL_:function(){
		var ico=this._doc.createElement("img");
		this._icoEL=ico;
		this._initPart_(ico);
	},
	    //当节点增加或删除下一个兄弟节点监听器,处理子节点的加入
    _hasNextSiblingListener_:function(pos,img){
        this._baseParts[pos].src=img;
        this._sons.each(function(){
        	this._hasNextSiblingListener_(pos,img);
        });
    },
       //执行节点的展开或关闭
    _xoImgOnClick_:function(event){
    	var node=this;
    	if(node._open){
    		node.collapse();
    	}else{
    		node.expand();
    	}
    },//设置xoIMG元素的图片路径,转让L T Lplus...
    _setXOImgsrc_:function(img){
    	this._xoEL.src=Tree.IMG[img];
    	this._xoEL.srcName=img;
    },
    _nameLableOnmouseover_:function(){
        this.style.textDecoration="underline";
    },
    _nameLableOnmouseout_:function(){
        this.style.textDecoration="none";
    },
	_checkBoxCascade_:function(beCheck,up,down){
           var tree=this._tree;
           var box=this._boxEL;
           var father=this._parent;
          //选中状态级联
          if(beCheck){
          	 tree._beCheckedNodes.add(this);
          	if(father){
           	   	father._checkedSonsCount++;
				//向上
				if(up){
					if(father._checkedSonsCount===father._sons.size()){
           				father.check(true,true,false);
           			}	
				}	           	
           	}
          	//向下
          	if(down){
          		this._sons.each(function(){
          			//排除已选中的
          			if(!this._checked){
          				this.check(true,false,true);
          			}
          		});
          	}
          //不选中级联	
          }else{
          	 tree._beCheckedNodes.remove(this);
          	 
          	 if(father){
           	   	father._checkedSonsCount--;
           	   	//向上
				if(up){
					if(father._checked){
						father.check(false,true,false);
					}	
				}
           	 }
             	//向下
          	if(down){
          	
          		this._sons.each(function(){
          			//仅处理已选中的
          			if(this._checked){
          				this.check(false,false,true);
          			}
          		});
          	} 
          }
	},
     //处理级联的box选择
    _checkBoxListener_:function(event){
           var box=this._boxEL;
           var tree=this._tree;
           var beCheck=box.checked;
           this.check(beCheck);
    },
    /**
     * boo 是否显示checkbox
     * cascade 是否级联处理
     * up 是否向上级联
     */
    checkBox:function(boo,cascade,up){
    	if(!this._inTree){
    		this._cacheOperation.put("checkBox",arguments);
    		return;
    	}
    	if(arguments.length===0){
    		return this._boxEL;
    	}
    	var box=this._boxEL;
    	if(boo){
    		if(box){
    			$o(box);
    		}else{
    			this._initBoxEL_();
    			return;
    		}
    	}else{
    		if(box){
    			$x(box);
    		}
    	}
    	if(cascade){
			if(up){
				var father=this._parent;
				if(father){
					father.checkBox(boo,true,true);
				}
			}else{
				var sons=this._sons;
				sons.each(function(){
					this.checkBox(boo,true,false);
				});
			}
    	}
    },
      /**
     * box选中和不选中
     * cascadeUp 向上级联 默认true
     * cascadeDown 向下级联 默认true
     */
    check:function(check,cascadeUp,cascadeDown){
    	if(!this._inTree){
    		this._cacheOperation.put("check",arguments);
    		return;
    	}
    	var box=this._boxEL;
    	if(arguments.length===0){
    		return box.checked;
    	}
		if(!box){
			return;
		}
    	if(this._checked===check){
    		return;
    	}
    	if(!this._tree._multiSelect){
    		var selectNode=this._tree._beCheckedNodes;
    		if(selectNode.size()!==0){
    			selectNode=selectNode.get(0);
    			selectNode._boxEL.checked=false;
    			selectNode._checked=false;
    		}
    		this._tree._beCheckedNodes.clear();
    		if(check){
    			this._boxEL.checked=true;
    			this._checked=true;
    			this._tree._beCheckedNodes.add(this);
	    	}else{
	    		this._boxEL.checked=false;
    			this._checked=false;
	    	}
	    	return;
	    }
    	var father=this._fatehr;
    	box.checked=check;
    	this._checked=check;
    	if(check){
    		cascadeUp=Object.isUndefined(cascadeUp)?box._upCheckedCascade:cascadeUp;
    		cascadeDown=Object.isUndefined(cascadeDown)?box._downCheckedCascade:cascadeDown;
    	}else{
    		cascadeUp=Object.isUndefined(cascadeUp)?box._upUnCheckedCascade:cascadeUp;
    		cascadeDown=Object.isUndefined(cascadeDown)?box._dowmUnCheckedCascade:cascadeDown;
    	}
    	this._checkBoxCascade_(check,cascadeUp,cascadeDown);
    },
    addCheckBoxClickListener:function(method){
    	if(!this._inTree){
    		this._cacheOperation.put("addCheckBoxClickListener",arguments);
    		return;
    	}
    	EventManager.addListener(this._boxEL,"click",method,this);
    },
    id:function(){
       return this._id;
    },
    parent:function(tier){
    	if(arguments.length===0){
    		tier=1;
    	}
    	var parent=this._parent;
    	while(--tier!==0){
    		parent=parent._parent;
    	}
    	return parent;
    },
    checkCascade:function(up1,up0,down1,down0){
    	var box=this._boxEL;
    	if(!box){
    		return;
    	}
    	switch(arguments.length){
    		case 0:return [box._upCheckedCascade,box._upUnCheckedCascade,box._downCheckedCascade,box._dowmUnCheckedCascade];
    		case 1:up1=up0=down1=down0=arguments[0];break;
    		case 2:up0=up1=arguments[0];down1=down0=arguments[1];break;
    		case 4:up1=arguments[0];up0=arguments[1];down1=arguments[2];down0=arguments[3];break;
    		default:return;
    	}
    	box._upCheckedCascade=up1;
    	box._upUnCheckedCascade=up0;
    	box._downCheckedCascade=down1;
    	box._dowmUnCheckedCascade=down0;
    },
    /**
     * 删除节点,cadcade 删除后是否删除下一个兄弟节点(默认false)
     */
	remove:function(cascade){
		if(!this._inTree){
    		this._cacheOperation.put("remove",arguments);
    		return;
    	}
		var tree=this._tree;
		//判断是否是根节点
   		if(this._tier===0){
   			//说明是根节点,销毁树
   			tree.release();
   			return;
   		}
   		//删除子节点
   		//这里从第一子节点开始
   	
   		if(this.hasChild()){
   			this._sons.first().remove(true);
   		}
   		this._sons.each(function(index){
   			this.remove();
   			
   		});
   		var father=this._parent;
		//判断当前删除节点是否被选中
		if(this===tree._beSelectedNode){
			//被选中,转移焦点
			//若有下一兄弟节点
			if(this._next){
   				this._next.select();
   			}else{
   				//说明是最后节点,转移到父节点上
   				father.select();
   			}
		}
		//先改变关联节点表示
		//1 父节点
		//仅在父节点包含唯一此子节点时且次父节点不是根节点
		if(father._sons.size()===1&&father._tier!==0){
          	father._setXOImgsrc_(father._xoEL.srcName.replace("/[plus|minus]/",""));
		}
		//2兄弟节点
		//仅在当前节点是最后一个节点是
		if(!this._next){
			var previous=this._previous;
			//改变上一兄弟
			if(previous){
				previous._setXOImgsrc_(previous._xoEL.srcName.replace("T","L"));
				//改变前端竖线
				//修改其子节点
                var changePosition=previous._baseParts.length;
                var sons=previous._sons;
                var I=Tree.IMG.None;
                for(var index=0,len=previous._sons.size(); index<len; index++) {
                	//改变兄弟节点子节点(如果存在)
                    sons.get(index)._hasNextSiblingListener_(changePosition,I);
                }
			}
		}
		//再删除关系
		//1从父节点中删除
		father._sons.removeByIndex(this._position);
		//2从兄弟节点中删除
		if(this._next){
			this._next._previous=this._previous;
			var next=this._next;
			while(next){
				next._position=next._position-1;
				next=next._next;	
			}
		}
		if(this._previous){
			this._previous._next=this._next;
		}
	
		//3从树中删除
		tree._beCheckedNodes.remove(this);
    	tree._id_node.remove(this._id);
   		//删除元素
   		DOM.removeNode(this._divEL);
   		DOM.removeNode(this._sonDivEL);
   		if(cascade){
   			if(this._next){
   				this._next.remove(true);
   			}	
   		}
   		
	},
	
	isRoot:function(){
    	return this._parent===null;
    },
    hasChild:function(){
       return this._sons.size()!==0;      
    },

    collapse:function(){
      if(!this._inTree){
    		this._cacheOperation.put("collapse",arguments);
    		return;
      }	
      //如果当前是打开的
      if(this._open){
         var img=this._xoEL;
        //说明不是根节点
        if(img){
             this._setXOImgsrc_(img.srcName.replace("min","pl"));
        }
        if(this._sonDivEL){
        	this._sonDivEL.style.display="none";	
        }
        this._open=false;
      }  
      	
    },
    expand:function(){
      if(!this._inTree){
    		this._cacheOperation.put("expand",arguments);
    		return;
      }	
     //如果当前是关闭的
      if(!this._open){
         var img=this._xoEL;
        //说明不是根节点
         if(img){
          	this._setXOImgsrc_(img.srcName.replace("pl","min"));
         }
        if(this._sonDivEL){
        	this._sonDivEL.style.display="";	
        }
        this._open=true;
      }
    },
    //节点选中
    select:function(boo){
        if(!this._inTree){
    		this._cacheOperation.put("select",arguments);
    		return;
        }	
    	if(arguments.length===0){
    		boo=true;
    	}
       	if(boo){
	       	//获取前一个被选中的节点
	        var selected=this._tree._beSelectedNode;
	        if(selected){
	            if(selected!==this){
	        		selected.select(false);
	        	}
	        }
		    //展开节点
	       	this.expand();
	       	//保存被选中节点
	       	this._tree._beSelectedNode=this;
	       	var nameEL=this._nameEL;
        	nameEL.style.backgroundColor="#B8CFE5";	
       	}else{
       		this._tree._beSelectedNode=null;
       		nameEL=this._nameEL;
    		nameEL.style.backgroundColor="";
       	}
    },
    ico:function(img){
    	if(!this._inTree){
    		this._cacheOperation.put("ico",arguments);
    		return;
        }
    	if(arguments.length===0){
    		return this._icoEL;
    	}
       if(img){
        	if(!this._icoEL){
         		this._initIcoEL_();
         	}
         	this._icoEL.src=img;
       }
       return this;
    },
    name:function(name){
    	if(!this._inTree){
    		this._cacheOperation.put("name",arguments);
    		return;
        }
    	if(arguments.length===0){
    		return this._name;
    	}
       if(name){
           this._name=name;
           if(!this._nameEL){
           	  this._initNameEL_();
           }
           this._nameEL.innerHTML=name;
       } 
    },
    addListener:function(type,callback){
    	if(!this._inTree){
    		this._cacheOperation.put("addListener",arguments);
    		return;
        }
    	EventManager.addListener(this._nameEL,type,callback,this);
    },
    bind:function(){
    	if(arguments.length===0){
    		return this._bindValue;
    	}else if(arguments.length===1){
    		return this._bindValue.get(arguments[0]);
    	}else if(arguments.length===2){
    		if(this._bindValue===null){
    			this._bindValue=new Map();
    		}
    		return this._bindValue.put(arguments[0],arguments[1]);
    	}
    },
    toString:function(){
        return "Tree.Node["+this._id+":"+this._name+"("+this._tier+"-"+this._position+")]";
    }
   
}


 
 /**
 * FieldSetTree Object constructor
 */
var FieldSetTree=function(container,doc){
		this._super_(container,doc);
}.extend(Tree);

//FieldSetTree ico constants
FieldSetTree.IMG={
       Collapse:"/MTSearch/images/collapse.gif",
       Expand:"/MTSearch/images/expand.gif"
};
//FieldSetTree error infomation 
FieldSetTree._id_=function(id){
		id+="";
	 if((id).indexOf("fieldsettree_")!=-1){
            return id;
        }
    return "fieldsettree_"+id;
}
    //初始化节点
FieldSetTree.prototype.__createElement__=function(node){
         var doc=this._doc;
         var id=FieldSetTree._id_(node._id);//节点标识符
         var father=node._parent//节点父节点对象
         
         var fieldset=doc.createElement("fieldset");
         fieldset.style.border="0";
         if(!node.isRoot()){
         	fieldset.style.styleFloat="left";
         	fieldset.style.cssFloat="left";
         }
         fieldset.style.margin="0 2px";
         fieldset.style.padding="2px 0";
         fieldset._id=id;
         var legend=doc.createElement("legend");
         fieldset.appendChild(legend);
         var sonDiv=doc.createElement("div");
         sonDiv._id="son_"+id;
         fieldset.appendChild(sonDiv);
         node._fieldsetEL=fieldset;
         node._element=legend;
         node._sonDivEL=sonDiv;
         node=this.__initBasePart__(node);
         //根节点
         if(father===null){
            this._container.appendChild(fieldset);   
         }else{
            father._sonDivEL.appendChild(fieldset);
         }
         node._inTree=true;
         return node;
    }
    //创建前段基本结构
FieldSetTree.prototype.__initBasePart__=function(node){
        var tier=node._tier;//获得节点所处层数
        var father=node._parent;
        //如果父节点存在,显示父节点边框
        if(father){
        	$o(father._xoEL);
			father._fieldsetEL.style.border="1px solid black";
        }
        //当前节点XO默认为折叠,且不显示
        var img=this._doc.createElement("img");
        img.style.display="none";
        img.src=FieldSetTree.IMG.Expand;
        node._initPart_(img);
        node._xoEL=img;
        
        //执行节点的展开关闭方法
        EventManager.addListener(img,"click",node._xoImgOnClick_,node);
        return node;
    }
FieldSetTree.prototype.initRootNode=function(id){
		if(Object.isNone(id)){
            throw new Error(1001,"根节点id未定义");
        }
	    var rootNode=new FieldSetTree.Node(null,id,this);
	    this._rootNode=rootNode;
	    this._tier=0; //设置层为0;
        this._position=1;//设置在当前层中位置为1 
        this._id_node.put(id,rootNode);//在树中记录
        return this.__createElement__(rootNode);
} 
FieldSetTree.prototype.initNode=function(fid,id){
    if(Object.isNone(fid)){
            throw new Error(1003,"父节点id未定义");
        }
        if(Object.isNone(id)){
            throw new Error(1004,"节点id未定义");
        }
        if(this.contains(id)){
           throw new Error(1005,"节点id重复:"+id);           
        }
        var node=new FieldSetTree.Node(fid,id,this);
        //未找到父节点ID,在_noFatherNode集合中找
        var father=this.getNode(fid);
        if(!father){
        	this._cacheOperation=new Map();
        	this._noFatherNode.push(node);
        	return node;
        }
        node._parent=father;
        return this.__initNode__(node); 
} 
FieldSetTree.prototype.toString=function(){
   	 return "FieldSetTree";
} 
/**
 * FieldSetTree
 */
/**
 *树节点对象
 */
FieldSetTree.Node=function(fid,id,tree){
	this._super_(fid,id,tree);    
   //节点div
    this._fieldsetEL=null;
      //对应DOM对象
    this._element=null;
}.extend(Tree.Node)
 

FieldSetTree.Node.prototype._initNameEL_=function(){
		 //初始化节点名称  
        var lab=this._doc.createElement("lable");
        lab.innerHTML=this._name;
        lab.title=this._name;
        lab.style.fontSize="12px";
        this._nameEL=lab;
        EventManager.addListener(lab,"onmouseover",this._nameLableOnmouseover_);
        EventManager.addListener(lab,"onmouseout",this._nameLableOnmouseout_);
        this._initPart_(lab);
}
	
FieldSetTree.Node.prototype._initPart_=function(target){
      this._element.appendChild(target);
      return this;
}
 
FieldSetTree.Node.prototype.collapse=function(){
      //如果当前是打开的
      if(this._open){
           	this._xoEL.src=FieldSetTree.IMG.Collapse;
            this._sonDivEL.style.display="none";
            this._open=false;
      }  
}
FieldSetTree.Node.prototype.expand=function(){
    	 //如果当前是关闭的
      if(!this._open){
      		this._xoEL.src=FieldSetTree.IMG.Expand;
              this._sonDivEL.style.display="";
              this._open=true;
       }  
}
    
FieldSetTree.Node.prototype.toString=function(){
        return "FieldSetTree.Node<"+this._id+":"+this._name+"("+this._tier+"-"+this._position+")>";
}
   
  

 /**
 * DOM
 * 
 */
 var DOM={};
 DOM.removeNode=function(node){
 	if(node&&node.parentNode){
 		node.parentNode.removeChild(node);
 	}	
 }
 
 DOM.getChildByAttribute=function(pNode,tagName,attribute,value){
    
    var arr=$(pNode).getElementsByTagName(tagName);
    
    if(arr.length==1){
        return arr[0];
    }
    
    for(var i=0;i<arr.length;i++){
        if(attribute==="class"){
            if(!arr[i].getAttribute(attribute)){
                attribute="className";
            }    
        }
        if(arr[i].getAttribute(attribute)===value){
            return arr[i];
        }
    }
    return null;
}
DOM.nextSibling=function(e,text){
    e=$(e);
       
    if(text){
            return e.nextSibling;   
    }else{
       if(e.nextSibling.nodeType===3){
            e=e.nextSibling;
        }
       return e.nextSibling;     
    }
    
    
}
DOM.previousSibling=function(e,text){
    e=$(e);
    if(text){
            return e.previousSibling;   
    }else{
       if(e.previousSibling.nodeType===3){
            e=e.previousSibling;
       }
       return e.previousSibling;     
    }
}
/**
 *
 *
 * 动态滚动,需手动在目标对象上下增加div对象
 *
 */
 
var Marquee=function(id,speed){
    this.target=document.getElementById(id);
    this.maxScrollHeight=0;
    this.intervalIndex=0;
    this.scroll=false;
    this._init_();
    this.speed=1;
}
Marquee.prototype={
        _init_:function(){
            
           EventManager.addListener(this.target,"mouseover",this.end,this);
           EventManager.addListener(this.target,"mouseout",this.start,this);
            
           this.start();
        },
        start:function(){
			    if(!this.scroll){
				    var mar=this;
				    this.intervalIndex=setInterval(function(){mar._scroll()},40);
				    this.scroll=true;
			    }
		    },
		end:function(){
			if(this.scroll){
				clearInterval(this.intervalIndex);
				this.scroll=false;
			}
		},
        _scroll:function(){
            if(this.maxScrollHeight<this.target.scrollTop){
                this.maxScrollHeight=this.target.scrollTop;
            }
                  
            this.target.scrollTop+=this.speed;
		    
		    if(this.target.scrollTop===this.maxScrollHeight){
			  this.target.scrollTop=0;
		    }
        }
        
    
}

 /**
  * EVENT
  * 
  */
var EventManager={
	_doEventType_:function(eventType){
		var ieEventType=eventType;
		if(eventType.charAt(0)==='o'&&eventType.charAt(1)==='n'){
			ieEventType=eventType;
			eventType=eventType.substr(2);
		}else{
			ieEventType="on"+eventType;
		}
		return {ie:ieEventType,other:eventType}; 
	},
	deleteListener:function(target,eventType,callback){
		eventType=this._doEventType_(eventType);
		//ie
		var ieEventType=eventType.ie;
		//other
		eventType=eventType.other;
		if(target.detachEvent){
			target.detachEvent(ieEventType,callback.__EventManagerCallBack__);
		}else{
			target.removeEventListener(eventType,callback.__EventManagerCallBack__);
		}
		
	},
	addListener:function(target,eventType,callback,this2who){
		eventType=this._doEventType_(eventType);
		//ie
		var ieEventType=eventType.ie;
		//other
		eventType=eventType.other;
		if(!this2who){
				this2who=target;
		}
		if(target.attachEvent){
				callback.__EventManagerCallBack__=function(){
					callback.call(this2who,window.event);
				};
			target.attachEvent(ieEventType,callback.__EventManagerCallBack__);
		}else{
				callback.__EventManagerCallBack__=function(event){
					callback.call(this2who,event);
				};
			target.addEventListener(eventType,callback.__EventManagerCallBack__,false);
		}
	},
	
    //获得事件源
    getEventSource:function(event){
        event=this.getEvent(event);
        var target=event.srcElement;
        if(!target){
             target=event.target;
        }
        return target;
    },
    //获得事件对象
    getEvent:function(event){
        if(event){
            return event;
        }
         var wins=[];
         wins.push(window.top);
         this.getSonWindows(window.top,wins);
         for(var i=0,len=wins.length; i<len; i++) {
            event=wins[i].event;
         	if(event){
         	    return event;
         	}
         }
   },
   getSonWindows:function(win,wins){
       var sonWins=win.frames;
       for(var i=0,len=sonWins.length; i<len; i++) {
         	wins.push(sonWins[i]);
         	this.getSonWindows(sonWins[i],wins);
       }   
   }
}
/**
 *获取windowLocation URL的queryString
 *
 */
var $QS=function(win){
     win=win||window;
     var result =win.location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+","g")); 
     var qs={};
     if(result != null){
      
         var tempIndex=0;
         var item,key,value;
         for(var i = 0; i < result.length; i++){
              item=result[i].substring(1);
             tempIndex=item.indexOf("=");
              key=item.substring(0,tempIndex);
              value=item.substr(tempIndex+1);
             qs[key]=value;
        }
     }
     
     return qs;
}


var Pagination=function(id,maxIndex,indexChange){
    this.target=document.getElementById(id);
    //上一页
    this.previousPageA=null;
    //下一页
    this.nextPageA=null;
    //上5页
    this.previous5PageA=null;
    //下5页
    this.next5PageA=null;
    //5页
    this.fivePageAs=[];
    //5页页码
    this.fivePageIndexes=[1,2,3,4,5];
    //当前页
    this.currentPageIndex=1;
    //最大页
    this.maxPageIndex=maxIndex;
    //页码改变handle
    this.currentIndexChange=indexChange;
    
    this._init_();
}

Pagination.prototype={
    _init_:function(){
        this._createElements_();
        this.updatePagination(1);
    },
    _createA_:function(text,clickHandle){
        var label=document.createElement("label");
        label.innerHTML=text;
        label.className="A";
        EventManager.addListener(label,"click",clickHandle,this);
       
        return label;
    },
    _createElements_:function(){
        //上一页
        this.previousPageA=this._createA_("上一页",this.previousPage);
        this.target.appendChild(this.previousPageA);
        //5页
        var fivePageA=null;
        for(var i=0;i<5;i++){
            fivePageA=this._createA_(""+(i+1),this.fivePage);
            this.target.appendChild(fivePageA);
            this.fivePageAs.push(fivePageA);
        }
        //下一页
        this.nextPageA=this._createA_("下一页",this.nextPage);
        this.target.appendChild(this.nextPageA);
    },
    reset:function(maxIndex,indexChange){
        //最大页
         this.maxPageIndex=maxIndex;
         if(indexChange){
          //页码改变handle
            this.currentIndexChange=indexChange;
         }
         this.updatePagination(1);
   
    },
    updatePagination:function(index){
        
        if(index<=1){
           this.previousPageA.style.visibility="hidden";
           
        }else{
           this.previousPageA.style.visibility="visible";
        }
        if(index>=this.maxPageIndex){
           
            this.nextPageA.style.visibility="hidden";
        }else{
            this.nextPageA.style.visibility="visible";
        }
        var fivePageA=null;
        
        var cp=document.getElementById("currentPage");
        if(cp){
            cp.id="";
        }
        
        if(index>2&&index+2<=this.maxPageIndex){
            
            this.fivePageIndexes[0]=index-2;
            this.fivePageIndexes[1]=index-1;
            this.fivePageIndexes[2]=index;
            this.fivePageIndexes[3]=index+1;
            this.fivePageIndexes[4]=index+2;  
             
        }
        for(var i=0;i<this.fivePageAs.length;i++){
            fivePageA=this.fivePageAs[i];
            
            if(this.fivePageIndexes[i]===index){
                  fivePageA.id="currentPage";
            }                        
            fivePageA.innerHTML=this.fivePageIndexes[i]+"";
            if(this.maxPageIndex!==1&&this.fivePageIndexes[i]<=this.maxPageIndex){
                fivePageA.style.display="inline";
            }else{
              fivePageA.style.display="none";
            }
        }
        this.currentPageIndex=index;
    },
    
    //上一页
    previousPage:function(e){
        this.gotoPage(this.currentPageIndex-1);
    },
    //下一页
    nextPage:function(e){
       this.gotoPage(this.currentPageIndex+1);
    },
    fivePage:function(e){
        var label=EventManager.getEventSource(e);
        var index=parseInt(label.innerHTML);
        this.gotoPage(index);
    },
    //到指定页
    gotoPage:function(index){
        if(index===this.currentPageIndex){
            return;
        }
        
        this.updatePagination(index);
        if(this.currentIndexChange){
            this.currentIndexChange(this.currentPageIndex);
        }
        
    },
    clear:function(){
        
        
        DOM.removeNode(this.previousPageA);
        DOM.removeNode(this.nextPageA);
        for(var i=0;i<this.fivePageAs.length;i++){
            DOM.removeNode(this.fivePageAs[i]);   
        }
             //页码改变handle
        this.currentIndexChange=null;
    }
    
}


