window.onload = function funcoes(){ var resolucao = screen.width; if(resolucao=="1024"){ var corpo = document.getElementsByTagName("body"); corpo[0].className = "menor"; } /*if(document.getElementById('fechar')){ document.getElementById('fechar').onclick = function(){ document.getElementById('noticias').style.display="none"; } }*/ if(document.getElementById('caminho')){ document.getElementById('arquivo').onchange = function(){ document.getElementById('caminho').innerHTML = document.getElementById('arquivo').value.substring(0, 32); } } } var objFrm; /* function objMsg (fieldName, validation, msgBR, msgUS, msgES) { this.fieldName = fieldName; this.validation = validation; this.msgBR = msgBR; this.msgUS = msgUS; this.msgES = msgES; } */ function objMsg (fieldName, validation, errorCod) { this.fieldName = fieldName; this.validation = validation; this.errorCod = errorCod; } // Validação de Formularios (nome do formulario, action) function checkForm(frm,strAction) { clearform(frm); objFrm = frm; checkFormJs(frm); if(!returnErrors()) { // se nao houver erros no JS, verifica no RPC checkFormRpc(frm,strAction+'.php'); } return false; } function returnErrors () { for (i = 0; i < errorField.length; i++){ field = errorField[i]; if(field.length>1){ if(field.type!="select-one"){ field.style.borderColor='red'; field.style.borderStyle='solid'; for (a = 0; a < field.length; a++){ field[a].style.borderColor='red'; field[a].style.borderStyle='solid'; } }else{ field.style.borderColor='red'; field.style.borderStyle='solid'; } }else{ if(field.type!="select-one"){ field.style.borderColor='red'; field.style.borderStyle='solid'; }else{ field.style.backgroundColor='red'; } if(errorField.length>0) { if(errorField[0].type!="hidden"){ //errorField[0].focus(); // seta o focus no primeiro campo com erro } } } } if(errorMsg.length>0) { /*objMsg = document.getElementById("msg"); objMsg.bgColor = 'red'; objMsg.style.color = '#ffffff'; objMsg.style.fontWeight = 'Bolder'; objMsg.innerHTML = errorMsg[0];*/ //alert(errorMsg[0]); //parent.alerta('sadasd'); //alert(errorField); if(errorMsg[titulo]==undefined){ titulo=ObjTradutor['TRA_atencao']; }else{ titulo=errorMsg[titulo]; } if( typeof alerta == 'function' ) { alerta(titulo,"300px",errorMsg[0],"","fechar"); } else { parent.alerta(titulo,"300px",errorMsg[0],"","fechar"); } return true; } else { return false; } } /* Adiciona novo erro ao vetor de mensagens */ function addError(message,field,titulo) { //field.style.borderColor='red'; //field.style.borderStyle='solid'; errorMsg[titulo]= titulo; if(field) { errorField[errorField.length] = field; // incrementa array de campos com erros } errorMsg[errorMsg.length] = message; // incrementa array de erros } function titulo(message) { errorMsg[titulo]= message; } function getErrorMsg(errorCod) { errorMessages = new Array(); errorMessages[1] = new Array(); errorMessages[1]['BR'] = 'Preencha o Nome da campanha'; errorMessages[2] = new Array(); errorMessages[2]['BR'] = 'Preencha o Assunto'; errorMessages[3] = new Array(); errorMessages[3]['BR'] = 'Preencha o Remetente'; errorMessages[4] = new Array(); errorMessages[4]['BR'] = 'Preencha o dia inícial'; errorMessages[5] = new Array(); errorMessages[5]['BR'] = 'Preencha o mes inícial'; errorMessages[6] = new Array(); errorMessages[6]['BR'] = 'Preencha o ano inícial'; errorMessages[7] = new Array(); errorMessages[7]['BR'] = 'Preencha a hora inícial'; errorMessages[8] = new Array(); errorMessages[8]['BR'] = 'Preencha o minuto inícial'; errorMessages[9] = new Array(); errorMessages[9]['BR'] = 'Preencha o dia limite'; errorMessages[10] = new Array(); errorMessages[10]['BR'] = 'Preencha o mes limite'; errorMessages[11] = new Array(); errorMessages[11]['BR'] = 'Preencha o ano limite'; errorMessages[12] = new Array(); errorMessages[12]['BR'] = 'Preencha a hora limite'; errorMessages[13] = new Array(); errorMessages[13]['BR'] = 'Preencha o minuto limite'; errorMessages[14] = new Array(); errorMessages[14]['BR'] = 'Preencha ao menos um formato'; return errorMessages[errorCod]['BR']; } /* Validação Padrão de Formularios em Php (Rpc) */ function checkFormRpc(frm,strAction) { f = iframe_rpc.document; f.open(); f.write(""); f.write(""); f.write(""); f.write(""); f.write("
"); if (frm != null){ if (frm.length != null){ for (i = 0; i < frm.length; i++){ field = frm.elements[i]; switch (field.type){ case "checkbox": case "radio": if (field.checked) f.write(""); break; case "select-multiple": for (var j=0; j < field.options.length; j++) { if (field.options[j].selected) f.write(""); } break; case "textarea": if(field.value!=""){ field.value = field.value.split('').join(''); } f.write(""); break; default: f.write(""); } field.disabled = true; } } } f.write("
"); f.write(""); f.write(""); f.close(); f.forms[0].submit(); } function enableFields() { for (i = 0; i < objFrm.length; i++){ field = objFrm.elements[i]; field.disabled = false; if( field.className != undefined ){ if( field.className.split("_")[0] == "disabled" ) field.disabled = true; } } } /* Validação Padrão de Formularios em Javascript */ function checkFormJs(frm) { // lê o array de mensagens errorField = new Array(); errorMsg = new Array(); for (var i in fields[frm.name]) { objVal = fields[frm.name][i]; fieldName = eval("frm.elements['"+objVal.fieldName+"']"); // Removendo saltos de linha para explorer var re = new RegExp ("\r\n", 'gi') ; var str = fieldName.value.replace(re,"") ; // Removendo saltos de linha para firefox e outros browsers sinistros var re = new RegExp ("\n", 'gi') ; var str = str.replace(re,"") ; // Convertendo expressao de validacao var re = new RegExp ('objField', 'gi') ; var newStrValue = objVal.validation.replace(re,"\""+str+"\"") ; re = /\\/gi; newStrValue = newStrValue.replace(re, "\\\\"); strFunction = eval(newStrValue); fieldName.style.borderColor=''; fieldName.style.borderStyle=''; fieldName.style.backgroundColor=''; } } function clearform(frm){ for (i = 0; i < frm.length; i++){ field = frm.elements[i]; switch (field.type){ case "text": case "select-one": case "textarea": case "radio": field.style.borderColor=''; field.style.borderStyle=''; field.style.backgroundColor='#ffffff'; break; } } } function buildError() { if (parseInt(objVal.errorCod)){ msgError = getErrorMsg(objVal.errorCod); }else{ msgError = objVal.errorCod; } addError(msgError,objFrm[objVal.fieldName]); } //****************** validacao *******// function isInt(fieldValue) { reInt = /^\d*$/; if (reInt.test(fieldValue)){ return false; } else { buildError(); return true; } } function limparstring(s) { while (s.search(" ")!=-1){ s=s.replace(" ",""); } return(s); } function isNull(fieldValue) { fieldValue = limparstring(fieldValue); if ( fieldValue.length == 0) { buildError(); return true; } else { return false; } } //verifica a data function isDate(fieldValue){ reData = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/(19|20)\d{2}$/; data = fieldValue.split("/"); if (reData.test(fieldValue)){//verifica ano bissexto if (!((data[1]==2) && (data[0]==29) && (data[2] % 4 != 0))) return true; } buildError(); return false; } function isIP(fieldValue){ reIP = /^[01]?\d?\d|2[0-4]\d|25[0-5]\.[01]?\d?\d|2[0-4]\d|25[0-5]\.[01]?\d?\d|2[0-4]\d|25[0-5]\.[01]?\d?\d|2[0-4]\d|25[0-5]$/; if (reIP.test(fieldValue)){ fieldValue = limparstring(fieldValue); IP = fieldValue.split("."); if (IP.length == 4) { if (((IP[0]>=0) && (IP[0]<=255)) && ((IP[1]>=0) && (IP[1]<=255)) && ((IP[2]>=0) && (IP[2]<=255)) && ((IP[3]!="") && (IP[3]>=0) && (IP[3]<=255))) return true; } } buildError(); return false; } // Realiza comparacao com o operador indicado // Retorna erro quando a comparacao resultar false // ATENCAO: Valores nulos serão convertidos para 0 function compareInt(fieldValue,compValue,operator) { if (!fieldValue) fieldValue = 0; fieldValue = parseInt(fieldValue); compValue = parseInt(compValue); if(eval(fieldValue+operator+compValue)) { return true; } else { buildError(); return false; } } function maxSize(fieldValue,len) { if(fieldValue.length > len) { buildError(); return true; } else { return false; } } function minSize(fieldValue,len) { if(fieldValue.length < len) { buildError(); return true; } else { return false; } } function compareString(fieldValue,compValue,operator) { if(eval("\""+fieldValue+"\""+operator+"\""+compValue+"\"")){ return true; } else { buildError(); return false; } } function validaHora(OBJ,separador) { if(OBJ.length == 4) OBJ = '0' + OBJ; hora=OBJ.substring(0,2); separador_teste=OBJ.substring(2,3); minuto=OBJ.substring(3,5); if((isNaN(hora) || hora < 0 || hora > 23) || (separador_teste != separador) || (isNaN(minuto) || minuto < 0 || minuto > 59)) { buildError(); return true; } else return false; } function validaData(OBJ) { dia = OBJ.substring(0,2); separador1 = OBJ.substring(2,3); mes = OBJ.substring(3,5); separador2 = OBJ.substring(5,6); ano = OBJ.substring(6,10); if(ano % 4) fev = 28; else fev = 29; DiaMes = Array(31,fev,31,30,31,30,31,31,30,31,30,31); mesd = Math.round(mes)-1; if((dia >= 1 && dia <= DiaMes[mesd]) && (mes >= 1 && mes <= 12) && (ano >= 1910 && ano <= 2100) && (separador1 == '/' && separador2 == '/')) { return false; } else buildError(); return true; } function ValidaEmail(FormField){ var x = FormField.value; var filter = /^[a-z0-9][\w\.-]*[a-z0-9]@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z0-9][a-z\.]*[a-z]$/; if (filter.test(x) == false) { alerta('Alerta','400px','O e-mail digitado não é válido.','','fechar'); //FormField.focus() return false; } return true; } function Trim(Texto){ var iPosIni, iPosFim; iPosIni = 0; while ((Texto.substr(iPosIni,1) == ' ')) { iPosIni++; } Texto = Texto.substr(iPosIni,Texto.length); iPosFim = Texto.length - 1; while ((Texto.substr(iPosFim,1) == ' ')){ iPosFim--; } iPosFim++; stam = Texto.length - iPosFim; ntam = Texto.length - Texto.substr(iPosFim,stam).length; return Texto.substr(0, ntam); } function confMobile_validaForm(){ var android = false; var apple = false; $("#div_android input").each(function(i,e){ if(this.value != "")android = true; }) $("#div_apple input").each(function(i,e){ if(this.value != "")apple = true; }); if ( $( "input[name='dados[certificate]']").val() == "1" ){ apple = true; } if ( ( android == false ) && ( apple == false ) ){ alerta('Atenção','300px','  Por favor, preencha os dados.','','fechar'); return false; } if ( android == true ){ if ( ( $("input[name='dados[gcm_api_key]']").val() == "") ){ alerta('Atenção','400px','  Por favor, preencha todas configurações do Android.','','fechar'); return false; } } if ( apple == true ){ if ( ( $("input[name='dados[apple_password]']").val() == "") ){ alerta('Atenção','400px','  Por favor, preencha o campo apple password.','','fechar'); return false; } if( ( $( "input[name='dados[certificate]']").val() == "0" ) && ( $("input[name='arquivo']").val() == "" ) ){ alerta('Atenção','400px','  Por favor, informe o apple certificate.','','fechar'); return false; } } return true; }