<script>


var __FORMCOMPONENT		=	{};
var NEW_ITEM			=	"{$language.lblNewItem}";
var lblLinkWithDatabase	=	"{$language.lblLinkWithDatabase}";
var lblPredefinedOptions=	"{$language.lblPredefinedOptions}";
var msgDeleteItem		=	"{$language.msgDeleteItem}";
var lblWarningMessage	=	"{$language.lblWarningMessage}";
var errDisableCriteria	=	"{$language.errDisableCriteria}";
var errDisableCriteriaMessage	=	"{$language.errDisableCriteriaMessage}";
var formID				= 	"{$formID}";
var editor				=	'';
var __FORM_SETTINGS,__FORMOBJECT;

/*Langauge lables*/
var lblImportPredefinedChoices = "{$language.lblImportPredefinedChoices}";



{if $formID>0}
	var __FORM_SETTINGS = 	{$__FORM_SETTINGS};
	var __FORMOBJECT	=	{$__FORMOBJECT|html_entity_decode};
	if(__FORM_SETTINGS['afterFormSubmission']=="ShowText"){
		__FORM_SETTINGS['afterFormSubmissionActionarea']=__FORM_SETTINGS['afterFormSubmissionAction'];
	}
	else{
		__FORM_SETTINGS['afterFormSubmissionActiontext']=__FORM_SETTINGS['afterFormSubmissionAction'];
	}
{/if}		
var fieldOptions = {
    "textSizes": [{
            value: "small",
            text: "{$language.lblSmall}"
        }, {
            value: "medium",
            text: "{$language.lblMedium}"
        }, {
            value: "large",
            text: "{$language.lblLarge}"
        }
    ],
	"layouts": [{
            value: "col1",
            text: "{$language.lblColumn1}"
        }, {
            value: "col2",
            text: "{$language.lblRow}"
        }
    ],
    "elemetTypes": [{
            value: "address",
            text: "{$language.lblAddressControler}"
        }, {
            value: "businesstype",
            text: "{$language.lblBusinessTypeControler}"
        }, {
            value: "checkbox",
            text: "{$language.lblCheckboxControler}"
        }, {
            value: "country",
            text: "{$language.lblCountrySelectControler}"
        }, {
            value: "countryState",
            text: "{$language.lblCountryStateControler}"
        }, {
            value: "date",
            text: "{$language.lblDateControler}"
        }, {
            value: "email",
            text: "{$language.lblEmailControler}"
        }, {
            value: "file",
            text: "{$language.lblFileUploaderControler}"
        }, {
            value: "html",
            text: "{$language.lblHtmlControler}"
        }, {
            value: "image",
            text: "{$language.lblImageUploaderControler}"
        }, {
            value: "name",
            text: "{$language.lblNameControler}"
        }, {
            value: "radio",
            text: "{$language.lblRadiobuttonControler}"
        }, {
            value: "select",
            text: "{$language.lblSelectBoxControler}"
        }, {
            value: 'select_multiple',
            text: "{$language.lblMultiselectControler}"
        }, {
            value: "text",
            text: "{$language.lblTextboxControler}"
        }, {
            value: "textarea",
            text: "{$language.lblTextareaControler}"
        }, {
            value: "website",
            text: "{$language.lblWebsiteControler}"
        }
    ],
	allowedExtensions:[
		{ 'type':'doc' },
		{ 'type':'jpg' },
		{ 'type':'gif' },
		{ 'type':'zip' },
		{ 'type':'rar' },
		{ 'type':'txt' },
		{ 'type':'png' },
		{ 'type':'xls' },
		{ 'type':'pdf' }
	],
	validate:[{
		rule:"required",
		text:"Required",
		applicable:[
			"address",
			"businesstype",
			"checkbox",
			"country",
			"state",
			'province',
			"countryState",
			'agreement',
			"date",
			"email",
			"file",
			"image",
			"name",
			"radio",
			"select",
			"select_multiple",
			"text",
			"textarea",
			"city",
			"zip",
			"website"
                        
		]
	},{
		rule:"email",
		text:"Email",
		applicable:[
			"text",
			"textarea",
			"email"
		]
	},{
		rule:"isPercentage",
		text:"Percentage",
		applicable:[
			"text"
		]
	},{
		rule:"isWholeNumber",
		text:"Whole Number",
		applicable:[
			"text"
		]
	},{
		rule:"isInteger",
		text:"Integer",
		applicable:[
			"text"
		]
	},{
		rule:"isPrice",
		text:"Price",
		applicable:[
			"text"
		]
	},{
		rule:"isNumber",
		text:"Number",
		applicable:[
			"text"
		]
	},{
		rule:"isFloat",
		text:"Float",
		applicable:[
			"text"
		]
	},{
		rule:"isLoginName",
		text:"Login Name",
		applicable:[
			"text"
		]
	},{
		rule:"isMultipleEmail",
		text:"Multiple Email",
		applicable:[
			"text",
			"textarea",
			"email"
		]
	},
	{
		rule:"isUrl",
		text:"Website",
		applicable:[
			"text",
			"textarea",
			"website"
		]
	}
      ]
};

