



// Script para cambiar el formulario de solicitar mas info por el de enviar a un amigo, en las fichas de productos
function formularios() {
	if ( document.getElementById('form_solicitar_info').style.display == 'none' ) {
		document.getElementById('form_solicitar_info').style.display = 'block'
		document.getElementById('form_enviar_amigo').style.display = 'none'
		document.getElementById('botonamigo').value = 'Envía esta oferta a un amigo'			
	}
	else {
		document.getElementById('form_solicitar_info').style.display = 'none'
		document.getElementById('form_enviar_amigo').style.display = 'block'
		document.getElementById('botonamigo').value = 'Solicitar información'
	}				
}
// Script para mostar la celda de documentos, en las fichas de productos
function mostrar_documentos() {
	if (document.getElementById('divdocumentos').style.display == 'block')
		document.getElementById('divdocumentos').style.display = 'none'
	else
		document.getElementById('divdocumentos').style.display = 'block'
}
// Script para mostrar más fotos, en las fichas de productos
function cambiar_foto() {
	for ( i=0; i<=numeroiteracciones; i++ ) {
		if (document.getElementById('fotoitem').src.indexOf(fotosinmuebles[i]) != -1) {
			j = i+1
			document.getElementById('fotoitem').src = fotosinmuebles[j];
			document.getElementById('fotoitem2').href = fotosinmuebles[j];
			return true;
		}
	}	
	document.getElementById('fotoitem').src = fotosinmuebles[0];
	document.getElementById('fotoitem2').href = fotosinmuebles[0];
}
// Validar formularios "Solicitar mas información"
function obligatoriossolinfo(theForm){
// Uno por campo
	theForm = document.getElementById(theForm);
	if (theForm.Nombre.value == ""){
		alert("Debe introducir su nombre.");
		theForm.Nombre.focus();
		return (false);
	}
	if (theForm.Apellidos.value == ""){
		alert("Debe introducir sus apellidos.");
		theForm.Apellidos.focus();
		return (false);
	}
	if (theForm.EMail.value == ""){
		alert("Debe introducir una direcci&oacute;n de e-mail.");
		theForm.EMail.focus();
		return (false);
	}
	if (theForm.EMail.value != ""){
		// valida el e-mail
		var checkEmail = "@.";
		var checkStr = theForm.EMail.value;
		var EmailValid = false;
		var EmailAt = false;
		var EmailPeriod = false;
		for (i = 0;  i < checkStr.length;  i++){
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkEmail.length;  j++){
				if (ch == checkEmail.charAt(j) && ch == "@")
				EmailAt = true;
				if (ch == checkEmail.charAt(j) && ch == ".")
				EmailPeriod = true;
				if (EmailAt && EmailPeriod)
				break;
				if (j == checkEmail.length)
				break;
			}
// if both the @ and . were in the string
			if (EmailAt && EmailPeriod){
				EmailValid = true
				break;
			}
		}
		if (!EmailValid){
			alert("Debe introducir una direcci&oacute;n de e-mail correcta.\n");
			theForm.EMail.focus();
			return (false);	
		}              	
	}
	if (theForm.telefono.value == ""){
		alert("Debe introducir su telefono.");
		theForm.telefono.focus();
		return (false);
	}
	document.forms[1].submit()
}

