if (window.attachEvent) try { document.execCommand("BackgroundImageCache",false,true); } catch (e) {};

/*
 * Popup: creates a Popup window.
 * Popups accept all of the normal features a
 */
Popup = Class.create();

Popup.prototype = {
  setOptions: function (options) {
    this.options = Object.extend({
      name        : null,
      center      : false, // centers the popup on the screen
      fillScreen  : false, // opens the browser window to the max (use with caution: can be very irritating)
    // from here on window features.
      width       : null, // width of the popup
      height      : null, // height of the popup
      top         : null, // left position of the popup
      left        : null, // right position of the popup
      location    : 0, // 0: address bar is invisible, 1: address bar is visible
      menubar     : 0, // 0: menu bar is invisible, 1: menu bar is visible (no use on mac browsers)
      resizable   : 1, // 0: popup is not resizable, 1: popup is resizable,
      scrollbars  : 0, // 0: scrollbars are invisible, 1: scrollbars are visible
      status      : 0, // 0: statusbar is invisible, 1: statusbar is visible
      toolbar     : 0, // 0: toolbar is invisible, 1: toolbar is visible
      directories : 0 // 0: bookmarks are invisible, 1: bookmarks are visible (no use on mac browsers)
    }, options || {})
  },
  initialize: function (href, options) {
    if (options.fillScreen) {
      options.width = screen.availWidth;
      options.height = screen.availHeight;
      options.left = 0;
      options.top = 0;
    }
    else if (options.center && options.width && options.height) {
      options.top = (screen.availHeight / 2) - (options.height / 2);
      options.left = (screen.availWidth / 2) - (options.width / 2);
    }
    this.setOptions(options);
    var f = [];
    var features = ['width', 'height','top', 'left', 'location', 'menubar',
      'resizable', 'scrollbars', 'status','toolbar','directories']; // these are all the options that go into the features string
    features.each(function (feature) {
      if (this.options[feature] != null && this.options[feature] != '') f.push(feature + '=' + this.options[feature]);
    }.bind(this));
    return window.open(href, options.name, options.features || f.join(','));
  }
}

/*
 * Navigation: creates a Navigation.
 */
Navigation = Class.create();

Navigation.prototype = {
  setOptions: function (options) {
    this.options = Object.extend({
      private: false
    }, options || {})
  },
  initialize: function (url, options) {
    __navigation = url;
    // Recuperamos idi de la url de la página
    var idi = document.location.search.toQueryParams().idi;
    
    // Obtenemos idi del link de Navigation si está en la url de la página
    if (!idi && (__navigation.indexOf("idi=") != -1)) {
      idi = __navigation.substring(__navigation.indexOf("idi=")+4, __navigation.indexOf("idi=")+5);
      __navigation = __navigation.replace(/\&?idi=\d\&?/gi, "");
    } else if (__navigation.indexOf("idi=") != -1) {
      __navigation = __navigation.replace(/\&?idi=\d\&?/gi, "");
    }

    // Si el link no contiene arg1
    if (__navigation.indexOf("arg1=") == -1) {
      __navigation = encodeURIComponent(__navigation);
      if (idi && __navigation.indexOf("idi") == -1) {
        __navigation += "&idi=" + idi;
      }
      if (!options || !options.private) {
        new Ajax.Updater($('navegacion'),'/_comun/jsp/menuizdoxml2.jsp?ajax=true&arg1=' + __navigation, {method: 'get', encoding: 'UTF-8'});
      }
      new Ajax.Updater($$('title')[0],'/_comun/jsp/titlexml2.jsp?ajax=true&arg1=' + __navigation, {method: 'get', encoding: 'UTF-8', onSuccess: function (req) {document.title = req.responseText}});
      new Ajax.Updater($('navegacion_contenido'),'/_comun/jsp/linkscabeceraxml2.jsp?ajax=true&arg1=' + __navigation, {method: 'get', encoding: 'UTF-8', insertion: Insertion.After});
      new Ajax.Updater($('banner_navegacion'),'/_comun/jsp/banners.jsp?ajax=true&arg1=' + __navigation, {method: 'get', encoding: 'UTF-8', insertion: Insertion.After});
    }
    else {
      if (idi && __navigation.indexOf("idi") == -1) {
        __navigation += "&idi=" + idi;
      }
      if (!options || !options.private) {
        new Ajax.Updater($('navegacion'),'/_comun/jsp/menuizdoxml2.jsp?ajax=true&' + __navigation, {method: 'get', encoding: 'UTF-8'});
      }
      new Ajax.Updater($$('title')[0],'/_comun/jsp/titlexml2.jsp?ajax=true&' + __navigation, {method: 'get', encoding: 'UTF-8', onSuccess: function (req) {document.title = req.responseText}});
      new Ajax.Updater($('navegacion_contenido'),'/_comun/jsp/linkscabeceraxml2.jsp?ajax=true&' + __navigation, {method: 'get', encoding: 'UTF-8', insertion: Insertion.After});
      new Ajax.Updater($('banner_navegacion'),'/_comun/jsp/banners.jsp?ajax=true&' + __navigation, {method: 'get', encoding: 'UTF-8', insertion: Insertion.After});
    }
  }
}

/*
 * Necesario para que IE aplique bien los estilos.
 */
if (navigator.appName == "Microsoft Internet Explorer") {
  setTimeout(function() {
    if (document.body && document.readyState == "complete") {
      document.body.className += " :screw-ie";
      var camino;
      if (camino = document.getElementById("camino")) camino.className += " :screw-ie";
    } else setTimeout(arguments.callee,10);
  }, 10);
}

/*if (typeof onload == 'function') __page_old_onload = onload;
onload = function () {
  if (typeof __page_old_onload  == 'function') __page_old_onload();
  if (typeof inicializa_pagina == 'function') inicializa_pagina();
}*/

function __inicializa_pagina() {
    if (typeof inicializa_pagina == 'function') inicializa_pagina();
}

FastInit.addOnLoad(__inicializa_pagina);