__FORMCOMPONENT['html']={
            "type": "html",
			"name":"html",
            "group": "standard",
			"category":"html",
			"multiple":false,
            "defaults": {
                "label": "{$language.lblParagraphText}",
                "instruction": "",
				"text":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris fermentum odio sed ipsum fringilla ut tempor magna accumsan. Aliquam erat volutpat. Vestibulum euismod ipsum non risus dignissim hendrerit. Nam metus arcu, blandit in cursus nec, placerat vitae arcu. Maecenas ornare porta mi, et tincidunt nulla luctus"
            }
        };
__FORMCOMPONENT['text']={
            "type": "text",
			"name":"text",
            "caption": "{$language.lblSingleLineText}",
            "group": "standard",
			"category":"input",
			"multiple":false,
            "defaults": {
                "instruction": "",
                "tabindex": "",
				"validate":[],
				"error":"{$language.errSingleLineText}",
				"enableSearch":false,
                "limitation": 0,
                "limitMin": 0,
                "limitMax": 50,
                "limitType": 'Words',
				"showInList":true,
                "size": 'small',
                "value": ''
            }
        };
__FORMCOMPONENT['date']={
            "type": "date",
			"name":"date",
            "caption": "{$language.lbldate}",
            "group": "standard",
			"category":"input",
			"multiple":false,
            "defaults": {
                "instruction": "",
				"tabindex": "",
				"validate":[],
				"error":"{$language.errDateTime}",
				"enableSearch":false,
                "enableRageSelection": 0,
                "size": "small",
                "timeFormat": 0,
				"showInList":true,
                "dateFormat": 0,
                "yearRangeMin": "1930",
                "yearRangeMax": (new Date).getFullYear()
            }
        };	
__FORMCOMPONENT['email']={
            "type": "email",
			"name":"email",
            "caption": "{$language.lblEmail}",
            "group": "standard",
			"category":"input",
			"multiple":false,
            "defaults": {
                "instruction": "",
				"tabindex": "",
				"validate":['email'],
				"error":"{$language.errEmailAddress}",
				"enableSearch":false,
				"showInList":true,
                "noDuplicates": 0,
                "size":"small",
                "value": ""
            }
        };	
__FORMCOMPONENT['website']={
            "type": "website",
			"name":'website',
            "caption": "{$language.lblWebsite}",
            "group": "standard",
			"category":"input",
			"multiple":false,
            "defaults": {
                "instruction": "",
				"tabindex": "",
				"validate":[],
				"error":"{$language.errWebsiteAddress}",
				"enableSearch":false,
				"showInList":true,
                "noDuplicates": 0,
                "size": "small",
                "value": "http://"
            }
        };
__FORMCOMPONENT['province']={
            "type": "province",
			"name":"province",
            "caption": "{$language.lblStateProvince}",
            "group": "standard",
			"category":"input",
			"multiple":false,
            "defaults": {
                "instruction": "",
				"tabindex": "",
				"validate":[],
				"error":"{$language.errEnterProvince}",
				"enableSearch":false,
				"showInList":true,
                "noDuplicates": 0,
                "size": "small",
                "value": ""
            }
        };		
