function DinamizeValidateForm(form){
DinamizeLimpaAvisos(); var enviar = true; var elem = form.elements; var dateElements = new Array(); var floatElements = new Array();
for(var i = 0; i < elem.length; i++){ if( elem[i].type != "hidden" ){ var classList = elem[i].className.split(" "); removeClass("field-error", elem[i]); elem[i].value = elem[i].value.trim(); if(classList.indexOf("type_EMAIL") != -1){ if(!validateEmail(elem[i].value) ){ addClass("field-error", elem[i]); enviar = false; } } if( classList.indexOf("field-required") != -1 ){ if(classList.indexOf("type_LVM") != -1){ var nameChks = elem[i].getAttribute("id"); var ok = false; var checkboxes = document.getElementsByClassName("chk_"+nameChks); removeClass("field-error", document.getElementById("containerMultiple_"+nameChks) ); if (checkboxes.length != 0){ for(var j=0; j < checkboxes.length; j++){ if(checkboxes[j].checked == true){ ok = true; break; } } } if(!ok){ addClass("field-error", document.getElementById("containerMultiple_"+nameChks) ); enviar = false; } }else{ if( elem[i].value.trim() == "" ){ addClass("field-error", elem[i]); enviar = false; } } } } } var isMsg = document.getElementById("isMsg").value; if(enviar && isMsg == "true"){ DinamizeLoadingForm(form); enviar = false; } return enviar; } function DinamizeLoadingForm(form) { var ifrm = document.createElement("iframe"); ifrm.setAttribute("id", "iframeFormIntegration"); ifrm.setAttribute("name", "iframeFormIntegration"); ifrm.style.display = "none"; document.body.appendChild(ifrm); var imgReq = document.createElement("img"); imgReq.setAttribute("id", "DinamizeImgResponse"); imgReq.src = "https://receiver.emkt.dinamize.com/in/313198/4/31cf/?" + serialize(form) + "&a=" + Math.floor((Math.random()*99999)+1); imgReq.style.display = "none"; document.body.appendChild(imgReq); imgReq.onload = function () { DinamizePostSuccess() } imgReq.onerror = function () { document.getElementById("DinamizeDivMessageAlert").style.display = "block"; } } function DinamizePostSuccess() { document.getElementById("DinamizeDivMessageSuccess").style.display = "block"; document.getElementById("formIntegration").reset(); } function DinamizeLimpaAvisos() { var msgAlert = document.getElementById("DinamizeDivMessageSuccess"); if(msgAlert) { msgAlert.style.display = "none"; } var msgAlert = document.getElementById("DinamizeDivMessageAlert"); if(msgAlert) { msgAlert.style.display = "none"; } var msgError = document.getElementById("DinamizeDivMessageError"); if(msgError) { msgError.style.display = "none"; } var ifrm = document.getElementById("iframeFormIntegration"); if(ifrm) { ifrm.parentNode.removeChild(ifrm); } var img = document.getElementById("DinamizeImgResponse"); if(img) { img.parentNode.removeChild(img); } } function validateEmail(email) { var re = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return re.test(email); } function addClass( classname, element ) { var cn = element.className; if( cn.indexOf( classname ) != -1 ) { return; } if( cn != "" ) { classname = " "+classname; } element.className = cn+classname; } function removeClass( classname, element ) { var cn = element.className; var rxp = new RegExp( "\\s?\\b"+classname+"\\b", "g" ); cn = cn.replace( rxp, "" ); element.className = cn; } //função do google faz o serialize estilo JQuery function serialize(form){if(!form||form.nodeName!=="FORM"){return }var i,j,q=[];for(i=form.elements.length-1;i>=0;i=i-1){if(form.elements[i].name===""){continue}switch(form.elements[i].nodeName){case"INPUT":switch(form.elements[i].type){case"text":case"hidden":case"password":case"button":case"reset":case"submit":q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value));break;case"checkbox":case"radio":if(form.elements[i].checked){q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value))}break;case"file":break}break;case"TEXTAREA":q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value));break;case"SELECT":switch(form.elements[i].type){case"select-one":q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value));break;case"select-multiple":for(j=form.elements[i].options.length-1;j>=0;j=j-1){if(form.elements[i].options[j].selected){q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].options[j].value))}}break}break;case"BUTTON":switch(form.elements[i].type){case"reset":case"submit":case"button":q.push(form.elements[i].name+"="+encodeURIComponent(form.elements[i].value));break}break}}return q.join("&")};