/*

Proposito
---------
Implementar la funcionalidad de los recortes en el sitio web.

Esto es:
  - Agregar recortes.
  - Eliminar recortes.
  - Marcar recortes como leidos, cuando lo son.
  - Desplegar texto de ayuda cuando no hay ningun recorte.

Autor
-----
1.0 - MCO - 03/10/2003.
1.1 - MCO - 23/06/2004. Se agrega funcion cambia_wmode() para cambiar wmode a banners externos,
                  con ID plenamente identificados.

*/

var recTodos = new Array();     // Estructura de datos de todos los recortes de la pagina.
var recEscogidos = new Array(); // Recortes seleccionados por el usuario.
var recLeidos = new Array();    // Recortes ya leidos.
var menus = new Array("Recortes");
var menuActivo = null; // Define cual menu esta actualmente activo.
var recorteActual = 0; // Recorte activo (para agregar, eliminar o marcar).
var tot_iteracion = 15; // Total de veces que va a "moverse" la tijera hacia la barra de recortes.

// Detecta IE.
var IE = document.all?true:false;

var BROWSER_VALIDO = false;
var IE6 = false;
var NS6 = false;
var OPERA = false;

var frameHead = parent.headdrs;
var frameCont = parent.contdrs;

// alert(navigator.appName + ' /// ' + parseInt(navigator.appVersion) + ' /// ' + navigator.userAgent + ' /// ' + navigator.userAgent.indexOf('MSIE 5'));
if (navigator.userAgent.indexOf('Opera') > 0) {
  var TOP_BARRA = 55; // 45;
  BROWSER_VALIDO = true;
  OPERA = true;
}
else if ( (navigator.appName == "Netscape") || (navigator.appName == "Microsoft Internet Explorer") ) {
	if (parseInt(navigator.appVersion) >= 5) {
	  BROWSER_VALIDO = true;
	  var TOP_BARRA = 55; // 45;
	  NS6 = true;
	}
	else if ( (navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0) ) {
	  BROWSER_VALIDO = true;
	  var TOP_BARRA = 55;

	  if (navigator.userAgent.indexOf('MSIE 6') > 0) {
	    IE6 = true;
	  };
	};
};

css_recortes(); // Carga los css de los recortes.


// Define atributo para crear objeto.
if (IE) {
  classFix = "className";
}
else {
  classFix = "class";
  document.captureEvents(Event.MOUSEMOVE);
  // frameHead.document.captureEvents(Event.MOUSEMOVE);
  document.captureEvents(Event.MOUSEMOVE);
};


// Posicion de origen y destino de la tijera.
var x0 = 0, x1 = 700, y0 = 0, y1 = 200, x, y, dx, dy, iteracion;

// Codigo para la captura de la posicion del mouse en la pagina.
var mouseX = mouseY = 0;

// Setea funcion getMouseXY para el evento onmousemove.
document.onmousemove = getMouseXY;

// Variable temporales para las coordenadas del mouse.
var tempX = 0;
var tempY = 0;

// -----------------------------------------------------------
function windowResize()  {
  // Posicionamiento de la barra de recortes.
  posHeadBar();

  if (document.getElementById("cuerpoArticulo") != null) seteoAltura_Articulo(); //adjust article layout

  // Cambia el alto del contenedor de acuerdo al alto de la pagina.
  recCambia_AltoContenedor();
}; // windowResize.

// -----------------------------------------------------------
//Esta funcion la ejecuta el onLoad del body. Es la funcion que inicia los recortes.
function initialize() {

  if (! BROWSER_VALIDO) {
    return;
  };

  obj = document.getElementById("BarraCont"); // Div principal donde se encuentran los recortes.
  obj.style.top = TOP_BARRA + "px"; //Fija un bug en la animacion de recortes.

  // Objeto para referencias espaciales.
  prontusScreen = new screenObject();

  if (document.getElementById("cuerpoArticulo")) inicializa_Articulo();	  // Despliega el articulo en columnas si existe.
  // inicioAcciones_divsMenu(); // Setea todos los eventos de usuario.


  // Timers y handlers generales.
  HeadBarTimer = setTimeout('setInterval("posHeadBar()",100)', 2000);

  // Al cambiar de tamano la ventana, llama a la funcion windowResize.
  window.onresize = windowResize;
  setTimeout("inicio_Recortes()", 4000); // Inicializa los recortes.
}; // initialize.

