function VTG_OptIn(){ // Object variables this.FormId = ""; this.Key = ""; this.SubmitType = "ajax"; this.SuccessRedirect = ""; this.ErrorRedirect = ""; this.Debug = false; this.Callback = ""; this.FormAttribute = "vtid"; this.ListId = new Array(); this.KeepList = 1; } function VTG_GetFields() { var campos = new Array(); var form = document.getElementById(this.FormId); var total = 0; for (i = 0; i < form.elements.length; i++) { if (form.elements[i].getAttribute(this.FormAttribute) != null) { switch(form.elements[i].getAttribute("type")) { case 'button': break; case 'submit': break; case 'reset': break; case 'radio': if (form.elements[i].checked == true) { campos[total] = new Array(); campos[total]['tag'] = form.elements[i].getAttribute(this.FormAttribute); campos[total]['value'] = form.elements[i].value; total++; } break; case 'checkbox': if (form.elements[i].checked == true) { campos[total] = new Array(); campos[total]['tag'] = form.elements[i].getAttribute(this.FormAttribute); campos[total]['value'] = form.elements[i].value; total++; } break; default: campos[total] = new Array(); campos[total]['tag'] = form.elements[i].getAttribute(this.FormAttribute); campos[total]['value'] = form.elements[i].value; total++; break; } } } return campos; } function VTG_Verify() { return true; } function VTG_SubmitForm() { frm = document.getElementById(this.FormId); iptKey = document.createElement("input"); iptKey.setAttribute("type", "hidden"); iptKey.setAttribute("name", "VTGChave"); iptKey.setAttribute("value", this.Key); iptType = document.createElement("input"); iptType.setAttribute("type", "hidden"); iptType.setAttribute("name", "VTGTipo"); iptType.setAttribute("value", this.SubmitType); if (this.SuccessRedirect != "") { iptSuccess = document.createElement("input"); iptSuccess.setAttribute("type", "hidden"); iptSuccess.setAttribute("name", "successRedirect"); iptSuccess.setAttribute("value", this.SuccessRedirect); } else { alert("Página de redirecionamento não encontrada."); return false; } if (this.ErrorRedirect != "") { iptError = document.createElement("input"); iptError.setAttribute("type", "hidden"); iptError.setAttribute("name", "errorRedirect"); iptError.setAttribute("value", this.ErrorRedirect); } else { alert("Página de redirecionamento não encontrada."); return false; } iptDebug = document.createElement("input"); iptDebug.setAttribute("type", "hidden"); iptDebug.setAttribute("name", "VTGDebug"); iptDebug.setAttribute("value", this.Debug); for (i = 0; i < this.ListId.length; i++) { iptLista = document.createElement("input"); iptLista.setAttribute("type", "hidden"); iptLista.setAttribute("name", "VTGListas[]"); iptLista.setAttribute("value", parseInt(this.ListId[i])); frm.appendChild(iptLista); } frm.appendChild(iptKey); frm.appendChild(iptType); frm.appendChild(iptSuccess); frm.appendChild(iptError); frm.appendChild(iptDebug); frm.action = document.location.protocol + "//gadgets.virtualtarget.com.br/index.dma/OptIn"; frm.submit(); } function VTG_SubmitAjax() { frm = document.getElementById(this.FormId); var campos = this.VTG_GetFields(); var param = ""; for (i = 0; i < this.ListId.length; i++) { param += "VTGListas[]=" + parseInt(this.ListId[i]) + "&"; } for (i = 0; i < campos.length; i++) { param += escape(campos[i]['tag'].toLowerCase()) + "=" + escape(campos[i]['value']) + "&"; } param += "VTGKeepList=" + this.KeepList + "&VTGChave=" + this.Key + "&VTGDebug=" + this.Debug + "&VTGTipo=ajax"; scr = document.createElement("script"); scr.setAttribute("src", document.location.protocol + "//gadgets.virtualtarget.com.br/index.dma/OptIn?" + param); scr.setAttribute("type", "text/javascript"); scr.setAttribute("id", "VTGScript"); frm.appendChild(scr); } function VTG_Submit() { if (document.getElementById(this.FormId) != undefined) { if (this.VTG_Verify()) { if (this.SubmitType == "form") { this.VTG_SubmitForm(); } else if (this.SubmitType == "ajax") { this.VTG_SubmitAjax(); } else { alert("Atributo SubmitType inválido."); } } } else { alert("Atributo FormId ("+ this.FormId + ") inválido."); } } // Definitions VTG_OptIn.prototype.VTG_Submit = VTG_Submit; VTG_OptIn.prototype.VTG_SubmitForm = VTG_SubmitForm; VTG_OptIn.prototype.VTG_SubmitAjax = VTG_SubmitAjax; VTG_OptIn.prototype.VTG_Verify = VTG_Verify; VTG_OptIn.prototype.VTG_GetFields = VTG_GetFields; // Start object VTG = new VTG_OptIn();