
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2008 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: 2008/04/10 13:35:00 $
*
* Adobe Output Module 2.0
*
* MediaGallery Originally Written by Quality Process Incorporated, Enhanced by
* Adobe System China. Contact Sheet written by Adobe System China.
* 
*
**************************************************************************/

//if hasProgramInteract is true,  it means program modify dropdownlist value, not user interact.
AOM.CS.hasProgramInteract= false;
AOM.CS.hasValid = true;

////////////////////////////////////////////////////////////////////////////////////
AOM.CSManager = function() {}

//designwindow class
AOM.CSManager.DesignWindow = function(container, tabbedPalette) {
	var content = tabbedPalette.content;
	this.currentDocument = content.document;
	
	this.create(container, tabbedPalette);
	this.initialize();
	AOM.theme(this.currentDocument).applyTheme(container, true);
};



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;
	
	if (drawerType == AOM.BridgePreferences.DRAWER_TYPE_CABINET) {
        //add first group 	
    	this.pdfTemplates = this.CSGroup.add(AOM.CS.pdfTemplateResource);
				
		//add separate line, for new UI required.
		this.pdfTemplates.linegrp = this.pdfTemplates.add(
			"group{\
				alignment:['left', 'bottom'], margins:0, \
				line:StaticText{text:'', margins:0, alignment:['left', 'bottom'], preferredSize:[100, 1], themeType:'spline'},\
			}");

   		//create cabinet
   		var cabinet = new AOM.Cabinet(this.CSGroup);
				
		//write foldableSet onClickFoldableSection callback
		cabinet.onClickFoldableSection = function(openCloseButton) {
			AOM.userInput(currentDocument).set(openCloseButton.name, openCloseButton.isOpen);   
		}
        		
        //add cabinet section
        this.documents = cabinet.addFoldableSection(AOM.CS.documentResource, "Document", AOM.localize("$$$/ContactSheet/javascript/title/document=Document"));	
        this.layouts = cabinet.addFoldableSection(AOM.CS.layoutResource, "Layout", AOM.localize("$$$/ContactSheet/javascript/title/layout=Layout"));		
        this.overlays = cabinet.addFoldableSection(AOM.CS.overlaysResource, "Overlays", AOM.localize("$$$/ContactSheet/javascript/title/overlays=Overlays"));
        this.playbacks = cabinet.addFoldableSection(AOM.CS.playbackResource, "Playback", AOM.localize("$$$/ContactSheet/javascript/title/playback=Playback"));
        this.watermarks = cabinet.addFoldableSection(AOM.CS.watermarkResource, "Watermark", AOM.localize("$$$/ContactSheet/javascript/title/watermark=Watermark"));
		this.savePdfs = cabinet.addSection(AOM.CS.savePdfResource, "savePdf");
        
        //apply custom layout manager to group
        this.CSGroup.layout = new AOM.CabinetLayoutManager(this.CSGroup);
        		
	} else if (drawerType == AOM.BridgePreferences.DRAWER_TYPE_ACCORDION) {
		var accordion = new AOM.Accordion(this.CSGroup);
				
		//wrtei foldableSet onClickFoldableSection callback
		accordion.onClickFoldableSection = function(openCloseButton) {
			var selectedSection = this.getSelectedSectionByName(openCloseButton.name);
			AOM.userInput(currentDocument).set("pdfselectedSection", selectedSection);  
		}
        	
		this.pdfTemplates = accordion.addSection(AOM.CS.pdfTemplateResource, "pdfTemplate");
        this.documents = accordion.addFoldableSection(AOM.CS.documentResource, "Document", AOM.localize("$$$/ContactSheet/javascript/title/document=Document"));	
        this.layouts = accordion.addFoldableSection(AOM.CS.layoutResource, "Layout", AOM.localize("$$$/ContactSheet/javascript/title/layout=Layout"));		
        this.overlays = accordion.addFoldableSection(AOM.CS.overlaysResource, "Overlays", AOM.localize("$$$/ContactSheet/javascript/title/overlays=Overlays"));
        this.playbacks = accordion.addFoldableSection(AOM.CS.playbackResource, "Playback", AOM.localize("$$$/ContactSheet/javascript/title/playback=Playback"));
        this.watermarks = accordion.addFoldableSection(AOM.CS.watermarkResource, "Watermark", AOM.localize("$$$/ContactSheet/javascript/title/watermark=Watermark"));
		this.savePdfs = accordion.addSection(AOM.CS.savePdfResource, "savePdf");
		
		//set open/close status
		var selectedSection = AOM.userInput(currentDocument).get("pdfselectedSection");
		if (selectedSection == undefined || selectedSection.length == 0) {
			this.CSGroup.selectedSection = "Document";
		} else {
			this.CSGroup.selectedSection = selectedSection;
		}
        	
		this.CSGroup.layout = new AOM.AccordionLayoutManager(this.CSGroup);
	} else {
    	throw new Error("AOM.CSManager.DesignWindow.create() throw an exception, not implement the type of drawer:" + drawerType);
	}
}


AOM.CSManager.DesignWindow.prototype.initialize = function() {
	var currentDocument = this.currentDocument;
	
	this.loadData(this.CSGroup, AOM.userInput(currentDocument));
	this.loadSpecialData(true);	
	this.initEventHandlers();
};


AOM.CSManager.DesignWindow.prototype.loadData = function(group, userInput, theme) {
try {
	for (var i = 0; i < group.children.length; i++) {
		var child = group.children[i];
			
		if (child instanceof Group) {
			this.loadData(child, userInput, theme);
		} else {
			var name = child.name;
			
			if (name != undefined) {
				var type = child.type;
				if (child.themeType != undefined)  {type = child.themeType;}

				var value =userInput.get(child.name);
				
				if (value == undefined) { value = ""; }
				switch(type.toLowerCase()) {
				case "checkbox" :
					child.value = AOM.CS.CString.strToBoolean(value);
					AOM.CS.UIUtils.setEnableStatus(child, userInput, theme);
					break;
				case "edittext" :
					if (child.dataType == "Float") {
						child.text = AOM.CS.Locale.toLocaleString(value);
						userInput.setElement(child);
					} else {
						child.text = value;
					}
					AOM.CS.UIUtils.setEnableStatus(child, userInput, theme);
					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 = AOM.CS.UIUtils.setDropDownList(child, newItems, value, true);
							if (selectedValue != value) {userInput.set(name, selectedValue); }
						}
					
						AOM.CS.UIUtils.setEnableStatus(child, userInput, theme);
					} 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.rsetDropDownList(child, newItems, value, true);
								userInput.setElement(child);
							} 
						} else {
							child.enabled = child.gsEnabled = false;
						}
					}
					break;
				case "imagebutton" :
					child.btPressed = AOM.CS.CString.strToBoolean(value);
					child.notify("onDraw");
					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;
					}
				
					AOM.CS.UIUtils.setEnableStatus(child, userInput, theme);
					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) {
						var control = child.refControl =  new AOM.AmgNumericStepper();
						control.createControl(parent);
						control.setSlider({
							minvalue: child.minvalue,
							maxvalue: child.maxvalue,
							stepdelta: 1,
							preferredSize:child.sliderPreferredSize,
						});

						control.setFootLabel({text:AOM.localizeEsc(child.footLabel)}); 
						control.setEditText({preferredSize:child.etPreferredSize});
						
						control.setValue(parseFloat(value));
					} else {
						var control = child.refControl ;
						control.setValue(parseFloat(value));
					}
					break;
				case "radiobutton" : 
				    if (value == "") {
                        value = child.checked;
                        userInput.set(child.name, value);
                    }
					child.value = AOM.CS.CString.strToBoolean(value);
					break;
				default:
					break;
				}
			}
		}
	}
} catch(e) {
	AOM.CS.Log.writeError("loadData():" + e);
}
}

