/**
 * POPUP WINDOW CODE v1.4
 * Used for displaying DHTML only popups instead of using buggy modal windows.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Contributions by:
 * 	Eric Angel - tab index code
 * 	Scott - hiding/showing selects for IE users
 *	Todd Huss - inserting modal dynamically and anchor classes
 *      Francisco Javier Galiano Aguila -- adaptacion del codigo para la llamada enviando el codigo html y paginas webs
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/subModal
 * 
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

// Popup code

    var IE = document.all?true:false

    // If NS -- that is, !IE -- then set up for mouse capture
    if (!IE) document.captureEvents(Event.MOUSEMOVE)

var gIsMouseDown = false;
var gRepeatTimeInMS = 100;

var valorWidth = 0;
var valorHeight = 0; 

var gPopupMask       = null;
var gPopupContainer  = null;
var gPopFrame        = null;
var gReturnFunc;
var gPopupIsShown    = false;
var gHideSelects     = false;
var contextPath      = "";
var pagina           = "";
var carpeta          = "/htm_modal";
var tipoVentanaModal = "2";
var contenidoDiv     = "";
var capaCreada       = false;
var botonCerrar      = "";
var botonMaxMin      = "";
botonCerrar  = "<center><input type=button value='X'  onclick=hidePopWin() class=boton_cerrar_ventana></center><br>";
botonMaxMin   = "";//<center><input type=button value='Max/Min' onclick=hidePopWin() class=boton_cerrar_ventana></center><br>";

var gTabIndexes = new Array();
// Pre-defined list of tags we want to disable/enable tabbing into
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	

// If using Mozilla or Firefox, use Tab-key trap.
if (!document.all) {
	document.onkeypress = keyDownHandler;
}



/**
 * Initializes popup code on load.	
 */
function initPopUp(p_contenido, ancho, alto) {

        theBody = document.getElementsByTagName('BODY')[0];
        
        if(capaCreada==true){
        
            var n = document.getElementById ( "popupMask");
            theBody.removeChild (n);
            
            n = document.getElementById ( "popupContainer");
            theBody.removeChild (n);
        
            capaCreada = false;
        
        }

        if(capaCreada==false)
        {
            
            popmask    = document.createElement('div');
            popmask.id = 'popupMask';
            popcont    = document.createElement('div');
            popcont.id = 'popupContainer';
            
            capaCreada = true;
        } 
        if(p_contenido=="loading"){   
                        popcont.innerHTML = '' +
	                '<div id="popupInner" style="background-color:transparent; ">' + 
	                        '<div id="popupFrame"></div>' +
	                        '<div id="lauding"><img src="'+contextPath+'/imgs/cargando_xavao.gif" width="40" height="40" /></div>'+
	                        '<iframe src="" style="width:1px;height:1px;background-color:transparent;" scrolling="auto" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="1px" height="1px">'+
	                        '</iframe>' +
	                '</div>';   
        }
        
        else if(p_contenido=="sinbarra"){   
                       if(tipoVentanaModal=="1"){
	                
	                popcont.innerHTML = '' +
	                '<div id="popupInner">' +
	                        '<div id="popupTitleBar">' +
	                                '<div id="popupTitle"></div>' + botonCerrar +
	                        '</div>' + 
	                        '<div id="lauding"></div>'+
	                        '<iframe src='+pagina+' id="popupFrame" name="popupFrame" style="width:'+ancho+'px;height:'+alto+'px;background-color:transparent;" scrolling="auto" frameborder="0" allowtransparency="true"  >'+
	                        '</iframe>' +
	                        '<div id="popupPieBar">' +
	                                '<div id="popupPie"></div>' +  +
	                        '</div>' + 
	                        
	                '</div>';      
	        } else if(tipoVentanaModal == "0"){
	            
	                popcont.innerHTML = '' +
	                '<div id="popupInner">' +
	                        '<div id="popupTitleBar">' +
	                                '<div id="popupTitle"></div>' + botonCerrar +
	                        '</div>' + 
	                        '<div id="popupFrame">'+contenidoDiv+'</div>' +
	                        '<div id="popupPieBar">' +
	                                '<div id="popupPie"></div>' +  +
	                        '</div>' + 
	                '</div>';          
	        
	        
	        
	        } 
        }
        
        else
        {
	      
	        if(tipoVentanaModal=="1"){
	                
	                popcont.innerHTML = '' +
	                '<div id="popupInner">' +
	                        '<div id="popupTitleBar">' +
	                                '<div id="popupTitle"></div><div id="lauding"><img src="'+contextPath+'/imgs/cargando_xavao.gif"  width="40" height="40" /></div>' + botonCerrar +
	                        '</div>' + 
                                ''+
	                        '<div id="popupZona"><iframe id="popupFrame" name="popupFrame" src='+pagina+'  style="width:'+ancho+'px;height:'+alto+'px;background-color:transparent;" scrolling="auto" frameborder="0" allowtransparency="true"  >'+
	                        '</iframe> </div>' +
	                        
	                        '<div id="popupPieBar">' +
	                                '<div id="popupPie"></div>' +  +
	                        '</div>' + 
	                '</div>';      
	        } else if(tipoVentanaModal == "0"){
	            
	                popcont.innerHTML = '' +
	                '<div id="popupInner">' +
	                        '<div id="popupTitleBar">' +
	                                '<div id="popupTitle"></div>' + botonCerrar +
	                        '</div>' + 
	                        '<div id="popupFrame">'+contenidoDiv+'</div>' +
	                        '<div id="popupPieBar">' +
	                                '<div id="popupPie"></div>' +  +
	                        '</div>' + 
	                '</div>';          
	        
	        
	        
	        }
        }
        pagina = "";
        
        if(capaCreada==true)
        {
            theBody.appendChild(popmask);
            theBody.appendChild(popcont);
        }    

	gPopupMask = document.getElementById("popupMask");
	gPopupContainer = document.getElementById("popupContainer");
	gPopFrame = document.getElementById("popupFrame");	
	
	// check to see if this is IE version 6 or lower. hide select boxes if so
	// maybe they'll fix this in version 7?
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
		gHideSelects = true;
	}
	
	// Add onclick handlers to 'a' elements of class submodal or submodal-width-height
	var elms = document.getElementsByTagName('a');
	for (i = 0; i < elms.length; i++) {
		if (elms[i].className.indexOf("submodal") == 0) { 
			// var onclick = 'function (){showPopWin(\''+elms[i].href+'\','+width+', '+height+', null);return false;};';
			// elms[i].onclick = eval(onclick);
			elms[i].onclick = function(){
				// default width and height
				var width = 400;
				var height = 200;
				// Parse out optional width and height from className
				params = this.className.split('-');
				if (params.length == 3) {
					width = parseInt(params[1]);
					height = parseInt(params[2]);
				}
				//showPopWin(this.href,width,height); return false;
			}
		}
	}
}
//addEvent(window, "load", initPopUp);


 /**
	* @argument width - int in pixels
	* @argument height - int in pixels
	* @argument url - url to display
	* @argument returnFunc - function to call when returning true from the window.
	*/

