/* from EventListener.js	 */
function EventListener()
{
	EventListener.prototype.eventObjects=new Array();
	EventListener.prototype.resizeObj=new Array();//用来保存监听了resize事件的对象.
	EventListener.prototype.oldWinWidth=getWindowWidth();
	EventListener.prototype.oldWinHeight=getWindowHeight();
	this.init=function()
	{
		try
		{
			document.onhelp=EventListener.prototype.onHelp;
			document.onselectstart=EventListener.prototype.onSelectStart;
			document.oncontextmenu=EventListener.prototype.onContextMenu;
			document.onkeydown=EventListener.prototype.onKeyDown;
			//添加了resize事件
			window.onresize=EventListener.prototype.onResize;
		}
		catch(e)
		{
			e.description="EventListener.init()::"+e.description;
			throw(e);
		}
	}
	/**
	*调用在resizeObj中各个对象的onResize(nw,nh,ow,oh)方法
	*其中(nw,nh)分别对应窗口改变大小后的宽度和高度
	*(ow,oh)分别对应窗口改变前的大小前的宽度和高度
	*/
	EventListener.prototype.onResize=function(ent){
		/*
		if(!ent){
			ent=window.event;
		}
		ent.cancelBubble=true;
		*/
		
		//begin zhao
		//使事件的处理兼容IE与DOM2 
		ent = ent ? ent : (window.event ? window.event : null);
	  if (ent.stopPropagation) 
	  {
		  ent.stopPropagation( ); 
    }
    else
    { 
  	  ent.cancelBubble = true;                     
	  }	
		//end zhao
		
		var nw=getWindowWidth();
		var nh=getWindowHeight();
		var ow=EventListener.prototype.oldWinWidth;
		var oh=EventListener.prototype.oldWinHeight;
		for(var i=0;i<EventListener.prototype.resizeObj.length;i++){
			EventListener.prototype.resizeObj[i].onResize(nw,nh,ow,oh);
		}
		EventListener.prototype.oldWinWidth=nw;
		EventListener.prototype.oldWinHeight=nh;
	}
	EventListener.prototype.addResizeListener=function(eventObject){
		try
		{
			if( typeof eventObject!="object" )
			{
				throw( new MapException() );
			}
		}
		catch(e)
		{
			e.name="TypeError";
			e.message="无效参数，该参数为非Object类型。";
			e.description=this.getClassName()+".add()::"+e.message;
			throw(e);
		}
		for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
		{
			if(eventObject==EventListener.prototype.eventObjects[i])
			{
				return;
			}
		}
		EventListener.prototype.resizeObj[EventListener.prototype.resizeObj.length]=eventObject;
	}
	EventListener.prototype.onMouseWheel=function(ent){
		//begin zhao
		//使事件的处理兼容IE与DOM2 
		ent = ent ? ent : (window.event ? window.event : null);
	  if (ent.stopPropagation) 
	  {
		  ent.stopPropagation( ); 
    }
    else
    { 
  	  ent.cancelBubble = true;                     
	  }	
		/*
		if(!ent)
		{
			ent=window.event;
		}
		*/
		//end zhao
		
		var bF=true;
		for(var i=0;i<EventListener.prototype.eventObjects.length;i++){
			 if(!EventListener.prototype.eventObjects[i].onMouseWheel(ent)){
			 		bF=false;
				}
		}
		return bF;
	}
	
	EventListener.prototype.onMouseDown=function(ent)
	{
		if(!ent)
		{
			ent=window.event;
		}
		
		try
		{
			for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
			{
				EventListener.prototype.eventObjects[i].onMouseDown(ent);
			}
		}
		catch(e)
		{
			e.description="EventListener.prototype.onMouseDown()::"+e.description;
			alert(e.description);
		}
		
		  if(ent.stopPropagation)   
      {
    	  ent.stopPropagation();
      }
      else 
      {
    	  ent.cancelBubble=true;
      }
    
      if(ent.preventDefault)  
      {
    	  ent.preventDefault();
      }
      else 
      {
    	  ent.returnValue=false;
      }
	}
	EventListener.prototype.onMouseMove=function(ent)
	{
		if(!ent)
		{
			ent=window.event;
		}
		
		try
		{
			for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
			{
				EventListener.prototype.eventObjects[i].onMouseMove(ent);
			}
		}
		catch(e)
		{
			e.description="EventListener.prototype.onMouseMove()::"+e.description;
			alert(e.description);
		}
		
		  if(ent.stopPropagation)   
      {
    	  ent.stopPropagation();
      }
      else 
      {
    	  ent.cancelBubble=true;
      }
    
      if(ent.preventDefault)  
      {
    	  ent.preventDefault();
      }
      else 
      {
    	  ent.returnValue=false;
      }
	}
	EventListener.prototype.onMouseUp=function(ent)
	{
		if(!ent)
		{
			ent=window.event;
		}
		
		try
		{
			for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
			{
				EventListener.prototype.eventObjects[i].onMouseUp(ent);
			}
		}
		catch(e)
		{
			e.description="EventListener.prototype.onMouseUp()::"+e.description;
			alert(e.description);
		}
		
		  if(ent.stopPropagation)   
      {
    	  ent.stopPropagation();
      }
      else 
      {
    	  ent.cancelBubble=true;
      }
    
      if(ent.preventDefault)  
      {
    	  ent.preventDefault();
      }
      else 
      {
    	  ent.returnValue=false;
      }
	}
	
	EventListener.prototype.onClick=function(ent)
	{
		//begin zhao
		//使事件的处理兼容IE与DOM2 
		ent = ent ? ent : (window.event ? window.event : null);
	  if (ent.stopPropagation) 
	  {
		  ent.stopPropagation( ); 
    }
    else
    { 
  	  ent.cancelBubble = true;                     
	  }	
		/*
		if(!ent)
		{
			ent=window.event;
		}
		*/
		//end zhao
		try
		{
			for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
			{
				EventListener.prototype.eventObjects[i].onClick(ent);
			}
		}
		catch(e)
		{
			e.description="EventListener.prototype.onClick()::"+e.description;
			alert(e.description);
		}
	}
	
	EventListener.prototype.onDoubleClick=function(ent)
	{
		//begin zhao
		//使事件的处理兼容IE与DOM2 
		ent = ent ? ent : (window.event ? window.event : null);
	  if (ent.stopPropagation) 
	  {
		  ent.stopPropagation( ); 
    }
    else
    { 
  	  ent.cancelBubble = true;                     
	  }	
		/*
		if(!ent)
		{
			ent=window.event;
		}
		*/
		//end zhao
		try
		{
			for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
			{
				EventListener.prototype.eventObjects[i].onDoubleClick(ent);
			}
		}
		catch(e)
		{
			e.description="EventListener.prototype.onDoubleClick()::"+e.description;
			alert(e.description);
		}
	}
	EventListener.prototype.onMouseOut=function(ent)
	{
		//begin zhao
		//使事件的处理兼容IE与DOM2 
		ent = ent ? ent : (window.event ? window.event : null);
	  if (ent.stopPropagation) 
	  {
		  ent.stopPropagation( ); 
    }
    else
    { 
  	  ent.cancelBubble = true;                     
	  }	
		/*
		if(!ent)
		{
			ent=window.event;
		}
		*/
		//end zhao
		try
		{
			for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
			{
				EventListener.prototype.eventObjects[i].onMouseOut(ent);
			}
		}
		catch(e)
		{
			e.description="EventListener.prototype.onMouseOut()::"+e.description;
			alert(e.description);
		}
	}
	EventListener.prototype.onHelp=function()
	{
		try
		{
			return false;
		}
		catch(e)
		{
			e.description="EventListener.prototype.onHelp()::"+e.description;
			alert(e.description);
		}
	}
	EventListener.prototype.onSelectStart=function(ent)
	{
	}
	EventListener.prototype.onContextMenu=function(ent)
	{
		if(!ent){
			ent=window.event;
		}
		try
		{
			for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
			{
				EventListener.prototype.eventObjects[i].onContextMenu(ent);
			}
		}
		catch(e)
		{
			e.description="EventListener.prototype.onContextMenu()::"+e.description;
			alert(e.description);
		}
	}
	EventListener.prototype.onKeyDown=function(ent)
	{
		if(!ent){
			ent=window.event;
		}
			if( (ent.keyCode==121&&ent.shiftKey)||(ent.keyCode==78&&ent.ctrlKey) )
			{
				ent.keyCode=0;
				return false;
			}
			for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
			{
				return EventListener.prototype.eventObjects[i].onKeyDown(ent);
			}
		
	}
	EventListener.prototype.add=function(eventObject)
	{
		try
		{
			if( typeof eventObject!="object" )
			{
				throw( new MapException() );
			}
		}
		catch(e)
		{
			e.name="TypeError";
			e.message="无效参数，该参数为非Object类型。";
			e.description=this.getClassName()+".add()::"+e.message;
			throw(e);
		}
		for(var i=0;i<EventListener.prototype.eventObjects.length;i++)
		{
			if(eventObject==EventListener.prototype.eventObjects[i])
			{
				return;
			}
		}
		EventListener.prototype.eventObjects[EventListener.prototype.eventObjects.length]=eventObject;
	}
	EventListener.prototype.removeOnResize=function(eventObject)
	{
		
		try
		{
			if( typeof eventObject!="object" )
			{
				throw( new MapException() );
			}
		}
		catch(e)
		{
			e.name="TypeError";
			e.message="无效参数，该参数为非Object类型。";
			e.description=this.getClassName()+".remove()::"+e.message;
			throw(e);
		}
		var eventObjects=EventListener.prototype.resizeObj;
		for(var i=0;i<eventObjects.length;i++)
		{
			if(eventObject==eventObjects[i])
			{
				eventObjects[i]=eventObjects[eventObjects.length-1];
				eventObjects.length-=1;
				break;
			}
		}
	}
	EventListener.prototype.remove=function(eventObject)
	{
		try
		{
			if( typeof eventObject!="object" )
			{
				throw( new MapException() );
			}
		}
		catch(e)
		{
			e.name="TypeError";
			e.message="无效参数，该参数为非Object类型。";
			e.description=this.getClassName()+".remove()::"+e.message;
			throw(e);
		}
		var eventObjects=EventListener.prototype.eventObjects;
		for(var i=0;i<eventObjects.length;i++)
		{
			if(eventObject==eventObjects[i])
			{
				eventObjects[i]=eventObjects[eventObjects.length-1];
				eventObjects.length-=1;
				break;
			}
		}
	}
	EventListener.prototype.captureEvent=function()
	{
		try
		{
			/*
			document.onmousemove=EventListener.prototype.onMouseMove;
			document.onmousedown=EventListener.prototype.onMouseDown;
			document.onmouseup=EventListener.prototype.onMouseUp;
			document.onclick=EventListener.prototype.onClick;
			document.ondblclick=EventListener.prototype.onDoubleClick;
			document.onmousewheel=EventListener.prototype.onMouseWheel;
			document.onmouseout=EventListener.prototype.onMouseOut;
			if(window.addEventListener&&navigator.product&&navigator.product=="Gecko"){
				document.addEventListener("DOMMouseScroll",EventListener.prototype.onMouseWheel,false);
			}			
			*/
			
			//begin zhao 将事件绑定应用于DOM2 IE5和IE4上 
			if(document.attachEvent)
			{
				document.getElementById("span_mapAreaPositionContainer").attachEvent("onmousedown", EventListener.prototype.onMouseDown);
				document.getElementById("span_mapAreaPositionContainer").attachEvent("onmousemove", EventListener.prototype.onMouseMove);
				document.getElementById("span_mapAreaPositionContainer").attachEvent("onmouseup",   EventListener.prototype.onMouseUp);
				document.getElementById("span_mapAreaPositionContainer").attachEvent("onclick",     EventListener.prototype.onClick);
				document.getElementById("span_mapAreaPositionContainer").attachEvent("ondblclick",  EventListener.prototype.onDoubleClick);
				document.getElementById("span_mapAreaPositionContainer").attachEvent("onmousewheel",EventListener.prototype.onMouseWheel); 
				document.getElementById("span_mapAreaPositionContainer").attachEvent("onmouseout",EventListener.prototype.onMouseOut); 
				
				document.getElementById("barMult").attachEvent("onmousemove", EventListener.prototype.onMouseMove);
				document.getElementById("barMult").attachEvent("onclick",     EventListener.prototype.onClick);
				document.getElementById("barMult").attachEvent("ondblclick",  EventListener.prototype.onDoubleClick); 
			}
			else if(document.addEventListener)
			{ 
				document.getElementById("span_mapAreaPositionContainer").addEventListener("mousedown",EventListener.prototype.onMouseDown,   true);
				document.getElementById("span_mapAreaPositionContainer").addEventListener("mousemove",EventListener.prototype.onMouseMove,   true);
				document.getElementById("span_mapAreaPositionContainer").addEventListener("mouseup",  EventListener.prototype.onMouseUp,     true);
				document.getElementById("span_mapAreaPositionContainer").addEventListener("click",    EventListener.prototype.onClick,       true);
				document.getElementById("span_mapAreaPositionContainer").addEventListener("dblclick", EventListener.prototype.onDoubleClick, true); 
				document.getElementById("span_mapAreaPositionContainer").addEventListener("DOMMouseScroll",EventListener.prototype.onMouseWheel,true);
				document.getElementById("span_mapAreaPositionContainer").addEventListener("onmouseout",EventListener.prototype.onMouseOut,true);
			}
			else
			{
				document.getElementById("span_mapAreaPositionContainer").onmousemove =EventListener.prototype.onMouseMove;
				document.getElementById("span_mapAreaPositionContainer").onmousedown =EventListener.prototype.onMouseDown;
				document.getElementById("span_mapAreaPositionContainer").onmouseup   =EventListener.prototype.onMouseUp;
				document.getElementById("span_mapAreaPositionContainer").onclick     =EventListener.prototype.onClick;
				document.getElementById("span_mapAreaPositionContainer").ondblclick  =EventListener.prototype.onDoubleClick;
				document.getElementById("span_mapAreaPositionContainer").onmousewheel=EventListener.prototype.onMouseWheel;
				document.getElementById("span_mapAreaPositionContainer").onmouseout  =EventListener.prototype.onMouseOut;
			  if(window.addEventListener&&navigator.product&&navigator.product=="Gecko")
			  {
				   document.addEventListener("DOMMouseScroll",EventListener.prototype.onMouseWheel,false);
			  }
			}
			//end zhao 
		}
		catch(e)
		{
			e.description="EventListener.prototype.captureEvent()::"+e.description;
			throw(e);
		}
	}
	EventListener.prototype.eventNull=function()
	{
		document.onmousemove="";
		document.onmousedown="";
		document.onmouseup="";
		document.onclick="";
		document.ondblclick="";
	}
	this.init();
	
}

function getWindowWidth(){
	var width=0;
	if(typeof(window.innerWidth)=='number'){
		width=window.innerWidth;
	}
	else if(document.documentElement&&document.documentElement.clientWidth){
		width=document.documentElement.clientWidth;
	}
	else if(document.body&&document.body.clientWidth){
		width=document.body.clientWidth;
	}
	if(!width||width<100){
		width=100;
	}
	return width;
}


function getWindowHeight(){
	var height=0;
	if(typeof(window.innerHeight)=='number'){
		height=window.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight){
		height=document.documentElement.clientHeight;
	}
	else if(document.body&&document.body.clientHeight){
		height=document.body.clientHeight;
	}
	if(!height||height<100){
		height=100;
	}
	return height;
}

new EventListener();
