
  /*------------------------------------------------------------------------------*/
/* 
 Uso:
	Object.registraClase(elemento(s), clase [, parametro(s)]);

 Parametros
	- elemento(s): Obligatorio. Se puede indicar bien el objeto DOM sobre el que 
		se quiere aplicar la clase o una una cadena de texto que puede tener 
		tres formatos:
		1 -	"nombreEtiqueta" aplica la clase a todos los elementos 
			con el mismo nombre de etiqueta en la página. Ejemplo "input".
		2 -	"#id" aplica la clase al elemento cuyo id coincida con 
el indicado. Ejemplo "#idZona".
		3 - 	"%nombre" se encarga de aplicar la clase a todos 
			aquellos elementos cuyo name coincida con el especificado. 
Ejemplo "%nombreZona".
	- clase : Obligatorio. La función que representa una clase estandar ECMA3.
	- parametro (s): Un array de elementos que se deben de pasar al constructor 
		de la clase. Si no se indican el constructor será invocado
		 sin parámetros.
*/
/*------------------------------------------------------------------------------*/

// declaro la funcion addOnLoad()
function ols(){}function addOnLoad(newFunction){var j=0;while(eval('ols.f'+j)){j++;}eval('ols.f'+j+'=' + newFunction);}
function eOls(){var j = 0;while(eval('ols.f'+j))	{eval('ols.f'+j+'()');j++;}}window.onload = eOls;


function componente(){
	for (i=0; i < document.getElementsByTagName("div").length; i++){ //recorro los divs
		clase=document.getElementsByTagName("div")[i].className; //recogo la clase de los divs
		if (clase == "c0302_448_a clearfix"){ //si la clase es la del contenedor que estoy buscando
		//compruebo que la clase del siguiente div sea textos, lo que significa que no existe la capa imagen. Si es asi, la cambio por teextos2, que tiene el ancho adecuado
		if(document.getElementsByTagName("div")[i].getElementsByTagName("div")[0].className == "textos"){
			document.getElementsByTagName("div")[i].getElementsByTagName("div")[0].className="";
		}
	}
}
}

function averigua(){
nav=window.navigator.userAgent;/*averiguo que navegador utilizo*/ 
if (document.getElementById("columna_gris")){
	if (document.getElementById("columna_gris").clientHeight > document.getElementById("columna_contenido").clientHeight){
		document.getElementById("columna_contenido").style.height=((document.getElementById("columna_gris").clientHeight)/10) -1.5 + "em";
	}
	else{  
		if (document.getElementById("alto").clientHeight > document.getElementById("destacados_der").clientHeight){
			if(navigator.appName=="Netscape"){		
				if(nav.indexOf("Firefox")!=-1){
					document.getElementById("borde").style.height=((document.getElementById("alto").clientHeight)/10) -6.3 + "em";
				}
				else{
					alert("netscape");
				}
			}
			else{
				if(nav.indexOf("MSIE")!=-1) {
					if(nav.indexOf("Opera")!=-1) 
						document.getElementById("borde").style.height=((document.getElementById("alto").clientHeight)/10) -6.2 + "em";
					else{
						document.getElementById("borde").style.height=((document.getElementById("alto").clientHeight)/10) -6.2 + "em";
					}
				}
			}	
		}
		else{
			if(navigator.appName=="Netscape"){		
				if(nav.indexOf("Firefox")!=-1){
					document.getElementById("borde").style.height=((document.getElementById("destacados_der").clientHeight)/10) + "em";
				}
				else{
					document.getElementById("borde").style.height=((document.getElementById("destacados_der").clientHeight)/10) + 0.1 + "em";
				}
			}
			else{
				if(nav.indexOf("MSIE")!=-1) {
					if(nav.indexOf("Opera")!=-1) {
						document.getElementById("borde").style.height=((document.getElementById("destacados_der").clientHeight)/10) + 0.1 + "em";
					}
					else{
						document.getElementById("borde").style.height=((document.getElementById("destacados_der").clientHeight)/10) + "em";
					}
				}
			}	
		}
	document.getElementById("columna_gris").style.height=((document.getElementById("columna_contenido").clientHeight)/10) + "em";
	}
}
}

