// JavaScript Document
function GotoContacta(url) {
	//url = 'form_amigo.htm?';
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  	tamX = (myWidth - 290)/2;
	tamY = (myHeight - 240)/2;
	 if(navigator.appName == "Netscape") {
		window.open(url,'win1','height=240,width=290,screenX='+tamX+',screenY='+tamY);
	 } 
	 else if( navigator.appName == "Microsoft Internet Explorer") {
	 	window.open(url,'win1','height=240,width=290,left='+tamX+',top='+tamY);
	}
}

function GotoContacta2(id) {
	url = 'tabla_ficha_inmueble.php?idinmueble='+id;
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  	tamX = (myWidth - 601)/2;
	tamY = (myHeight - 545)/2;
	 if(navigator.appName == "Netscape") {
		window.open(url,'win2','height=545,width=620,scrollbars=YES,screenX='+tamX+',screenY='+tamY);
	 } 
	 else if( navigator.appName == "Microsoft Internet Explorer") {
	 	window.open(url,'win2','height=545,width=620,scrollbars=YES,left='+tamX+',top='+tamY);
	}
}

function GoToPromocion(id) {
	url = 'promociones/promo_descri.php?codpromo='+id;
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  	tamX = (myWidth - 601)/2;
	tamY = (myHeight - 545)/2;
	 if(navigator.appName == "Netscape") {
		window.open(url,'win2','height=545,width=601,screenX='+tamX+',screenY='+tamY);
	 } 
	 else if( navigator.appName == "Microsoft Internet Explorer") {
	 	window.open(url,'win2','height=545,width=601,left='+tamX+',top='+tamY);
	}
}

function GotoNoticia(id) {
	url = 'tabla_noticia.php?id='+id;
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  	tamX = (myWidth - 540)/2;
	tamY = (myHeight - 260)/2;
	 if(navigator.appName == "Netscape") {
		window.open(url,'win1','height=260,width=540,screenX='+tamX+',screenY='+tamY);
	 } 
	 else if( navigator.appName == "Microsoft Internet Explorer") {
	 	window.open(url,'win1','height=260,width=540,left='+tamX+',top='+tamY);
	}
}

function GotoCalculadora(id,ancho, alto) {
	switch (id){
		case '1': url = 'calcPrestamo.php?'; break;
		case '2': url = 'calcCuota.php?'; break;
		case '3': url = 'calcCompraVenta.php?';break;
		case '4': url = 'calcPrestamoHipotecario.php?'; break
	}
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  	tamX = (myWidth - ancho)/2;
	tamY = (myHeight - alto)/2;
	 if(navigator.appName == "Netscape") {
		window.open(url,'win1','height='+alto+',width='+ancho+',screenX='+tamX+',screenY='+tamY);
	 } 
	 else if( navigator.appName == "Microsoft Internet Explorer") {
	 	window.open(url,'win1','height='+alto+',width='+ancho+',left='+tamX+',top='+tamY);
	}
}


function Ejecuta_Buscar(modo,opcion){
	if (document.form1.select_tipo.value!=''){
		
		f=eval('document.form1');
		url = 'index.php?opc='+ opcion +'&modo=' + modo;
		f.action=url;
		document.form1.oculto.value="1";
		f.submit();
	}
	else{
		if (document.form1.ref.value==''){
			alert('SELECCIONE UN TIPO DE INMUEBLE');
		}else{
			f=eval('document.form1');
			url = 'index.php?opc='+ opcion +'&modo=' + modo;
			f.action=url;
			document.form1.oculto.value="1";
			f.submit();
		}
	}
}

function enviar(form){
	if (document.form1.select_tipo.value!=''){
		f=eval('document.'+form);
		f.submit();
	}
	else{
		alert('SELECCIONE UN TIPO DE INMUEBLE');
	}
}

function comprobar_tipo(){
	tipo = document.form1.select_tipo;
	habit = document.form1.input_habit;
	if ( tipo.value.charAt(0)  == '1')
		habit.disabled=false;
	else 
		habit.disabled=true;
	}
	
function envio_form()
{
	var f_franqui=document.form_franquicias;

	if(f_franqui.nombre.value.length==0)
		{
		alert("Por favor introduzca un Nombre");
		f_franqui.nombre.focus();
		return void(0);
		}
		
   if(isNaN(f_franqui.telefono.value)||	(f_franqui.telefono.value.length==0))
		{
		alert("Por favor introduzca un número de Teléfono");
		f_franqui.telefono.focus();
		return void(0);
		}


	if(f_franqui.email.value.length==0)
		{
		alert("Por favor introduzca un E mail");
		f_franqui.email.focus();
		return void(0);
		}

    if(f_franqui.email.value !=0)
		{
			var pos1, pos2, bOk = true; 
    		pos1 = f_franqui.email.value.indexOf('@', 0); 
    		bOk = bOk && (pos1 > 0); 
    		if (!bOk)
				{ 
     				alert("Por favor introduzca una dirección de correo válida"); 
     				f_franqui.email.focus(); 
     				return false; 
    			} 
		}

	f_franqui.submit();
}

