﻿
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2011 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*
* $DateTime:  $
*
* Adobe Output Module 4.0
*
* MediaGallery Originally Written by Quality Process Incorporated, Enhanced by
* Adobe Systems China. Contact Sheet written by Adobe Systems China.
* 
*
**************************************************************************/

AOM.CS.hasValid = true;

////////////////////////////////////////////////////////////////////////////////////
AOM.CSManager = function() {}
//designwindow class
AOM.CSManager.DesignWindow = function(container, tabbedPalette) {
	var content = tabbedPalette.content;
	this.currentDocument = content.document;
	
	var buildPDFStatEle = AOM.StartupTimes.findElement("ContentOnResize.BuildUIStack.BuildPDF");
	AOM.StartupTimes.start("CreateUI", buildPDFStatEle);
	this.create(container, tabbedPalette);
	AOM.StartupTimes.end("CreateUI", buildPDFStatEle);
	
	AOM.StartupTimes.start("Initialize", buildPDFStatEle);
	this.initialize();
	AOM.StartupTimes.end("Initialize", buildPDFStatEle);
	
	AOM.StartupTimes.start("ApplyTheme", buildPDFStatEle);
	AOM.theme(this.currentDocument).applyTheme(container, true);
	AOM.StartupTimes.end("ApplyTheme", buildPDFStatEle);
};



AOM.CSManager.DesignWindow.prototype.create = function(container, tabbedPalette) {
	this.CSGroup = container;
	
	// According drawerType, set current drawer style.
	var drawerType = AOM.BridgePreferences.getDrawerType();
	var currentDocument = this.currentDocument;
	
	var foldableSet;
	var customPanel = new AOM.CustomPanel(this.CSGroup);

	if (drawerType == AOM.BridgePreferences.DRAWER_TYPE_CABINET) {
		this.pdfTemplates = customPanel.addHeaderSection(AOM.CS.pdfTemplateResource, "pdfTemplate", "bottom");

		foldableSet = customPanel.addCabinetSection();
		// Write foldableSet onClickFoldableSection callback
		foldableSet.onClickFoldableSection = function(openCloseButton) {
			AOM.userInput(currentDocument).set(openCloseButton.name, openCloseButton.isOpen);
		}
	} else if (drawerType == AOM.BridgePreferences.DRAWER_TYPE_ACCORDION) {
		this.pdfTemplates = customPanel.addHeaderSection(AOM.CS.pdfTemplateResource, "pdfTemplate");

		foldableSet = customPanel.addAccordionSection();
		// Write foldableSet onClickFoldableSection callback
		foldableSet.onClickFoldableSection = function(openCloseButton) {
			var selectedSection = this.getSelectedSectionByName(openCloseButton.name);
			AOM.userInput(currentDocument).set("pdfselectedSection", selectedSection);
		}

		// Set open/close status
		var selectedSection = AOM.userInput(currentDocument).get("pdfselectedSection");
		if (selectedSection == undefined || selectedSection.length == 0) {
			customPanel.accordionSection.selectedSection = "Document";
		} else {
			customPanel.accordionSection.selectedSection = selectedSection;
		}

	} else {
    	throw new Error("AOM.CSManager.DesignWindow.create() throw an exception, not implement the type of drawer:" + drawerType);
	}

    this.documents = foldableSet.addFoldableSection(AOM.CS.documentResource, "Document", AOM.localize("$$$/ContactSheet/javascript/title/document=Document"));	
    this.layouts = foldableSet.addFoldableSection(AOM.CS.layoutResource, "Layout", AOM.localize("$$$/ContactSheet/javascript/title/layout=Layout"));		
    this.overlays = foldableSet.addFoldableSection(AOM.CS.overlaysResource, "Overlays", AOM.localize("$$$/ContactSheet/javascript/title/overlays=Overlays"));
    this.header = foldableSet.addFoldableSection(AOM.CS.headerResource, "Header", AOM.localize("$$$/ContactSheet/javascript/title/header=Header"));
    this.footer = foldableSet.addFoldableSection(AOM.CS.footerResource, "Footer", AOM.localize("$$$/ContactSheet/javascript/title/footer=Footer"));
    this.playbacks = foldableSet.addFoldableSection(AOM.CS.playbackResource, "Playback", AOM.localize("$$$/ContactSheet/javascript/title/playback=Playback"));
    this.watermarks = foldableSet.addFoldableSection(AOM.CS.watermarkResource, "Watermark", AOM.localize("$$$/ContactSheet/javascript/title/watermark=Watermark"));

    this.savePdfs = customPanel.addFooterSection(AOM.CS.savePdfResource, "savePdfs", "top");
    this.CSGroup.layout = new AOM.CustomPanelLayoutManager(this.CSGroup);
}


AOM.CSManager.DesignWindow.prototype.initialize = function() {
	var currentDocument = this.currentDocument;
	
	var initialStatEle = AOM.StartupTimes.findElement("ContentOnResize.BuildUIStack.BuildPDF.Initialize");
	AOM.StartupTimes.start("LoadData", initialStatEle);
	this.loadData(this.CSGroup, AOM.userInput(currentDocument), AOM.theme(currentDocument));
	AOM.StartupTimes.end("LoadData", initialStatEle);
	
	AOM.StartupTimes.start("LoadSpecialData", initialStatEle);
	this.loadSpecialData(true);	
	AOM.StartupTimes.end("LoadSpecialData", initialStatEle);
	
	AOM.StartupTimes.start("InitEventHandler", initialStatEle);
	this.initEventHandlers();
	AOM.StartupTimes.end("InitEventHandler", initialStatEle);
};


AOM.CS.Paths.userTemplate = Folder.userData + "/Adobe/Bridge " + AOM.CS_VERSION + "/Adobe Output Module/UserTemplate/ContactSheet/";

AOM.CSManager.DesignWindow.prototype.reloadTemplate = function(userInput, bySelect)
{
    var templateDropDown = this.pdfTemplates.columngrp.tgrp.template;
	var value = userInput.get("template");
	var defaultItems = AOM.CS.UIUtils.getItemListByDefaultItems("template");
	
	
	var realItems = new Array();
	if (value == AOM.CSConstant.CUSTOM) {
		var customItem = {};
		customItem.value = AOM.CSConstant.CUSTOM;
		customItem.text = userInput.get("template_display");
		realItems.push(customItem);
		var separator = {};
		separator.value = "-";
		realItems.push(separator);
	}
	
	var templateFolder = new Folder(AOM.CS.Paths.userTemplate);
	var files = templateFolder.getFiles();
	var templateNumber = 0;
	for (var j = 0; j < files.length; j++) {
		if (files[j].name.substr(files[j].name.length - 5, 5) == ".json") {
			var customTemplate = {};
			customTemplate.value = File.decode(files[j].name.substr(0, files[j].name.length - 5));
			customTemplate.text = File.decode(files[j].name.substr(0, files[j].name.length - 5));
			realItems.push(customTemplate);
			templateNumber++;
		}
	}
	if (templateNumber > 0) {
		var separator2 = {};
		separator2.value = "-";
		realItems.push(separator2);
	}
	
	for (var j = 0; j < defaultItems.length; j++) {
		if (defaultItems[j].value != AOM.CSConstant.CUSTOM)
			realItems.push(defaultItems[j]);
	}
	
	var oldHasProgramInteract = AOM.CS.UIUtils.blockDropDownListEvent();
	
	templateDropDown.removeAll();
	AOM.CS.UIUtils.addDropDownListItems(templateDropDown, realItems);
	
	if(!bySelect) {
		AOM.CS.UIUtils.setDropDownListSelection(templateDropDown, value, true);
		var newValue = templateDropDown.selection.value;
		if (newValue != value) {
			templateDropDown.add("separator", "", 0);
			var newItem = templateDropDown.add("item", AOM.CSConstant.CUSTOM, 0);
			newItem.value = AOM.CSConstant.CUSTOM;
			templateDropDown.selection = newItem;
		}
		value = templateDropDown.selection.value;
		this.setButtons(value);
		userInput.setElement(templateDropDown);
		AOM.CS.UIUtils.unblockDropDownListEvent(oldHasProgramInteract);
	} else {
		var items = templateDropDown.items;
		var i;
		for (i = 0; i < items.length; i++) {
			if (items[i].value == value) {
				templateDropDown.selection = items[i];
				break;
			}
		}
		if (i == items.length) {
			templateDropDown.selection = items[0];
		}
		if (templateDropDown.selection.value != AOM.CSConstant.CUSTOM) {
			var max = templateDropDown.items.length;
			for (var i = 0; i < max; i++) {
				value = templateDropDown.selection.value;
				userInput.setElement(templateDropDown);
				AOM.CS.UIUtils.unblockDropDownListEvent(oldHasProgramInteract);
				var result = templateDropDown.onChange(true);
				oldHasProgramInteract = AOM.CS.UIUtils.blockDropDownListEvent();
				if (result != "fail") {
					break;
				} else {
					templateDropDown.selection = templateDropDown.items[0];
				}
			}
		}
		AOM.CS.UIUtils.unblockDropDownListEvent(oldHasProgramInteract);
	}
	return value;
}

AOM.CSManager.DesignWindow.prototype.setButtons = function(value)
{
	var saveButton = this.pdfTemplates.columngrp.tgrp.templateSaveBtn;
	var deleteButton = this.pdfTemplates.columngrp.tgrp.templateDeleteBtn;
	
	if (value == AOM.CSConstant.CUSTOM) {
		saveButton.gsEnabled = saveButton.enabled = true;
		deleteButton.gsEnabled = deleteButton.enabled = false;
	} else {
		saveButton.gsEnabled = saveButton.enabled = false;
		if (AOM.CSConstant.isPreset[value] != undefined) {
			deleteButton.gsEnabled = deleteButton.enabled = false;
		} else {
			deleteButton.gsEnabled = deleteButton.enabled = true;
		}
	}
}

AOM.CSManager.DesignWindow.prototype.updateTemplate = function(document)
{
	if (AOM.latestDocumentId == document.id) {
		return;
	}
	var userInput = AOM.userInput(document);
	this.reloadTemplate(userInput, true);
}


AOM.CSManager.DesignWindow.prototype.loadData = function(group, userInput, theme, enabled) {
	for (var i = 0; i < group.children.length; ++i) {
		var child = group.children[i];
		
		var type = child.themeType ? child.themeType.toLowerCase() : 
				   (child.type ? child.type.toLowerCase() : "unknown");
		
		var status = enabled;
		if (child.enableParent != undefined && child.equalToParent != undefined) {
			// Override parents' enableParent.
			status = AOM.CS.UIUtils.getEnableStatus(child, userInput);
		}

		if (type == "group" || type == "panel") {
			this.loadData(child, userInput, theme, status);
		} else {
			var name = child.name;
			if (name != undefined) {
				var value =userInput.get(child.name);
				if (value == undefined) { value = ""; }
				
				switch(type) {
				case "checkbox" :
					child.value = AOM.CS.CString.strToBoolean(value);
					break;
				case "customcheckbox" :
                        child.checked = AOM.CS.CString.strToBoolean(value);
						var wrappedObject = new AOM.CustomCheckbox(child);
				case "edittext" :
					if (child.dataType == "UnitFloat") {
						child.value = AOM.CS.Locale.parseFloat(value);
						child.text = AOM.CS.UIUtils.getUnitDisplayText(value, userInput.get("pageUnit"));
						userInput.setElement(child);
					} else {
						child.value = value;
						child.text = value;
					}
					break;
				case "sdropdownlist" :
				case "dropdownlist" :
					var refParent = child.refParent;
					if (refParent == undefined) {
						var newItems = AOM.CS.UIUtils.getItemListByDefaultItems(name);
						if (newItems != undefined && newItems.length > 0) {
							var selectedValue;
							if (child.items.length <= 0) {
								if (name == "template") {
									selectedValue = this.reloadTemplate(userInput, false);
								} else {
									selectedValue = AOM.CS.UIUtils.setDropDownList(child, newItems, value, true);
								}
							} else {
								selectedValue = AOM.CS.UIUtils.setDropDownListSelection(child, value, true);
								if (name == "template")
									this.setButtons(selectedValue);
							}						
							if (selectedValue != value) {userInput.set(name, selectedValue); }
						}
					} else {
						
						var refParentName = userInput.get(refParent);
						var newItems = AOM.CS.UIUtils.getItemListByDefaultItems(name, refParentName);	
						
						if (newItems != undefined && newItems.length > 0) {		
							var oldValue = undefined;
							if (child.selection != undefined) {		
								oldValue = child.selection.value;
							}
							if (oldValue == undefined || oldValue != value) {
								AOM.CS.UIUtils.setDropDownList(child, newItems, value, true);
								userInput.setElement(child);
							} 
						} else {
							status = false;
						}
					}
					break;
				case "imagebutton" :
					child.btPressed = AOM.CS.CString.strToBoolean(value);
					child.notify("onDraw");
					var wrappedObject = new AOM.CustomIconButton(child);
					break;
				case "button":
					break;
				case "colorpnl" :
				    var rgb;
				    if (value == "") {
                        rgb = [1, 1, 1];
                        userInput.set(child.name, rgb.toSource());
                    } else {
                        rgb = eval(value);
                    }                
					var gfx = child.graphics;
					gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, rgb);	
					child.notify("onDraw");
					break;
				case "statictext" :
					var refParent = child.refParent;
					if (refParent != undefined) {
						var refParentValue = userInput.get(refParent);
						var unitText = AOM.CS.UIUtils.getUnitText(refParentValue);
						child.text = unitText;
					}
					break;
				case "openclosebtn" :
					/* If the drawer type is "accordion", don't use the "value"
					 * to change "isOpen", because the "value" is used for "cabinet"
					 * only. */
					if(app.preferences.aomDrawerType == AOM.BridgePreferences.DRAWER_TYPE_ACCORDION)
						break;

					if(value == "true" || value == true) {
						child.isOpen = true;
					} else {
						child.isOpen = false;
					}
					break;
				case "hslider" :
				    if (value == "" || value == NaN) {
				        value = child.value;
				        userInput.set(child.name, value);
                    }
					var parent = child.parent;
					if (child.refControl == undefined || !child.refControl instanceof AOM.AmgNumericStepper) {
						child.refControl =  new AOM.AmgNumericStepper(child);
					}
					child.refControl.setValue(parseFloat(value));
					break;
				case "radiobutton" : 
					if (value.toString() == "") {
                        value = child.checked;
                        userInput.set(child.name, value);
					}
					child.value = AOM.CS.CString.strToBoolean(value);
					break;
                  case "customradiobutton" :
                      if (value.toString() == "") {
                          value = AOM.CS.CString.strToBoolean(child.checked);
                          userInput.set(child.name, value);
                          child.value = value;
                      } else {
                           child.value = AOM.CS.CString.strToBoolean(value);
                      }
                      var wrappedObject = new AOM.CustomRadioButton(child);
                      break;
				case "sysfontgroup" :
					if (child.helper == undefined) {
						child.helper = new AOM.SysFontGroupHelper(child, userInput, true, this.currentDocument);
						child.helper.createUI();
					} else {
						child.helper.refreshValues();
					}
					break;
				case "syscolorgroup" :
					if (child.helper == undefined) {
						child.helper = new AOM.SysFontGroupHelper(child, userInput, true);
						child.helper.createColorUI();
					} else {
						child.helper.refreshValues();
					}
					break;
				case "dialgroup":
					if (child.dialGroup == undefined) {
						child.dialGroup = new AOM.DialGroup(child);
					}
					child.dialGroup.setValue(userInput.get(child.dialGroup.getName()));
					break;
				default:
					break;
				}
			
				
				// Set status for ctrls
				AOM.CS.UIUtils.setEnabledStatus(child, status, theme);
			}
		}
	}
}