Object.registraClase = function(tag, clase, args){
	// Se mantienen referencias para volver a aplicar la clase 
	// mapeando sombre document.createElement
	if (!this._tags){
		this._tags = new Array();
	}

	// Variable donde se almacenarán los objetos sobre los que 
	// se quiere aplicar la clase
	var tags;
	
	if (typeof tag == "string"){
		// Si se indica el elemento a aplicar la clase mediante un string hay que 
		// comprobar que el navegador permite más que manejo de DOM básico
		if (!document.getElementsByTagName || !document.getElementById){
			return false;
		}

		// Se comprueba si el nombre del elemento se ha indicado mediante el 
		// id, el name o el tagname
		if (tag.charAt(0) != "#" && tag.charAt(0) != "%"){
			this._tags[tag] = {clase:clase,args:args};
		}

		if (!args){
			args = [];
		
		}	

		// Si comienza por # es que se ha indicado mediante el id	
		if (tag.charAt(0) == "#"){
			tags = [document.getElementById(tag.substr(1))];
		} else {
			// Si comienza por % es que se ha indicado mediante el name
			if (tag.charAt(0) == "%"){
				tags = document.getElementsByName(tag.substr(1));
			} else {
				// Se ha indicado mediante el tagname
				tags =  document.getElementsByTagName(tag);		
			}

		}
	
	} else {
		// Directamente se ha pasado el objeto
		tags = [tag];
	}
	
	// Se aplica la clase a los elementos indicados
	var obj;
	for (var i = 0; i < tags.length; i++){
		obj = tags[i];
		// Se copian los métodos del prototype de la clase
		for (var p in clase.prototype){
			obj[p] = clase.prototype[p];
		}
		// Se reinstancia
		if (clase.apply){
			clase.apply(obj);
		} else {
			// Navegador viejo, no aplicable
			obj.__RCinit = clase;
			obj.__RCinit(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]);
		}
	}

	return true;
}


function AsignarComportamiento() {

	var objForm = document.forms
	//Asignamos comportamientos a los campos de texto
	for (i = 0; i < objForm.length; i++)  {
		for(k = 0; k < objForm[i].elements.length; k++) {
			if(objForm[i].elements[k].type == "text" || objForm[i].elements[k].type == "textarea"|| objForm[i].elements[k].type == "select-one") {
				Object.registraClase(objForm[i].elements[k], MetodoInput);	
			}
			if(objForm[i].elements[k].tagName == "INPUT" && objForm[i].elements[k].type == "radio") {
				Object.registraClase(objForm[i].elements[k], MetodoFocusCampo);	
			}

		}
	}
		//Asignamos comportamientos a las etiquetas label, para que al hacer click sobre ellas se active el radiobutton que le precede
		var objLabel = document.getElementsByTagName("label");
		for (i = 0; i < objLabel.length; i++)  {
			//Object.registraClase(objLabel[i].parentNode, MetodoClick);
			//Compruebo si la clase del label es activarCajetin, que se encuentra en los label de Clave y Firma correspondientes
			
			if (objLabel[i].className == "ActivarCajetin") {
				for(w = 0; w < objLabel[i].parentNode.parentNode.childNodes.length; w++){
				//alert(objLabel[i].parentNode.parentNode.innerHTML);
					if (objLabel[i].parentNode.parentNode.childNodes[w].tagName == "INPUT"){
						
						Object.registraClase(objLabel[i].parentNode.parentNode.childNodes[w], MetodoFirmaActivar);
					}
				}
			}
			 //Compruebo si la clase del label es DesactivarCajetin, que se encuentra en los label de Clave y Firma correspondientes
			else if (objLabel[i].className == "DesactivarCajetin") {
				for(w = 0; w < objLabel[i].parentNode.parentNode.childNodes.length; w++){
					if (objLabel[i].parentNode.parentNode.childNodes[w].tagName == "INPUT" || objLabel[i].parentNode.parentNode.childNodes[w].tagName == "SELECT"){
						Object.registraClase(objLabel[i].parentNode.parentNode.childNodes[w], MetodoFirmaDesactivar);
					}
				}
			}
		}
	
	}