function envio_form_amigo()
{
	var amigo=document.form_amigo;

	if(amigo.nombre.value.length==0)
		{
		alert("Por favor introduzca un Nombre");
		amigo.nombre.focus();
		return void(0);
		}
		
	if(amigo.emailamigo.value.length==0)
		{
		alert("Por favor introduzca el E mail de su amigo");
		amigo.emailamigo.focus();
		return void(0);
		}
		 
   if(amigo.emailamigo.value !=0)
		{
			var pos1, pos2, bOk = true; 
    		pos1 = amigo.emailamigo.value.indexOf('@', 0); 
    		bOk = bOk && (pos1 > 0); 
    		if (!bOk)
				{ 
     				alert("Por favor introduzca una dirección de correo válida"); 
     				amigo.emailamigo.focus(); 
     				return false; 
    			} 
		}
		
	amigo.submit();
	window.close();
}


function comprobar_tipo_busqueda(){
	tipo = document.busco_casa.select_tipo;
	habit = document.busco_casa.input_habit;
	if ( tipo.value.charAt(0) == '1')
		habit.disabled=false;
	else 
		habit.disabled=true;
	}
	
function enviar_busco(){
	if (document.busco_casa.select_tipo.value!=''){
		f=eval('document.busco_casa');
		f.submit();
	}
	else{
		alert('SELECCIONE UN TIPO DE INMUEBLE');
	}
}
function envio_datos_busco(){
	if (document.busco_casa.select_tipo.value!=''){
		f=eval('document.busco_casa');
		f.submit();
	}
	else{
		alert('SELECCIONE UN TIPO DE INMUEBLE');
	}
}


function ValorLetra(Num)
{
    LaLetraEs= new Array();LaLetraEs[0]  = "T" ;LaLetraEs[1]  = "R" ;LaLetraEs[2]  = "W" ;
                           LaLetraEs[3]  = "A" ;LaLetraEs[4]  = "G" ;LaLetraEs[5]  = "M" ;
                           LaLetraEs[6]  = "Y" ;LaLetraEs[7]  = "F" ;LaLetraEs[8]  = "P" ;
                           LaLetraEs[9]  = "D" ;LaLetraEs[10] = "X" ;LaLetraEs[11] = "B" ;
                           LaLetraEs[12] = "N" ;LaLetraEs[13] = "J" ;LaLetraEs[14] = "Z" ;
                           LaLetraEs[15] = "S" ;LaLetraEs[16] = "Q" ;LaLetraEs[17] = "V" ;
                           LaLetraEs[18] = "H" ;LaLetraEs[19] = "L" ;LaLetraEs[20] = "C" ;
                           LaLetraEs[21] = "K" ;LaLetraEs[22] = "E" ;
    return LaLetraEs[Num];
}



function inscripcion_buscar()
{
	var busco=document.busco_casa;
		if(busco.input_nombre.value.length==0)
			{
			alert("Por favor introduzca su Nombre");
			busco.input_nombre.focus();
			return void(0);
			}
		if(busco.input_apellido1.value.length==0)
			{
			alert("Por favor introduzca su Primer Apellido");
			busco.input_apellido1.focus();
			return void(0);
			}
		if(busco.input_apellido2.value.length==0)
			{
			alert("Por favor introduzca su Segundo Apellido");
			busco.input_apellido2.focus();
			return void(0);
			}
		if(busco.input_dni.value.length==0)
			{
			alert("Por favor introduzca su D.N.I.");
			busco.input_dni.focus();
			return void(0);
			}else{
				// COMPROBACIÓN DE LA LETRA DEL DNI
				if ((busco.input_dni.value.length != 9)){
					alert(" \t Escriba un NIF correcto \n");
						return void(0);
				}else{
					var dni_numero=busco.input_dni.value.substring(0,8);
					var dni_calcular=(dni_numero%23);
					var letra=ValorLetra(dni_calcular);
					var dni_letra= busco.input_dni.value.substring(8,9);
					if(letra!=(dni_letra.toUpperCase())){
						alert (" \t La letra del NIF no coincide");
						return void(0);
	
					}
				}
			}
		if(busco.input_iniciales.value.length==0)
			{
			alert("Por favor introduzca sus Iniciales");
			busco.input_iniciales.focus();
			return void(0);
			}
	   if(isNaN(busco.input_telefono.value)||(busco.input_telefono.value.length==0))
			{
			alert("Por favor introduzca un número de Teléfono");
			busco.input_telefono.focus();
			return void(0);
			}
		if(busco.input_email.value.length==0)
			{
			alert("Por favor introduzca su E mail");
			busco.input_email.focus();
			return void(0);
			}
	    if(busco.input_email.value !=0)
			{
				var pos1, bOk = true; 
    			pos1 = busco.input_email.value.indexOf('@', 0); 
    			bOk = bOk && (pos1 > 0); 
    			if (!bOk)
					{ 
     					alert("Por favor introduzca una dirección de correo válida"); 
     					busco.input_email.focus(); 
     					return false; 
    				} 
			}
		if(busco.acepto_servicio.checked)
		{
			if(busco.acepto_proteccion.checked)
			{			
				busco.action ="envio_busco_casa.php";
				busco.target="EnvioBuscoCasa";
				busco.submit();
			}
			else
			{
				alert("No se puede continuar el registro si no acepta los términos");
				busco.acepto_proteccion.focus();
				return void(0);
			}
		}
		else
		{
			alert("No se puede continuar el registro si no acepta los términos");
			busco.acepto_servicio.focus();
			return void(0);
		}

}
