function compruebaPedido(formulario){

	
	nombre=document.getElementById('nombre').value;
	apellidos=document.getElementById('apellidos').value;
	telefono2=document.getElementById('telefono2').value;
	habitaciones=document.getElementById('habitaciones').value;
	precio=document.getElementById('precio').value;
	
	//compruebo que los campos nombre y apellidos no esten vacios
	if((nombre=="")||(apellidos=="")){
		alert("Introduzca su nombre y apellidos");
		return false;
	}
	
	//compruebo que el telefono tenga 9 numeros y que no este vacio
	longitud=telefono2.length;
	if ((isNaN(telefono2))||(telefono2=="")||(longitud<9)||(longitud>9)) { 
			alert("El teléfono introducido no es correcto");
			return false;
	}
	
	
	if ((isNaN(habitaciones))||(habitaciones=="")){
		alert("Introduzca el número de dormitorios");
		return false;	
	}
	if ((isNaN(precio))||(precio=="")){
		alert("Introduzca el precio del inmueble");
		return false;	
	}
	
	acepto=document.getElementById('acepto').checked;
	
	if(acepto==false){
		alert("Debe aceptar las condiciones legales.");
		return false;
	
	}

}

function validavalo(formulario){
	
	nombre=document.getElementById('nombre').value;
	apellidos=document.getElementById('apellidos').value;
	direccion=document.getElementById('direccion').value;
	telefono2=document.getElementById('telefono2').value;
	email=document.getElementById('email').value;
	direccionim=document.getElementById('direccionim').value;
	numero=document.getElementById('numero').value;
	poblacionim=document.getElementById('poblacionim').value;
	cpostal=document.getElementById('cpostal').value;
	observaciones=document.getElementById('observaciones').value;
	
	
	//compruebo que los campos nombre y apellidos no esten vacios
	if((nombre=="")||(apellidos=="")||(telefono2=="")||(direccionim=="")||(numero=="")||(poblacionim=="")||(cpostal=="")){
		alert("Rellene todos los campos");
		return false;
	}
	
	longitudc=cpostal.length;
	if ((isNaN(cpostal))||(cpostal=="")||(longitudc<5)||(longitudc>5)){
			alert("El CP introducido no es correcto");
			return false;
	
	}
	
	
	
	//compruebo que el telefono tenga 9 numeros y que no este vacio
	longitud=telefono2.length;
	if ((isNaN(telefono2))||(telefono2=="")||(longitud<9)||(longitud>9)) { 
			alert("El teléfono introducido no es correcto");
			return false;
	}
	
	//comprueba mediante la funcion compruebamail que tiene el formato correcto
	if(compruebamail(email)==false){
			alert("Mail con formato no válido");
			return false;
		
	}
	
	acepto=document.getElementById('acepto').checked;
	
	if(acepto==false){
		alert("Debe aceptar las condiciones legales.");
		return false;
	
	}
	
	

}




function compruebamail(texto){ 
		var mailres = true;             
		var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
        var arroba = texto.indexOf("@",0); 
		if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 
			var punto = texto.lastIndexOf("."); 
                
     for (var contador = 0 ; contador < texto.length ; contador++){ 
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){ 
            mailres = false; 
            break; 
     } 
    } 

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
     mailres = true; 
    else 
     mailres = false; 
                 
    return mailres; 
} 




function getProvinces(state,divResult,pagina){
	if(state!="-"){
		url="getProvinces.php?state="+state+"&pagina="+pagina;
		printDivResult(divResult,url);
	
	}
	
}

function getPosFromProvince(province,divResult,pagina){
	
	if(province!="-"){
		url="getpos.php?province="+province+"&pagina="+pagina;
		printDivResult(divResult,url);
	
	}
}




function printDivResult(divResults,url){
		//compruebo que la div exista
		var destination=document.getElementById(divResults);
		var ajax=nuevoAjax();
		ajax.open("GET", url, true);
		ajax.onreadystatechange=function(){	
			if((ajax.readyState==1)||(ajax.readyState==2)||(ajax.readyState==3)){
			destination.innerHTML="<div align='center'><img src='loading.gif'></div>";
			}
			if (ajax.readyState==4){
				destination.innerHTML=ajax.responseText;
				if (typeof document.body.style.maxHeight != "undefined")		//Ejecutara la funcion con navegadores superiores a IE6
					label_pos();
			} 
		}
		ajax.send(null);
}



	

//creo el objeto Ajax	
function nuevoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) { 
		xmlhttp = false;
		} 
		}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
}



function carga_mapa(latitude,longitude){
	var icon = new GIcon();  
				icon.image = "images/logo_tecno.png";  
				icon.iconSize = new GSize(25, 25); 
				icon.iconAnchor = new GPoint(25, 25); 
				icon.infoWindowAnchor = new GPoint(31, 8);  
		      function createMarker(point) {
		        var marker = new GMarker(point,icon);
		       
		        return marker;
		      } 				  
	var map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(latitude,longitude),17);
	var point = new GLatLng(latitude,longitude);
	var marker = createMarker(point)
	map.addOverlay(marker);

}