function showPopWin(url, width, height, p_contextPath, p_tituloVentana, p_codigoBoton, p_codigoBotonMaxMin,p_subir) {
	
        var posicionx  = document.getElementById("Raton").RatonX.value;         
        var posiciony  = document.getElementById("Raton").RatonY.value;
        
        //alert("inicio posiciony "+ document.documentElement.scrollTop);
         
        var tamaniox_vent = document.getElementById("VentanaP").ventanaX.value;   
        var tamanioy_vent = document.getElementById("VentanaP").ventanaY.value;  
        
        diferenciaY = (parseInt((posiciony/tamanioy_vent))*(tamanioy_vent));
        //alert("n posicionx :"+posicionx+" - posiciony :"+posiciony +"////p_tamaņo _ventx :"+tamaniox_vent+" - p_tamaņo _vent y :"+tamanioy_vent);  
        //alert("posiciony :"+posiciony);
        //alert("tamanioy_vent :"+tamanioy_vent);
        //alert("residuo :"+(posiciony%tamanioy_vent));
        //alert("tamnaņo mitad :"+(tamanioy_vent/2));
        if ((posiciony%tamanioy_vent)>= (tamanioy_vent/2))
        {
            if (posiciony<tamanioy_vent)
            {
             // alert("zona 1  ");
               diferenciaY = ((parseInt((posiciony/tamanioy_vent)) )*(tamanioy_vent));
              // alert("diferenciaY "+diferenciaY);
              var IE3 = document.all?true:false
               if (!IE3) {
	               if ((posiciony%tamanioy_vent)!=0)
	               {
	                   diferenciaY = diferenciaY - (tamanioy_vent);
	               }
               }
               if (diferenciaY<0){
                diferenciaY=0;
               }
               
               posiciony = diferenciaY;

               var IE2 = document.all?true:false
	       if (!IE2)
                   window.scrollTo(0,posiciony);  
               if (IE2)
               setTimeout('window.scrollTo(0, '+posiciony+')',1);

            }
            else
            {
             //alert("zona 2  ");      
               var IE2 = document.all?true:false
	       if (!IE2)                   
               window.scrollTo(0,(posiciony-tamanioy_vent));  
               if (IE2)
               setTimeout('window.scrollTo(0, '+ posiciony-tamanioy_vent +')',1);
               

            }
        }
        else
        {
            if (posiciony<tamanioy_vent)
            {
              //alert("zona 4 " + posiciony+" - "+tamanioy_vent);
             //alert("n posicionx :"+posicionx+" - posiciony :"+posiciony +"////p_tamaņo _ventx :"+tamaniox_vent+" - p_tamaņo _vent y :"+tamanioy_vent);  
                     
               diferenciaY = ((parseInt((posiciony/tamanioy_vent)))*(tamanioy_vent));
               //diferenciaY = ((parseInt((posiciony/tamanioy_vent))+1)*(tamanioy_vent));
              var IE3 = document.all?true:false
               if (!IE3) {
               if ((posiciony%tamanioy_vent)!=0)
               {
                   diferenciaY = diferenciaY - (tamanioy_vent);
               }
               }


               if (diferenciaY<0){
                diferenciaY=0;
               }
               posiciony = diferenciaY;
              //alert("zona 4 " + posiciony+" - "+tamanioy_vent);
              
               var IE2 = document.all?true:false
	       if (!IE2)
               window.scrollTo(0,posiciony);  
               if (IE2)
               setTimeout('window.scrollTo(0, '+posiciony+')',1);
               
               
               //alert("zona 4" + posiciony+" - "+tamanioy_vent);
             
            }
            else
            {
              // alert("zona 3  "+getViewportHeight()); 
               diferenciaY = ((parseInt((posiciony/tamanioy_vent))-1)*(tamanioy_vent));
              var IE3 = document.all?true:false
               if (!IE3) {
               if ((posiciony%tamanioy_vent)!=0)
               {
                   diferenciaY = diferenciaY - (tamanioy_vent);
               }
               }             
               if (diferenciaY<0){
                   diferenciaY=0;
               }
               //alert("zona 3.1  "+diferenciaY); 
               posiciony = diferenciaY;   
              
               var IE2 = document.all?true:false
	       if (!IE2)
               window.scrollTo(0,(posiciony));  
               if (IE2)
               setTimeout('window.scrollTo(0, '+posiciony+')',1);
            
             
            }
        }
         
        if(height>tamanioy_vent)
        {
        
           height = tamanioy_vent -100;
        }
        
        if(width>tamaniox_vent)
        {
        
           width = tamaniox_vent -100;
        }           
        
        contextPath      = p_contextPath;
        pagina           = contextPath + carpeta + "/loading.html";
        botonCerrar      = p_codigoBoton;
        botonMaxMin      = p_codigoBotonMaxMin;        
        var paginaModal  = "";
        tipoVentanaModal = "1";
        

        paginaModal = contextPath + url;
        
        
        pagina = paginaModal;
        
        initPopUp("normal",width, height);
 
        gPopupIsShown = true;
	//disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
        
        
	centerPopWin(width, height,"normal",0,posiciony);
        	
	var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);

        document.getElementById("popupTitle").innerHTML = p_tituloVentana;
        
        //gPopFrame = document.getElementById("popupFrame");
        //gPopFrame.src = pagina;


	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";


	// set the url
        //gPopFrame.src = paginaModal;
	
	//gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	window.setTimeout("setPopTitle();", 600);
         var theRoot   = document.getElementById("popupContainer");

        theRoot.style.left   = "0px";
	theRoot.style.top    = "0px";
	theRoot.style.right  = "0px";
	theRoot.style.bottom = "0px";  
	
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "hidden";
		
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		theRoot.style.top = scTop + "px";
		theRoot.style.left = scLeft + "px";
		
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		//alert (scTop + " - " + fullHeight+ " - " +height+ " - " +titleBarHeight+ " - " +posiciony);
		if (!IE2)
		var posicion = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) +posiciony;
		
		if (IE2)
		var posicion = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) +posiciony;
		
		theRoot.style.top = posicion+ "px";
		theRoot.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";    
	       
         
         //Drag.init(theRoot);  

        
}

