function colorear_fila(fila, color, letra, colsel)
{
    nreg = fila.cells.length
    for (i=0; i<nreg; i++) {
      if (colsel.length > 0) {
        fila.cells[i].style.backgroundColor=colsel
        fila.cells[i].style.color=letra
      }
      else {
        fila.cells[i].style.backgroundColor=color
        fila.cells[i].style.color=letra
      }
    }
}


function ventanaFicha(id){
    window.open("/busqueda/index.php?Evento=MOSTRAR_INFO_FINCA&Id="+id,"","scrollbars=yes,resizable=yes,width=700,height=520,left=15,top=15");
}


function order_by(string,consulta){
	var tr= consulta.search("order");
	
	if(tr==-1){
	var ReConsulta= consulta +" order by "+ string;
	}
	else{
	consulta=consulta.substring(0,tr);
	var ReConsulta= consulta +" order by "+ string;
	}
	
	document.ftabla.TL_Consulta.value=ReConsulta;
	document.ftabla.submit();
	
}


//Funciones destinadas a la getión de la cabecera
function mostrar_banner( ) {
	//Buscamos el flash y la capa con las imágenes estáticas
	var flash_cabecera = document.getElementById( "flash_cabecera" );
	var div_cabecera = document.getElementById( "capa_cabecera_fija" );
	//Ocultamos el flash
	flash_cabecera.style.display = "none";
	//Mostramos la capa
	div_cabecera.style.display = "block";
}


//Función para la gestión del buscador de inmuebles de la home
function selecciona_sitio( ) {
	if (document.form_busqueda.TipoGestion.options[document.form_busqueda.TipoGestion.selectedIndex].value!='A'){
		document.form_busqueda.Precio[1]=new Option('< 90.000€','1');
		document.form_busqueda.Precio[2]=new Option('90.000€ > < 120.000€','2');
		document.form_busqueda.Precio[3]=new Option('120.000€ > < 150.000€','3');
		document.form_busqueda.Precio[4]=new Option('150.000€ > < 180.000€','4');
		document.form_busqueda.Precio[5]=new Option('> 180.000€','5');
		document.form_busqueda.Precio.length = 6;
		
	}
	else{
		document.form_busqueda.Precio[1]=new Option('< 350€','1'); 
		document.form_busqueda.Precio[2]=new Option('350€ > < 500€','2');
		document.form_busqueda.Precio[3]=new Option('> 500€ ','3');
		document.form_busqueda.Precio.length = 4;  
	}
}	


//------------- Funciones de gestión de solapas de formularios ---------------
// div contenedora de texto --> forms_texto
// div contenedora del form --> forms_datos

//Función que muestra la introducción de texto
function forms_mostrar_texto( ) {
	var div_texto = document.getElementById( "forms_texto" );
	var div_form = document.getElementById( "forms_datos" );
	var a_texto = document.getElementById( "forms_a_texto" );
	var a_form = document.getElementById( "forms_a_datos" );

	div_form.style.display = "none";
	div_texto.style.display = "block";		
	a_texto.className = "forms_pestana_sel";
	a_form.className = "forms_pestana_desel";
}


//Función que muestra el formulario
function forms_mostrar_datos( ) {
	var div_texto = document.getElementById( "forms_texto" );
	var div_form = document.getElementById( "forms_datos" );
	var a_texto = document.getElementById( "forms_a_texto" );
	var a_form = document.getElementById( "forms_a_datos" );

	div_texto.style.display = "none";	
	div_form.style.display = "block";
	a_texto.className = "forms_pestana_desel";
	a_form.className = "forms_pestana_sel";

}


//Funciones para el simulador de hipotecas
function isnumber(str) {
	isPrice = /^\d+\.\d{2}$/;
	return isPrice.test( str );
}