/****
 *  Function loadSpecialData() is invoked in two cases, the AOM being started and
 *  the template of PDF being changed. In the first case, the font dropdown list
 *  must not be fully initialized by loading all system fonts in order to reduce
 *  startup time. In the second case, the list could be fully initialized. Parameter
 *  _lazy_ is used to distinguish the two cases.
 */
AOM.CSManager.DesignWindow.prototype.loadSpecialData = function(lazy) {
	var pdfTemplates = this.pdfTemplates;
	var currentDocument = this.currentDocument;
	
	
	// Process pdfTemplates.
	var currentTemplate = pdfTemplates.columngrp.tgrp.template;
	var currentSelectedTemplate = AOM.userInput(currentDocument).get(currentTemplate.name);
	if (currentSelectedTemplate != AOM.CSConstant.CUSTOM) {
		var theSelection = currentTemplate.selection;
		var oldHasProgramInteract = AOM.CS.UIUtils.blockDropDownListEvent();
		var hasCustom = false;
		//remove custom item.
		for (var i = 0; i < currentTemplate.items.length; i++) {
			var currentItem = currentTemplate.items[i];
			if (currentItem.value == AOM.CSConstant.CUSTOM) {
				currentTemplate.selection = currentTemplate.items[i];
				AOM.CS.UIUtils.removeDropDownListItem(currentTemplate, currentItem);
				hasCustom = true;
				break;
			}
		}
		
		if(hasCustom) {
			for (var i = 0; i < currentTemplate.items.length; i++) {
				var currentItem = currentTemplate.items[i];
				if (currentItem.type == "separator") {
					AOM.CS.UIUtils.removeDropDownListItem(currentTemplate, currentItem);
					break;
				}
			}
		}
		currentTemplate.selection = theSelection;
		AOM.CS.UIUtils.unblockDropDownListEvent(oldHasProgramInteract);
	}
}

AOM.CS.UIUtils.getEnableStatus = function(ele, userInput) {
	if(ele && ele.enableParent && ele.equalToParent) {
		var enableParents = ele.enableParent.split(",");
		var equalToParents = ele.equalToParent.split(",");
		
		var isTrue = function(value) {
			ret = true;
			if (value == undefined || value.toString().toLowerCase() == "false" || 
				value.toString().toLowerCase() == "none" ||
				value.toString().toLowerCase() == "undefined")
				ret = false;
			return ret;
		}
		
		var enabled = true;
		for(var i=0; i<enableParents.length; ++i) {
			var epivalue = userInput.get(enableParents[i]);	
			if(isTrue(epivalue) != isTrue(equalToParents[i])) {
				enabled = false;
				break;
			}
		}
		return enabled;
	} 
}

AOM.CS.UIUtils.setEnabledStatus = function(child, enabled, theme) {
	if (undefined == child || undefined == enabled || undefined == child.type) return;
	
	var type = child.type.toLowerCase();
	switch(type) {
		case "group":
			for (var i = 0; i < child.children.length; ++i) {
				AOM.CS.UIUtils.setEnabledStatus(child.children[i], enabled, theme);
			}
			break;
		case "edittext":
			child.gsEnabled = child.enabled = enabled;

			 // Workaround:
			 //	 Set edittext control's disabled theme explicitly
			 //  for its onDraw callback function cannot be overwritted.
			theme.setEditTextDisableBgColor(child);
			break;
		default:
			child.gsEnabled = child.enabled = enabled;
			break;
	}
}

AOM.CS.UIUtils.getUnitText = function(spaceToUnit) {
	var spaceUnitValue;
	if (spaceToUnit == AOM.CSConstant.UNIT_INCHES) {
		spaceUnitValue = AOM.CSConstant.UNIT_INCHES_ABBR;
	} else if (spaceToUnit == AOM.CSConstant.UNIT_PIXELS) {
		spaceUnitValue = AOM.CSConstant.UNIT_PIXELS_ABBR;
	} else {
		spaceUnitValue = AOM.CSConstant.UNIT_CENTIMETERS_ABBR;
	}

	return spaceUnitValue;
}


AOM.CSManager.DesignWindow.prototype.initEventHandlers = function() {
	var currentDocument = this.currentDocument;
	
	this.initBasicEventHandler(this.CSGroup, currentDocument);
	this.initPdfTemplatesEventHandlers();
	this.initDocumentEventHandlers();
	this.initLayoutEventHandlers();
	this.initHeaderEventHandlers();
	this.initFooterEventHandlers();
	this.initOverlaysEventHandlers();
	this.initPlaybackEventHandlers();
	this.initWatermarksEventHandlers();
	this.initPDFGenerationEventHandlers();
	this.initKeyboardEventListener();
}


AOM.CSManager.DesignWindow.prototype.initBasicEventHandler = function(group, currentDocument) {
	var pdfTemplates = this.pdfTemplates;
		
	for (var i = 0; i < group.children.length; i++) {
		var child = group.children[i];	
		var type = child.type;
		if (child.themeType != undefined)  {type = child.themeType;}
		if (type != undefined) type = type.toLowerCase();
		
		if (type == "group" || type == "panel") {
			this.initBasicEventHandler(child, currentDocument);
		} else {
			if (child.name != undefined) {
				var name = child.name;

				switch(type) {
				case "checkbox":
					child.onClick  = function() {
						AOM.userInput(currentDocument).setElement(this);
						//change template
						AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
					}
					break;
                  case "customcheckbox" :
						child.onMouseDown = function() {
							AOM.userInput(currentDocument).setElement(this);
							//change template
                            AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
                        }
				case "edittext":
					child.onChange = function() {
						this.value = this.text;
						if (AOM.userInput(currentDocument).isValid(this.name, this.text)) {
							AOM.userInput(currentDocument).setElement(this);
							AOM.CS.hasValid = true;
						} else {
							var oldText = AOM.userInput(currentDocument).get(this.name);
							if (oldText == undefined)
								oldText = '';
							this.text = oldText;
							AOM.CS.hasValid = false;
						}
					}
					break;
				case "sdropdownlist":
				case "dropdownlist":
					child.onChange = function() {
						AOM.userInput(currentDocument).setElement(this);
					}
					break;
				case "hslider":
					var control = child.refControl;
					if (control != undefined && control instanceof AOM.AmgNumericStepper) {
						control.onChange = function() {
							AOM.userInput(currentDocument).set(name, this.value);
							//change template
							AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
						}
					}
					break;
				case "radiobutton":
					child.onClick = function() {
						AOM.userInput(currentDocument).setElement(this);
						//change template
						AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
					}
					break;
                  case "customradiobutton" :
                    child.onMouseDown = function() {
						AOM.userInput(currentDocument).setElement(this);
						//change template
						AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
					}
                    break;
				case "sysfontgroup":
					var changeTempFunc = function(event, target) {
						//change template
						AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
					}
					child.helper.onFontFamilyChange = changeTempFunc;
					child.helper.onFontFaceChange = changeTempFunc;
					child.helper.onFontSizeChange = changeTempFunc;
					child.helper.onFontColorChange = changeTempFunc;
					child.helper.onFontColorPickerChange = changeTempFunc;
					break;
				case "dialgroup":
					child.dialGroup.onChange = function() {
						AOM.userInput(currentDocument).set(this.getName(), this.getValue());
						//change template
						AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
					}
					break;
				case "syscolorgroup" :
					var changeTempFunc = function(event, target) {
						//change template
						AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
					}
					child.helper.onFontColorChange = changeTempFunc;
					child.helper.onFontColorPickerChange = changeTempFunc;
					break;
				default:
					break;
				}
			}
		}
	}
}

AOM.CSManager.DesignWindow.prototype.initKeyboardEventListener = function() {
	var layoutLayer = this.layouts;
	var docLayer = this.documents;
	var playbackLayer = this.playbacks;
	var headerLayer = this.header;
	var footerLayer = this.footer;
	
	docLayer.wgrp.grp.pageWidth.addEventListener('keydown',  AOM.Keyboard.nonNegativeRealEditText);
	docLayer.hgrp.grp.pageHeight.addEventListener('keydown',  AOM.Keyboard.nonNegativeRealEditText);
	
	var layoutgrp = layoutLayer.grp.layoutgrp;
	var margingrp = layoutLayer.grp.margingrp;	
	
	layoutgrp.setRow.pageRows.addEventListener('keydown', AOM.Keyboard.nonNegativeIntegerEditText);
	layoutgrp.setCol.pageColumns.addEventListener('keydown', AOM.Keyboard.nonNegativeIntegerEditText);
	
	layoutgrp.horizontal.setVal.horizontalSpacing.addEventListener('keydown',  AOM.Keyboard.nonNegativeRealEditText);
	layoutgrp.vertical.setVal.verticalSpacing.addEventListener('keydown',  AOM.Keyboard.nonNegativeRealEditText);

	margingrp.setTop.topMargin.addEventListener('keydown',  AOM.Keyboard.nonNegativeRealEditText);
	margingrp.setBottom.bottomMargin.addEventListener('keydown',  AOM.Keyboard.nonNegativeRealEditText);
	margingrp.setLeft.leftMargin.addEventListener('keydown',  AOM.Keyboard.nonNegativeRealEditText);
	margingrp.setRight.rightMargin.addEventListener('keydown',  AOM.Keyboard.nonNegativeRealEditText);
	
	headerLayer.grp2.bottomGrp.disGrp.headerDistance.addEventListener('keydown',AOM.Keyboard.nonNegativeRealEditText);
	footerLayer.grp2.bottomGrp.disGrp.footerDistance.addEventListener('keydown',AOM.Keyboard.nonNegativeRealEditText);
	
	playbackLayer.selects.advances.advanceSeconds.addEventListener('keydown',  AOM.Keyboard.nonNegativeIntegerEditText);	
}

AOM.CSManager.DesignWindow.deleteSeparator = function(dropdown)
{
	if (dropdown.items[0].value == AOM.CSConstant.CUSTOM) {
		if (dropdown.items[2].type == "separator")
			dropdown.remove(2);
	}
}