function showPopWinRespaldo(url, width, height, p_contextPath, p_tituloVentana, p_codigoBoton, p_codigoBotonMaxMin,p_subir) {
	
        scrollTo(0,0);         
        
        contextPath      = p_contextPath;
        pagina           = contextPath + carpeta + "/loading.html";
        botonCerrar      = p_codigoBoton;
        botonMaxMin      = p_codigoBotonMaxMin;        
        var paginaModal  = "";
        tipoVentanaModal = "1";
        

        paginaModal = contextPath + url;
        
        
        pagina = paginaModal;
        
        initPopUp("normal",width, height);
 
        gPopupIsShown = true;
	//disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
        
        
	centerPopWin(width, height,"normal",0,0);
        	
	var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);

        document.getElementById("popupTitle").innerHTML = p_tituloVentana;
        
        //gPopFrame = document.getElementById("popupFrame");
        //gPopFrame.src = pagina;


	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";


	// set the url
        //gPopFrame.src = paginaModal;
	
	//gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	window.setTimeout("setPopTitle();", 600);
         var theRoot   = document.getElementById("popupContainer");

        theRoot.style.left   = "0px";
	theRoot.style.top    = "0px";
	theRoot.style.right  = "0px";
	theRoot.style.bottom = "0px";  
	
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "hidden";
		
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		theRoot.style.top = scTop + "px";
		theRoot.style.left = scLeft + "px";
		
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		
		theRoot.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
		theRoot.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";    
	       
         
         //Drag.init(theRoot);   

        
}
function showPopWinMaximizado(url, width, height, p_contextPath, p_tituloVentana, p_codigoBoton, p_codigoBotonMaxMin) {
	
        scrollTo(0,0);         
        contextPath      = p_contextPath;
        pagina           = contextPath + carpeta + "/loading.html";
        botonCerrar      = p_codigoBoton;
        botonMaxMin      = p_codigoBotonMaxMin;        
        var paginaModal  = "";
        tipoVentanaModal = "1";
        height = screen.height-240;
        width = screen.width ;        

        paginaModal = contextPath + url;
        
        
        pagina = paginaModal;
        
        initPopUp("normal",width, height);
 
        gPopupIsShown = true;
	//disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
        
        
	centerPopWin("100%", height,"normal",0,0);
        	
	var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);

        document.getElementById("popupTitle").innerHTML = p_tituloVentana;
        
        //gPopFrame = document.getElementById("popupFrame");
        //gPopFrame.src = pagina;


	gPopupContainer.style.width = "100%";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	//gPopupContainer.style.height= "1000px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";


	// set the url
        //gPopFrame.src = paginaModal;
	
	//gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	window.setTimeout("setPopTitle();", 600);
         var theRoot   = document.getElementById("popupContainer");

        theRoot.style.left   = "0px";
	theRoot.style.top    = "0px";
	theRoot.style.right  = "0px";
	theRoot.style.bottom = "0px";  
	
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "hidden";
		
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		theRoot.style.top = scTop + "px";
		theRoot.style.left = scLeft + "px";
		
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		
		//theRoot.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
		//theRoot.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";    
	       
         
         //Drag.init(theRoot);   

        
}