function calcular_hipoteca()
{
	var importe_euros
	// primero validamos los campos
	// 'importe' (en 'moneda' pesetas o euros)
	// tipo interes ('tient' parte entera y 'tifrac' parte fraccionaria)
	// 'plazo'
	
	if (document.fhip.importe.value.length == 0 || !isNaN(document.fhip.importe.value) == 0) {
		alert("Porfavor ponga un importe valido")
		document.fhip.importe.focus()
		return false
	}

	if (document.fhip.tient.value.length == 0 && document.fhip.tifrac.value.length == 0) {
		if (confirm("Debe poner un tipo de interes, ¿Desea usar el valor por defecto?")) {
			document.fhip.tient.value = 3
			document.fhip.tifrac.value = 89
		}
	}
	if (document.fhip.tient.value.length == 0 || !isNaN(document.fhip.tient.value) == 0) {
		alert("Porfavor ponga un tipo de interés valido")
		document.fhip.tient.focus()
		return false
	}
	if (document.fhip.tifrac.value.length == 0 || !isNaN(document.fhip.tifrac.value) == 0) {
		alert("Porfavor ponga un tipo de interés valido")
		document.fhip.tifrac.focus()
		return false
	}

	// bien. todo es medio normal. tengo numeritos para trabajar.
	// haz los calculos (todo siempre en euros)

	/// los datos
	plazos = document.fhip.plazo.value
	importe_euros = document.fhip.importe.value
	if (document.fhip.moneda.value == 2) {
		// se ha puesto el importe en pesetas: conviertelo
		importe_euros = document.fhip.importe.value / 166.386
	}
	tipo_interes = eval(document.fhip.tient.value + '.' + document.fhip.tifrac.value)
	/// los calculos
	// interes periodo:
	ip = tipo_interes/100/12
	// pagos  mensuales
	pm = plazos*12
	// cuota mensual:
	cm = (importe_euros*ip) / (1 - Math.pow((1+ip), (-pm)))

	document.fhip.cuotamensual.value = /\d*.\d\d/.exec(cm)
	document.fhip.cuotamensual_ptas.value = Math.round(cm*166.386)

	return /\d*.\d\d/.exec(cm)
}


// ------------------ Funciones de control del scroll de la home ------------------
var scroll_paso = 10;
var max_delay = 1000;
var min_delay = 20;

function scroll_up( ) {
	var scroll = document.getElementById( "marquesina_inferior" );
	scroll.direction = "up";
}

function scroll_down( ) {
	var scroll = document.getElementById( "marquesina_inferior" );
	scroll.direction = "down";
}

function scroll_pause( ) {
	var scroll = document.getElementById( "marquesina_inferior" );
	scroll.stop( );	
}

function scroll_play( ) {
	var scroll = document.getElementById( "marquesina_inferior" );
	scroll.start( );	
}

function scroll_menos( ) {
	var scroll = document.getElementById( "marquesina_inferior" );
	if( scroll.scrollDelay < max_delay ) {
		scroll.scrollDelay = scroll.scrollDelay + scroll_paso;
	}
}

function scroll_mas( ) {
	var scroll = document.getElementById( "marquesina_inferior" );
	if( scroll.scrollDelay > min_delay ) {
		scroll.scrollDelay = scroll.scrollDelay - scroll_paso;
	}
}

function ventanaCircular(f)
{
	var ventana= window.open("","circular","top=20, left=20, width=370, height=280, resizable=yes");
	ventana.document.write("<html><head><title>Foto circular</title></head><body>");
	ventana.document.write("<applet code='EggApplet.class' archive='e3D.jar' codebase='../inc/librerias/e3D/' width='350' height='260' name='EGGPhoto'>");
    ventana.document.write("<PARAM NAME='icons' VALUE='applet.ear'><PARAM NAME='album' VALUE='"+f+"'><PARAM NAME='displaylist' VALUE='false'></applet>");
	ventana.document.write("</body></html>");
}

function ventanaCircular2(f)
{
	var ventana= window.open("","circular","top=475, left=410, width=370, height=280, resizable=yes");
	ventana.document.write("<html><head><title>Foto circular</title></head><body>");
	ventana.document.write("<applet code='EggApplet.class' archive='e3D.jar' codebase='../inc/librerias/e3D/' width='350' height='260' name='EGGPhoto'>");
    ventana.document.write("<PARAM NAME='icons' VALUE='applet.ear'><PARAM NAME='album' VALUE='"+f+"'><PARAM NAME='displaylist' VALUE='false'></applet>");
	ventana.document.write("</body></html>");
}