AOM.CSManager.DesignWindow.prototype.initPdfTemplatesEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var layoutLayer = this.layouts;
	var docLayer = this.documents;
	var playbackLayer = this.playbacks;
	var watermarks = this.watermarks;
	var currentDocument = this.currentDocument;
	var theTemplates = pdfTemplates.columngrp.tgrp.template;
	var saveButton = pdfTemplates.columngrp.tgrp.templateSaveBtn;
	var deleteButton = pdfTemplates.columngrp.tgrp.templateDeleteBtn;
	var that = this;
	
	var aRefreshPreview = pdfTemplates.columngrp.refreshgrp.refreshPreview;
	aRefreshPreview.onClick = function() {
		if (!AOM.CS.UIUtils.checkEditTextValidOnMac()) {return;}
		
		//check preview palette has initialized.
		AOM.PreviewPanel.checkPreviewPalette(currentDocument);
        			
		//after
		var pdfMaker = new AOM.CS.PDFMaker(currentDocument);
		var anyError = pdfMaker.generatePDF(true);
		AOM.CSManager.DesignWindow.processPDFGenerationError(anyError);
		pdfMaker.destroy();
	}

	var designWindow = this;
	theTemplates.onChange = function(changedByDelete) {
		var userInput = AOM.userInput(currentDocument);
		if (AOM.CS.hasProgramInteract) {
			userInput.setElement(this);
		} else {
			if (this.selection != undefined) {
				var newTemplate = this.selection;
				var oldTemplate = userInput.get("template");
				userInput.setElement(this);
			
				var currentTemplate = this.selection.value;
				if (currentTemplate == AOM.CSConstant.CUSTOM) return ;
				
				var templatePath;
				var isPreset = true;
				if (AOM.CSConstant.isPreset[currentTemplate] != undefined) {
					templatePath = AOM.CS.Paths.customTemplate + currentTemplate + ".json";
				} else {
					isPreset = false;
					templatePath = AOM.CS.Paths.userTemplate + currentTemplate + ".json";
				}
				
				var defaultFile = new File(AOM.CS.Paths.commonTemplateData);
				var templateFile = new File(templatePath);

				if (!templateFile.open("r") || !defaultFile.open("r")) {
					AOM.CS.UIUtils.removeDropDownListItem(this, this.selection);
					AOM.CSManager.DesignWindow.deleteSeparator(this);
					if(this.items[0].type == "separator")
						this.remove(0);
					if (changedByDelete != true) {
						AOM.CS.UIUtils.setDropDownListSelection(this, oldTemplate, true);
						AOM.alert(AOM.localizeWithArgs("$$$/ContactSheet/javascript/template/cannotLoadTemplate=Can not load the template file caused by system error."));
					}
					return "fail";
				} else {
					templateFile.seek(6,2);
					var end = templateFile.readln();
					templateFile.seek(4,2);
					var end2 = templateFile.readln();
					if (isPreset == false && end != "];" && end2 != "];") {
						templateFile.close();
						templateFile.remove();
						AOM.CS.UIUtils.removeDropDownListItem(this, this.selection);
						AOM.CSManager.DesignWindow.deleteSeparator(this);
						if(this.items[0].type == "separator")
							this.remove(0);
						if (changedByDelete != true) {
							AOM.CS.UIUtils.setDropDownListSelection(this, oldTemplate, true);
							AOM.alert(AOM.localizeWithArgs("$$$/ContactSheet/javascript/template/loadTemplateError=Can not load the template file because the file is broken."));
						}
						return "fail";
					}
					templateFile.seek(0);
					var jsonDefault = defaultFile.read();
	                defaultFile.close();
	                try {
	                	eval(jsonDefault);
					} catch (e) {
						AOM.alert(AOM.localizeWithArgs("$$$/ContactSheet/javascript/template/cannotLoadTemplate=Can not load the template file caused by system error."));
						return "fail";
					}
					
	                var defaultData = AOM.CS.UserInput.persistedData;
	                
	                var jsonTemplate = templateFile.read();
					templateFile.close();
					try{
						eval(jsonTemplate);
					} catch (e) {
						templateFile.remove();
						AOM.CS.UIUtils.removeDropDownListItem(this, this.selection);
						AOM.CSManager.DesignWindow.deleteSeparator(this);
						if(this.items[0].type == "separator")
							this.remove(0);
						if (changedByDelete != true) {
							AOM.CS.UIUtils.setDropDownListSelection(this, oldTemplate, true);
							AOM.alert(AOM.localizeWithArgs("$$$/ContactSheet/javascript/template/loadTemplateError=Can not load the template file because the file is broken."));
						}
						return "fail";
					}
					var templateData = AOM.CS.UserInput.persistedDataTemplate;
					
					if (templateData == undefined || templateData.length <=0) {
						templateFile.remove();
						AOM.CS.UIUtils.removeDropDownListItem(this, this.selection);
						AOM.CSManager.DesignWindow.deleteSeparator(this);
						if(this.items[0].type == "separator")
							this.remove(0);
						if (changedByDelete != true) {
							AOM.CS.UIUtils.setDropDownListSelection(this, oldTemplate, true);
							AOM.alert(AOM.localizeWithArgs("$$$/ContactSheet/javascript/template/loadTemplateError=Can not load the template file because the file is broken."));
						}
						return "fail";
					} else{
						var theme = AOM.theme(currentDocument);
						var oldUnitValue = userInput.get("pageUnit");
						var pdfMode = userInput.get("pdfMode");
						if (AOM.CSConstant.isPreset[currentTemplate] != undefined) {
							for (var i = 0; i < defaultData.length; i++) {
								var field = defaultData[i];
								userInput.set(field.id, File.decode(field.value));
							}
						}
						if (pdfMode != undefined)
							userInput.set("pdfMode", pdfMode);
						for (var j=0; j < templateData.length; j++) {
							var field = templateData[j];
							userInput.set(field.id, File.decode(field.value));
						}
						userInput.setElement(this);
						var newUnitValue = userInput.get("pageUnit");
							
						designWindow.loadData(designWindow.CSGroup, userInput, theme);
						designWindow.loadSpecialData(false);
						AOM.CS.UIUtils.updateControlsWithUnit(designWindow, userInput, oldUnitValue, newUnitValue, 
							"pageWidth,pageHeight,topMargin,bottomMargin,rightMargin,leftMargin,horizontalSpacing,verticalSpacing");		
					}
				}
			}
		}
		that.setButtons(this.selection.value);
	}
	
	saveButton.onClick = function() {
		var userInput = AOM.userInput(currentDocument);
	
		openSaveDialog = function() {
			var saveDialog = new Window("dialog", AOM.localize("$$$/ContactSheet/javascript/title/templateTitle=New Template"), undefined);
			var sdGroup = saveDialog.add(
			"group{\
				orientation:'column',\
				nameGroup:Group{\
					alignment:['right', 'center'], \
					st:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/templateNameLabel=Template Name:") + "'},\
					edt:EditText{text:'', preferredSize:[160, 20]},\
				},\
				btnGroup:Group{\
					alignment:['right', 'center'],\
					createBtn:Button{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/createTemplateButton=Create") + "'},\
					cancelBtn:Button{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/cancelTemplateButton=Cancel") + "'},\
				},\
			}\
			");
				
			saveDialog.defaultElement = sdGroup.btnGroup.createBtn;
			saveDialog.cancelElement = sdGroup.btnGroup.cancelBtn;
			sdGroup.nameGroup.edt.active = true;
		
			sdGroup.btnGroup.cancelBtn.onClick = function() {
				saveDialog.hasCanceled = true;
				saveDialog.close();
			}
			sdGroup.btnGroup.createBtn.onClick = function() {
				var presetName = this.parent.parent.nameGroup.edt.text.amgTrim();
				if (presetName == undefined || presetName.length == 0) {
					AOM.alert(AOM.localize("$$$/ContactSheet/javascript/title/emptyTemplateName=Template name is required, please input template name."));
					return;
				}
                  if(presetName.length > 30) {
					AOM.alert(AOM.localize("$$$/ContactSheet/javascript/title/tooLongTemplateName=Template name is too long, please input template name again."));
					return;
				}
				if (!AOM.CS.Validation.isTemplateName(presetName)) {
					AOM.alert(AOM.localize("$$$/ContactSheet/javascript/title/illegalTemplateName=Template name includes illegal characters, please input template name again."));
					return;
				}
				
				for (var i = 0; i < theTemplates.items.length; i++) {
					if (theTemplates.items[i].type == "separator")
						continue;
					var templateName = theTemplates.items[i].value;
					if (presetName.toLowerCase() == templateName.toLowerCase()) {
						if(AOM.CSConstant.isPreset[templateName] != undefined) {
							AOM.alert(AOM.localize("$$$/ContactSheet/javascript/title/duplicateWithPreset=The name is the same as a preset template, please input another one."));
							return;
						} else {
							if(!AOM.confirm(AOM.localize("$$$/ContactSheet/javascript/title/duplicateTemplateName=The name is the same as an existent one, \nreplace it?"))) {
								return;	
							}
							theTemplates.remove(templateName);
							var filePath = AOM.CS.Paths.userTemplate + templateName + ".json";
							var file = new File(filePath);
							file.remove();
						}
					}
				}
				
				saveDialog.hasCanceled = false;
				saveDialog.presetName = presetName;
				saveDialog.close();
			}
			saveDialog.show();
		
			return saveDialog;
		}
		this.gsEnabled = this.enabled = false;
		//call save dialog
		var saveDialog = openSaveDialog();
		if (saveDialog.hasCanceled || saveDialog.presetName == undefined) {
			this.gsEnabled = this.enabled = true;
		 	return; 
		}
		var newPresetName = saveDialog.presetName;
		
		var oldHasProgramInteract = AOM.CS.UIUtils.blockDropDownListEvent();
		theTemplates.remove(0);
		theTemplates.remove(0);
		
		var hasCustom = false;

		if(AOM.CSConstant.isPreset[theTemplates.items[0].value] != undefined){
			theTemplates.add("separator", "", 0);
		}
		
		var newItem = theTemplates.add("item", newPresetName, 0);
		newItem.value = newPresetName;
		theTemplates.selection = newItem;
		AOM.CS.UIUtils.unblockDropDownListEvent(oldHasProgramInteract);
		
		deleteButton.gsEnabled = deleteButton.enabled = true;

		userInput.setElement(theTemplates);
		userInput.persistUserTemplate(newPresetName, "ContactSheet");
	}
	
	deleteButton.onClick = function() {
		this.gsEnabled = this.enabled = false;
		var userInput = AOM.userInput(currentDocument);
		var currentTemplate = userInput.get("template");
		
		if(!AOM.confirm(AOM.localize("$$$/ContactSheet/javascript/title/deleteTemplate=Do you really want to delete the template?"))) {
			this.gsEnabled = this.enabled = true;
			return;
		}
		
		var filePath = AOM.CS.Paths.userTemplate + currentTemplate + ".json";
		var file = new File(filePath);
		file.remove();
		
		var oldHasProgramInteract = AOM.CS.UIUtils.blockDropDownListEvent();
		theTemplates.remove(currentTemplate);
		if(theTemplates.items[0].type == "separator")
			theTemplates.remove(0);
		var max = theTemplates.items.length;
		for (var i = 0; i < max; i++) {
			theTemplates.selection = theTemplates.items[0];
			userInput.setElement(theTemplates);
			AOM.CS.UIUtils.unblockDropDownListEvent(oldHasProgramInteract);
			var result = theTemplates.onChange(true);
			if (result != "fail")
				break;
			oldHasProgramInteract = AOM.CS.UIUtils.blockDropDownListEvent();
		}
	}
}

AOM.CSConstant.isPreset = {
	TwoUpGreetingCard:"TwoUpGreetingCard",
	TwoCells:"TwoCells",
	FourContactSheet:"FourContactSheet",
	FiveContactSheet:"FiveContactSheet",
	FineArtMart:"FineArtMart",
	MaximizeSize:"MaximizeSize",
	Triptych:"Triptych"
}

AOM.CS.UIUtils.changePortraitOrLandscape = function(docLayer, width, height, userInput) {
	var width = AOM.CS.Locale.parseFloat(width);
	var height = AOM.CS.Locale.parseFloat(height);
	
	if (width <= height) {
		AOM.CS.UIUtils.swapPortraitAndLandscape(
			docLayer.hgrp.grp.pagePortrait, docLayer.hgrp.grp.pageLandscape, 
			docLayer.wgrp.grp.pageWidth, docLayer.hgrp.grp.pageHeight, userInput
		);
	} else {
		AOM.CS.UIUtils.swapPortraitAndLandscape(
			docLayer.hgrp.grp.pageLandscape, docLayer.hgrp.grp.pagePortrait, 
			docLayer.hgrp.grp.pageHeight, docLayer.wgrp.grp.pageWidth, userInput
		);
	}
}

AOM.CS.UIUtils.swapPortraitAndLandscape = function(mainBtn, secondBtn, mainEdt, secondEdt, currentUserInput) {
	if (mainBtn.btPressed == false) {
		mainBtn.btPressed = true;
		secondBtn.btPressed = false;
		currentUserInput.setElement(mainBtn);
		currentUserInput.setElement(secondBtn);
		
		if ((AOM.CS.Locale.parseFloat(mainEdt.text) - AOM.CS.Locale.parseFloat(secondEdt.text)) > 0) {
			var tempText = mainEdt.text;
			mainEdt.text = secondEdt.text;
			secondEdt.text = tempText;
				
			var tempValue = mainEdt.value;
			mainEdt.value = secondEdt.value;
			secondEdt.value = tempValue;
			
			currentUserInput.setElement(mainEdt);
			currentUserInput.setElement(secondEdt);
		}
	
		mainBtn.notify("onDraw");
		secondBtn.notify("onDraw");
	}
}

AOM.CS.UIUtils.setEditTextWithUnit = function(et, currentUnit, userInput) {
	if (currentUnit == AOM.CSConstant.UNIT_PIXELS) {
		et.text = AOM.CS.Locale.toLocaleString(AOM.CS.Locale.parseFloat(et.text, 0, "round"));
	} else {
		et.text = AOM.CS.Locale.toLocaleString(AOM.CS.Locale.parseFloat(et.text, 2, "round"));
	}
	et.value = AOM.CS.UIUtils.unitConvertion(currentUnit, AOM.CSConstant.UNIT_PIXELS, et.text);
	userInput.setElement(et);
}


AOM.CS.UIUtils.changePageSize = function(designWindow, pageSizeSelectedValue, userInput) {
	var docLayer = designWindow.documents;
	var layoutLayer = designWindow.layouts;	
	var sizeInfo = AOM.CSConstant.pageSizeMap[pageSizeSelectedValue];
	if (sizeInfo != undefined) {
		//change width, height
		var pageWidth = docLayer.wgrp.grp.pageWidth;
		var pageHeight = docLayer.hgrp.grp.pageHeight;
		pageWidth.value = sizeInfo.width;
		pageWidth.text = AOM.CS.UIUtils.getUnitDisplayText(pageWidth.value, sizeInfo.unit);
		pageHeight.value = sizeInfo.height;
		pageHeight.text = AOM.CS.UIUtils.getUnitDisplayText(pageHeight.value, sizeInfo.unit);
		userInput.setElement(pageWidth);
		userInput.setElement(pageHeight);
		
		//chagne unit
		var pageUnit = docLayer.wgrp.grp.pageUnit;
		var oldUnitValue = userInput.get(pageUnit.name);
		var newUnitValue = AOM.CS.UIUtils.setDropDownListSelection(pageUnit, sizeInfo.unit);
		userInput.setElement(pageUnit);
		
		AOM.CS.UIUtils.updateControlsWithUnit(designWindow, userInput, oldUnitValue, newUnitValue, "pageWidth,pageHeight");
		
		//change portrait or landscape
		AOM.CS.UIUtils.changePortraitOrLandscape(docLayer, sizeInfo.width, sizeInfo.height, userInput);
	}	
}


