function showSelect(cual){
	if (cual.value == 1){
		document.getElementById('marcas').style.display = 'block';
		document.getElementById('modelos').style.display = 'block';
		//document.getElementById('cilindrada').style.display = 'block';
		document.getElementById('marca').selectedIndex = 0;
		document.getElementById('modelo').innerHTML = "<option value=''>ELIGE UNA MARCA</option>";
	}else{
		document.getElementById('marcas').style.display = 'none';
		document.getElementById('modelos').style.display = 'none';
		document.getElementById('cilindrada').style.display = 'none';
	}
}

function cargarCilindrada(){
	if (document.altaUpdate.marca.selectedIndex == 0 || document.altaUpdate.marca.value == "Harley-Davidson" || document.altaUpdate.marca.value == "Buell") document.getElementById('cilindrada').style.display = "none";
	else document.getElementById('cilindrada').style.display = "block";
	
	document.altaUpdate.cilindrada.selectedIndex == 0;
}

function validarFormulario(){
	var validado = true;
	
	if (document.altaUpdate.email.value == ""){
		validado = false;
		document.getElementById('mail').className = 'obligatorio';
	}else if (valEmail(document.altaUpdate.email.value) == false){
		validado = false;
		document.getElementById('mail').className = 'obligatorio';
	}else if (document.altaUpdate.email.value != document.altaUpdate.emailRepetir.value){
		validado = false;
		document.getElementById('mailRepetir').className = 'obligatorio';
	}
	
	if (document.altaUpdate.nombre.value == ""){
		validado = false;
		document.getElementById('nombre').className = 'obligatorio';
	}
	if (document.altaUpdate.apellidos.value == ""){
		validado = false;
		document.getElementById('apellidos').className = 'obligatorio';
	}
	if (document.altaUpdate.cp.value == ""){
		validado = false;
		document.getElementById('cp').className = 'obligatorio';
	}
	
	if (document.altaUpdate.sexo[0].checked == false && document.altaUpdate.sexo[1].checked == false){
		validado = false;
		document.getElementById('sexo').className = 'obligatorio';
	}
	if (document.altaUpdate.movil.value == ""){
		validado = false;
		document.getElementById('movil').className = 'obligatorio';
	}
	if (document.altaUpdate.direccion.value == ""){
		validado = false;
		document.getElementById('direccion').className = 'obligatorio';
	}
	if (document.altaUpdate.poblacion.value == ""){
		validado = false;
		document.getElementById('poblacion').className = 'obligatorio';
	}
	
	if (document.altaUpdate.provincia.selectedIndex == 0){
		validado = false;
		document.getElementById('provincia').className = 'obligatorio';
	}
	
	if (document.altaUpdate.permiso[0].checked == false && document.altaUpdate.permiso[1].checked == false){
		validado = false;
		document.getElementById('permiso').className = 'obligatorio';
	}
	
	if (document.altaUpdate.moto[0].checked == false && document.altaUpdate.moto[1].checked == false) {
		validado = false;
		document.getElementById('moto').className = 'obligatorio';
	}
	
	if (document.altaUpdate.confirmacion.checked == false){
		validado = false;
		document.getElementById('confirm').className = 'obligatorio';
	}
	
	if (document.altaUpdate.moto[0].checked){
		if (document.altaUpdate.marca.selectedIndex == 0){
			validado = false;
			document.getElementById('textoMarca').className = 'obligatorio';
		}
		
		if (document.altaUpdate.modelo.selectedIndex == 0){
			validado = false;
			document.getElementById('textoModelo').className = 'obligatorio';
		}
		if (document.altaUpdate.marca.value != "Harley-Davidson" && document.altaUpdate.marca.value != "Buell" && document.altaUpdate.cilindrada.selectedIndex == 0) {
			validado = false;
			document.getElementById('textoCilindrada').className = 'obligatorio';
		}
	}
	
	if (validado) document.altaUpdate.submit();
}

function validarFormularioAmigo(){
	var validado = true;
	if (document.amigo.tuNombre.value == ""){
		validado = false;
		document.getElementById('textotunombre').className = 'obligatorio';
	}
	if (document.amigo.tuEmail.value == ""){
		validado = false;
		document.getElementById('textotucorreo').className = 'obligatorio';
	}else if (valEmail(document.amigo.tuEmail.value) == false){
		validado = false;
		document.getElementById('textotucorreo').className = 'obligatorio';
	}
	
	if (document.amigo.nombreAmigo.value == ""){
		validado = false;
		document.getElementById('textosunombre').className = 'obligatorio';
	}
	if (document.amigo.emailAmigo.value == ""){
		validado = false;
		document.getElementById('textosucorreo').className = 'obligatorio';
	}else if (valEmail(document.amigo.emailAmigo.value) == false){
		validado = false;
		document.getElementById('textosucorreo').className = 'obligatorio';
	}
	
	if (validado) document.amigo.submit();
}

function ponerCampoNormal(cual){
	document.getElementById(cual).className = 'normal'
}

function mirarValorProvincia(){
	if (document.altaUpdate.provincia.value == '') document.altaUpdate.provincia.selectedIndex = 0;
}

function cargarResultado(cual,tamany){
	var h,w;
	if (navigator.appVersion.indexOf("MSIE") != -1){
		h = document.body.clientHeight;
		w = document.body.clientWidth;
	}else{
		h = window.innerHeight;
		w = window.innerWidth;
	}

	//document.getElementById('fondoResultado').style.width = w + "px";
	document.getElementById('fondoResultado').style.height = h + "px"
	document.getElementById('fondoResultado').style.visibility = 'visible';
	
	document.getElementById(cual).style.top = h/2 - 35/2 + "px";
	document.getElementById(cual).style.left = w/2 - tamany/2 + "px";
	document.getElementById(cual).style.visibility = 'visible';
}

function cerrarResultado(){
	document.getElementById('fondoResultado').style.visibility = 'hidden';
	document.getElementById('resultadook').style.visibility = 'hidden'
	document.getElementById('resultadoRepetido').style.visibility = 'hidden';
	document.getElementById('resultadoActivada').style.visibility = 'hidden';
	document.getElementById('resultadoNoActivada').style.visibility = 'hidden';
	document.getElementById('resultadoNoExiste').style.visibility = 'hidden';
	document.getElementById('resultadoPeticionBaja').style.visibility = 'hidden';
	document.getElementById('resultadoBaja').style.visibility = 'hidden';
	document.getElementById('resultadoPeticionBaja').style.visibility = 'hidden';
	document.getElementById('resultadoAmigoExiste').style.visibility = 'hidden';
	document.getElementById('resultadoAmigoEnviado').style.visibility = 'hidden';
}

function abrirVentana(cual){
	var url = "";
	
	if (cual == "aviso") url = "aviso.php";
	if (cual == "politica") url = "politica.php";
	if (cual == "importas") url = "importas.php";
	
	window.open(url,"_blank","width=655,height=500,menubars=0,scrollbars=yes");
}

