
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
    
      if (test.indexOf('isEmail')!=-1) { 
        p=val.indexOf('@');
        if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(val)))         
            errors+='- '+args[i+1]+' deve conter um email valido.\n';
            
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+args[i+1]+' deve ser um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+args[i+1]+' deve conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+args[i+1]+' é obrigatório.\n'; }
  }
  if (document.forms[0].elements['email'].value != document.forms[0].elements['email-conf'].value){
	  errors += '- Designação diferente no campo da E-mail\n';
  }
  if (document.forms[0].elements['contrasena'].value != document.forms[0].elements['contrasena-conf'].value){
	  errors += '- Designação diferente no campo da contra-senha\n';
  }
  /*if (document.forms[0].elements['sexo'] && (!document.forms[0].elements['sexo'].selectedIndex != "")) {
      errors += '- Sexo é obrigatório\n';
  }
  if (document.forms[0].elements['abonado'] && (!document.forms[0].elements['abonado'].selectedIndex != "")) {
      errors += '- Seleciona o canal do qual voce é assinante\n';
  }
  if (document.forms[0].elements['provincia'] && (!document.forms[0].elements['provincia'].selectedIndex != "")) {
      errors += '- Seleciona um distrito\n';
  }
  if (document.forms[0].elements['telefono'] && (document.forms[0].elements['telefono'].value.length < 9)) {
      errors += '- O telefone deve conter almenos 9 numeros\n';
  }
  if (document.forms[0].elements['dia'] && (!document.forms[0].elements['dia'].selectedIndex != "")) {
      errors += '- O dia de nascimento é obrigatorio\n';
  }
  if (document.forms[0].elements['mes'] && (!document.forms[0].elements['mes'].selectedIndex != "")) {
      errors += '- O mes de nascimento é obrigatorio\n';
  }
  if (document.forms[0].elements['ano'] && (!document.forms[0].elements['ano'].selectedIndex != "")) {
      errors += '- O ano de nascimento é obrigatorio\n';
  }  */
  if (document.forms[0].elements['aviso'] && !document.forms[0].elements['aviso'].checked) {
      errors += '- Voce deve aceitar o Aviso Legal\n';
  }  
  if (errors) alert('Atençao por favor:\n\n'+errors);
  document.MM_returnValue = (errors == '');
} 

function confirmaBaja () {
if (confirm('Atençao por favor:\n\nConfirma que vôce nao quer mais ser usuario, essa açao nao pode ser refeita')){ return true; } else { return false; }
}
function confirmaBajaN () {
if (confirm('Atençao por favor:\n\nConfirma que vôce nao quer mais Newsletter')){ document.form.newsletter.submit(); } else { return false; }
}
