// ModalWindow Client Script Library
// Alfa-XP, Michael Isipciuc, 2007.
//

Type.registerNamespace("FM");
// (RUN ONLY FROM TOP PARENT WINDOW CONTEXT)
FM.ModalWindow= function() {
		var w= 400; var h= 300;
		this.width= w;
		this.height= h;
		this.headerHeight= 26;
		this._fullScreen= false;
		this.commandBarMode= 'frame';
		this.simpleHide= false;

		this._content= document.createElement("DIV");
		with (this._content.style) {
			display= "none"; position= "absolute"; left= "0px"; top= "0px"; zIndex= 1001;
			width= w + "px"; height= h + "px";
		}
		document.body.insertBefore(this._content, document.body.firstChild);

		var ip= fmCommonPath + "Images/Window/";
		var sWnd= "<table style='width:100%;height:100%;' cellspacing='0' cellpadding='0'>";
		sWnd+= "<tr><td><table width='100%' cellpadding='0' cellspacing='0' style='-moz-user-select:none;'><tr><td style='background-image:url("+ip+"headerL.gif);width:5px;height:26px'></td><td style='font-weight: bold; font-size: 10pt; background-image:url("+ip+"headerBg.gif);cursor: move; font-family: Arial CE, Arial; height: 26px'><img src='"+ip+"ico_top.gif' align='absmiddle'>&nbsp;<label id='_HeaderText'>" + fmres("wnd_loading", "Window content is loading...") + "</label></td><td style='padding-right: 5px;background-image:url("+ip+"headerBg.gif);height:26px;'>&nbsp;</td><td align='right' style='background-image:url("+ip+"headerBg.gif);height:26px;width:" + ((window._help) ? "119" : "95") + "px;' valign='top'><img src='"+ip+"btn_!.gif' alt='Should you experience any problems with this form - &#10;Please contact us!' border='0' height='18' width='27' style='margin-top:1px;'/>" + ((window._help) ? "<img src='"+ip+"btn_help.gif' alt='Help' border='0' height='18' width='24' style='margin-top:1px;'/>" : "") + "<img src='"+ip+"btn_max.gif' alt='Maximize' border='0' height='18' width='24' style='margin-top:1px;'/><img src='"+ip+"btn_close.gif' alt='Close' border='0' height='18' width='44' style='margin-top:1px;'/></td><td style='background-image:url("+ip+"headerR.gif);width:5px;height:26px'></td></tr></table></td></tr>";
		var innerWnd= "<iframe style='width:100%;height:100%;background-color:#FFF;' frameborder='0' scrolling='no'></iframe>";
		sWnd+= "<tr style='height:100%'><td style='border-right:#3A434B 1px solid;padding-right:5px;padding-left:5px;border-left:#3A434B 1px solid;height:100%;background-color:#c0d7eb;'>" + innerWnd + "</td></tr>";
		sWnd+= "<tr><td><table width='100%' cellpadding='0' cellspacing='0'><tr><td style='background-image:url("+ip+"bottomL.gif);width:6px;height:7px'></td><td style='background-image:url("+ip+"bottomBg.gif);height:7px'><img src='"+ip+"pixel.gif' border='0' /></td><td style='background-image:url("+ip+"bottomR.gif);width:6px;height:7px'></td></tr></table></td></tr>";
		sWnd+= "</table>";

		this._content.innerHTML= sWnd;
		this._wndBody= this._content.firstChild.rows[1].cells[0].firstChild;

		this._header= this._content.firstChild.rows[0].cells[0].firstChild.rows[0].cells[1].lastChild;
		this._content_document= this._wndBody.contentWindow.document;
		this._contentBody= null;
		this._footer= null;
		this._wndHeader= this._content.firstChild.rows[0].cells[0].firstChild.rows[0].cells[1];
				
		this._tdButtons= this._content.firstChild.rows[0].cells[0].firstChild.rows[0].cells[3];
		this._tdResize= this._content.firstChild.rows[2].cells[0].firstChild.rows[0].cells[2];
		this._btnIco= this._content.firstChild.rows[0].cells[0].firstChild.rows[0].cells[1].firstChild;

		/*
		if (FM.ModalWindow._bg == null) {
			FM.ModalWindow._bg= document.createElement("DIV");
			FM.ModalWindow._bg.className= 'modalWnd_Background';
			with (FM.ModalWindow._bg.style) {
				display= "none"; position= "absolute"; left= "0px"; top= "0px";
				width="100%"; height= "100%";
			}
			document.body.insertBefore(FM.ModalWindow._bg, document.body.firstChild);
		}*/

		//this._resizeHandler= Function.createDelegate(this, this.setPosition);
		//this._scrollHandler= Function.createDelegate(this, this.setPosition);
		this._closeHandler= Function.createDelegate(this, this.Hide);
		this._moveHandler= Function.createDelegate(this, this._MoveStart);
		this._resizeWndHandler= Function.createDelegate(this, this._ResizeWnd);
		this._keyHandler= Function.createDelegate(this, this.keyPress);
		this._resizeStartH= Function.createDelegate(this, this._ResizeStart);
		this._showInfoH= Function.createDelegate(this, this._ShowInfo);
		
		this._windowLoadedHandler= Function.createDelegate(this, this.onWindowLoaded);
		
		//
		this.onBeforeClose= null;
		this.refreshParent= false;
		
		this.innerObject= null;
		this.Visibled= false;
		this.PreventUnregister= false;
		this._isCustom= false;
		
		this.ID= FM.ModalWindow.getUniqueID();
}

FM.ModalWindow.prototype= {
  
  dispose : function() {
		
    this._detachPopup();

		//this._resizeHandler= null;
		//this._scrollHandler= null;
		this._closeHandler= null;
		this._moveHandler= null;
		this._keyHandler= null;
		this._resizeWndHandler= null;
		this._resizeStartH= null;
  },
  
  Open : function(callback, refreshCallback, w, h, full) {
		this._loadCallback= callback;
		this._refreshCallback= refreshCallback;
		this.width= w; this.height= h;
		this._fullScreen= (!full) ? false : true;
		
		if (this._contentBody == null) {
			this._wndBody.src= fmDataViewerPath + "FramePage.aspx?lang=" + fmLCID;
			$addHandler(this._wndBody, 'load', this._windowLoadedHandler);
			//
			FM._ProgressBar.getInstance().Show(null, fmres("wnd_loading", "Window content is loading..."));
		} else {
			// was cleared onclose
			this._loadCallback(this._wndBody.contentWindow, this);
		}	
		this.Show();		
  },
  
  onWindowLoaded : function() {
		var doc_body= this._wndBody.contentWindow.document.body;
		if (!this._isCustom) this._contentBody= doc_body.getElementsByTagName('DIV')[1];
		FM._ProgressBar.getInstance().Hide();		
		this._loadCallback(this._wndBody.contentWindow, this);
		$removeHandler(this._wndBody, 'load', this._windowLoadedHandler);
		
		this._attachPopup();
		this._wndBody.contentWindow.FM.CurrentFrame= this;
  },
  
  //2008-01-30/testing
  OpenUrl : function(url, callback, refreshCallback, w, h, full) {
		this._loadCallback= callback;
		this._refreshCallback= refreshCallback;
		this.width= w; this.height= h;
		this._fullScreen= (!full) ? false : true;
		this._isCustom= true;
		this.PreventUnregister= true;
		
		if (this._url != url) {
			this._wndBody.src= this._url= url;
			$addHandler(this._wndBody, 'load', this._windowLoadedHandler);
		} else {
			// was cleared onclose
			this._loadCallback(this._wndBody.contentWindow, this);
		}	
		this.Show();		
  },  
  
  _attachPopup : function() {
		//$addHandler(window, 'resize', this._resizeHandler);
		//$addHandler(window, 'scroll', this._scrollHandler);
		$addHandler(document, 'keydown', this._keyHandler);
    //$addHandler(this._bg, 'click', this._closeHandler);
    $addHandler(this._wndHeader, 'mousedown', this._moveHandler);
    $addHandler(this._wndHeader, 'dblclick', this._resizeWndHandler);
    this._windowHandlersAttached= true;
    
 		this._tdButtons.tabIndex= 100;
 		$addHandlers(this._tdButtons, {
			'click': this.buttons_Click,
			'mouseover': this.buttons_Over,
			'mouseout': this.buttons_Out
		}, this);

		$addHandlers(this._wndBody, {
			'focus': this.focus
		}, this);
		
		$addHandler(this._tdResize, 'mousedown', this._resizeStartH);
		$addHandler(this._btnIco, 'click', this._showInfoH);
  },

  _detachPopup : function() {
    if (this._windowHandlersAttached) {
			//$removeHandler(window, 'resize', this._resizeHandler);
			//$removeHandler(window, 'scroll', this._scrollHandler);
			//$removeHandler(window, 'resize', this._resizeHandler); // IE FIX
			//$removeHandler(window, 'scroll', this._scrollHandler); // IE FIX
      $removeHandler(this._wndHeader, 'mousedown', this._moveHandler);
      $removeHandler(this._wndHeader, 'dblclick', this._resizeWndHandler);
			$clearHandlers(this._tdClose); 
			//$removeHandler(this._bg, 'click', this._closeHandler);
			$removeHandler(document, 'keydown', this._keyHandler);
			$removeHandler(this._tdResize, 'mousedown', this._resizeStartH);
			$removeHandler(this._btnIco, 'click', this._showInfoH);
			this._tdClose.tabIndex= -1;
      this._windowHandlersAttached= false;
    }
  },

	Show : function() {
		this._content.style.width= this.width + "px";
		this._content.style.height= this.height + "px";		
		this.setPosition();
		
		this.zIndex= FM.ModalWindow.reserveZIndex();
		//FM.ModalWindow._bg.style.zIndex= this.zIndex - 1;
		//FM.ModalWindow._bg.style.display= '';

		this.Visibled= true;		
		this._content.style.zIndex= this.zIndex;
		this._content.style.display= '';
		
		this._wndBody.focus();
		
		this.raiseOnShow();
		
		var img= this._tdButtons.childNodes[(window._help) ? 2 : 1];
		if (this._fullScreen) { img.src= fmCommonPath + "Images/Window/" + "btn_max_min.gif"; img.title= "Restore Down";  }
		else { img.src= fmCommonPath + "Images/Window/" + "btn_max.gif"; img.title= "Maximize";}
	},
	
	Disable : function() { 
		//this._bg.style.zIndex= this.zIndex + 100; 
	},
	Enable : function() { 
		//this._bg.style.zIndex= this.zIndex - 1; 
	},
	
	Hide : function() {
		if (!this._content) return;
		var allowClose= this.raiseBeforeCloseEvent();
		if (!allowClose) return;

		this.Visibled= false;		
		this._content.style.display= "none";
		//this._bg.style.display= "none";

		if (this._refreshCallback && this.refreshParent) { this._refreshCallback(this); this._refreshCallback= null; this.refreshParent= false; }

		this.buttons_Out(this._tdButtons.childNodes[(window._help) ? 3 : 2]);
		FM.ModalWindow.restoreZIndex();
		if (!this._isCustom) {
			this._header.innerHTML= "Please wait, the content is being loaded...";		
			if (this.PreventUnregister) this.ClearContent();
			else FM.ModalWindow.releaseWindowFrame(this);
		}
	},
	
	buttons_Click : function(e) {
		if (e.target.tagName != "IMG") return;
		var src= e.target.src;
		if (src.indexOf("btn_close") > 0) this.Hide();
		else if (src.indexOf("btn_max") > 0) this._ResizeWnd(null, e.target); 
		else if (src.indexOf("btn_!") > 0) this._ShowInfo();
		else if (src.indexOf("btn_help") > 0) this._ShowHelp();
	},
			
	Close : function() {
		this.Hide();
	},
	
	raiseBeforeCloseEvent : function() {
		if (this.onBeforeClose) return this.onBeforeClose();
		return true;
	},
	
	refreshParentAfterClose : function() { this.refreshParent= true; },

	setPosition : function() {
		var scrolledX, scrolledY;
		if (self.pageYOffset) {
			scrolledX= self.pageXOffset;
			scrolledY= self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {
			scrolledX= document.documentElement.scrollLeft;
			scrolledY= document.documentElement.scrollTop;
		} else if (document.body) {
			scrolledX= document.body.scrollLeft;
			scrolledY= document.body.scrollTop;
		}
		
		var brwWidth= getWindowWidth();
		var brwHeight= getWindowHeight();
		
		if (this._fullScreen) {
			this._content.style.top= "0px";
			this._content.style.left= "0px";
			this._content.style.width= brwWidth + "px";
			this._content.style.height= (brwHeight - this.headerHeight - 7) + "px";
		} else {
			var h= this.height + this.headerHeight + 7;
			if (brwHeight < h) {
				this.height= brwHeight - this.headerHeight - 7;
				this.top= 0;
			} else {
				this.top= scrolledY + (brwHeight - (this.height + this.headerHeight)) / 2;
			}
			this.left= scrolledX + (brwWidth - this.width) / 2;

			//this._bg.style.width= brwWidth + "px";
			//this._bg.style.height= brwHeight + "px";
			
			this._content.style.top= this.top + "px";
			this._content.style.left= this.left + "px";
			this._content.style.width= this.width + "px";
			this._content.style.height= this.height + "px";
		}
	},
  
  buttons_Over : function(e) { 
		if (e.target.tagName != "IMG") return;
		var src= e.target.src;
		if (src.indexOf("_on.gif") == -1) e.target.src= src.replace(".gif", "") + "_on.gif";
	},
  buttons_Out : function(e, img) { 
		if (e != null) img= e.target;
		if (img == null || img.tagName != "IMG") return;
		var src= img.src;
		if (src.indexOf("_on.gif") > 0 -1) img.src= src.replace("_on.gif", "") + ".gif";
	},
  
  SetContent : function(modalContent, trans) {
		if (this._contentBody) {
			if (trans) FM._ResourceLoader.StartTransitionalEffect(this._contentBody, 50, 20);
			this._contentBody.innerHTML= modalContent.BodyHtml;
		}
		this.SetHeader(modalContent.Title, modalContent.Description);
		this.SetTopBtns(modalContent.TopBtns);
		//this._footer.innerHTML= modalContent.FooterHtml;	
  },
  SetHtml : function(html) {
		this._contentBody.innerHTML= html;
  },
  
  SetTopBtns : function(btns) {
		if (btns) {
			var s= new Sys.StringBuilder();
			for (var i= 0; i < btns.length; i++) s.append(btns[i]);
			this._tdClose.previousSibling.innerHTML= s.toString();
		}
  },
  
  SetHeader : function(title, desc) {
		this._header.innerHTML= (title != null) ? title : "";
		//this._header.childNodes[0].innerHTML= (title != null) ? title : "";
		//this._header.childNodes[1].innerHTML= (desc != null) ? desc : "";
  },
  
  Clear : function(title, desc) {
		if (!this._contentBody) return;
		this._contentBody.innerHTML= "";
		this.SetHeader(title, desc);
		//this._footer.innerHTML= "";
  },
  
  ClearContent : function() {
		if (this.innerObject) { this.innerObject.dispose(); this.innerObject= null; }
		this._contentBody.innerHTML= "";
  },
  
  GetBodyElement : function() { return this._contentBody; },
  
  _MoveStart : function(e) {
		if (!this.Visibled || this._fullScreen) return;
    var dobj= this._content;
    this._tx= parseInt(dobj.style.left+0);
    this._ty= parseInt(dobj.style.top+0);
    this._x= e.clientX;
    this._y= e.clientY;
    
    FM.ModalWindow.moveMouseFrame(e.clientX, e.clientY);
    
    if (!this._moveCompleteHandler) this._moveCompleteHandler= Function.createDelegate(this, this._MoveComplete);
    if (!this._movingHandler) this._movingHandler= Function.createDelegate(this, this._Move);
    $addHandler(window.document, 'mouseup', this._moveCompleteHandler);
		$addHandler(window.document, 'mousemove', this._movingHandler);
    return false;
  },
  
  _Move : function(e) {
		FM.ModalWindow.moveMouseFrame(e.clientX, e.clientY);
		var dobj= this._content;
		var left= this._tx + e.clientX - this._x;
		var top= this._ty + e.clientY - this._y;
		dobj.style.left= ((left > 0) ? left : 0) + 'px';
		dobj.style.top= ((top > 0) ? top : 0) + 'px';
		return false;
  },
  
  _MoveComplete : function(e) {
		$removeHandler(window.document, 'mouseup', this._moveCompleteHandler);
		$removeHandler(window.document, 'mousemove', this._movingHandler);
		FM.ModalWindow.hideMouseFrame();		
		this.focus();
	},
	
	_ResizeWnd : function(e, img) {
		if (!this.Visibled) return;
		this._fullScreen= !this._fullScreen;
		this.setPosition();
		
		if (img == null) img= this._tdButtons.childNodes[(window._help) ? 2 : 1];
		if (this._fullScreen) { img.src= fmCommonPath + "Images/Window/" + "btn_max_min.gif"; img.title= "Restore Down";  }
		else { img.src= fmCommonPath + "Images/Window/" + "btn_max.gif"; img.title= "Maximize";}
	},
	
	keyPress : function(e) {
		if (!this.Visibled || !FM.ModalWindow.isActive(this)) return;
		switch (e.keyCode) {
			case Sys.UI.Key.esc : 
			//case 121 : //F10
				this.Hide(); break;
		}
	},
	
	_ResizeStart : function(e) {
		if (!this.Visibled || this._fullScreen) return;
    return false;
	},
	
	_ShowInfo : function(e) {
		var o= this.innerObject;
		if (o == null) {alert("No Info");return;}
		if (o._currentForm && o._currentForm.tableName == "AX_Incidents") return;		
		var s= "";
		var w= this;
		while (w != null && w.innerObject != null) {
			s+= w.innerObject.GetContextInfo() + "\n\n";
			w= w.parentFrame;
		}
		s+= window.parent.location.href;
		var qs= "_data=Comments:" + escape(s) + ",Subject:" + escape(": " + getInnerText(this._header) + "");
		window.openRecordByHandler("AX_Incidents", "FORM:AX_Incidents/Auto", qs, 670, 400, false);
	},
	
	_ShowHelp : function(e) {
		var o= this.innerObject;
		if (o == null) {alert("No Info");return;}
		var url= fmDataViewerPath + "Help.aspx?info=" + o.GetDescriptor();
		openStdWin(url, "Help", 600, 600);
		/*
		var callback= function(oWnd, hostWnd) { 
		}
		if (!window.parent._helpWindow) {
			window.parent._helpWindow= new window.parent.FM.ModalWindow();
		}
		window.parent._helpWindow.OpenUrl(url, callback, null, 800, 700);
		*/
	},
	
	SetStatus : function(s) {
		this._header.title= s;
	},
	
	focus : function(e) {
		//if (this.innerObject != null) this.innerObject.focus();
	},
	
	lastFocus : function(e) { this.close_Over(); },
	lastBlur : function(e) { this.close_Out(); this.focus(); },
	
	// Events
  add_OnShow: function(h) { this._onShowCallback= h; },
  remove_OnShow: function() { this._onShowCallback= null; },
  raiseOnShow: function(fl) { if (this._onShowCallback) this._onShowCallback(fl); },
		
	EndFunc : function() { }
}

FM.ModalWindow.registerClass('FM.ModalWindow', null, Sys.IDisposable);

//

FM.SimpleWindow= function(elem, pWindow) {
		if (elem != null) {
			this._content= elem;
		} else {
			this._content= document.createElement("DIV");
			this._content.className= "autosize";
			document.body.insertBefore(this._content, document.body.firstChild);
		}
		this.parentWindow= pWindow;
		this.commandBarMode= 'internal';		

		this._contentBody= this._content;
		this.ID= FM.ModalWindow.getUniqueID();
}

FM.SimpleWindow.prototype= {
  
  dispose : function() {
		this.parentWindow= null;
  },

	refreshParentAfterClose : function() { if (this.parentWindow) this.parentWindow.refreshParentAfterClose();  },
	Close : function() {if (this.parentWindow) this.parentWindow.Close();  },
  
	Show : function() { if (this.parentWindow) this.parentWindow.Show();  }, 
		
	Disable : function() { 
		//this._bg.style.zIndex= this.zIndex + 100; 
	},
	Enable : function() { 
		//this._bg.style.zIndex= this.zIndex - 1; 
	},
	
	Hide : function() {
	},

  SetContent : function(modalContent) {
		this._contentBody.innerHTML= modalContent.BodyHtml;
		this.SetHeader(modalContent.Title, modalContent.Description);
		//this._footer.innerHTML= modalContent.FooterHtml;	
  },
  SetHtml : function(html) {
		this._contentBody.innerHTML= html;
  },
  
  SetHeader : function(title, desc) {
		//this._header.innerHTML= (title != null) ? title : "";
		//this._header.innerHTML+= (desc != null) ? desc : "";
  },
  
  Clear : function(title, desc) {
		this._contentBody.innerHTML= "";
		this.SetHeader(title, desc);
		//this._footer.innerHTML= "";
  },
  
  GetBodyElement : function() { return this._contentBody; }

}

FM.SimpleWindow.registerClass('FM.SimpleWindow', null, Sys.IDisposable);

// POPUP WINDOW (RUN FROM CURRENT WINDOW CONTEXT)
FM.PopupWindow= function(div, bg, wnd_doc, w, h) {
	this.wndDocument= (wnd_doc != null) ? wnd_doc : window.document;
	this._parent= null;
	this.useTransitional= false;
	if (!div) {
		div= this.wndDocument.createElement("DIV");
		div.style.position= "absolute"; div.style.display= "none";
		this.wndDocument.body.insertBefore(div, this.wndDocument.body.firstChild);
	}
	if (!bg) {
		bg= this.wndDocument.createElement("DIV");
		bg.style.position= "absolute"; bg.style.display= "none";
		this.wndDocument.body.insertBefore(bg, this.wndDocument.body.firstChild);
	}
	this._content= div;
	this._bg= bg;
	with (this._content.style) {
		position= "absolute"; display= "none"; 
		width= w + "px"; height= h + "px";
		backgroundColor= "#FFF";
	}
	this._contentBody= this._content;
	
	this._bg.className= 'modalWnd_Background';
	with (this._bg.style) {
		position= "absolute"; display= "none"; 
		width= w + "px"; height= h + "px";
	}
	
	this.top= 0;this.left= 0;
	this.width= w;this.height= h;
	this.Visibled= false;
	this.bodyClickDlg= Function.createDelegate(this, this._onBodyClick);
}

FM.PopupWindow.prototype= {
  
  dispose : function() {
		if (this.Visibled) { $removeHandler(document.body, 'click', this.bodyClickDlg); this.bodyClickDlg= null; this.Visibled= false; }
  },
  
  _onBodyClick : function(e) {
		if (!this.Visibled) return;
    if (this._wasClicked) {
      // If we received a click that we expected, do nothing
      this._wasClicked= false;
    } else {
      // If the click was outside our control, hide the popup
      this.Hide();
    }
	},
  
 	SetOffsetParent : function(parentElem) {
		this._parent= parentElem;
	},

	Hide : function() {
		if (!this.Visibled) return;
		$removeHandler(document.body, 'click', this.bodyClickDlg);
		this.Visibled= false;
		this._content.style.display= "none";
		this._bg.style.display= "none"; 
	},
  
	Show : function() {
		if (this.Visibled) return;
		this._wasClicked= true;
		this.setPosition();
		this._content.style.display= ""; 
		this._bg.style.display= "";
		this.Visibled= true;
		if (this.useTransitional) FM._ResourceLoader.StartTransitionalEffect(this._contentBody, 20, 20);
		$addHandler(document.body, 'click', this.bodyClickDlg);
	}, 
		
  SetContent : function(sHtml) { this._contentBody.innerHTML= sHtml; },
  SetHtml : function(html) { this._contentBody.innerHTML= html; },
  
  setPosition : function() {
		var pHeight= this._parent.offsetHeight;
		var loc= Sys.UI.DomElement.getLocation(this._parent);
		// left
		this.left= loc.x;
		var right= (this.left + this.width);
		var dx= (this.wndDocument.body.clientWidth - right - 5);
		if (dx < 0)	this.left+= dx;
		// top
		this.top= loc.y + pHeight - 3;
		var bottom= this.top + this.height;
		if (bottom > window.document.body.clientHeight) this.top= loc.y - this.height;
		this._content.style.left= this.left + "px";
		this._content.style.top= this.top + "px";
		
		this._bg.style.left= (this.left + 5) + "px";
		this._bg.style.top= (this.top + 5) + "px";
	},
  
  GetBodyElement : function() { return this._contentBody; }
}

FM.PopupWindow.registerClass('FM.PopupWindow', null, Sys.IDisposable);

FM.ModalWindow._zIndex= 1000;
FM.ModalWindow.reserveZIndex= function() { return FM.ModalWindow._zIndex+= 100; return FM.ModalWindow._zIndex; }
FM.ModalWindow.restoreZIndex= function() { FM.ModalWindow._zIndex-= 100; }
FM.ModalWindow.isActive= function(wnd) { return wnd.zIndex == FM.ModalWindow._zIndex; }

FM.ModalWindow._uniqueID= 0;
FM.ModalWindow.getUniqueID= function () { return ("wnd_" + (++FM.ModalWindow._uniqueID)); }
FM.ModalWindow.find= function(id) { alert('FM.ModalWindow.find is not supported now'); return null; }

FM.ModalWindow.getMouseFrame= function() {
if (!FM.ModalWindow._mouseFrame) {
	var o= document.createElement("DIV");
  o.style.position= "absolute"; o.style.zIndex= 5000;
	o.style.width= "120px"; o.style.height= "140px";
	document.body.appendChild(o);
  FM.ModalWindow._mouseFrame= o;
}
return FM.ModalWindow._mouseFrame;
}
FM.ModalWindow.moveMouseFrame= function(x, y) {
	var o= FM.ModalWindow.getMouseFrame();
	o.style.left= (x - 60) + "px"; 
	o.style.top= (y - 50) + "px"; 
	if (o.style.display == "none") o.style.display= "";
}
FM.ModalWindow.hideMouseFrame= function() { FM.ModalWindow.getMouseFrame().style.display= "none"; }

FM.ModalWindow.createWindowFrame= function() {
if (window.parent._windows == null || window.parent._windows.length == 0) {
	return new window.parent.FM.ModalWindow();
} else {
	return window.parent._windows.pop();
}
}
FM.ModalWindow.releaseWindowFrame= function(wnd) {
	wnd.ClearContent();
	if (window.parent._windows == null) window.parent._windows= new Array();
	window.parent._windows.push(wnd);
}

FM.ModalWindow.PrepareInstance= function() {
	var wnd= new window.parent.FM.ModalWindow();
	window.parent._windows= new Array();
	window.parent._windows.push(wnd);
}

// Gets real Top value with respect to client area
getAbsoluteTop= function(o, dy) {
  var top= (dy != null) ? dy : 0;
  while (o && o.tagName != "BODY") { top+= o.offsetTop; o= o.offsetParent; }
  return top;
}
// Get real Left value with respect to client area
getAbsoluteLeft= function(o, dx) {
	var left= (dx != null) ? dx : 0;
  while (o && o.tagName != "BODY") { left+= o.offsetLeft; o= o.offsetParent; }
  return left;
}

getWindowWidth= function() {
	if (self.innerWidth) return self.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
	else if (document.body) return document.body.clientWidth;
	return 0;
}
getWindowHeight= function() {
	if (self.innerHeight) return self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
	else if (document.body) return document.body.clientHeight;
	return 0;
}

Sys.Application.notifyScriptLoaded();