__FORMCOMPONENT['textarea']={
            "type": "textarea",
			"name":"textarea",
            "caption": "{$language.lblMultiLineText}",
            "group": "standard",
			"category":"input",
			"multiple":false,
            "defaults": {
                "instruction": "",
				"tabindex": "",
				"validate":[],
				"error":"{$language.errSingleLineTextArea}",
				"enableSearch":false,
				"showInList":true,
				"rows":4,
				"cols":100,
                "limitation": 0,
                "limitMin": 0,
                "limitMax":50,
                "limitType": "Words",
                "size": "small",
                "value": ""
            }
        };
__FORMCOMPONENT['checkbox']={
            "type": "checkbox",
			"name":"checkbox",
            "caption": "{$language.lblCheckboxes}",
            "group": "standard",
			"category":"input",
			"multiple":true,
            "defaults": {
                "instruction": "",
				"tabindex": "",
				"validate":[],
				"error":"{$language.errChoices}",
				"enableSearch":false,
				"showInList":true,
                "randomize": 0,
                "allowOther": 0,
                "layout": "col1",
                "items": [{
                        "text": "Checkbox 1",
                        "selected": true,
						"optionOrder":0
                    }, {
                        "text": "Checkbox 2",
                        "selected": false,
						"optionOrder":1
                    }, {
                        "text": "Checkbox 3",
                        "selected": false,
						"optionOrder":2
                    }
                ],
                "value": "Checkbox 1"
            }
        };

__FORMCOMPONENT['radio']={
            "type": "radio",
			"name":'radio',
            "caption": "{$language.lblMultipleChoice}",
            "group": "standard",
			"category":"select",
			"multiple":true,
            "defaults": {
                "instruction": "",
				"tabindex": "",
				"validate":[],
				"error":"{$language.errChoices}",
				"enableSearch":false,
				"showInList":true,
                "randomize": 0,
                "layout": "col1",
                "items": [{
                        "text": "{$language.lblChoice1}",
                        "selected": true,
						"optionOrder":0
                    }, {
                        "text":"{$language.lblChoice2}",
                        "selected": false,
						"optionOrder":1
                    }, {
                        "text": "{$language.lblChoice3}",
                        "selected": false,
						"optionOrder":2
                    }
                ],
                "value": "{$language.lblChoice1}"
            }
        };
__FORMCOMPONENT['select']={
		"type": "select", 
		"name": "select", 
		"caption": "{$language.lblSelectBoxControler}", 
		"group": "standard", 
		"category": "select", 
		"multiple": false, 
		"defaults": {
			"instruction": "", 
			"tabindex": "",
			"validate": [ ], 
			"error": "{$language.errChoices}", 
			"enableSearch": false, 
			"showInList": true, 
			"size": "small", 
			"items": [
				{
					"text": "{$language.lblSelect1}", 
					"selected": true, 
					"optionOrder": 0
				}, 
				{
					"text": "{$language.lblSelect2}", 
					"selected": false, 
					"optionOrder": 1
				}, 
				{
					"text": "{$language.lblSelect3}", 
					"selected": false, 
					"optionOrder": 2
				}, 
				{
					"text": "{$language.lblSelect4}", 
					"selected": false, 
					"optionOrder": 3
				}, 
				{
					"text": "{$language.lblSelect5}", 
					"selected": false, 
					"optionOrder": 4
				}
			], 
			"value": "{$language.lblSelect1}"
		}
	};
__FORMCOMPONENT['country']={
		"type": "country", 
		"name": "country", 
		"caption": "{$language.lblCountry}", 
		"group": "standard", 
		"category": "select", 
		"multiple": false, 
		"defaults": {
			"instruction": "", 
			"tabindex": "",
			"validate": [ ], 
			"error": "{$language.errSelectCountry}", 
			"enableSearch": false, 
			"showInList": true, 
			"size": "small", 
			"items": [
				{
					"text": "Select", 
					"selected": true
				}
			], 
			"value": "Afghanistan"
		}
	};
__FORMCOMPONENT['state']={
		"type": "state", 
		"name": "state", 
		"caption": "{$language.lblState}", 
		"group": "standard", 
		"category": "select", 
		"multiple": false, 
		"defaults": {
			"instruction": "", 
			"tabindex": "",
			"validate": [ ], 
			"error": "{$language.errSelectTheState}", 
			"showInList": true, 
			"size": "small", 
			"items": [
				{
					"text": "{$language.lblSelectState}", 
					"selected": true
				}
			], 
			"value": "{$language.lblSelectState}"
		}
	};