function showPopWinPosicion(url, width, height, p_contextPath, p_tituloVentana, p_codigoBoton,p_posicionx,p_posiciony,inicio,bloquear, p_codigoBotonMaxMin) 
{
	
        var posicionx  = document.getElementById("Raton").RatonX.value;         
        var posiciony  = document.getElementById("Raton").RatonY.value;
        
        //alert("inicio posiciony "+ document.documentElement.scrollTop);
         
        var tamaniox_vent = document.getElementById("VentanaP").ventanaX.value;   
        var tamanioy_vent = document.getElementById("VentanaP").ventanaY.value;  
        
        diferenciaY = (parseInt((posiciony/tamanioy_vent))*(tamanioy_vent));
        //alert("n posicionx :"+posicionx+" - posiciony :"+posiciony +"////p_tamaņo _ventx :"+tamaniox_vent+" - p_tamaņo _vent y :"+tamanioy_vent);  
        //alert("posiciony :"+posiciony);
        //alert("tamanioy_vent :"+tamanioy_vent);
        //alert("residuo :"+(posiciony%tamanioy_vent));
        //alert("tamnaņo mitad :"+(tamanioy_vent/2));
        if ((posiciony%tamanioy_vent)> (tamanioy_vent/2))
        {
            if (posiciony<tamanioy_vent)
            {
              //alert("zona 1  ");
               diferenciaY = ((parseInt((posiciony/tamanioy_vent)) )*(tamanioy_vent));
              // alert("diferenciaY "+diferenciaY);
               if (diferenciaY<0){
                diferenciaY=0;
               }
               posiciony = diferenciaY;

               var IE2 = document.all?true:false
	       if (!IE2)
                   window.scrollTo(0,posiciony);  
               if (IE2)
               setTimeout('window.scrollTo(0, '+posiciony+')',1);

            }
            else
            {
             //alert("zona 2  ");      
               var IE2 = document.all?true:false
	       if (!IE2)                   
               window.scrollTo(0,(posiciony-tamanioy_vent));  
               if (IE2)
               setTimeout('window.scrollTo(0, '+ posiciony-tamanioy_vent +')',1);
               

            }
        }
        else
        {
            if (posiciony<tamanioy_vent)
            {
              //alert("zona 4" + posiciony+" - "+tamanioy_vent);
             //alert("n posicionx :"+posicionx+" - posiciony :"+posiciony +"////p_tamaņo _ventx :"+tamaniox_vent+" - p_tamaņo _vent y :"+tamanioy_vent);  
                     
               diferenciaY = ((parseInt((posiciony/tamanioy_vent)))*(tamanioy_vent));
               //diferenciaY = ((parseInt((posiciony/tamanioy_vent))+1)*(tamanioy_vent));
               if (diferenciaY<0){
                diferenciaY=0;
               }
               posiciony = diferenciaY;
               
               var IE2 = document.all?true:false
	       if (!IE2)
               window.scrollTo(0,posiciony);  
               if (IE2)
               setTimeout('window.scrollTo(0, '+posiciony+')',1);
               
               
               //alert("zona 4" + posiciony+" - "+tamanioy_vent);
             
            }
            else
            {
              //  alert("zona 3  "+getViewportHeight()); 
               diferenciaY = ((parseInt((posiciony/tamanioy_vent))-1)*(tamanioy_vent));
               if (diferenciaY<0){
                   diferenciaY=0;
               }
               //alert("zona 3.1  "+diferenciaY); 
               posiciony = diferenciaY;   
              
               var IE2 = document.all?true:false
	       if (!IE2)
               window.scrollTo(0,(posiciony));  
               if (IE2)
               setTimeout('window.scrollTo(0, '+posiciony+')',1);
            
             
            }
        }
         
        if(height>tamanioy_vent)
        {
        
           height = tamanioy_vent -100;
        }
        
        if(width>tamaniox_vent)
        {
        
           width = tamaniox_vent -100;
        }           
        
        contextPath      = p_contextPath;
        pagina           = contextPath + carpeta + "/loading.html";
        botonCerrar      = p_codigoBoton;
        botonMaxMin      = p_codigoBotonMaxMin;        
        var paginaModal  = "";
        tipoVentanaModal = "1";
        

        paginaModal = contextPath + url;
        
        
        pagina = paginaModal;
        
        initPopUp("normal",width, height);
 
        gPopupIsShown = true;
	//disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
        
        
	centerPopWin(width, height,"normal",0,posiciony);
        	
	var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);

        document.getElementById("popupTitle").innerHTML = p_tituloVentana;
        
        //gPopFrame = document.getElementById("popupFrame");
        //gPopFrame.src = pagina;


	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";


	// set the url
        //gPopFrame.src = paginaModal;
	
	//gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	window.setTimeout("setPopTitle();", 600);
         var theRoot   = document.getElementById("popupContainer");

        theRoot.style.left   = "0px";
	theRoot.style.top    = "0px";
	theRoot.style.right  = "0px";
	theRoot.style.bottom = "0px";  
	
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "hidden";
		
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		theRoot.style.top = scTop + "px";
		theRoot.style.left = scLeft + "px";
		
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		//alert (scTop + " - " + fullHeight+ " - " +height+ " - " +titleBarHeight+ " - " +posiciony);
		if (!IE2)
		var posicion = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) +posiciony;
		
		if (IE2)
		var posicion = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) +posiciony;
		
		theRoot.style.top = posicion+ "px";
		theRoot.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";    
	       
         
         //Drag.init(theRoot);   

        
}