// -----------------------------------------------------------
// Funcion principal para obtener las coordenadas del mouse en la ventana.
function getMouseXY(e) {
  if (IE) { // Graba las posiciones x-y si el browser es IE.
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  }
  else {    // Graba las posiciones x-y si el browser es NS.
    tempX = e.pageX;
    tempY = e.pageY;

  };
  // Capturando posibles valores negativos en NS4.
  if (tempX < 0) { tempX = 0; };
  if (tempY < 0) { tempY = 0; };
  mouseX = tempX;
  mouseY = tempY;
  return true;
}; // getMouseXY

// -----------------------------------------------------------
// Objeto que encapsula las distintas formas de obtener datos de la pantalla.
function screenObject() {
  this.bottom = function() {
    if (document.body.scrollHeight) return document.body.scrollHeight};
  this.height = function() {
    if (document.body.offsetHeight) return document.body.offsetHeight;};
  this.visHeight = function() {
    if (window.innerHeight) return window.innerHeight;
    if (document.body.clientHeight) return document.body.clientHeight;};
  this.width = function() {
    if (document.body.offsetWidth) return document.body.offsetWidth;};
  this.scrollTop = function() {
    if(document.body.scrollTop) return document.body.scrollTop;
    if (window.pageYOffset) return window.pageYOffset;
    else return 0;};
  this.scrollLeft = function() {
    if(document.body.scrollLeft) return document.body.scrollLeft;
    if (window.pageXOffset) return window.pageXOffset;
    else return 0;};
}; // screenObject.

// -----------------------------------------------------------
// Posicionamiento de la barra Head.
function posHeadBar() {

  obj = document.getElementById("BarraCont");

  // ScrollTop lleva parentesis porque es una funcion generica. Ver la funcion ScreenObject.
  if (prontusScreen.scrollTop() > TOP_BARRA) {
    obj.style.top = prontusScreen.scrollTop() + "px";
    document.getElementById("menuRecortes").style.top = prontusScreen.scrollTop();
  }
  else {
    obj.style.top = TOP_BARRA + "px";

    document.getElementById("menuRecortes").style.top = TOP_BARRA + 'px';
  };
}; // posHeadBar.

// -----------------------------------------------------------
// Detecta los articulos con recorte habilitado en la pagina web (rescatandolos de una cookie) y
// crea un arreglo con ellos. Ademas, actualiza la visibilidad del iconito.
function crea_recTodosArray() {
  recTodos    = new Array();
  var losdivs = document.getElementsByTagName("DIV");
  var alt = '';
  var id = '';
  for (i=0; i < losdivs.length; i++) {
    if (losdivs[i].id.indexOf("rec") > -1) {
      id = losdivs[i].id;
      losdivs[i].style.visibility = "visible";
      // Busca el recorte entre los leidos. Si esta, lo invisibiliza.
      for (j=0; j < recEscogidos.length; j++) {
        if (id == recEscogidos[j].id) {
          losdivs[i].style.visibility = "hidden";
          break;
        };
      };
      losdivs[i].onclick = addRecorte;

      eval("alt = t" + id); // Titular. Para no ocupar el alt de la imagen.
      if (alt == '') {
        eval('alt = document.getElementsByName("i' + id + '")[0].alt');
      };
      eval('var path = v' + id);
      // path = document.getElementsByName("rec" + id)[0].path;

      recTodos[recTodos.length] = new Recorte(id,alt,path,false);
    };
  };
}; // crea_recTodosArray.

// -----------------------------------------------------------
// Este evento es gatillado cuando un recorte es clickeado.
function addRecorte()   {
  nuevoRecorte = this.id;

  duplicate = false;
  var pos = 0;
  for (i=0; i < recTodos.length; i++) { // Encuentra la posicion del recortes seleccionado dentro del arreglo recTodos.
    if (nuevoRecorte == recTodos[i].id) {pos = i; i = recTodos.length};
  };

  if (recEscogidos.length > 0) chequea_recortesDuplicados(); // Verifica que el recorte no fue seleccionado anteriormente.
  if (!duplicate) {
    chequeo_aceptaCookies(); // Chequea si el browser acepta cookies.
    if (cookiesOn == true) {
      // Crea nuevo objeto recorte y lo agrega a un arreglo.
      // eval('var path = v' + recTodos[pos].id);
      recEscogidos[recEscogidos.length] = new Recorte(recTodos[pos].id,recTodos[pos].titular,recTodos[pos].path);

      recorteInstancia_Visibility(this.id,'hidden'); // Encuentra todas las instancias del recorte en la pagina y las esconde.

      // Obtiene la posicion inicial del recorte para encontrar la posicion del mouse.
      x0 = mouseX;
      y0 = mouseY;

      // Entrega la posicion donde se encuentra el boton en el div de la barra.
      // obj = frameCont.document.getElementById("BarraCont");
      obj = document.getElementById("BarraCont");
      x1 = 740;
      y1 = parseInt(obj.style.top);

      despliega_Recortes();

      if (document.all) event.cancelBubble = true;

      // actualiza_contadorRecortes();
      self.setTimeout('actualiza_contadorRecortes()', 500);

      graba_cookieRecortes();

      // Deja con valores iniciales las variables que se usan para el movimiento de la imagen tijera.
      x = x0; y = y0; dx = (x1 - x0) / tot_iteracion; dy = (y1 - y0) / tot_iteracion; iteracion = 0;
      tijeraTimer = setInterval("moverTijera()",tot_iteracion); // Mueve imagen tijera.



    };
  };
}; // addRecorte.

