OverDialog = function (){
	this.isOpen = false;
	this.inited = false;
	this.closeLink = "<img src='/images/closeDialog.png' border=0>";
	this.hasTop = true;
	this.styleSheet = null;
	this.overlayDiv = null;
	this.overlayFrameDiv = null;
	this.overlayTop = null;
	this.overlayCloseA = null;
	this.overlayTitle = null;
	this.overlayFrame = null;
	this.onclose = null;
};
	
OverDialog.createElement = function(elName)
{
	var el = document.createElement(elName);
	return el;
}

OverDialog.appendToDocument = function (el)
{
	document.body.appendChild(el);
}
	
OverDialog.prototype.init = function (){
		if(this.inited)
			return;
			
			this.styleSheet = OverDialog.createElement('link');
			this.styleSheet.rel = 'stylesheet';
			this.styleSheet.href = '/css/overDialog.css';
			this.styleSheet.type = 'text/css';
			OverDialog.appendToDocument(this.styleSheet);
	
			this.overlayDiv = OverDialog.createElement("div");
			this.overlayDiv.className="overlayDiv";
			this.overlayDiv.id="overlayDiv";
			this.overlayDiv.style.display="none";
			OverDialog.appendToDocument(this.overlayDiv);
	
			this.overlayFrameDiv = OverDialog.createElement("div");
			this.overlayFrameDiv.className="overlayFrameDiv";
			this.overlayFrameDiv.id="overlayFrameDiv";
			this.overlayFrameDiv.style.display="none";
			OverDialog.appendToDocument(this.overlayFrameDiv);
	
			this.overlayTop = OverDialog.createElement("div");
			this.overlayTop.className="overlayTop";
			this.overlayTop.id="overlayTop";
			this.overlayFrameDiv.appendChild(this.overlayTop);
	
			this.overlayCloseA = OverDialog.createElement("a");
			this.overlayCloseA.className="overlayCloseA";
			this.overlayCloseA.id="overlayCloseA";
			this.overlayCloseA.href="javascript:this.dialog.hideDialog()";
			this.overlayCloseA.dialog = this;
			
			
			if (this.closeLink && this.closeLink!='')
				this.overlayCloseA.innerHTML = this.closeLink;
			this.overlayTop.appendChild(this.overlayCloseA);
	
			this.overlayTitle = OverDialog.createElement("div");
			this.overlayTitle.className="overlayTitle";
			this.overlayTitle.id="overlayTitle";
			this.overlayTitle.innerHTML="";
			this.overlayTop.appendChild(this.overlayTitle);
		
			this.overlayFrame = document.createElement("iframe");
			this.overlayFrame.name="overlayFrame";
			this.overlayFrame.id="overlayFrame";
			this.overlayFrame.className="overlayFrame";
			this.overlayFrame.src="";
			this.overlayFrame.frameBorder="0";
			this.overlayFrameDiv.appendChild(this.overlayFrame);
			
			//if(typeof Drag !='undefined')
			//	Drag.init(t,d);
			
			this.inited = true;
	};
	
OverDialog.prototype.showDialog = function (src,title,width,height,topHeight){
		if(this.isOpen)
			return;
			
		if(!this.inited)
			this.init();

		this.hideShowSelectElements(false);
		
		/*title*/
		if(title)
			this.overlayTitle.innerHTML=title;
		else
		{
			this.overlayTop.style.display='none';
			this.hasTop=false;
		}
		
		if (topHeight)
			this.overlayTop.style.height = topHeight+'px';
		else
			this.overlayTop.style.height = '20px';
		/*title END*/
		
		/*sizes*/
		if (width)
			this.overlayFrameDiv.style.width=width+'px';
			
		if (height)
			this.overlayFrameDiv.style.height=height+'px';
			
		if (!this.overlayFrameDiv.style.width)
			this.overlayFrameDiv.style.width='80%';
			
		if (!this.overlayFrameDiv.style.height)
			this.overlayFrameDiv.style.height='80%';			
			
		/*sizes END*/
		
			
			
		this.overlayFrameDiv.style.display="block";
		this.overlayDiv.style.display="block";
		if(src)
			this.overlayFrame.src=src;
		this.isOpen = true;
		
		this.setPositions();
	};
	
OverDialog.prototype.setPositions= function (){
	
		this.overlayDiv.style.height=getPageDimensions().height+'px';
		
		this.overlayFrameDiv.style.top=(getWindowScrollPosition().h+(getWindowInnerDimensions().height/2)-(this.overlayFrameDiv.clientHeight/2))+'px';
		this.overlayFrameDiv.style.left=(getWindowScrollPosition().w+(getWindowInnerDimensions().width/2)-(this.overlayFrameDiv.clientWidth/2))+'px';
		
		if (this.overlayFrameDiv.style.top && parseInt(this.overlayFrameDiv.style.top)<0)
			this.overlayFrameDiv.style.top = "0px";
		if (this.overlayFrameDiv.style.left && parseInt(this.overlayFrameDiv.style.left)<0)
			this.overlayFrameDiv.style.left = "0px";
		
		//alert(document.getElementById("overlayTop").style.display);
		if (this.hasTop)
			this.overlayFrame.style.height=(this.overlayFrameDiv.clientHeight-this.overlayTop.clientHeight)+'px';
		else
			this.overlayFrame.style.height=this.overlayFrameDiv.clientHeight+'px';
																						  
		this.overlayFrame.style.width=this.overlayFrameDiv.clientWidth+'px';
		this.overlayTop.style.width=this.overlayFrameDiv.clientWidth+'px';
		
	};
	
OverDialog.prototype.hideDialog= function (){
		if(!this.isOpen)
			return;
		if (this.onclose)
			this.onclose();
		this.hideShowSelectElements(true);
		this.overlayFrameDiv.style.display="none";
		this.overlayDiv.style.display="none";
		this.isOpen = false;
		this.overlayFrame.src="about:blank";
		
	};
	
OverDialog.prototype.hideShowSelectElements= function (show)
	{
	  if(document.getElementsByTagName)
	  {
	  	var arrElements=document.getElementsByTagName('select');
	  	for(var i=0;i<arrElements.length;i++)
	  		arrElements[i].style.visibility=show?'visible':'hidden';
	  }
	};


function getWindowInnerDimensions()
{
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	var dim = {width:x,height:y};
	return dim;
}

function getWindowScrollPosition()
{
	var x,y;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	var pos = {w:x,h:y};
	return pos;
}

function getPageDimensions()
{
	var x,y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	}
	else // Explorer Mac;
		 //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}
	var dim = {width:x,height:y};
	return dim;
}