AOM.CS.UIUtils.updateControlsWithUnit = function(designWindow, userInput, fromUnit, toUnit, excludeString) {
	if(!fromUnit || !toUnit || fromUnit == toUnit) return;
	// get the correct unit text:
	var unitText = "";
	switch(toUnit) {
		case AOM.CSConstant.UNIT_INCHES:
			unitText = AOM.CSConstant.UNIT_INCHES_ABBR;
			break;
		case AOM.CSConstant.UNIT_PIXELS:
			unitText = AOM.CSConstant.UNIT_PIXELS_ABBR;
			break;
		case AOM.CSConstant.UNIT_CENTIMETERS:
			unitText = AOM.CSConstant.UNIT_CENTIMETERS_ABBR;
			break;
		default:
	}

	var doConvert = function(element) {
		//There is a limitation that all the control names can't be substring of another.
		if (excludeString == undefined || excludeString.indexOf(element.name) < 0) {
			// change unit text and value.
			element.text = AOM.CS.UIUtils.getUnitDisplayText(element.value, toUnit);
			var st = element.parent.t;
			if(st) st.text = unitText;
		}
	}
	
	var pageWidth = designWindow.documents.wgrp.grp.pageWidth;
	var pageHeight = designWindow.documents.hgrp.grp.pageHeight;
	var layoutgrp = designWindow.layouts.grp.layoutgrp;
	var margingrp = designWindow.layouts.grp.margingrp;
	var headerDistance = designWindow.header.grp2.bottomGrp.disGrp.headerDistance;	
	var footerDistance = designWindow.footer.grp2.bottomGrp.disGrp.footerDistance;
	
	// do convert
	doConvert(pageWidth);
	doConvert(pageHeight);
	doConvert(layoutgrp.horizontal.setVal.horizontalSpacing);
	doConvert(layoutgrp.vertical.setVal.verticalSpacing);
	doConvert(margingrp.setTop.topMargin);
	doConvert(margingrp.setBottom.bottomMargin);
	doConvert(margingrp.setLeft.leftMargin);
	doConvert(margingrp.setRight.rightMargin);
	doConvert(headerDistance);
	doConvert(footerDistance);	
}

AOM.CS.UIUtils.changeTemplate = function(pdfTemplates, userInput) {
	var currentTemplate = pdfTemplates.columngrp.tgrp.template;
	var saveButton = pdfTemplates.columngrp.tgrp.templateSaveBtn;
	var deleteButton = pdfTemplates.columngrp.tgrp.templateDeleteBtn;
	
	//change to custom item.
	if (currentTemplate.selection.value != AOM.CSConstant.CUSTOM) {
		
		var oldHasProgramInteract = AOM.CS.UIUtils.blockDropDownListEvent();
		currentTemplate.add("separator", "", 0);
		var newItem = currentTemplate.add("item", AOM.localize("$$$/ContactSheet/javascript/title/CustomTemplate=Custom"), 0);
		newItem.value = AOM.CSConstant.CUSTOM;
		currentTemplate.selection = newItem;
		AOM.CS.UIUtils.unblockDropDownListEvent(oldHasProgramInteract);
		saveButton.gsEnabled = saveButton.enabled = true;
		deleteButton.gsEnabled = deleteButton.enabled = false;
		userInput.setElement(currentTemplate);
	}
}

AOM.CS.UIUtils.changePagePresetToCustom = function(pagePreset, pageSize, userInput) {
	if (pagePreset.selection.value != AOM.CSConstant.CUSTOM) {
		AOM.CS.UIUtils.setDropDownListSelection(pagePreset, AOM.CSConstant.CUSTOM, true);
		var newItems = AOM.CS.UIUtils.getItemListByDefaultItems(pageSize.name, AOM.CSConstant.CUSTOM);
		AOM.CS.UIUtils.setDropDownList(pageSize, newItems, AOM.CSConstant.CUSTOM, true);
		userInput.setElement(pagePreset);
		userInput.setElement(pageSize);
	} 
}

AOM.CS.UIUtils.checkEditTextValidOnMac = function() {
	if (File.fs == "Macintosh") {
		if (AOM.CS.hasValid == false) {
			//reset the value.
			AOM.CS.hasValid = true;
			return false;
		}
	}
	return true;
}

AOM.CS.UIUtils.setEnabledStatus = function(child, enabled, theme) {
	if (undefined == child || undefined == enabled || undefined == child.type) return;
	
	var type = child.type.toLowerCase();
	switch(type) {
		case "group":
			for (var i = 0; i < child.children.length; ++i) {
				AOM.CS.UIUtils.setEnabledStatus(child.children[i], enabled, theme);
			}
			break;
		case "edittext":
			child.gsEnabled = child.enabled = enabled;

			 // Workaround:
			 //	 Set edittext control's disabled theme explicitly
			 //  for its onDraw callback function cannot be overwritted.
			theme.setEditTextDisableBgColor(child);
			break;
		default:
			child.gsEnabled = child.enabled = enabled;
			break;
	}
}

AOM.CS.UIUtils.getItemListByDefaultItems = function(name, childName) {
	var newItems = undefined;
	//lang first
	if (childName == undefined) {
		var langName = name + "_lang_" + app.language;
		newItems = AOM.CSConstant.dropDownListDefaultItems[langName];
		if (newItems == undefined || newItems.length == 0) {
			newItems = AOM.CSConstant.dropDownListDefaultItems[name];
		}
	} else {
		var langChildName = childName + "_lang_" + app.language;
		newItems = AOM.CSConstant.dropDownListDefaultItems[name][langChildName];
		
		if (newItems == undefined || newItems.length == 0) {
			newItems = AOM.CSConstant.dropDownListDefaultItems[name][childName];
		} 
	}
	return newItems;
}

AOM.CS.UIUtils.disablePageNumber = function(pageNumberLocation, userInput) {
	AOM.CS.UIUtils.setDropDownListSelection(
		pageNumberLocation, AOM.CSConstant.PAGENUMBER_LOCATION_NONE, true);
	
	// Manual call onChange event, to disable all child elements.
	pageNumberLocation.onChange();	
}

AOM.CS.UIUtils.confirmDisablePageNumber = function(location) {
	var msg = AOM.localizeWithArgs(
		"$$$/ContactSheet/javascript/validation/disablePageNumber=The page number is set to \"(1)\". Do you want to disable page number?", 
		location);
	return AOM.confirm(msg);
}


AOM.CSManager.DesignWindow.prototype.initDocumentEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var layoutLayer = this.layouts;
	var docLayer = this.documents;
	var headerLayer = this.header;
	var footerLayer = this.footer;
	var currentUserInput = AOM.userInput(this.currentDocument);
	var currentTheme = AOM.theme(this.currentDocument);
	var that = this;
	
	docLayer.pagegrp.pagePreset.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			if (this.selection != undefined) {
				// Get changed value
				var pagePresetSelectedValue = this.selection.value;
				currentUserInput.setElement(this);
				
				// Change pageSize
				var pageSize = docLayer.sgrp.pageSize;
				var newItems = AOM.CS.UIUtils.getItemListByDefaultItems(pageSize.name, pagePresetSelectedValue);
				var pageSizeSelectedValue = AOM.CS.UIUtils.setDropDownList(pageSize, newItems, "A4", true);
				currentUserInput.setElement(pageSize);
				
				// Change pageSize infos
				AOM.CS.UIUtils.changePageSize(that, pageSizeSelectedValue, currentUserInput);
				
				// Change quality
				var pageQuality = AOM.CSConstant.PAGE_QUALITY_MAP[this.selection.value];
				if (pageQuality != undefined) {
					AOM.CS.UIUtils.setDropDownListSelection(docLayer.pdfgrp.pdfPreset, pageQuality, true);
					currentUserInput.setElement(docLayer.pdfgrp.pdfPreset);
				}
				
				// Change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
		}	
	}

	docLayer.sgrp.pageSize.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			if (this.selection != undefined) {
				var pageSizeSelectedValue = this.selection.value;
				currentUserInput.setElement(this);
		
				//change pageSize infoes
				AOM.CS.UIUtils.changePageSize(that, pageSizeSelectedValue, currentUserInput);		
				
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
		}
	}
	
	docLayer.wgrp.grp.pageWidth.onChange = docLayer.hgrp.grp.pageHeight.onChange = function() {
		var pageUnit = currentUserInput.get("pageUnit");
		var oldText = AOM.CS.UIUtils.getUnitDisplayText(currentUserInput.get(this.name), pageUnit);
		if (currentUserInput.isValid(this.name, this.text)) {
			AOM.CS.UIUtils.setEditTextWithUnit(this, pageUnit, currentUserInput);
			if (this.text != oldText) {
				//set pagePreset and pageSize is custom
				AOM.CS.UIUtils.changePagePresetToCustom(
					docLayer.pagegrp.pagePreset, docLayer.sgrp.pageSize, currentUserInput);
				
				//change portrait and landscape and template
				AOM.CS.UIUtils.changePortraitOrLandscape(docLayer, 
					docLayer.wgrp.grp.pageWidth.text, docLayer.hgrp.grp.pageHeight.text, currentUserInput);
				
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
			AOM.CS.hasValid = true;
		} else {
			this.text = oldText;
			AOM.CS.hasValid = false;
		}
	}

	docLayer.wgrp.grp.pageUnit.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
			this.notify("onDraw");
		} else {
			var fromUnit = currentUserInput.get(this.name);
			currentUserInput.setElement(this);
			var toUnit = this.selection.value;
			//update ctrls with unit
			AOM.CS.UIUtils.updateControlsWithUnit(that, currentUserInput, fromUnit, toUnit);
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		}
	}
	
	docLayer.hgrp.grp.pagePortrait.onMouseDown = function() {
		if (this.btPressed == false) {
			if (!AOM.CS.UIUtils.checkEditTextValidOnMac()) {return;}
			
			AOM.CS.UIUtils.swapPortraitAndLandscape(
				this, this.parent.pageLandscape, 
				docLayer.wgrp.grp.pageWidth, docLayer.hgrp.grp.pageHeight, currentUserInput
			);
			
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			AOM.CS.UIUtils.changePagePresetToCustom(
				docLayer.pagegrp.pagePreset, docLayer.sgrp.pageSize, currentUserInput);
		}
	}
	
	docLayer.hgrp.grp.pageLandscape.onMouseDown = function() {
		if (this.btPressed == false) {
			if (!AOM.CS.UIUtils.checkEditTextValidOnMac()) {return;}
			
			AOM.CS.UIUtils.swapPortraitAndLandscape(
				this, this.parent.pagePortrait,
				docLayer.hgrp.grp.pageHeight, docLayer.wgrp.grp.pageWidth, currentUserInput
			);
		
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			AOM.CS.UIUtils.changePagePresetToCustom(
				docLayer.pagegrp.pagePreset, docLayer.sgrp.pageSize, currentUserInput);
		}
	}

	docLayer.pdfgrp.pdfPreset.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			if (this.selection != undefined) {
				currentUserInput.setElement(this);
								
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
		}
	}
	
    // checkbox method
	docLayer.docgrp.docPass.checks.hasDocPass.onMouseDown = function() {
		var docPass = this.parent.parent.edits.docPass;
		if (this.checked) {
			docPass.enabled = docPass.gsEnabled = true;
		} else {
			docPass.enabled = docPass.gsEnabled = false;
		}
		currentTheme.setEditTextDisableBgColor(docPass);
		currentUserInput.setElement(this);
	}

    // checkbox method
	docLayer.docgrp.docPass.checks.hasDocOwnerPass.onMouseDown = function() {
		var docOwnerPass = this.parent.parent.edits.docOwnerPass;
		var disablePrint = this.parent.parent.parent.print.disablePrint;
		if (this.checked) {
			docOwnerPass.enabled = docOwnerPass.gsEnabled = true;
			disablePrint.enabled = disablePrint.gsEnabled = true;
		} else {
			docOwnerPass.enabled = docOwnerPass.gsEnabled = false;
			disablePrint.enabled = disablePrint.gsEnabled = false;
		}
		currentTheme.setEditTextDisableBgColor(docOwnerPass);
		currentUserInput.setElement(this);
	}

	docLayer.docgrp.docPass.edits.docPass.onChange = function() {
		if (currentUserInput.isValid(this.name, this.text)) {
			this.value = this.text;
			currentUserInput.setElement(this);
			AOM.CS.hasValid = true;
		} else {
			this.text = "";
			AOM.CS.hasValid = false;
		}
	}

	docLayer.docgrp.docPass.edits.docOwnerPass.onChange = function() {
		if (currentUserInput.isValid(this.name, this.text)) {
			this.value = this.text;
			currentUserInput.setElement(this);
			AOM.CS.hasValid = true;
		} else {
			this.text = "";
			AOM.CS.hasValid = false;
		}
	}
}


