
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - switch800x600.js - */
my_ie_hack_lock = false;
function pageWidth() {
 return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;
}
function resetLock() {
 my_ie_hack_lock = false;
}
function switch800x600() {
  if(!my_ie_hack_lock) {
    my_ie_hack_lock = true;
    setTimeout(resetLock, 200);
    var pagewidth = pageWidth();
    if (pagewidth != null && pageWidth() < 990) {
      setActiveStyleSheet('800x600');
    }
    else {
      setActiveStyleSheet('default');
    }
   //$("select").selectboxfix();
  }
  return false;
}
function init_800x600() {
  if (document.all) {
      document.body.onresize = switch800x600;
  } 
  else {
    if (window.addEventListener) {
      window.addEventListener("resize", switch800x600, false);
    } else {
      window.attachEvent("resize", switch800x600);
    }
  }
  switch800x600();
}

registerPloneFunction(init_800x600);


/* - focos.js - */
function collapse(id){
    collapsible =  document.getElementById(id);
    collapsible.className ='novisible';
    return false;
}

function jscss(a,o,c1,c2)
{
  switch (a){
    case 'swap':
      o.className=!jscss('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
    break;
    case 'add':
      if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}
  
function focoin(elemento) {
    if(elemento.style != null) {
        elemento.style.background = "#166573";
        elemento.style.color = "#FFFFFF";
    }
    var nodeName = elemento.nodeName;
    if (nodeName == 'SELECT') {
        var child = elemento.firstChild;
        while (child != null) {
            if (child.className == 'letraroja') child.className = 'letrarojaB';
            child = child.nextSibling;
        }
    }
    if (nodeName == 'INPUT') {
        type = elemento.getAttribute('type');
        if (type == 'text') {
            elemento.style.color = "#FFFFFF";
        }
    }
}

function no_focoin(elemento) {
    var toElem;
    try {
        toElem = window.event.toElement;
    }
    catch (error) {
        toElem = null;
    }
    if ( navigator.userAgent.indexOf('Firefox') != -1 ) {
        elemento.style.background = "#FFFFFF";
        elemento.style.color = "#166573";
        var nodeName = elemento.nodeName;
        if (nodeName == 'SELECT') {
            var child = elemento.firstChild;
            while (child != null) {
                if (child.className == 'letrarojaB') child.className = 'letraroja';
                child = child.nextSibling;
            }
        }
    }
    else { 
        if ( toElem != null || window.event.type == 'blur' ) {
            elemento.style.background = "#FFFFFF";
            elemento.style.color = "";
        var nodeName = elemento.nodeName;
        if (nodeName == 'INPUT') {
            type = elemento.getAttribute('type');
        }
        if (nodeName == 'TEXTAREA') {
        }
        if (nodeName == 'SELECT') {
            var child = elemento.firstChild;
            while (child != null) {
                if (child.className == 'letrarojaB') child.className = 'letraroja';
                child = child.nextSibling;
            }
        }
        }
    }
}

function focoin2(elemento) {
    if(elemento.style != null) {
        jscss('add',elemento,'selectActive');
    }
}

function no_focoin2(elemento) {
    var toElem;
    try {
        toElem = window.event.toElement;
    }
    catch (error) {
        toElem = null;
    }
    if ( navigator.userAgent.indexOf('Firefox') != -1 ) {
        jscss('remove',elemento,'selectActive');
    }
    else { 
        if ( toElem != null || window.event.type == 'blur' ) {
            jscss('remove',elemento,'selectActive');
        }
    }
}

function focob(elemento) {
    elemento.style.background = "#FFFFFF";
    elemento.style.color = "#436976";
}

function no_focob(elemento) {
    elemento.style.background = "#E4FFA4";
    elemento.style.color = "#176574";
    elemento.style.border = "1px solid #0D0E67";
}

function foco(elemento) {
    var parentnode = elemento.parentNode;
    if( jscss('check',parentnode,'oncebuttontr'))  {
        oncebuttondiv = getNearestParentOfTypeAndClass(elemento, 'div', 'oncebuttonnoacc', false);
        try {
          jscss('swap', oncebuttondiv, 'oncebuttonnoacc', 'oncebuttonacc');
        }
        catch (e){}
    }
    else {
        if (! jscss('check', elemento, 'hiddenStructure')) {
            try {
              jscss('swap', elemento, 'context', 'contextacc');
              jscss('swap', elemento, 'standalone', 'standaloneacc');
            }
            catch (e){}
        }
    }
}

function no_foco(elemento) {
    var parentnode = elemento.parentNode;
    if( jscss('check',parentnode,'oncebuttontr'))  {
        //jscss('swap', parentnode, 'oncebuttonnoacc', 'oncebuttonacc');
        oncebuttondiv = getNearestParentOfTypeAndClass(elemento, 'div', 'oncebuttonacc', false);
        try {
         jscss('swap', oncebuttondiv, 'oncebuttonacc', 'oncebuttonnoacc');
        }
        catch (e) {}
    }
    else {
        if (! jscss('check', elemento, 'hiddenStructure')) {
            try {
             jscss('swap', elemento, 'contextacc', 'context');
             jscss('swap', elemento, 'standaloneacc', 'standalone');
            }
            catch (e){}
        }
    }
}

function focointhis(e) {
    if (!e) {
        e = (typeof window != "undefined" && window && window.event);
    }
    if (e) {
        var elemento;
        if (document.all) elemento = event.srcElement;
        else elemento = e.target;
        var nodeName;
        try {
         nodeName = elemento.nodeName.toLowerCase();
        }
        catch(e) {
         nodeName = ''
        }
        if( nodeName == 'input' || nodeName == 'select' || nodeName == 'textarea' || nodeName == 'option') {
         focoin(elemento);
        }
    }

}

function no_focointhis(e) {
    if (!e) {
        e = (typeof window != "undefined" && window && window.event);
    }
    if (e) {
        var elemento;
        if (document.all) elemento = event.srcElement;
        else elemento = e.target;
        var nodeName;
        try {
         nodeName = elemento.nodeName.toLowerCase();
        }
        catch(e) {
         nodeName = ''
        }
        if( nodeName == 'input' || nodeName == 'select' || nodeName == 'textarea' || nodeName == 'option') {
         no_focoin(elemento);
        }
    }
}

function focoin2this(e) {
    if (!e) {
        e = (typeof window != "undefined" && window && window.event);
    }
    if (e) {
        var elemento;
        if (document.all) elemento = event.srcElement;
        else elemento = e.target;
        focoin2(elemento);
    }
}

function no_focoin2this(e) {
    if (!e) {
        e = (typeof window != "undefined" && window && window.event);
    }
    if (e) {
        var elemento;
        if (document.all) elemento = event.srcElement;
        else elemento = e.target;
        no_focoin2(elemento);
    }
}

function focothis(e) {
    var elemento;
    if (document.all) elemento = event.srcElement;
    else elemento = e.target;
    foco(elemento);
}

function no_focothis(e) {
    var elemento;
    if (document.all) elemento = event.srcElement;
    else elemento = e.target;
    no_foco(elemento);
}

// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling)
{
  bubbling = bubbling || false;
  if(window.addEventListener) { // Standard
    element.addEventListener(type, expression, bubbling);
    return true;
  } else if(window.attachEvent) { // IE
    element.attachEvent('on' + type, expression);
    return true;
  } else return false;
}

function cambiarSrc(isActive) {
    return function(e) {
        var elemento;
        if (document.all) elemento = event.srcElement;
        else elemento = e.target;
        var fc = 'fc';
        var action_img;
        if (elemento.nodeName.toLowerCase() == 'img' || elemento.nodeName.toLowerCase() == 'input' ) {
          action_img = elemento;
        }
        else {
            action_img = elemento.getElementsByTagName('img')[0];
        }
        try {
            var src = action_img.getAttribute('src');
            var srcfc;
            if (isActive)  {
                srcfc = src.replace('fc.gif', '.gif');
            }
            else {
                // Hacemos esta comprobacion para evitar dos veces
                if (src.indexOf('fc.gif')==-1) {
                  srcfc = src.replace('.gif', 'fc.gif');
                }
                else {
                  srcfc = src;
                }
            }
            action_img.src =  srcfc;
            }
        catch (error) {
        }
    }
}

function init_searchbuttons() {
    // Esta funcion reemplaza los onfocus, onmouseover, etc. del codigo de los botones de buscar y el collapse de las noticias Home
    var button;
    var buttons = ['searchButton',
                   'buscar',
                   'searchname',
                   'replegarimg_a',
                   ];

    /* si solo hay un elemento esto no aplica porque no hay li */

    for (var i=0; i<buttons.length; i++) {
        button = document.getElementById(buttons[i]);
        if (button != null) {
            addListener(button, 'focus', new cambiarSrc(false), false);
            addListener(button, 'mouseover', new cambiarSrc(false), false);
            addListener(button, 'mouseout', new cambiarSrc(true), false);
            addListener(button, 'blur', new cambiarSrc(true), false);
        }
    }
}

function init_siteactions() {
    var action_li;
    var action_a;
    var action_id;
   
    var actions = ['accessibility',
                   'acc',
                   'help',
                   'sitemap'
                   ];

    /* si solo hay un elemento esto no aplica porque no hay li */

    for (var i=0; i<actions.length; i++) {
        action_li = document.getElementById('siteaction-'+actions[i]);
        action_a = action_li.getElementsByTagName('a')[0];
        addListener(action_a, 'focus', new cambiarSrc(false), false);
        addListener(action_a, 'mouseover', new cambiarSrc(false), false);
        addListener(action_a, 'mouseout', new cambiarSrc(true), false);
        addListener(action_a, 'blur', new cambiarSrc(true), false);
    }
}

function init_form() {
    var inputs = document.getElementsByTagName('input');
    var type;
    for (var i=0; i<inputs.length; i++) {
      type = inputs[i].getAttribute('type');
      // Lo comento porque los inputs se procesan para todos los navegadores
      // if (type == 'submit') {
      //     addListener(inputs[i], 'focus', focothis, false);
      //     addListener(inputs[i], 'mouseover', focothis, false);
      //     addListener(inputs[i], 'mouseout', no_focothis, false);
      //     addListener(inputs[i], 'blur', no_focothis, false);
      // }
      if (type == 'text') {
          addListener(inputs[i], 'focus', focointhis, false);
          addListener(inputs[i], 'mouseover', focointhis, false);
          addListener(inputs[i], 'mouseout', no_focointhis, false);
          addListener(inputs[i], 'blur', no_focointhis, false);
      }
      if (type == 'password') {
          addListener(inputs[i], 'focus', focointhis, false);
          addListener(inputs[i], 'mouseover', focointhis, false);
          addListener(inputs[i], 'mouseout', no_focointhis, false);
          addListener(inputs[i], 'blur', no_focointhis, false);
      }
	  if (type == 'checkbox') {
          addListener(inputs[i], 'focus', focointhis, false);
          addListener(inputs[i], 'mouseover', focointhis, false);
          addListener(inputs[i], 'mouseout', no_focointhis, false);
          addListener(inputs[i], 'blur', no_focointhis, false);
      }
    }

    
    var selects = document.getElementsByTagName('select');
    for (var i=0; i<selects.length; i++) {
      addListener(selects[i], 'focus', focoin2this, false);
      addListener(selects[i], 'mouseover', focoin2this, false);
      addListener(selects[i], 'mouseout', no_focoin2this, false);
      addListener(selects[i], 'blur', no_focoin2this, false);
    }
    var textareas = document.getElementsByTagName('textarea');
    for (var i=0; i<textareas.length; i++) {
      addListener(textareas[i], 'focus', focointhis, false);
      addListener(textareas[i], 'mouseover', focointhis, false);
      addListener(textareas[i], 'mouseout', no_focointhis, false);
      addListener(textareas[i], 'blur', no_focointhis, false);
    }

    // OJO: Habilitamos cacheo de las imagenes en IE6
    try {
    	document.execCommand("BackgroundImageCache", false, true);
    } catch (e) { }

}

function init_form2() {
    var inputs = document.getElementsByTagName('input');
    var type;
    // select replacement
    // $("select").selectbox();

    for (var i=0; i<inputs.length; i++) {
      type = inputs[i].getAttribute('type');
      if (type == 'submit') {
          addListener(inputs[i], 'focus', focothis, false);
          addListener(inputs[i], 'mouseover', focothis, false);
          addListener(inputs[i], 'mouseout', no_focothis, false);
          addListener(inputs[i], 'blur', no_focothis, false);
      }

    }
}
function init_btn_buscador() {
    var lupa = getElementsByClass('imagenlupa', document, 'input');
    for (var i=0; i<lupa.length; i++) {
      type = lupa[i].getAttribute('type');
      if (type == 'image') {
          addListener(lupa[i], 'focus', new cambiarSrc(false), false);
          addListener(lupa[i], 'mouseover', new cambiarSrc(false), false);
          addListener(lupa[i], 'mouseout', new cambiarSrc(true),false);
          addListener(lupa[i], 'blur', new cambiarSrc(true), false);
      }
    }
}

function init_resalte_document_actions() {
    var action_a;
    var action_id;
   
    /* si solo hay un elemento tambien aplica */
    var actions_container = getElementsByClass('documentActions', document, 'div');
    if(actions_container.length > 0) {
        var actions = actions_container[0].getElementsByTagName('a');

        for (var i=0; i<actions.length; i++) {
            jscss('add',actions[i],'sinborde');
            action_a = actions[i];
            addListener(action_a, 'focus', new cambiarSrc(false), false);
            addListener(action_a, 'mouseover', new cambiarSrc(false), false);
            addListener(action_a, 'mouseout', new cambiarSrc(true), false);
            addListener(action_a, 'blur', new cambiarSrc(true), false);
        }
    }
    actions_container = getElementsByClass('documentActionsDiv', document, 'div');
    if(actions_container.length > 0) {
        var actions = actions_container[0].getElementsByTagName('a');

        for (var i=0; i<actions.length; i++) {
            jscss('add',actions[i],'sinborde');
            action_a = actions[i];
            addListener(action_a, 'focus', new cambiarSrc(false), false);
            addListener(action_a, 'mouseover', new cambiarSrc(false), false);
            addListener(action_a, 'mouseout', new cambiarSrc(true), false);
            addListener(action_a, 'blur', new cambiarSrc(true), false);
        }
    }
    actions_container = getElementsByClass('documentActionsDiv', document, 'span');
    if(actions_container.length > 0) {
        var actions = actions_container[0].getElementsByTagName('a');

        for (var i=0; i<actions.length; i++) {
            jscss('add',actions[i],'sinborde');
            action_a = actions[i];
            addListener(action_a, 'focus', new cambiarSrc(false), false);
            addListener(action_a, 'mouseover', new cambiarSrc(false), false);
            addListener(action_a, 'mouseout', new cambiarSrc(true), false);
            addListener(action_a, 'blur', new cambiarSrc(true), false);
        }
    }
}
function init_vermas() {
    var enlaces_vermas = getElementsByClass('vermas-enlace', document, 'a');
    for (var j=0; j<enlaces_vermas.length; j++) {
        jscss('add',enlaces_vermas[j],'sinborde');
      addListener(enlaces_vermas[j], 'focus', new cambiarSrc(false), false);
      addListener(enlaces_vermas[j], 'mouseover', new cambiarSrc(false), false);
      addListener(enlaces_vermas[j], 'mouseout', new cambiarSrc(true),false);
      addListener(enlaces_vermas[j], 'blur', new cambiarSrc(true), false);
    }
/*
    var vermas = getElementsByClass('vermas', document, 'img');
    for (var i=0; i<vermas.length; i++) {
      addListener(vermas[i], 'focus', new cambiarSrc(false), false);
      addListener(vermas[i], 'mouseover', new cambiarSrc(false), false);
      addListener(vermas[i], 'mouseout', new cambiarSrc(true),false);
      addListener(vermas[i], 'blur', new cambiarSrc(true), false);
    }
*/
    enlaces_vermas = getElementsByClass('vermaspeq-enlace', document, 'a');
    for (var j=0; j<enlaces_vermas.length; j++) {
        jscss('add',enlaces_vermas[j],'sinborde');
      addListener(enlaces_vermas[j], 'focus', new cambiarSrc(false), false);
      addListener(enlaces_vermas[j], 'mouseover', new cambiarSrc(false), false);
      addListener(enlaces_vermas[j], 'mouseout', new cambiarSrc(true),false);
      addListener(enlaces_vermas[j], 'blur', new cambiarSrc(true), false);
    }
/*
    vermas = getElementsByClass('vermaspeq', document, 'img');
    for (var i=0; i<vermas.length; i++) {
      addListener(vermas[i], 'focus', new cambiarSrc(false), false);
      addListener(vermas[i], 'mouseover', new cambiarSrc(false), false);
      addListener(vermas[i], 'mouseout', new cambiarSrc(true),false);
      addListener(vermas[i], 'blur', new cambiarSrc(true), false);

    }
*/
    enlaces_vermas = getElementsByClass('masNoticias', document, 'a');
    for (var j=0; j<enlaces_vermas.length; j++) {
        jscss('add',enlaces_vermas[j],'sinborde');
    }
}
function init_selects() {
    var selects = document.getElementsByTagName('select');
    for (var i=0; i<selects.length; i++) {
      addListener(selects[i], 'focus', focoin2this, false);
      addListener(selects[i], 'mouseover', focoin2this, false);
      addListener(selects[i], 'mouseout', no_focoin2this, false);
      addListener(selects[i], 'blur', no_focoin2this, false);
    }
    var textareas = document.getElementsByTagName('textarea');
    for (var i=0; i<textareas.length; i++) {
      addListener(textareas[i], 'focus', focointhis, false);
      addListener(textareas[i], 'mouseover', focointhis, false);
      addListener(textareas[i], 'mouseout', no_focointhis, false);
      addListener(textareas[i], 'blur', no_focointhis, false);
    }
}

var ieVer=/*@cc_on function(){ switch(@_jscript_version){ case 1.0:return 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5; case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7; case 5.8:return 8; }}()||@*/0;
if(/MSIE 6.0/i.test(navigator.userAgent)) {ieVer=6;}

function addClassId() {
     var isMSIE = /*@cc_on!@*/false; 
     var reproductor = document.getElementById('reproductor');
     if (isMSIE && reproductor != null) {
        // reproductor.setAttribute('classid','clsid:d27cdb6e-ae6d-11cf-96b8-444553540000');   
        reproductor.CLASSID="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000";   
     }
}
var AccesibleFlash = {
	inicio: function(ide){ // llamaremos a esta función desde Flash. Solo si hay flash se establecera el tabindex 0 para el object
		this.estableceTabindex(ide);
	},
	estableceTabindex: function(ide){
                try {
		 if(document.getElementById('reproductor2')) document.getElementById('reproductor2').setAttribute('tabindex', '0');
                }catch(e){}
	},
	desenfocaObject: function(ide){
            try {
              if(ieVer!=0) {
                 var nextsibling;
                 // el siguiente elemento al reproductor debe tener alguno de estos ids
                 nextsibling = document.getElementById('reprdcha');
                 if (nextsibling == null) {
                     nextsibling = document.getElementById('focorepro');
                 }
                 if (nextsibling == null) {
                   var nextsiblings = getElementsByClass('bloqueHome', document, 'div');
                   if (nextsiblings.length>0) nextsibling = nextsiblings[0];
                   if(ieVer>6) {
                       nextsiblings = nextsibling.getElementsByTagName('a')
                       if (nextsiblings.length>0) nextsibling = nextsiblings[0];
                   }
                 }
                 if (nextsibling != null) {
                    nextsibling.focus();
                 }
              }
              else {
		 document.getElementById('reproductor2').blur();
              }
            }catch(e){}
	}
}

if(window.attachEvent) { // IE
   registerPloneFunction(init_form);

}
// registerPloneFunction(addClassId);
registerPloneFunction(init_form2);
registerPloneFunction(init_btn_buscador);
if(window.opera) {
 registerPloneFunction(init_selects);
}
/*(25/05/09) No es necesario por haberse eliminado las imagenes de las actions --> solicitado por ONCE
      registerPloneFunction(init_siteactions);
*/
registerPloneFunction(init_searchbuttons);

// dmunicio: resalte de las document_actions
registerPloneFunction(init_resalte_document_actions);
// dmunicio: resalte de los vermas
registerPloneFunction(init_vermas);

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function getNearestParentOfTypeAndClass(node, type, classname, exact_match) {
    /* well the title says it all ;) */
    if (exact_match == null) var exact_match = false;
    var type = type.toLowerCase();
    while (node) {
        if (node.nodeName.toLowerCase() == type && ((exact_match && node.className == classname) || (!exact_match && jscss('check', node, classname)))) {
            return node;
        }
        var node = node.parentNode;
    }
    return false;
}