// -----------------------------------------------------------
// Inicializa un objeto de clase Recorte.
function Recorte(id,titular,path,leido) {
  this.id = id;

  // Los codigos html siguientes, hacen que de error en el js, ya que terminan en ; y el texto se corta.
  // Estos codigos los agrega Yerko desde el prontus.
  expReg = /\&\#39\;/;
  titular = titular.replace(expReg, "'");

  expReg = /\&quot\;/;
  titular = titular.replace(expReg, '"');

  expReg = /\&amp\;/;
  titular = titular.replace(expReg, "&");

  this.titular = titular;
  this.path = path;
  this.leido = leido;
  this.clicked = marca_leido; // No usado.
}; // Recorte.

// -----------------------------------------------------------
// Hace volar la tijera hacia la barra donde esta el menu.
function moverTijera() {
  if (iteracion < tot_iteracion) {
    x = x0 + iteracion * dx;
    y = y0 + iteracion * dy;
    document.getElementById("tijera").style.left = x;

    if (document.getElementById("cuerpoArticulo") != null) {
      document.getElementById("tijera").style.top  = y;
    }
    else {
      document.getElementById("tijera").style.top  = y; // - y1;
    };

    document.getElementById("tijera").style.visibility = "visible";
    iteracion++;
  }else{
    document.getElementById("tijera").style.visibility = "hidden";
    clearInterval(tijeraTimer);
  };
}; // moverTijera.

// -----------------------------------------------------------
// Lee los recortes seleccionados del usuario desde la cookie.
function getRecortesFromCookie()  {
  var recortes = null;
  var aux = document.cookie.split(";");
  var x = -1;
  for (i = 0; i < aux.length; i++)  {
    if (aux[i].indexOf('recs=') > -1) { // Encuentra la seccion de los recortes.
      inicio = aux[i].indexOf("=") + 2;
      recortes = aux[i].substring(inicio,aux[i].length);
      break;
    };
  };

  if (recortes != null) {
    aux = recortes.split("|");
    if (aux.length > 1) {
      x = 0;
      for (i = 0; i < aux.length/4; i++) {
        recEscogidos[i] = new Recorte(aux[x],aux[x+1],aux[x+2],aux[x+3]); // id,titular,leido.
        x+=4;
      };
    };
  };
}; // getRecortesFromCookie

// -----------------------------------------------------------
// Dibuja los recortes (html) en el menu de recortes cuando se presiona la imagen de la barra de recortes.
function despliega_Recortes() {
  newHTML = "";

  if (recEscogidos.length < 1) {
    // Texto de ayuda cuando no hay recortes.
    newHTML = "<span class='recorteItem'>No hay recortes grabados.  Para agregar uno, haga click en un ícono:";
    newHTML += "<img src='/prontus_providencia/imag/head/recorteFantasma.gif'><br><br>";
    newHTML += "Usted puede acceder a sus recortes a través de este menú, o haciendo click sobre el número a la derecha del menú de recortes.  Ese número representa los recortes no leídos.";
  };

  for (i=0; i < recEscogidos.length; i++) {
    recorte = recEscogidos[i];

    // OJO: Esto no funciona en IE5 para Mac.
    if (recorte.leido == "yes") {
      tClass = "recorteItemRead";
    }
    else {
      tClass = "recorteItem";
    };

    // Genera los links de los articulos seleccionados.
    newHTML += '<a href="' + recorte.path + '" onmousedown="marca_leido(' + "'" + recorte.id + "'" + ');" class="' + tClass + '" id="cLink' + recorte.id + '">';
    newHTML += unescape(recorte.titular) +"</a>";
  };

  // frameCont.obj = frameCont.document.getElementById("rContainer"); // Objeto que contendra los links.
  obj = document.getElementById("rContainer"); // Objeto que contendra los links.
  // obj.style.top = frameCont.document.body.scrollTop + 'px';
  obj.style.top = document.body.scrollTop + 'px';
  obj.innerHTML = newHTML;

  recCambia_AltoContenedor();
}; // despliega_Recortes

