// JavaScript Document

//////////////////////////////////////////////////////////////////////////
/************************************************************************/
//FUNCTION:popUpWindow
//Parametros: URLStr. Dirección de la página a abrir
//			  left. Posicion izquierda
//            top. Posición superior
//            ancho. Ancho de la ventana
//            alto. alto de la ventana
//   
//Comentarios : Abre un pop-up o ventana emergente
//////////////////////////////////////////////////////////////////////////
/************************************************************************/
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

//////////////////////////////////////////////////////////////////////////
/************************************************************************/
//FUNCTION:abrirVentanaCentrada
//Parametros: url. Dirección de la página a abrir
//            ancho. Ancho de la ventana
//            alto. Alto de la ventana
//Comentarios : Abre una ventana normal con navegacion y redimensionable
//////////////////////////////////////////////////////////////////////////
/************************************************************************/
function abrirVentanaCentrada(url,ancho,alto) {
		izquierda=(screen.width-ancho)/2;
		arriba=(screen.height-alto)/2;
		window.open(url, 'nueva', 'toolbar=yes,location=yes,directories=yes, status=yes, height=' + alto + ', width=' + ancho + ', left='+izquierda+', top='+arriba+', scrollbars=yes,resizable=yes');
}

/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

//Usar iframe como buffer
function loadExternal(url) {
  if ( window.frames['contenido'] ) {
    window.frames['contenido'].location = url;
    var lyr = document.getElementById? document.getElementById('display'): document.all? document.all['display']: null;
    if ( lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = '<img src="../../images/loading.gif" alt="">';
    }
    return false;
  } 
  return true; // other browsers follow link
}

// called when documents loaded into iframe (from their body's onload attribute)
function displayExternal() {
  var lyr = document.getElementById? document.getElementById('display'): document.all? document.all['display']: null;
    if ( window.frames['contenido'] && lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = window.frames['contenido'].document.body.innerHTML;
    }
}

//Cambia titulo del iframe a partir de capa invisible
function cambiaTitulo() {
	//alert(document.getElementById("titulo").innerHTML);
	//alert(window.frames['contenido'].document.getElementById("tituloInvisible").innerHTML);
	var lyr = window.frames['contenido'].document.getElementById? window.frames['contenido'].document.getElementById('tituloInvisible'): document.all? window.frames['contenido'].document.all['tituloInvisible']: null;
	if ( window.frames['contenido'] && lyr && typeof lyr.innerHTML != "undefined" ) {
      	document.getElementById("titulo").innerHTML = window.frames['contenido'].document.getElementById("tituloInvisible").innerHTML;
    }else{
		document.getElementById("titulo").innerHTML = 'Sin titulo'
	}
}

//scroll para iframe
var timer_id;
function scroll_iframe(frm,inc,dir) {
  if (timer_id) clearTimeout(timer_id);
  if (window.frames[frm]) {
    if (dir == "v") window.frames[frm].scrollBy(0, inc);
    else window.frames[frm].scrollBy(inc, 0);
    timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 20);
  }
}

function stopScroll() { if (timer_id) clearTimeout(timer_id); }

//Para centrar iframe
function setIframe(h) {
  var theIframe = document.getElementById? document.getElementById('ifrm'): document.all? document.all['ifrm']: null;
  if (theIframe) {
    viewport.getWinHeight();
    //  both theIframe.height and theIframe.style.height seem to work 
    theIframe.style.height = Math.round( h * viewport.height ) + "px";
    theIframe.style.marginTop = Math.round( (viewport.height - parseInt(theIframe.style.height) )/2 ) + "px";
  }
}

// for sizing and positioning the iframe in the window
// .5 for height="50%"
//setIframe(.8);
//window.onresize = function() { setIframe(.8) }

//cargar iframe
function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;   
    return false;
  }
  else return true;
}