function formPresentationLocalization(){this.months=new Array('Month','January','February','March','April','May','June','July','August','September','October','November','December');this.date='Date';this.year='Year';this.errorHeading="Missing Fields";return;}
function formPresentationForm(name,heading,height,width,charwidth,columns,columncolumns,margin,margintotal){TypeWriters=new formPresentationFieldTypeWriters();this.TypeWriters=TypeWriters;this.name=name;this.heading=heading;this.columns=columns;this.columncolumns=columncolumns;this.height=height;this.width=width;this.charwidth=charwidth;this.padding=8;this.columnmargin=new String();this.columnmargin.total=(typeof(margintotal)=='undefined'?130:margintotal)/this.columns;this.columnmargin.margin=typeof(margin)=='undefined'?20:margin;this.requiredfields=new Array();this.validatefields=new Array();this.maxlengthfields=new Array();this.columnwidth=Math.floor((this.width-this.columnmargin.total)/this.columns);this.localization=new formPresentationLocalization();this.events=new Array();this.onload=function(){if(this.events.length>0){for(var i=0;i<this.events.length;i++){this.events[i].apply(this);}}};this.Columns=new Array();switch(columns){case 1:this.addColumn('free',width);break;case 2:this.addColumn('left');this.addColumn('right');this.addColumn('free');break;}}
function formPresentationColumn(name){this.name=name;this.lines=0;this.Sections=new Array();}
function formPresentationSection(name,heading,type){this.name=name;this.heading=heading;this.parameters={};this.type=type;this.lines=0;this.Groups=new Array();}
function formPresentationGroup(name,type){this.name=name;this.type=typeof(type)=='string'?type:'Row';this.parameters={};this.maxWidth=0;this.required=false;this.Fields=new Array();}
function formPresentationField(name,text,type,def,required,maxsize,errortext,fieldval,maxlength){this.write=TypeWriters[type];this.type=type;this.parameters={};this.name=name;this.text=text;this.type=type;this.def=def;this.required=required;this.maxsize=maxsize;this.size=maxsize;try{this.maxlength=maxlength.length>0?parseInt(maxlength):null;}catch(e){}
switch(type){case'Select':this.size=0;break;default:this.size=this.size<text.length?(text.length-3):this.size<5?5:this.size>35?35:maxsize;break;}
this.errortext=errortext;this.fieldval=fieldval;this.SubFields=new Array();}
function formPresentationSubField(name,text,type,def,required,maxsize,errortext,fieldval,maxlength){this.write=TypeWriters[type];this.type=type;this.parameters={};this.name=name;this.text=text;this.def=def;this.required=required;this.maxsize=maxsize;this.size=maxsize;try{this.maxlength=maxlength.length>0?parseInt(maxlength):null;}catch(e){}
switch(type){case'Select':this.size=0;break;default:this.size=this.size<text.length?(text.length-3):this.size<5?5:this.size>35?35:maxsize;break;}
this.errortext=errortext;}
function formPresentationParameter(value,displayname){this.value=value;this.display=displayname;}
formPresentationForm.prototype.write=formPresentationFormWrite;formPresentationForm.prototype.addColumn=formPresentationFormAddColumn;formPresentationForm.prototype.balance=formPresentationColumnBalance;formPresentationColumn.prototype.write=formPresentationColumnWrite;formPresentationColumn.prototype.addSection=formPresentationColumnAddSection;formPresentationSection.prototype.write=formPresentationSectionWrite;formPresentationSection.prototype.addGroup=formPresentationSectionAddGroup;formPresentationSection.prototype.addParameter=formPresentationAddParameter;formPresentationGroup.prototype.write=formPresentationGroupWrite;formPresentationGroup.prototype.addField=formPresentationGroupAddField;formPresentationGroup.prototype.chars=formPresentationGroupChars;formPresentationGroup.prototype.addParameter=formPresentationAddParameter;formPresentationGroup.prototype.balance=formPresentationGroupBalance;formPresentationField.prototype.addSubField=formPresentationFieldAddSubField;formPresentationField.prototype.addParameter=formPresentationAddParameter;formPresentationSubField.prototype.addParameter=formPresentationAddParameter;function formPresentationColumnBalance(){if(this.columns>1){var totalcols=0;for(var cols=0;cols<this.Columns.length;cols++){totalcols+=this.Columns[cols].lines;}
var avgcols=Math.ceil(totalcols/this.columns)+2;for(var cols=0;cols<this.Columns.length-1;cols++){while(this.Columns[cols].lines<avgcols&&this.Columns[this.Columns.length-1].Sections.length>0){var newsection=this.Columns[this.Columns.length-1].Sections.shift();this.Columns[cols].lines+=newsection.lines;this.Columns[cols].Sections.push(newsection);}}
if(this.Columns[this.Columns.length-1].Sections.length>0){for(var section=0;section<this.Columns[this.Columns.length-1].Sections.length;section++){var newsection=this.Columns[this.Columns.length-1].Sections.shift();this.Columns[this.Columns.length-2].lines+=newsection.lines;this.Columns[this.Columns.length-2].Sections.push(newsection);}}
var popc=this.Columns.pop();}}
function formPresentationGroupBalance(groupnumber){var fields=this.Fields.length;var maxchars=this.chars();var groupdesignator=1;switch(this.type){case'Row':case'ListRow':if(fields>3||(fields>1&&maxchars>150)){groupdesignator++;this.section.addGroup(this.name+groupdesignator.toString(),this.type);movegroup=this.section.Groups.pop();this.section.Groups=this.section.Groups.insert(groupnumber+1,movegroup);var chars=0;var field=0;do{if(typeof(this.Fields[field])=='object'){chars+=this.Fields[field].size;if(chars>150||field>=3){this.section.Groups[groupnumber+1].Fields.push(this.Fields[field]);chars-=this.Fields[field].size;maxchars-=this.Fields[field].size;fields--;this.Fields.splice(field,1);}else{field++;}}else{break;}}while(fields>3||(fields>1&&maxchars>150));}
break;}}
function formPresentationGoldenRatio(totalwidth,totalchars,columns){if(columns==1){this.apixels=totalwidth;this.bpixels=0;this.achars=totalchars;this.bchars=0;this.aratio=this.apixels/this.achars;this.bratio=0;return;}
var aplusb=totalwidth;var a=aplusb/1.618;var b=aplusb-a;this.apixels=a;this.bpixels=b;aplusb=Math.floor(totalchars/columns);a=aplusb/1.618;b=aplusb-a;this.achars=a;this.bchars=b;this.aratio=this.apixels/this.achars;this.bratio=this.bpixels/this.bchars;return;}
function formPresentationGroupChars(){var chars=0;if(this.Fields.length>0){for(var field=0;field<this.Fields.length;field++){switch(this.type){case'Row':case'ListRow':chars+=this.Fields[field].size;break;case'List':case'RowList':switch(field){case 0:chars=this.Fields[field].size;break;default:if(this.Fields[field].size>chars){chars=this.Fields[field].size;}
break;}}}}
return chars;}
function formPresentationFormWrite(formelement){this.balance();for(var column=0;column<this.Columns.length;column++){if(typeof(this.Columns[column])=='object'){formelement.appendChild(this.Columns[column].write());}}
var requiredfields=this.requiredfields;formelement.requiredfields=requiredfields?requiredfields.copy():[];var validatefields=this.validatefields;formelement.validatefields=validatefields?validatefields.copy():[];var maxlengthfields=this.maxlengthfields;formelement.maxlengthfields=maxlengthfields?maxlengthfields.copy():[];formelement.onsubmit=formPresentationFormValidate;this.formelement=formelement;window.formelement=formelement;this.onload();}
function formPresentationColumnWrite(){var column=document.createElement('div');column.className='fpColumn';column.id='fpColumn'+this.name;column.style.marginLeft=this.form.columnmargin.margin+'px';switch(this.name){case'left':column.style.marginRight=(((this.form.columnmargin.total-(this.form.columnmargin.margin*this.form.columns))*this.form.columns)/(this.form.columns+1))+'px';break;case'right':column.style.marginRight='0px';break;default:column.style.marginRight='0px';break;}
column.style.width=this.form.columnwidth+'px';column.style.height=this.form.height;for(var section=0;section<this.Sections.length;section++){column.appendChild(this.Sections[section].write());}
return column;}
function formPresentationSectionWrite(){var section;switch(this.type){case'Paragraph':section=document.createElement('p');section.className='fp'+this.type;if(typeof(this.className)!='undefined'){if(this.className.length>0){section.className+=' '+this.className;}}
section.innerHTML=this.heading;break;default:var fields=0;for(var group=0;group<this.Groups.length;group++){if(this.Groups[group].Fields.length>0){fields+=this.Groups[group].Fields.length;break;}}
if(fields==0){section=document.createElement("div");section.style.display="none";section.hidden=true;return section;}
section=document.createElement('div');for(var param in this.parameters){if(typeof(this.parameters[param])!='function'){section[this.parameters[param].value]=this.parameters[param].display;}}
switch(this.type){case'Standard':section.className='fpSection';break;case'Indent':section.className='fpSection fpIndent';break;}
section.id='fpSection'+this.name;if(this.heading.length>0){heading=document.createElement('label');heading.innerHTML=this.heading;heading.id='fpLabel_'+this.name;heading.className='fpLabel';section.appendChild(heading);}
var requiredgroups=0;for(var group=0;group<this.Groups.length;group++){this.Groups[group].balance(group);section.appendChild(this.Groups[group].write());if(this.Groups[group].required){requiredgroups++;}}
if(((this.Groups.length==requiredgroups)||section.required)&&(this.heading.length>0)){heading.innerHTML+='<span>*</span>';}
break;}
return section;}
function formPresentationGroupWrite(){if(this.Fields.length>0){var group=document.createElement('div');for(var param in this.parameters){if(typeof(this.parameters[param])!='function'){group[this.parameters[param].value]=this.parameters[param].display;}}
group.className+=' fpGroup fp'+this.type+'Group';group.id='fpGroup'+this.name;if(!this.required&&this.Fields.length>0){var requiredfields=0;for(var field=0;field<this.Fields.length;field++){if(this.Fields[field].required){requiredfields++;}}
if(this.Fields.length==requiredfields){this.required=true;}}
if(this.required&&(this.Fields[0].type.indexOf('Radio')!=-1||this.Fields[0].type.indexOf("CheckBoxGroup")!=-1)){this.form.requiredfields.push(this.name);}
if(group.heading){heading=document.createElement('label');if(group.heading.length>0&&this.required){group.heading+='<span>*</span>';}
heading.innerHTML=group.heading;heading.id='fpLabel_'+this.name;heading.className='fpLabel';group.appendChild(heading);}
switch(this.Fields[0].type){case'FreeText':group.className+=' fpHiddenGroup';this.section.topicselect.changegroup=group.id;break;}
this.maxchars=this.chars();switch(this.type){case'Row':case'ListRow':switch(this.Fields.length){case 1:switch(this.Fields[0].type){case'Select':group.appendChild(this.Fields[0].write('auto',this.column.goldenratio.aratio*this.Fields[0].size));break;default:group.appendChild(this.Fields[0].write('auto',this.column.goldenratio.apixels));break;}
break;case 2:switch(true){case(this.Fields[0].size==this.Fields[1].size):group.appendChild(this.Fields[0].write('auto',(this.form.columnwidth/2)-this.form.columnmargin.margin));group.appendChild(this.Fields[1].write('auto',(this.form.columnwidth/2)-this.form.columnmargin.margin));break;case(this.Fields[1].size>this.Fields[0].size):group.appendChild(this.Fields[0].write('auto',this.column.goldenratio.bpixels));group.appendChild(this.Fields[1].write('auto',this.column.goldenratio.apixels));break;default:group.appendChild(this.Fields[0].write('auto',this.column.goldenratio.apixels));group.appendChild(this.Fields[1].write('auto',this.column.goldenratio.bratio*this.Fields[1].size));break;}
break;default:var ratio=(this.form.columnwidth-(this.Fields.length*this.form.padding*1.5))/this.maxchars;for(var field=0;field<this.Fields.length;field++){group.appendChild(this.Fields[field].write('auto',Math.floor(this.Fields[field].size*ratio)));}
break;}
break;case'List':case'RowList':for(var field=0;field<this.Fields.length;field++){switch(this.Fields[field].SubFields.length){case 2:group.appendChild(this.Fields[field].write('auto',this.form.columnwidth));break;default:var thisField=this.Fields[field];if(thisField.type=='Text'&&typeof(this.Fields[field+1])=='object'){var nextField=this.Fields[field+1];try{if(nextField.parameters["ownLine"].display=="true"){nextField=false;}}catch(e){}
if(this.column.goldenratio.bratio>0&&nextField&&nextField.size*this.column.goldenratio.bratio<=this.column.goldenratio.bpixels){if((typeof(this.Fields[field+2])=='object'&&this.Fields[field+2].size<nextField.size)){group.appendChild(thisField.write('auto',this.column.goldenratio.apixels));}else{var row=document.createElement('div');row.className='fpListColumns';var fielditemA=thisField.write('auto',this.column.goldenratio.apixels);fielditemA.className+=' fpListColumnField';row.appendChild(fielditemA);var fielditemB=nextField.write('auto',nextField.size*this.column.goldenratio.bratio);fielditemB.className+=' fpListColumnField';row.appendChild(fielditemB);group.appendChild(row);field++;}}else{if(this.column.goldenratio.bratio>0&&nextField&&(thisField.maxsize==nextField.maxsize)&&(parseInt(thisField.maxsize)+parseInt(nextField.maxsize)<130)){if(nextField.size*this.column.goldenratio.aratio<=((this.form.columnwidth-this.form.padding)/2)){var row=document.createElement('div');row.className='fpListColumns';var fielditemA=thisField.write('auto',thisField.size*this.column.goldenratio.aratio);fielditemA.className+=' fpListColumnField';row.appendChild(fielditemA);var fielditemB=nextField.write('auto',nextField.size*this.column.goldenratio.aratio);fielditemB.className+=' fpListColumnField';row.appendChild(fielditemB);group.appendChild(row);field++;}else{if((thisField.size<nextField.size)&&(parseInt(thisField.maxsize)+parseInt(nextField.maxsize)<130)){if(nextField.size*this.column.goldenratio.aratio<=this.column.goldenratio.apixels){var row=document.createElement('div');row.className='fpListColumns';var fielditemA=thisField.write('auto',this.column.goldenratio.bpixels);fielditemA.className+=' fpListColumnField';row.appendChild(fielditemA);var fielditemB=nextField.write('auto',this.column.goldenratio.apixels);fielditemB.className+=' fpListColumnField';row.appendChild(fielditemB);group.appendChild(row);field++;}}else{group.appendChild(thisField.write('auto',this.column.goldenratio.apixels));}}}else{group.appendChild(thisField.write('auto',this.column.goldenratio.apixels));}}}else{if((thisField.size*this.column.goldenratio.aratio)<=(this.column.goldenratio.apixels*0.4)){group.appendChild(thisField.write('auto',thisField.size*this.column.goldenratio.aratio));}else{group.appendChild(thisField.write('auto',this.column.goldenratio.apixels));}}
break;}}
break;}}else{group=document.createElement('div');group.style.display='none';this.hidden=true;}
return group;}
function formPresentationFormAddColumn(name){this.Columns.push(new formPresentationColumn(name));this.Columns[this.Columns.length-1].parent=this;this.Columns[this.Columns.length-1].form=this;this.Columns[this.Columns.length-1].goldenratio=new formPresentationGoldenRatio(this.columnwidth-this.columnmargin.total,this.charwidth,this.columncolumns);this[name]=this.Columns[this.Columns.length-1];return this.Columns[this.Columns.length-1];}
function formPresentationColumnAddSection(name,heading,type){this.Sections.push(new formPresentationSection(name,heading,type));this.Sections[this.Sections.length-1].parent=this.form;this.Sections[this.Sections.length-1].form=this.form;this.Sections[this.Sections.length-1].column=this;this[name]=this.Sections[this.Sections.length-1];return this.Sections[this.Sections.length-1];}
function formPresentationSectionAddGroup(name,type){this.Groups.push(new formPresentationGroup(name,type));this.Groups[this.Groups.length-1].parent=this;this.Groups[this.Groups.length-1].section=this;this.Groups[this.Groups.length-1].form=this.form;this.Groups[this.Groups.length-1].column=this.column;this[name]=this.Groups[this.Groups.length-1];switch(type){case'Row':case'ListRow':this.lines++;this.column.lines++;break;}
return this.Groups[this.Groups.length-1];}
function formPresentationGroupAddField(name,text,type,def,required,maxsize,errortext,fieldval,maxlength){this.Fields.push(new formPresentationField(name,text,type,def,required,maxsize,errortext,fieldval,maxlength));this.Fields[this.Fields.length-1].parent=this;this.Fields[this.Fields.length-1].group=this;this.Fields[this.Fields.length-1].section=this.parent;this.Fields[this.Fields.length-1].form=this.form;this.Fields[this.Fields.length-1].column=this.column;this.Fields[this.Fields.length-1].fieldtype='Field';this.Fields[this.Fields.length-1].fieldval=fieldval;this[name]=this.Fields[this.Fields.length-1];switch(this.type){case'List':case'RowList':if(type=='DealerRadio'||type=="DealerPreselected"){if(typeof(setupDealerSelectionLayer)!='function'){this.parent.lines+=3;this.column.lines+=3;}}else{this.parent.lines++;this.column.lines++;}
break;}
return this.Fields[this.Fields.length-1];}
function formPresentationFieldAddSubField(name,text,type,def,required,maxsize,errortext,fieldval,maxlength){this.SubFields.push(new formPresentationSubField(name,text,type,def,required,maxsize,errortext,fieldval,maxlength));this.SubFields[this.SubFields.length-1].parent=this;this.SubFields[this.SubFields.length-1].field=this;this.SubFields[this.SubFields.length-1].group=this.parent;this.SubFields[this.SubFields.length-1].section=this.parent.section;this.SubFields[this.SubFields.length-1].form=this.form;this.SubFields[this.SubFields.length-1].fieldtype='SubField';this.SubFields[this.SubFields.length-1].fieldval=fieldval;this[name]=this.SubFields[this.SubFields.length-1];return this.SubFields[this.SubFields.length-1];}
function formPresentationAddParameter(value,displayname){var paramName=!isNaN(value)?"param"+value:value;this.parameters[paramName]=new formPresentationParameter(value,displayname);if(this.type=='Select'){if(displayname.length+13>this.size){this.size=displayname.length+13;}}}
function formPresentationFieldTypeWriters(){this.TextWrite=function(h,w){var required=this.required?(this.text.length>0?'<span>*</span>':''):'';var container=new formPresentationContainer(this.group.type,'fpcontainer_'+this.name,h,w,this.form.padding);var itemlabel=new formPresentationLabel("text",this.name,this.text+required,h,w,this.form.padding,this.form.columnwidth);var hiddenlabel;var textbox;switch(this.type){case'View':textbox=document.createNamedElement('p',this.name);textbox.id=this.name;break;case'FreeText':var hiddenlabel=document.createNamedElement('input',(this.labelName!=null?this.labelName:this.name+'Label'));hiddenlabel.type='hidden';hiddenlabel.id=(this.labelName!=null?this.labelName:this.name+'Label');hiddenlabel.value=this.text+required;hiddenlabel.className='fpFieldHidden';container.appendChild(hiddenlabel);var topicselect=this.group.section.topicselect;topicselect.changelabels.push((this.labelName!=null?this.labelName:this.name+'Label'));topicselect.changefields.push(this.name);default:textbox=document.createNamedElement('input',this.name);textbox.type='text';if(this.type=='Password')textbox.type='password';textbox.id=this.name;textbox.maxLength=(this.maxlength||this.maxsize);textbox.size=this.size;textbox.className='fpFieldText';textbox.value=this.def;break;}
if(this.type=="DatePicker"&&typeof(jQuery)!="undefined"){if(!!this.pairedoptionslist){var times=this.pairedoptionslist.split("||");var hiddenDayOfWeek=document.createNamedElement('input',this.name+"DayOfWeek");hiddenDayOfWeek.type='hidden';hiddenDayOfWeek.id=this.name+"DayOfWeek";hiddenDayOfWeek.className="fpFieldHidden";container.appendChild(hiddenDayOfWeek);hiddenDayOfWeek.Sunday=times[0];hiddenDayOfWeek.Monday=times[1];hiddenDayOfWeek.Tuesday=times[2];hiddenDayOfWeek.Wednesday=times[3];hiddenDayOfWeek.Thursday=times[4];hiddenDayOfWeek.Friday=times[5];hiddenDayOfWeek.Saturday=times[6];hiddenDayOfWeek.setAttribute('paired',this.paired);}
if(w<200)w=200;
				jQuery(textbox).datepicker(
					jQuery.extend(
						{}, 
						jQuery.datepicker.regional[this.parameters.languageCode.display],
						{
							dateFormat: (!!this.parameters.dateFormat ? (this.parameters.dateFormat.display) : !!jQuery.datepicker.regional[this.parameters.languageCode.display] ? jQuery.datepicker.regional[this.parameters.languageCode.display].dateFormat : jQuery.datepicker.regional[''].dateFormat),
							closeAtTop: true,
							hideIfNoPrevNext: true,
							goToCurrent: true,
							changeMonth: false,
							changeYear: false,
							changeFirstDay: false,
							rangeSelect: false,
							minDate: (!!this.parameters.minDate ? parseInt(this.parameters.minDate.display) : null),
							maxDate: (!!this.parameters.maxDate ? parseInt(this.parameters.maxDate.display) : null),
							showOn: "focus",
							altField: (!!this.pairedoptionslist ? "#"+this.name+"DayOfWeek" : null),
							altFormat: (!!this.pairedoptionslist ? "yy-mm-dd" : null),
							onClose: (!!this.pairedoptionslist ? function(){formPresentationDatePickerTimes.apply(document.getElementById(this.name+"DayOfWeek"));} : null)
						}
					)
				);		
			}
if(this.maxlength){this.form.maxlengthfields.push(this.name);}
if(this.required){textbox.required=this.required;textbox.errortext=this.errortext;textbox.validate=formPresentationFieldValidate;this.form.requiredfields.push(this.name);if(this.parameters)textbox.parameters=this.parameters;}
if(typeof(this.parameters.validate)!='undefined'){textbox.validate=formPresentationFieldValidate;textbox.errortext=this.errortext;this.form.validatefields.push(this.name);textbox.parameters=this.parameters;}
switch(this.group.type){case'List':case'RowList':if(this.fieldtype=='SubField'){if(arguments[2]==0){textbox.style.width=(w-29)+'px';itemlabel.style.width=(w-29)+'px';}else{textbox.style.width=w+'px';textbox.style.marginRight='0px';}}else{textbox.style.width=w+'px';}
break;case'Row':textbox.style.width=w+'px';break;}
container.appendChild(itemlabel);container.appendChild(textbox);if(typeof(jQuery)!='undefined'&&this.type=='DatePicker')jQuery(textbox).ifixpng();if(typeof(arguments[2])=='string'){document.getElementById(arguments[2]).appendChild(container);}
return container;};this.Text=this.TextWrite;this.FreeText=this.TextWrite;this.Password=this.TextWrite;this.View=this.TextWrite;this.DatePicker=this.TextWrite;this.SelectWrite=function(h,w){var required=this.required?(this.text.length>0?'<span>*</span>':''):'';var container=new formPresentationContainer(this.group.type,'fpcontainer_'+this.name,h,w,this.form.padding);var itemlabel=new formPresentationLabel("select",this.name,this.text+required,h,w,this.form.padding,this.form.columnwidth);var selectname=this.type=="TopicSelect"?this.name+"Select":this.name;var select=document.createNamedElement('select',selectname);select.setAttribute("default",this.def);for(var optionparam in this.parameters){if(typeof(this.parameters[optionparam])!='function'){var option=document.createElement('option');option.value=this.parameters[optionparam].value;option.innerHTML=this.parameters[optionparam].display;if(this.def==this.parameters[optionparam].display){option.selected=true;}
select.appendChild(option);}}
select.id=selectname;select.maxLength=this.maxsize;select.className='fpFieldSelect';switch(this.type){case'TopicSelect':var hiddentopic=document.createNamedElement('input',this.name);hiddentopic.type='hidden';hiddentopic.id=this.name;hiddentopic.className='fpFieldHidden';container.appendChild(hiddentopic);if(this.required){hiddentopic.required=this.required;hiddentopic.errortext=this.errortext;hiddentopic.validate=formPresentationFieldValidate;}
select.onchange=formPresentationTopicSelect;select.requiredText=required;select.changefields=new Array();select.changelabels=new Array();this.group.section.topicselect=select;break;case'PairedSelect':var pairoptions=document.createNamedElement('span',this.name+'PairOptions');pairoptions.id=this.name+'PairOptions';pairoptions.className='fpFieldHidden';pairoptions.style.display="none";pairoptions.innerHTML=this.pairedoptionslist;container.appendChild(pairoptions);select.onchange=formPresentationPairedSelect;select.setAttribute('paired',this.paired);}
if(this.required){select.required=this.required;select.errortext=this.errortext;select.validate=formPresentationFieldValidate;this.form.requiredfields.push(this.name);}
switch(this.group.type){case'List':case'RowList':break;}
if(this.group.type=='Row'||this.group.type=="List"){container.appendChild(itemlabel);}
container.appendChild(select);return container;};this.Select=this.SelectWrite;this.TopicSelect=this.SelectWrite;this.PairedSelect=this.SelectWrite;this.RadioWrite=function(h,w){var itemlabel;if(typeof(this.SubFields)!='undefined'){if(this.SubFields.length>0){labelw=w-29;itemlabel=new formPresentationContainer(this.group.type,'fpcontainer_subfields_'+this.name,h,labelw,this.form.padding);switch(this.SubFields.length){case 1:itemlabel.appendChild(this.SubFields[0].write(h,labelw));break;case 2:if(this.SubFields[0].size>=this.SubFields[1].size){itemlabel.appendChild(this.SubFields[0].write(h,this.column.goldenratio.apixels,0));itemlabel.appendChild(this.SubFields[1].write(h,this.column.goldenratio.bratio*this.SubFields[1].size,1));}else{var shortie=this.column.goldenratio.bratio*(this.SubFields[0].size>5?this.SubFields[0].size:10);itemlabel.appendChild(this.SubFields[0].write(h,shortie,0));itemlabel.appendChild(this.SubFields[1].write(h,this.column.goldenratio.apixels-shortie-12,1));}
break;}}
else{labelw=w;itemlabel=new formPresentationLabel("radio",this.name,this.text,h,labelw,this.form.padding,this.form.columnwidth);}}
var radio=document.createNamedElement('input',this.group.name);radio.type='radio';radio.id=this.name;radio.value=this.name;if(typeof(this.fieldval)!='undefined'&&this.fieldval.length>0){radio.setAttribute("value",this.fieldval);}else{radio.setAttribute("value",this.name);}
radio.className='fpFieldRadio fpField'+this.type;var container;switch(this.type){case'DealerPreselected':radio.style.display="none";radio.checked=true;this.form.events.push(function(){dealerradioonclick.apply(radio);});case'DealerRadio':if(typeof(dealerradioonclick)=='function'){radio.onclick=dealerradioonclick;}
container=new formPresentationContainer(this.group.type+' fpGroup'+this.type,'fpcontainer_'+this.name,h,w,this.form.padding);break;default:container=new formPresentationContainer(this.group.type,'fpcontainer_'+this.name,h,w,this.form.padding);break;}
if(this.def==this.name){radio.checked=true;}
if(this.required){radio.required=true;radio.validate=formPresentationFieldValidate;}
radio.errortext=this.errortext;container.appendChild(radio);container.appendChild(itemlabel);if(typeof(arguments[2])=='string'){document.getElementById(arguments[2]).appendChild(container);}
return container;};this.Radio=this.RadioWrite;this.RowRadio=this.RadioWrite;this.DealerRadio=this.RadioWrite;this.DealerPreselected=this.RadioWrite;this.TextArea=function(h,w){var required=this.required?(this.text.length>0?'<span>*</span>':''):'';var container=new formPresentationContainer(this.group.type,'fpcontainer_'+this.name,h,w,this.form.padding);var itemlabel=new formPresentationLabel("textarea",this.name,this.text+required,h,w,this.form.padding,this.form.columnwidth);var textarea=document.createNamedElement('textarea',this.name);textarea.id=this.name;textarea.maxLength=(this.maxlength||this.maxsize);textarea.wrap='hard';textarea.onkeypress=formPresentationMaxChars;textarea.className='fpFieldTextArea';textarea.style.width=(this.form.columnwidth-this.form.columnmargin.margin)+'px';if(this.required){textarea.required=this.required;textarea.errortext=this.errortext;textarea.validate=formPresentationFieldValidate;this.form.requiredfields.push(this.name);}
if(this.maxlength){this.form.maxlengthfields.push(this.name);}
for(var param in this.parameters){if(typeof(this.parameters[param])!='function'){textarea[this.parameters[param].value]=this.parameters[param].display;}}
container.appendChild(itemlabel);container.appendChild(textarea);if(arguments[2]){document.getElementById(arguments[2]).appendChild(container);}
return container;};this.CheckBoxWrite=function(h,w){var required=this.required&&this.type!="CheckBoxGroup"?(this.text.length>0?'<span>*</span>':''):'';var container=new formPresentationContainer(this.group.type,'fpcontainer_'+this.name,h,w,this.form.padding);var itemlabel=new formPresentationLabel("checkbox",this.name,this.text+required,h,w,this.form.padding,this.form.columnwidth);var checkbox;checkbox=document.createNamedElement('input',this.type=="CheckBoxGroup"?this.group.name:this.name);checkbox.type='checkbox';checkbox.id=this.name;if(typeof(this.fieldval)!='undefined'&&this.fieldval.length>0){checkbox.value=this.fieldval;}else{checkbox.value=this.name;}
checkbox.className='fpFieldCheckBox';checkbox.style.width='21px';if(this.required){checkbox.required=this.required;checkbox.errortext=this.errortext;checkbox.validate=formPresentationFieldValidate;this.form.requiredfields.push(this.name);}
if(this.text+required){itemlabel.style.cssFloat="left";container.style.clear="none";}
container.appendChild(checkbox);container.appendChild(itemlabel);if(arguments[2]){document.getElementById(arguments[2]).appendChild(container);}
if(typeof(this.def)=='string'){if(this.def.length>0){checkbox.checked=true;checkbox.setAttribute("checked","checked");if(checkbox.outerHTML){checkbox.outerHTML=checkbox.outerHTML.replace("INPUT","INPUT type=\"checkbox\" onload='formPresentationPreCheck()'");checkbox.type="checkbox";}}}
return container;};this.CheckBox=this.CheckBoxWrite;this.CheckBoxGroup=this.CheckBoxWrite;this.BirthDate=function(h,w){var required=this.required?(this.text.length>0?'<span>*</span>':''):'';var container=new formPresentationContainer(this.group.type,'fpcontainer_'+this.name,h,w,this.form.padding);var itemlabel=new formPresentationLabel("birthdate",this.name,this.text+required,h,w,this.form.padding,this.form.columnwidth);var monthdrop=document.createNamedElement('select',this.name+'Month');for(var optionparam=0;optionparam<this.form.localization.months.length;optionparam++){var option=document.createElement('option');option.value=optionparam;option.innerHTML=this.form.localization.months[optionparam];monthdrop.appendChild(option);}
monthdrop.id=this.name+'Month';monthdrop.className='fpFieldSelect';monthdrop.onchange=formPresentationChangeMonth;monthdrop.changedate=formPresentationSetFullDate;var datedrop=document.createNamedElement('select',this.name+'Date');var option=document.createElement('option');option.value=0;option.innerHTML=this.form.localization.date;datedrop.appendChild(option);datedrop.id=this.name+'Date';datedrop.className='fpFieldSelect';for(var dateoption=1;dateoption<32;dateoption++){var option=document.createElement('option');option.value=dateoption;option.innerHTML=dateoption;datedrop.appendChild(option);}
datedrop.onchange=formPresentationSetFullDate;var yeardrop=document.createNamedElement('select',this.name+'Year');var date=new Date();var option=document.createElement('option');option.value='';option.innerHTML=this.form.localization.year;yeardrop.appendChild(option);for(var years=date.getFullYear()-10;years>date.getFullYear()-100;years--){var option=document.createElement('option');option.value=years;option.innerHTML=years;yeardrop.appendChild(option);}
yeardrop.id=this.name+'Year';yeardrop.className='fpFieldSelect';yeardrop.onchange=formPresentationSetFullDate;var fulldate=document.createNamedElement('input',this.name);fulldate.type='hidden';fulldate.className='fpFieldHidden';fulldate.value='';fulldate.setValue=formPresentationSetFullDate;fulldate.id=this.name;if(this.required){fulldate.required=this.required;fulldate.errortext=this.errortext;fulldate.validate=formPresentationFieldValidate;this.form.requiredfields.push(this.name);}
if(this.group.type=='Row'){container.appendChild(itemlabel);}
if(typeof(this.parameters['dateformat'])=='undefined'){this.parameters['dateformat']=new formPresentationParameter('dateformat','dmy');}
container.appendChild(fulldate);for(var datesection=0;datesection<3;datesection++){switch(this.parameters['dateformat'].display.toLowerCase().substr(datesection,1)){case'm':container.appendChild(monthdrop);break;case'd':container.appendChild(datedrop);break;case'y':container.appendChild(yeardrop);break;}}
if(arguments[2]){document.getElementById(arguments[2]).appendChild(container);}
return container;};}
function formPresentationContainer(type,name,h,w,p){var container=document.createElement('div');container.id=name;container.className='fpContainer fpGroup'+type;return container;}
function formPresentationLabel(type,name,inner,h,w,p,columnwidth){var itemlabel=document.createElement('label');itemlabel.htmlFor=name;itemlabel.id='fpLabel_'+name;itemlabel.className='fpLabel';if(w<100&&inner.indexOf('<span>*</span>')!=-1){itemlabel.style.paddingRight='30px';}
if(inner.length>60){itemlabel.style.whiteSpace="normal";itemlabel.style.display="block";itemlabel.style.width=(columnwidth-((type=="checkbox"||type=="radio")?55:20))+"px";}
switch(typeof(inner)){case'string':itemlabel.innerHTML=inner;break;case'object':itemlabel.appendChild(inner);break;}
return itemlabel;}
function formPresentationMaxChars(){return(this.value.length>=this.maxLength)?false:true;}
function formPresentationChangeMonth(){var yearelement=document.getElementById(this.id.substring(0,this.id.length-5)+'Year');var dateelement=document.getElementById(this.id.substring(0,this.id.length-5)+'Date');var dateselected=dateelement.options[dateelement.selectedIndex].value;var year=yearelement.options[yearelement.selectedIndex].value;var month=this.options[this.selectedIndex].value;var days=new Date(year,month,0).getDate();var option=document.createElement('option');option.value=0;option.innerHTML=dateelement.options[0].innerHTML;do{dateelement.removeChild(dateelement.firstChild);}while(dateelement.childNodes.length>0)
dateelement.appendChild(option);for(var day=1;day<=days;day++){var option=document.createElement('option');option.value=day;option.innerHTML=day;if(day==dateselected){option.selected=true;}
dateelement.appendChild(option);}
this.changedate();}
function formPresentationTopicSelect(){var newquestions=this.options[this.selectedIndex].value;if(newquestions.length>0){document.getElementById(this.changegroup).style.display='block';document.getElementById(this.id.substring(0,this.id.length-6)).value=this.options[this.selectedIndex].innerHTML;var questions=newquestions.split('||');var optionname=questions.shift();for(var q=0;q<this.changelabels.length;q++){document.getElementById(this.changelabels[q])
var label=document.getElementById(this.changelabels[q]);label.value="";if(typeof(label.isRequired)=='undefined'){label.isRequired=label.required;}
label.required=false;label.validate=false;var field=document.getElementById(this.changefields[q]);field.errortext="";field.value="";field.style.display="none";if(typeof(field.isRequired)=='undefined'){field.isRequired=field.required;}
field.required=false;field.validate=false;document.getElementById('fpLabel_'+this.changefields[q]).style.display="none";}
for(var q=0;q<questions.length;q++){if(questions[q].length>0&&questions[q].indexOf("|")!=-1){var qande=questions[q].split('|');var label=document.getElementById(this.changelabels[q]);label.value=qande[0];if(typeof(label.isRequired)!='undefined'){label.required=label.isRequired;label.validate=label.required?formPresentationFieldValidate:false;}
var field=document.getElementById(this.changefields[q]);field.errortext=qande[1];field.style.display="block";if(typeof(field.isRequired)!='undefined'){field.required=field.isRequired;field.validate=field.required?formPresentationFieldValidate:false;}
document.getElementById('fpLabel_'+this.changefields[q]).innerHTML=qande[0]+(field.required?this.requiredText:"");document.getElementById('fpLabel_'+this.changefields[q]).style.display="block";}}}else{document.getElementById(this.changegroup).style.display='none';}}
function formPresentationDatePickerTimes(){var dow=new Date(this.values).getDay();var child=document.getElementById(this.getAttribute('paired'));if(child!=null&&typeof(child)!="undefined"){var childselect=child.options.length>0?child.options[child.selectedIndex].value:"";var dayofweek="Sunday";switch(dow){case 0:dayofweek="Sunday";break;case 1:dayofweek="Monday";break;case 2:dayofweek="Tuesday";break;case 3:dayofweek="Wednesday";break;case 4:dayofweek="Thursday";break;case 5:dayofweek="Friday";break;case 6:dayofweek="Saturday";break;}
if(this[dayofweek]!=undefined){var childvalues=this[dayofweek].split("|");while(child.hasChildNodes()){child.removeChild(child.firstChild);}
var blankopt=document.createElement("option")
blankopt.value="";blankopt.innerHTML=child.getAttribute("default");child.appendChild(blankopt);for(var opt=0;opt<childvalues.length;opt++){var optionValue=document.createElement("option");optionValue.value=childvalues[opt];optionValue.innerHTML=childvalues[opt];if(childvalues[opt].value==childselect){optionValue.checked=true;}
child.appendChild(optionValue);}}}}
function formPresentationPairedSelect(){var parentselect=this.selectedIndex-1;if(parentselect>=0){var child=document.getElementById(this.getAttribute('paired'));if(child!=null&&typeof(child)!="undefined"){var childselect=child.options.length>0?child.options[child.selectedIndex].value:"";var childvalues=document.getElementById(this.id+'PairOptions').innerHTML.split("||")[parentselect].split("|");while(child.hasChildNodes()){child.removeChild(child.firstChild);}
var blankopt=document.createElement("option")
blankopt.value="";blankopt.innerHTML=child.getAttribute("default");child.appendChild(blankopt);for(var opt=0;opt<childvalues.length;opt++){var optionValue=document.createElement("option");optionValue.value=childvalues[opt];optionValue.innerHTML=childvalues[opt];if(childvalues[opt].value==childselect){optionValue.checked=true;}
child.appendChild(optionValue);}}}}
function formPresentationPreCheck(){this.checked=true;this.setAttribute("checked","checked");}
function formPresentationSetFullDate(setDate){var basename='';switch(this.id.substring(this.id.length-4,this.id.length)){case'Date':basename=this.id.substring(0,this.id.length-4);break;case'onth':basename=this.id.substring(0,this.id.length-5);break;case'Year':basename=this.id.substring(0,this.id.length-4);break;default:basename=this.id;break;}
var fulldate=document.getElementById(basename);var date=document.getElementById(basename+'Date');var month=document.getElementById(basename+'Month');var year=document.getElementById(basename+'Year');if(setDate&&setDate.length>0){var newDate=setDate.split("T")[0].split("-");var dateObjectArray=[year,month,date];try{for(var o=0;o<newDate.length;o++){for(var i=0;i<dateObjectArray[o].options.length;i++){if(parseInt(dateObjectArray[o].options.item(i).value.replace(/0([0-9]{1})/ig,"$1"))==parseInt(newDate[o].replace(/0([0-9]{1})/ig,"$1"))){dateObjectArray[o].selectedIndex=i;break;}}}}catch(e){}}
fulldate.value=month.options[month.selectedIndex].value+'/'+date.options[date.selectedIndex].value+'/'+year.options[year.selectedIndex].value;}
function formPresentationFormSubmit(form,callback){var result=form.onsubmit();if(result){if(typeof(callback)=='function'){callback.call(form);}else{setTimeout(function() {form.submit();}, 500);}}
return result;}
function formPresentationFormErrorSetup(thisForm){if(!document.getElementById('fpErrorhead')){errorhead=document.createElement('h2');errorhead.id='fpErrorhead';errorhead.style.display="none";errorhead.className='fpErrorTxt';errorhead.innerHTML=section.form.localization.errorHeading+':';thisForm.insertBefore(errorhead,thisForm.childNodes[2]);}else{document.getElementById("fpErrorhead").style.display="none";}
if(document.getElementById('errorTxt')){errorlist=document.getElementById('errorTxt');errorlist.style.display="none";if(errorlist.childNodes.length>0){do{errorlist.removeChild(errorlist.firstChild);}while(errorlist.childNodes.length>0)}}else{var errorlist=document.createElement('ul');errorlist.id='errorTxt';errorlist.className='fpErrorTxt';thisForm.insertBefore(errorlist,thisForm.childNodes[3]);}}
function formPresentationFormAddError(fieldName,errortext){var errorlist=document.getElementById("errorTxt");if(errorlist.innerHTML.toLowerCase().indexOf("<li>"+errortext+"</li>")==-1){var li=document.createElement('li');li.innerHTML=errortext;errorlist.appendChild(li);if(document.getElementById('fpLabel_'+fieldName)){var label=document.getElementById('fpLabel_'+fieldName);label.className+=' fpErrorLabel';}else{if(document.getElementById('fpGroup'+fieldName)){var group=document.getElementById('fpGroup'+fieldName);var labels=group.parentNode.getElementsByTagName('label');if(labels.length>0){labels[0].className+=' fpErrorLabel';}}}}}
function formPresentationFormShowErrors(){document.getElementById("fpErrorhead").style.display="block";document.getElementById("errorTxt").style.display="block";}
function formPresentationValidateField(fieldName,validationType,callback){var fields=document.getElementsByName(fieldName);for(var field=0;field<fields.length;field++){var validated=fields[field].validate?fields[field].validate(validationType):true;if(!validated)return formPresentationFieldError(fields[field].errortext,validationType);}
return validated;}
function formPresentationValidateFieldLength(fieldName,validationType,callback){var fields=document.getElementsByName(fieldName);for(var field=0;field<fields.length;field++){var validated=fields[field].maxlength?(fields[field].value.length<fields[field].maxlength?true:false):true;if(!validated)return formPresentationFieldError(fields[field].errortext,validationType);}
return validated;}
function formPresentationFieldError(errortext,errortype){var error=errortext;var errsplit=errortext.split("|");if(errsplit.length==1)return errortext;for(var e=0;e<errsplit.length;e+=2){if(errsplit[e]==errortype&&errsplit.length>e+1)return errsplit[e+1];if(errsplit[e]=="default"&&errsplit.length>e+1)error=errsplit[e+1];}
return error;}
function formPresentationFormValidate(e){var thisForm=this;if(typeof(thisForm.nodeName)=='undefined'){thisForm=this.formelement;}
formPresentationFormErrorSetup(thisForm);var errorlist=document.getElementById("errorTxt");var maxback=!!thisForm.maxlengthfields?thisForm.maxlengthfields.join("|"):null;var valback=!!thisForm.validatefields?thisForm.validatefields.join("|"):null;var reqback=!!thisForm.requiredfields?thisForm.requiredfields.join("|"):null;var errors=0;if(!!thisForm.validatefields){for(var fieldName=0;fieldName<thisForm.validatefields.length;fieldName++){validated=formPresentationValidateField(thisForm.validatefields[fieldName],"valid");if(typeof(validated)=='string'){formPresentationFormAddError(thisForm.validatefields[fieldName],validated);thisForm.maxlengthfields=thisForm.maxlengthfields.join("|").replace(thisForm.validatefields[fieldName],"").replace("||","|").split("|");thisForm.requiredfields=thisForm.requiredfields.join("|").replace(thisForm.validatefields[fieldName],"").replace("||","|").split("|");errors++;}}}
if(!!thisForm.maxlengthfields){for(var fieldName=0;fieldName<thisForm.maxlengthfields.length;fieldName++){validated=formPresentationValidateFieldLength(thisForm.maxlengthfields[fieldName],"length");if(typeof(validated)=='string'){formPresentationFormAddError(thisForm.maxlengthfields[fieldName],validated);thisForm.requiredfields=thisForm.requiredfields.join("|").replace(thisForm.maxlengthfields[fieldName],"").replace("||","|").split("|");errors++;}}}
if(!!thisForm.requiredfields){for(var fieldName=0;fieldName<thisForm.requiredfields.length;fieldName++){validated=formPresentationValidateField(thisForm.requiredfields[fieldName],"required");if(typeof(validated)=='string'){formPresentationFormAddError(thisForm.requiredfields[fieldName],validated);errors++;}}}
thisForm.requiredfields=!!reqback?reqback.split("|"):[];thisForm.validatefields=!!valback?valback.split("|"):[];thisForm.maxlengthfields=!!maxback?maxback.split("|"):[];if(errors>0){formPresentationFormShowErrors();if(e){e.returnvalue=false;document.getElementById("fpErrorhead").style.display="block";}
if(typeof(tt)!='undefined'&&typeof(tt.FormError)!='undefined'){tt.FormError(thisForm.name,errorlist.innerHTML);}
return false;}else{if(e){e.returnValue=true;formPresentationFormShowErrors();}
if(typeof(tt)!='undefined'&&typeof(tt.FormSubmit)!='undefined'){tt.FormSubmit(thisForm.name);}
return true;}}
function formPresentationFieldValidate(validationType){var emailre=new RegExp(/(^[\w\d\-\.\_\,\!\#\$\%\&\'\*\+\/\=\?\^\`\{\|\}\~]+\@([\w\d\-\_]+\.)+[\w]{2,3}$)/i);var validated=false;validationType=validationType||"both";var validateRequired=(validationType=="both"||validationType=="required");var validateValid=(validationType=="both"||validationType=="valid");if(this.required||this.validate){if(this.required&&validateRequired){switch(this.nodeName.toLowerCase()){case'textarea':case'input':switch(this.type.toLowerCase()){case'text':case'textarea':case'hidden':if(this.value.length>0){validated=true;}else{validated=(this.validate)?((this.required)?false:true):false;}
break;case'password':if(this.id.indexOf("Confirm")!=-1){validated=false;if(this.value==document.getElementById(this.id.replace("Confirm","Password")).value)validated=true;}else{if(this.value.length>0){validated=true;}else{validated=false;}}
break;case'checkbox':if(this.checked){validated=true;}else{validated=false;var checkboxgroup=document.getElementsByName(this.name);if(checkboxgroup.length>1){for(var c=0;c<checkboxgroup.length;c++){if(checkboxgroup[c].checked){validated=true;break;}}}}
break;case'radio':if(this.checked){var subfields=this.parentNode.getElementsByTagName('input');if(subfields.length>1){if(subfields[1].value.length>0){if(subfields[1].type.toLowerCase()=="text"&&subfields[1].id.indexOf("email")!=-1){validated=emailre.test(subfields[1].value);}else{validated=true;}}else{validated=false;}}else{validated=true;}}else{var radiogroup=document.getElementsByName(this.name);validated=false;for(var r=0;r<radiogroup.length;r++){if(radiogroup[r].checked){validated=true;break;}}}
break;}
break;case'select':if(this.options[this.selectedIndex].value.length>0){validated=true;}else{validated=false;}
break;}}
if(validateValid&&this.validate&&this.parameters&&this.parameters['validatepattern']){if(this.parameters['validatepattern'].display.length>0){if(this.value.length>0){vare=new RegExp(this.parameters['validatepattern'].display);validated=vare.test(this.value);}else{validated=true;}}else{validated=true;}}else if(validateValid&&this.nodeName.toLowerCase()=="input"&&this.type.toLowerCase()=="text"){if(this.id.indexOf("email")!=-1&&this.value.length>0){validated=emailre.test(this.value);}}}
return validated;}
