// JavaScript Document

if(typeof OverlayGenerator == "undefined") var OverlayGenerator = new Object();
OverlayGenerator.create = function(title,content){
	//alert("Function Create Started OK!");
	
	this.domElement = document.createElement("div");
	this.domElement.id = "overlay";

	this.background = document.createElement("div");
	this.background.id = "overlay-background";
	
	this.foreground = document.createElement("div");
	this.foreground.id = "overlay-foreground";
	
	var sizer = document.createElement("div");
	sizer.className = "sizer";
	this.background.appendChild(sizer);
	
	var table = '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tbody><tr><td align="center" valign="middle"></td></tr></tbody></table>';
	
	var container = document.createElement("div");
	container.id = "overlay-content";

	var header = document.createElement("div");
	header.id = "overlay-head";
	
	this.theTitle = document.createElement("div");
	this.theTitle.className = "title";
	
	this.theBody = document.createElement("div");
	this.theBody.id = "overlay-body";

	var footer = document.createElement("div");
	footer.id = "overlay-foot";
	
	var closeLink = document.createElement("a");
	closeLink.className = "close";
	closeLink.href = "javascript:void(0)";
	closeLink.onclick = closeOverlay;

	var closeImg = document.createElement("img");
	closeImg.src = "html/img/overlay_close.gif";
	closeImg.border = "0";
	
	closeLink.appendChild(closeImg);
	header.appendChild(this.theTitle);
	header.appendChild(closeLink);
	container.appendChild(header);
	container.appendChild(this.theBody);
	container.appendChild(footer);

	this.foreground.innerHTML = table;
	
	this.foreground.firstChild.firstChild.firstChild.firstChild.appendChild(container);
	
	this.domElement.appendChild(this.background);
	this.domElement.appendChild(this.foreground);
	
	this.init = false;
};
OverlayGenerator.create.prototype = {
	 center:true
	,show:function(){
		 if(!this.init){
			 this.init = true;
			 document.body.insertBefore(this.domElement, document.body.firstChild);
			 if(overlayElement.center){
				 overlayElement.foreground.style.top = overlayElement.getScrollTop()+"px"
			 }else{
				 document.location = "#";
			 }
		 }
	 }
	,open:function(title,content){
		if(title != null) this.setTitle(title);
		if(content != null) this.setContent(content);
		this.show();
	 }
	,close:function(){
		if(this.init){
			document.body.removeChild(this.domElement);
			this.init = false;
		}
	 }
	,html:function(object, content){
		if(typeof $ != "undefined" && typeof jQuery != "undefined"){
			$(object).html(content);
		}else{
			object.innerHTML = content;
		}
	 }
	,setTitle:function(title){ this.html(this.theTitle, title);/*this.theTitle.innerHTML = title;*/ }
	,setContent:function(content){ this.html(this.theBody, content);/*this.theBody.innerHTML = content;*/ }
	,getScrollTop:function() {
		var n_win = window.pageYOffset ? window.pageYOffset : 0;
		var n_docel = document.documentElement ? document.documentElement.scrollTop : 0;
		var n_body = document.body ? document.body.scrollTop : 0;
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}
};

var Overlay = OverlayGenerator.create;

var overlayElement = null;

function openOverlay(title,content){
	if(navigator.userAgent.indexOf("MSIE 6") > -1){
		var selects = document.getElementsByTagName("select");
		for(var i=0;i<selects.length;i++) selects[i].style.visibility = "hidden";
	}
	if(overlayElement == null){
		overlayElement = new Overlay(title,content);
	}
	overlayElement.open(title,content);
}

function closeOverlay(){
	if(overlayElement != null){
		if(navigator.userAgent.indexOf("MSIE 6") > -1){
			var selects = document.getElementsByTagName("select");
			for(var i=0;i<selects.length;i++) selects[i].style.visibility = "visible";
		}
		overlayElement.close();
	}
}