// -----------------------------------------------------------
// Graba los recortes en una cookie.
function graba_cookieRecortes() {
  tempCookie = "recs=";
  for(i=0; i < recEscogidos.length; i++) {
    tempCookie=tempCookie+"|"+(recEscogidos[i].id)+"|"+(recEscogidos[i].titular)+"|"+(recEscogidos[i].path)+"|"+(recEscogidos[i].leido);
  };

  var expire = new Date ();
  expire.setTime (expire.getTime() + (6 * 24 * 3600000)); // Expira en 6 dias.
  expire = expire.toGMTString();
  finalCookie = tempCookie+"; path=/; expires="+expire;
  // frameHead.document.cookie = finalCookie;
  document.cookie = finalCookie;
}; // graba_cookieRecortes.

// -----------------------------------------------------------
// Chequea que el browser del usuario acepte cookies.
function chequeo_aceptaCookies() {
  tempCookie = "recs=";
  for(i=0; i < recEscogidos.length; i++) {
    tempCookie=tempCookie+"|"+(recEscogidos[i].id)+"|"+(recEscogidos[i].titular)+"|"+(recEscogidos[i].path)+"|"+(recEscogidos[i].leido);
  };

  var expire = new Date ();
  expire.setTime (expire.getTime() + (6 * 24 * 3600000)); // Expira en 6 dias.
  expire = expire.toGMTString();

  finalCookie = tempCookie+"; path=/; expires="+expire;
  document.cookie = finalCookie;

  buffer_cookie = document.cookie.split(";");

  for (x=0; x < buffer_cookie.length; x++) {
    if (buffer_cookie[x].indexOf("recs") >= 0) {cookiesOn = true;};
  }
  if (cookiesOn == false) alert("Necesitará habilitar grabación de cookies para usar Recortes.");
}; // chequeo_aceptaCookies.

// -----------------------------------------------------------
// Marca un recorte como leido.
function marca_leido(id) {

  for (i=0; i < recEscogidos.length; i++) {
    if (recEscogidos[i].id == id) recEscogidos[i].leido = "yes";
  };

  graba_cookieRecortes();
}; // marca_leido.

// -----------------------------------------------------------
// Lee el siguiente recorte de la lista cuando se clickea sobre el numero de recortes en barra.
function Despliega_proxRecorte() {
  if (recEscogidos != null)  {
    total = 0;
    for (var i = 0; i < recEscogidos.length; i++) {
      if (recEscogidos[i].leido != "yes")  {
        marca_leido(recEscogidos[i].id);

        graba_cookieRecortes();

        document.location = recEscogidos[i].path;
        break;
      };
    };
  };
}; // Despliega_proxRecorte

// -----------------------------------------------------------
// Elimina los recortes que ya han sido leidos.
function Limpia_recEscogidos() {
  tempRecortes = new Array();
  x = 0;
  for (i=0; i < recEscogidos.length; i++) {
    if (recEscogidos[i].leido != "yes") {tempRecortes[x] = recEscogidos[i]; x++};
  };
  recEscogidos = tempRecortes;
  despliega_Recortes();
  setRecortesVisibility();
  actualiza_contadorRecortes();
  graba_cookieRecortes();
}; // Limpia_recEscogidos.

// -----------------------------------------------------------
// Elimina todos los recortes que selecciono el usuario en la portada.
function Limpia_recTodos() {
  recEscogidos = new Array();
  despliega_Recortes();
  setRecortesVisibility();
  actualiza_contadorRecortes();
  graba_cookieRecortes();
}; // Limpia_recTodos.


// -----------------------------------------------------------
// Setea el alto del contenedor de recortes para adecuarse a la cantidad de articulos seleccionados.
function recCambia_AltoContenedor() {
  // obj = frameCont.document.getElementById("rContainer");
  obj = document.getElementById("rContainer");

//  if (IE6) {
//    obj.style.height= '250px'; // Math.round(prontusScreen.visHeight()/3)+"px";
//  }
//  else {
//    obj.style.height= Math.round(prontusScreen.visHeight()/3)+"px";
//  };

  obj.style.height= '200px';
}; // recCambia_AltoContenedor.

