﻿/*FUNCIONS GLOBALS*/


function alerta_ct (str)
{
	alert("Revisa el camp " + str + " ...");
}


function alerta_en (str)
{
	alert("Check the field " + str + " ...");
}

function alerta_es (str)
{
	alert("Revisa el campo " + str + " ...");
}


function esta_ple(d1)
{
	if (d1.value=='')
		return 0;
	else
		return 1;
}

function mira_email(email) {
/* Torna
        0: no hi ha res
        1: si es correcte
        9: email incorrecte
*/

if(email.value!="")
   {
   if (/^[A-Za-z0-9\.+_-]+@[A-Za-z0-9\.-]+\.[A-Za-z]{2,6}$/.test(email.value))
  	{
	return 1;
	}
	else
	{
	return 9;
	}
   }
else
   {
	return 0;
   }
}

/* COMPROVAR FORMULARIS */


function valida_contactar_es()
{
        with (document.contacta)
               {
               	result1 = esta_ple(nombre);
				result2 = esta_ple(empresa);
                result3 = mira_email(email);
               	result4 = esta_ple(comentarios);
		
               if (result1 == 0)
               {
				alerta_es('Nombre');
				nombre.focus();
				return false;
				}
				
               if (result2 == 0)
               {
				alerta_es('Empresa');
				empresa.focus();
				return false;
				}
				
               else if (result3 != 1)
               {
               	alert('Debe introducir una dirección de correo electrónico válida');
				email.focus();
				return false;
               }

				else if (result4 == 0)
				{
				alerta_es('Comentarios');
				comentarios.focus();
				return false;
				}	

	       else submit();
       }
}





