// CAMBIA EL COLOR DE FONDO Y BORDE EL OBJETO SELECCIONADO
// EJEMPLO: onmouseover(this); onmouseout(this); 
function rOver(object){ 
	//fondo_old = object.style.background; 	// Esto parece que no va
	object.style.background = '#f0f0f0'; 
}
function rOut(object) { 
	object.style.background = '#FFFFFF'; 
}


// --- Cambia los retornos de carro de un texto a <br>
	function texto_br(texto){
		// --- Esto no se debe usar dentro de input ni textarea
		texto = String(texto);
		if(texto!=''){
			salto = new RegExp(String.fromCharCode(10),"g")
			texto=texto.replace(salto,"<br>")	
			return texto;
		}else{
			return '';
		}
	}
	
	function texto_specialchar(texto){
		texto = String(texto);
		if(texto!=''){
			texto=texto.replace(/>/g,"&gt;");
			texto=texto.replace(/</g,"&lt;");
			texto=texto.replace('"',"&quot;");
			
			return texto;
		}else{
			return '';
		}
	}




// --- Comprueba si un obj es un array
function _IS_ARRAY(obj){ if( obj.constructor.toString().indexOf("Array") == -1 ){ return false; }else{ return true; } }


// --- Comprueba si una variable esta definida
function _IS_DEFINED(variable){ return (typeof(window[variable]) != "undefined"); }


// --- Salta a una url
function go_location(href){ document.location.href=href; }


function popup_redimensionar() {
	var browser=navigator.appName;	// Nombre del navegador

	ancho =  document.getElementById('popup_redimensionar').offsetWidth;
	alto =  document.getElementById('popup_redimensionar').offsetHeight;
	if(ancho >= screen.width){ ancho = screen.width; }
	if(alto >= screen.height){ alto = screen.height; }
	
	
	if(browser == 'Microsoft Internet Explorer' ){ // IE
		//document.body.clientWidth = ancho;
		//document.body.clientHeight = alto;
		top.resizeTo(ancho,alto);
		window.resizeBy(24,47)
	}else{
		 window.innerWidth = ancho;
		 window.innerHeight = alto;
	}
	
	// Centrando Ventana
	iz=(screen.width-document.body.clientWidth) / 2; 
	de=(screen.height-document.body.clientHeight) / 2; 
	moveTo(iz,de);
}

function _wopen(direccion, w_name, ancho, alto, w_cfg){
	// --- Centrando ventana
	coordx= screen.width ? (screen.width-ancho)/2 : 0;	
	coordy= screen.height ? (screen.height-alto)/2 : 0;
	w_config = 'width='+ancho+',height='+alto+',top='+coordy+',left='+coordx;
	
	// --- Configuracion de la ventana
	if(w_cfg !=''){
		w_config += ', '+w_cfg;
	}else{w_config += ', scrollbars=yes,resizable=yes'; }	// --- Por defecto
	
	// --- Trae al frente la ventana
	var newwindow;
	newwindow = window.open(direccion, w_name, w_config);
	if (window.focus) {newwindow.focus() }
}





// --------------------------------------------------------------------------------------------------------------------
// --- Muestra ventanitas tooltip
// --------------------------------------------------------------------------------------------------------------------
var tooltipID = function(){
	// --- Esta funcion muestra el contenido de un div en un tooltip
	return{
		show:function(div_id){
			contenido = document.getElementById(div_id).innerHTML;
			tooltip.show(contenido);
		},
		hide:function(){
			tooltip.hide();
			
		}
	
	};	
}();


