// 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 = "Complejo Anaconda: 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)
{
	if( winTitle ) title = winTitle;
	else title = "PopUp";
	if( !winName ) winName = "WinPopup";
	if(!posX) posX=0;
	if(!posY) posY=0;
	//if(!autoclose) autoclose=1;
	openFramelessPopup(urlStr,winName,winW,winH,posX,posY,Centered,full,0,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);
	    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+">"+
							"<frame name='bottom' src='about:blank' scrolling='no'>"+
							"</frameset>"+
							"</html>";
		    NW.document.open();
		    NW.document.write(frameString);
		    NW.document.close();
		}
  	} else {
    	NW=window.open(urlPopup,winName,s);
    	NW.blur();
    	window.focus();
    	NW.resizeTo(windowW,windowH);
    	NW.moveTo(windowX,windowY);
  }   
  NW.focus();   
  if (autoclose){
    window.onunload = function(){NW.close()}
  }
}
// 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) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  
	imageWidth = new Number(imageWidth);
	imageHeight = new Number(imageHeight);
	
	if (bgndColor=="") {
		bgndColor="#FFFFFF";
	}
	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 (imageWidth>w){	
	  byFactor = w / imageWidth;			
	  imageWidth = w;
	  imageHeight = imageHeight * byFactor;
	}
	
	if (imageHeight>h-adj){
	  byFactor = h / imageHeight;
	  imageWidth = (imageWidth * byFactor);
	  imageHeight = h; 
	}
	   
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if (imageHeight>scrHeight){
  	  imageHeight=imageHeight*lift;
	  imageWidth=imageWidth*lift;
	}

	var posLeft=0;
	var posTop=0;

	if (hugger == "hug"){
	  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;}

	  posTop =  ((h-(scrHeight/lift)-adj)/2);
	  posLeft = ((w-(scrWidth)-adj)/2);
	  
 	}
	if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
		imageHeight=imageHeight-adj;
		imageWidth=imageWidth-adj;
	}
	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 {
	newWindow = window.open("about:blank","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+winTitle+'</title><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 src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Imagen cedida por Richard Illa" >'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}

