/// 载入页面所有事件
//当属性rel值为"rel"时为mouseover事件，其它为click事件
//兼容firefox
try
{
	HTMLElement.prototype.__defineGetter__("children",
	function () {
	var returnValue = new Object();
	var number = 0;
	for (var i=0; i<this.childNodes.length; i++) {
	if (this.childNodes[i].nodeType == 1) {
	returnValue[number] = this.childNodes[i];
	number++;
	}
	}
	returnValue.length = number;
	return returnValue;
	}
	);
}
catch(e){}


function getEvent(){     //同时兼容ie和ff的写法
         if(document.all)    return window.event;        
         func=getEvent.caller;            
         while(func!=null){    
             var arg0=func.arguments[0];
             if(arg0){
                 if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
                     || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){    
                     return arg0;
                 }
             }
             func=func.caller;
         }
         return null;
 }

var value=[];
function getrunelement(obj)
{
    try
    {
	    if(obj.children.length>0)
	    {
		    for(var i=0;i<obj.children.length;i++)
		    {
			    var o=obj.children[i];
    			
			    if(o.getAttribute("rel")!=null&&o.getAttribute("rel")!="")
			    {
				    value[value.length]=o;
			    }
			    getrunelement(o);
		    }
		 }
	}
	catch(e){}
}
function RunEventFunction()
{
    {
        var event=arguments[0]||window.event;
        var obj=event.srcElement||event.target;
        if(obj.getAttribute("rev")!=null&&obj.getAttribute("rev")!="")
        {
            try
            {
                eval(OperatorObject+"."+obj.getAttribute("rev")+"()"); 
            }
            catch(e)
            {
                try
				{
					eval(obj.getAttribute("rev"))();
				}
				catch (e)
				{
				}
            }
        }
        else
        {
            runAjax(obj.getAttribute("rel"));
        }
    }
}
//加载所有事件
function LoadAllEvent()
{
    var elements=getRunElement();
    var obj=null;
    for(var i=0;i<elements.length;i++)
    {
        obj=elements[i];
        if(obj.tagName!="LINK")
        {
             if(obj.getAttribute("rel")!="rel")
             {
                if (window.attachEvent)
                {
                    obj.attachEvent("onclick",RunEventFunction); 
                }
                if (window.addEventListener)
                {
                    obj.addEventListener("click",RunEventFunction,false);
                } 
             }
             else
             {
                if (window.attachEvent)
                {
                    obj.attachEvent("onmouseover",RunEventFunction); 
                }
                if (window.addEventListener)
                {
                    obj.addEventListener("mouseover",RunEventFunction,false);
                } 
             }
        }
    }
}
//去除所有事件
function DeleteAllEvent()
{
    var elements=getRunElement();
    var obj=null;
    for(var i=0;i<elements.length;i++)
    {
        obj=elements[i];
        if(obj.tagName!="LINK")
        {
             if(obj.getAttribute("rel")!="rel")
             {
                if (window.attachEvent)
                {
                    obj.detachEvent("onclick",RunEventFunction); 
                }
                if (window.addEventListener)
                {
                    obj.removeEventListener("click",RunEventFunction,false);
                } 
             }
             else
             {
                if (window.attachEvent)
                {
                    obj.detachEvent("onmouseover",RunEventFunction); 
                }
                if (window.addEventListener)
                {
                    obj.removeEventListener("mouseover",RunEventFunction,false);
                } 
             }
        }
    } 
}
//取得页面所有有事件的对象
function getRunElement()
{
    value=[];
    getrunelement(document.getElementsByTagName("body")[0]);
    return value;
}
//运行ajax
function runAjax(url)
{
    var  options={
        method:'get',
        parameters:"",
        onComplete:
            function(transport)
	        {
				var returnvalue=transport.responseText;
				eval(returnvalue);
	        } 
	}
	new Ajax.Request(url,options);
}



var eventLoaded=false;

if(!eventLoaded)
{
    if (window.attachEvent)
    {
        window.attachEvent("onload",LoadAllEvent); 
    }
    if (window.addEventListener)
    {
        window.addEventListener("load",LoadAllEvent,false);
    } 
    eventLoaded=true;
}

EventLoad={};
//重新加载事件
EventLoad.Reload=function()
{
    DeleteAllEvent();
    LoadAllEvent();
}