function showPopWinSinBarra(url, width, height, p_contextPath, p_tituloVentana, p_codigoBoton, p_codigoBotonMaxMin) 
{
	var posicionx  = document.getElementById("Raton").RatonX.value;         
        var posiciony  = document.getElementById("Raton").RatonY.value;
        
        //alert("inicio posiciony "+ document.documentElement.scrollTop);
         
        var tamaniox_vent = document.getElementById("VentanaP").ventanaX.value;   
        var tamanioy_vent = document.getElementById("VentanaP").ventanaY.value;  
        
        diferenciaY = (parseInt((posiciony/tamanioy_vent))*(tamanioy_vent));
        //alert("n posicionx :"+posicionx+" - posiciony :"+posiciony +"////p_tamaņo _ventx :"+tamaniox_vent+" - p_tamaņo _vent y :"+tamanioy_vent);  
        //alert("posiciony :"+posiciony);
        //alert("tamanioy_vent :"+tamanioy_vent);
        //alert("residuo :"+(posiciony%tamanioy_vent));
        //alert("tamnaņo mitad :"+(tamanioy_vent/2));
        if ((posiciony%tamanioy_vent)> (tamanioy_vent/2))
        {
            if (posiciony<tamanioy_vent)
            {
              //alert("zona 1  ");
               diferenciaY = ((parseInt((posiciony/tamanioy_vent)) )*(tamanioy_vent));
              // alert("diferenciaY "+diferenciaY);
               if (diferenciaY<0){
                diferenciaY=0;
               }
               posiciony = diferenciaY;

               var IE2 = document.all?true:false
	       if (!IE2)
                   window.scrollTo(0,posiciony);  
               if (IE2)
               setTimeout('window.scrollTo(0, '+posiciony+')',1);

            }
            else
            {
             //alert("zona 2  ");      
               var IE2 = document.all?true:false
	       if (!IE2)                   
               window.scrollTo(0,(posiciony-tamanioy_vent));  
               if (IE2)
               setTimeout('window.scrollTo(0, '+ posiciony-tamanioy_vent +')',1);
               

            }
        }
        else
        {
            if (posiciony<tamanioy_vent)
            {
              //alert("zona 4  " + posiciony+" - "+tamanioy_vent);
             //alert("n posicionx :"+posicionx+" - posiciony :"+posiciony +"////p_tamaņo _ventx :"+tamaniox_vent+" - p_tamaņo _vent y :"+tamanioy_vent);  
                     
               diferenciaY = ((parseInt((posiciony/tamanioy_vent)))*(tamanioy_vent));
               //diferenciaY = ((parseInt((posiciony/tamanioy_vent))+1)*(tamanioy_vent));
               if (diferenciaY<0){
                diferenciaY=0;
               }
               posiciony = diferenciaY;
               
               var IE2 = document.all?true:false
	       if (!IE2)
               window.scrollTo(0,posiciony);  
               if (IE2)
               setTimeout('window.scrollTo(0, '+posiciony+')',1);
               
               
               //alert("zona 4" + posiciony+" - "+tamanioy_vent);
             
            }
            else
            {
              //  alert("zona 3  "+getViewportHeight()); 
               diferenciaY = ((parseInt((posiciony/tamanioy_vent))-1)*(tamanioy_vent));
               if (diferenciaY<0){
                   diferenciaY=0;
               }
               //alert("zona 3.1  "+diferenciaY); 
               posiciony = diferenciaY;   
              
               var IE2 = document.all?true:false
	       if (!IE2)
               window.scrollTo(0,(posiciony));  
               if (IE2)
               setTimeout('window.scrollTo(0, '+posiciony+')',1);
            
             
            }
        }
         
        if(height>tamanioy_vent)
        {
        
           height = tamanioy_vent -100;
        }
        
        if(width>tamaniox_vent)
        {
        
           width = tamaniox_vent -100;
        }           
        
        contextPath      = p_contextPath;
        pagina           = contextPath + carpeta + "/loading.html";
        botonCerrar      = p_codigoBoton;
        botonMaxMin      = p_codigoBotonMaxMin;        
        var paginaModal  = "";
        tipoVentanaModal = "1";
        

        paginaModal = contextPath + url;
        
        
        pagina = paginaModal;
         initPopUp("sinbarra",width, height);
        //initPopUp("normal",width, height);
 
        gPopupIsShown = true;
	//disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
        
        
	centerPopWin(width, height,"normal",0,posiciony);
        	
	var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);

        document.getElementById("popupTitle").innerHTML = p_tituloVentana;
        
        //gPopFrame = document.getElementById("popupFrame");
        //gPopFrame.src = pagina;


	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";


	// set the url
        //gPopFrame.src = paginaModal;
	
	//gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	window.setTimeout("setPopTitle();", 600);
         var theRoot   = document.getElementById("popupContainer");

        theRoot.style.left   = "0px";
	theRoot.style.top    = "0px";
	theRoot.style.right  = "0px";
	theRoot.style.bottom = "0px";  
	
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "hidden";
		
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		theRoot.style.top = scTop + "px";
		theRoot.style.left = scLeft + "px";
		
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		//alert (scTop + " - " + fullHeight+ " - " +height+ " - " +titleBarHeight+ " - " +posiciony);
		if (!IE2)
		var posicion = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) +posiciony;
		
		if (IE2)
		var posicion = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) +posiciony;
		
		theRoot.style.top = posicion+ "px";
		theRoot.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";    
	       
         
         //Drag.init(theRoot);  	
         

        
}


