var ifr;
var textoInicial = "";
var origenPlantilla = false;

function scroll_top(){

	if(window.pageYOffset){
		return window.pageYOffset;
	 }
	 else {
		return  Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	 }

}


function IPopup(addr,width,height,vScrollbar,hScrollbar,texto, vieneDePlantilla)
{	
    origenPlantilla = vieneDePlantilla;
	textoInicial = (texto == null) ? "" : texto;
	ifr = document.createElement('iframe');
	ifr.style.position = 'absolute';
	// toma tamaño de body donde reside el frame
  var screenwidth=document.body.clientWidth;
  var screenheight=document.body.clientHeight;
	// si el popup es > que el 90% de la pantalla lo achica
  if (width>screenwidth*0.8 || width==0)
  	width=screenwidth*0.8;
  if (height>screenheight*0.8 || height==0)
  	height=screenheight*0.8;
	ifr.style.width = width+'px';
	ifr.style.height = height+'px';
	ifr.style.left = ((parseInt(document.body.clientWidth) - width)/2)+'px';
	//ifr.style.top = (((parseInt(document.body.clientHeight) - height - 60)/2)+parseInt(document.documentElement.scrollTop))+'px'; IE
	//ifr.style.top = (((parseInt(document.body.clientHeight) - height - 60)/2)+parseInt(document.body.scrollTop))+'px'; MOZILLA
	ifr.style.top = (((parseInt(document.body.clientHeight) - height - 60)/2)+(parseInt(scroll_top()/2)))+'px';

	ifr.frameBorder = "0";
	ifr.style.border = '2px solid gray';
	ifr.style.zIndex = 99999;
	(vScrollbar)?ifr.style.overflowY = 'scroll':void(0);
	(hScrollbar)?ifr.style.overflowH = 'scroll':void(0);
	grayOut(true,{'opacity':'75'})
	document.body.appendChild(ifr);
	ifr.src = addr;
}
function IClose()
{
	if (ifr)
	{
		grayOut();
		document.body.removeChild(ifr);
		ifr = null;
	}
}
function grayOut(vis, options) 
{  
	var options = options || {};
	var zindex = options.zindex || 50;
	var opacity = options.opacity || 70;
	var opaque = (opacity / 100);
	var bgcolor = options.bgcolor || '#666666';
	var dark=document.getElementById('darkenScreenObject');
	if (!dark) {    
		var tbody = document.getElementsByTagName("body")[0];
		var tnode = document.createElement('iframe');
		tnode.frameBorder = 0;
		tnode.style.position='absolute';
		tnode.style.top='0px';
		tnode.style.left='0px';
		tnode.style.overflow='hidden';
		tnode.style.display='none';
		tnode.id='darkenScreenObject';
		tbody.appendChild(tnode);
		dark=document.getElementById('darkenScreenObject');
	}  
	if (vis) {    
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) 
 		{        
			var pageWidth = document.body.scrollWidth+'px';
			var pageHeight = document.body.scrollHeight+'px';
		} else if( document.body.offsetWidth ) {      
			var pageWidth = document.body.offsetWidth+'px';
			var pageHeight = document.body.offsetHeight+'px';
	    } else {       
			var pageWidth='100%';
			var pageHeight='100%';
    	}       

		dark.style.opacity=opaque;
		dark.style.MozOpacity=opaque;
		dark.style.filter='alpha(opacity='+opacity+')';
		dark.style.zIndex=zindex;
		dark.style.backgroundColor=bgcolor;
		dark.style.width= pageWidth;
		dark.style.height= pageHeight;
		dark.style.display='block';
	} else {     
		dark.style.display='none';
  	}
}


function IPopupHTMLPrivado(html,width,height,vScrollbar,hScrollbar,lleft,ttop,opacity,conGrayOut)
{	
    if (opacity == null)
      opacity = '75';
    else
      opacity = new String(opacity);
	ifr = document.createElement('div');
	ifr.style.position = 'absolute';
	// toma tamaño de body donde reside el frame
  var screenwidth=document.body.clientWidth;
  var screenheight=document.body.clientHeight;
	// si el popup es > que el 90% de la pantalla lo achica
  if (width>screenwidth*0.8 || width==0)
  	width=screenwidth*0.8;
  if (height>screenheight*0.8 || height==0)
  	height=screenheight*0.8;
	ifr.style.width = width+'px';
	ifr.style.height = height+'px';
	ifr.style.left = ((lleft == null)?(parseInt(document.body.clientWidth) - width)/2:lleft)+'px';
	ifr.style.top = ((ttop == null)?((parseInt(document.body.clientHeight) - height - 60)/2)+parseInt(document.body.scrollTop):ttop)+'px';
	ifr.frameBorder = "0";
	//ifr.style.border = '2px solid gray';
	ifr.style.zIndex = 99999;
	(vScrollbar)?ifr.style.overflowY = 'scroll':void(0);
	(hScrollbar)?ifr.style.overflowH = 'scroll':void(0);
	if (conGrayOut)
         grayOut(true,{'opacity':opacity});
	document.body.appendChild(ifr);
        div = document.createElement('div');
        ifr.appendChild(div);
	div.innerHTML = html;
//        ifr.onmouseover = function ()  {
//          ifr.style.left = Math.floor(Math.random()*parseInt(document.body.clientWidth)) + 1;
//          ifr.style.top  = Math.floor(Math.random()*parseInt(document.body.clientHeight)) + 1;
//        };
}

function IPopupHTML(html,width,height,vScrollbar,hScrollbar,lleft,ttop,opacity) {
  IPopupHTMLPrivado(html,width,height,vScrollbar,hScrollbar,lleft,ttop,opacity,true);
}
function IPopupHTMLSinGrayOut(html,width,height,vScrollbar,hScrollbar,lleft,ttop) {
  IPopupHTMLPrivado(html,width,height,vScrollbar,hScrollbar,lleft,ttop,0,false);
}

