/**
 * MyPopup v1.1 por José Carlos Cruz Parra http://www.internia.net 2008-04-04
 */

function MyPopup(varName, width, height, css_class, hideSelects)
{
	this.content = "";
	this.css_class = (css_class == null) ? "popup" : css_class;
	this.varName = varName;
	this.id = "popup"+Math.round(10000*Math.random());
	this.centered = true;
	this.closable = true;
	this.visible = false;
	this.width = width;
	this.height = height;
	this.overflow = "hidden";
	this.hideSelects = (hideSelects == null ? false : hideSelects);

	this.getStyle = function()
	{
		var style = "overflow:"+this.overflow+";";
		style += this.visible ? "display:block;" : "display:none;";
		if(this.width != null && this.width > 0)
		{
			style += ("width:"+width+"px;");
		}
		if(this.height != null && this.height > 0)
		{
			style += ("height:"+height+"px;");
		}
		return style;
	}
	this.display = function(visible)
	{
		this.visible = visible;
		var divPopup = document.getElementById(this.id);
		divPopup.style.display = this.visible ? "inline" : "none";
		if(this.hideSelects)
		{
			var sdisplay = visible ? "none" : "inline";
			var selects = document.getElementsByTagName("select");
			for(var c=0; c<selects.length; c++)
			{
				selects[c].style.display = sdisplay;
			}
			var selects = divPopup.getElementsByTagName("select");
			for(var c=0; c<selects.length; c++)
			{
				selects[c].style.display = divPopup.style.display;
			}
		}
		if(this.centered)
		{
			document.getElementById(this.id).style.top = "50%";
			document.getElementById(this.id).style.left = "50%";
			//document.getElementById(this.id).style.margin = "-"+this.height+"px 0px 0px -"+(this.width/2)+"px";
		}
	}
	this.SetContent = function(content)
	{
		this.content = this.closable ? '<div style="padding:0px;text-align:right" class="mini"><a href="javascript:'+this.varName+'.Close();"><b>X</b> Cerrar</a></div><br />' : '<br />';

		if(content != null)
		{
			this.content += content;
		}
		document.getElementById(this.id).innerHTML = this.content;
	}
	this.Show = function(content)
	{
		if (content != null)
		{
			this.SetContent(content);
		}
		this.display(true);
	}
	this.Close = function()
	{
		this.display(false);
	}

	document.write('<div class="'+this.css_class+'" id="'+this.id+'" style="'+this.getStyle()+'"></div>');
}