/****
 *  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 overlaysLayer=  this.overlays;
	var currentDocument = this.currentDocument;
	
	//load current system font (used for early initialization)
	var loadCurrentSystemFont = function(fontControl, fontFaceControl)
	{
		var userInput = AOM.userInput(currentDocument);
		var displayValue = userInput.get(fontControl.name + "_display");
		var value = userInput.get(fontControl.name);
		var faceDisplayValue = userInput.get(fontFaceControl.name + "_display");
		var faceValue = userInput.get(fontFaceControl.name);
		
		var item;
		item = fontControl.add("item", displayValue);
		item.value = value;
		item.selected = true;
		item = fontFaceControl.add("item", faceDisplayValue);
		item.value = faceValue;
		item.selected = true;
	}
	
	//load all system fonts (used for lazy initialization)
	var loadSystemFonts = function(fontControl, fontFaceControl) {
		var userInput = AOM.userInput(currentDocument);
		var fontValue = userInput.get(fontControl.name);
		var fontFaceValue = userInput.get(fontFaceControl.name);

		//get old value
		var oldFontValue = undefined;
		if (fontControl.items.length > 0 && fontControl.selection != undefined) {		
			oldFontValue = fontControl.selection.value;
		}
		
		//if font is empty, add all, else only change select value.
		var families = AOM.PDFGenerator.getSystemFontFamilies();
		if(families.errors != undefined && families.errors.length != 0) {
			for(var i = 0; i < families.errors.length; ++i)
				AOM.CS.Log.writeError("Font handling error: " + families.errors[i] + ".");
		}
			
		fontValue = AOM.CS.UIUtils.setDropDownList(fontControl, families.sort(), fontValue, true, true);

		//if font not changed, only change font face selection value, otherwise removeall and add all
		var faces = AOM.PDFGenerator.getSystemFontFaces(fontValue);
		if (oldFontValue == undefined || oldFontValue != fontValue) {
			//changed
			AOM.CS.UIUtils.rsetDropDownList(fontFaceControl, faces, fontFaceValue, true, true);
		} else {
			AOM.CS.UIUtils.setDropDownList(fontFaceControl, faces, fontFaceValue, true, true);
		}
		
		userInput.setElement(fontControl);
		userInput.setElement(fontFaceControl);
	}


	AOM.CS.hasProgramInteract = true;
	var currentTemplate = pdfTemplates.tgrp.template;
	var currentSelectedTemplate = AOM.userInput(currentDocument).get(currentTemplate.name);
	if (currentSelectedTemplate != AOM.CSConstant.CUSTOM) {
		//remove custom item.
		for (var i = 0; i < currentTemplate.items.length; i++) {
			var currentItem = currentTemplate.items[i];
			if (currentItem.value == AOM.CSConstant.CUSTOM) {
				currentTemplate.remove(currentItem);
			}
		}
	}
	
	//load fileNameFonts (early init only)
	var fileNameFont = overlaysLayer.rgrp.fontgrp.fileNameFont;
	var fileNameFontFace = overlaysLayer.rgrp.fontgrp.fileNameFontFace;
	if(lazy)
		loadCurrentSystemFont(fileNameFont, fileNameFontFace);
	
	//load watermarkFonts (early init only)
	var watermarks = this.watermarks;
	var watermarkFont = watermarks.outgrp.fontgrp.watermarkFont;
	var watermarkFontFace = watermarks.outgrp.fontgrp.watermarkFontFace;
	if(lazy)
		loadCurrentSystemFont(watermarkFont, watermarkFontFace);
	
	if(lazy) {
		var fileNameFontInit = function() { 
			AOM.CS.hasProgramInteract = true;
			if(fileNameFont.initialized != true) {
				fileNameFont.removeAll();
				loadSystemFonts(fileNameFont, fileNameFontFace);
				fileNameFont.initialized = true;
			}
			fileNameFont.removeEventListener("mousedown", fileNameFontInit);
			fileNameFontFace.removeEventListener("mousedown", fileNameFontInit);
			AOM.CS.hasProgramInteract = false;
		};
		var	watermarkFontInit = function() {
			AOM.CS.hasProgramInteract = true;
			watermarkFont.removeAll();
			loadSystemFonts(watermarkFont, watermarkFontFace);
			watermarkFont.removeEventListener("mousedown", watermarkFontInit);
			watermarkFontFace.removeEventListener("mousedown", watermarkFontInit);
			AOM.CS.hasProgramInteract = false;
		};
		fileNameFont.addEventListener("mousedown", fileNameFontInit);
		fileNameFontFace.addEventListener("mousedown", fileNameFontInit);
		watermarkFont.addEventListener("mousedown", watermarkFontInit);
		watermarkFontFace.addEventListener("mousedown", watermarkFontInit);
	} else {
		AOM.CS.hasProgramInteract = true;
		if(fileNameFont.initialized != true) {
			fileNameFont.initialized = true;
			fileNameFont.removeAll();
		}
		loadSystemFonts(fileNameFont, fileNameFontFace);
		AOM.CS.hasProgramInteract = false;
	}
		
	AOM.CS.hasProgramInteract = false;
}

AOM.CS.UIUtils.setEnableStatus = function(ele, userInput, theme) {
try {
	var enableParent = ele.enableParent;
	if (enableParent !=undefined) {
		var eparentValue = userInput.get(enableParent)
		if (eparentValue == undefined)
			eparentValue = "false";
		else
			eparentValue = eparentValue.toString().toLowerCase();

		var equalToParent = ele.equalToParent;

		if (equalToParent == "none") {
			if (eparentValue == equalToParent) {
				ele.enabled = ele.gsEnabled = false;
			} else {
				ele.enabled = ele.gsEnabled = true;
			}
		} else {
			//else is always true or false
			if (eparentValue == equalToParent) {
				ele.enabled = ele.gsEnabled = true;
			} else {
				ele.enabled = ele.gsEnabled = false;
			}
		}
	
		if (theme != undefined && ele.type.toLowerCase() == "edittext") {
			theme.setEditTextDisableBgColor(ele);
		}
	}
} catch(e) {
	AOM.CS.Log.writeError('enable error:'  + e);
}
}

AOM.CS.UIUtils.getUnitText = function(spaceToUnit) {
	var spaceUnitValue;
	if (spaceToUnit == AOM.CSConstant.UNIT_INCHES) {
		spaceUnitValue = AOM.CSConstant.SPACE_UNIT_IN;
	} else if (spaceToUnit == AOM.CSConstant.UNIT_PIXELS) {
		spaceUnitValue = AOM.CSConstant.SPACE_UNIT_PX;
	} else {
		spaceUnitValue = AOM.CSConstant.SPACE_UNIT_CM;
	}

	return spaceUnitValue;
}


AOM.CSManager.DesignWindow.prototype.initEventHandlers = function() {
	var currentDocument = this.currentDocument;
	
	this.initBasicEventHandler(this.CSGroup, currentDocument);
	this.initPdfTemplatesEventHandlers();
	this.initDocumentEventHandlers();
	this.initLayoutEventHandlers();
	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];
			
		if (child instanceof Group) {
			this.initBasicEventHandler(child, currentDocument);
		} else {
			if (child.name != undefined) {
				var name = child.name;
				var type = child.type;
				if (child.themeType != undefined)  {type = child.themeType;}
				
				switch(type.toLowerCase()) {
				case "checkbox" :
					child.onClick  = function() {
						AOM.userInput(currentDocument).setElement(this);
						
						//change template
						AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
					}
					break;
				case "edittext" :
					child.onChange = function() {
						AOM.userInput(currentDocument).setElement(this);
					}
					break;
				case "sdropdownlist" :
				case "dropdownlist" :
					child.onChange = function() {
						if (AOM.CS.hasProgramInteract) {
							AOM.userInput(currentDocument).setElement(this);
						} else {
							if (this.selection != undefined) {
								AOM.userInput(currentDocument).setElement(this);
								
								//change template
								AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
							}
						}
					}
					break;
				case "hslider" :
					var control = child.refControl;
					if (control != undefined && control instanceof AOM.AmgNumericStepper) {
						control.onChange = function() {
							AOM.userInput(currentDocument).set(name, this.value);
						}
					}
					break;
				case "radiobutton" :
					child.onClick = function() {
						AOM.userInput(currentDocument).setElement(this);
					}
					break;
				default :
					break;
				}
			}
		}
	}
}

AOM.CSManager.DesignWindow.prototype.initKeyboardEventListener = function() {
	var layoutLayer = this.layouts;
	var docLayer = this.documents;
	var playbackLayer = this.playbacks;
	
	docLayer.wgrp.grp.pageWidth.addEventListener('keydown',  AOM.CS.Keyboards.numericEditKeyBoardHandler);
	docLayer.hgrp.grp.pageHeight.addEventListener('keydown',  AOM.CS.Keyboards.numericEditKeyBoardHandler);
	
	var layoutgrp = layoutLayer.grp.layoutgrp;
	var margingrp = layoutLayer.grp.margingrp;	
	
	layoutgrp.setRow.pageRows.addEventListener('keydown', AOM.CS.Keyboards.rowAndColumnEditKeyBoardHandler);
	layoutgrp.setCol.pageColumns.addEventListener('keydown', AOM.CS.Keyboards.rowAndColumnEditKeyBoardHandler);
	
	layoutgrp.horizontal.setVal.horizontalSpacing.addEventListener('keydown',  AOM.CS.Keyboards.numericEditKeyBoardHandler);
	layoutgrp.vertical.setVal.verticalSpacing.addEventListener('keydown',  AOM.CS.Keyboards.numericEditKeyBoardHandler);

	margingrp.setTop.topMargin.addEventListener('keydown',  AOM.CS.Keyboards.numericEditKeyBoardHandler);
	margingrp.setBottom.bottomMargin.addEventListener('keydown',  AOM.CS.Keyboards.numericEditKeyBoardHandler);
	margingrp.setLeft.leftMargin.addEventListener('keydown',  AOM.CS.Keyboards.numericEditKeyBoardHandler);
	margingrp.setRight.rightMargin.addEventListener('keydown',  AOM.CS.Keyboards.numericEditKeyBoardHandler);
	
	playbackLayer.selects.advances.advanceSeconds.addEventListener('keydown',  AOM.CS.Keyboards.rowAndColumnEditKeyBoardHandler);	
}


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;
	
	pdfTemplates.refreshgrp.refreshPreview.onClick = function() {
		//before check
		if (File.fs == "Macintosh") {
			/*
			//docLayer
			if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.wgrp.grp.pageWidth))  return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.hgrp.grp.pageHeight)) return;

			//layoutLayer
			var layoutgrp = layoutLayer.grp.layoutgrp;
			var margingrp = layoutLayer.grp.margingrp;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(layoutgrp.setCol.pageColumns)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(layoutgrp.setRow.pageRows)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(layoutgrp.horizontal.setVal.horizontalSpacing)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(layoutgrp.vertical.setVal.verticalSpacing)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(margingrp.setTop.topMargin)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(margingrp.setBottom.bottomMargin)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(margingrp.setLeft.leftMargin)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(margingrp.setRight.rightMargin)) return;
							
			//plabackLayer
			if (!AOM.CS.UIUtils.checkEditTextOnMac(playbackLayer.selects.advances.advanceSeconds))  return;
			
			//watermarks
			if (!AOM.CS.UIUtils.checkEditTextOnMac(watermarks.textgrp.watermarkText)) return;
			
			//last but not least , check pass
			if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.docgrp.docPass.docPass))  return;
			*/
			if (AOM.CS.hasValid == false) {
				AOM.CS.hasValid = true;
				return;
			}
		}
		
        //check preview palette has initialized.
		AOM.PreviewPanel.checkPreviewPalette(currentDocument);
        	
		//after
		var pdfMaker = new AOM.CS.PDFMaker(currentDocument);
		pdfMaker.generatePDF(true);
		pdfMaker.destroy();
	}

	var designWindow = this;
	pdfTemplates.tgrp.template.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput(currentDocument).setElement(this);
		} else {
			if (this.selection != undefined) {
				AOM.userInput(currentDocument).setElement(this);
			
				var currentTemplate = this.selection.value;
				if (currentTemplate == AOM.CSConstant.CUSTOM) return ;
				
				var templatePath = AOM.CS.Paths.customTemplate + currentTemplate + ".json";
				var templateFile = new File(templatePath);

				if (!templateFile.open("r") || templateFile.length <= 35) { 
					AOM.CS.hasProgramInteract = true;
					this.remove(this.selection);
					AOM.CS.UIUtils.setDropDownListSelection(this, AOM.CSConstant.CUSTOM ,true);
					AOM.CS.hasProgramInteract = false;
						
					AOM.CS.UIUtils.alertLocale("$$$/ContactSheet/javascript/template/cannotLoadTemplate=Can not load the template file caused by system error.");
					return ;
				} else {
					var json = templateFile.read();
					templateFile.close();
					eval(json);
						
					var data = AOM.CS.UserInput.persistedData;
					if (data == undefined && data.length <=0) {
						AOM.CS.UIUtils.alertLocale("$$$/ContactSheet/javascript/template/cannotLoadTemplate=Can not load the template file caused by system error.");
						return ;
					} else{
						var theme = AOM.theme(currentDocument);
						var userInput = AOM.userInput(currentDocument);
						//userInput.data = new Object();
						for (var i = 0; i < data.length; i++) {
							var field = data[i];
							userInput.set(field.id, File.decode(field.value));
						}
							
						AOM.CS.hasProgramInteract = true;
						designWindow.loadData(designWindow.CSGroup, userInput, theme);
						designWindow.loadSpecialData(false);
						
						//remove custom item if exists.
						for (var i = 0; i < this.items.length; i++) {
							var currentItem = this.items[i];
							if (currentItem.value == AOM.CSConstant.CUSTOM) {
								this.remove(currentItem);
							}
						}
						
						AOM.CS.hasProgramInteract = false;
					}
				}
			}
		}
	}
}

