if (window.attachEvent){
	//页面关闭时清理事件
	var clearElementProps = ['data','onmouseover','onmouseout','onmousedown','onmouseup','ondblclick','onclick','onselectstart','oncontextmenu','onchange','onpropertychange'];
	//清除单个对象事件引用
	function cleanUpEvent(obj){
        for(var c = clearElementProps.length;c--;){
			try{
				obj[clearElementProps[c]] = null;
				obj.removeAttribute([clearElementProps[c]]);
			}catch(e){}
		}
	}
	//清除输入对象子对象事件引用
    function cleanUpChildEvent(obj){
        var el;
		for(var d = obj.getElementsByTagName('*').length;d--;){
			el = obj.getElementsByTagName('*')[d];
			cleanUpEvent(el);
		}
		el=null;
	}
}
/* 
 * by Keith Gaughan
 * This allows event handlers to be registered unobtrusively, and cleans
 * them up on unload to prevent memory leaks.
 *
 * Copyright (c) Keith Gaughan, 2005.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * (CPL) which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/cpl.php
 *
 * This software is covered by a modified version of the Common Public License
 * (CPL), where Keith Gaughan is the Agreement Steward, and the licensing
 * agreement is covered by the laws of the Republic of Ireland.
  */ 

//  For implementations that don't include the push() methods for arrays. 
if (!Array.prototype.push){
    Array.prototype.push = function(elem){
        this[this.length] = elem;
    }
}
var  EventManager  =  {
    _registry:null,
    Initialise:function(){
         if  (this._registry  == null) {
             this._registry = [];
             //  Register the cleanup handler on page unload. 
             EventManager.Add(window,"onunload",function(){
				 EventManager.CleanUp();
				 if (window.attachEvent){
					 var el;
					 for(var d = document.all.length;d--;){
						el = document.all[d];
						cleanUpEvent(el);
					 }
					 el=null;
				 }
			 });
        }
    },
     /* *
     * Registers an event and handler with the manager.
     *
     * @param  obj         Object handler will be attached to.
     * @param  type        Name of event handler responds to.
     * @param  fn          Handler function.
     * @param  useCapture  Use event capture. False by default.
     *                     If you don't understand this, ignore it.
     *
     * @return True if handler registered, else false.
      */ 
     Add:function(obj, type, fn, useCapture) {
        this.Initialise();
         //  If a string was passed in, it's an id. 
        if(typeof(obj) == "string") {
            obj = document.getElementById(obj);
        }
        if(obj == null || fn  == null ) {
             return   false ;
        }
         //  Mozilla/W3C listeners? 
        if (obj.addEventListener) {
            obj.addEventListener(type, fn, useCapture);
             this._registry.push({obj: obj, type: type, fn: fn,useCapture: useCapture});
             return true ;
        }
         //  IE-style listeners? 
        if(obj.attachEvent&& obj.attachEvent(type, fn)) {
             this._registry.push({obj: obj, type: type,fn:fn,useCapture:false});
             return true;
        }
        return false;
    },
     /* *
     * Cleans up all the registered event handlers.
      */ 
   CleanUp:function() {
		  if(!EventManager._registry) return;
         for  (var  i  =   0 ; i  <  EventManager._registry.length; i ++ ) {
             with(EventManager._registry[i]) {
                 //  Mozilla/W3C listeners? 
                if(obj.removeEventListener) {
                    obj.removeEventListener(type, fn, useCapture);
                }else if(obj.detachEvent) { //  IE-style listeners? 
                    obj.detachEvent(type, fn);
                }
            }
        }
         //  Kill off the registry itself to get rid of the last remaining 
         //  references. 
        EventManager._registry = null ;
    },
	CleanUpObject:function(o) {
		 if(!EventManager._registry) return;
		 var temp=[];
		// alert(EventManager._registry.length);
         for  (var  i  =   0 ; i  <  EventManager._registry.length; i ++ ) {
             with(EventManager._registry[i]) {
                 //  Mozilla/W3C listeners? 
				 if(obj==o){
					if(obj.removeEventListener) {
						obj.removeEventListener(type, fn, useCapture);
					}else if(obj.detachEvent) { //  IE-style listeners? 
						obj.detachEvent(type, fn);
						//alert(o.tagName+'||'+fn);
					}
					//EventManager._registry[i]=null;
                    //delete EventManager._registry[i];
				 }else{
					 temp.push(EventManager._registry[i]);
				 }
            }
        }
		EventManager._registry=temp;
		temp=null;
    }
}; 
var removeUtil={
	remove:function(obj){
	//	alert(1);
		while (obj && obj.firstChild){
			arguments.callee.call(this,obj.firstChild);
		}
		if(obj){
			EventManager.CleanUpObject(obj);
			if(window.attachEvent){
				cleanUpEvent(obj);
			}
			this.removeNode(obj);
		}
	},
	removeNode :function(){   
		var d;   
		return function(n){   
			if(n && n.tagName != 'BODY'){   
				d = d || document.createElement('div');   
				d.appendChild(n);   
				d.innerHTML = '';   
			}   
		}   
	}()
}