AOM.CSManager.DesignWindow.prototype.initLayoutEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var layoutLayer = this.layouts;
	var currentUserInput = AOM.userInput(this.currentDocument);
	var currentTheme = AOM.theme(this.currentDocument);
	var layoutgrp = layoutLayer.grp.layoutgrp;
	var margingrp = layoutLayer.grp.margingrp;	
	
	layoutLayer.igrp.imagePlacement.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			if (this.selection != undefined) {
				currentUserInput.setElement(this);
								
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
		}
	}
	
	//hasUserAutoSpacing - checkbox 
	layoutLayer.autoSpace.hasUseAutoSpacing.onMouseDown = function() {
		currentUserInput.setElement(this);
		
		var enabled = true;
		if (this.checked) {
			enabled = false;
		} 
		AOM.CS.UIUtils.setEnabledStatus(layoutgrp.horizontal, enabled, currentTheme);
		AOM.CS.UIUtils.setEnabledStatus(layoutgrp.vertical, enabled, currentTheme);
		AOM.CS.UIUtils.setEnabledStatus(layoutgrp.parent.margingrp, enabled, currentTheme);

		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}

    // checkbox method
	layoutLayer.rgrp.hasRotate.onMouseDown = function() {
		currentUserInput.setElement(this);
		
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}

	var changeMarginEditText = function() {
		var pageUnit = currentUserInput.get("pageUnit");
		var oldText = AOM.CS.UIUtils.getUnitDisplayText(currentUserInput.get(this.name), pageUnit);
		if (currentUserInput.isValid(this.name, this.text)) {
			AOM.CS.UIUtils.setEditTextWithUnit(this, pageUnit, currentUserInput);
			
			if (this.text != oldText) {
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
			AOM.CS.hasValid = true;
		} else {
			this.text = oldText;
			AOM.CS.hasValid = false;
		}
	}

	//horizontalSpacing - editttext
	layoutgrp.horizontal.setVal.horizontalSpacing.onChange = changeMarginEditText;
	layoutgrp.vertical.setVal.verticalSpacing.onChange = changeMarginEditText;
	margingrp.setTop.topMargin.onChange = changeMarginEditText;
	margingrp.setBottom.bottomMargin.onChange = changeMarginEditText;
	margingrp.setLeft.leftMargin.onChange = changeMarginEditText;
	margingrp.setRight.rightMargin.onChange = changeMarginEditText;
	
	var changeRowAndColumn = function() {
		var oldText = currentUserInput.get(this.name);
		if (currentUserInput.isValid(this.name, this.text)) {
			this.value = AOM.CS.Locale.parseInt(this.text);
			this.text = this.value;
			currentUserInput.setElement(this);
			if (this.text != oldText) {
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
			AOM.CS.hasValid = true;
		} else {
			this.text = oldText;
			AOM.CS.hasValid = false;
		}
	}
	
	layoutgrp.setCol.pageColumns.onChange = changeRowAndColumn;
	layoutgrp.setRow.pageRows.onChange = changeRowAndColumn;


	//hasRepeatPerPage - checkbox
	layoutLayer.repeatgrp.hasRepeatPerPage.onMouseDown = function() {
		currentUserInput.setElement(this);
		
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}
}

AOM.CSManager.DesignWindow.prototype.initHeaderEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var currentUserInput = AOM.userInput(this.currentDocument);
	var currentTheme = AOM.theme(this.currentDocument);
	var bottomGrp = this.header.grp2.bottomGrp;
	var topGrp = this.header.grp1;
	
	// checkbox: has header or not
	topGrp.hasHeader.pageNumberLocation = this.overlays.pgrp.pngrp.pageNumberLocation;
	topGrp.hasHeader.onMouseDown = function() {
		if (!this.checked) {
			if (this.pageNumberLocation.selection.value == AOM.CSConstant.PAGENUMBER_LOCATION_HEADER) {
				this.checked = true;
				if (AOM.CS.UIUtils.confirmDisablePageNumber(this.pageNumberLocation.selection.text)) {
					AOM.CS.UIUtils.disablePageNumber(this.pageNumberLocation, currentUserInput);
					this.checked = false;
				} else {
					return ;
				}
			}
		}

		currentUserInput.setElement(this);
		
		var enabled = this.checked;
		AOM.CS.UIUtils.setEnabledStatus(topGrp.parent, enabled, currentTheme);
		this.enabled = this.gsEnabled = true;
		
		// Set divider color enabled status.
		if (bottomGrp.dlGrp.headerDLWidth.selection.value == "None") {
			AOM.CS.UIUtils.setEnabledStatus(bottomGrp.dlColorGrp, false, currentTheme);
		}
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}
	
	topGrp.headerAlignment.onChange = function()
	{
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput.setElement(this);
		} else {
			currentUserInput.setElement(this);
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		}
	}
	
	// EditText: header distance
	bottomGrp.disGrp.headerDistance.onChange = function() {
		var pageUnit = currentUserInput.get("pageUnit");
		var oldText = AOM.CS.UIUtils.getUnitDisplayText(currentUserInput.get(this.name), pageUnit);
		if (currentUserInput.isValid(this.name, this.text)) {
			AOM.CS.UIUtils.setEditTextWithUnit(this, pageUnit, currentUserInput);
			
			AOM.CS.hasValid = true;
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		} else {
			this.text = oldText;
			AOM.CS.hasValid = false;
		}
	}
	
	bottomGrp.dlGrp.headerDLWidth.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput.setElement(this);
		} else {
			if (this.selection != undefined) {
				currentUserInput.setElement(this);
				
				// Set divider color enabled status.
				var enabled = (this.selection.value != "None");
				AOM.CS.UIUtils.setEnabledStatus(bottomGrp.dlColorGrp, enabled, currentTheme);
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
		}
	}
}

AOM.CSManager.DesignWindow.prototype.initFooterEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var currentUserInput = AOM.userInput(this.currentDocument);
	var currentTheme = AOM.theme(this.currentDocument);
	var bottomGrp = this.footer.grp2.bottomGrp;
	var topGrp = this.footer.grp1;

	// checkbox: has footer or not
	topGrp.hasFooter.pageNumberLocation = this.overlays.pgrp.pngrp.pageNumberLocation;
	topGrp.hasFooter.onMouseDown = function() {
		if (!this.checked) {
			if (this.pageNumberLocation.selection.value == AOM.CSConstant.PAGENUMBER_LOCATION_FOOTER) {
				this.checked = true;
				if (AOM.CS.UIUtils.confirmDisablePageNumber(this.pageNumberLocation.selection.text)) {
					AOM.CS.UIUtils.disablePageNumber(this.pageNumberLocation, currentUserInput);
					this.checked = false;
				} else {
					return ;
				}
			}
		}
	
		currentUserInput.setElement(this);
		
		var enabled = this.checked;
		AOM.CS.UIUtils.setEnabledStatus(topGrp.parent, enabled, currentTheme);
		this.enabled = this.gsEnabled = true;
		
		// Set divider color enabled status.
		if (bottomGrp.dlGrp.footerDLWidth.selection.value == "None") {
			AOM.CS.UIUtils.setEnabledStatus(bottomGrp.dlColorGrp, false, currentTheme);
		}
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}
	
	topGrp.footerAlignment.onChange = function()
	{
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput.setElement(this);
		} else {
			currentUserInput.setElement(this);
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		}
	}
	
	// EditText: footer distance
	bottomGrp.disGrp.footerDistance.onChange = function() {
		var pageUnit = currentUserInput.get("pageUnit");
		var oldText = AOM.CS.UIUtils.getUnitDisplayText(currentUserInput.get(this.name), pageUnit);
		if (currentUserInput.isValid(this.name, this.text)) {
			AOM.CS.UIUtils.setEditTextWithUnit(this, pageUnit, currentUserInput);
			
			AOM.CS.hasValid = true;
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		} else {
			this.text = oldText;
			AOM.CS.hasValid = false;
		}
	}
	
	bottomGrp.dlGrp.footerDLWidth.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput.setElement(this);
		} else {
			if (this.selection != undefined) {
				currentUserInput.setElement(this);
				
				// Set divider color enabled status.
				var enabled = (this.selection.value != "None");
				AOM.CS.UIUtils.setEnabledStatus(bottomGrp.dlColorGrp, enabled, currentTheme);
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
		}
	}
}

AOM.CSManager.DesignWindow.prototype.initOverlaysEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var currentUserInput = AOM.userInput(this.currentDocument);

	this.overlays.rgrp.filegrp.hasFileName.sysFontGrp = this.overlays.rgrp.sysfontgrp;
    
    // checkbox method
	this.overlays.rgrp.filegrp.hasFileName.onMouseDown = function() {
		currentUserInput.setElement(this);
		
		var hasExtension = this.parent.hasExtension;
		if (this.checked) {
			hasExtension.enabled = true;
		} else {
			hasExtension.enabled = false;
		}
		hasExtension.gsEnabled = hasExtension.enabled;
		AOM.CS.UIUtils.setEnabledStatus(this.sysFontGrp, (this.checked == true));
		
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}
	
    // checkbox method
	this.overlays.rgrp.filegrp.hasExtension.onMouseDown = function() {
		currentUserInput.setElement(this);
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}
	
	var isLocationEnabled = function(pageNumberLocationValue, hasHeader, hasFooter) {
		if (pageNumberLocationValue == AOM.CSConstant.PAGENUMBER_LOCATION_HEADER) {
			return hasHeader.checked;
		} else {
			return hasFooter.checked;
		} 
	}

	var confirmEnableHeaderFooterFirst = function(pageNumberLocationValue) {
		var pnLocationWithLocaleStr;
		if (pageNumberLocationValue == AOM.CSConstant.PAGENUMBER_LOCATION_HEADER) {
			pnLocationWithLocaleStr = "$$$/ContactSheet/javascript/title/header=Header";
		} else {
			pnLocationWithLocaleStr = "$$$/ContactSheet/javascript/title/footer=Footer";
		}
		return AOM.confirm(AOM.localizeWithArgs(
			"$$$/ContactSheet/javascript/validation/enableHeaderFooterFirst=The (1) section is disabled. Do you want to enable (1) section?",
			pnLocationWithLocaleStr));
	}
	
	var pageNumberLocation = this.overlays.pgrp.pngrp.pageNumberLocation;
	pageNumberLocation.sysFontGrp = this.overlays.pgrp.sysfontgrp;
	pageNumberLocation.locationGroup = this.overlays.pgrp.lgrp;	
	pageNumberLocation.hasHeader = this.header.grp1.hasHeader;
	pageNumberLocation.hasFooter = this.footer.grp1.hasFooter;
	pageNumberLocation.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			var oldValue = currentUserInput.get(this.name);
			var selectedValue = pageNumberLocation.selection.value;
			var enabled;
			if (selectedValue == AOM.CSConstant.PAGENUMBER_LOCATION_NONE) {
				enabled = false;
			} else {
				if (isLocationEnabled(selectedValue, this.hasHeader, this.hasFooter)) {
					enabled = true;
				} else {
					AOM.CS.UIUtils.setDropDownListSelection(this, oldValue ,true);
					
					if (confirmEnableHeaderFooterFirst(selectedValue)) {
						enabled = true;
						
						//set back selectedValue.
						AOM.CS.UIUtils.setDropDownListSelection(this, selectedValue ,true);
						
						//notify hasHeader or hasFooter.
						if (selectedValue == AOM.CSConstant.PAGENUMBER_LOCATION_HEADER) {
							/*
					 		* Workaround:
					 		* 	Invoke onClick funtion directly instead of using notify("onClick");
					 		* 	because in multi-window environment, a alert or confirm dialog can cause another window 
					 		*   be selected, and the notify function can't work any more.
					 		*/
					 		//this.hasHeader.notify("onClick");
							this.hasHeader.checked = !this.hasHeader.checked;
							this.hasHeader.onMouseDown();
						} else {
							//this.hasFooter.notify("onClick");
							this.hasFooter.checked = !this.hasFooter.checked;
							this.hasFooter.onMouseDown();
						}
					} else {
						return;
					}
				}
			}
		
			AOM.CS.UIUtils.setEnabledStatus(this.locationGroup, enabled);
			AOM.CS.UIUtils.setEnabledStatus(this.sysFontGrp, enabled);
			currentUserInput.setElement(this);
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		}
	}
	this.overlays.pgrp.lgrp.pageNumberAlignment.onChange = function()
	{
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			currentUserInput.setElement(this);
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		}
	}
}

AOM.CSManager.DesignWindow.prototype.initPlaybackEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var currentUserInput = AOM.userInput(this.currentDocument);
	var currentTheme = AOM.theme(this.currentDocument);

	//hasAdvances - checkbox
	this.playbacks.selects.hasAdvance.onMouseDown = function() {
		currentUserInput.setElement(this);
		
		var advanceSeconds = this.parent.advances.advanceSeconds;
		if (this.checked) {
			advanceSeconds.enabled = advanceSeconds.gsEnabled = true;
		} else {
			advanceSeconds.enabled = advanceSeconds.gsEnabled = false;
		}
		currentTheme.setEditTextDisableBgColor(advanceSeconds);
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}

	this.playbacks.selects.advances.advanceSeconds.onChange = function(event) {
		var oldText = currentUserInput.get(this.name);
		if (currentUserInput.isValid(this.name, this.text)) {
			this.value = AOM.CS.Locale.parseInt(this.text);
			this.text = this.value;

			currentUserInput.setElement(this);
			AOM.CS.hasValid = true;
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		} else {
			this.text = oldText;
			AOM.CS.hasValid = false;
		}
	}

	//transition - dropdownlist
	var transition = this.playbacks.dynamics.tgrp.transition;
	transition.directionGroup = this.playbacks.dynamics.dgrp;
	transition.speedGroup = this.playbacks.dynamics.sgrp;
	this.playbacks.dynamics.tgrp.transition.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			if (this.selection != undefined) {
				var selectedValue = this.selection.value;
				
				// Setting directions drop-down-list control
				var direction = this.directionGroup.direction;
				var directionItems = AOM.CS.UIUtils.getItemListByDefaultItems(direction.name, selectedValue);
				if (directionItems == undefined || directionItems.length == 0) {
					currentUserInput.set(direction.name, undefined);
					AOM.CS.UIUtils.setEnabledStatus(this.directionGroup, false);
				} else {
					AOM.CS.UIUtils.setDropDownList(direction, directionItems, "undefined", true);
					currentUserInput.set(direction.name, direction.selection.value);
					AOM.CS.UIUtils.setEnabledStatus(this.directionGroup, true);
				}
				
				// Setting speed drop-down-list control
				AOM.CS.UIUtils.setEnabledStatus(this.speedGroup, (this.selection.value != "None"));
				
				currentUserInput.setElement(this);
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
			}
		}
	}
	this.playbacks.dynamics.dgrp.direction.onChange = function()
	{
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			currentUserInput.setElement(this);
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		}
	}
	this.playbacks.dynamics.sgrp.speed.onChange = function()
	{
		if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			currentUserInput.setElement(this);
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		}
	}
}