// -----------------------------------------------------------
// Determina si un nuevo recorte ya existe.
function chequea_recortesDuplicados() {
  for (i=0; i < recEscogidos.length; i++) {
    if (nuevoRecorte == recEscogidos[i].id) {i = recTodos.length; duplicate = true;};
  };
}; // chequea_recortesDuplicados

// -----------------------------------------------------------
// Crea el codigo html para las tijeras que vuelan cuando se hace click en un icono de recorte.
function creaRecorteTijera() {
  for (x=0; x < 4; x++) {
    if (document.getElementById("recorteTijera") == null) {
      recorteTijera = document.createElement("img");
      recorteTijera.src = "../../../../imag/head/recorteFantasma.gif";
      recorteTijera.setAttribute(classFix,"recorteTijera");
      recorteTijera.setAttribute("id","recorteTijera"+x);
      parentObj = document.getElementById("bodyNode");
      parentObj.appendChild(recorteTijera);
    };
  };
}; // creaRecorteTijera.

// -----------------------------------------------------------
// Detecta los articulos en la pagina web y crea un arreglo con ellos.
var recortesDivArray = new Array();
function crea_arreglo_pagRecortes() {
  d = document.getElementsByTagName("DIV");
  for (j=0; j < d.length; j++) if (d[j].id.indexOf("rec") > -1) {
    recortesDivArray[recortesDivArray.length] = d[j];
  };
}; // crea_arreglo_pagRecortes.

// -----------------------------------------------------------
// Setea la visibilidad de una instancia de los iconos de recortes en la pagina.
function recorteInstancia_Visibility(id,state) {
  t = document.getElementsByName(id);
  if (t.length > 0) {
    for (j=0; j < t.length; j++) {
      t[j].style.visibility = state;
      t[j].onclick = addRecorte;
    };
  }
  else {
    // OJO: IE5mac y NS6 no retornan el largo de la coleccion de object.
    d = recortesDivArray;
		for (j=0; j < d.length; j++) {
		  if (d[j].id == id) {
  			d[j].style.visibility = state;
  			d[j].onclick = addRecorte;
			};
		};
  };
}; // recorteInstancia_Visibility.

// -----------------------------------------------------------
// Setea la visibilidad y los eventos de los iconos de recortes en la pagina.
function setRecortesVisibility() {
  for (i=0; i < recTodos.length; i++) {
    vis = "visible";
    // Si el recorte esta seleccionado, lo marca como invisible.
    for (x=0; x < recEscogidos.length; x++) {
      if (recTodos[i].id == recEscogidos[x].id) vis = "hidden";
    };
    obj = recTodos[i].id;

    recorteInstancia_Visibility(obj,vis);
  };
}; // setRecortesVisibility.

// -----------------------------------------------------------
// Asigna funciones a los eventos de los div que contienen el menu de recortes.
function inicioAcciones_divsMenu() {
  for (i=0; i < menus.length; i++) {
    // obj = frameHead.document.getElementById("nav"+menus[i]);
    obj = document.getElementById("nav"+menus[i]);
    obj.onclick = despliegaMenu;

    // obj = frameCont.document.getElementById("menu"+menus[i]);
    obj = document.getElementById("menu"+menus[i]);
    // obj.onmouseover = frameCont.menuOver;
    obj.onmouseover = menuOver;
    // obj.onmouseout = frameCont.menuOut;
    obj.onmouseout = menuOut;
  };

  // obj = frameHead.document.getElementById("navRecortesCounter");
  // obj = document.getElementById("navRecortesCounter");
  // obj.onclick = Despliega_proxRecorte;
}; // inicioAcciones_divsMenu.

// -----------------------------------------------------------
// Cancela evento onclick.
function menuOver() {
  document.onclick = null;
  if (document.all) event.cancelBubble=true;
}; // menuOver.

// -----------------------------------------------------------
// Esconde menu y cancela evento onclick.
function menuOut() {
  document.onclick = escondeMenu;
  if (document.all) event.cancelBubble=true;
}; // menuOut.

// -----------------------------------------------------------
// Despliega el menu de recortes.
function despliegaMenu(e) {
  // if (menuActivo != null) frameCont.escondeMenu();
  if (menuActivo != null) escondeMenu();
  menuActivo = "menu"+this.id.substring(3,this.id.length);

  // obj = frameCont.document.getElementById(menuActivo);
  obj = document.getElementById(menuActivo);

  // if (frameCont.document.body.scrollTop > TOP_BARRA) { // Deja la barra donde quedo en la pagina y no la sube al inicio.
  if (document.body.scrollTop > TOP_BARRA) { // Deja la barra donde quedo en la pagina y no la sube al inicio.
    // frameCont.document.getElementById("BarraCont").style.top = frameCont.document.body.scrollTop + 'px';
    document.getElementById("BarraCont").style.top = document.body.scrollTop + 'px';
    // obj.style.top = frameCont.document.body.scrollTop + 'px';
    obj.style.top = document.body.scrollTop + 'px';
  };

  if (obj) {
    obj.style.visibility = "visible";

    // Se esconde, ya que usualmente a los banners de los diarios (hechos por ellos) no le agregan
    // <OBJECT ... <PARAM NAME=WMode VALUE=Transparent> ...> y <EMBED... wmode=transparent ..> y
    // quedan sobre el menu de recortes seleccionados.
//    if (frameCont.document.getElementById("bannerdr")) {
//      frameCont.document.getElementById("bannerdr").style.visibility = "hidden"; // Banner de emol.
//    };
//    if (frameCont.document.getElementById("banner1")) {
//      frameCont.document.getElementById("banner1").style.visibility = "hidden"; // Banner de emol.
//    };
//    if (frameCont.document.getElementById("banner2")) {
//      frameCont.document.getElementById("banner2").style.visibility = "hidden"; // Banner de emol.
//    };
//    if (frameCont.document.getElementById("banner3")) {
//      frameCont.document.getElementById("banner3").style.visibility = "hidden"; // Banner de emol.
//    };
//    if (frameCont.document.getElementById("banner4")) {
//      frameCont.document.getElementById("banner4").style.visibility = "hidden"; // Banner de emol.
//    };
//    if (frameCont.document.getElementById("banner5")) {
//      frameCont.document.getElementById("banner5").style.visibility = "hidden"; // Banner de emol.
//    };

    if (document.getElementById("bannerdr")) {
      document.getElementById("bannerdr").style.visibility = "hidden"; // Banner de emol.
    };
    if (document.getElementById("banner1")) {
      document.getElementById("banner1").style.visibility = "hidden"; // Banner de emol.
    };
    if (document.getElementById("banner2")) {
      document.getElementById("banner2").style.visibility = "hidden"; // Banner de emol.
    };
    if (document.getElementById("banner3")) {
      document.getElementById("banner3").style.visibility = "hidden"; // Banner de emol.
    };
    if (document.getElementById("banner4")) {
      document.getElementById("banner4").style.visibility = "hidden"; // Banner de emol.
    };
    if (document.getElementById("banner5")) {
      document.getElementById("banner5").style.visibility = "hidden"; // Banner de emol.
    };


  };

  if (document.all) document.onclick = escondeMenu;
  // if (document.all) frameHead.event.cancelBubble=true;
  if (document.all) event.cancelBubble=true;
}; // despliegaMenu.

// -----------------------------------------------------------
// Esconde el menu de lista de recortes activo.
function escondeMenu() {
  document.onclick = null;
  if (menuActivo != null) {
    // obj = frameCont.document.getElementById(menuActivo);
    obj = document.getElementById(menuActivo);
    obj.style.visibility = "hidden";

    // Se despliega, una vez escondido el menu de recortes seleccionados.
//    if (frameCont.document.getElementById("bannerdr")) {
//      frameCont.document.getElementById("bannerdr").style.visibility = "visible";
//    };
//    if (frameCont.document.getElementById("banner1")) {
//      frameCont.document.getElementById("banner1").style.visibility = "visible";
//    };
//    if (frameCont.document.getElementById("banner2")) {
//      frameCont.document.getElementById("banner2").style.visibility = "visible";
//    };
//    if (frameCont.document.getElementById("banner3")) {
//      frameCont.document.getElementById("banner3").style.visibility = "visible";
//    };
//    if (frameCont.document.getElementById("banner4")) {
//      frameCont.document.getElementById("banner4").style.visibility = "visible";
//    };
//    if (frameCont.document.getElementById("banner5")) {
//      frameCont.document.getElementById("banner5").style.visibility = "visible";
//    };


    if (document.getElementById("bannerdr")) {
      document.getElementById("bannerdr").style.visibility = "visible";
    };
    if (document.getElementById("banner1")) {
      document.getElementById("banner1").style.visibility = "visible";
    };
    if (document.getElementById("banner2")) {
      document.getElementById("banner2").style.visibility = "visible";
    };
    if (document.getElementById("banner3")) {
      document.getElementById("banner3").style.visibility = "visible";
    };
    if (document.getElementById("banner4")) {
      document.getElementById("banner4").style.visibility = "visible";
    };
    if (document.getElementById("banner5")) {
      document.getElementById("banner5").style.visibility = "visible";
    };

  };
}; // escondeMenu.