AOM.CS.UIUtils.changePortraitOrLandscape = function(docLayer, width, height) {
	var width = AOM.CS.Locale.parseFloat(width);
	var height = AOM.CS.Locale.parseFloat(height);
	if (width <= height) {
		//alert('call pagePortrait' + width + "<=" + height);
		docLayer.hgrp.grp.pagePortrait.notify("onClick");
	} else {
		//alert('call landscape' + width + ">" + height);
		docLayer.hgrp.grp.pageLandscape.notify("onClick");
	}
}


AOM.CS.UIUtils.changePageSize = function(docLayer,layoutLayer, pageSizeSelectedValue, userInput) {	
	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.text = AOM.CS.Locale.toLocaleString(sizeInfo.width);
		pageHeight.text = AOM.CS.Locale.toLocaleString(sizeInfo.height);
		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);
		//if (oldUnitValue != newUnitValue) {
			AOM.CS.UIUtils.changeLayoutUnitControlles(layoutLayer, userInput, oldUnitValue, newUnitValue);
		//}
		
		//change portrait or landscape
		AOM.CS.UIUtils.changePortraitOrLandscape(docLayer, sizeInfo.width, sizeInfo.height);
	}
}


AOM.CS.UIUtils.changeLayoutUnitControlles = function(layoutLayer, userInput, spaceFromUnit, spaceToUnit) {
	var layoutgrp = layoutLayer.grp.layoutgrp;
	var margingrp = layoutLayer.grp.margingrp;	
		
	//get static text value
	var spaceUnitValue;
	if (spaceToUnit == AOM.CSConstant.UNIT_INCHES) {
		spaceUnitValue = AOM.CSConstant.SPACE_UNIT_IN;
	} else if (spaceToUnit == AOM.CSConstant.UNIT_PIXELS) {
		spaceUnitValue = AOM.CSConstant.SPACE_UNIT_PX;
	} else {
		spaceUnitValue = AOM.CSConstant.SPACE_UNIT_CM;
	}
			
	var changeLayoutControllerByUnit = function(element, userInput) {
		if (spaceFromUnit == undefined || spaceFromUnit.length == 0) {
			//
		} else {
			element.text = AOM.CS.CommonFuncs.unitConvertion(spaceFromUnit, spaceToUnit, element.text);
		}
		element.parent.t.text = spaceUnitValue;
		userInput.setElement(element);
	}
			
	changeLayoutControllerByUnit(layoutgrp.horizontal.setVal.horizontalSpacing, userInput);
	changeLayoutControllerByUnit(layoutgrp.vertical.setVal.verticalSpacing, userInput);
	changeLayoutControllerByUnit(margingrp.setTop.topMargin, userInput);
	changeLayoutControllerByUnit(margingrp.setBottom.bottomMargin, userInput);
	changeLayoutControllerByUnit(margingrp.setLeft.leftMargin, userInput);
	changeLayoutControllerByUnit(margingrp.setRight.rightMargin, userInput);
}

AOM.CS.UIUtils.checkEditTextOnMac = function(ele) {
	AOM.CS.hasValid = true;
	ele.notify("onChange");
	if (AOM.CS.hasValid == false) {
		return false;
	} else {
		return true;
	}
}

AOM.CS.UIUtils.checkEditTextHasUnitOnMac = function(ele, pageUnit, fromUnit) {
	AOM.CS.hasValid = true;
	ele.notify("onChange");
	if (AOM.CS.hasValid == false) {
		AOM.CS.hasProgramInteract = true;
		AOM.CS.UIUtils.setDropDownListSelection(pageUnit, fromUnit);
		AOM.CS.hasProgramInteract = false;
		return false;
	} else {
		return true;
	}
}


AOM.CS.UIUtils.changeTemplate = function(pdfTemplates, userInput) {
	var currentTemplate = pdfTemplates.tgrp.template;
	if (AOM.CS.hasProgramInteract) {
		AOM.CS.UIUtils.changeToCustom(currentTemplate, userInput);	
	} else {
		AOM.CS.hasProgramInteract = true;
		AOM.CS.UIUtils.changeToCustom(currentTemplate, userInput);	
		AOM.CS.hasProgramInteract = false;
	}
}