__FORMCOMPONENT['businesstype']={
		"type": "businesstype", 
		"name": "businesstype", 
		"caption": "{$language.lblMenuBusinessTypes}", 
		"group": "standard", 
		"category": "select", 
		"multiple": false, 
		"defaults": {
			"instruction": "", 
			"tabindex": "",
			"validate": [ ], 
			"error": "{$language.errSelectBusiness}", 
			"enableSearch": false, 
			"showInList": true, 
			"size": "small", 
			"items": [
				{
					"text": "{$language.lblSelectBusinessTypes}", 
					"selected": true
				}
			], 
			"value": "{$language.lblSelectBusinessTypes}"
		}
	};
__FORMCOMPONENT['select_multiple']={
		"type": "select_multiple", 
		"name": "select_multiple", 
		"caption": "{$language.lblList}", 
		"group": "standard", 
		"category": "select", 
		"multiple": false, 
		"defaults": {
			"instruction": "", 
			"tabindex": "",
			"validate": [ ], 
			"error": "{$langauge.errChoices}", 
			"enableSearch": false, 
			"showInList": true, 
			"size": "small", 
			"items": [
				{
					"text": "{$language.lblValue1}", 
					"selected": false, 
					"optionOrder": 0
				}, 
				{
					"text": "{$language.lblValue2}", 
					"selected": false, 
					"optionOrder": 1
				}, 
				{
					"text": "{$language.lblValue3}", 
					"selected": false, 
					"optionOrder": 2
				}
			], 
			"value": ""
		}
	};
__FORMCOMPONENT['name']={
		"items": [
			{
				"type": "text", 
				"name": "name", 
				"caption": "{$language.lblFirstName}", 
				"group": "standard", 
				"category": "input", 
				"multiple": false, 
				"defaults": __FORMCOMPONENT['text'].defaults
			}, 
			{
				"type": "text", 
				"name": "name", 
				"caption": "{$language.lblLastName}", 
				"group": "standard", 
				"category": "input", 
				"multiple": false, 
				"defaults": __FORMCOMPONENT['text'].defaults
			}
		]
	};	
__FORMCOMPONENT['file']={
		"type": "file", 
		"name": "file", 
		"caption": "{$language.lblFileUploaderControler}", 
		"group": "standard", 
		"category": "file", 
		"multiple": false, 
		"defaults": {
			"enableSearch": false, 
			"tabindex": "",
			"instruction": "", 
			"validate": [ ], 
			"error": "{$language.errPleaseUploadAFileType}", 
			"allowedExtensions": [
				"doc"
			], 
			"maxSize": 0, 
			"maxSizeUnit": "KB"
		}
	};	
__FORMCOMPONENT['address']={
		"address": [
			{
				"type": "text", 
				"name": "name", 
				"caption": "{$language.lblAddress1}", 
				"group": "standard", 
				"category": "input", 
				"multiple": false, 
				"defaults": __FORMCOMPONENT['text'].defaults
			}, 
			{
				"type": "text", 
				"name": "name", 
				"caption": "{$language.lblAddress2}", 
				"group": "standard", 
				"category": "input", 
				"multiple": false, 
				"defaults": __FORMCOMPONENT['text'].defaults
			}, 
			{
				"type": "text", 
				"name": "city", 
				"caption": "{$language.lblCity}", 
				"group": "standard", 
				"category": "input", 
				"multiple": false, 
				"defaults": __FORMCOMPONENT['text'].defaults
			}, 
			__FORMCOMPONENT['country'], 
			__FORMCOMPONENT['state'], 
			__FORMCOMPONENT['province'], 
			{
				"type": "text", 
				"name": "zip", 
				"caption": "{$language.lblZipcode}", 
				"group": "standard", 
				"category": "input", 
				"multiple": false, 
				"defaults": __FORMCOMPONENT['text'].defaults
			}
		]
	};	
__FORMCOMPONENT['countryState']={
		"items":[
			__FORMCOMPONENT['country'],
			__FORMCOMPONENT['state'],
			__FORMCOMPONENT['province']
		]
        };	
__FORMCOMPONENT['image']={
		"type": "image", 
		"name": "image", 
		"caption": "{$language.lblImage}", 
		"group": "standard", 
		"category": "file", 
		"multiple": false, 
		"defaults": {
			"instruction": "", 
			"tabindex": "",
			"validate": [ ], 
			"error": "Please select any image", 
			"enableSearch": false
		}
	};	
		
