var FormBuilder=Class.create({container:null,isEditing:false,urlScheme:"http://",title:null,description:null,fieldsets:null,properties:null,elements:null,paymentInfo:null,initialize:function(a,d,b,c){if(typeof a=="string")this.container=$PROTO(a);else this.container=a;this.isEditing=d;if(c)this.urlScheme=c;this.paymentInfo=b.data.paymentInfo;this.properties=b.data.properties;this.elements=b.data.elements;this.fieldsets=[];this.paymentInfo&&this.container.addClassName("paymentForm");this.BuildForm()},BuildForm:function(){var a=new Element("div",{"class":"formHeader"});try{this.title=new Element("h2",{"class":"formTitle"}).update(this.properties.title)}catch(c){this.title=new Element("h2",{"class":"formTitle"}).update(this.properties.title.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi,""))}try{this.description=new Element("p",{"class":"formDescription"}).update(this.properties.description)}catch(c){this.description=new Element("p",{"class":"formDescription"}).update(this.properties.description.stripTags())}a.insert(this.title);a.insert(this.description);this.container.insert(a);this.elements!=null&&this.elements.each(function(a){a.isCaptcha=a.formElementID==this.properties.captchaFieldsetID;this.insertFieldset(a,true)},this)},insertFieldset:function(a,g,h){var b=new Element("div",{"class":"fieldItem type-"+a.fieldType});a.cssClass&&a.cssClass.each(function(a){b.addClassName(a)},this);var c=new Element("div",{"class":"fieldItemInner"}),f=new Element("div",{"class":"fieldTitle"}).update('<span class="title">'+a.fieldTitle+'</span><span class="req">'+(a.isRequired?"*":"")+'</span><em class="uni">'+(a.isUnique?"(unique)":"")+"</em>"),d=new Element("div",{"class":"fieldInstructions"}).update(a.instructions?a.instructions:""),e=[];b.fieldTitle=f;b.instructions=d;c.insert(f);c.insert(this.BuildFields(a,b,h,e));c.insert(d);b.insert(c);this.container.insert(b);e.each(function(a){$PROTO(a).checked=true},this);if(g)this.fieldsets.push(b);else return b},BuildFields:function(d,h,g,f){var e=new Element("div",{"class":"fieldContent"}),i=0,a=new Element("p",{"class":"fieldRow"});Object.extend(h,{fields:[]});d.fields.each(function(b){if(i!=b.fieldRow){e.insert(a);i=b.fieldRow;a=new Element("p",{"class":"fieldRow"})}var j=new Element("span",{"class":"fieldBlock"}),k=new Element("label",{"class":"fieldName"}).update(b.name?b.name:""),l=new Element("em",{"class":"fieldNote"}).update(b.fieldNote?b.fieldNote:""),c,d="field_"+this.properties.formID+"_"+(g?g:b.fieldID);switch(b.type){case"text":c=new Element("input",{name:d,type:"text",size:b.size,"class":"textField "+$A(b.cssClass).join(" ")+(b.isRequired?" required validate-"+b.type:""),value:b.defaultValue?b.defaultValue:""});break;case"radio":c=new Element("span",{"class":b.type+"-container"});b.options.each(function(a,h){var g=new Element("span",{"class":"choice-option"}),i=new Element("label",{"for":d+"_option_"+h}).update(a.text),e=new Element("input",{id:d+"_option_"+h,name:d,checked:a.isDefault?true:false,type:b.type,value:a.text});e.optionID=a.optionID;a.isDefault&&f.push(e.id);this.paymentInfo&&e.addClassName("priceField");g.insert(e);g.insert(i);c.insert(g)},this);break;case"checkbox":c=new Element("span",{"class":b.type+"-container"});b.options.each(function(e,h){var g=new Element("span",{"class":"choice-option"}),i=new Element("label",{"for":d+"_option_"+h}).update(e.text),a=new Element("input",{id:d+"_option_"+h,name:d+"_option_"+h,type:b.type,"class":"checkbox",checked:e.isChecked?true:false,value:e.text});if(!a.value||a.value=="")a.value="checked";a.optionID=e.optionID;e.isChecked&&f.push(a.id);this.paymentInfo&&a.addClassName("priceField");g.insert(a);g.insert(i);c.insert(g)},this);break;case"country":c=this.BuildDropDownWithImage(d,Country.data,"country",b.defaultValue);break;case"state":c=this.BuildDropDown(d,US_States.data,"states");c.value=b.defaultValue?b.defaultValue:"";break;case"email":c=new Element("input",{name:d,type:"text",size:b.size,"class":"textField "+$A(b.cssClass).join(" ")+(b.isRequired?" required validate-"+b.type:""),value:b.defaultValue?b.defaultValue:""});break;case"website":c=new Element("input",{id:d,name:d,type:"text",size:b.size,"class":"textField "+$A(b.cssClass).join(" ")+(b.isRequired?" required validate-"+b.type:""),value:b.defaultValue?b.defaultValue:""});break;case"select":c=this.BuildDropDown(d,b.options);this.paymentInfo&&c.addClassName("priceField");if(b.defaultValue&&b.defaultValue!="")c.value=b.defaultValue;break;case"currency":c=new Element("input",{name:d,type:"text",size:b.size,"class":"textField "+$A(b.cssClass).join(" ")+(b.isRequired?" required validate-"+b.type:""),value:b.defaultValue?b.defaultValue:""});break;case"number":c=new Element("input",{name:d,type:"text",size:b.size,"class":"textField "+$A(b.cssClass).join(" ")+(b.isRequired?" required validate-"+b.type:""),value:b.defaultValue?b.defaultValue:""});break;case"textarea":c=new Element("textarea",{name:d,rows:b.rows?b.rows:6,cols:b.size&&b.size>0?b.size:46,"class":"textField "+$A(b.cssClass).join(" ")+(b.isRequired?" required validate-"+b.type:"")});c.value=b.defaultValue?b.defaultValue:"";break;case"filebutton":c=new Element("button",{name:d,size:b.size,"class":"textField "+$A(b.cssClass).join(" ")}).update("Upload File");break;case"file":c=new Element("input",{name:d,type:"file",size:b.size,"class":"textField "+$A(b.cssClass).join(" ")+(b.isRequired?" required validate-"+b.type:""),value:b.defaultValue?b.defaultValue:""});break;case"richtext":c=new Element("span",{id:d,"class":"",value:b.defaultValue?b.defaultValue:""});break;case"captcha":c=new Element("img",{src:this.urlScheme+(location.host=="www.icebrrg.com"?"www.icebrrg.com":"www.formbldr.com")+"/formHandler/captcha.aspx?width=200&height=50&formID="+this.properties.formID+(this.properties.captchaCode?"&code="+encodeURIComponent(this.properties.captchaCode):""),width:"200",height:"50"});break;default:c=new Element("input",{name:d,type:"text",size:b.size,"class":"textField "+$A(b.cssClass).join(" ")+(b.isRequired?" required validate-"+b.type:""),value:b.defaultValue?b.defaultValue:""})}j.insert(k);j.insert(c);j.insert(l);a.insert(j);h.fields.push({name:k,field:c,note:l})},this);if(!this.isEditing&&d.fieldType=="date"){var b=new Element("span",{"class":"fieldBlock datePickerImage"});b.insert(new Element("label",{"class":"fieldName"}).update("&nbsp;"));var c=new Element("img",{src:this.urlScheme+"www.icebrrg.com/images/cal.gif"});c.observe("click",function(a,b){DatePickerManager.Show(Event.element(a),b);a.stop()}.bindAsEventListener(this,a));c.rel=d.formatType;b.insert(c);b.insert(new Element("em",{"class":"fieldNote"}).update("&nbsp;"));a.insert(b)}e.insert(a);return e},BuildDropDown:function(e,d,c,a){var b=new Element("select",{name:e,"class":"dropdown "+c,multiple:c=="multiple"});d.each(function(c){var d=new Element("option",{value:c.value?c.value:c.text}).update(c.text);if(c.isDefault&&(null==a||""==a))a=d.value;d.optionID=c.optionID;b.insert(d)},this);if(a)b.value=a;return b},BuildDropDownWithImage:function(g,d,f,c){var a=new Element("div",{"class":"dropdown-image-container"}),e=this.BuildDropDown(g,d,f,c),b=new Element("span",{"class":"dropdown-image"});a.insert(e);a.insert(b);return a},updateSelectOptionList2:function(c,b,d,a){if(!a)a=["value","text"];b.each(function(e,f){var b=document.createElement("option");b.value=a[0]?e[a[0]]:f;b.appendChild(document.createTextNode(e[a[1]]));if(e[a[0]]==d)b.selected="selected";c.appendChild(b)})}});JsonBuilder={buildObject:function(a,b){if(b)a=a.replace(/\\\\/g,"\\");var c=a.evalJSON(true);return c}}