var tooltip=function(){
	// --- Esta funcion muestra un ToolTip
	// --- Forma de usar:
	// --- onmouseover="tooltip.show('texto');"  onmouseover="tooltip.hide();"
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 400;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

























	

/*---------------------------------------------------------------------------------------------*/
/* Los inputs deben tener unos nombres predefinidos y fijos el formulario: fila, estiloselec y */
/* estiloactual. Tambien se le pasa el identificador de la fila actualmente seleccionada.      */
/* Ejemplo: listaClick(document.seleccion, this.id); (el resultado es igual q el anterior)     */
/* *NOTA: si no se desea que se pueda desmarcar una fila marcada, basta con quitar el 'if'     */
/*        principal y toda la parte del 'else'.                                                */
/*---------------------------------------------------------------------------------------------*/
function listaClick (formulario, idfila) {
	if (formulario.fila.value!=idfila) {		/* Comprobamos si la fila no se encuentra marcada.*/
		if (formulario.estiloselec.value!=''){	/* Comprobamos si habia una fila marcada 		  */									
			document.getElementById(formulario.fila.value).className=formulario.estiloselec.value;
		} 
		formulario.fila.value=document.getElementById(idfila).id;	/* Almacenamos el id de la fila marcada. */
		formulario.estiloselec.value=formulario.estiloactual.value;		/* Almacenamos el estiloselec actual.         */
		document.getElementById(idfila).className='lista_select_marcada';/* Marcamos la fila seleccionada.   */
	}else{  							/* si se marca una fila ya marcada, se desmarca. */
		document.getElementById(formulario.fila.value).className=formulario.estiloselec.value;
		formulario.estiloactual.value=formulario.estiloselec.value;		   
		formulario.fila.value='';			/* ponemos el estiloselec anterior  */
		formulario.estiloselec.value='';
		//parent.bt_limpia();		
	}
}
/*-------------------------------------------------------------------------------------------*/   
/* Gestiona la pasada del ratón sobre las filas de la tabla.					   */
/*-------------------------------------------------------------------------------------------*/   
function listaOver (formulario, idfila) {
	if (document.getElementById(idfila).id!=formulario.fila.value) { // Si la fila no esta marcada.
		/* Antes de asignarle la clase de selección (!!ojo!! no la clase de fila marcada), es	*/
		/* decir, la clase de cuando se mueve el ratón sobre la fila, guardamos la clase que	*/
		/* tiene la fila antes de asignar la clase de selección.						*/
		formulario.estiloactual.value=document.getElementById(idfila).className;	 /* Guardamos y   */
		
		/* asignamos a la fila la clase de selección. */
		if(document.getElementById(idfila).className == 'lista_select') {
			document.getElementById(idfila).className = 'lista_select_over';
		}else{
			document.getElementById(idfila).className = 'lista_over';
		}		
	}else{
		//formulario.estiloactual.value=formulario.estiloselec.value;
		formulario.estiloactual.value=document.getElementById(idfila).className;	
	}
	
}
/*-------------------------------------------------------------------------------------------*/      
/* Gestiona cuando el puntero del ratón sale de la fila.                                     */
/*-------------------------------------------------------------------------------------------*/   
function listaOut (formulario, idfila) {
	/* Si el ratón sale de una fila no marcada, le pone la clase */
	/* que tenía antes de entrar						 */
	if (document.getElementById(idfila).id!=formulario.fila.value) {  
		document.getElementById(idfila).className=formulario.estiloactual.value; /* Le ponemos su clase normal*/
	}
}
/*-------------------------------------------------------------------------------------------*/      
/* Gestiona cuando se limpia el formulario de operaciones                                    */
/*-------------------------------------------------------------------------------------------*/   
function listaDesmarca (formulario) {
	if (document.getElementById(formulario.fila.value)) {
		document.getElementById(formulario.fila.value).className=formulario.estiloselec.value;
	}
	formulario.fila.value='';	
	formulario.estiloselec.value='';	
}
/*-------------------------------------------------------------------------------------------*/   
/*-------------------------------------------------------------------------------------------*/   
/*-------------------------------------------------------------------------------------------*/   
/*-------------------------------------------------------------------------------------------*/   
/*-------------------------------------------------------------------------------------------*/   
function countLines(strtocount, cols) {
	var hard_lines = 1;
	var last = 0;
	while ( true ) {
		last = strtocount.indexOf("\n", last+1);
		hard_lines ++;
		if ( last == -1 ) break;
	}
	var soft_lines = Math.round(strtocount.length / (cols-1));
	var hard = eval("hard_lines  " + unescape("%3e") + "soft_lines;");
	if ( hard ) soft_lines = hard_lines;
	return soft_lines;
}

function cleanForm() {	
   
	for ( var n_form in document.forms ) {	    				    		    
		the_form = document.forms[n_form];
		//alert (the_form.name);			
			    
		for ( var x in the_form ) {
		  if ( ! the_form[x] ) continue;
		  if( typeof the_form[x].rows != "number" ) continue;
		  the_form[x].rows = countLines(the_form[x].value,the_form[x].cols) + 1;
		}
	
	}		    
	setTimeout("cleanForm();", 300);	    
}




function popup(url,ancho,alto) { 
	// Abre una ventana y la centra
	var win = null;
	LeftPosition = (screen.width) ? (screen.width-ancho)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-alto)/2 : 0;
	settings = 'height='+alto+',width='+ancho+',top='+TopPosition+',left='+LeftPosition+',toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0,dependent=0,channelmode=0';
	win = window.open(url,'',settings);
	//window.open(url , "" , "width="+ancho+",height="+alto+",toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0,dependent=0,channelmode=0"); 
}



function button_op(form,op){
	eval("document."+form+".op.value=op");
	eval("document."+form+".submit()");
}



// Busca un valor en un array
Array.prototype.in_array = function(search_term) {
  var i = this.length;
  if (i > 0) {
	 do {
		if (this[i] === search_term) {
		   return true;
		}
	 } while (i--);
  }
  return false;
}



//**************** funciones de idiomas *******************************/

var idioma_seleccionado = 'es';
	
// Función que cambia el idioma de los campos ocultos al campo visible de los idiomas
function cambiar_idioma(codigo_idioma,campo){
	texto = document.getElementById('idioma_'+codigo_idioma).value;
	document.getElementById('campo_'+campo).value = texto;
	idioma_seleccionado = codigo_idioma;
}


// Función inversa a la anterior, cambia del campo visible al campo oculto correspondiente
function meter_idioma(campo){
	texto = document.getElementById('campo_'+campo).value;
	document.getElementById('idioma_'+idioma_seleccionado).value = texto;
}