function tipoInmueble(id,nombreId){
 //Activo pestaña
 //if(document.getElementById(nombreId).className=="tabInactive")
 //{
   
	 document.getElementById(nombreId).className="tabActive";
	 
	 document.getElementById("tipo_inmueble").value=id;
 //} 
 
 
 
 
 //Desactivo la otra que hay por ahora
 if(nombreId=="Naves"){
    if(document.getElementById("Suelo").className!="tabInactive"){
      document.getElementById("Suelo").className="tabInactive";
    }  
    if(document.getElementById("Oficinas").className!="tabInactive"){   
       document.getElementById("Oficinas").className="tabInactive";   
     }
    
    //if(document.getElementById("p1").style.display=="none"){
	  // document.getElementById("p1").style.display="block";
	//} 
     
 }
 if(nombreId=="Suelo"){
    if(document.getElementById("Naves").className!="tabInactive"){   
       document.getElementById("Naves").className="tabInactive";   
    }
    if(document.getElementById("Oficinas").className!="tabInactive"){   
       document.getElementById("Oficinas").className="tabInactive";   
     }
   
    //if(document.getElementById("p1").style.display=="none"){
	  // document.getElementById("p1").style.display="block";
	//} 
   
 }
 if(nombreId=="Oficinas"){
     if(document.getElementById("Naves").className!="tabInactive"){   
       document.getElementById("Naves").className="tabInactive";   
     }
     if(document.getElementById("Suelo").className!="tabInactive"){
       document.getElementById("Suelo").className="tabInactive";
     }
      //if(document.getElementById("p1").style.display=="block"){
	  //   document.getElementById("p1").style.display='none';
	  //}  
 }
 
 

}




function EnviarBusqueda(){

document.buscador.submit();

}

function EnviarBusquedaPagina(pagina){
document.getElementById("pag").value=pagina;
document.buscador.submit();

}

function EnviarBusquedaPaginaSiguiente(paginaSiguiente){
  document.getElementById("siguienteAMostrar").value=paginaSiguiente;
  document.buscador.submit();

}


function operacion_respuestaBusqueda() { 
if (http.readyState == 4) { 
		if (http.status == 200) { 
			if (http.responseText.indexOf('invalid') == -1) {							
				document.getElementById("textoTipoOperacionBusqueda").innerHTML = http.responseText;
				enProceso = false;
			}
	}
}
}




function ajaxTipoOperacionBusqueda(obj) {
	if (!enProceso && http) {
		var valor = escape(obj.selectedIndex);
		var url = "./ajax/tipo_operacion.asp?id_tipo_inmueble="+ valor+"&busqueda=s";	
		http.open("GET", url, true);
		http.onreadystatechange = operacion_respuestaBusqueda;
		enProceso = true;
		http.send(null);
	}
}



function ajaxprovinciaBusqueda() {
	if (!enProceso && http) {
		var valor = escape(document.getElementById("id_comunidad").value);
		if(valor!=""){
			var url = "./ajax/provinciaParaAlta.asp?id_comunidad="+ valor +"&busqueda=n";
			http.open("GET", url, true);
			http.onreadystatechange = provincia_respuesta_busqueda;
			enProceso = true;
			http.send(null);
		//Elimino las opciones del combo ciuddad y 
			selectCiu=document.getElementById("id_ciudad");
			selectCiu.options[0]=new Option("Seleccione provincia","","defaultSelected");;
			totalCiu=selectCiu.options.length;
			selectCiu.options.length = 1;
		
			
		}else{
		      document.getElementById("id_provincia").selectedIndex="";
		      document.getElementById("id_ciudad").selectedIndex="";		      
		     }	
	}
}



function provincia_respuesta_busqueda(){
var resultado="";
if (http.readyState == 4) { 
	if (http.status == 200) { 
		if (http.responseText.indexOf('invalid') == -1) {
		// Armamos un array, usando la coma para separar elementos
		document.getElementById("textoprovinciaBusqueda").innerHTML =http.responseText ;
		enProceso = false;
		}
	}
}
}




function ajaxCiudad() {
if (!enProceso && http) {
var valor = escape(document.getElementById("id_provincia").value);
var url = "./ajax/CargaciudadParaAlta.asp?id_provincia="+ valor+"&busqueda=n";
http.open("GET", url, true);
http.onreadystatechange = ciudad_respuesta;
enProceso = true;
http.send(null);
}
}
function ciudad_respuesta() { 
if (http.readyState == 4) { 
if (http.status == 200) { 
if (http.responseText.indexOf('invalid') == -1) {
// Armamos un array, usando la coma para separar elementos
results = http.responseText.split(","); 
document.getElementById("textociudad").innerHTML = results[0];
enProceso = false;
}
}
}
}


  
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) { xmlhttp = false; }
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) { xmlhttp = false; }
}
return xmlhttp;
}

var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest



