/*

	LISTA DE EQUIVALENCIAS DE ACENTOS

	\u00e1 -> á 

	\u00e9 -> é 

	\u00ed -> í 

	\u00f3 -> ó 

	\u00fa -> ú 

	\u00c1 -> Á 

	\u00c9 -> É 

	\u00cd -> Í 

	\u00d3 -> Ó 

	\u00da -> Ú 

	\u00f1 -> ñ 

	\u00d1 -> Ñ 

*/
function dameListaModelosFiltroProfesional(sel, idProfesional) {

	var idMarca = sel.options[sel.selectedIndex].value;

	if (idMarca == "") {

		document.getElementById('id_modelo').options.length = 0;

		document.getElementById('id_modelo').options[document.getElementById('id_modelo').options.length] = new Option('Selecciona marca...','');		

	} else {

		document.getElementById('id_modelo').options.length = 0;

		document.getElementById('id_modelo').options[document.getElementById('id_modelo').options.length] = new Option('Calculando...','');

	}

	if(idMarca.length>0) {

		

		ajax.requestFile = 'includes/dame_modelos_filtro_profesional.php?idMarca='+idMarca+'&idProfesional='+idProfesional;	

		ajax.onCompletion = creaModelosFiltro;	

		ajax.runAJAX();	

	}	

}



function creaModelosFiltroProfesional() {

	var obj = document.getElementById('id_modelo');

	eval(ajax.response);	

}


function dameListaModelosFiltro(sel) {

	var idMarca = sel.options[sel.selectedIndex].value;

	if (idMarca == "") {

		document.getElementById('id_modelo').options.length = 0;

		document.getElementById('id_modelo').options[document.getElementById('id_modelo').options.length] = new Option('Selecciona marca...','');		

	} else {

		document.getElementById('id_modelo').options.length = 0;

		document.getElementById('id_modelo').options[document.getElementById('id_modelo').options.length] = new Option('Calculando...','');

	}

	if(idMarca.length>0) {

		

		ajax.requestFile = 'includes/dame_modelos_filtro.php?idMarca='+idMarca;	

		ajax.onCompletion = creaModelosFiltro;	

		ajax.runAJAX();	

	}	

}



function creaModelosFiltro() {

	var obj = document.getElementById('id_modelo');

	eval(ajax.response);	

}



function abreBusqueda() {

	

	if (document.getElementById('busqueda_avanzada').style.display == "") {

		document.getElementById('busqueda_avanzada').style.display = "none";

	} else {

		document.getElementById('busqueda_avanzada').style.display = "";

	}

}





function dameListaLocalidades(sel) {

	var idProvincia = sel.options[sel.selectedIndex].value;

	document.getElementById('id_localidad').options.length = 0;	

	ajax.requestFile = 'includes/dame_localidades.php?idProvincia='+idProvincia;	

	ajax.onCompletion = creaLocalidades;	

	ajax.runAJAX();	

	

	

	var idProvincia = sel.options[sel.selectedIndex].value;

	if (idProvincia == "") {

		document.getElementById('id_localidad').options.length = 0;

		document.getElementById('id_localidad').options[document.getElementById('id_localidad').options.length] = new Option('Selecciona...','');			

	} else {

		document.getElementById('id_localidad').options.length = 0;

		document.getElementById('id_localidad').options[document.getElementById('id_localidad').options.length] = new Option('Calculando...','');		

	}		

}



function creaLocalidades() {

	var obj = document.getElementById('id_localidad');

	eval(ajax.response);	

}



function checkEmail(str)

{

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(str)){

		return true;

	}

	return false;

}



function validaVal() {

	if (document.frmValidar.passwd.value == "" || !checkEmail(document.frmValidar.emailV.value)) {

		alert('Por favor, introduce una direcci\u00f3n de correo electr\u00f3nico y una contrase\u00f1a v\u00e1lidos para iniciar sesi\u00f3n.');

		return false;

	} else { 

		return true;

	}	

}





function ventana(id){

	window.open('ampliar_imagen.php?cod='+id,'ampliacion','toolbar=no,location=no,status=yes,menubar=no, scrollbars=yes,resizable=yes,width=600,height=500,top=50,left=50');	

}

function condiciones(cuales){

	if (cuales == "particulares") {

		window.open('condiciones_particulares.php','condiciones_particulares','toolbar=no,location=no,status=yes,menubar=no, scrollbars=yes,resizable=yes,width=800,height=600,top=50,left=50');	

	} else {

		window.open('condiciones_profesionales.php','condiciones_profesionales','toolbar=no,location=no,status=yes,menubar=no, scrollbars=yes,resizable=yes,width=800,height=600,top=50,left=50');	

	}

}

function validarContactoVehiculo() {

	if (document.frmVehiculo.nombre.value == "" || document.frmVehiculo.telefono.value == "" 

		|| document.frmVehiculo.id_provincia.value == "" || document.frmVehiculo.id_localidad.value == "") {

		alert('Por favor, introduce correctamente los campos marcados con un\n asterisco (*), son necesarios.');

		return false;

	} else { 

		if (!checkEmail(document.frmVehiculo.email.value)) {

			alert('Por favor, introduce una direcci\u00f3n de correo electr\u00f3nico correcta.');

			return false;

		} else {

			document.getElementById('contactoVehiculo').value=1;

			return true;

		}

	}	

}

function validarAlertasEmail() {

	if (!checkEmail(document.frmAlertas.email_alerta.value)) {

		alert('Por favor, introduce una direcci\u00f3n de correo electr\u00f3nico correcta.');

		return false;

	} else {

		document.getElementById('alertasEmail').value=1;

		return true;

	}

}

function limpiaCampo(campo, frase) {

	if (document.getElementById(campo).value == frase) {

		document.getElementById(campo).value = "";

	}

}

function validarContactoWeb() {

	if (document.frmContacto.nombre.value == "" || document.frmContacto.telefono.value == ""  || document.frmContacto.mensaje.value == "") {

		alert('Por favor, rellena correctamente todos los campos del formulario de contacto.');

		return false;

	} else { 

		if (!checkEmail(document.frmContacto.email.value)) {

			alert('Por favor, introduce una direcci\u00f3n de correo electr\u00f3nico correcta.');

			return false;

		} else {

			if (document.frmContacto.txt_img.value == "") {

				alert("Por favor, introduce el texto de la imagen.");

				return false;

			} else {

				document.getElementById('contactoWeb').value=1;

				return true;

			}

		}

	}	

}

function validarContactoTasacion() {

	if (document.frmContacto.nombre.value == "" || document.frmContacto.telefono.value == ""  || document.frmContacto.marca.value == "" 
		  || document.frmContacto.modelo.value == "" || document.frmContacto.fecha_matriculacion.value == "" || document.frmContacto.kilometros.value == "" 
		   || document.frmContacto.combustible.value == "") {

		alert('Por favor, rellena correctamente todos los campos del formulario resaltados en naranja.');

		return false;

	} else { 

		if (!checkEmail(document.frmContacto.email.value)) {

			alert('Por favor, introduce una direcci\u00f3n de correo electr\u00f3nico correcta.');

			return false;

		} else {

			if (document.frmContacto.txt_img.value == "") {

				alert("Por favor, introduce el texto de la imagen.");

				return false;

			} else {

				document.getElementById('contactoTasacion').value=1;

				return true;

			}

		}

	}	

}

function info(cuales){

	if (cuales == "leame") {

		window.open('importante_leame.php','importante_leame','toolbar=no,location=no,status=yes,menubar=no, scrollbars=yes,resizable=yes,width=600,height=600,top=50,left=50');	

	}

}