function showPopWinDiv(p_contenido, p_tituloVentana, p_contextPath, width, height) {

        scrollTo(0,0);
        contextPath      = p_contextPath;
        tipoVentanaModal = "0";
        contenidoDiv     = p_contenido;
        
        //addEvent(window, "load", initPopUp);
        ver_p_contenido = p_contenido;
        if(p_contenido=="loading"){
            p_contenido = '<img src="'+p_contextPath+'/imgs/cargando_xavao.gif" width="40" height="40" />';
        } else if(p_contenido=="sinbarra"){
            p_contenido = '<img src="'+p_contextPath+'/imgs/cargando_xavao.gif" width="40" height="40"/>';
        }
        contenidoDiv = p_contenido;
        
        initPopUp(ver_p_contenido,width, height);
        
        gopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
        
        // calculate where to place the window on screen
	centerPopWin(width, height,ver_p_contenido,0,0);
	
        if(ver_p_contenido=="loading"){   
	   var titleBarHeight = 0;
        }
        else if(ver_p_contenido=="sinbarra"){   
	   var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
        }
        else
        {
	   var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);

        }
        
        //document.getElementById("popupTitle").innerHTML = "";//p_tituloVentana;
        if(ver_p_contenido=="loading"){   
            document.getElementById("popupFrame").innerHTML = "";
        }
        else if(ver_p_contenido=="sin barra"){   
            document.getElementById("popupFrame").innerHTML = "";
        }
        else
        {
           document.getElementById("popupFrame").innerHTML = p_contenido;
        }


	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();
        
    	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	//gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	//gPopFrame.style.height = (height) + "px";
	
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	 window.setTimeout("setPopTitle();", 600);
	 var theRoot   = document.getElementById("popupContainer");

       
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "hidden";
		
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		theRoot.style.top = scTop + "px";
		theRoot.style.left = scLeft + "px";
		
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		
		theRoot.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
		theRoot.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";    
	       
	       	 
         //Drag.init(theRoot);   
}


//
var gi = 0;
function centerPopWin(width, height,p_contenido,suma_w,suma_h) {
        
        
	if (gPopupIsShown == true) {
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		//var theBody = document.documentElement;
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "hidden";
		

		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		gPopupMask.style.top = scTop + "px";
		gPopupMask.style.left = scLeft + "px";
	
		setMaskSize();
		
		//window.status = gPopupMask.style.top + " " + gPopupMask.style.left + " " + gi++;
		if(p_contenido=="loading"){ 
   		    var titleBarHeight = 0;
		}
		else if(p_contenido=="sinbarra"){ 
   		    var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
		}
		else
		{
		   var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
		}
		
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		
		gPopupContainer.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) +suma_h+ "px";
		gPopupContainer.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";               

	}
}
//addEvent(window, "resize", centerPopWin);
//addEvent(window, "scroll", centerPopWin);
addEvent(window, "load", preCargaImagenes);

//window.onscroll = centerPopWin;

/**
 * Sets the size of the popup mask.
 *
 */
function setMaskSize() {
	var theBody = document.getElementsByTagName("BODY")[0];
			
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	
	// Determine what's bigger, scrollHeight or fullHeight / width
	if (fullHeight > theBody.scrollHeight) {
		popHeight = fullHeight;
	} else {
		popHeight = theBody.scrollHeight;
	}
	
	if (fullWidth > theBody.scrollWidth) {
		popWidth = fullWidth;
	} else {
		popWidth = theBody.scrollWidth;
	}
	
	gPopupMask.style.height = popHeight + "px";
	gPopupMask.style.width = popWidth + "px";
}

/**
 * @argument callReturnFunc - bool - determines if we call the return function specified
 * @argument returnVal - anything - return value 
 */
function hidePopWin(callReturnFunc) {
	gPopupIsShown = false;
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "";
	restoreTabIndexes();
	if (gPopupMask == null) {
		return;
	}
	gPopupMask.style.display = "none";
	gPopupContainer.style.display = "none";
	
        if (callReturnFunc == true && gReturnFunc != null) {
		gReturnFunc(window.frames["popupFrame"].returnVal);
	}
        
	gPopFrame.src = pagina;
        
	// display all select boxes
	if (gHideSelects == true) {
		displaySelectBoxes();
	}
        
        document.getElementById("popupFrame").innerHTML = '';


        
}
function hidePopWinRefre(callReturnFunc) {
	gPopupIsShown = false;
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "";
	restoreTabIndexes();
	if (gPopupMask == null) {
		return;
	}
	gPopupMask.style.display = "none";
	gPopupContainer.style.display = "none";
	
        if (callReturnFunc == true && gReturnFunc != null) {
		gReturnFunc(window.frames["popupFrame"].returnVal);
	}
        
	gPopFrame.src = pagina;
        
	// display all select boxes
	if (gHideSelects == true) {
		displaySelectBoxes();
	}
        
        //document.getElementById("popupFrame").innerHTML = '';
    //alert("cerrando submodal");
    //if (refrescar== "S")
	//{
		showPopWinDiv('loading', 'Cargando zona, por favor espere...', contextPath, 90, 20);
		javascript:location.reload();
	//}

        
}
function hidePopWinAncla(callReturnFunc, capa) {
	gPopupIsShown = false;
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "";
	restoreTabIndexes();
	if (gPopupMask == null) {
		return;
	}
	gPopupMask.style.display = "none";
	gPopupContainer.style.display = "none";
	
        if (callReturnFunc == true && gReturnFunc != null) {
		gReturnFunc(window.frames["popupFrame"].returnVal);
	}
        
	gPopFrame.src = pagina;
        
	// display all select boxes
	if (gHideSelects == true) {
		displaySelectBoxes();
	}
        irA(capa);
        document.getElementById("popupFrame").innerHTML = '';
        

        
}
/**
 * Sets the popup title based on the title of the html document it contains.
 * Uses a timeout to keep checking until the title is valid.
 */
function setPopTitle() {
	return;
	if (window.frames["popupFrame"].document.title == null) {
		window.setTimeout("setPopTitle();", 10);
	} else {
		document.getElementById("popupTitle").innerHTML = window.frames["popupFrame"].document.title;
                
	}
}

// Tab key trap. iff popup is shown and key was [TAB], suppress it.
// @argument e - event - keyboard event that caused this function to be called.
function keyDownHandler(e) {
    if (gPopupIsShown && e.keyCode == 9)  return false;
}

// For IE.  Go through predefined tags and disable tabbing into them.
function disableTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				gTabIndexes[i] = tagElements[k].tabIndex;
				tagElements[k].tabIndex="-1";
				i++;
			}
		}
	}
}

// For IE. Restore tab-indexes.
function restoreTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				tagElements[k].tabIndex = gTabIndexes[i];
				tagElements[k].tabEnabled = true;
				i++;
			}
		}
	}
}


/**
* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*
* Thanks for the code Scott!
*/
function hideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}

/**
* Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*/
function displaySelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}





function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}


function preCargaImagenes(){

            var n = document.getElementsByTagName('BODY')[0];
            
            preloadedImages     = document.createElement('div');
            preloadedImages.id  = 'preloadedImages';
            preloadedImages2    = document.createElement('div');
            preloadedImages2.id = 'preloadedImages2';

            document.body.appendChild (preloadedImages);
            document.body.appendChild (preloadedImages2);

}


function getMouseXY(e) {


    
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  

  return true
}

function MoverVentana()
{
   id=document.getElementById("popupContainer");
   Drag.init(id); 
}



function mouseOver(e){
    
   id=document.getElementById("popupContainer");
   DimeXY.init(id); 
   
   id2=document.getElementById("popupFrame");    
   DimeXY.init(id2); 
        
}

function setMouseUp2()
{
    id=document.getElementById("popupContainer");
    DimeXY2.init(id); 

}

function setMouseUp()
{
    id=document.getElementById("popupContainer");
    Drag2.init(id); 
}