AOM.CSManager.DesignWindow.prototype.initWatermarksEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var watermarks = this.watermarks;
	var currentUserInput = AOM.userInput(this.currentDocument);
	var currentTheme = AOM.theme(this.currentDocument);
	var hasTextWatermark = watermarks.istextgrp.hasTextWatermark;
	var hasImageWatermark = watermarks.isimagegrp.hasImageWatermark;
	
	// Checkbox: hasWatermark
	watermarks.generalgrp.hasWatermark.onMouseDown = function() {
		currentUserInput.setElement(this);
		AOM.CS.UIUtils.setEnabledStatus(watermarks, this.checked, currentTheme);
		AOM.CS.UIUtils.setEnabledStatus(watermarks.imagegrp, this.checked && hasImageWatermark.value, currentTheme);
		AOM.CS.UIUtils.setEnabledStatus(watermarks.textgrp, this.checked && hasTextWatermark.value, currentTheme);
		this.enabled = this.gsEnabled = true;
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}
	
	// RadioButton: insert text / image.
	hasTextWatermark.onMouseDown = function() {
		hasImageWatermark.value = false;
		currentUserInput.setElement(this);
		currentUserInput.setElement(hasImageWatermark);
		AOM.CS.UIUtils.setEnabledStatus(watermarks.imagegrp, false, currentTheme);
		AOM.CS.UIUtils.setEnabledStatus(watermarks.textgrp, true, currentTheme);
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}
	hasImageWatermark.onMouseDown = function() {
		hasTextWatermark.value = false;
		currentUserInput.setElement(this);
		currentUserInput.setElement(hasTextWatermark);
		AOM.CS.UIUtils.setEnabledStatus(watermarks.textgrp, false, currentTheme);
		AOM.CS.UIUtils.setEnabledStatus(watermarks.imagegrp, true, currentTheme);
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
	}
	
	var imageFileValidation = function(imagePath) {
		var isValidImage = function(srcImage) {
			var ret = false;
			var bitmapData = new BitmapData(srcImage);
			if (bitmapData != undefined) {
				if (bitmapData.pointer != undefined)
					ret = true;
				bitmapData.dispose();
			}
			return ret;
		}	
		
		if (imagePath.length == 0) {
			return true;
		}

		var imageFile = new File(File.encode(imagePath));
		if (!imageFile.exists) {
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/wmImageNotExist=The file doesn't exist."));
			AOM.CS.hasValid = false;
			return false;
		}
	
		var isFileOpen = imageFile.open("r");
		imageFile.close();
		if (!isFileOpen) {
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/wmCannotOpenFile=Bridge can not open the file."));
			AOM.CS.hasValid = false;
			return false;
		} 
		
		if (!isValidImage(imageFile)) {
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/badWatermarkImage=The selected file is not a supported image."));
			AOM.CS.hasValid = false;
			return false;
		}
		
		return true;
	}
	
	// Button: set wmImagepath
	watermarks.imagegrp.pathgrp.pathbtn.onClick = function() 
	{
		var imageFile = File.openDialog(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/chooseWMImage=Choose an image file"));
		if (imageFile && imageFileValidation(imageFile.fsName)) {
			watermarks.imagegrp.pathgrp.wmImagePath.text = imageFile.fsName;
			watermarks.imagegrp.pathgrp.wmImagePath.value = imageFile.fsName;
			currentUserInput.setElement(watermarks.imagegrp.pathgrp.wmImagePath);
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		}
	}
	
	// EditText: wmImagePath
	watermarks.imagegrp.pathgrp.wmImagePath.onChange = function() 
	{
		var oldPath = currentUserInput.get(this.name);
		if (!oldPath) oldPath = "";
		
		this.text = AOM.CS.CString.trim(this.text);
		if (imageFileValidation(this.text)) {
			this.value = this.text;
			currentUserInput.setElement(this);
		}
		else {
			this.text = oldPath;
		}
	}
	watermarks.generalgrp.wmLayer.onChange = function() {
	if (AOM.CS.hasProgramInteract) {
			currentUserInput.setElement(this);
		} else {
			currentUserInput.setElement(this);
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, currentUserInput);
		}
	}
}

AOM.CSManager.DesignWindow.prototype.initPDFGenerationEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var currentUserInput = AOM.userInput(this.currentDocument);
	var layoutLayer = this.layouts;
	var docLayer = this.documents;
	var playbackLayer = this.playbacks;
	var watermarks = this.watermarks;
	var currentDocument = this.currentDocument;
	
	this.savePdfs.contentgroup.hasViewPdf.onMouseDown  = function() {
		AOM.userInput(currentDocument).setElement(this);
	}

	//TODO, temp set save btn onclick event
	this.savePdfs.contentgroup.saveBtn.onClick = function() {	
		if (!AOM.CS.UIUtils.checkEditTextValidOnMac()) {return;}
			
		//after
		var pdfMaker = new AOM.CS.PDFMaker(currentDocument);
		var anyError = pdfMaker.generatePDF();
		AOM.CSManager.DesignWindow.processPDFGenerationError(anyError);
		pdfMaker.destroy();
	}
}


AOM.CSManager.DesignWindow.processPDFGenerationError = function( errorCode ){
	var ret = false;
	switch ( errorCode ) {
		case AOM.CSConstant.SELECT_NONE:
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/noSelectThumbnail=No item is selected. Please select at least one item and try again."));
			break;
		case AOM.CSConstant.LAYOUT_WIDTH_ERROR:
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/layoutWidthError=The specified page width does not provide enough space for image display. \nPlease reduce number of columns, amount of horizontal spacings or margins."));
			break;
		case AOM.CSConstant.LAYOUT_HEIGHT_ERROR:
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/layoutHeightError=The specified page height does not provide enough space for image display. \nPlease reduce number of rows, amount of vertical spacings, margins, header distance, or footer distance."));		
			break;
		case AOM.CSConstant.NEED_DOCPASS:
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/passwordEmpty=The Open Password is empty. Please either deselect the 'Open Password' option or enter a password."));
			break;
		case AOM.CSConstant.NEED_OWNERPASS:
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/ownerPasswordEmpty=The Permissions Password is empty. Please either deselect the 'Permissions Password' option or enter a password."));
			break;
		case AOM.CSConstant.PASSWD_IDENTICAL:
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/passwordsCantBeSame=The Open Password and the Permissions Password are identical. Please change either the 'Open Password' or the 'Permissions Password'."));
			break;
		case AOM.CSConstant.WATERMARK_IMAGE_NOT_EXIST:
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/wmImageInexistent=The watermark image no longer exists."));
			break;
		case AOM.CSConstant.WATERMARK_IMAGE_UNSUPPORT:
			AOM.alert(AOM.localize("$$$/ContactSheet/javascript/pdfGenerator/wmImageUnsupport=The watermark image format is not supported."));
			break;
		case AOM.CSConstant.HEADERFOOTER_ERROR:
			break;
		default:
			ret = true;
	}
	return ret;

};


/*****************************************************************************************************************
                    Define Resource Specification Here
******************************************************************************************************************/

AOM.CSManager.initializationResources = function()
{

	AOM.CS.pdfTemplateResource = 
	"group{\
		orientation:'row', alignment:['left', 'top'], alignChildren:['left', 'top'], margins:[20,5,10,0], spacing:6,\
         t:StaticText{text:'" +AOM.localizeEsc("$$$/ContactSheet/javascript/title/template=Template:") + "', preferredSize:[-1, 18]},\
         columngrp:Group{\
            orientation:'column', alignment:['left','top'], alignChildren:['left', 'top'], margins:0, spacing:6,\
            tgrp:Group{\
                orientation:'row',alignment:['left', 'top'], alignChildren:['left', 'top'], margins:0, spacing:5,\
                template:DropDownList{preferredSize:[170, 22], name:'template'},\
                templateSaveBtn:IconButton{\
                    text:'',\
                    preferredSize:[20, 20],\
                    normalImagePath:'" + AOM.Paths.images + "/new_normal.png" + "',\
                    rolloverImagePath:'" + AOM.Paths.images + "/new_rollover.png" + "',\
                    disableImagePath:'" + AOM.Paths.images + "/new_disable.png" + "',\
                    themeType:'swapbutton',\
                    helpTip:' " + AOM.localizeEsc("$$$/ContactSheet/javascript/ftp/saveTemplate=Save Template") + "', \
                },\
                templateDeleteBtn: IconButton{\
                    text:'', \
                    preferredSize:[20, 20],\
                    normalImagePath:'" + AOM.Paths.images + "/delete_normal.png" + "',\
                    rolloverImagePath:'" + AOM.Paths.images + "/delete_rollover.png" + "',\
                    disableImagePath:'" + AOM.Paths.images + "/delete_disable.png" + "',\
                    themeType:'swapbutton',\
                    helpTip:' " + AOM.localizeEsc("$$$/ContactSheet/javascript/ftp/deleteTemplate=Delete Selected Template") + "', \
                },\
            },\
            refreshgrp:Group{\
                alignment:['left', 'top'], alignChildren:['left', 'top'], margins:[0, 0, 10, 10],\
                refreshPreview:IconButton{\
                themeType:'iconbutton', \
                preferredSize:[170, 22],\
                helpTip:' " + AOM.localizeEsc("$$$/ContactSheet/javascript/tooltip/preview=Refresh PDF file and preview") + "', \
                text:'" +AOM.localizeEsc("$$$/ContactSheet/javascript/title/refreshPreview=Refresh Preview") + "', \
                },\
		   },\
         },\
	}";
	
	AOM.CS.documentResource = 
	"Group {\
		orientation:'column', alignment:['left', 'top'], alignChildren:['right', 'top'], spacing:6, margins:[8, 5, 0, 5], \
		pagegrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/pagePreset=Page Preset:") + "', preferredSize:[-1, 18]},\
			pagePreset:DropDownList{preferredSize:[148, 22], name:'pagePreset'}\
		},\
		sgrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/size=Size:") + "', preferredSize:[-1, 18]},\
			pageSize:DropDownList{preferredSize:[148, 22], name:'pageSize', refParent:'pagePreset'}\
		},\
		wgrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/width=Width:") + "', preferredSize:[-1, 18]}, \
			grp:Group{\
				margins:0, spacing:10 ,\
				pageWidth:EditText{text:'8.5', preferredSize:[40, 18], name:'pageWidth', title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/widthTitle=Width") + "', properties: {borderless:true}, dataType:'UnitFloat'},\
				pageUnit:DropDownList{preferredSize:[98, 22], name:'pageUnit'},\
			}\
		},\
		hgrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/height=Height:") + "', preferredSize:[-1, 18]}, \
			grp:Group{\
				margins:0, spacing:8, \
				pageHeight:EditText{text:'11', preferredSize:[40, 18], name:'pageHeight', title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/heightTitle=Height") + "', properties: {borderless:true}, dataType:'UnitFloat'},\
				st:StaticText{text:'', preferredSize:[10, 22]},\
				pagePortrait:Custom{\
					type:'customBoundedValue',\
					text:'', \
					helpTip:' " + AOM.localizeEsc("$$$/ContactSheet/javascript/tooltip/portrait=Portrait") + "', \
					preferredSize:[23, 23],\
					btPressed:true,\
					imagePath:'" + AOM.CS.Paths.images + "icon_norotator.png" + "',\
					themeType:'imagebutton', name:'pagePortrait'\
				},\
				pageLandscape:Custom{\
					type:'customBoundedValue',\
					text:'',\
					helpTip:' " + AOM.localizeEsc("$$$/ContactSheet/javascript/tooltip/landscape=Landscape") + "', \
					preferredSize:[23, 23],\
					btPressed:true,\
					imagePath:'" + AOM.CS.Paths.images + "icon_rotator.png" + "',\
					themeType:'imagebutton', name:'pageLandscape'\
				},\
				st:StaticText{text:'', preferredSize:[20, 22]}\
			}\
		},\
		pdfgrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/adobePdfPreset=Quality:") + "', preferredSize:[-1, 18]},\
			pdfPreset:DropDownList{preferredSize:[148, 22], name:'pdfPreset'}\
		}, \
		quagrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/jpegQuality=Quality:") + "', preferredSize:[-1, 18]},\
			jpegQualitySlider:Group{\
				themeType:'hslider', \
				minvalue:0, maxvalue:100, stepdelta:1, value:70, \
				footLabel:'',\
				sliderPreferredSize:[110, 22], etPreferredSize:[34, 18], \
				name:'jpegQualitySlider',\
				preferredSize:[0, 5],  text:'',\
			},\
		}, \
		bggrp:Group{\
			orientation:'column',alignment:['right', 'top'],alignChildren:['right', 'center'],spacing:6, \
			themeType:'syscolorgroup', colorTitle: '" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/background=Background:") + "',\
			name:'pageBackground', basePreferredSize:[148, 22],\
		},\
		docgrp: Group{\
			orientation:'column', alignment:['fill', 'center'], alignChildren:['fill', 'center'], margins:[0, 5, 0, 0],spacing:6,\
			docPass:Group{\
				orientation:'row', alignChildren:['fill', 'top'],\
				spacing:5,\
				checks:Group{\
					orientation:'column', spacing:7,\
					margins:[0, 2, 0, 0],\
						hasDocPass:Custom{\
						type:'customBoundedValue',\
						themeType:'customcheckbox', \
						alignment:['left','center'],\
						title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/openPassword=Open Password:") + "',\
						name:'hasDocPass',\
						preferredSize:[100, 18],\
					},\
                     hasDocOwnerPass:Custom{\
						type:'customBoundedValue',\
						themeType:'customcheckbox', \
						alignment:['left','center'],\
						title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/permissionsPassword=Permissions Password:") + "',\
						name:'hasDocOwnerPass',\
						preferredSize:[100, 18],\
					},\
				}\
				edits:Group{\
					orientation:'column', spacing:6,\
					docPass:EditText{\
						text:'',\
						preferredSize:[110, 18],\
						name:'docPass',\
						properties: {noecho: true, borderless:true}, enableParent:'hasDocPass', equalToParent:'true',alignment:['left', 'center']\
					}\
					docOwnerPass:EditText{\
						text:'',\
						preferredSize:[110, 18],\
						name:'docOwnerPass',\
						properties: {noecho: true, borderless:true}, enableParent:'hasDocOwnerPass', equalToParent:'true',alignment:['left', 'center']\
					}\
				}\
			},\
			print:Group{\
				g:Group{preferredSize:[20, 18]}\
                  disablePrint:Custom{\
					type:'customBoundedValue',\
					themeType:'customcheckbox', \
					preferredSize:[100, 18],\
					title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/disablePrinting=Disable Printing") + "',\
					enableParent:'hasDocOwnerPass',\
					equalToParent:'true',\
					name:'disablePrint'\
                },\
			}\
		}\
	}" ;
	