// -----------------------------------------------------------
function cambia_wmode() { // 1.1.
  // Nombre unico usado por los diarios regionales.
  cant_banners = document.getElementsByName("ad_banner_example").length;

  for (var i = 0; cant_banners > i; i++) {
    document.getElementsByName("ad_banner_example")[i].wmode = "opaque";
	};
}; // cambia_wmode.

// -----------------------------------------------------------
// Actualiza el contador de recortes. Cuenta el numero de recortes no leidos que tiene seleccionado
// el usuario.
function actualiza_contadorRecortes() {
  t2 = 0;
  t1 = 0;
  if (recEscogidos != null) {
    total = 0;
    for (i = 0; i < recEscogidos.length; i++) {
      if (recEscogidos[i].leido != "yes") total++;
    };
    t2 = total;
    if (total > 9) {
      total = total + ""; // Cambia la variable numerica a alfanumerica.
      t1 = total.substring(0,1);
      t2 = total.substring(1,2);
    };
  };

//  frameHead.document.getElementById("cln0").src = '/imag/head/' + t1 + '_left.gif';
//  frameHead.document.getElementById("cln1").src = '/imag/head/' + t2 + '_right.gif';

  //window.document.getElementById("cln0").src = '../../../../imag/head/' + t1 + '_left.gif';
  window.document.getElementById("cln0").src = '/prontus_providencia/imag/head/' + t1 + '_left.gif';

  //window.document.getElementById("cln1").src = '../../../../imag/head/' + t2 + '_right.gif';
  window.document.getElementById("cln1").src = '/prontus_providencia/imag/head/' + t2 + '_right.gif';




  t2 = 0;
  t1 = 0;
  if (recorteActual != null) {
    total = recorteActual;
    t2 = total;
    if (total > 9) {
      total = total + ""; // Cambia la variable numerica a alfanumerica.
      t1 = total.substring(0,1);
      t2 = total.substring(1,2);
    };
  };


}; // actualiza_contadorRecortes.

// -----------------------------------------------------------
// Inicializa las variables yobjetos relacionados con los recortes.
var cookiesOn = false;

function inicio_Recortes() {
  getRecortesFromCookie();
  crea_recTodosArray();

  crea_arreglo_pagRecortes();
  creaRecorteTijera();
  setRecortesVisibility();

  inicioAcciones_divsMenu();

  actualiza_contadorRecortes();

  despliega_Recortes();

}; // inicio_Recortes.

