﻿	var s_primero=1,tnum=/^([0-9])+$/;

	function enviar(){
		var i=document.mail.email.value;
		
		if(i!=""&&i.search("@")>-1&&i.search(".")>-1){
			var I=document.mail.email.value,l=window.open("okmail.asp?email="+I,"mail","width=300,height=300");
			fueramail();
		}
	}

	var str="";

	var laya='<span class="ii"><input class="frmd" type="text" maxlength="6" name="presupuesto" />&nbsp;&euro;</span>';
	laya = laya + '<span class="tt"></span><input type="hidden" name="total"/>';
	laya = laya + '<span class="ii"><input class="bttn" type="button" name="ok" onclick="sending()" value="Calcular" /></span>';
	
	var layb = laya.replace('presupuesto', 'cuota');

	function writetoLyr(name,message){
		if(document.layers){
			document.layers[name].document.close();
			document.layers[name].document.write('');
			document.layers[name].document.write(message);
			document.layers[name].document.close();
		}
		else{
			if(document.all){
				eval("document.all."+name+".innerHTML='"+''+"'");
				eval("document.all."+name+".innerHTML='"+message+"'");
			}
			else{
				document.getElementById(name).innerHTML=message;
			}
		}
	}

	function setMessage(){
		if(str==""){
			for(var ii=0;ii<120;ii+=10){
				str=str+"    ";
			}
			
			str=str+"UNOAUTO SOLO MIRA NUESTROS PRECIOS.... ";
		}
		else{
			str=str.substring(2,str.length);
		}
		
		window.status=str;
		JSCTimeOutID=window.setTimeout('setMessage()',100);
	}

	function models(){
		var select=document.formucoches.marcaspro;
		marcas=select.options[select.selectedIndex].value;
		document.formucoches.modelos.length=1;
		
		if(select.options[select.selectedIndex].value==0){
			document.formucoches.modelos.length=1;
		}
		else{
			document.formucoches.modelos.options[0]=new Option("------------",'0',true,true);
			eval("modelos = modelo_"+marcas+".length");
			
			for(a=0;a<modelos;++a){
				eval("texto = modelo_"+marcas+"["+a+"]");
				eval("value= modelo_"+marcas+"["+a+"]");
				document.formucoches.modelos.options[a+1]=new Option(texto,value);
			}
		}
	}

	function comprobar_datos(){
		if(document.formucoches.marcaspro.options[document.formucoches.marcaspro.selectedIndex].value==0&&document.formucoches.modelos.options[document.formucoches.modelos.selectedIndex].value==0&&document.formucoches.combustible.options[document.formucoches.combustible.selectedIndex].value==0){
			alert("Rellene al menos un campo para iniciar la busqueda")
		}
		else{
			document.formucoches.marcas.value=document.formucoches.marcaspro.value;
			document.formucoches.marcaspro.options[0]=new Option("------------",'0',true,true);
			document.formucoches.submit();
		}
	}

	function abrir_ventana(I){
		var i=window.open(I,"ventana","width=450, height=600, scrollbars=yes");
	}

	function desplenuevo(){
		document.getElementById("nuevos").style.visibility="visible";
		document.getElementById("usados").style.visibility="hidden";
		document.dinero.desple[0].checked=true;
		document.dinero.desple[1].checked=false;
	}

	function despleviejo(){
		document.getElementById("nuevos").style.visibility='hidden';
		document.getElementById("usados").style.visibility='visible';
	}

	function presupuesto(){
		pelas=document.dinero.presupuesto.value;
		
		if(pelas==0){
			alert("no puede poner presupuesto 0");
			return false;
		}
		document.dinero.preciodebajo.value=(pelas/100)*95;
		document.dinero.precioarriba.value=(pelas/100)*105;
		document.dinero.submit();
	}

	function sending(){
		var total;
		
		if(document.mensual.presupuesto=="[object HTMLInputElement]"){
			total=document.mensual.presupuesto.value;
			
			if(total==0||!tnum.test(document.mensual.presupuesto.value)){
				alert("Valor incorrecto en el campo 'Presupuesto total'");
				return false;
			}
		}
		else{
	
			if(document.mensual.cuota.value==''||!tnum.test(document.mensual.cuota.value)){
				alert("Valor incorrecto en el campo 'Cuota'");
				return false;
			}
			
			total=document.mensual.cuota.value;
			total=total/0.014358;
			total=Math.round(total);
			
			document.mensual.total.value=total;
		}
		
		document.mensual.preciodebajo.value=(total/100)*95;
		document.mensual.precioarriba.value=(total/100)*105;
		document.mensual.submit();
	}
	
	function validarNum(e){
		// 8      = retroceso
		// 9	  = tab (-)
		// 47-58  = números (1234567890)
		
		tecla=(document.all) ? e.keyCode : e.which;
	
		if (tecla = 0) {
			tecla = e.which;
		}

		if ((tecla!=8) && (tecla!=9)){
			if ((tecla>47) && (tecla<58)){
				return true;
			}
			else{
				return false;
			}
		}
		else{
			return true;	
		}
	}
	
	function validarForm(theForm){
		var tletraonumero       = /^([a-z]|\d|[.\-_@])+$/;
		var tmail               = /^.+\@.+\..+$/;
		var tnum 				= /^[6-9]+([0-9]{8})+$/;
		var cpost 				= /^([0-9]{5})+$/;
		var a					= 0;
		
		//E-mail
		if (theForm.mail !== undefined){
			if (theForm.mail.value=="") {
				alert("E-mail es obligatorio");
				theForm.mail.focus();
				return (false); 
			}
			
			if (!tletraonumero.test(theForm.mail.value)) {
				alert("E-mail no puede contener carácteres especiales");
				theForm.mail.focus();
				return (false);
			}
			
			if (!tmail.test(theForm.mail.value)) {
				alert("E-mail incorrecto.\n Formato: [usuario]@[servidor].[dominio]");
				theForm.mail.focus();
				return (false); 
			}
		}
		
		//Nombre
		if (theForm.nombre !== undefined) {
			if (theForm.nombre.value.length < 3) {
				  alert('Nombre incorrecto');
				  theForm.nombre.focus();
				  return (false);
			}
		}
		
		//Teléfono
		if (theForm.telefono !== undefined) {
			if (!tnum.test(theForm.telefono.value)) {
				  alert('Teléfono incorrecto');
				  theForm.telefono.focus();
				  return (false);
			}
		}
		
		//Código postal
		if (theForm.provincia !== undefined) {
			if (theForm.provincia.value.length < 3) {
				  alert('La provincia es obligatoria');
				  theForm.provincia.focus();
				  return (false);
			}
		}
		
		//Aviso legal
		if (theForm.okis !== undefined){
 			if (theForm.okis.checked != true){ 
				alert("Es necesario leer y aceptar el aviso legal");
    			theForm.okis.focus();
    			return (false);
			}
		}

  		return (true);
	}