function getIsValidSubmission(n){return n.validSubmission?n.validSubmission():!0}var formAlreadySubmitted=!1,FormBuilderRender={RenderForms:function(n){this.BindSelectedFields(n),this.BindDropDownControls(n),this.BindPriceFields(n),Object.extend(n,{errorSummary:new Element("div",{style:"display:none;","class":"errorSummary"})}),n.errorSummary.insert(new Element("p").update("Please enter the required information")),Element.insert(n.container.select(".formHeader")[0],{after:n.errorSummary}),Object.extend(n,{fldErrors:[],validSubmission:this.formHandler.bind(this,n)})},BindSelectedFields:function(n){n.container.select("input").each(function(n){n.observe("keydown",function(n){n.keyCode==13&&Event.stop(n)}.bindAsEventListener(this))},this),n.container.select(".fieldItem").each(function(n){n.observe("click",function(n,t){$$(".fieldSelected").each(function(n){this.id!=n.id&&n.removeClassName("fieldSelected")}),t.addClassName("fieldSelected")}.bindAsEventListener(this,n))},this),n.container.select("input, textarea, select").each(function(n){n.type&&n.type!="button"&&n.observe("focus",function(n,t){var i=t.up("div.fieldItem");i.hasClassName("fieldSelected")||($$(".fieldSelected").each(function(n){n.removeClassName("fieldSelected")},this),i.addClassName("fieldSelected"))}.bindAsEventListener(this,n))},this)},BindDropDownControls:function(n){var t=n.urlScheme+"www.formbldr.com/images/flags/";n.container.select(".dropdown-image-container").each(function(n){var i=n.select(".dropdown")[0];i.options.length>0&&(n.select(".dropdown-image")[0].insert(new Element("img",{src:t+i.options[i.selectedIndex].value+".png"})),i.observe("change",function(){this.next(".dropdown-image",0).update(new Element("img",{src:t+this.options[this.selectedIndex].value+".png",width:"16",height:"11"}))}),i.observe("keypress",function(){Prototype.Browser.IE||this.next(".dropdown-image",0).update(new Element("img",{src:t+this.options[this.selectedIndex].value+".png",width:"16",height:"11"}))}))})},BindPriceFields:function(n){Object.extend(n,{priceSelectedField:new Element("input",{type:"hidden",name:"priceField_"+n.properties.formID,value:""})}),n.container.insert(n.priceSelectedField),n.fieldsets.each(function(t,i){var r=n.elements[i].fieldType;t.select("input.priceField").each(function(i){r=="multiplechoice"?i.observe("click",this.PriceFieldUpdate.bindAsEventListener(this,n,t,i,!0)):i.observe("click",this.PriceFieldUpdate.bindAsEventListener(this,n,t,i,!1)),i.checked&&(n.priceSelected.push(i.optionID),t.lastSelectedPrice=i.optionID)},this),t.select("select.priceField").each(function(t){t.observe("change",function(n,t,i){var u=i.options[i.selectedIndex].optionID,r=t.priceSelected.indexOf(i.lastSelectedPrice);r<0||t.priceSelected.splice(r,1),t.priceSelected.push(u),i.lastSelectedPrice=u}.bindAsEventListener(this,n,t));var r=t.options[t.selectedIndex].optionID;n.priceSelected.push(r),t.lastSelectedPrice=r},this)},this)},PriceFieldUpdate:function(n,t,i,r,u){var e,f;r.checked?t.priceSelected.indexOf(r.optionID)<0&&(u&&i.lastSelectedPrice&&(e=t.priceSelected.indexOf(i.lastSelectedPrice),e<0||t.priceSelected.splice(e,1)),t.priceSelected.push(r.optionID),i.lastSelectedPrice=r.optionID):(f=t.priceSelected.indexOf(r.optionID),f>0&&t.priceSelected.splice(f,1))},formResponseHandler:function(n,t){var i,r,u;t.contentDocument?(i=t.contentDocument,r=t.contentWindow):t.contentWindow?(i=t.contentWindow.document,r=t.contentWindow):(i=window.frames[t.id].document,r=window.frames[t.id]);try{u=i.forms[0].hfResponse.value.evalJSON(!0),this.responseHandler(n,u)}catch(f){}},responseHandler:function(n,t){if(t.formResponse.isSuccess)switch(t.formResponse.confirmationType){case"text":this.initializeMessage(t.formResponse.confirmationText,n);break;case"redirect":location.href=t.formResponse.confirmationText;break;case"form":this.buildForm(t.formResponse.confirmationText.evalJSON(!0))}else{for(i=0;i<t.formResponse.elements.length;i++)n.fldErrors.push({fieldset:n.fieldsets[t.formResponse.elements[i].fieldset],message:t.formResponse.elements[i].message,fields:[]});FormBuilderValidate.AddErrors(n)}},buildForm:function(n){var i=$$("body")[0],t=new Element("form",{action:n.action,method:n.method,target:"_parent"});i.insert(t),n.elements.each(function(n){t.insert(new Element("input",{type:"hidden",name:n.name,value:n.value}))},this),t.submit()},linkString:function(){return Prototype.Browser.IE?"history.back(2)":"history.go(-2)"},initializeMessage:function(n,t){FormBuilderLightbox.Show({container:t.container,afterShow:function(n){var r=new Element("div",{"class":"confirmation-content"}),i=new Element("div",{"class":"confirmation-content-message"}),u=new Element("a",{href:"javascript:"+FormBuilderRender.linkString()+";"}).update("Return to the previous page"),t;n.showMessage&&i.update("<p>&nbsp;</p><p><strong>"+n.showMessage+"</strong></p>"),i.insert(new Element("p").insert(u)),r.insert(i),t=$$("#lightbox_content .lightbox-content")[0],t.update(),t.insert(r)},showMessage:n,closeable:!1})},formHandler:function(n){return n.priceSelectedField.value=n.priceSelected,FormBuilderValidate.Validate(n)},appendSubmitControls:function(n){var t=new Element("div",{"class":"submitButtonContainer"}),u=new Element("input",{type:"submit","class":"submitButton",value:"Submit"}),r,i;u.observe("click",function(n,t){var u=getIsValidSubmission(t);if(u&&!formAlreadySubmitted){formAlreadySubmitted=!0;var f=+new Date/1e3,i=Math.floor(Math.random()*999999),r=f.toString()+i.toString();Object.extend(t,{uniqueSubmitToken:new Element("input",{type:"hidden",name:"uniqueSubmitToken",value:r})}),t.container.insert(t.uniqueSubmitToken),t.onValidSubmission&&t.onValidSubmission()}else Event.stop(n)}.bindAsEventListener(this,n)),t.insert(u),n.properties.showReportAbuseLink&&(r=new Element("span").update("&nbsp;"),i=new Element("a",{href:"/public/reportabuse.aspx",target:"_blank"}).update("Report Abuse"),t.insert(r),t.insert(i)),n.container.insert(t)},loadViewState:function(n){if(n.viewStateField.value!=""){var i=document.forms[0],t=n.viewStateField.value.evalJSON(!0);t.each(function(n){var r=i[n.name];r.type&&r.type.toLowerCase()=="file"||(r.value=n.value,n.checked&&(r.checked=!0))},this)}},saveViewState:function(n){var t=[];n.container.select("INPUT, SELECT, TEXTAREA").each(function(n){n.name!=""&&n.name!="uniqueSubmitToken"&&t.push({name:n.name,value:n.value,checked:n.checked?!0:!1})},this),n.viewStateField.value=t.toJSON()}}
