// CAMBIA EL COLOR DE FONDO Y BORDE EL OBJETO SELECCIONADO
// EJEMPLO: onmouseover(this); onmouseout(this); 
function rOver(object){ 
	fondo_old = object.style.background; 
	object.style.background = '#f0f0f0'; 
}
function rOut(object) { 
	object.style.background = fondo_old; 
}


function popup_redimensionar() {
	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; }
	top.resizeTo(ancho,alto);
	window.resizeBy(24,47);
	// Centrando Ventana
	iz=(screen.width-document.body.clientWidth) / 2; 
	de=(screen.height-document.body.clientHeight) / 2; 
	moveTo(iz,de);
}
	

/*---------------------------------------------------------------------------------------------*/
/* 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;
}
