// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function obrirFoto(titol,foto,alcada,amplada,esquerra,superior) { 
  myWin= open("", "", "width="+amplada+",height="+alcada+",left="+esquerra+",top="+superior);

  // open document for further output
  myWin.document.open();
  
  // create document
  myWin.document.write("<html><head><title>" + titol + "</title>");
  myWin.document.write("<style type='text/css'><!-- .fondogaleria { background-image: url(" + foto + ");	background-repeat: no-repeat;}</style>");
  myWin.document.write("<style type='text/css'><!-- a:link, a:visited, a:hover { color: #000000; text-decoration: none; font-weight: bold;} </style>");
  myWin.document.write("<style type='text/css'><!-- a:hover { text-decoration: underline;} </style>");
  myWin.document.write("</head>");
  myWin.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'> ");
  myWin.document.write("<table width=" + amplada + " height=" + alcada + " border='0' align='center' class='fondogaleria'>");
  myWin.document.write("<tr> <td height=" + (alcada - 37) + ">&nbsp;</td>");
  myWin.document.write("</tr><tr><td align='left'></td></tr>");
  myWin.document.write("</table>");
  myWin.document.write("</body></html>");

  // close the document - (not the window!)
  myWin.document.close();  
}
   function verificarForm(form, url) 
   {
	   valor = form.remitente.value;
       correo = "valor.lastIndexOf('@')!=valor.indexOf('@') || valor.indexOf('@')<2 || valor.lastIndexOf('.')<valor.length-4 || valor.lastIndexOf('.')>valor.length-3";

	   if (form.assumpte.value == "")
	   {
		  alert("Siusplau introdueix el tipus de tràmit.");
		  form.assumpte.focus();
		  return false;
	   }      
	   else if (form.nombre.value == "" || form.nombre.value.length<3 )
	   {
		  alert("Siusplau, introdueix el teu nom.");
		  form.nombre.focus();
		  return false;
	   }      
	   else if (form.apellido1.value == "" || form.apellido1.value.length<3 )
	   {
		  alert("Siusplau, introdueix el teu primer cognom.");
		  form.apellido1.focus();
		  return false;
	   }      
	   else if (form.apellido2.value == "" || form.apellido2.value.length<3 )
	   {
		  alert("Siusplau, introdueix el teu segon cognom.");
		  form.apellido2.focus();
		  return false;
	   }      
	   else if (form.dni.value == "")
	   {
			alert("Per favor, introdueix un DNI vàlid.");
			form.dni.focus();
			return false;
	   }       
	   else if (form.adreca.value == "" || form.adreca.value.length<3 )
	   {
		  alert("Siusplau, introdueix la teva adreça.");
		  form.adreca.focus();
		  return false;
	   }      
	   else if (form.telF2.value != "" && (form.telF1.value == "" || form.telF3.value == "" || form.telF4.value == "" || form.telF1.value.length < 2 || form.telF2.value.length < 3 || form.telF3.value.length < 3 || form.telF4.value.length < 3 || !Number(form.telF1.value) || !Number(form.telF2.value) || !Number(form.telF3.value) || !Number(form.telF4.value)))
	   {
			alert("Per favor, introdueix un telèfon fixe vàlid.");
			form.telF1.focus();
			return false;
	   }       
	   else if (form.telM1.value == "" || form.telM2.value == "" || form.telM3.value == "" || form.telM1.value.length < 3 || form.telM2.value.length < 3 || form.telM3.value.length < 3 || !Number(form.telM1.value) || !Number(form.telM2.value) || !Number(form.telM3.value))
	   {
		  alert("Per favor, introdueix un telèfon mòvil válid.");
		  form.telM1.focus();
		  return false;
	   }       
	   else if (form.entitat.value == "" || !Number(form.entitat.value))
	   {
		  alert("Per favor, introdueix un número d'entitat correcte.");
		  form.entitat.focus();
		  return false;
	   }       
	   else if (form.oficina.value == "" || !Number(form.oficina.value))
	   {
		  alert("Per favor, introdueix la oficina.");
		  form.oficina.focus();
		  return false;
	   }       
	   else if (form.dc.value == "" || !Number(form.dc.value))
	   {
		  alert("Per favor, introdueix els dígits de control.");
		  form.dc.focus();
		  return false;
	   }
	   else if (form.numcompte.value == "" || !Number(form.numcompte.value))
	   {
		  alert("Per favor, introdueix el número de compte.");
		  form.numcompte.focus();
		  return false;
	   }
	   else if (eval(correo))
	   {
		  alert("Siusplau, introdueix un correu electrònic vàlid.");
		  form.remitente.focus();
		  return false;
	   }      
       else
	   {
	   	  go(form, url);
	   }      
   }

   function verificarForm2(form, url) 
   {
	   valor = form.email.value;
       correo = "valor.lastIndexOf('@')!=valor.indexOf('@') || valor.indexOf('@')<2 || valor.lastIndexOf('.')<valor.length-4 || valor.lastIndexOf('.')>valor.length-3";

	   if (form.nom.value == "" || form.nom.value.length < 9 )
	   {
		  alert("Siusplau, introdueix el teu nom i els dos cognoms.");
		  form.nom.focus();
		  return false;
	   }      
	   else if (form.llicencia.value == "")
	   {
		  alert("Siusplau introdueix el número de llicència.");
		  form.llicencia.focus();
		  return false;
	   }      
	   else if (form.dni.value == "")
	   {
			alert("Per favor, introdueix un DNI o NIF vàlid.");
			form.dni.focus();
			return false;
	   }       
	   else if (form.direccio1.value == "" || form.direccio1.value.length<3 )
	   {
		  alert("Siusplau, introdueix la teva adreça.");
		  form.direccio1.focus();
		  return false;
	   }      
	   else if (form.cp.value == "" || form.cp.value.length<5 || !Number(form.cp.value))
	   {
		  alert("Siusplau, introdueix el teu codi postal.");
		  form.cp.focus();
		  return false;
	   }      
	   else if (form.poblacio.value == "" || form.poblacio.value.length<3 )
	   {
		  alert("Siusplau, introdueix la teva població.");
		  form.poblacio.focus();
		  return false;
	   }      
	   else if (form.provincia.value == "" || form.provincia.value.length<3 )
	   {
		  alert("Siusplau, introdueix la teva província.");
		  form.provincia.focus();
		  return false;
	   }      
	   else if (form.telF2.value != "" && (form.telF1.value == "" || form.telF3.value == "" || form.telF4.value == "" || form.telF1.value.length < 2 || form.telF2.value.length < 3 || form.telF3.value.length < 3 || form.telF4.value.length < 3 || !Number(form.telF1.value) || !Number(form.telF2.value) || !Number(form.telF3.value) || !Number(form.telF4.value)))
	   {
			alert("Per favor, introdueix un número de telèfon fixe vàlid.");
			form.telF1.focus();
			return false;
	   }       
	   else if (form.telM1.value == "" || form.telM2.value == "" || form.telM3.value == "" || form.telM1.value.length < 3 || form.telM2.value.length < 3 || form.telM3.value.length < 3 || !Number(form.telM1.value) || !Number(form.telM2.value) || !Number(form.telM3.value))
	   {
		  alert("Per favor, introdueix un número de mòbil vàlid.");
		  form.telM1.focus();
		  return false;
	   }       
	   else if (eval(correo))
	   {
		  alert("Siusplau, introdueix un correu electrònic vàlid.");
		  form.email.focus();
		  return false;
	   }      
	   else if (form.escuderia.value == "" || form.escuderia.value.length<3 )
	   {
		  alert("Siusplau, introdueix la teva escuderia.");
		  form.escuderia.focus();
		  return false;
	   }      
	   else if (form.classe.options[form.classe.selectedIndex].value == "Selecciona una opció")
	   {
		  alert("Siusplau, selecciona la classe.");
		  form.classe.focus();
		  return false;
	   }      
	   else if (form.numvehicle.value == "" || form.numvehicle.value.length<3 )
	   {
		  alert("Siusplau, introdueix el número del teu vehicle.");
		  form.numvehicle.focus();
		  return false;
	   }      
	   else if (form.marca.value == "" || form.marca.value.length<3 )
	   {
		  alert("Siusplau, introdueix la teva marca.");
		  form.marca.focus();
		  return false;
	   }      
	   else if (form.model.value == "" || form.model.value.length<3 )
	   {
		  alert("Siusplau, introdueix el teu model.");
		  form.model.focus();
		  return false;
	   }      
	   else if (form.cilindrada.value == "" || form.cilindrada.value.length<3 )
	   {
		  alert("Siusplau, introdueix la cilindrada.");
		  form.cilindrada.focus();
		  return false;
	   }      
	   else if (form.condicions[1].checked)
	   {
		  alert("Si no acceptes les condicions no et pots inscriure.");
		  form.condicions[0].focus();
		  return false;
	   }      
       else
	   {
	   	  go(form, url);
	   }      
   }

   function verificarFormRalli(form, url) 
   {
	   if (form.nom_p.value == "" || form.nom_p.value.length < 9 )
	   {
		  alert("Siusplau, introdueix el nom i els dos cognoms del pilot.");
		  form.nom.focus();
		  return false;
	   }      
	   else if (form.dni_p.value == "")
	   {
			alert("Per favor, introdueix DNI o NIF vàlid del pilot.");
			form.dni.focus();
			return false;
	   }       
	   else if (form.nom_co.value == "" || form.nom_co.value.length < 9 )
	   {
		  alert("Siusplau, introdueix el nom i els dos cognoms del copilot.");
		  form.nom_co.focus();
		  return false;
	   }      
	   else if (form.dni_co.value == "")
	   {
			alert("Per favor, introdueix DNI o NIF vàlid del copilot.");
			form.dni_co.focus();
			return false;
	   }       
	   else if (form.nom_c.value == "" || form.nom_c.value.length < 9 )
	   {
		  alert("Siusplau, introdueix el nom i els dos cognoms del concursant.");
		  form.nom_cur.focus();
		  return false;
	   }    
	   else if (form.marca.value == "" || form.marca.value.length<3 )
	   {
		  alert("Siusplau, introdueix la marca del vehicle.");
		  form.marca.focus();
		  return false;
	   }      
	   else if (form.model.value == "" || form.model.value.length<3 )
	   {
		  alert("Siusplau, introdueix el model del vehicle.");
		  form.model.focus();
		  return false;
	   }
	   else if (form.condicions[1].checked)
	   {
		  alert("Si no acceptes les condicions no et pots inscriure.");
		  form.condicions[0].focus();
		  return false;
	   }      
       else
	   {

	   	  go(form, url);
	   }      
   }

   function verificarFormAutocross(form, url) 
   {
	   if (form.nom.value == "" || form.nom.value.length < 9 )
	   {
		  alert("Siusplau, introdueix el nom i els dos cognoms/Por favor introduce nombre y apellidos.");
		  form.nom.focus();
		  return false;
	   }      
	   else if (form.dni.value == "")
	   {
			alert("Per favor, introdueix DNI o NIF vàlid del pilot/Por favor introduzca DNI válido.");
			form.dni.focus();
			return false;
	   }       
	   else if (form.marca.value == "")
	   {
		  alert("Siusplau, introdueix la marca del vehicle/Por favor introduzca la marca del vehículo.");
		  form.marca.focus();
		  return false;
	   }      
	   else if (form.model.value == "")
	   {
		  alert("Siusplau, introdueix el model del vehicle/Por favor introduzca el modelo del vehículo.");
		  form.model.focus();
		  return false;
	   }      
	   else if (form.condicions[1].checked)
	   {
		  alert("Si no acceptes les condicions no et pots inscriure/Si no acepta las condiciones no se puede inscribir.");
		  form.condicions[0].focus();
		  return false;
	   }      
       else
	   {
	   	  go(form, url);
	   }      
   }

function go(form,url) 
{
	form.action = url;
	form.submit();
}

