
/******************************************************************************
******************************************************************************/
function validatePrompt(Ctrl,PromptStr)
{
  alert(PromptStr);
  Ctrl.focus();
  return;
}
function fieldIsNumber(camp)
{
 var i;
 for(i=0;i<camp.value.length;i++)
 {
   if ((camp.value.charAt(i)<"0") || (camp.value.charAt(i)>"9"))
   {
   return false;	    
	}
 }
 return true;
}


/****************************************************************************
*****************************************************************************
*****************************************************************************
******************************************************************************/
function nom (camp)
{
    if (camp.value=="")
    {
      validatePrompt(camp,"Es obligatorio introducir el nombre de la Persona de Contacto");
      return(false);
    }
	return (true);
}

/******************************************************************************
******************************************************************************/
function localitat (camp)
{
    if (camp.value=="")
    {
      validatePrompt(camp,"Es obligatorio introducir la Localidad");
      return(false);
    }
	return (true);
}

/******************************************************************************
******************************************************************************/
function email(camp)
{
    if (camp.value=="")
    {
      validatePrompt(camp,"Es obligatorio introducir un E-mail.");
      return(false);
    }
	else
	{
		 var i,sw=0;
		 for(i=0;i<camp.value.length;i++)
		 {
		   if (camp.value.charAt(i)=="@")
		   {
			sw=1;
		   }
		 }
		 if (sw==0) 
		 {
	        validatePrompt(camp,"Repasa el e-mail, te falta una @");
	        return(false);
	 	 }
	}
    return (true);
}

/******************************************************************************
******************************************************************************/
function telefon(camp)
{
	if (camp.value=="")
	{
    	validatePrompt(camp,"Es obligatorio introducir el Teléfono");
    	return false;
	}
	else
	{
	   if (fieldIsNumber(camp))
	   {	
 	 	 return(true);
   	   }
	   else
	   {
    	validatePrompt(camp,"Debes introducir números en el campo Teléfono.");
    	return false;
	   }
	}
}


/******************************************************************************
******************************************************************************/
/******************************************************************************
******************************************************************************/
/******************************************************************************
******************************************************************************/
function validar(form)
{

	if (!(nom(form.PersonaContacte))) return false;
	if (document.getElementById("Entitat").value == 0)	{
		alert("Debe seleccionar una Organización");
		return false;
	}
	else {
		if (!(document.getElementById("Entitat").value == "Particular"))
		{
			if (form.nomEntitat.value == "")
			{
				validatePrompt(document.getElementById("nomEntitat"),"Debes introducir el nombre de la " + document.getElementById("Entitat").value);
				return false;
			}

		}
	}
		
	if (!(localitat(form.Localitat))) return false;
	if (!(telefon(form.Telefon))) return false;
	if (!(email(form.email))) return false;
{
	if (document.getElementById("Com ens ha conegut?").value == 0)	{
		alert("Debe marcar cómo nos ha conocido.");
		return false;
	}
	else {
		if (!(document.getElementById("Com ens ha conegut?").value == "Google"))
		if (!(document.getElementById("Com ens ha conegut?").value == "Yahoo"))
		if (!(document.getElementById("Com ens ha conegut?").value == "Bing-MSN"))
		if (!(document.getElementById("Com ens ha conegut?").value == "PaginasAmarillas"))
		if (!(document.getElementById("Com ens ha conegut?").value == "OtroBuscador"))
		if (!(document.getElementById("Com ens ha conegut?").value == "Referencias"))
		if (!(document.getElementById("Com ens ha conegut?").value == "Revistas"))
		if (!(document.getElementById("Com ens ha conegut?").value == "Obra"))
		
		if (form.Quina.value == "")
			{
		validatePrompt(document.getElementById("Quina"),"Debes rellenar el campo " + document.getElementById("Com ens ha conegut?").value);
				return false;
			}

		}
	}


	form.submit();
//	alert("ok");
}