AOM.CS.UIUtils.changeToCustom = function(currentTemplate, userInput) {
	//change to custom item.
	if (currentTemplate.selection.value != AOM.CSConstant.CUSTOM) {
		var customItem = currentTemplate.add(
			"item", AOM.localize("$$$/ContactSheet/javascript/dropdownlist/templateCustom=Custom"));
		customItem.value = AOM.CSConstant.CUSTOM;
		currentTemplate.selection = customItem;
		userInput.setElement(currentTemplate);
	}
}

AOM.CS.UIUtils.setEnabledProps = function(group, enabled, theme) {
	for (var i = 0; i < group.children.length; i++) {
		var child = group.children[i];
		if (child instanceof Group) {
			AOM.CS.UIUtils.setEnabledProps(child, enabled, theme);
		} else {
			if (child.type == "edittext") {
				child.gsEnabled = child.enabled = enabled;
				theme.setEditTextDisableBgColor(child);
			} else {
				child.gsEnabled = child.enabled = enabled;
			}
		}
	}
}

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.CSManager.DesignWindow.prototype.initDocumentEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var layoutLayer = this.layouts;
	var docLayer = this.documents;
	var currentDocument = this.currentDocument;
	
	//pagePreset - dropdownlist
	docLayer.pagegrp.pagePreset.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput(currentDocument).setElement(this);
		} else {
			if (this.selection != undefined) {
				//get changed value
				var pagePresetSelectedValue = this.selection.value;
				AOM.userInput(currentDocument).setElement(this);
				
				AOM.CS.hasProgramInteract = true;
				
				//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);
				
				//change pageSize infos
				AOM.CS.UIUtils.changePageSize(docLayer,layoutLayer, pageSizeSelectedValue, AOM.userInput(currentDocument));		
				
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
				
				AOM.CS.hasProgramInteract = false;
			
				AOM.userInput(currentDocument).setElement(pageSize);
			}
		}	
	}

	//pageSize - dropdownlist
	docLayer.sgrp.pageSize.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput(currentDocument).setElement(this);
		} else {
			if (this.selection != undefined) {
				var pageSizeSelectedValue = this.selection.value;
				AOM.userInput(currentDocument).setElement(this);
		
				AOM.CS.hasProgramInteract = true;
				//change pageSize infoes
				AOM.CS.UIUtils.changePageSize(docLayer, layoutLayer, pageSizeSelectedValue, AOM.userInput(currentDocument));		
				
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
				
				AOM.CS.hasProgramInteract = false;
			}
		}
	}
	
	//pageWidth - edittext
	docLayer.wgrp.grp.pageWidth.onChange = function() {
		var oldValue = AOM.userInput(currentDocument).get(this.name);
		var newValue = AOM.CS.Validation.checkHasUnitNumber(this.title, this.text, false, AOM.userInput(currentDocument).get("pageUnit"), currentDocument);
		
		if (newValue >= 0) {
			this.text = AOM.CS.Locale.toLocaleString(newValue);
			AOM.userInput(currentDocument).setElement(this);
		
			if (this.text != oldValue) {
				//set pagePreset and pageSize is custom
				AOM.CS.UIUtils.setDropDownListSelection(docLayer.pagegrp.pagePreset, AOM.CSConstant.CUSTOM, true);
			
				//change portrailt and landscape and template
				AOM.CS.hasProgramInteract = true;
				AOM.CS.UIUtils.changePortraitOrLandscape(docLayer, this.text, docLayer.hgrp.grp.pageHeight.text);
				
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
				
				AOM.CS.hasProgramInteract = false;	
			}
			AOM.CS.hasValid = true;
		} else {
			this.text = oldValue;
			AOM.CS.hasValid = false;
		}
	}

	//pageHeight - edittext
	docLayer.hgrp.grp.pageHeight.onChange = function() {
		var oldValue = AOM.userInput(currentDocument).get(this.name);
		var newValue = AOM.CS.Validation.checkHasUnitNumber(this.title, this.text, false, AOM.userInput(currentDocument).get("pageUnit"), currentDocument);
		
		if (newValue >= 0) {
			this.text = AOM.CS.Locale.toLocaleString(newValue);
			AOM.userInput(currentDocument).setElement(this);
		
			if (this.text != oldValue) {
				AOM.CS.UIUtils.setDropDownListSelection(docLayer.pagegrp.pagePreset, AOM.CSConstant.CUSTOM, true);
				
				AOM.CS.hasProgramInteract = true;
				AOM.CS.UIUtils.changePortraitOrLandscape(docLayer, docLayer.wgrp.grp.pageWidth.text, this.text);
				
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
				
				AOM.CS.hasProgramInteract = false;
			}
			AOM.CS.hasValid = true;
		} else {
			this.text = oldValue;
			AOM.CS.hasValid = false;
		}
	}

	//pageUnit - dropdownliste
	docLayer.wgrp.grp.pageUnit.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput(currentDocument).setElement(this);
			this.notify("onDraw");
		} else {
			var userInput = AOM.userInput(currentDocument);
			var fromUnit = userInput.get(this.name);

			 if (File.fs == "Macintosh") {
				var layoutgrp = layoutLayer.grp.layoutgrp;
				var margingrp = layoutLayer.grp.margingrp;
				if (!AOM.CS.UIUtils.checkEditTextHasUnitOnMac(docLayer.wgrp.grp.pageWidth, this, fromUnit))  return;
				if (!AOM.CS.UIUtils.checkEditTextHasUnitOnMac(docLayer.hgrp.grp.pageHeight, this, fromUnit)) return;
				if (!AOM.CS.UIUtils.checkEditTextHasUnitOnMac(layoutgrp.horizontal.setVal.horizontalSpacing, this, fromUnit)) return;
				if (!AOM.CS.UIUtils.checkEditTextHasUnitOnMac(layoutgrp.vertical.setVal.verticalSpacing, this, fromUnit)) return;
				if (!AOM.CS.UIUtils.checkEditTextHasUnitOnMac(margingrp.setTop.topMargin, this, fromUnit)) return;
				if (!AOM.CS.UIUtils.checkEditTextHasUnitOnMac(margingrp.setBottom.bottomMargin, this, fromUnit)) return;
				if (!AOM.CS.UIUtils.checkEditTextHasUnitOnMac(margingrp.setLeft.leftMargin, this,fromUnit)) return;
				if (!AOM.CS.UIUtils.checkEditTextHasUnitOnMac(margingrp.setRight.rightMargin, this, fromUnit)) return;
			}
			
			//after
			var pageWidth = this.parent.pageWidth;
			var pageHeight = docLayer.hgrp.grp.pageHeight;
			var toUnit = this.selection.value;
		
			pageWidth.text = AOM.CS.CommonFuncs.unitConvertion(fromUnit, toUnit , pageWidth.text);
			pageHeight.text = AOM.CS.CommonFuncs.unitConvertion(fromUnit, toUnit, pageHeight.text);
			userInput.setElement(pageWidth);
			userInput.setElement(pageHeight);
			
			userInput.setElement(this);
		
			//change layout unit
			if(fromUnit != toUnit) {
				AOM.CS.UIUtils.changeLayoutUnitControlles(layoutLayer, userInput, fromUnit, toUnit);
			}
		}
	}

	//pagePortrait - iconbutton
	docLayer.hgrp.grp.pagePortrait.onClick = function() {
		if (this.btPressed == false) {
			var pageLandscape = this.parent.pageLandscape;
			
			//before check
			 if (File.fs == "Macintosh") {
				 /*
				if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.wgrp.grp.pageWidth))  return;
				if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.hgrp.grp.pageHeight)) return;
				*/
				if (AOM.CS.hasValid == false) {
					AOM.CS.hasValid = true;
					return;
				}
			}
			
			//after 
			this.btPressed = true;
			pageLandscape.btPressed = false;
			AOM.userInput(currentDocument).setElement(this);
			AOM.userInput(currentDocument).setElement(pageLandscape);
			
			var pageWidth = docLayer.wgrp.grp.pageWidth;
			var pageHeight = docLayer.hgrp.grp.pageHeight;
			if ((AOM.CS.Locale.parseFloat(pageWidth.text) - AOM.CS.Locale.parseFloat(pageHeight.text)) > 0) {   
				var tempText = pageWidth.text;
				pageWidth.text = pageHeight.text;
				pageHeight.text = tempText;
				
				AOM.userInput(currentDocument).setElement(pageWidth);
				AOM.userInput(currentDocument).setElement(pageHeight);
			}
		
			//change template
			if (!AOM.CS.hasProgramInteract) {
				AOM.CS.hasProgramInteract = true;
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
				var pagePreset = docLayer.pagegrp.pagePreset;
				if (pagePreset.selection.value != AOM.CSConstant.CUSTOM) {
					AOM.CS.UIUtils.setDropDownListSelection(docLayer.pagegrp.pagePreset, AOM.CSConstant.CUSTOM, true);
					var pageSize = docLayer.sgrp.pageSize;
					var newItems = AOM.CS.UIUtils.getItemListByDefaultItems(pageSize.name, AOM.CSConstant.CUSTOM);
					AOM.CS.UIUtils.setDropDownList(pageSize, newItems, AOM.CSConstant.CUSTOM, true);
					AOM.userInput(currentDocument).setElement(pagePreset);
					AOM.userInput(currentDocument).setElement(pageSize);
				} 
				AOM.CS.hasProgramInteract = false;
			}
		
			this.notify("onDraw");
			this.parent.pageLandscape.notify("onDraw");
		}
	}
	
	docLayer.hgrp.grp.pageLandscape.onClick = function() {
		if (this.btPressed == false) {
			var pagePortrait = this.parent.pagePortrait;
			
			//before check
			 if (File.fs == "Macintosh") {
				 /*
				if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.wgrp.grp.pageWidth))  return;
				if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.hgrp.grp.pageHeight)) return;
				*/
				if (AOM.CS.hasValid == false) {
					AOM.CS.hasValid = true;
					return;
				}
			}
			
			//after
			this.btPressed = true;
			pagePortrait.btPressed = false;
			AOM.userInput(currentDocument).setElement(this);
			AOM.userInput(currentDocument).setElement(pagePortrait);

			var pageWidth = docLayer.wgrp.grp.pageWidth;
			var pageHeight = docLayer.hgrp.grp.pageHeight;
			
			if ((AOM.CS.Locale.parseFloat(pageWidth.text) - AOM.CS.Locale.parseFloat(pageHeight.text)) < 0) {
				var tempText = pageWidth.text;
				pageWidth.text = pageHeight.text;
				pageHeight.text = tempText;
				
				AOM.userInput(currentDocument).setElement(pageWidth);
				AOM.userInput(currentDocument).setElement(pageHeight);
			}  
		
			//change template
			if (!AOM.CS.hasProgramInteract) {
				AOM.CS.hasProgramInteract = true;
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
				var pagePreset = docLayer.pagegrp.pagePreset;
				if (pagePreset.selection.value != AOM.CSConstant.CUSTOM) {
					AOM.CS.UIUtils.setDropDownListSelection(docLayer.pagegrp.pagePreset, AOM.CSConstant.CUSTOM, true);
					var pageSize = docLayer.sgrp.pageSize;
					var newItems = AOM.CS.UIUtils.getItemListByDefaultItems(pageSize.name, AOM.CSConstant.CUSTOM);
					AOM.CS.UIUtils.setDropDownList(pageSize, newItems, AOM.CSConstant.CUSTOM, true);
					AOM.userInput(currentDocument).setElement(pagePreset);
					AOM.userInput(currentDocument).setElement(pageSize);
				} 
				AOM.CS.hasProgramInteract = false;
			}
		
			this.notify("onDraw");
			this.parent.pagePortrait.notify("onDraw");
		}
	}

	//backgroundColorPicker - button
	docLayer.bggrp.bgVal.pageBackgroundColor.onClick = function() {
		var gfx = this.graphics;
		var oldRGB = eval(AOM.userInput(currentDocument).get(this.name));
		var oldColorValue = AOM.CS.UIUtils.setColorToColorPicker(oldRGB);
		var selectedColor = $.colorPicker(oldColorValue);
		
		if (selectedColor == undefined || selectedColor == -1) return;
		
		var rgb= AOM.CS.UIUtils.getColorFromColorPicker(selectedColor);
		gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, rgb);
		AOM.userInput(currentDocument).set(this.name, rgb.toSource());
		AOM.userInput(currentDocument).set("pageBackgroundColorCustom",rgb.toSource());
		
		//set pageBackground value
		AOM.CS.UIUtils.setDropDownListSelection(this.parent.pageBackground, AOM.CSConstant.COLOR_CUSTOM, true);
	}

	//background - dropdownlist
	docLayer.bggrp.bgVal.pageBackground.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput(currentDocument).setElement(this);
		} else {
			if (this.selection != undefined) {
				var selectedValue = this.selection.value;			
				var pageBackgroundColor = this.parent.pageBackgroundColor;
				var gfx = pageBackgroundColor.graphics;
			
				switch(selectedValue) {
				case AOM.CSConstant.COLOR_WHITE:
					gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, [1, 1, 1]);
					break;
				case AOM.CSConstant.COLOR_BLACK:
					gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, [0, 0, 0]);
					break;
				case AOM.CSConstant.COLOR_CUSTOM:
					var rgb = eval(AOM.userInput(currentDocument).get("pageBackgroundColorCustom"));
					if(rgb) {
						gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, rgb );
						AOM.userInput(currentDocument).set(pageBackgroundColor.name, rgb); 
					}
					break;
				default:
					break;
				}
		
				AOM.userInput(currentDocument).setElement(this);
				AOM.userInput(currentDocument).set(pageBackgroundColor.name, gfx.customBgColor.color.toSource());
			}
			this.parent.pageBackgroundColor.notify("onDraw");
		}
	}
	
	
	//docPass - checkbox
	docLayer.docgrp.docPass.checks.hasDocPass.onClick = function() {
		var docPass = this.parent.parent.edits.docPass;
		if (this.value == true) {
			docPass.enabled = docPass.gsEnabled = true;
		} else {
			docPass.enabled = docPass.gsEnabled = false;
		}
		AOM.theme(currentDocument).setEditTextDisableBgColor(docPass);
		AOM.userInput(currentDocument).setElement(this);
	}
	docLayer.docgrp.docPass.checks.hasDocOwnerPass.onClick = function() {
		var docOwnerPass = this.parent.parent.edits.docOwnerPass;
		var disablePrint = this.parent.parent.parent.print.disablePrint;
		if (this.value == true) {
			docOwnerPass.enabled = docOwnerPass.gsEnabled = true;
			disablePrint.enabled = disablePrint.gsEnabled = true;
		} else {
			docOwnerPass.enabled = docOwnerPass.gsEnabled = false;
			disablePrint.value = disablePrint.enabled = disablePrint.gsEnabled = false;
			AOM.userInput(currentDocument).setElement(disablePrint);
		}
		AOM.theme(currentDocument).setEditTextDisableBgColor(docOwnerPass);
		AOM.userInput(currentDocument).setElement(this);
	}
	docLayer.docgrp.docPass.edits.docPass.onChange = function() {
		//var oldValue = AOM.userInput(currentDocument).get(this.name);
		var isValid = AOM.userInput(currentDocument).set(this.name, this.text);
		if (isValid) {
			AOM.CS.hasValid = true;
		} else {
			this.text = "";
			AOM.CS.hasValid = false;
		}
	}
	docLayer.docgrp.docPass.edits.docOwnerPass.onChange = function() {
		//var oldValue = AOM.userInput(currentDocument).get(this.name);
		var isValid = AOM.userInput(currentDocument).set(this.name, this.text);
		if (isValid) {
			AOM.CS.hasValid = true;
		} else {
			this.text = "";
			AOM.CS.hasValid = false;
		}
	}
	docLayer.docgrp.print.disablePrint.onClick = function() {
		AOM.userInput(currentDocument).setElement(this);
	}

}