function css_recortes() {
  /* RECORTES */
  document.write('<style type="text/css">');
  // document.write('#bodyNode {position: absolute; top: 0px; scroll: true}');
  document.write('.r { cursor:hand; display:inline;}');
  document.write('.click {cursor: hand;}');
  document.write('.stytijera { position:absolute; width:16px; height:14px; z-index:1; left: 0px; top: 0px; visibility:hidden;}');
  document.write('#pageContents {width:762px; margin:0px; text-align:left;}');
  document.write('                                                                                                                                                                                         ');
  document.write('.b3 {clear:both; height:8px;}');
  document.write('	                                                                                                                                                                                       ');
  document.write('                                                                                                                                                                                         ');
  document.write('/* background para articulos */                                                                                                                                                          ');
  document.write('.bgbotones {background-image:url(../../../../imag/head/bgPat.gif);}');
  document.write('                                                                                                                                                                                         ');
  document.write('.menuOutline {border:1px #000000 solid; border-bottom:2px #999999 solid; background:#EEEEEE;}');
  if (! NS6) {
    document.write('.menuBg {background:#EEEEEE; border:1px #FFFFFF solid; }');
  }
  else {
    document.write('.menuBg {background:#EEEEEE;}');
  };

  document.write('#menuRecortes {border:1px #000000 solid; position:absolute; width:200px; top:0px; left:559px; height:240px; z-index:99; display:block; visibility:hidden}');  // Aqui se define borde recortes.
  document.write('#rContainer {width:100%; height:200px; overflow:auto; z-index:98;}');
  document.write('#rControls {border-top:1px #50555A solid;background:#FAF9F5;padding:2px; z-index:97}');
  document.write('                                                                                                                                                                                         ');
  document.write('.mI, .mI:visited, .menuItem, menuItemS, .menuItem:visited {display:block; padding:4px; font:11px verdana, arial, san-serif; color:#444444; padding-top:2px; padding-bottom:2px;}');
  document.write('.mI:hover, .menuItem:hover, menuItemS:hover {background:#CCCCCC}');
  document.write('.menuItemS {width:22px;}');
  document.write('                                                                                                                                                                                         ');
  document.write('.hL, .headlineList {font:70% Verdana, Arial, san-serif;line-height:120%; color:#50555A;}');
  document.write('                                                                                                                                                                                         ');
  document.write('#BarraCont {z-Index:100; display:block;}');
  document.write('#BarraTop {position:absolute; top: 40px; height:18px; width:770px; z-index:100; left:10px;}');
  document.write('#HeadBar {padding-top:0px; left:0px; height:18px; width:770px; z-index:100; background-image:url(../../../../imag/head/head/left_back.gif); background-repeat:repeat-x; }');
  document.write('                                                                                                                                                                                         ');
  document.write('.recorteItem, .recorteItem:visited, .recorteItemRead  {padding:4px; font:10px verdana, arial, san-serif; color:#FF0000; padding-top:4px; padding-bottom:2px; display:block}');
  document.write('.recorteItem:hover {background:#FFFFFF;}');
  document.write('.recorteItemRead, .recorteItemRead:visited {color:#999999}');
  document.write('.recorteItemRead:hover {background:#FFFFFF; color:#50555A;}');
  document.write('                                                                                                                                                                                         ');
  document.write('.recNumCol {position:absolute; height:22px; width:12px; z-index:0; overflow:hidden; top:18px;}');
  document.write('                                                                                                                                                                                         ');
//  document.write('#cln0 {position:absolute; top:40px;}');
//  document.write('#cln1 {position:absolute; top:40px;}');
  document.write('                                                                                                                                                                                         ');
  document.write('.recorteTijera {position:absolute; top:0px; left:0px; visibility:hidden}');
  document.write('                                                                                                                                                                                         ');
  document.write('#mainBody {width:760px; position:relative;}');
  document.write('.col0 {width:178px; margin-left:25px; height:100%;}');
  document.write('.col1 {width:178px;}');
  document.write('.col2, .col3 {width:210px;} /* 236px */                                                                                                                                                ');
  document.write('.colMax {width:760px; height:18px;}');
  document.write('.colMaxArt {width:618px}');
  document.write('                                                                                                                                                                                         ');
  document.write('/* Articulos */                                                                                                                                                                          ');
  document.write('.encabezadoBg {background-image:url(../../../../imag/head/bgPat.gif); border:1px #FFFFFF solid; border-bottom:1px #FFFFFF solid; width:625px; padding-top:5px; padding-bottom:2px;}');
  document.write('                                                                                                                                                                                         ');
  document.write('/* Columnas del texto*/                                                                                                                                                                  ');
  document.write('#articuloPadre {height:190px; overflow:hidden; width:640px; left:0px; z-index:0; margin-left:0px; position:relative;}');
  document.write('.artCol {width:200px; height:190px; position:absolute; margin-right:14px; z-index:1} /* Mozilla will use a style WITHOUT a float */                                                                    ');
  document.write('.artText {position:absolute; width:200px; top:0px; left:10px; margin-right:5px;}');
  document.write('.artText SPAN P {margin-top:0px; margin-bottom:0px;}');
  document.write('.artText {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; line-height:16px; display:none;}');
  document.write('.artText a:link { color: #0000FF; text-decoration:underline;}');
  document.write('.artText a:hover { color: #FF0000; text-decoration:underline;}');
  document.write('.artText a:active { color: #FF0000; text-decoration:underline;}');
  document.write('.artText a:visited { color: #551A8B; text-decoration:underline;}');
  document.write('                                                                                                                                                                                         ');
  document.write('#pagina_siguiente, #pagina_anterior {position:absolute; z-index:3}');
  document.write('                                                                                                                                                                                         ');
  document.write('#pagSiguienteArticulo, #pagAnteriorArticulo, #articleOwnerGraphic {position:absolute; visibility:visible;}');
  document.write('#pagSiguienteArticulo {left:550px; top:-9px; z-index:4;}');
  document.write('#pagAnteriorArticulo  {left:470px; top:-9px; z-index:4;}');
  document.write('#articleOwnerGraphic {top:0px; left:0px;}');
  document.write('                                                                                                                                                                                         ');
  document.write('.pageNumCol {position:absolute; height:11px; width:11px; overflow:hidden; top:26px; z-index:4;}');
  document.write('                                                                                                                                                                                         ');
  document.write('#pgCol0 {position:absolute; top:10px;}');
  document.write('#pgCol1 {position:absolute; top:10px;}');
  document.write('#pgCol2 {position:absolute; top:10px;}');
  document.write('#pgCol3 {position:absolute; top:10px;}');
  document.write('</style>');
}; // css_recortes.

