// Verifico que el Navegador sea IE o Netscape
var isIE = document.all?true:false
// Si quiero darle un nombre particular debo modificar esta variable localmente
var title = "Esquemas.com: Window PopUp";

/* Forma simple de abrir una ventana para uso rápido (incluso para usuarios)
   Recibe: url,titulo,ancho,alto,centrada(1:SI/0:NO),posición X, posición Y,cerrado automático, tamaño fijo
   Nombre del objeto ventana, muestra o no el Status Bar */
function NuevaVentanaPopUp(urlStr,winTitle,winW,winH,Centered,posX,posY,autoclose,full,noresize,winName,statbar,scrollbar,noframe)
{
	if( winTitle ) title = winTitle;
	else title = "PopUp";
	if( !winName ) winName = "WinPopup";
	if(!posX) posX=0;
	if(!posY) posY=0;
	if(!noframe) noframe=0;
	//if(!autoclose) autoclose=1;
	return openFramelessPopup(urlStr,winName,winW,winH,posX,posY,Centered,full,noframe,autoclose,noresize,statbar,scrollbar);
}

// Abre una nueva ventana sin marco (detecta el navegador)
// Recibe: url, tamaño (Width,Height), posición (X,Y), centrado (Si/No),
// 		   si barra de titulo, sin frames, auto-cerrado (se cierra automáticamente al cerrar página "padre", 
//		   tamaño fijo, muestra o no la Status Bar, muestra o no los scrollbars )
function openFramelessPopup(urlPopup,winName,windowW,windowH,windowX,windowY,centered,notitle,noframe,autoclose,noresize,statbar,scrollbar)
{
	if( centered )
	{
		windowX = (window.screen.width-windowW)/2;
		windowY = (window.screen.height-windowH)/2;
	}
	if( !windowX ) windowX = 20;
	if( !windowY ) windowY = 20;
	if( !winName ) winName = "popUpWindow";
	if( !statbar ) statbar = 0;
	if( !scrollbar ) scrollbar = "no";
	s = "width="+windowW+",height="+windowH+",toolbar=0,location=0,directories=0,status="+statbar+",menubar=0,scrollbars="+scrollbar;
	if( !noresize ) s = s+",resizable=1"; 
	if( notitle ) s = "fullscreen,"+s;

	window.name = "parentWin";
	if (isIE){
		NW = window.open("",winName,s);
		if(  NW == null ) 
			alert( 'Esta aplicación Web requiere la habilitación de Pop-Ups para su normal funcionamiento\n\nPor favor, verifique en su barra de tareas que los Pop-Ups no estén bloqueados,\nen ese caso, habilítelos para este Sitio.\nDisculpe las molestias y gracias por su comprensión...' );
		else 
			NW.blur();
	    window.focus();
	    NW.resizeTo(windowW,windowH);
	    NW.moveTo(windowX,windowY);
	    if( noframe ){
	    	NW.document.location=urlPopup;
	    } else {
		    var frameString=""+
						    "<html>"+
							"<head>"+
							"<title>"+title+"</title>"+
							"</head>"+
							"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
							"<frame name='top' src='"+urlPopup+"' scrolling="+scrollbar+" noresize>"+
							"<frame name='bottom' src='about:blank' scrolling='no' noresize>"+
							"</frameset>"+
							"</html>";
		    NW.document.open();
		    NW.document.write(frameString);
		    NW.document.close();
		}
  	} else {
    	NW=window.open(urlPopup,winName,s);
		if(  NW == null ) 
			alert( 'Esta aplicación Web requiere la habilitación de Pop-Ups para su normal funcionamiento\n\nPor favor, verifique en su barra de tareas que los Pop-Ups no estén bloqueados,\nen ese caso, habilítelos para este Sitio.\nDisculpe las molestias y gracias por su comprensión...' );
		else 
			NW.blur();
    	window.focus();
    	NW.resizeTo(windowW,windowH);
    	NW.moveTo(windowX,windowY);
  }   
  NW.focus(); 
  NW.parentWin = window;  
  if (autoclose){
    window.onunload = function(){NW.close()}
  }
  return NW;
}
// Abre una nueva ventana del tamaño justo de la imagen
// Recibe: imageName   -> URL de la imágen
//		   imageWidth  -> Ancho de la imágen
//		   imageHeight -> Alto de la imágen
//		   winTitle	   -> Titulo de la ventana (el que aparecerá en el border de la misma)
//		   bgndColor   -> Color de fondo de la ventana
//		   hugger	   -> Si viene "hug" quiere decir que va a abrir la ventana ajustada a la imágen
//		   hugMargin   -> Márgen que se le debe agregar al ajustar la ventana a la imágen
function OpenImageWindow(imageName,imageWidth,imageHeight,winTitle,bgndColor,hugger,hugMargin,posTop,posLeft,centered) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;

	if(w<740){
	  var lift=0.90;
	}
	if(w>=740 & w<835){
	  var lift=0.91;
	}
	if(w>=835){
	  var lift=0.93;
	}

	if (bgndColor=="") {
		bgndColor="#FFFFFF";
	}

	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if( imageWidth && imageHeight )
	{
		imageWidth = new Number(imageWidth);
		imageHeight = new Number(imageHeight);
	
		if (imageWidth>w)
		{	
			byFactor = w / imageWidth;			
			imageWidth = w;
			imageHeight = imageHeight * byFactor;
		}
	
		if (imageHeight>h-adj)
		{
			byFactor = h / imageHeight;
			imageWidth = (imageWidth * byFactor);
			imageHeight = h; 
		}
	   

		if (imageHeight>scrHeight)
		{
			imageHeight=imageHeight*lift;
			imageWidth=imageWidth*lift;
		}

		if (hugger == "hug" || !hugger )
		{
			if (hugMargin == "" || ! hugMargin )
				hugMargin = 0;

	  		var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
			if (scrHeightTemp < scrHeight)
				scrHeight = scrHeightTemp;

			var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
			if (scrWidthTemp < scrWidth)
				scrWidth = scrWidthTemp;
	  
			if (scrHeight<100){scrHeight=100;}
			if (scrWidth<100){scrWidth=100;}
 		}

		if (imageHeight > (h*lift)-adj || imageWidth > w-adj)
		{
			imageHeight=imageHeight-adj;
			imageWidth=imageWidth-adj;
		}
	}
	else
	{
		scrWidth = 100;
		scrHeight= 100;
	}

	if( centered )
	{
		posTop = (window.screen.width-scrWidth)/2;
		posLeft = (window.screen.height-scrHeight)/2;
	}
	else
	{
		if( !posTop )
			posTop =  ((h-(scrHeight/lift)-adj)/2);
		if( !posLeft )
			posLeft = ((w-(scrWidth)-adj)/2);
	}

	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);		
	scrWidth = parseInt(scrWidth); 
	scrHeight = parseInt(scrHeight);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1)
	{
		var args= new Array();
		args[0]='parent';
		args[1]=imageName;
		var i ; document.MM_returnValue = false;
		for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	} 
	else 
	{
		var JSContent="";
		JSContent+="<"+"SCRIPT>\n";
		JSContent+="function resizeToFitImg()\n";
		JSContent+="{\n";
		JSContent+="window.resizeTo(document.getElementById('Img').width + 1 + " + hugMargin + ",document.getElementById('Img').height + 10 + " + hugMargin + ");\n";
		if( centered )
			JSContent+="window.moveTo("+posLeft+" - (document.getElementById('Img').height/2),"+posTop+"-(document.getElementById('Img').width/2));\n";
		JSContent+="}\n";
		JSContent+="</"+"SCRIPT>\n";

		
		newWindow = window.open("about:blank","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
		newWindow.document.open();
		newWindow.document.write('<html><head><title>'+winTitle+'</title>');
		if( !imageWidth || !imageHeight )
		{
			newWindow.document.write(JSContent+'</head>');
			newWindow.document.write('<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgndColor='+bgndColor+' onBlur="self.close()" onClick="self.close()" onload="resizeToFitImg()">');
			newWindow.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" height="100%" ><tr><td>');
			newWindow.document.write('<img name="Img" id="Img" src="'+imageName+'" alt="Click aquí para cerrar" >'); 
		}
		else
		{
			newWindow.document.write('</head><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgndColor='+bgndColor+' onBlur="self.close()" onClick="self.close()">');
			newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
			newWindow.document.write('<img name="Img" id="Img" src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Click aquí para cerrar" >'); 
		}
		newWindow.document.write('</td></tr></table></body></html>');
		newWindow.document.close();
		newWindow.focus();
	}
}