AOM.CSManager.DesignWindow.prototype.initLayoutEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var layoutLayer = this.layouts;
	var currentDocument = this.currentDocument;

	var layoutgrp = layoutLayer.grp.layoutgrp;
	var margingrp = layoutLayer.grp.margingrp;	
	
	//hasUserAutoSpacing - checkbox 
	layoutLayer.autoSpace.hasUseAutoSpacing.onClick = function() {
		AOM.userInput(currentDocument).setElement(this);
		
		var enabled = true;
		if (this.value == true) {
			enabled = false;
		} 
		var theme = AOM.theme(currentDocument);
		AOM.CS.UIUtils.setEnabledProps(layoutgrp.horizontal, enabled, theme);
		AOM.CS.UIUtils.setEnabledProps(layoutgrp.vertical, enabled, theme);
		AOM.CS.UIUtils.setEnabledProps(layoutgrp.parent.margingrp, enabled, theme);

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

	layoutLayer.rgrp.hasRotate.onClick = function() {
		var oldValue = AOM.userInput(currentDocument).get(this.name);
		var newValue = this.value;
		
		if (oldValue != newValue) {
			//change template
			AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
		}
	
		AOM.userInput(currentDocument).setElement(this);
	}

	var changeMarginEditText = function() {
		var oldValue = AOM.userInput(currentDocument).get(this.name);
		var newValue = AOM.CS.Validation.checkHasUnitNumber(this.title, this.text, true, AOM.userInput(currentDocument).get("pageUnit"), currentDocument);
		
		if (newValue >= 0) {
			this.text = AOM.CS.Locale.toLocaleString(newValue);
			AOM.userInput(currentDocument).setElement(this);
		
			if (this.text != oldValue) {
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
			}
			AOM.CS.hasValid = true;
		} else {
			//reverse old value
			this.text = oldValue;
			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 oldValue = AOM.userInput(currentDocument).get(this.name);
		var newValue = AOM.CS.Validation.checkNumber(this.title, this.text, 1, 100, true, currentDocument);
		
		if (newValue >= 0) {
			this.text = newValue;
			AOM.userInput(currentDocument).setElement(this);
		
			if (this.text != oldValue) {
				//change template
				AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
			}
			AOM.CS.hasValid = true;
		} else {
			//reverse old value
			this.text = oldValue;
			AOM.CS.hasValid = false;
		}
	}
	
	layoutgrp.setCol.pageColumns.onChange = changeRowAndColumn;
	layoutgrp.setRow.pageRows.onChange = changeRowAndColumn;


	//hasRepeatPerPage
	layoutLayer.repeatgrp.hasRepeatPerPage.onClick = function() {
		AOM.userInput(currentDocument).setElement(this);
		
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
	}
}

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

	this.overlays.rgrp.filegrp.hasFileName.onClick = function() {
		AOM.userInput(currentDocument).setElement(this);
		
		var hasExtension = this.parent.hasExtension;
		if (this.value == true ) {
			hasExtension.enabled = true;
			
		} else {
			hasExtension.enabled = false;
			
			hasExtension.value = false;
			AOM.userInput(currentDocument).setElement(hasExtension);
		}
		hasExtension.gsEnabled = hasExtension.enabled;
		
		//change template
		AOM.CS.UIUtils.changeTemplate(pdfTemplates, AOM.userInput(currentDocument));
	}

	//add sysfont onChange event
	this.overlays.rgrp.fontgrp.fileNameFont.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput(currentDocument).setElement(this);
		} else {
			if (this.selection != undefined) {
				var oldValue = AOM.userInput(currentDocument).get(this.name);
				var selectedValue = this.selection.value;
				
				if (oldValue != selectedValue) {
					var fileNameFontFace = this.parent.fileNameFontFace;
				
					var faces = AOM.PDFGenerator.getSystemFontFaces(selectedValue);
					AOM.CS.UIUtils.rsetDropDownList(fileNameFontFace, faces, undefined, true, true);
					AOM.userInput(currentDocument).setElement(fileNameFontFace);
				}
		
				AOM.userInput(currentDocument).setElement(this);
				
			}
		}
	}
	
	this.overlays.rgrp.fontsizegrp.fileNameSize.selectionTextSuffix = " pt";

	this.overlays.rgrp.colorgrp.fontForegroundColor.onClick = function() {
		var gfx = this.graphics;
		var oldRGB = eval(AOM.userInput(currentDocument).get(this.name));
		var oldColorValue = AOM.CS.UIUtils.setColorToColorPicker(oldRGB);
		var selectedColor = $.colorPicker(oldColorValue);
		
		if (selectedColor == undefined || selectedColor == -1) return;
		
		var rgb= AOM.CS.UIUtils.getColorFromColorPicker(selectedColor);
		gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, rgb);
		AOM.userInput(currentDocument).set(this.name, rgb.toSource());
		AOM.userInput(currentDocument).set("fontForegroundColorCustom", rgb.toSource());
		
		//set fontForeground value
		AOM.CS.UIUtils.setDropDownListSelection(this.parent.fontForeground, AOM.CSConstant.COLOR_CUSTOM, true);
	}

	this.overlays.rgrp.colorgrp.fontForeground.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput(currentDocument).setElement(this);
		} else {
			if (this.selection != undefined) {
				var selectedValue = this.selection.value;			
				var fontForegroundColor = this.parent.fontForegroundColor;
				var gfx = fontForegroundColor.graphics;
			
				switch(selectedValue) {
				case AOM.CSConstant.COLOR_WHITE:
					gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, [1, 1, 1]);
					break;
				case AOM.CSConstant.COLOR_BLACK:
					gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, [0, 0, 0]);
					break;
				case AOM.CSConstant.COLOR_CUSTOM:
					var rgb = eval(AOM.userInput(currentDocument).get("fontForegroundColorCustom"));
					if(rgb) {
						gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, rgb );
						AOM.userInput(currentDocument).set(fontForegroundColor.name, rgb); 
					}					
					break;
				default:
					break;
				}
		
				AOM.userInput(currentDocument).setElement(this);
				AOM.userInput(currentDocument).set(fontForegroundColor.name, gfx.customBgColor.color.toSource());
			}
	
			this.parent.fontForegroundColor.notify("onDraw");
		}
	}	
}

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

	//hasAdvances - checkbox
	this.playbacks.selects.advances.hasAdvance.onClick = function() {
		AOM.userInput(currentDocument).setElement(this);
		
		var advanceSeconds = this.parent.advanceSeconds;
		if (this.value == true) {
			advanceSeconds.enabled = advanceSeconds.gsEnabled = true;
		} else {
			advanceSeconds.enabled = advanceSeconds.gsEnabled = false;
		}
		AOM.theme(currentDocument).setEditTextDisableBgColor(advanceSeconds);
	}

	this.playbacks.selects.advances.advanceSeconds.onChange = function(event) {
		var oldValue = AOM.userInput(currentDocument).get(this.name);
		var newValue = AOM.CS.Validation.checkNumber(this.title, this.text, 1, 60, true, currentDocument);
		
		if (newValue >= 0) {
			this.text = newValue;
			AOM.userInput(currentDocument).setElement(this);
			AOM.CS.hasValid = true;
		} else {
			//reverse old value
			this.text = oldValue;
			AOM.CS.hasValid = false;
		}
	}

	//transition - dropdownlist
	this.playbacks.dynamics.tgrp.transition.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput.setElement(this);
		} else {
			if (this.selection != undefined) {
				AOM.userInput(currentDocument).setElement(this);
			
				var parentName = this.selection.value;
			
				//set direction
				var child = this.parent.parent.dgrp.direction;
				var newItems = AOM.CS.UIUtils.getItemListByDefaultItems(child.name, parentName);
			
				AOM.CS.UIUtils.setDropDownList(child, newItems, undefined, true);
				if (newItems.length == 0) {
					AOM.userInput(currentDocument).set(child.name, undefined);
				} 
				
				//set speed
				var speed = this.parent.parent.sgrp.speed;
				if (this.selection.value == "None") {	
					speed.enabled = false;
					speed.gsEnabled = false;
				} else {
					var speedValue = AOM.CS.UIUtils.setDropDownListSelectionByIdx(speed,0, true);
					AOM.userInput(currentDocument).setElement(speed);
					speed.enabled = true;
					speed.gsEnabled = true;
				}
			}
		}
	}
	
	this.playbacks.selects.hasFullScreen.onClick = this.playbacks.selects.hasLoop.onClick = function() {
		AOM.userInput(currentDocument).setElement(this);
	}

	this.playbacks.dynamics.dgrp.direction.onChange = function() {
		AOM.userInput(currentDocument).setElement(this);
	}
}