function MetodoInput(){
	this.onclick = this._onclick
}  
MetodoInput.prototype._onclick = function () {
	
	var clase = new String(this.className);
	if(clase.indexOf("colorCampoNegro") == -1){ 
	if (this.type != "select-one" && (this.readOnly == false  && this.disabled == false) ) {
	 //this.value = "";
	}
	this.className = this.className + " " + "colorCampoNegro"
	};
	MetodoRadio(this);
	
}

function MetodoFirmaActivar(){
	this.onfocus = this._onfocus
}  
MetodoFirmaActivar.prototype._onfocus = function () {
	ActivarCapa(this.id)
}
function MetodoFirmaDesactivar(){
	this.onfocus = this._onfocus
}  
MetodoFirmaDesactivar.prototype._onfocus = function () {
DesactivarCapa()
}


 
function MetodoRadio (paramObj) {
	

	objPrincipal = paramObj.parentNode.childNodes;

	
	
		
	for (i = 0; i < objPrincipal.length;i++) {

		if(objPrincipal[i].type == "text" || objPrincipal[i].type == "textarea"|| objPrincipal[i].type == "select-one") {
			var objOriginal = objPrincipal[i];
			var obj = objPrincipal[i];
			break;
		}
	}
	if (objOriginal){
		
		var x = 1;
		var focus = true;
		var checked = false;
		
		obj = obj.nextSibling;
	
		if (obj){

			objPrevious = obj.previousSibling;
			
			for (i = 0; i < x; i++)
			{
				
				checked = true;
				if(objPrevious){
					if(objPrevious.tagName == "INPUT" && objPrevious.type == "radio") {
						
								
								objPrevious.checked = true;
								
							
						
								if (objPrevious.attributes['onclick']){

									var strFor = objPrevious.attributes['onclick'].value;

								eval(strFor)
								}
									break;


	
					}
					else {
						x = x + 1;
					}
					objPrevious =objPrevious.previousSibling;
				}

			}

		}

		
	}

	
	
	
	
	
}
function MetodoFocusCampo(){
	this.onfocus = this._onfocus
}  
MetodoFocusCampo.prototype._onfocus = function () {

	var x = 1;
	var objNext = this.nextSibling;
	for (i = 0; i < x; i++)
	{	
		if(objNext){

			if(objNext.type == "text" || objNext.type == "textarea" ) {

				objNext.focus();
				break;
			}
			else {
				x = x + 1;
				objNext =objNext.nextSibling;
			}					
		}
		else {
			break;
		}
	}
}

function LimpiaFormulario(fr) { 
	for (var i=0;i< fr.elements.length;i++) { 
		if (fr.elements[i].value != undefined && 
           (fr.elements[i].type == "text") || (fr.elements[i].type == "textarea")) { 
			fr.elements[i].value=""; 
		} 
	} 
} 


var popupactive=false;

function StartPopup(){
 xWin=window.open("/LCE/popup.html#abc","popup","height=10,width=10,screenX="+screen.availWidth+",screenY="+screen.availHeight);
 setTimeout("test_xWin()",700);
}

function test_xWin(){
  if ( (xWin==null) ||(typeof(xWin)=="undefined") ||(typeof(xWin.location.hash)!="string"))
  {
  	popupactive=true;
  }
  else
  {
  	xWin.close();
 	var div = document.getElementById("popup");
	if (div != null) {
		div.style.display = 'none';
	}
  	
  }  
  window.focus();
}


addOnLoad("AsignarComportamiento");
addOnLoad("componente");
//addOnLoad("averigua");




