//----------------------------------------------------- // campos do formulário de pedido de informação //----------------------------------------------------- function valida_info1(form,id) { if (id == "1") if ( CampoNulo(form.nome, "Nome", id) ) return; if (id == "1") if ( CampoNulo(form.empresa, "Empresa", id) ) return; if (id == "1") if ( CampoNulo(form.morada, "Morada", id) ) return; if (id == "1") if ( CampoNulo(form.codpostal1, "Código Postal", id) || CampoNulo(form.codpostal2, "Código Postal", id) ) return; if (id == "1") if ( CampoNulo(form.localidade, "Localidade", id) ) return; if ( !Telefone(form.telefone,id) ) return; if (id == "1") if ( CampoNulo(form.email, "E-mail", id) ) return; form.submit(); } //----------------------------------------------------- // campos do formulário de envio de questão //----------------------------------------------------- function valida_info(form,id) { if (id == "1") if ( CampoNulo(form.nome, "Nome", id) ) return; if (id == "1") if ( CampoNulo(form.empresa, "Empresa", id) ) return; if (id == "1") if ( CampoNulo(form.observacoes, "Questão", id) ) return; form.submit(); } //----------------------------------------------------- // mensagem de validação do campo nulo //----------------------------------------------------- function CampoNulo(form,campo,id){ if( (form.value=="") || (form.value==null) ) { if (id == "1") alert("O campo " + campo + " é de preenchimento obrigatório."); if (id == "2") alert("The field " + campo + " cannot be null."); form.focus(); return true; } else { return false; } } //----------------------------------------------------- // validação dos campos telefone //----------------------------------------------------- function Telefone(campo1,id){ if(eval(campo1).value==""){ if (id == "1") alert('O campo Telefone é de preenchimento obrigatório.'); return false; } return true; } //----------------------------------------------------- // valida campo numérico //----------------------------------------------------- function numero(letras){ if(isNaN(Number(letras))==true){return false;} } function numeros(campo, NCaracteres,id){ valor=new String(campo); comp=valor.length; if(comp!=NCaracteres){ if (id == "1") alert('O campo deverá ter '+NCaracteres+' caracteres.') if (id == "2") alert('Please, fill in the field '+NCaracteres+' characters.') return false; } else{ pos=new Array(comp) for(var i=0;i "9"))) return false; } return true; } function stripCharsInBag(s, bag){ var i; var returnString = ""; for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function daysInFebruary (year){ return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } function DaysArray(n) { for (var i = 1; i <= n; i++) { this[i] = 31 if (i==4 || i==6 || i==9 || i==11) {this[i] = 30} if (i==2) {this[i] = 29} } return this } function isDate(dtStr,id){ var daysInMonth = DaysArray(12) var pos1=dtStr.indexOf(dtCh) var pos2=dtStr.indexOf(dtCh,pos1+1) var strDay=dtStr.substring(0,pos1) var strMonth=dtStr.substring(pos1+1,pos2) var strYear=dtStr.substring(pos2+1) strYr=strYear if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1) if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1) for (var i = 1; i <= 3; i++) { if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1) } month=parseInt(strMonth) day=parseInt(strDay) year=parseInt(strYr) if (pos1==-1 || pos2==-1){ if (id == "1") alert("O formato da data deverá ser: dd/mm/aaaa") if (id == "2") alert("Valid date example: dd/mm/aaaa") return false } if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){ if (id == "1") alert("Insira um dia válido.") if (id == "2") alert("Insert a valid day.") return false } if (strMonth.length<1 || month<1 || month>12){ if (id == "1") alert("Insira um mês válido.") if (id == "2") alert("Insert a valid month.") return false } if (strYear.length != 4 || year==0){ if (id == "1") alert("Insira um ano válido.") if (id == "2") alert("Insert a valid year.") return false } if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){ if (id == "1") alert("Insira uma data válida.") if (id == "2") alert("Insert a valid date.") return false } return true } function ValidateForm(valor,id){ var dt=valor; if (isDate(dt,id)==false){ return false } return true }