AOM.CSManager.DesignWindow.prototype.initWatermarksEventHandlers = function() {
	var pdfTemplates = this.pdfTemplates;
	var watermarks = this.watermarks;
	var currentDocument = this.currentDocument;

	watermarks.textgrp.watermarkText.onChange = function(event) {
		var userInput = AOM.userInput(currentDocument);
		var oldValue = userInput.get(this.name);
		var isValid = userInput.setElement(this);
		if (isValid) {
			AOM.CS.hasValid = true;
			return true;
		} else {
			if (oldValue == undefined) { oldValue = ""; }
			this.text = oldValue;
			userInput.setElement(this);
			AOM.CS.hasValid = false;
			return false;
		}
	}

	//add sysfont onChange event
	watermarks.outgrp.fontgrp.watermarkFont.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput(currentDocument).setElement(this);
		} else {
			if (this.selection != undefined) {
				var oldValue = AOM.userInput(currentDocument).get(this.name);
				var selectedValue = this.selection.value;
				
				if (oldValue != selectedValue) {
					var fontFace = watermarks.outgrp.fontgrp.watermarkFontFace;
				
					var faces = AOM.PDFGenerator.getSystemFontFaces(selectedValue);
					AOM.CS.UIUtils.rsetDropDownList(fontFace, faces, undefined, true, true);
					AOM.userInput(currentDocument).setElement(fontFace);
				}
		
				AOM.userInput(currentDocument).setElement(this);
			}
		}
	}
	watermarks.outgrp.fontgrp.watermarkFontFace.onChange = function() {
		if (!AOM.CS.hasProgramInteract) {
			if (this.selection) {
				AOM.userInput(currentDocument).setElement(this);
			}
		}
	}

	watermarks.outgrp.colorgrp.cgrp.watermarkColor.onClick = function() {
		var gfx = this.graphics;
		var oldRGB = eval(AOM.userInput(currentDocument).get(this.name));
		var oldColorValue = AOM.CS.UIUtils.setColorToColorPicker(oldRGB);
		var selectedColor = $.colorPicker(oldColorValue);
		
		if (selectedColor == undefined || selectedColor == -1) return;
		
		var rgb= AOM.CS.UIUtils.getColorFromColorPicker(selectedColor);
		gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, rgb);
		AOM.userInput(currentDocument).set(this.name, rgb.toSource());
		AOM.userInput(currentDocument).set("watermarkColorCustom", rgb.toSource());
		
		//set watermarkColorType value
		AOM.CS.UIUtils.setDropDownListSelection(this.parent.watermarkColorType, AOM.CSConstant.COLOR_CUSTOM, true);
	}

	watermarks.outgrp.colorgrp.cgrp.watermarkColorType.onChange = function() {
		if (AOM.CS.hasProgramInteract) {
			AOM.userInput(currentDocument).setElement(this);
		} else {
			if (this.selection != undefined) {
				var selectedValue = this.selection.value;			
				var watermarkColor = this.parent.watermarkColor;
				var gfx =watermarkColor.graphics;
				
				switch(selectedValue) {
				case AOM.CSConstant.COLOR_WHITE:
					gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, [1, 1, 1]);
					break;
				case AOM.CSConstant.COLOR_BLACK:
					gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, [0, 0, 0]);
					break;
				case AOM.CSConstant.COLOR_CUSTOM:
					var rgb = eval(AOM.userInput(currentDocument).get("watermarkColorCustom"));
					if(rgb) {
						gfx.customBgColor = gfx.newBrush(gfx.BrushType.SOLID_COLOR, rgb );
						AOM.userInput(currentDocument).set(watermarkColor.name, rgb); 
					}			
					break;
				default:
					break;
				}

				AOM.userInput(currentDocument).setElement(this);
				AOM.userInput(currentDocument).set(watermarkColor.name, gfx.customBgColor.color.toSource());
				
				watermarkColor.notify("onDraw");
			}
		}
	}	

	watermarks.ordergrp.hasWatermarkForeground.onClick = watermarks.ordergrp.hasWatermarkBackground.onClick = function() {
		var hasForeground = watermarks.ordergrp.hasWatermarkForeground;
		var hasBackground = watermarks.ordergrp.hasWatermarkBackground;
		
		if (hasForeground.value) {
			hasBackground.value = false;
		} else if (hasBackground.value) {
			hasForeground.value = false;
		}
		AOM.userInput(currentDocument).setElement(hasForeground);
		AOM.userInput(currentDocument).setElement(hasBackground);
	}

}

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

	//TODO, temp set save btn onclick event
	this.savePdfs.contentgroup.saveBtn.onClick = function() {
	try {	
		//before check
		if (File.fs == "Macintosh") {
			/*
			//docLayer
			if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.wgrp.grp.pageWidth))  return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.hgrp.grp.pageHeight)) return;

			//layoutLayer
			var layoutgrp = layoutLayer.grp.layoutgrp;
			var margingrp = layoutLayer.grp.margingrp;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(layoutgrp.setCol.pageColumns)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(layoutgrp.setRow.pageRows)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(layoutgrp.horizontal.setVal.horizontalSpacing)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(layoutgrp.vertical.setVal.verticalSpacing)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(margingrp.setTop.topMargin)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(margingrp.setBottom.bottomMargin)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(margingrp.setLeft.leftMargin)) return;
			if (!AOM.CS.UIUtils.checkEditTextOnMac(margingrp.setRight.rightMargin)) return;
				
			//plabackLayer
			if (!AOM.CS.UIUtils.checkEditTextOnMac(playbackLayer.selects.advances.advanceSeconds))  return;
			
			//watermarks
			if (!AOM.CS.UIUtils.checkEditTextOnMac(watermarks.textgrp.watermarkText)) return;
			
			//last but not least , check pass
			if (!AOM.CS.UIUtils.checkEditTextOnMac(docLayer.docgrp.docPass.edits.docPass))  return;
			*/
			if (AOM.CS.hasValid == false) {
				AOM.CS.hasValid = true;
				return;
			}
		}
			
		//after
		var pdfMaker = new AOM.CS.PDFMaker(currentDocument);
		pdfMaker.generatePDF();
		pdfMaker.destroy();
	} catch(e) {
		AOM.CS.Log.writeError(e);
	}
	}
}