var controllerObject = {
    "html": {
        "type": "html",
        "template": "htmlControllerTemplate",
        "data": __FORMCOMPONENT['html']
    },
    "text": {
        "type": "text",
        "template": "textboxControllerTemplate",
        "data": $.extend(true, {}, __FORMCOMPONENT['text'])
    },
	"province": {
        "type": "text",
        "template": "textboxControllerTemplate",
		"data": __FORMCOMPONENT['province']
    },
    "textarea": {
        "type": "textarea",
        "template": "textareaControllerTemplate",
        "data": __FORMCOMPONENT['textarea']
    },
    "checkbox": {
        "type": "checkbox",
        "template": "checkboxControllerTemplate",
        "data": __FORMCOMPONENT['checkbox']
    },
	"agreement": {
        "type": "checkbox",
        "template": "agreementControllerTemplate",
        "data": __FORMCOMPONENT['agreement']
    },
    "radio": {
        "type": "radio",
        "template": "radioControllerTemplate",
        "data": __FORMCOMPONENT['radio']
    },
    "select": {
        "type": "select",
        "template": "selectControllerTemplate",
        "data": __FORMCOMPONENT['select']
    },
	"businesstype": {
        "type": "select",
        "template": "selectControllerTemplate",
        "data": __FORMCOMPONENT['businesstype']
    },
    "select_multiple": {
        "type": "select_multiple",
        "template": "listControllerTemplate",
        "data": __FORMCOMPONENT['select_multiple']
    },
    "date": {
        "type": "text",
        "template": "textboxControllerTemplate",
        "data": __FORMCOMPONENT['date']
    },
    "email": {
        "type": "email",
        "template": "textboxControllerTemplate",
        "data": __FORMCOMPONENT['email']
    },
    "website": {
        "type": "website",
        "template": "textboxControllerTemplate",
        "data": __FORMCOMPONENT['website']
    },
    "name": {
        "type": "name",
        "template": "textboxControllerTemplate",
        "data": __FORMCOMPONENT['name']
    },
    "file": {
        "type": "file",
        "template": "uploadControllerTemplate",
        "data": __FORMCOMPONENT['file']
    },
    "country": {
        "type": "select",
        "template": "countryControllerTemplate",
        "data": __FORMCOMPONENT['country']
    },
	"state": {
        "type": "select",
        "template": "selectControllerTemplate",
        "data": __FORMCOMPONENT['state']
    },
    "address": {
        "type": "select",
        "template": "addressControllerTemplate",
        "data": __FORMCOMPONENT['address']
    },
    "countryState": {
        "type": "select",
        "template": "countryStateControllerTemplate",
        "data": __FORMCOMPONENT['countryState']
    },
    "image": {
        "type": "file",
        "template": "imageControllerTemplate",
        "data": __FORMCOMPONENT['image']
    }
};

 var pre_options={
	"pre_gender":new Array(
		"{$language.lblFormMale}","{$language.lblFormFemale}","{$language.lblFormPreferNottoAnswer}"
	),
	"pre_age":new Array(
		"{$language.lblFormUnder18}","18-24","25-34","35-44",
		"45-54","55-64","{$language.lblForm65orAbove}",
		"{$language.lblFormPreferNottoAnswer}"
	),
	"pre_employment":new Array(
		"{$language.lblFormEmployedFullTime}","{$language.lblFormEmployedPartTime}",
		"{$language.lblFormSelfemployed}","{$language.lblFormNotemployedbut}",
		"{$language.lblFormNotEmployed}","{$language.lblFormHomemaker}",
		"{$language.lblFormRetired}","{$language.lblFormStudent}","{$language.lblFormPreferNottoAnswer}"
	),
	"pre_education":new Array(
		"{$language.lblFormSomeHighSchool}","{$language.lblFormHighSchoolGraduateEquivalent}",
		"{$language.lblFormTradeVocationalDegree}","{$language.lblFormSomeCollege}",
		"{$language.lblFormAssociateDegree}","{$language.lblFormBachelorsDegree}",
		"{$language.lblFormGraduateProfessionalDegree}","{$language.lblFormPreferNottoAnswer}"
	),
	"pre_marital":new Array(
		"{$language.lblFormSingleNeverMarried}","{$language.lblFormMarried}",
		"{$language.lblFormLivingwithPartner}","{$language.lblFormSeparated}",
		"{$language.lblFormDivorced}","{$language.lblFormWidowed}","{$language.lblFormPreferNottoAnswer}"
	),
	"pre_race":new Array(
		"{$language.lblFormWhiteCaucasian}","{$language.lblFormSpanishHispanicLatino}",
		"{$language.lblFormBlackAfricanAmerican}","{$language.lblFormAsian}",
		"{$language.lblFormPacificIslander}","{$language.lblFormNativeAmerican}",
		"{$language.lblFormOther}","{$language.lblFormPreferNottoAnswer}"
	),
	"pre_months":new Array(
		"{$language.lblFormJanuary}","{$language.lblFormFebruary}","{$language.lblFormMarch}","{$language.lblFormApril}","{$language.lblFormMay}","{$language.lblFormJune}","{$language.lblFormJuly}","{$language.lblFormAugust}","{$language.lblFormSeptember}","{$language.lblFormOctober}","{$language.lblFormNovember}","{$language.lblFormDecember}"
	),
	"pre_days":new Array(
		"{$language.lblFormMonday}","{$language.lblFormTuesday}","{$language.lblFormWednesday}","{$language.lblFormThursday}","{$language.lblFormFriday}","{$language.lblFormSaturday}","{$language.lblFormSunday}"
	),
	"pre_continents":new Array(
		"{$language.lblFormAfrica}","{$language.lblFormAntarctica}","{$language.lblFormAsia}","{$language.lblFormAustralia}","{$language.lblFormEurope}","{$language.lblFormNorthAmerica}","{$language.lblFormSouthAmerica}"
	),
	"pre_howoften":new Array(
		"{$language.lblFormEveryday}","{$language.lblFormOnceweek}","{$language.lblForm2timesMonth}","{$language.lblFormOnceMonth}","{$language.lblFormLessthanOnceMonth}"
	),
	"pre_howlong":new Array(
		"{$language.lblFormLessThanMonth}","{$language.lblForm16months}","{$language.lblForm13years}","{$language.lblFormOver3Years}","{$language.lblFormNeverused}"
	),
	"pre_satisfied":new Array(
		"{$language.lblFormVerySatisfied}","{$language.lblFormSatisfied}","{$language.lblFormNeutral}","{$language.lblFormUnsatisfied}","{$language.lblFormVeryUnsatisfied}"
	)
	
};
{if $formID>0}
	var html="";
	for(key in __FORMOBJECT){
		var element		=	__FORMOBJECT[key];
		var elementType	=	element['data']['type'];
		if(typeof element['data']['defaults']!='undefined'){ 
			var validateRule=	element['data']['defaults']['validate'];
			if(typeof validateRule=='undefined'){
				element['data']['defaults']['validate']=[];
			}
		}
		var templateID	=	controllerObject[elementType].template;
		var data		=	element['data'];
		var extradata	=	new Object();
		extradata.uniqueID=element['uniqueID'];
		extradata.elementType=element['elementType'];
		html+='<li class="sub clearfix ui-draggable formElement " data-controller="'+elementType+'" style="display: block;" uniqueid="'+element['uniqueID']+'" rel="fieldSettings">'+$( "#"+templateID).render( data,extradata )+'</li>';
		
	}
	$("#dynamicForm").html(html);
	addLiClass();
{/if}

function addLiClass(){
	if(__FORM_SETTINGS['fieldAlignment']=="frm-style01" || __FORM_SETTINGS['fieldAlignment']=="frm-style03"){
				$(".element-three").remove();
				$("#dynamicForm li").removeClass('odd')
				$("#dynamicForm li").removeClass('even')
				$("#dynamicForm li").each(function(index){
					if(index%2){
						$(this).addClass('even');
						$(this).after('<li class="element-three ui-disabled clearfix"></li>');
					}
					else{
						$(this).addClass('odd');
					}
				});
			}
			else{
				$(".element-three").remove();
				$("#dynamicForm li").each(function(){
					$(this).after('<li class="element-three ui-disabled clearfix"></li>');
				});
			}
}	

</script>