
//String to check Email Value
function IsInd(STR,subSTR){
  var s = STR.indexOf(subSTR);
  if (s != -1) return true;	else return false;
}

//Test Fields function
function test_fields(){
	with (document.mailform){
		if (nome.value == ""){alert("Introduza o seu nome."); nome.focus(); return false}
		if (nome.value.length < 4) {alert("Nome inválido."); nome.focus(); return false}
		if (email.value == "" || !IsInd(email.value,"@") || !IsInd(email.value,".")){alert("Introduza o seu email."); return false}
		if (document.mailform.login) if (login.value.length < 4) {alert("Login inválido."); login.focus(); return false}
		if (document.mailform.passwd1) if (passwd1.value.length < 4 || passwd1.value.length < 4) {alert("As senhas devem ter mais do que 4 caracteres."); passwd1.focus(); return false}
		if (document.mailform.passwd1) if (passwd1.value.length == 0 ){alert("Por favor, escreva a senha duas vezes."); passwd1.focus(); return false}
		if (document.mailform.passwd1) if (passwd1.value != passwd2.value ){alert("A senhas não são iguais, por favor escreva novamente."); passwd1.focus(); return false}
	}
	return true
}

//Check Day
function checkday() {
   with (document.mailform.datadd){
      if (isNaN(parseInt(value,10)) || (parseInt(value,10) < 1 || parseInt(value,10) > 31 ) ) {
         alert("Valor do campo \"Dia\" invalido!");	
         value = "";
      } else
         value = parseInt(value,10);
   }
}

//Check Month
function checkmonth() {
   with (document.mailform.datamm){
      if (isNaN(parseInt(value,10)) || (parseInt(value,10) < 1 || parseInt(value,10) > 12 ) ) {
         alert("Valor do campo \"Mês\" invalido!");	
         value = "";
      } else
        value = parseInt(value,10);
   }
}

//Check Year
function checkyear() {
   with (document.mailform.dataaaaa){
      if (isNaN(parseInt(value,10)) || (parseInt(value,10) < 1900 || parseInt(value,10) > 2000 ) ) {
         alert("Valor do campo \"Ano\" invalido!");	
         value = "";
      } else
        value = parseInt(value,10);
   }
}