AOM.CS.layoutResource = 
	"Group {\
		orientation:'column', alignment:['fill', 'top'], alignChildren:['right', 'top'], spacing:6, margins:[8, 10, 0, 3],\
		igrp:Group{\
			alignChildren:['right', 'center'], \
			margins:[0, 0, 0, 6], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/imagePlacement=Image Placement:") + "', preferredSize:[-1, 18]},\
			imagePlacement:DropDownList{preferredSize:[148, 22], name:'imagePlacement' }\
		}, \
		grp:Group{\
			spacing:6,\
			alignment:['fill', 'top'],\
			layoutgrp:Group{\
				orientation:'column', alignment:['left', 'center'], alignChildren:['right', 'center'], spacing:6,\
				setCol:Group{\
					alignChildren:['right', 'center'],spacing:6,\
					t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/columns=Columns:") + "', preferredSize:[-1, 18]}, \
					pageColumns:EditText{preferredSize:[62, 18],  name:'pageColumns',\
						title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/pageColumns=Columns") + "', properties: {borderless:true}},\
				},\
				setRow:Group{\
					alignChildren:['right', 'center'],spacing:6,\
					t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/rows=Rows:") + "', preferredSize:[-1, 18]}, \
					pageRows:EditText{preferredSize:[62, 18], name:'pageRows',\
						title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/pageRows=Rows") + "', properties: {borderless:true}},\
				},\
				horizontal:Group{\
					alignChildren:['right', 'center'],spacing:6,\
					t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/horizontal=Horizontal:") + "', name:'horizontalSpacingSt', enableParent:'hasUseAutoSpacing', equalToParent:'false', preferredSize:[-1, 18]}, \
					setVal:Group{\
						alignChildren:['left', 'center'],spacing:3,\
						horizontalSpacing:EditText{text:'0.15', preferredSize:[43, 18], name:'horizontalSpacing', enableParent:'hasUseAutoSpacing', equalToParent:'false',\
							 title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/horizontalSpace=Horizontal Space") + "', properties: {borderless:true}, dataType:'UnitFloat'},\
						t:StaticText{text:'" + AOM.localizeEsc(AOM.CSConstant.UNIT_INCHES_ABBR) + "',  preferredSize:[18, 18], refParent:'pageUnit', name:'horizontalUnit', enableParent:'hasUseAutoSpacing', equalToParent:'false'},\
					}\
				},\
				vertical:Group{\
					alignChildren:['right', 'center'],spacing:6,\
					t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/vertical=Vertical:") + "', name:'verticalSpacingSt', enableParent:'hasUseAutoSpacing', equalToParent:'false', preferredSize:[-1, 18]}, \
					setVal:Group{\
						alignChildren:['left', 'center'],spacing:3,\
						verticalSpacing:EditText{ text:'0.15', preferredSize:[43, 18], name:'verticalSpacing', enableParent:'hasUseAutoSpacing', equalToParent:'false',\
							 title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/verticalSpace=Vertical Space") + "', properties: {borderless:true}, dataType:'UnitFloat'},\
						t:StaticText{text:'" + AOM.localizeEsc(AOM.CSConstant.UNIT_INCHES_ABBR) + "', preferredSize:[18, 18], refParent:'pageUnit', name:'verticalUnit', enableParent:'hasUseAutoSpacing', equalToParent:'false'},\
					}\
				},\
			},\
			margingrp:Group{\
				orientation:'column', alignment:['right', 'center'], alignChildren:['right', 'top'], spacing:6,\
				setTop:Group{\
					alignChildren:['right', 'center'],spacing:6,\
					tt:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/top=Top:") + "', name:'topMarginSt', enableParent:'hasUseAutoSpacing', equalToParent:'false', preferredSize:[-1, 18]},\
					topMargin:EditText{ text:'0.15', preferredSize:[43, 18], name:'topMargin', enableParent:'hasUseAutoSpacing', equalToParent:'false',\
						 title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/topMarginTitle=Top Margin") + "', properties: {borderless:true}, dataType:'UnitFloat'},\
					t:StaticText{text:'" + AOM.localizeEsc(AOM.CSConstant.UNIT_INCHES_ABBR) + "', preferredSize:[18, 18], refParent:'pageUnit', name:'topMarginUnit', enableParent:'hasUseAutoSpacing', equalToParent:'false'},\
				},\
				setBottom:Group{\
					alignChildren:['right', 'center'],spacing:6,\
					tt:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/bottom=Bottom:") + "', name:'bottomMarginSt', enableParent:'hasUseAutoSpacing', equalToParent:'false', preferredSize:[-1, 18]},\
					bottomMargin:EditText{text:'0.15',preferredSize:[43, 18],  name:'bottomMargin', enableParent:'hasUseAutoSpacing', equalToParent:'false',\
						 title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/bottomMarginTitle=Bottom Margin") + "', properties: {borderless:true}, dataType:'UnitFloat'},\
					t:StaticText{text:'" + AOM.localizeEsc(AOM.CSConstant.UNIT_INCHES_ABBR) + "',preferredSize:[18, 18], refParent:'pageUnit', name:'bottomMarginUnit', enableParent:'hasUseAutoSpacing', equalToParent:'false'},\
				},\
				setLeft:Group{\
					alignChildren:['right', 'center'],spacing:6,\
					tt:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/left=Left:") + "', name:'leftMarginSt', enableParent:'hasUseAutoSpacing', equalToParent:'false', preferredSize:[-1, 18]},\
					leftMargin:EditText{ text:'0.15', preferredSize:[43, 18], name:'leftMargin', enableParent:'hasUseAutoSpacing', equalToParent:'false',\
						title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/leftMarginTitle=Left Margin") + "', properties: {borderless:true}, dataType:'UnitFloat'},\
					t:StaticText{text:'" + AOM.localizeEsc(AOM.CSConstant.UNIT_INCHES_ABBR) + "',preferredSize:[18, 18], refParent:'pageUnit', name:'leftMarginUnit', enableParent:'hasUseAutoSpacing', equalToParent:'false'},\
				},\
				setRight:Group{\
					alignChildren:['right', 'center'],spacing:6,\
					tt:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/right=Right:") + "', name:'rightMarginSt', enableParent:'hasUseAutoSpacing', equalToParent:'false', preferredSize:[-1, 18]},\
					rightMargin:EditText{ text:'0.15',preferredSize:[43, 18],  name:'rightMargin', enableParent:'hasUseAutoSpacing', equalToParent:'false',\
						 title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/validation/rightMarginTitle=Right Margin") + "', properties: {borderless:true}, dataType:'UnitFloat'},\
					t:StaticText{text:'" + AOM.localizeEsc(AOM.CSConstant.UNIT_INCHES_ABBR) + "',preferredSize:[18, 18], refParent:'pageUnit', name:'rightMarginUnit', enableParent:'hasUseAutoSpacing', equalToParent:'false'},\
				}\
			}\
		},\
		autoSpace:Group{\
			alignment:['fill', 'center'], margins:[0, 5, 0, 0],\
			hasUseAutoSpacing: Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/useAutoSpacing=Use Auto-Spacing") + "', name:'hasUseAutoSpacing'},\
		},\
		rgrp:Group{\
			alignment:['fill', 'center'], alignChildren:['left', 'center'], \
			hasRotate:Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/rotateForBestFit=Rotate for Best Fit") + "', name:'hasRotate'}\
		},\
		repeatgrp:Group{\
			alignment:['fill', 'center'], alignChildren:['left', 'center'],\
			hasRepeatPerPage: Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/repeatPerPage=Repeat One Photo per Page") + "', name:'hasRepeatPerPage'},\
		},\
	}" ;
	
	
	AOM.CS.overlaysResource = 
	"Group {\
		orientation:'column', alignment:['fill', 'top'], spacing:24, margins:[8, 10, 0, 10], \
		rgrp:Group{\
			orientation:'column', alignment:['right', 'top'], alignChildren:['left', 'top'], spacing:3, \
			filegrp:Group{\
				alignChildren:['left', 'top'], spacing:50, \
				hasFileName:Custom{\
					type:'customBoundedValue',\
					themeType:'customcheckbox', \
					preferredSize:[60, 18],\
					title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/fileName=Filename") + "', \
					name:'hasFileName', preferrredSize:[-1, 20]\
				},\
				hasExtension:Custom{\
					type:'customBoundedValue',\
					themeType:'customcheckbox', \
					preferredSize:[60, 18],\
					title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/Extension=Extension") + "', \
					name:'hasExtension',  enableParent:'hasFileName', equalToParent:'true', },\
			},\
			sysfontgrp:Group{\
				orientation:'column',alignment:['right', 'top'],alignChildren:['right', 'center'],spacing:6, margins:[18, 0, 0, 0], \
				themeType:'sysfontgroup', isApplyFSSlider:false,\
				name:'fileName', basePreferredSize:[166, 22],\
				enableParent:'hasFileName', equalToParent:'true', \
			},\
		},\
		pgrp:Group{\
			orientation:'column', alignment:['right', 'top'], alignChildren:['right', 'top'], spacing:6, \
			pngrp:Group{\
				alignChildren:['right', 'center'], spacing:6, \
				pageNumberLocationLabel:StaticText{text:'"+AOM.localizeEsc("$$$/ContactSheet/javascript/title/pageNumber=Page Number:")+"', preferredSize:[-1, 18]},\
				pageNumberLocation:DropDownList{\
					preferredSize:[166, 22], name:'pageNumberLocation',\},\
			},\
			sysfontgrp:Group{\
				orientation:'column',alignChildren:['right', 'center'],spacing:6, \
				themeType:'sysfontgroup', isApplyFSSlider:false,\
				name:'pageNumber', basePreferredSize:[166, 22],\
				enableParent:'pageNumberLocation', equalToParent:'true', \
			},\
			lgrp:Group{\
				alignChildren:['right', 'center'], spacing:6,\
				pnAlignLabel:StaticText{\
					text:'"+AOM.localizeEsc("$$$/ContactSheet/javascript/title/pageNumberAlignment=Alignment:")+"',\
					name:'pageNumberAlignLabel', enableParent:'pageNumberLocation', equalToParent:'true', preferredSize:[-1, 18]},\
				pageNumberAlignment:DropDownList{\
					preferredSize:[83, 22], name:'pageNumberAlignment', \
					enableParent:'pageNumberLocation', equalToParent:'true', \},\
				sp:StaticText{text:'', preferredSize:[77, 22]},\
			},\
		},\
	}" ;
	
	AOM.CS.headerResource = 
	"Group {\
		orientation:'column', spacing:6, alignChildren:['right', 'center'],\
		grp1:Group{\
			alignment:['left', 'center'], spacing:6,\
			hasHeader:Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				name:'hasHeader', title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/addHeader=Add Header:") + "'},\
			headerAlignment:DropDownList{name:'headerAlignment', preferredSize:[90,22],enableParent:'hasHeader', equalToParent:'true'},\
		},\
		grp2:Group{\
			orientation:'column', spacing:6, margins:[8,0,0,0], alignChildren:['right', 'center'],\
			txtGrp:Group{\
				spacing:6, alignChildren:['right','top'],\
				stTxt:StaticText{name:'stTxt', text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/text=Text:") + "',enableParent:'hasHeader', equalToParent:'true', preferredSize:[-1, 18]},\
				headerText:EditText{name:'headerText',preferredSize:[166,18],properties:{borderless:true},enableParent:'hasHeader', equalToParent:'true'},\
			},\
			sysfontgrp:Group{\
				orientation:'column',alignChildren:['right', 'center'],spacing:6, \
				themeType:'sysfontgroup', isApplyFSSlider:false,\
				name:'header', basePreferredSize:[166, 22],\
				enableParent:'hasHeader', equalToParent:'true', \
			},\
			bottomGrp:Group{\
				orientation:'column', spacing:6, alignment:['right','top'],alignChildren:['right','center'],\
                disGrp:Group{\
					alignment:['right','center'], alignChildren:['right','center'], spacing:6,\
					stDistance:StaticText{name:'stDistance',preferredSize:[-1,22],text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/distance=Distance:") + "',enableParent:'hasHeader', equalToParent:'true'},\
					headerDistance:EditText{\
						name:'headerDistance',preferredSize:[83,18],properties:{borderless:true},\
						enableParent:'hasHeader', equalToParent:'true', dataType:'UnitFloat'},\
					t:StaticText{name:'distanceUnit', text:'" + AOM.localizeEsc(AOM.CSConstant.UNIT_INCHES_ABBR) + "', preferredSize:[18, 18], refParent:'pageUnit',enableParent:'hasHeader', equalToParent:'true'},\
					sp:StaticText{text:'', preferredSize:[55, 18]},\
				},\
				dlGrp:Group{\
					alignChildren:['right', 'center'], spacing:6,\
					headerDLLabel:StaticText{\
						text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/divider=Divider:") + "', \
						name:'headerDLLabel', enableParent:'hasHeader', equalToParent:'true', preferredSize:[-1, 18]\
					},\
					headerDLWidth:DropDownList{\
						name:'headerDLWidth', preferredSize:[83,22],\
						enableParent:'hasHeader', equalToParent:'true',\
						selectionTextSuffix:' " + AOM.localizeEsc(AOM.CSConstant.UNIT_PIXELS_ABBR) + "', excludeItem:'None',\
					},\
					sp:StaticText{text:'', preferredSize:[77, 18]},\
				},\
				dlColorGrp:Group{\
					orientation:'column', alignChildren:['right', 'center'],spacing:6, \
					themeType:'syscolorgroup', \
					colorTitle:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/dividerColor=Divider Color:") + "', \
					name:'headerDL', basePreferredSize:[166, 22],\
					enableParent:'hasHeader,headerDLWidth', equalToParent:'true,true', \
				},\
			},\
		},\
	};"
	
	AOM.CS.footerResource = 
	"Group {\
		orientation:'column', spacing:6, alignChildren:['right', 'center'],\
		grp1:Group{\
			alignment:['left', 'center'], spacing:6,\
			hasFooter:Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				name:'hasFooter', title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/addFooter=Add Footer:") + "'},\
			footerAlignment:DropDownList{name:'footerAlignment', preferredSize:[90,22],enableParent:'hasFooter', equalToParent:'true'},\
		},\
		grp2:Group{\
			orientation:'column', spacing:6, margins:[8,0,0,0], alignChildren:['right', 'center'],\
			txtGrp:Group{\
				spacing:6, alignChildren:['right','top'],\
				stTxt:StaticText{name:'stTxt', text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/text=Text:") + "',enableParent:'hasFooter', equalToParent:'true', preferredSize:[-1, 18]},\
				footerText:EditText{name:'footerText',preferredSize:[166,18],properties:{borderless:true},enableParent:'hasFooter', equalToParent:'true'},\
			},\
			sysfontgrp:Group{\
				orientation:'column',alignChildren:['right', 'center'],spacing:6, \
				themeType:'sysfontgroup', isApplyFSSlider:false,\
				name:'footer', basePreferredSize:[166, 22],\
				enableParent:'hasFooter', equalToParent:'true', \
			},\
			bottomGrp:Group{\
				orientation:'column', spacing:6, alignment:['right','top'],alignChildren:['right','center'],\
				disGrp:Group{\
					alignment:['right','center'], alignChildren:['right','center'], spacing:6,\
					stDistance:StaticText{name:'stDistance',preferredSize:[-1,22],text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/distance=Distance:") + "',enableParent:'hasFooter', equalToParent:'true'},\
					footerDistance:EditText{\
						name:'footerDistance',preferredSize:[83,18],properties:{borderless:true},\
						enableParent:'hasFooter', equalToParent:'true', dataType:'UnitFloat'},\
					t:StaticText{name:'distanceUnit', text:'" + AOM.localizeEsc(AOM.CSConstant.UNIT_INCHES_ABBR) + "', preferredSize:[18, 18], refParent:'pageUnit',enableParent:'hasFooter', equalToParent:'true'},\
					sp:StaticText{text:'', preferredSize:[55, 18]},\
				},\
				dlGrp:Group{\
					alignChildren:['right', 'center'], spacing:6,\
					footerDLLabel:StaticText{\
						text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/divider=Divider:") + "', \
						name:'footerDLLabel', enableParent:'hasFooter', equalToParent:'true', preferredSize:[-1, 18]\
					},\
					footerDLWidth:DropDownList{\
						name:'footerDLWidth', preferredSize:[83,22],\
						enableParent:'hasFooter', equalToParent:'true',\
						selectionTextSuffix:' " + AOM.localizeEsc(AOM.CSConstant.UNIT_PIXELS_ABBR) + "', excludeItem:'None',\
					},\
					sp:StaticText{text:'', preferredSize:[77, 18]},\
				},\
				dlColorGrp:Group{\
					orientation:'column', alignChildren:['right', 'center'],spacing:6, \
					themeType:'syscolorgroup', \
					colorTitle:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/dividerColor=Divider Color:") + "', \
					name:'footerDL', basePreferredSize:[166, 22],\
					enableParent:'hasFooter,footerDLWidth', equalToParent:'true,true', \
				},\
			},\
		},\
	};"
	
	AOM.CS.playbackResource = 
	"Group {\
		orientation:'column', alignment:['fill', 'center'], alignChildren:['fill', 'center'], margins:[8, 10, 0, 10], \
		selects:Group{\
			orientation:'column', alignChildren:['left', 'center'], spacing:6,\
			hasFullScreen:Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/openInFullScreenMode=Open in Full Screen Mode") + "', name:'hasFullScreen'},\
			hasAdvance:Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/hasAdvance=Automatic advance to the next page") + "', name:'hasAdvance'},\
			advances:Group{\
				margins:[15, 0, 0, 0],\
				alignChildren:['left', 'center'], \
				t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/Duration=Duration (second):") + "', preferredSize:[-1, 18]}\
				advanceSeconds:EditText{preferredSize:[35, 18], name:'advanceSeconds', enableParent:'hasAdvance', equalToParent:'true', \
						properties: {borderless:true}, title:'" +AOM.localizeEsc("$$$/ContactSheet/javascript/validation/advanceSeconds=Advance Seconds") + "'},\
			},\
			hasLoop:Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/loopAfterLastPage=Loop After Last Page") + "', name:'hasLoop'}\
		},\
		dynamics:Group{\
			orientation:'column', alignChildren:['right', 'center'], spacing:6,\
			tgrp:Group{\
				alignChildren:['right', 'center'], spacing:6, \
				t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/transition=Transition:") + "', preferredSize:[-1, 18]},\
				transition:DropDownList{preferredSize:[182, 22], name:'transition'}\
			},\
			dgrp:Group{\
				alignChildren:['right', 'center'], spacing:6,\
				directionLabel:StaticText{\
					text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/direction=Direction:") + "',\
					name:'directionLabel', enableParent:'transition,direction', equalToParent:'true,true', preferredSize:[-1, 18]\
				},\
				direction:DropDownList{preferredSize:[152, 22], name:'direction', refParent:'transition', enableParent:'transition', equalToParent:'true'}\
			},\
			sgrp:Group{\
				alignChildren:['right', 'center'], spacing:6,\
				speedLabel:StaticText{\
					text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/speed=Speed:") + "',\
					name:'speedLabel', enableParent:'transition', equalToParent:'true', preferredSize:[-1, 18]\
				},\
				speed:DropDownList{preferredSize:[152, 22], name:'speed', enableParent:'transition', equalToParent:'true'}\
			}\
		}\
	}" ;
		
		
	// Slider width should be set to even number. This is because when the size
	// of the whole slider is set to even, the width of the real visible slider
	// bar is odd, so the indicator can be put at the middle pixel exactly.
	AOM.CS.watermarkResource = 
	"group{\
		orientation:'column', \
		alignment:['fill', 'center'], \
		alignChildren:['fill', 'center'],\
		margins:[8, 10, 10, 10], spacing:6, \
		generalgrp:Group{\
			alignChildren:['right', 'center'],\
			alignment:['left', 'center'],\
			spacing:6, \
			hasWatermark:Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				name:'hasWatermark',\
				alignment:['left', 'center'],\
				title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/addWatermark=Add Watermark:") + "',\
			},\
			wmLayer:DropDownList{\
				name:'wmLayer',\
				preferredSize:[110, 22],\
				enableParent:'hasWatermark', equalToParent:'true', \
			},\
		},\
		eachimagegrp:Group{\
			margins:[15, 0, 0, 0],\
			alignment:'left', \
			spacing:6, \
			alignChildren:['left', 'center'], \
			orientation:'column',\
			enableParent:'hasWatermark', equalToParent:'true', \
			wmAtEachImage:Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				redSize:[100, 18],\
				title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/eachImage=Place on Each Image") + "',\
				name:'wmOnEachImage',\
			},\
		},\
		istextgrp:Group{\
			spacing:6,\
			margins:[15, 6, 0, 1],\
			enableParent:'hasWatermark', equalToParent:'true', \
             hasTextWatermark:Custom{\
				type:'customBoundedValue',\
				themeType:'customradiobutton', \
				alignment:['left', 'center'],\
				name:'hasTextWatermark',\
				checked:'true',\
				text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/insertWMText=Insert Text:") + "', \
				preferredSize:[100, 18],\
            },\
		},\
		textgrp:Group{\
			orientation:'column', \
			alignment:['right', 'center'],\
			alignChildren:['right', 'center'],\
			spacing:9, \
			enableParent:'hasTextWatermark,hasWatermark', equalToParent:'true,true', \
			watermarkText:EditText{\
				name:'watermarkText', properties:{borderless:true},\
				preferredSize:[215, 18],\
			},\
			sysfontgrp:Group{\
				orientation:'column',\
				alignment:['right', 'top'],alignChildren:['right', 'center'],\
				spacing:9, \
				themeType:'sysfontgroup',isApplyFSSlider:true,\
				name:'watermark',basePreferredSize:[181, 22],\
				enableParent:'hasTextWatermark,hasWatermark', equalToParent:'true,true', \
			},\
		},\
		isimagegrp:Group{\
			spacing:6,\
			margins:[15, 6, 0, 3],\
			enableParent:'hasWatermark', equalToParent:'true', \
               hasImageWatermark:Custom{\
				type:'customBoundedValue',\
				themeType:'customradiobutton', \
				alignment:['left', 'center'],\
				margins:[22, 0, 0, 0],\
				name:'hasImageWatermark',\
				text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/insertWMImage=Insert Image:") + "',\
				checked:'false',\
				preferredSize:[100, 18],\
			},\
		},\
		imagegrp:Group{\
			margins:[30, 0, 0, 0],\
			spacing:9,\
			alignment:['right', 'center'],\
			orientation:'column', alignChildren:['right', 'center'], \
			enableParent:'hasImageWatermark,hasWatermark', equalToParent:'true,true', \
			pathgrp:Group{\
				alignChildren:['right','center'],\
				spacing: 6,\
				label:StaticText{\
					name:'label', \
					text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/wmImagePath=Path:") + "', preferredSize:[-1, 18]\
				},\
				wmImagePath:EditText{\
					name:'wmImagePath',\
					preferredSize:['145','18'],\
					properties:{borderless:true},\
				},\
				pathbtn:IconButton{\
					name:'browseWMImage',\
					preferredSize:['30','18'], text:'...',\
				},\
			},\
			scalegrp:Group{\
				alignChildren:['right', 'center'], spacing:6, \
				enableParent:'hasWatermark,hasImageWatermark', equalToParent:'true,true', \
				label:StaticText{\
					name:'label', \
					text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/wmImageScale=Scale:") + "', preferredSize:[-1, 18]\
				},\
				watermarkImageScale:Group{\
					themeType:'hslider', \
					minvalue:1, maxvalue:100, stepdelta:1, value:100, \
					footLabel:'% ',\
					sliderPreferredSize:[112, 22], etPreferredSize:[34, 18], \
					name:'watermarkImageScale',\
				},\
			},\
		},\
		outgrp:Group{\
			orientation:'column',\
			alignment:['fill', 'center'],\
			alignChildren:['right', 'center'],\
			margins:[15, 6, 0, 0], spacing:6,\
			enableParent:'hasWatermark', equalToParent:'true', \
			opacitygrp:Group{\
				alignChildren:['right', 'center'], spacing:6, \
				label:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/opacity=Opacity:") + "', preferredSize:[-1, 18]\
					name:'label',\
				},\
				watermarkOpacity:Group{\
					themeType:'hslider', \
					minvalue:1, maxvalue:100, stepdelta:1, value:100, \
					footLabel:'% ',\
					sliderPreferredSize:[124, 22], etPreferredSize:[34, 18], \
					name:'watermarkOpacity',\
					preferredSize:[0, 5],  text:'',\
				},\
			},\
			offsetgrp:Group{\
				alignChildren:['right', 'center'],\
				spacing:6, orientation:'column',\
				hoffsetgrp:Group{\
					spacing:6,\
					label:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/wmHOffset=H.Offset:") + "',\
						name:'label',preferredSize:[-1, 18]\
					},\
					wmHOffset:Group{\
						themeType:'hslider', \
						minvalue:-100, maxvalue:100, stepdelta:1, value:100, \
						footLabel:'% ',\
						sliderPreferredSize:[124, 22], etPreferredSize:[34, 18], \
						name:'wmHOffset',\
						preferredSize:[0, 5],  text:'',\
					},\
				},\
				voffsetgrp:Group{\
					spacing:6,\
					label:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/wmVOffset=V.Offset:") + "',\
						name:'label', preferredSize:[-1, 18]\
					},\
					wmVOffset:Group{\
						themeType:'hslider', \
						minvalue:-100, maxvalue:100, stepdelta:1, value:100, \
						footLabel:'% ',\
						sliderPreferredSize:[124, 22], etPreferredSize:[34, 18], \
						name:'wmVOffset',\
						preferredSize:[0, 5],  text:'',\
					},\
				},\
			},\
			rotationgrp:Group{\
				spacing:6,\
				margins:[0, 0, 0, 0],\
				alignChildren:['right', 'center'],\
				wmRotation:Group{\
					themeType:'dialgroup',\
					name:'wmRotation',\
					enableParent:'hasWatermark', equalToParent:'true', \
					title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/wmRotation=Rotation:") + "'\
				},\
				aligner:StaticText{\
					preferredSize:[90, 5],  text:'',\
				},\
			},\
		},\
	}";
		
	AOM.CS.savePdfResource = 
	"group{\
		name:'foldgroup',\
		orientation:'column', alignment:['fill', 'top'], alignChildren:['left', 'top'], margins:0, spacing:0,\
		contentgroup:Group{\
			alignChildren:['left', 'bottom'], margins:[20, 10, 10, 10], \
			hasViewPdf:Custom{\
				type:'customBoundedValue',\
				themeType:'customcheckbox', \
				preferredSize:[100, 18],\
				title:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/viewPdfAfterSave=View PDF After Save") + "',name:'hasViewPdf'},\
			t:StaticText{text:'', preferredSize:[24, 22]}, \
			saveBtn:IconButton{\
				text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/saveas=Save...") + "', \
				helpTip:' " + AOM.localizeEsc("$$$/ContactSheet/javascript/tooltip/save=Generate and save PDF file") + "', \
				preferredSize:[81, 22], \
			},\
		}\
	}";


}