AOM.CSManager.DesignWindow.prototype.populate = function() {
	//
};

AOM.CSManager.DesignWindow.prototype.refreshData = function() {
	//
}

AOM.CSManager.DesignWindow.prototype.clear = function() {
	//
}

AOM.CSManager.DesignWindow.prototype.destory = function() {
	
};


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

AOM.CSManager.initializationResources = function()
{

	AOM.CS.pdfTemplateResource = 
	"group{\
		orientation:'column', alignment:['left', 'top'], alignChildren:['left', 'top'], margins:0, spacing:6,\
		tgrp:Group{\
			alignChildren:['center', 'center'], spacing:5, margins:[20, 5, 10, 0], \
			t:StaticText{text:'" +AOM.localizeEsc("$$$/ContactSheet/javascript/title/template=Template:") + "'},\
			template:DropDownList{preferredSize:[180, 22], name:'template'},\
		},\
		refreshgrp:Group{\
			alignment:['center', 'center'], alignChildren:['center', 'center'], margins:[20, 0, 10, 5],\
			refreshPreview:Button{\
				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:") + "'},\
			pagePreset:DropDownList{preferredSize:[148, 22], name:'pagePreset'}\
		},\
		sgrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/size=Size:") + "'},\
			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:") + "'}, \
			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:'Float'},\
				pageUnit:DropDownList{preferredSize:[98, 22], name:'pageUnit'},\
			}\
		},\
		hgrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/height=Height:") + "'}, \
			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:'Float'},\
				t:StaticText{text:'', preferredSize:[10, 22]},\
				pagePortrait:IconButton{\
					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:IconButton{\
					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'\
				},\
				t:StaticText{text:'', preferredSize:[20, 22]}\
			}\
		},\
		pdfgrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/adobePdfPreset=Quality:") + "'},\
			pdfPreset:DropDownList{preferredSize:[148, 22], name:'pdfPreset'}\
		}, \
		bggrp:Group{\
			alignChildren:['right', 'center'], spacing:6,\
			t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/background=Background:") + "'}, \
			bgVal:Group{\
				margins:0, spacing:6, \
				pageBackground:DropDownList{preferredSize:[84, 22], name:'pageBackground'},\
				pageBackgroundColor:IconButton{ \
					helpTip:' " + AOM.localizeEsc("$$$/ContactSheet/javascript/tooltip/colorpicker=Click here to choose from more colors") + "', \
					preferredSize:[30, 20], \
					themeType:'colorPnl',\
					name:'pageBackgroundColor'},\
				t:StaticText{text:'', preferredSize:[22, 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:6,\
					hasDocPass:Checkbox{\
						alignment:['left','center'],\
						text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/documentPassword=Open Password:") + "',\
						name:'hasDocPass'\
					},\
					hasDocOwnerPass:Checkbox{\
						alignment:['left','center'],\
						text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/documentOwnerPassword=Permission Password:") + "',\
						name:'hasDocOwnerPass'\
					}\
				}\
				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:Checkbox{\
					text:'" + 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:") + "'},\
			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:") + "'}, \
					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:") + "'}, \
					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'}, \
					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:'Float'},\
						t:StaticText{text:'in', preferredSize:[16, 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'}, \
					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:'Float'},\
						t:StaticText{text:'in', preferredSize:[16, 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'},\
					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:'Float'},\
					t:StaticText{text:'in',preferredSize:[16, 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'},\
					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:'Float'},\
					t:StaticText{text:'in',preferredSize:[16, 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'},\
					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:'Float'},\
					t:StaticText{text:'in',preferredSize:[16, 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'},\
					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:'Float'},\
					t:StaticText{text:'in',preferredSize:[16, 18], refParent:'pageUnit', name:'rightMarginUnit', enableParent:'hasUseAutoSpacing', equalToParent:'false'},\
				}\
			}\
		},\
		autoSpace:Group{\
			alignment:['fill', 'center'], margins:[0, 5, 0, 0],\
			hasUseAutoSpacing: Checkbox{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/useAutoSpacing=Use Auto-Spacing") + "', name:'hasUseAutoSpacing'},\
		},\
		rgrp:Group{\
			alignment:['fill', 'center'], alignChildren:['left', 'center'], \
			hasRotate:Checkbox{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/rotateForBestFit=Rotate for Best Fit") + "', name:'hasRotate'}\
		},\
		repeatgrp:Group{\
			alignment:['fill', 'center'], alignChildren:['left', 'center'],\
			hasRepeatPerPage: Checkbox{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/repeatPerPage=Repeat One Photo per Page") + "', name:'hasRepeatPerPage'},\
		},\
	}" ;
	
	
	AOM.CS.overlaysResource = 
	"Group {\
		alignment:['fill', 'top'],  spacing:6, margins:[8, 10, 0, 10], \
		lgrp:Group{\
			orientation:'column', alignment:['left', 'top'], alignChildren:['right', 'center'], spacing:6, \
			sp:StaticText{text:'', preferredSize:[1, 22]},\
			stFont:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/font=Font:") + "', preferredSize:[-1, 22]},\
			stSize:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/size=Size:") + "', preferredSize:[-1, 22]},\
			stColor:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/fontColor=Color:") + "', preferredSize:[-1, 22]}, \
		},\
		rgrp:Group{\
			orientation:'column', alignment:['right', 'top'], alignChildren:['left', 'top'], spacing:6, \
			filegrp:Group{\
				alignChildren:['left', 'top'], \
				hasFileName:Checkbox{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/fileName=Filename") + "', name:'hasFileName', preferrredSize:[-1, 22]},\
				hasExtension:Checkbox{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/Extension=Extension") + "', \
					name:'hasExtension',  enableParent:'hasFileName', equalToParent:'true', preferredSize:[-1, 22]},\
			},\
			fontgrp:Group{\
				alignChildren:['left', 'top'], spacing:6,\
				fileNameFont:DropDownList{preferredSize:[128, 22],  name:'fileNameFont'},\
				fileNameFontFace:DropDownList{preferredSize:[78, 22],  name:'fileNameFontFace'},\
			},\
			fontsizegrp:Group{\
				alignChildren:['left', 'top'], \
				fileNameSize:DropDownList{preferredSize:[93, 22],  name:'fileNameSize'},\
			},\
			colorgrp:Group{\
				alignChildren:['left', 'top'], \
				fontForeground:DropDownList{preferredSize:[93, 22], name:'fontForeground'},\
				fontForegroundColor:IconButton{\
					helpTip:' " + AOM.localizeEsc("$$$/ContactSheet/javascript/tooltip/fontcolorpicker=Click here to choose from more font colors") + "', \
					preferredSize:[30, 20], \
					themeType:'colorPnl', \
					name:'fontForegroundColor'\
				},\
			}\
		},\
	}" ;
	
	
	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:Checkbox{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/openInFullScreenMode=Open in Full Screen Mode") + "', name:'hasFullScreen'},\
			advances:Group{\
				alignChildren:['left', 'center'], \
				hasAdvance:Checkbox{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/advanceEvery=Advance Every") + "', name:'hasAdvance'},\
				advanceSeconds:EditText{preferredSize:[35, 18], name:'advanceSeconds', enableParent:'hasAdvance', equalToParent:'true', \
						properties: {borderless:true}, title:'" +AOM.localizeEsc("$$$/ContactSheet/javascript/validation/advanceSeconds=Advance Seconds") + "'},\
				t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/seconds=Seconds") + "'}\
			},\
			hasLoop:Checkbox{text:'" + 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:") + "'},\
				transition:DropDownList{preferredSize:[195, 22], name:'transition'}\
			},\
			dgrp:Group{\
				alignChildren:['right', 'center'], spacing:6,\
				t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/direction=Direction:") + "'},\
				direction:DropDownList{preferredSize:[135, 22], name:'direction', refParent:'transition', enableParent:'transition', equalToParent:'none'}\
			},\
			sgrp:Group{\
				alignChildren:['right', 'center'], spacing:6,\
				t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/speed=Speed:") + "'},\
				speed:DropDownList{preferredSize:[135, 22], name:'speed', enableParent:'transition', equalToParent:'none'}\
			}\
		}\
	}" ;
		
		
	AOM.CS.watermarkResource = 
	"group{\
		orientation:'column', alignment:['fill', 'center'], alignChildren:['fill', 'center'], margins:[8, 10, 10, 10], spacing:6, \
		textgrp:Group{\
			orientation:'column', alignChildren:['fill', 'center'], \
			st:StaticText{text:'"+AOM.localizeEsc("$$$/ContactSheet/javascript/title/watermarktext=Watermark Text:")+"', alignment:['left', 'center'], },\
			watermarkText:EditText{text:'', name:'watermarkText', properties:{borderless:true}, preferredSize:[-1, 18]},\
		},\
		outgrp:Group{\
			orientation:'column', alignment:['fill', 'center'], alignChildren:['right', 'center'], \
			fontgrp:Group{\
				alignChildren:['right', 'center'], spacing: 5,  \
				t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/font=Font:") + "'},\
				watermarkFont:DropDownList{preferredSize:[127, 22],  name:'watermarkFont' },\
				watermarkFontFace:DropDownList{preferredSize:[78, 22],  name:'watermarkFontFace'},\
			},\
			sizegrp:Group{\
				alignChildren:['right', 'center'], spacing:3, \
				label:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/size=Size:") + "'},\
				watermarkFontSize:StaticText{\
					themeType:'hslider', \
					minvalue:8, maxvalue:240, stepdelta:1, value:12, \
					footLabel:'pt',\
					sliderPreferredSize:[139, 22], etPreferredSize:[35, 18], \
					name:'watermarkFontSize',\
					preferredSize:[0, 5],  text:'',\
				},\
			},\
			colorgrp:Group{\
				alignChildren:['right', 'center'], spacing:5, \
				t:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/fontColor=Color:") + "'}, \
				cgrp:Group{\
					margins:0, spacing:5, \
					watermarkColorType:DropDownList{preferredSize:[98, 22], name:'watermarkColorType'},\
					watermarkColor:IconButton{\
						helpTip:' " + AOM.localizeEsc("$$$/ContactSheet/javascript/tooltip/watermarkcolorpicker=Click here to choose from more watermark colors") + "', \
						preferredSize:[30, 20], \
						themeType:'colorPnl', \
						name:'watermarkColor'\
					},\
					space:StaticText{text:'', preferredSize:[72, 22]}, \
				}\
			},\
			opacitygrp:Group{\
				alignChildren:['right', 'center'], spacing:3, \
				label:StaticText{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/opacity=Opacity:") + "'},\
				watermarkOpacity:StaticText{\
					themeType:'hslider', \
					minvalue:0, maxvalue:100, stepdelta:1, value:100, \
					footLabel:'% ',\
					sliderPreferredSize:[139, 22], etPreferredSize:[35, 18], \
					name:'watermarkOpacity',\
					preferredSize:[0, 5],  text:'',\
				},\
			},\
		},\
		ordergrp:Group{\
			orientation:'column', alignChildren:['left', 'center'],\
			hasWatermarkForeground:RadioButton{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/watermarkforeground=Foreground") + "', name:'hasWatermarkForeground', checked:'true'},\
			hasWatermarkBackground:RadioButton{text:'" + AOM.localizeEsc("$$$/ContactSheet/javascript/title/watermarkbackground=Background") + "', name:'hasWatermarkBackground', checked:'false'},\
		},\
	}";
		
	AOM.CS.savePdfResource = 
	"group{\
		name:'foldgroup',\
		orientation:'column', alignment:['fill', 'top'], alignChildren:['left', 'top'], margins:0, spacing:0, margins:[8, 10, 0, 10],\
		contentgroup:Group{\
			alignChildren:['left', 'bottom'], \
			hasViewPdf:Checkbox{text:'" + 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], \
			},\
		}\
	}";


}
