// JavaScript Document
	/*
		创建弹出菜单对象
		sender 触发对象的ID
		source popupDiv的ID
		mode 模式，是单击click还是鼠标经过mouseover时弹出
		程序：追梦客
		QQ:16991200
	*/
	function DMKPopupDiv(senderId,sourceId,mode)
	{
		this.sender = this.GetObject(senderId);
		this.source = this.GetObject(sourceId);
		this.source.style.position="absolute";
		this.source.style.zIndex="99";
		this.Disabled = false;
		this.__timeOut__ = null;
		DMKPopupDiv.prototype.MaskDepth += 1;
		//alert(DMKPopupDiv.prototype.MaskDepth);
		document.write("<iframe frameborder=\"0\" style=\"position:absolute;z-index:10;left:0px;top:0px;\" id=\"ifm_"+DMKPopupDiv.prototype.MaskDepth+"\"></iframe>")
		this.mask = this.GetObject("ifm_"+DMKPopupDiv.prototype.MaskDepth);
		
		this.PopupHidden();//事先隐藏
		this.mode = "click";
		if(mode)
		{
			this.mode = mode.toLowerCase();
		}
		this.Point = function (iX, iY){
			this.x = iX;
			this.y = iY;
		}
		this.sender.Popup = this;
		this.source.Popup = this;
		try{
			switch(this.mode)
			{
				case "over":
					this.sender.onmouseover = function (evt)
					{
						this.Popup.PopupShow(evt);
						if(this.Popup.__timeOut__!=null)
						{
							clearTimeout(this.Popup.__timeOut__);
						}
					}
					this.sender.onmouseout = function (evt)
					{
						var _this = this;
						var _func = function(){
							_this.Popup.PopupHidden(evt)
						};
						_this.Popup.__timeOut__ = setTimeout(_func,500);						
					}
					this.source.onmouseover = function (evt)
					{
						if(this.Popup.__timeOut__!=null)
						{
							clearTimeout(this.Popup.__timeOut__);
						}
					}
					this.source.onmouseout = function (evt)
					{
						var _this = this;
						var _func = function(){
							_this.Popup.PopupHidden(evt)
						};
						_this.Popup.__timeOut__ = setTimeout(_func,500);				
					}
					break;
				default:
					this.sender.onclick = function (evt)
					{

						this.Popup.PopupShow(evt);
					}
					this.source.onclick = function (evt)
					{
						var _event = evt?evt:event;
						_event.cancelBubble = true;
					}										

					document.onclick = function (evt)
					{
						if(window.__CurrentPopupDiv__)
							window.__CurrentPopupDiv__.PopupHidden(evt);
					}
					break;
			}
		}catch(ex)
		{
			
		}
	}
	DMKPopupDiv.prototype.GetObject = function (id)
	{
		if(document.getElementById)
		{
			return document.getElementById(id);
		}
		if(document.all)
		{
			return document.all[id]	;
		}
		if(document.layers)
		{
			return document.layers[id];
		}
	}

	DMKPopupDiv.prototype.PopupShow = function (evt)
	{
	    if(!this.Disabled)
	    {
		    var _event = evt?evt:window.event;
		    _event.cancelBubble = true;
		    if(window.__CurrentPopupDiv__==this)
		    {
			    return false;
		    }
		    if(window.__CurrentPopupDiv__)
		    {
			    window.__CurrentPopupDiv__.PopupHidden();
		    }
		    window.__CurrentPopupDiv__ = this;
		    var pt = this.GetPopupPoint();

		    this.source.style.top = pt.y+"px";
		    this.source.style.left = pt.x+"px";
		    this.mask.style.top = pt.y+"px";
		    this.mask.style.left = pt.x+"px";

		    this.mask.style.width = this.source.offsetWidth+"px";
		    this.mask.style.height = this.source.offsetHeight+"px";
    		
		    this.source.style.visibility = "visible";
		    this.mask.style.visibility = "visible";
		  }
	}
	DMKPopupDiv.prototype.PopupHidden = function (evt)
	{
		window.__CurrentPopupDiv__ = null;
		this.source.style.visibility = "hidden";
		this.mask.style.visibility = "hidden";
	}
	
	
	DMKPopupDiv.prototype.GetPopupPoint = function (){
		var tempObject = this.sender;
		var pt = new this.Point(0,0);
		do{
			pt.x += tempObject.offsetLeft;
			pt.y += tempObject.offsetTop;
			if(!tempObject.offsetParent) return false; //for NS
			tempObject = tempObject.offsetParent;
		}
		while(tempObject.tagName.toLowerCase()!="body");
		
		if(pt.x+this.source.offsetWidth>document.body.clientWidth)
		{
		    pt.x -= pt.x+this.source.offsetWidth-document.body.clientWidth;
		}
		if(pt.x<=0)
		{
		    pt.x=0;
		}
		if(pt.y+this.source.offsetHeight>document.body.clientHeight)
		{
		    pt.y-=this.source.offsetHeight;
		}
		else
		{
		    pt.y += this.sender.offsetHeight;
		}
		pt.y -= 1;
		if(pt.y<=0)
		{
		    pt.y=0;
		}
		return pt;
	}
	DMKPopupDiv.prototype.MaskDepth = 0;
