
/* - 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 = "#565656";
	//elemento.className ='inputTextActive';
        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;
        }
    }
}

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 = "";
        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' ) {
           if (elemento.type=="checkbox"){
               elemento.style.background = "#eff5f1";
              }
            else { 
                  elemento.style.background = "#FFFFFF";
              } 
            elemento.style.color = "";
        var nodeName = elemento.nodeName;
        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 = "#004f1b";
    elemento.style.color = "#ffffff";
}

function no_focob(elemento) {
    elemento.style.background = "#ffffff";
    elemento.style.color = "#0C480A";
    
}

function foco(elemento) {
   elemento.style.color = "#ffffff";	
   if (elemento.className=="searchButton")
      {elemento.style.background = "#565656";} 
   else
      {
       if(elemento.name=="submit")
         {elemento.style.background = "#565656 url(./linkTransparent.gif) no-repeat scroll  9px 3px";}
       else  
         {elemento.style.background = "#565656 url(./linkTransparent.gif) no-repeat scroll  9px 1px";}
	  }	 
 }


function no_foco(elemento) {
    elemento.style.color = "#000000";	
    if (elemento.className=="searchButton")
	{elemento.style.background = "transparent";}
    else
	{
	 if(elemento.name=="submit")
         {elemento.style.background = "transparent url(./linkTransparent.gif) no-repeat scroll  9px 3px";}
       else  
         {elemento.style.background = "transparent url(./linkTransparent.gif) no-repeat scroll  9px 1px";}
	}	         
}

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;
        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;
        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 init_form() {
    var inputs = document.getElementsByTagName('input');
    var type;
    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);
      }
      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);
    }
}



if(window.attachEvent) { // IE
  registerPloneFunction(init_form);
}
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;
}

// No mostramos el datePicker porque todavia no es totalmente accesible
/*
function init_datePicker() {
 var datePickers = getElementsByClass('datePicker', document);
  for (i = 0; i < datePickers.length; i++) {
   jscss('add',datePickers[i],'activado');
  }
 
}
registerPloneFunction(init_datePicker);
*/

/*
function quitar_bola() {
    if (!W3CDOM) { return false; }
        var links = cssQuery("#content a", document);
        for (i=0; i < links.length; i++) {
            if ( (links[i].getAttribute('href')) ) {
               var linkval = links[i].getAttribute('href');
               if (links[i].hasChildNodes) {

                  var children = links[i].childNodes;
                  var haveImg = false;
                  for (var j=0;j<children.length;j++) {

                     try {
                     if (j.tagName.toLowerCase() == 'img') {
                        alert('found'+ links[i].innerHTML);
                        haveImg = true;                         
                     }

                     } catch(e) {}
 
                  }
                  if (linkval.indexOf('http:') == 0 && haveImg) {
                     links[i].setAttribute('background', 'none');
                  }
               }
            }    
      }
}
registerPloneFunction(quitar_bola);
*/









