var messages = new function () { this.MESSAGE001 = "HTTP Server Error. Code:"; this.MESSAGE002 = "You have reached the maximum number of items allowed on the canvas."; this.MESSAGE003 = "Your Outfit was saved successfully."; this.MESSAGE004 = "Each Combination must be given a name."; this.MESSAGE005 = "Each Combination must have atleast 2 items!"; this.MESSAGE006 = "You are about to delete this Combination forever. Are you sure?"; this.MESSAGE007 = "To create a combo drag items from the palette on the left, then when you are done - hit the SAVE button."; this.MESSAGE008 = "Invalid name - check the name for any special characters."; this.MESSAGE009 = "Your Fashion Canvas was saved successfully."; this.MESSAGE010 = "Click on the EDIT button to type text into this box."; this.MESSAGE011 = "Wardrobes introduction text & description - claire asap please"; this.MESSAGE012 = "You haven't selected any item in the palette to remove, please before deleting click over an item to select it"; this.FATAL = "FATAL"; this.ERROR = "ERROR"; this.WARNING = "WARNING"; this.ADVISE = "HELP"; this.VALIDCHARACTERS = "abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRST0123456789 .,'"; this.TEXTVALIDCHARACTERS = "abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRST0123456789 .,'!£$*@:;+=-()_[]{}<>"; this.ITEM = 'clothesImage'; this.COMBO = 'comboImage'; this.FASHIONPHOTO = 'fashionphoto' }; var versionIE = parseFloat(navigator.appVersion.split("MSIE")[1]); function compose_id_for_html(primaryKey, typeItem) { var composition = ''; composition = typeItem + "_" + primaryKey; return composition } function get_PK_HTML_element(id) { var posSeparator = id.lastIndexOf('_'); var itemPK = id.substring(posSeparator + 1, id.length); return itemPK } function popupWindow(url, nameWindow, width, height) { var left = (screen.width - width) / 2; var top = (screen.height - height) / 2; var params = 'width=' + width + ', height=' + height; params += ', top=' + top + ', left=' + left; params += ', directories=no'; params += ', location=no'; params += ', menubar=no'; params += ', resizable=no'; params += ', scrollbars=no'; params += ', status=no'; params += ', toolbar=no'; newwin = window.open(url, nameWindow, params); if (window.focus) { newwin.focus() } return false } var iaz_preserved_elements = []; var iaz_preserved_zindexes = []; function ie_apply_zindex(element_id, zindex, context_id) { if (Prototype.Browser.IE) { if (undefined == zindex) { zindex = 1 } var context = (undefined == context_id ? $(context_id) : $(document.body)); var element = $(element_id); for (i = iaz_preserved_elements.length - 1; i >= 0; i--) { iaz_preserved_elements[i].setStyle({ 'z-index': iaz_preserved_zindexes[i] }) } iaz_preserved_elements = []; iaz_preserved_zindexes = []; element.ancestors().each(function (ancestor) { if ('relative' == ancestor.getStyle('position')) { iaz_preserved_elements.push(ancestor); iaz_preserved_zindexes.push(ancestor.getStyle('z-index')); ancestor.setStyle({ 'z-index': zindex }) } if (ancestor == context) { throw $break; } }) } } Watermark = Class.create(); Watermark.prototype = { initialize: function (element, options) { this.options = Object.extend({ text: 'Type in here', color: '#aaa' }, options || {}); this.input = $(element); this.defaultColor = this.input.getStyle("color"); this.input.observe("focus", function (event) { this.clearMessage() } .bind(this)); this.input.observe("blur", function (event) { this.insertMessage() } .bind(this)); this.input.observe("change", function (event) { this.insertMessage() } .bind(this)); this.insertMessage() }, clearMessage: function () { if (this.input.value == this.options.text) this.input.value = ""; this.input.setStyle({ color: this.defaultColor }) }, insertMessage: function () { if (this.input.value.length == 0 || this.input.value == this.options.text) { this.input.value = this.options.text; this.input.setStyle({ color: this.options.color }) } else this.input.setStyle({ color: this.defaultColor }) }, setText: function (value) { if (value == '') { this.input.value = ''; this.insertMessage() } else { this.input.setStyle({ color: this.defaultColor }); this.input.value = value } }, getText: function () { if ((this.input.value == this.options.text) && (this.input.getStyle("color") == this.options.color)) return ''; else return this.input.value } }; function html_entity_decode(str) { var ta = document.createElement("textarea"); ta.innerHTML = str.replace(/</g, "&lt;").replace(/>/g, "&gt;"); return ta.value } var global = new function () { this.MAX_ITEMS_IN_CANVAS = 50; this.HEIGHT_THUMBNAIL_IMAGE = 75; this.WIDTH_THUMBNAIL_IMAGE = 75; this.CANVAS_DEFAULT_SIZE_IMAGE = 150; this.CANVAS_DECORATOR_SIZE_IMAGE = 50; this.PK_NO_BORDER_BUBBLE = 30; this.TOTAL_ITEMS_IN_PALETTE = 20; this.TOTAL_TEXTITEMS_IN_PALETTE = 24; this.TOTAL_TABS = 15; this.TEXT_DEFAULT_WIDTH = 250; this.TEXT_DEFAULT_HEIGHT = 40; this.TEXT_DEFAULT = "Welcome to avenue7" }; function onNonColorItemClick(event) { Event.stop(event); return false } var ColorContainer = function (ParentContainer, obj, Containerid) { if ($(Containerid) == null) { this.ColorPalette = ["rgb(102, 0, 0)", "rgb(222, 99, 24)", "rgb(211, 209, 0)", "rgb(140, 140, 0)", "rgb(41, 50, 6)", "rgb(52, 227, 229)", "rgb(32, 82, 96)", "rgb(28, 9, 70)", "rgb(70, 0, 140)", "rgb(51, 21, 26)", "rgb(227, 14, 92)", "rgb(61, 31, 0)", "rgb(94, 24, 0)", "rgb(0, 0, 0)", "rgb(152, 0, 0)", "rgb(255, 127, 0)", "rgb(255, 255, 0)", "rgb(136, 186, 65)", "rgb(0, 103, 0)", "rgb(101, 243, 201)", "rgb(49, 140, 140)", "rgb(49, 49, 140)", "rgb(94, 49, 140)", "rgb(82, 15, 65)", "rgb(255, 89, 172)", "rgb(140, 94, 49)", "rgb(140, 70, 0)", "rgb(80, 80, 80)", "rgb(255, 0, 0)", "rgb(255, 160, 0)", "rgb(238, 213, 79)", "rgb(119, 40, 98)", "rgb(0, 174, 0)", "rgb(119, 246, 167)", "rgb(98, 140, 140)", "rgb(74, 115, 189)", "rgb(119, 98, 140)", "rgb(132, 14, 71)", "rgb(239, 140, 174)", "rgb(142, 112, 50)", "rgb(209, 180, 91)", "rgb(130, 130, 131)", "rgb(227, 38, 54)", "rgb(255, 197, 73)", "rgb(255, 255, 109)", "rgb(140, 140, 98)", "rgb(0, 255, 0)", "rgb(178, 255, 255)", "rgb(98, 119, 140)", "rgb(88, 154, 213)", "rgb(172, 89, 255)", "rgb(140, 98, 119)", "rgb(234, 208, 205)", "rgb(140, 119, 98)", "rgb(226, 219, 154)", "rgb(181, 181, 182)", "rgb(250, 98, 77)", "rgb(255, 200, 152)", "rgb(255, 255, 174)", "rgb(150, 210, 198)", "rgb(169, 250, 0)", "rgb(216, 255, 178)", "rgb(189, 214, 189)", "rgb(161, 196, 233)", "rgb(162, 151, 233)", "rgb(198, 165, 182)", "rgb(255, 223, 239)", "rgb(198, 156, 123)", "rgb(255, 255, 255)", "rgb(231, 231, 231)"]; try { if (ColorPalette.length > 0) this.ColorPalette = ColorPalette } catch (e) { } var divColorGrid = Builder.node("div", { id: Containerid, className: "colorContainer", style: "display:none;z-Index:1000000;position:absolute;" }); $$('body')[0].appendChild(divColorGrid); this.ColorPalette.each(function (color) { var coloritem = Builder.node("div", { className: "colorItem", style: "background-color: " + color }); var Blankcoloritem = Builder.node("div", { style: "width:14px; height:14px; text-align:center;top:0px;display:none;float:left;margin:0 1px 1px 0; color:#ccc" }, "x"); var container = Builder.node("a", [coloritem, Blankcoloritem]); divColorGrid.appendChild(container); Event.observe(coloritem, 'click', obj.onColorItemClick.bindAsEventListener(obj)); Event.observe(Blankcoloritem, 'click', onNonColorItemClick) }) } }; Avenue7Designer = Class.create(); Avenue7Designer.prototype = { initialize: function () { this.rootApp = $('rootApplication').value; this.modalwindow = MM; var observerMessages = new ObserverMessages(this.modalwindow); this.palette = new Palette(); this.canvas = new CanvasCombo('canvas', { rootPathApp: this.rootApp }); var observerCheckCanvasElement = new ObserverCheckCanvasElement(this.canvas); this.canvas.attatchObserver(observerMessages); this.canvas.userId = $('userName').value; this.IsSaveAsDraft = false; this.AjaxRequest = null; this.resizeWindow = this.onResizeWindow.bindAsEventListener(this); this.clickNewComboBind = this.onClickNewCombo.bindAsEventListener(this); this.clickRemoveItemBind = this.onClickRemoveItem.bindAsEventListener(this); this.clickBackGroundBind = this.onClickBackground.bindAsEventListener(this); this.clickForeGroundBind = this.onClickForeground.bindAsEventListener(this); this.clickFlipImageBind = this.onClickFlipImage.bindAsEventListener(this); this.onClickCloneImageBind = this.onClickCloneImage.bindAsEventListener(this); this.onClickFlopImageBind = this.onClickFlopImage.bindAsEventListener(this); this.onClickRotateImageBind = this.onClickRotateImage.bindAsEventListener(this); this.onClickARotateImageBind = this.onClickARotateImage.bindAsEventListener(this); this.onClickZoomInBind = this.onClickZoomIn.bindAsEventListener(this); this.onClickZoomOutBind = this.onClickZoomOut.bindAsEventListener(this); this.onClickCenterImageBind = this.onClickCenterImage.bindAsEventListener(this); this.clickSaveComboBind = this.onSaveCombo.bindAsEventListener(this); this.clickSaveAsDraftBind = this.onSaveAsDraft.bindAsEventListener(this); this.clickBkGrndToggleBind = this.onBkGrndToggle.bindAsEventListener(this); this.clickOpacityToggleBind = this.onOpacityToggle.bindAsEventListener(this); Droppables.add(this.canvas.element, { accept: messages.ITEM, onDrop: function (element) { this.canvas.onDropItemIntoCanvas(element, "image") } .bind(this) }); this.registerEventsButtons(); $('instructions').show(); if ($('userName').value == "") { this.anonymoususer() } else { this.loadInitCombo() } }, loadInitCombo: function () { var url = window.location.href.toQueryParams(); var ComboID = url.ComboID; if (ComboID) { this.getDataComboFromServer(ComboID) } else { if ($('DesignData').value != "") { this.drawComboInCanvas(unescape($('DesignData').value)) } } this.loadItemFromProductPage() }, getDataComboFromServer: function (comboID) { Avenue7_Presentation.OutfitService.GetDataCombosInCanvas(comboID, this.getDataComboFromServerOC, this.getDataComboFromServerOE, this) }, getOutfitDraftFromServer: function (comboID, ComboPicture) { this.canvas.DisplayPopupMsgWithNoButtons("Loading the outfit details...", "Loading..."); this.canvas.DraftID = comboID; this.canvas.DraftPicture = ComboPicture; Avenue7_Presentation.OutfitService.GetOutfitDraftDetailsById(comboID, this.getDataComboFromServerOC, this.getDataComboFromServerOE, this) }, getDataComboFromServerOC: function (arg, context) { try { context.drawComboInCanvas(unescape(arg)) } catch (e) { } MM.hideBox() }, getDataComboFromServerOE: function (arg, context) { context.canvas.nameCombo = ''; context.canvas.comboPicture = ''; context.canvas.comboID = -1; context.canvas.DraftID = ""; context.canvas.DraftPicture = ""; MM.showMessage(messages.MESSAGE001 + arg.status, messages.ERROR) }, drawComboInCanvas: function (JSONComboData) { var comboDesign = JSONComboData.evalJSON(); comboDesign.Items.sort(this.sortItemsbyZindex); this.canvas.resetCanvas(); comboDesign.Items.each(function (item) { this.canvas.addItem(item.ItemPK, item.PathImage, item.Flip, item.Flop, item.Clear, item.Rotate, item.XPosition, item.YPosition, item.Width, item.Height, item.ZPosition, item.InstanceID, false, item.ItemType, unescape(item.HTMLText), item.Opacity == undefined ? 1 : item.Opacity, item.TextColor == undefined ? "" : item.TextColor, item.TextBGColor == undefined ? "" : item.TextBGColor, item.TextFont == undefined ? "" : item.TextFont) } .bind(this)); this.canvas.comboID = comboDesign.ComboID; this.canvas.nameCombo = comboDesign.Name; this.canvas.comboPicture = comboDesign.ComboPicture; if (comboDesign.Items.size() > 0) { $('instructions').hide(); this.canvas.showOutfitManagingButtons(true) } this.canvas.saveDataInCookie = true; this.canvas.saveCookie() }, sortItemsbyZindex: function (a, b) { if (a.ZPosition > b.ZPosition) return 1; if (a.ZPosition < b.ZPosition) return -1; if (a.ZPosition = b.ZPosition) return 0 }, loadItemFromProductPage: function () { var items = this.canvas.cookiejar.get("AddToCanvas"); var curObj = this; try { if (items != null && items != "") { items.each(function (item) { curObj.canvas.addItemInToCanvas(item.id, item.Url, item.ImgP) }) } } catch (e) { } this.canvas.cookiejar.remove("AddToCanvas") }, registerEventsButtons: function () { Event.observe(window, "resize", this.resizeWindow); Event.observe('btnNewCombo', "click", this.clickNewComboBind); Event.observe('btnRemoveItem', "click", this.clickRemoveItemBind); Event.observe('btnForeground', "click", this.clickForeGroundBind); Event.observe('btnBackground', "click", this.clickBackGroundBind); Event.observe('btnFlipImage', "click", this.onClickFlopImageBind); Event.observe('btnFlopImage', "click", this.clickFlipImageBind); Event.observe('btnCloneItem', "click", this.onClickCloneImageBind); Event.observe('btnZoomIn', "click", this.onClickZoomInBind); Event.observe('btnZoomOut', "click", this.onClickZoomOutBind); Event.observe('btnCenter', "click", this.onClickCenterImageBind); Event.observe('btnSaveCombo', 'click', this.clickSaveComboBind); Event.observe('btnSaveDraft', 'click', this.clickSaveAsDraftBind); Event.observe('btnToggleBkGrnd', 'click', this.clickBkGrndToggleBind); Event.observe('btnToggleopacity', 'click', this.clickOpacityToggleBind); Event.observe('txtText', 'keypress', this.RestrictSpecialChars.bindAsEventListener(this)); Event.observe('btnUpdateText', 'click', this.UpdateText.bindAsEventListener(this)); $("spCText").observe("click", function (event) { $("ClrPalette").hide(); $("divFontList").show(); $("divFontList").setStyle("zIndex", 999999); $("sFont").show(); Event.stop(event) }); $("imgSText").observe("click", function (event) { $("ClrPalette").hide(); $("divFontList").show(); $("divFontList").setStyle("zIndex", 999999); $("sFont").show(); Event.stop(event) }); var obj = this; $$("#sFont li").each(function (ele) { $(ele).observe('click', obj.onFontClick.bindAsEventListener(obj)) }); this.CreateColorPalette() }, onClickNewCombo: function () { var temp = this; temp.canvas.newCombo(); this.AddAnalytics(69) }, onSaveCombo: function () { this.canvas.VerifyCanvasItems() }, onSaveAsDraft: function () { this.IsSaveAsDraft = true; this.canvas.saveCanvasAsDraft(); return false }, onSaveAsDraftAfterLogOn: function () { this.canvas.saveCanvasAsDraft(); return false }, onClickSaveCombo: function () { this.canvas.saveCanvas() }, onClickRemoveItem: function () { if (this.canvas.selectedItem != "") this.canvas.removeItemManager(this.canvas.selectedItem, true); this.AddAnalytics(68); return false }, onClickBackground: function () { if (this.canvas.selectedItem != "") this.canvas.sendToBackGround(this.canvas.selectedItem); this.AddAnalytics(67); return false }, onClickForeground: function () { if (this.canvas.selectedItem != "") this.canvas.bringToForeGround(this.canvas.selectedItem); this.AddAnalytics(66); return false }, onBkGrndToggle: function () { if (this.canvas.selectedItem != "") this.canvas.ToggleBackGround(this.canvas.selectedItem); this.AddAnalytics(247); return false }, onOpacityToggle: function () { if (this.canvas.selectedItem != "") this.canvas.ToggleOpacity(this.canvas.selectedItem); this.AddAnalytics(257); return false }, onClickFlipImage: function () { if (this.canvas.selectedItem != "") this.canvas.flipImage(this.canvas.selectedItem); this.AddAnalytics(65); return false }, onClickCloneImage: function () { if (this.canvas.selectedItem != "") this.canvas.cloneImage(this.canvas.selectedItem); this.AddAnalytics(245); return false }, onClickFlopImage: function () { if (this.canvas.selectedItem != "") this.canvas.flopImage(this.canvas.selectedItem); this.AddAnalytics(244); return false }, onClickRotateImage: function () { if (this.canvas.selectedItem != "") this.canvas.rotateImage(this.canvas.selectedItem, 10); return false }, onClickARotateImage: function () { if (this.canvas.selectedItem != "") this.canvas.rotateImage(this.canvas.selectedItem, -10); return false }, onClickZoom: function (zoom) { var width; var height; var top; var left; var CanvasDim = this.getCenterPoint(); for (var i = 0; i < this.canvas.items.length; i++) { var item = this.canvas.items[i]; width = (item.options.width * zoom) - item.options.width; height = (item.options.height * zoom) - item.options.height; top = (item.options.posY - CanvasDim.height) * (zoom - 1); left = (item.options.posX - CanvasDim.width) * (zoom - 1); item.resizeItem(top, left, width, height); item.updateItemOptions(); item.redraw() } return false }, onClickZoomIn: function () { this.onClickZoom(1.2); this.AddAnalytics(248); return false }, onClickZoomOut: function () { this.onClickZoom(0.8); this.AddAnalytics(249); return false }, getCenterPoint: function () { var Dim = []; var canvasDimension = this.canvas.element.getDimensions(); Dim.width = parseInt(canvasDimension.width) / 2; Dim.height = parseInt(canvasDimension.height) / 2; return Dim }, onClickCenterImage: function () { if (this.canvas.items.length > 0) { var avgCenterPointX = 0; var avgCenterPointY = 0; var NoOfItems = this.canvas.items.length; var CanvasDim = this.getCenterPoint(); for (var i = 0; i < NoOfItems; i++) { var it = this.canvas.items[i]; avgCenterPointX += it.options.posX + it.options.width / 2; avgCenterPointY += it.options.posY + it.options.height / 2 } avgCenterPointX = avgCenterPointX / NoOfItems; avgCenterPointY = avgCenterPointY / NoOfItems; var left = CanvasDim.width - avgCenterPointX; var top = CanvasDim.height - avgCenterPointY; for (var i = 0; i < NoOfItems; i++) { var item = this.canvas.items[i]; item.resizeItem(top, left, 0, 0); item.updateItemOptions(); item.redraw() } var ZoomOutScaleFac = this.canvas.items[0].Scale(); for (var i = 0; i < NoOfItems; i++) { var it = this.canvas.items[i]; ZoomOutScaleFac = Math.max(ZoomOutScaleFac, it.Scale()) } if (ZoomOutScaleFac > 0) this.onClickZoom(ZoomOutScaleFac) } this.AddAnalytics(250); return false }, onClickClearCanvas: function () { this.canvas.resetCanvas() }, onResizeWindow: function () { if ($('kkkk')) $('kkkk').remove() }, anonymoususer: function () { }, AddAnalytics: function (EventID) { try { Analytics.AddActivity(EventID, Url, UserId, Sid) } catch (e) { } }, AddTextToCanvas: function (color, font) { var canvasSize = this.canvas.getCanvasCenterXY(); var w = 250; var h = 40; var x = canvasSize.CenterX - (w / 2); var y = canvasSize.CenterY - (h / 2); this.canvas.addItem("101", "Welcome to avenue7", 0, 0, 2, 0, x, y, w, h, 1, -1, true, "text", "", 1, color, "", font); this.canvas.saveDataInCookie = true; this.canvas.showOutfitManagingButtons(true); this.canvas.saveCookie(); $('instructions').hide(); return false }, UpdateText: function () { if ($('txtText').value.empty() == false) { if (this.canvas.selectedItem) { this.canvas.selectedItem.options.src = $('txtText').value; this.canvas.selectedItem.redraw(); this.canvas.selectedItem.SetAlphaFilter(); this.canvas.saveDataInCookie = true; this.canvas.saveCookie() } } return false }, RestrictSpecialChars: function (event) { var code = event.keyCode || event.which || event.charCode; var keyChar = String.fromCharCode(code).toLowerCase(); if (code == null || code == 8 || code == 27 || code == 9 || code == 46 || (code >= 37 && code <= 40)) return true; if (messages.TEXTVALIDCHARACTERS.indexOf(keyChar) > -1) return true; else { if (code == 13) this.UpdateText(); Event.stop(event); return false } }, CreateColorPalette: function () { ColorContainer($('canvas'), this, "ClrPalette"); ColorContainer($('canvasTextEditor'), this, "ClrPalette"); Event.observe('spBG', 'click', this.ShowColorPalette.bindAsEventListener(this)); Event.observe('spColor', 'click', this.ShowColorPalette.bindAsEventListener(this)) }, ShowColorPalette: function (event) { $("ClrPalette").show(); var ID = Event.element(event).id; var offset = $(ID).cumulativeOffset(); var sleft = offset.left; var stop = offset.top + $(ID).getHeight(); $("ClrPalette").setStyle({ top: stop + "px", left: sleft + "px" }); this.ColorEventID = ID; $("sFont").hide(); $("divFontList").setStyle("zIndex", -1); $("divFontList").hide(); Event.stop(event) }, onColorItemClick: function (event) { var ele = Event.element(event); var Color = $(ele).getStyle("backgroundColor"); if (this.ColorEventID == "spBG") { if (this.canvas.selectedItem) this.canvas.selectedItem.options.textBGColor = Color } else if (this.ColorEventID == "spColor") { if (this.canvas.selectedItem) this.canvas.selectedItem.options.textColor = Color } $(this.ColorEventID).setStyle({ backgroundColor: Color }); $("ClrPalette").hide(); this.UpdateText(); if (this.canvas.selectedItem) { $("canvasControlsClothesPreview").innerHTML = this.canvas.selectedItem.getThumbnailPictureSmall() } }, onFontClick: function (event) { var ele = Event.element(event).parentNode; if (this.canvas.selectedItem) { this.canvas.selectedItem.options.textFont = $(ele).readAttribute("value"); this.UpdateText(); $("sFont").hide(); $("divFontList").hide(); $("divFontList").setStyle("zIndex", -1); $("spCText").innerHTML = this.canvas.selectedItem.getThumbnailTextPictureSmall(); $("canvasControlsClothesPreview").innerHTML = this.canvas.selectedItem.getThumbnailPictureSmall(); Event.stop(event) } } }; ObserverMessages = Class.create(); ObserverMessages.prototype = { initialize: function (modalwindow) { this.name = "onShowMessage"; this.modalwindow = modalwindow }, update: function (message) { MM.showMessage(message.description, message.name) } }; ObserverRefreshCombos = Class.create(); ObserverRefreshCombos.prototype = { initialize: function (combosContainer) { this.combosContainer = combosContainer; this.name = "onRefreshCombos" }, update: function (message) { this.combosContainer.loadItemsPalette(0) } }; ObserverCheckCanvasElement = Class.create(); ObserverCheckCanvasElement.prototype = { initialize: function (canvas) { this.canvas = canvas; this.name = "onCheckItemInCanvas" }, update: function (item) { this.canvas.removeItemsStartingWithPrefix(item.itemType + '_' + item.itemPK) } }; CanvasBase = Abstract; CanvasBase.prototype = { start: function (element, options) { this.options = Object.extend({ rootPathApp: '' }, options || {}); this.element = $(element); this.items = []; this.observers = []; this.userId = ''; this.selectedItem = ''; this.editingName = false; this.saveDataInCookie = false; this.IsSaveBtnClicked = false; this.cookiejar = new CookieJar({ expires: 3600 * 24 * 365, path: '/' }); this.removeCookie(''); this.clickCanvas = this.onClickCanvas.bindAsEventListener(this); Event.observe(document, 'keypress', this.removeItemBind); Event.observe(this.element, 'click', this.clickCanvas); this.showItemManagingButtons(false); this.showOutfitManagingButtons(false); this.DraftID = -1; this.DraftPicture = '' }, attatchObserver: function (observer) { this.observers.push(observer) }, detachObserver: function (observer) { this.observers = this.observers.without(observer) }, notifyObserver: function (eventName, context) { this.observers.each(function (observer) { if (observer.name == eventName) { observer.update(context) } } .bind(this)) }, getCanvasCenterXY: function () { var canvasSize = {}; canvasSize.CenterX = parseInt(this.element.getStyle('width').sub('px', '')) / 2; canvasSize.CenterY = parseInt(this.element.getStyle('height').sub('px', '')) / 2; return canvasSize }, getItem: function (itemID) { var askedItem = this.items.find(function (item) { return (item.id == itemID) }); return askedItem }, onDropItemIntoCanvas: function (item, typeItem) { var initialSize; var x; var y; var srcElement; var idElement; var width; var height; var zIndex = 0; var cumOffset = Position.cumulativeOffset($(this.element.id)); idElement = get_PK_HTML_element(item.id); if (item.id.indexOf("_image_") > -1) { initialSize = this.getInitialSizeItemForCanvas(typeItem); x = Position.cumulativeOffset(item)[0] - (initialSize.width / 2) - cumOffset[0]; y = Position.cumulativeOffset(item)[1] - (initialSize.height / 2) - cumOffset[1]; width = initialSize.width; height = parseInt(initialSize.height / $(item).readAttribute("ImgP")); srcElement = item.src.toQueryParams(); var fileSrc = srcElement.file; if ((typeItem == messages.BUBBLE) && (idElement == global.PK_NO_BORDER_BUBBLE)) { fileSrc = srcElement.file; var prefixExt = fileSrc.substring(0, fileSrc.lastIndexOf('.')); prefixExt = prefixExt.substring(0, prefixExt.length - 1); var extFile = fileSrc.substring(fileSrc.lastIndexOf('.'), fileSrc.length); fileSrc = prefixExt + extFile } this.addItem(idElement, fileSrc, 0, 0, 2, 0, x, y, width, height, zIndex, -1, true, typeItem, "", 1, "", "", "") } else if (item.id.indexOf("_text_") > -1) { initialSize = this.getInitialSizeItemForCanvas("text"); x = Position.cumulativeOffset(item)[0] - (initialSize.width / 2) - cumOffset[0]; y = Position.cumulativeOffset(item)[1] - (initialSize.height / 2) - cumOffset[1]; width = initialSize.width; height = initialSize.height; fileSrc = global.TEXT_DEFAULT; var color = $(item).readAttribute("Color"); var font = $(item).readAttribute("title"); this.addItem(idElement, fileSrc, 0, 0, 2, 0, x, y, width, height, zIndex, -1, true, "text", "", 1, color, "", font) } else if (item.id.indexOf("_draft_") > -1) { try { this.DraftID = idElement; var temp = item.src.toQueryParams().file; var index = temp.lastIndexOf("/"); if (index > -1) this.DraftPicture = temp.substring(index + 1); av7design.getOutfitDraftFromServer(idElement, this.DraftPicture) } catch (e) { MM.showMessage("There was an unexpected error occured while loading the draft details into canvas, please try again later", "Error") } return } $('instructions').hide(); this.saveDataInCookie = true; this.showOutfitManagingButtons(true); this.saveCookie() }, addItemMiddleCanvas: function (itemid) { var item = $(itemid); var zIndex = 0; var srcElement = item.src.toQueryParams(); var idElement = get_PK_HTML_element(item.id); var ImgP = $(item).readAttribute("ImgP"); av7design.canvas.addItemInToCanvas(idElement, srcElement.file, ImgP); return false }, addItemInToCanvas: function (imgID, imgSrc, ImgP) { var A7Canvas = av7design != undefined ? av7design.canvas : this; var initialSize = A7Canvas.getInitialSizeItemForCanvas("image"); var canvasSize = A7Canvas.getCanvasCenterXY(); var x = canvasSize.CenterX - (initialSize.width / 2); var y = canvasSize.CenterY - (initialSize.height / 2); width = initialSize.width; height = parseInt(initialSize.height / ImgP); var zIndex = 0; var idElement = imgID; var fileSrc = imgSrc; $('instructions').hide(); A7Canvas.addItem(idElement, fileSrc, 0, 0, 2, 0, x, y, width, height, zIndex, -1, true, "image", "", 1, "", "", ""); A7Canvas.saveDataInCookie = true; A7Canvas.showOutfitManagingButtons(true); A7Canvas.saveCookie() }, getInitialSizeItemForCanvas: function (typeItem) { var initialSize = {}; switch (typeItem) { case messages.DECORATOR: initialSize.width = global.CANVAS_DECORATOR_SIZE_IMAGE; initialSize.height = global.CANVAS_DECORATOR_SIZE_IMAGE; break; case "text": initialSize.width = global.TEXT_DEFAULT_WIDTH; initialSize.height = global.TEXT_DEFAULT_HEIGHT; break; default: initialSize.width = global.CANVAS_DEFAULT_SIZE_IMAGE; initialSize.height = global.CANVAS_DEFAULT_SIZE_IMAGE; break } return initialSize }, selectItemManager: function (item) { if (this.selectedItem) this.selectedItem.unmarkAsSelectedItem(); this.selectedItem = item; item.markAsSelectedItem(); this.saveDataInCookie = true }, showItemManagingButtons: function (show) { if (show) { $("canvasControlsClothes").show(); if (this.selectedItem.options.typeItem == "text") $("canvasTextEditor").show() } else { $("canvasControlsClothes").hide(); $("canvasTextEditor").hide() } }, showOutfitManagingButtons: function (show) { if (show) { $$("div.canvasControlsOutfit").each(function (div) { $(div).show() }); $$("div.outfitControls").each(function (div) { $(div).show() }) } else { $$("div.canvasControlsOutfit").each(function (div) { $(div).hide() }); $$("div.outfitControls").each(function (div) { $(div).hide() }) } }, getNumberCopyItem: function (itemPrefix) { var n = 1; this.items.each(function (item) { if (itemPrefix + n == item.id) n++ }); return n }, bringToForeGround: function (item) { var maxZIndex = 0; var itemArray = this.items; itemArray.sort(this.sortItemsbyZindex); for (var i = 0; i < itemArray.length; i++) { if (itemArray[i].options.zIndex > item.options.zIndex && itemArray[i].id != item.id) { maxZIndex = itemArray[i].options.zIndex; itemArray[i].changeStyleAttributeItem('z-index', item.options.zIndex); item.changeStyleAttributeItem('z-index', maxZIndex); break } } }, sendToBackGround: function (item) { var minZIndex = 0; var itemArray = this.items; itemArray.sort(this.sortItemsbyZindex); for (var i = itemArray.length - 1; i >= 0; i--) { if (itemArray[i].options.zIndex < item.options.zIndex && itemArray[i].id != item.id) { minZIndex = itemArray[i].options.zIndex; itemArray[i].changeStyleAttributeItem('z-index', item.options.zIndex); item.changeStyleAttributeItem('z-index', minZIndex); break } } }, sortItemsbyZindex: function (a, b) { if (a.options.zIndex > b.options.zIndex) return 1; if (a.options.zIndex < b.options.zIndex) return -1; if (a.options.zIndex = b.options.zIndex) return 0 }, bringToForeGroundOnAddItem: function (item) { var maxZIndex = 0; for (var i = 0; i < this.items.length; i++) { if (this.items[i].options.zIndex > maxZIndex) { maxZIndex = this.items[i].options.zIndex } } item.changeStyleAttributeItem('z-index', maxZIndex + 1) }, addOneUnitToEveryZIndexItem: function (item) { for (var i = 0; i < this.items.length; i++) { this.items[i].changeStyleAttributeItem('z-index', this.items[i].options.zIndex + 1) } }, ToggleBackGround: function (item) { item.ToggleBackGround() }, ToggleOpacity: function (item) { item.ToggleOpacity() }, flipImage: function (item) { item.flipImage() }, flopImage: function (item) { item.flopImage() }, rotateImage: function (item, angle) { item.rotateImage(angle) }, cloneImage: function (item) { item.cloneImage() }, addItem: function (id, srcElement, flip, flop, clear, rotate, x, y, width, height, zIndex, insID, selectItem, typeItem, textHTML, opacity, textColor, textBGColor, textFont) { if (this.items.length < global.MAX_ITEMS_IN_CANVAS) { var instanceID = 0; var itemIDPrefix = typeItem + '_' + id + '_copy'; if (insID >= 0) { instanceID = insID } else { instanceID = this.getNumberCopyItem(itemIDPrefix) } var elementId = itemIDPrefix + instanceID; var newImage = new ItemPicture(this, elementId, { posX: x, posY: y, width: width, height: height, flip: flip, flop: flop, clear: clear, rotate: rotate, zIndex: zIndex, src: srcElement, pkItem: id, typeItem: typeItem, opacity: opacity, selectedWhenCreated: selectItem, textColor: textColor, textBGColor: textBGColor, textFont: textFont }); newImage.instanceID = instanceID; this.items.push(newImage) } else { var context = { description: messages.MESSAGE002, name: messages.ADVISE }; this.notifyObserver("onShowMessage", context) } }, onRemoveItem: function (event) { if (event.keyCode == Event.KEY_DELETE || event.keyCode == Event.KEY_BACKSPACE) { if ((this.selectedItem != '') && (!this.editingName)) { this.removeItemManager(this.selectedItem, true) } } }, onClickCanvas: function (event) { var elt = Event.findElement(event, 'div'); if (elt.id == this.element.id) { if (this.selectedItem) this.selectedItem.unmarkAsSelectedItem(); this.selectedItem = '' } }, removeItemManager: function (item, withEffect) { try { item.deleteItemFromCanvas(withEffect) } catch (e) { } this.items = this.items.without(item); this.selectedItem = ''; if (this.items.length == 0) { if (withEffect) t = setTimeout("$('instructions').show();", 400); else $('instructions').show(); this.showOutfitManagingButtons(false) } this.showItemManagingButtons(false); this.saveCookie() }, removeItemsStartingWithPrefix: function (prefix) { this.items.each(function (item) { if (prefix == item.id.substring(0, prefix.length)) this.removeItemManager(item, false) } .bind(this)) }, resetCanvas: function () { this.items.each(function (item) { this.removeItemManager(item, false) } .bind(this)); if (this.userId != "") { this.removeCookie() } }, getHTMLCanvas: function () { var returnedHTML = ''; this.items.each(function (item) { returnedHTML += item.getHTMLItem() } .bind(this)); return returnedHTML }, getHTMLCanvas: function (prefix) { var returnedHTML = ''; this.items.each(function (item) { returnedHTML += item.getHTMLItem(prefix) } .bind(this)); return returnedHTML }, HideFontSelection: function () { $("sFont").hide() } }; CanvasCombo = Class.create(); CanvasCombo.prototype = Object.extend(Object.extend(CanvasCombo.prototype, CanvasBase.prototype), { initialize: function (element, options) { this.start.apply(this, arguments); this.comboID = -1; this.nameCombo = ''; this.comboPicture = ''; this.description = ''; this.Music = ''; this.celebrityGUID = ''; this.moodPicture = ''; this.tagList = ''; this.comboPicture = ''; this.FBUserID = ''; this.FBSessionKey = ''; this.FBHasPermission = false; this.HasUserEnablesFBPost = false; this.FBChkBox = null; this.IsNewUser = 0; if (Sys.Browser.agent === Sys.Browser.Chrome || Sys.Browser.agent === Sys.Browser.Safari) { window.onbeforeunload = function () { var msg = "If you have not clicked 'Save as Draft' you will lose your outfit!"; if (av7design.canvas.items.length > 0) return msg } } else { Event.observe(window, 'beforeunload', this.Verify.bind(this)) } }, InitFacebookFeature: function () { FB_RequireFeatures(["Connect", "Api"], function () { FB.Facebook.init(FB_API_KEY, "../../xd_receiver.htm") }) }, InitFacebook: function (chkBox) { var CurObj = this; this.FBChkBox = chkBox; FB_RequireFeatures(["Connect", "Api"], function () { FB.Facebook.init(FB_API_KEY, "../../xd_receiver.htm"); FB.Connect.requireSession(function () { FB.ensureInit(function () { CurObj.VerifyUserHasPerm() }) }, function () { CurObj.FBChkBox.checked = false }); FB.Facebook.get_sessionState().waitUntilReady(function () { CurObj.FBUserID = FB.Facebook.apiClient.get_session().uid; CurObj.FBSessionKey = FB.Facebook.apiClient.get_session().session_key }) }) }, VerifyUserHasPerm: function () { var CurObj = this; var Fbperms = "publish_stream,offline_access"; FB.Facebook.apiClient.users_hasAppPermission(Fbperms, function (perms) { if (perms != null) { FB.Connect.showPermissionDialog(Fbperms, function (permgranted) { var permission = true; var temp = Fbperms.split(','); for (var i = 0; i < temp.length; i++) { if (permgranted == null || !permgranted) { permission = false; break } else { if (permgranted.indexOf(temp[i]) < 0) { permission = false; break } } } if (!permission) { CurObj.FBHasPermission = false; if (CurObj.FBChkBox != null) CurObj.FBChkBox.checked = false; alert("You need to grant these permissions before your proceed") } else { CurObj.FBHasPermission = true; if (CurObj.FBChkBox != null) CurObj.FBChkBox.checked = true; CurObj.HasUserEnablesFBPost = true; this.UpdateAutoPublishDetails(true) } }) } else { CurObj.FBHasPermission = true; CurObj.HasUserEnablesFBPost = true; if (CurObj.FBChkBox != null) CurObj.FBChkBox.checked = true; this.UpdateAutoPublishDetails(true) } }) }, PublishContentToFBWall: function (oGuid, oName, oDesc, oUrl, oImgUrl) { if (this.HasUserEnablesFBPost) { var action_links = [{ "text": "View details", "href": oUrl}]; var message = ''; var attachment = { 'name': oName, 'href': oUrl, 'caption': '', 'description': oDesc, 'properties': {}, 'media': [{ 'type': 'image', 'src': oImgUrl, 'href': oUrl}] }; try { var curObj = this; if (FB == null || FB.Connect == null) { FB_RequireFeatures(["Connect", "Api"], function () { FB.Facebook.init(FB_API_KEY, "../../xd_receiver.htm"); FB.Facebook.apiClient.set_session(curObj.FBSessionKey); FB.Connect.ifUserConnected(curObj.FBUserID, function (result) { FB.Facebook.apiClient.users_hasAppPermission("offline_access,publish_stream", function (perms) { FB.Facebook.apiClient.users_isAppUser(function (result, exception) { FB.Connect.streamPublish(message, attachment, action_links, curObj.FBUserID, '', curObj.PublishContentToFBWallCallBack, true) }) }) }) }) } else { FB.Connect.streamPublish(message, attachment, action_links, this.FBUserID, '', this.PublishContentToFBWallCallBack, true) } } catch (e) { MM.hideBox(); MW.hideBox(); MW.showBoxP('/ModalContent/OutfitSaved.aspx?OutfitGUID=&IsNewUser=' + this.IsNewUser) } } }, PublishContentToFBWall: function (oName, oUrl, oImgUrl) { Avenue7_Presentation.OutfitService.PublishToFBWall(this.FBUserID, this.FBSessionKey, oName, oUrl, oImgUrl, this.PublishContentToFBWallOnComplete, this.PublishContentToFBWallOnComplete, this) }, PublishContentToFBWallOnComplete: function (args, context) { if (args == "error") { alert("There was an error occured while publishing the outfits into your facebook wall."); context.UpdateAutoPublishDetails(false, context.FBSessionKey) } MM.hideBox(); MW.hideBox(); MW.showBoxP('/ModalContent/OutfitSaved.aspx?OutfitGUID=&IsNewUser=' + context.IsNewUser) }, PublishContentToFBWallCallBack: function (post_id, exception) { MM.hideBox(); MW.hideBox(); if (exception == null) { } else { alert("There was an issue publishing the outfit into your facebook wall!") } MW.showBoxP('/ModalContent/OutfitSaved.aspx?OutfitGUID=&IsNewUser=' + this.IsNewUser) }, DisplayPopupMsgWithNoButtons: function (Msg, Title) { MM.hideBox(); MW.hideBox(); MM.showMessage(Msg, Title); $('MimgClose').hide(); $("warningOK").hide() }, Verify: function (event) { var msg = "If you have not clicked 'Save as Draft' you will lose your outfit!"; if (this.items.length > 0) { return (event.returnValue = msg) } }, VerifyCanvasItems: function () { this.IsSaveBtnClicked = true; var blnIsItemsFallOutsideCanvas = false; var ItemPk = ""; var canvasSize = {}; canvasSize.width = parseInt(this.element.getStyle('width').sub('px', '')); canvasSize.height = parseInt(this.element.getStyle('height').sub('px', '')); this.items.each(function (item) { var X1 = item.options.posX + item.options.width; var Y1 = item.options.posY + item.options.height; var X2 = item.options.posX; var Y2 = item.options.posY; if (X1 < 0 || X2 > canvasSize.width || Y1 < 0 || Y2 > canvasSize.height) { blnIsItemsFallOutsideCanvas = true; ItemPk += item.idwrapper + "," } }); if (!blnIsItemsFallOutsideCanvas) { if (this.userId != "88888888-8888-8888-8888-888888888888") { if (this.comboID != -1) this.saveCanvas(); else MW.showBoxP('/ModalContent/OutfitDetails.aspx?' + Math.floor((new Date()).getTime() / 86400000)) } else { MW.showBoxP("/modalContent/LoginSml.aspx") } } else { MW.showBoxP('/ModalContent/OutfitOnError.aspx?items=' + ItemPk) } return false }, saveCanvas: function () { if (this.userId != "") { this.DisplayPopupMsgWithNoButtons("Saving your outfit...", "Saving..."); var comboDesignSaveData = Object.toJSON(this.getCanvasObject()); var comboDesignSaveDataOnlyItems = Object.toJSON(this.getCanvasObjectOnlyItems()); Avenue7_Presentation.OutfitService.SaveOutfitDesign(escape(comboDesignSaveData), escape(comboDesignSaveDataOnlyItems), escape(this.getHTMLCanvas()), this.saveOutfitOC, this.saveOutfitOE, this) } else { MW.showBoxP("/modalContent/LoginSml.aspx") } }, saveOutfitOC: function (arg, context) { var response = arg.evalJSON(); var tempID = context.comboID; if (response.Code == 0) { context.comboID = response.MessageBack; if (context.userId != "") { context.removeCookie() } try { av7design.palette.ResetToDefault() } catch (e) { } var OutfitDetails = []; context.newCombo(); context.context = ""; if (context.HasUserEnablesFBPost) { try { OutfitDetails = response.ComboName.evalJSON() } catch (e) { } if (OutfitDetails != null) { context.DisplayPopupMsgWithNoButtons("Publishing your outfit to your facebook...", "Publishing..."); context.PublishContentToFBWall(OutfitDetails.OutfitName, OutfitDetails.OutfitUrl, OutfitDetails.OutfitImgUrl) } else { MM.hideBox(); MW.showBoxP('/ModalContent/OutfitSaved.aspx?OutfitGUID=' + tempID + '&IsNewUser=' + context.IsNewUser) } } else { MM.hideBox(); MW.showBoxP('/ModalContent/OutfitSaved.aspx?OutfitGUID=' + tempID + '&IsNewUser=' + context.IsNewUser) } } else { MW.hideBox(); if (response.Code == 901) { context.IsSaveBtnClicked = true; MW.showBoxP("/modalContent/LoginSml.aspx") } else { var msg = { description: response.ErrorMessage, name: response.TypeMessage }; context.notifyObserver("onShowMessage", msg) } } }, saveOutfitOE: function (arg, context) { return false }, saveCanvasAsDraft: function () { if (this.userId != "88888888-8888-8888-8888-888888888888") { $('userName').value = this.userId; var comboDesignSaveData = Object.toJSON(this.getCanvasObject()); Avenue7_Presentation.OutfitService.SaveOutfitDraft(escape(comboDesignSaveData), this.saveOutfitAsDraftOC, this.saveOutfitOE, this) } else { MW.showBoxP("/modalContent/LoginSml.aspx") } }, saveOutfitAsDraftOC: function (arg, context) { var response = arg.evalJSON(); var tempID = context.comboID; if (response.Code == 0) { try { av7design.palette.ResetToDefault() } catch (e) { } MM.showMessage("Your outfit has been added to your drafts tab", "Draft saved successfully!"); av7design.AddAnalytics(251) } else { MW.hideBox(); if (response.Code == 901) { MW.showBoxP("/modalContent/LoginSml.aspx") } else { var msg = { description: response.ErrorMessage, name: response.TypeMessage }; context.notifyObserver("onShowMessage", msg) } } context.removeCookie(); context.newCombo(); return false }, DeleteDraft: function (DraftID) { if (confirm("Are you sure want to delete this outfit from draft?")) { Avenue7_Presentation.OutfitService.DeleteDraft(DraftID, this.DeleteDraftOC, this.DeleteDraftOE, this); if (this.DraftID = DraftID) { this.resetCanvas(); this.DraftID = -1; this.DraftPicture = "" } } }, DeleteDraftOC: function (arg, context) { MM.showMessage("The outfit from the draft has been successfully deleted.", "Draft deleted successfully!"); av7design.palette.RefreshTabDetails(-2) }, DeleteDraftOE: function (arg, context) { MM.showMessage(arg, "Error saving draft!") }, UpdateAutoPublishDetails: function (blnAutoPublish, SessionKey) { Avenue7_Presentation.OutfitService.UpdateSocialXConnectAutoPublish(1, this.FBUserID, this.userId, blnAutoPublish, SessionKey, function (args) { }, function (args) { }) }, saveCookie: function () { }, removeCookie: function (value) { this.cookiejar.remove("CBO" + this.userId); this.cookiejar.remove("CBO88888888-8888-8888-8888-888888888888") }, newCombo: function () { this.resetCanvas(); this.comboPicture = ''; this.comboID = -1; if (this.DraftID > -1) { av7design.palette.RefreshTabDetails(-2); this.DraftID = -1; this.DraftPicture = "" } }, getCanvasObject: function () { var comboDesignData = { Name: this.nameCombo, Description: this.description, Music: this.Music, CelebrityGUID: this.celebrityGUID, MoodPicture: this.moodPicture, TagList: this.tagList, ComboPicture: this.DraftID > -1 ? this.DraftPicture : this.comboPicture, ComboID: this.comboID, IsFromDraft: this.DraftID > -1 ? true : false, DraftID: this.DraftID, Items: [] }; this.items.each(function (item) { var itemCanvas = item.getObjectToCommunicateWithServer(); comboDesignData.Items.push(itemCanvas) } .bind(this)); return comboDesignData }, getCanvasObjectOnlyItems: function () { var comboDesignData = { Name: this.nameCombo, Description: this.description, Music: this.Music, CelebrityGUID: this.celebrityGUID, MoodPicture: this.moodPicture, TagList: this.tagList, ComboPicture: this.comboPicture, ComboID: this.comboID, Items: [] }; this.items.each(function (item) { if (item.options.typeItem == messages.ITEM) { var itemCanvas = item.getObjectToCommunicateWithServer(); comboDesignData.Items.push(itemCanvas) } } .bind(this)); return comboDesignData }, SetComboName: function (name) { this.nameComboWatermark.setText(name); this.saveCanvas() }, checkSavingCombo: function () { var errMessage = ''; var text = this.nameComboWatermark.getText(); if (text == '' || text == "Name Of Combination") errMessage = messages.MESSAGE004; if (this.items.length == 0) errMessage = messages.MESSAGE005; var invalidCharacter = false; for (var i = 0; i < text.length; i++) { if (messages.VALIDCHARACTERS.indexOf(text.charAt(i)) < 0) { invalidCharacter = true } } if (invalidCharacter) errMessage = messages.MESSAGE008; return errMessage } }); ItemBase = Abstract; ItemBase.prototype = { start: function (canvas, element, options) { this.options = Object.extend({ posX: 0, posY: 0, width: 0, height: 0, zIndex: 1, src: '', typeItem: '', pkItem: '', selectedWhenCreated: false, flip: 0, flop: 0, rotate: 0, clear: 2, opacity: 1, textColor: 'rgb(0,0,0)', textBGColor: 'rgb(255,255,255)', textFont: 'Arial' }, options || {}); this.canvas = canvas; this.id = element; this.idwrapper = element + 'wrapdiv'; this.instanceID = 0; if (this.options.typeItem == "text") { this.options.textColor = this.options.textColor == "" ? "rgb(0,0,0)" : this.options.textColor; this.options.textBGColor = this.options.textBGColor == "" ? "rgb(255,255,255)" : this.options.textBGColor; this.options.textFont = this.options.textFont == "" ? "Arial" : this.options.textFont; this.options.clear = 0 } this.draw(); this.handles = []; this.selectItemBind = this.onSelectItem.bindAsEventListener(this); var nameAllHandles = ["handle NE", "handle SE", "handle SW", "handle NW", "handle R"]; for (var i = 0; i < nameAllHandles.length; ++i) { this.handles.push(new Handle(this, nameAllHandles[i])) } this.registerItemEvents(); this.IsZoom = false; this.ZIndexOnDrag = 0; this._values = [1, 0, 0, 1]; if (this.options.rotate != 0) { var angle = this.options.rotate * (Math.PI / 180); this.SetRotationMatrix(-angle) } }, getThumbnailPicture: function (pathPictureFile) { var width = this.options.width; var height = this.options.height; if (height == null || height > 400) height = 400; if (width == null || width > 400) width = 400; if (this.options.typeItem == "image") { return this.canvas.options.rootPathApp + 'MakeThumbnailPng.aspx?width=' + width + '&height=' + height + '&flip=' + this.options.flip + '&flop=' + this.options.flop + '&rotate=' + this.options.rotate + '&noar=1&clear=' + this.options.clear + '&opacity=' + this.options.opacity + '&file=' + escape(pathPictureFile) } else { var Clr = this.options.textColor == "" ? "rgb(0,0,0)" : this.options.textColor; var BgClr = this.options.textBGColor == "" ? "rgb(255,255,255)" : this.options.textBGColor; var Font = this.options.textFont == "" ? "Arial" : this.options.textFont; return this.canvas.options.rootPathApp + 'MakeThumbnailPng.aspx?width=' + width + '&height=' + height + '&flip=' + this.options.flip + '&flop=' + this.options.flop + '&rotate=' + this.options.rotate + '&noar=1&clear=' + this.options.clear + '&opacity=' + this.options.opacity + '&text=' + escape(pathPictureFile) + "&clr=" + escape(Clr) + "&bg=" + escape(BgClr) + "&font=" + escape(Font) } }, getThumbnailPictureSmall: function () { var img = "<img alt='' src='"; if (this.options.typeItem == "image") { img += this.canvas.options.rootPathApp + 'MakeThumbnailPng.aspx?width=45&height=45&flip=&flop=&rotate=0&noar=1&clear=2&opacity=1&file=' + escape(this.options.src) } else { var Clr = this.options.textColor == "" ? "rgb(0,0,0)" : this.options.textColor; var BgClr = this.options.textBGColor == "" ? "rgb(255,255,255)" : this.options.textBGColor; var Font = this.options.textFont == "" ? "Arial" : this.options.textFont; img += this.canvas.options.rootPathApp + 'MakeThumbnailPng.aspx?width=45&height=25&flip=&flop=&rotate=0&noar=1&clear=' + this.options.clear + '&opacity=1&text=Avenue7&clr=' + escape(Clr) + '&bg=' + escape(BgClr) + '&font=' + escape(Font) } return img += "' />" }, getThumbnailPictureSmall2: function (pathPictureFile) { return this.canvas.options.rootPathApp + 'MakeThumbnailPng.aspx?width=100&height=100&flip=' + this.options.flip + '&flop=' + this.options.flop + '&rotate=' + this.options.rotate + '&noar=1&clear=2&opacity=1&file=' + escape(pathPictureFile) }, getThumbnailTextPictureSmall: function () { var Font = this.options.textFont == "" ? "Arial" : this.options.textFont; var img = "<img alt='" + Font + "' src='"; img += this.canvas.options.rootPathApp + 'MakeThumbnailPng.aspx?width=75&height=20&flip=&flop=&rotate=0&noar=1&clear=2&opacity=1&text=Avenue7&clr=&bg=&font=' + Font; return img += "' />" }, getObjectToCommunicateWithServerTemplate: function () { var item = {}; item.ItemType = this.options.typeItem; item.ItemPK = this.options.pkItem; item.PathImage = this.options.src; item.XPosition = this.options.posX; item.YPosition = this.options.posY; item.ZPosition = this.options.zIndex; item.Width = this.options.width; item.Height = this.options.height; item.Flip = this.options.flip; item.Flop = this.options.flop; item.Clear = this.options.clear; item.Rotate = this.options.rotate; item.InstanceID = this.instanceID; item.Opacity = this.options.opacity; item.TextColor = this.options.textColor; item.TextBGColor = this.options.textBGColor; item.TextFont = this.options.textFont; return item }, registerItemEvents: function () { Event.observe(this.idwrapper, 'click', this.selectItemBind); var dragoptions = null; if (Prototype.Browser.IE && this.options.rotate != 0) dragoptions = { zindex: this.options.zIndex, starteffect: null, endeffect: null }; else dragoptions = { zindex: this.options.zIndex }; this.dragHandle = new Draggable(this.idwrapper, { zindex: this.options.zIndex, onStart: function (element) { this.canvas.selectItemManager(this); this.ZIndexOnDrag = this.options.zIndex } .bind(this), onDrag: function (element) { this.manageHandlerVisibility(element) } .bind(this), onEnd: function (element) { this.canvas.saveDataInCookie = true; this.updateItemOptions(); if (!this.isItemInsideCanvasArea()) this.canvas.removeItemManager(this, false) } .bind(this), starteffect: function (element) { if (Prototype.Browser.IE && this.options.rotate != 0) { } else { new Effect.Opacity(element, { duration: 0, from: 1, to: 0.7 }) } } .bind(this), endeffect: function (element) { if (Prototype.Browser.IE && this.options.rotate != 0) { } else { new Effect.Opacity(element, { duration: 0, from: 0.7, to: 1 }) } } .bind(this) }) }, isItemInsideCanvasArea: function () { var canvasSize = {}; var insideCanvas = true; var canvasDimension = this.canvas.element.getDimensions(); canvasSize.width = parseInt(canvasDimension.width); canvasSize.height = parseInt(canvasDimension.height); if (((this.options.posX + this.options.width) < 0) || (this.options.posX > canvasSize.width)) insideCanvas = false; if (((this.options.posY + this.options.height) < 0) || (this.options.posY > canvasSize.height)) insideCanvas = false; return insideCanvas }, manageHandlerVisibility: function (element) { }, deleteItemFromCanvasTemplate: function (withEffect) { this.dragHandle.destroy(); this.handles.each(function (handle) { Event.stopObserving(handle.node, 'mousedown', handle.mouseDownBind) }); var allHandles = 'div#' + this.idwrapper + ' div'; $$(allHandles).each(function (handle) { if ((versionIE >= 5.5) && (versionIE < 7) && (document.body.filters)) { if (handle.className != "") handle.remove() } else { handle.remove() } }); try { if (withEffect) { Effect.Shrink(this.id, { afterFinish: function () { Element.remove($(this.idwrapper)) } .bind(this) }) } else { Element.remove($(this.idwrapper)) } } catch (e) { Element.remove($(this.idwrapper)) } }, onSelectItem: function () { this.canvas.selectItemManager(this) }, markAsSelectedItemTemplate: function () { var allHandles = 'div#' + this.idwrapper + ' .handle'; $$(allHandles).each(function (handle) { $(handle).addClassName('imgRszHandle') }); $(this.idwrapper).addClassName('selectedImgWrapper'); if (Prototype.Browser.IE) { var styleBorder = "position:absolute; top:5px; left:5px; border: 1px solid #aaa; width:" + (this.options.width + 4) + "px; height:" + (this.options.height + 4) + "px" } else { var styleBorder = "position:absolute; top:3px; left:3px; border: 1px solid #aaa; width:" + (this.options.width + 2) + "px; height:" + (this.options.height + 2) + "px" } var borderWrapper = Builder.node("div", { id: this.idwrapper + "_border", style: styleBorder }); $(this.idwrapper).appendChild(borderWrapper); this.canvas.showItemManagingButtons(true); var BkGrndToggle = this.options.clear == 2 ? "Keep" : "Remove"; $('btnToggleBkGrnd').innerHTML = BkGrndToggle + " background"; $('btnToggleopacity').innerHTML = this.options.opacity == 1 ? "Make transparent" : "Make solid"; if (this.options.typeItem == "text") { $("txtText").value = this.options.src; $("spBG").setStyle({ backgroundColor: this.options.textBGColor }); $("spColor").setStyle({ backgroundColor: this.options.textColor }); var objThis = this; $("spCText").innerHTML = this.getThumbnailTextPictureSmall(); this.canvas.HideFontSelection() } $("canvasControlsClothesPreview").innerHTML = this.getThumbnailPictureSmall() }, unmarkAsSelectedItemTemplate: function () { var allHandles = 'div#' + this.idwrapper + ' .handle'; $$(allHandles).each(function (handle) { $(handle).removeClassName('imgRszHandle') }); if ($(this.idwrapper + "_border")) $(this.idwrapper + "_border").remove(); this.canvas.showItemManagingButtons(false) }, resizeItemTemplate: function (topOffset, leftOffset, widthOffset, heightOffset) { var styleElement; var styleWrapper; var styleBorderWrapper; if ($(this.id)) styleElement = $(this.id).style; if ($(this.idwrapper)) styleWrapper = $(this.idwrapper).style; if ($(this.idwrapper + "_border")) styleBorderWrapper = $(this.idwrapper + "_border").style; if (topOffset != 0 && topOffset) { if ($(this.idwrapper)) { if (this.IsZoom) styleWrapper.top = topOffset + "px"; else styleWrapper.top = Math.round(this.options.posY + topOffset) + "px" } } if (leftOffset != 0 && leftOffset) { if ($(this.idwrapper)) { if (this.IsZoom) styleWrapper.left = leftOffset + "px"; else styleWrapper.left = Math.round(this.options.posX + leftOffset) + "px" } } if (widthOffset != 0 && widthOffset) { var width = this.options.width + widthOffset; if (width > 10) { if ($(this.id)) styleElement.width = width + "px"; if ($(this.idwrapper + "_border")) styleBorderWrapper.width = (width + 1) + "px" } } if (heightOffset != 0 && heightOffset) { var height = this.options.height + heightOffset; if (height > 10) { if ($(this.id)) styleElement.height = height + "px"; if ($(this.idwrapper + "_border")) styleBorderWrapper.height = (height + 1) + "px" } } }, changeStyleAttributeItemTemplate: function (attribute, value) { switch (attribute) { case 'top': $(this.idwrapper).setStyle({ top: value }); break; case 'left': $(this.idwrapper).setStyle({ left: value }); break; case 'z-index': $(this.idwrapper).setStyle({ zIndex: value }); break; case 'width': $(this.id).setStyle({ width: value }); break; case 'height': $(this.id).setStyle({ height: value }); break } }, ToggleBackGround: function () { }, ToggleOpacity: function () { }, flipImage: function () { }, flopImage: function () { }, rotateImage: function (angle) { }, updateItemOptionsTemplate: function () { if ($(this.idwrapper)) { this.options.posY = parseInt(Element.getStyle($(this.idwrapper), 'top')); this.options.posX = parseInt(Element.getStyle($(this.idwrapper), 'left')); this.options.zIndex = parseInt(Element.getStyle($(this.idwrapper), 'z-index')); this.options.width = parseInt(Element.getStyle($(this.id), 'width')); this.options.height = parseInt(Element.getStyle($(this.id), 'height')); if (this.userId != "") { if (this.canvas.saveDataInCookie) this.canvas.saveCookie() } } }, getCanvasCenterPoint: function () { var Dim = []; var canvasDimension = this.canvas.element.getDimensions(); Dim.width = parseInt(canvasDimension.width); Dim.height = parseInt(canvasDimension.height); return Dim }, calculateScale: function (x, y) { var ExtraZoomFactor = -0.2; var canvasSize = this.getCanvasCenterPoint(); var canvascenterX = canvasSize.width / 2; var canvascenterY = canvasSize.height / 2; var scalefactor = 0; var temp; if ((x < 0 || x > canvasSize.width) || (y < 0 || y > canvasSize.height)) { temp = (x - canvascenterX) / canvascenterX; temp = temp < 0 ? temp * -1 : temp; scalefactor = Math.max(temp, scalefactor); temp = (y - canvascenterY) / canvascenterY; temp = temp < 0 ? temp * -1 : temp; scalefactor = Math.max(temp, scalefactor); scalefactor = scalefactor - ExtraZoomFactor } return scalefactor > 0 ? 1 / scalefactor : scalefactor }, Scale: function () { var P1x = this.options.posX; var P1y = this.options.posY; var P2x = this.options.posX + this.options.width; var P2y = P1y; var P3x = P1x; var P3y = this.options.posY + this.options.height; var P4x = P2x; var P4y = P3y; var scalefactor = 0; var temp; scalefactor = Math.max(scalefactor, this.calculateScale(P1x, P1y)); scalefactor = Math.max(scalefactor, this.calculateScale(P2x, P2y)); scalefactor = Math.max(scalefactor, this.calculateScale(P3x, P3y)); scalefactor = Math.max(scalefactor, this.calculateScale(P4x, P4y)); return scalefactor } }; ItemPicture = Class.create(); ItemPicture.prototype = Object.extend(Object.extend(ItemPicture.prototype, ItemBase.prototype), { initialize: function (canvas, element, options) { this.start.apply(this, arguments); this.canvas.bringToForeGroundOnAddItem(this); this.Toggle = false; this._previousAngle = 0 }, getObjectToCommunicateWithServer: function () { return this.getObjectToCommunicateWithServerTemplate() }, getHTMLItem: function (prefix) { if (prefix == null) prefix = ""; var auxStyle = 'position: absolute; overflow:hidden; left:' + this.options.posX + 'px; top:' + this.options.posY + 'px; z-index:' + this.options.zIndex; var pathThumbnailPicture = this.getThumbnailPicture(this.options.src); var nodeHTML = Builder.node('div', { id: prefix + this.idwrapper, className: 'imgWrapper', width: this.options.width, height: this.options.height, style: auxStyle }, [Builder.node('img', { id: prefix + this.id, width: this.options.width, height: this.options.height, src: pathThumbnailPicture, style: 'position:relative; padding:4px', className: 'item' })]); return nodeHTML.outerHTML }, redraw: function () { this.SetAlphaFilter() }, draw: function () { var imgStyle = 'left:' + this.options.posX + 'px; top:' + this.options.posY + 'px; z-index:' + this.options.zIndex + '; display:none'; var pathThumbnailPicture = this.getThumbnailPicture(this.options.src); if (Prototype.Browser.IE) { styleFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(Src=' + pathThumbnailPicture + ',SizingMethod=scale);width:' + (this.options.width) + 'px;height:' + (this.options.height) + 'px;margin:8px;'; var picture = Builder.node('div', { id: this.id, style: styleFilter }) } else { var picture = Builder.node('img', { id: this.id, width: this.options.width, height: this.options.height, src: pathThumbnailPicture, className: 'item' }) } if (Prototype.Browser.IE) { imgStyle += "filter: progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand')" } this.node = Builder.node('div', { id: this.idwrapper, width: this.options.width, height: this.options.height, className: 'imgWrapper', style: imgStyle }, [picture]); $(this.canvas.element).appendChild(this.node); Effect.Appear($(this.node.id), { duration: 1, afterFinish: function () { if (this.options.selectedWhenCreated) { if ($(this.idwrapper)) { this.onSelectItem() } } else { if ($(this.idwrapper)) { this.unmarkAsSelectedItem() } } } .bind(this) }); this.updateItemOptions(); this.SetMargins() }, ToggleBackGround: function () { this.options.clear = this.options.clear == 2 ? 0 : 2; var text = this.options.clear == 2 ? "Keep" : "Remove"; text += " background"; this.SetAlphaFilter(); this.updateItemOptions(); $('btnToggleBkGrnd').innerHTML = text }, SetAlphaFilter: function () { if (Prototype.Browser.IE) { styleFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(Src=' + this.getThumbnailPicture(this.options.src) + ',SizingMethod=scale); width:' + this.options.width + 'px ;height:' + this.options.height + 'px; margin:8px'; var picture = Builder.node('div', { id: this.id, style: styleFilter }); $(this.id).outerHTML = picture.outerHTML } else { $(this.id).src = this.getThumbnailPicture(this.options.src) } }, ToggleOpacity: function () { this.options.opacity = this.options.opacity == 1 ? 0.5 : 1; this.updateItemOptions(); this.SetAlphaFilter(); $('btnToggleopacity').innerHTML = this.options.opacity == 1 ? "Make transparent" : "Make solid" }, flipImage: function () { this.options.flip = 1 - this.options.flip; this.SetAlphaFilter(); this.updateItemOptions() }, flopImage: function () { this.options.flop = 1 - this.options.flop; this.SetAlphaFilter(); this.updateItemOptions() }, rotateImage: function (angle) { this.options.rotate = ((this.options.rotate == undefined ? 0 : this.options.rotate) + angle) % 360; if ((versionIE >= 5.5) && (versionIE < 7) && (document.body.filters)) { styleFilter = 'filter:progid:DXImageTransform.Microsoft.Matrix(sizingMethod="auto expand"); width:' + this.options.width + 'px ;height:' + this.options.height + 'px; margin:8px'; var picture = Builder.node('div', { id: this.id, style: styleFilter }); $(this.id).outerHTML = picture.outerHTML } this.updateItemOptions() }, rotateImageNew: function (blnSetMargins) { if (this.options.rotate != 0) { if (document.body.filters) { $(this.idwrapper).setStyle({ filter: 'progid:DXImageTransform.Microsoft.Matrix(sizingMethod="auto expand")' }); var matrix = $(this.idwrapper).filters["DXImageTransform.Microsoft.Matrix"]; matrix.M11 = this._values[0]; matrix.M12 = this._values[2]; matrix.M21 = this._values[1]; matrix.M22 = this._values[3]; if (blnSetMargins) this.SetMargins() } else { var mat = [this._values[0], this._values[1], this._values[2], this._values[3], 0, 0].join(","); $(this.idwrapper).setStyle({ MozTransform: "matrix(" + mat + ")", WebkitTransform: "matrix(" + mat + ")", OTransform: "matrix(" + mat + ")" }) } } }, CalculateOffsetsOnRotate: function () { }, cloneImage: function () { var x = this.options.posX + 20; var y = this.options.posY + 20; var width = this.options.width; var height = this.options.height; var canvasSize = {}; var canvasDimension = this.canvas.element.getDimensions(); canvasSize.width = parseInt(canvasDimension.width); canvasSize.height = parseInt(canvasDimension.height); if ((((x + width) < 0) || (x > canvasSize.width)) || (((y + height) < 0) || (y > canvasSize.height))) { x = y = 10 } this.canvas.addItem(this.options.pkItem, this.options.src, this.options.flip, this.options.flop, this.options.clear, this.options.rotate, x, y, width, height, 0, -1, true, this.options.typeItem, "", this.options.opacity, this.options.textColor, this.options.textBGColor, this.options.textFont); this.saveDataInCookie = true }, deleteItemFromCanvas: function (withEffect) { this.deleteItemFromCanvasTemplate(withEffect) }, markAsSelectedItem: function () { this.markAsSelectedItemTemplate() }, unmarkAsSelectedItem: function () { this.unmarkAsSelectedItemTemplate() }, updateItemOptions: function () { this.updateItemOptionsTemplate() }, changeStyleAttributeItem: function (attribute, value) { this.changeStyleAttributeItemTemplate(attribute, value); this.updateItemOptions() }, resizeItem: function (topOffset, leftOffset, widthOffset, heightOffset) { this.resizeItemTemplate(topOffset, leftOffset, widthOffset, heightOffset) }, SetRotationMatrix: function (angle) { var CosTheta = Math.cos(angle); var SinTheta = Math.sin(angle); this._values[0] = CosTheta; this._values[1] = -SinTheta; this._values[2] = SinTheta; this._values[3] = CosTheta; this.options.rotate = -(angle / (2 * Math.PI) * 360); this.rotateImageNew(true) }, Rotate: function (event, movedX, movedY) { this.rect = []; this.rect.x1 = this.options.posX; this.rect.y1 = this.options.posY; this.rect.x2 = this.options.posX + this.options.width; this.rect.y2 = this.options.posY + this.options.height; this.Center = []; this.Center.x = (this.rect.x1 + this.rect.x2) / 2; this.Center.y = (this.rect.y1 + this.rect.y2) / 2; var EventXY = this.GetCanvasXYPos(event); var rad = this.ConvertRatioToAngle(EventXY.x - this.Center.x, -EventXY.y + this.Center.y); var tmpAngle = rad / (2 * Math.PI) * 360; var tmpRad = tmpAngle * (Math.PI / 180); if (tmpAngle > 0) tmpAngle = 360 - tmpAngle; else tmpAngle = -tmpAngle; this.SetRotationMatrix(rad); Event.stop(event) }, GetPageXYDetails: function (event) { var x = event.pageX; var tmp = []; if (!x && 0 !== x) { x = event.clientX || 0 } var y = event.pageY; if (!y && 0 !== y) { y = event.clientY || 0 } tmp.x = x; tmp.y = y; return tmp }, GetWindowScrollPos: function () { var tmp = []; if (window.pageXOffset !== undefined) { tmp.x = window.pageXOffset; tmp.y = window.pageYOffset } else { if (document.documentElement) { tmp.x = document.documentElement.scrollLeft; tmp.y = document.documentElement.scrollTop } else { tmp.x = document.body.scrollLeft; tmp.y = document.body.scrollTop } } return tmp }, ConvertRatioToAngle: function (x, y) { var hyp = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); var angle = -Math.asin(x / hyp); if (y < 0) { angle = Math.PI - angle } return angle }, GetCanvasXYPos: function (event) { var XY_Pos = this.GetPageXYDetails(event); var CanvasXY = getElementXYPos(this.canvas.element); XY_Pos.x -= CanvasXY.x; XY_Pos.y -= CanvasXY.y; return XY_Pos }, SetMargins: function () { if (Prototype.Browser.IE) { var offset = $(this.idwrapper).getDimensions(); var mleft = ((this.options.width - offset.width) / 2) - 2 + "px"; var mtop = ((this.options.height - offset.height) / 2) - 2 + "px"; $(this.idwrapper).setStyle({ marginLeft: mleft, marginTop: mtop }) } } }); Handle = Class.create(); Handle.prototype = { initialize: function (item, position) { this.item = item; this.node = Builder.node('div', { className: position }); this.position = position; this.startX = 0; this.startY = 0; this.mouseDownBind = this.onMouseDown.bindAsEventListener(this); this.mouseUpBind = this.onMouseUp.bindAsEventListener(this); this.mouseMoveBind = this.onMouseMove.bindAsEventListener(this); $(this.item.idwrapper).appendChild(this.node); Event.observe(this.node, 'mousedown', this.mouseDownBind) }, onMouseDown: function (event) { Event.observe(document, 'mouseup', this.mouseUpBind); Event.observe(document, 'mousemove', this.mouseMoveBind); this.item.canvas.saveDataInCookie = true; this.startX = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; this.startY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop; if (this.position != 'handle R') new Effect.Opacity($(this.item.id), { duration: 0.2, from: 1, to: 0.7 }); Event.stop(event) }, onMouseMove: function (event) { var pointer = [Event.pointerX(event), Event.pointerY(event)]; var pointerMovedX = this.startX - pointer[0]; var pointerMovedY = this.startY - pointer[1]; if (this.position == 'handle R') { this.item.Rotate(event, pointer[0], pointer[1]); return } var canvas = getElementXYPos(this.item.canvas.element); var mouseX = pointer[0] - canvas.x; var mouseY = pointer[1] - canvas.y; var theta = this.item.options.rotate; var width = this.item.options.width; var height = this.item.options.height; var thetaRad = theta * Math.PI / 180; var delta = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) / 2; var beta = Math.atan(width / height); var alpha = beta - thetaRad; var omega = 2 * Math.asin(width / (2 * delta)); var deltaPosY, deltaPosX, deltaWidth, deltaHeight; if (this.position == 'handle SE') { var mx = mouseX - (this.item.options.posX + width / 2 + delta * Math.sin(alpha)); var my = mouseY - (this.item.options.posY + height / 2 + delta * Math.cos(alpha)); var md = Math.sqrt(Math.pow(mx, 2) + Math.pow(my, 2)); var epsilon = Math.asin(my / md); if (mx < 0) epsilon = Math.PI - epsilon; var lambda = Math.PI / 2 - epsilon + thetaRad; deltaWidth = md * Math.sin(lambda); deltaHeight = md * Math.cos(lambda); if (width + deltaWidth < 10) deltaWidth = 10 - width; if (height + deltaHeight < 10) deltaHeight = 10 - height; var newWidth = width + deltaWidth; var newHeight = height + deltaHeight; var newDelta = Math.sqrt(Math.pow(newWidth, 2) + Math.pow(newHeight, 2)) / 2; var newBeta = Math.atan(newWidth / newHeight); var newAlpha = newBeta - thetaRad; deltaPosX = (width - newWidth) / 2 + (newDelta * Math.sin(newAlpha) - delta * Math.sin(alpha)); deltaPosY = (height - newHeight) / 2 + (newDelta * Math.cos(newAlpha) - delta * Math.cos(alpha)) } else if (this.position == 'handle NE') { var mx = mouseX - (this.item.options.posX + width / 2 + delta * Math.sin(omega - alpha)); var my = mouseY - (this.item.options.posY + height / 2 - delta * Math.cos(omega - alpha)); var md = Math.sqrt(Math.pow(mx, 2) + Math.pow(my, 2)); var epsilon = Math.asin(my / md); if (mx < 0) epsilon = Math.PI - epsilon; var lambda = Math.PI / 2 - epsilon + thetaRad; deltaWidth = md * Math.sin(lambda); deltaHeight = -md * Math.cos(lambda); if (width + deltaWidth < 10) deltaWidth = 10 - width; if (height + deltaHeight < 10) deltaHeight = 10 - height; var newWidth = width + deltaWidth; var newHeight = height + deltaHeight; var newDelta = Math.sqrt(Math.pow(newWidth, 2) + Math.pow(newHeight, 2)) / 2; var newBeta = Math.atan(newWidth / newHeight); var newAlpha = newBeta - thetaRad; var newOmega = 2 * Math.asin(newWidth / (2 * newDelta)); deltaPosX = (width - newWidth) / 2 + (newDelta * Math.sin(newOmega - newAlpha) - delta * Math.sin(omega - alpha)); deltaPosY = (height - newHeight) / 2 + (delta * Math.cos(omega - alpha) - newDelta * Math.cos(newOmega - newAlpha)) } else if (this.position == 'handle SW') { var mx = mouseX - (this.item.options.posX + width / 2 - delta * Math.sin(omega - alpha)); var my = mouseY - (this.item.options.posY + height / 2 + delta * Math.cos(omega - alpha)); var md = Math.sqrt(Math.pow(mx, 2) + Math.pow(my, 2)); var epsilon = Math.asin(my / md); if (mx < 0) epsilon = Math.PI - epsilon; var lambda = Math.PI / 2 - epsilon + thetaRad; deltaWidth = -md * Math.sin(lambda); deltaHeight = md * Math.cos(lambda); if (width + deltaWidth < 10) deltaWidth = 10 - width; if (height + deltaHeight < 10) deltaHeight = 10 - height; var newWidth = width + deltaWidth; var newHeight = height + deltaHeight; var newDelta = Math.sqrt(Math.pow(newWidth, 2) + Math.pow(newHeight, 2)) / 2; var newBeta = Math.atan(newWidth / newHeight); var newAlpha = newBeta - thetaRad; var newOmega = 2 * Math.asin(newWidth / (2 * newDelta)); deltaPosX = (width - newWidth) / 2 + (delta * Math.sin(omega - alpha) - newDelta * Math.sin(newOmega - newAlpha)); deltaPosY = (height - newHeight) / 2 + (newDelta * Math.cos(newOmega - newAlpha) - delta * Math.cos(omega - alpha)) } else if (this.position == 'handle NW') { var mx = mouseX - (this.item.options.posX + width / 2 - delta * Math.sin(alpha)); var my = mouseY - (this.item.options.posY + height / 2 - delta * Math.cos(alpha)); var md = Math.sqrt(Math.pow(mx, 2) + Math.pow(my, 2)); var epsilon = Math.asin(my / md); if (mx < 0) epsilon = Math.PI - epsilon; var lambda = Math.PI / 2 - epsilon + thetaRad; deltaWidth = -md * Math.sin(lambda); deltaHeight = -md * Math.cos(lambda); if (width + deltaWidth < 10) deltaWidth = 10 - width; if (height + deltaHeight < 10) deltaHeight = 10 - height; var newWidth = width + deltaWidth; var newHeight = height + deltaHeight; var newDelta = Math.sqrt(Math.pow(newWidth, 2) + Math.pow(newHeight, 2)) / 2; var newBeta = Math.atan(newWidth / newHeight); var newAlpha = newBeta - thetaRad; deltaPosX = (width - newWidth) / 2 + (delta * Math.sin(alpha) - newDelta * Math.sin(newAlpha)); deltaPosY = (height - newHeight) / 2 + (delta * Math.cos(alpha) - newDelta * Math.cos(newAlpha)) } this.item.resizeItem(deltaPosY, deltaPosX, deltaWidth, deltaHeight); if (Prototype.Browser.IE) { var offset = $(this.item.idwrapper).getDimensions(); var mleft = ((this.item.options.width + deltaWidth - offset.width) / 2) - 2 + "px"; var mtop = ((this.item.options.height + deltaHeight - offset.height) / 2) - 2 + "px"; $(this.item.idwrapper).setStyle({ marginLeft: mleft, marginTop: mtop }) } }, onMouseUp: function (event) { Event.stopObserving(document, 'mouseup', this.mouseUpBind); Event.stopObserving(document, 'mousemove', this.mouseMoveBind); if ($(this.item.id)) { if (this.position != 'handle R') new Effect.Opacity($(this.item.id), { duration: 0.2, from: 0.7, to: 1 }) } this.item.updateItemOptions(); this.item.redraw(); this.item.SetMargins(); Event.stop(event) } }; Palette = Class.create(); Palette.prototype = { initialize: function () { this.Tabs = []; this.TabContainer = $('tabContainer'); this.PanelContainer = $('tdContainer'); this.OnInitialLoad = true; this.CreateDefaultTabs(); this.SelectedTab = this.Tabs[0]; try { if (this.Tabs[0].TabPanel.images.length > 0) this.SelectedTab = this.Tabs[0]; else this.SelectedTab = this.Tabs[this.Tabs.length - 1] } catch (e) { } this.SelectedTab.Show(); this.cookiejar = null; this.initializeCookie(); this.ResizeTabs(); this.removeCookie() }, initializeCookie: function () { this.cookiejar = new CookieJar({ expires: 3600 * 24 * 365, path: '/' }) }, AddAnalytics: function (EventID) { try { Analytics.AddActivity(EventID, Url, UserId, Sid) } catch (e) { } }, CreateDefaultTabs: function () { var tab1 = new TabBase(this, 1, "Fav", false, "My favorites", false, 0, "", "", "", "", 0, 3); this.Tabs.push(tab1); if (this.IsUserLoggedIn()) { var tabDraft = new TabBase(this, -2, "Draft", false, "My drafts", false, 0, "", "", "", "", 0, 3); this.Tabs.push(tabDraft) } var tab0 = new TabBase(this, -1, "Text", false, "Text", false, 0, "", "", "", "", 0, 3); this.Tabs.push(tab0); var tab2 = new TabBase(this, 0, "New", false, "New Tab", false, 0, "", "", "", "", 0, 3); this.Tabs.push(tab2); var palette = this; if ($("tab").value != "") { try { var tabs = unescape($("tab").value).evalJSON(); for (var i = 0; i < tabs.length; i++) { var tab = tabs[i]; var color = ""; var Tier2CatId = 0; var BrandType = 3; try { try { if (tab.Color != undefined && tab.Color != null) color = tab.Color } catch (Error) { } try { if (tab.Tier2CatID != undefined && tab.Tier2CatID != null) Tier2CatId = tab.Tier2CatID } catch (Error) { } try { if (tab.BrandType != undefined && tab.BrandType != null) BrandType = tab.BrandType } catch (Error) { } var Usertab = new TabBase(palette, tab.ID, "UserTab", true, html_entity_decode(tab.Name), true, tab.CategoryID, tab.BrandGuid, html_entity_decode(tab.BrandName), html_entity_decode(tab.SearchText), color, Tier2CatId, BrandType); palette.Tabs.push(Usertab) } catch (e) { palette.removeCookie(); if (palette.Tabs.length == 3) { palette.addTab(false) } break } } } catch (ex) { this.addTab(false) } } else this.addTab(false) }, IsUserLoggedIn: function () { if ($('userName').value != "88888888-8888-8888-8888-888888888888") return true; else return false }, addTab: function (blnSelect) { var UniqueID = this.getUniqueID(); UniqueID++; var tab = new TabBase(this, UniqueID, "All", true, "All clothes", true, -1, "", "", "", "", 0, 3); this.Tabs.push(tab); if (blnSelect) { this.SelectedTab.Hide(); this.SelectedTab = tab; this.SelectedTab.Show(); this.AddAnalytics(253) } this.saveCookie(); if (this.Tabs.length - 3 >= global.TOTAL_TABS) { document.getElementById('Tab_0').parentNode.parentNode.style.display = "none" } this.ResizeTabs() }, addDraftTab: function () { if (this.IsUserLoggedIn()) { var tabDraft = new TabBase(this, -2, "Draft", false, "My Drafts", true, 0, "", "", "", "", 0, 3); this.Tabs.splice(1, 0, tabDraft) } }, getUniqueID: function () { var ID = 0; for (var i = 0; i < this.Tabs.length; i++) ID = Math.max(this.Tabs[i].ID, ID); return ID }, onSelect: function (tab) { if (!tab) return; if (this.SelectedTab) { if (tab == this.SelectedTab) { return } else { try { this.SelectedTab.Hide() } catch (e) { } } } tab.Show(); this.SelectedTab = tab; return false }, onClose: function (tab) { if (!tab) return; if (this.SelectedTab == tab) { this.SelectedTab = this.Tabs[0] } this.Tabs = this.Tabs.without(tab); tab.Delete(); this.saveCookie(); this.SelectedTab.Show(); if (this.Tabs.length - 2 < global.TOTAL_TABS) { document.getElementById('Tab_0').parentNode.parentNode.style.display = "block" } this.ResizeTabs(); return false }, saveCookie: function () { var TabDetails = this.getTabObject(); if ($('userName').value != "88888888-8888-8888-8888-888888888888") { TabDetails = TabDetails.length > 0 ? escape(Object.toJSON(TabDetails)) : ""; ret = Avenue7_Presentation.OutfitService.TabUpdateTabDetails($('userName').value, TabDetails, this.TabOC, this.TabOE) } else { if (this.cookiejar == null) this.initializeCookie() } if (this.SelectedTab != undefined) this.SelectedTab.Show() }, TabOC: function (args) { return false }, TabOE: function (args) { return false }, removeCookie: function (value) { if (this.cookiejar == null) this.initializeCookie(); this.cookiejar.remove("Tabs") }, getTabObject: function () { var Tabs = []; for (var i = 0; i < this.Tabs.length; i++) { if (this.Tabs[i].ID > 1) { var tab = {}; tab.ID = this.Tabs[i].ID; tab.Name = this.Tabs[i].TabName; tab.CategoryID = this.Tabs[i].TabPanel.categoryID; tab.BrandGuid = this.Tabs[i].TabPanel.BrandGuid; tab.BrandName = this.Tabs[i].TabPanel.BrandName; tab.SearchText = this.Tabs[i].TabPanel.SearchText; tab.Color = this.Tabs[i].TabPanel.Color; tab.Tier2CatID = this.Tabs[i].TabPanel.Tier2CatID; tab.BrandType = this.Tabs[i].TabPanel.BrandType; Tabs.push(tab) } } return Tabs }, RefreshTabDetails: function (TabID) { for (var i = 0; i < this.Tabs.length; i++) { if (TabID == this.Tabs[i].ID) { this.Tabs[i].Refresh(); break } } }, ResizeTabs: function () { if (Prototype.Browser.IE) { var width = 0; $$('div.tabMain').each(function (tabMain) { if (tabMain.innerHTML.indexOf("Tab_1 ") < 0 && tabMain.innerHTML.indexOf("Tab_0 ") < 0) { $(tabMain).descendants().each(function (node) { if (node.nodeName.toLowerCase() == "div" && node.className.toLowerCase() != "clearer") { width += $(node).getWidth() } }); $(tabMain).setStyle({ width: (width + 1) + "px" }); width = 0 } }) } }, ResetToDefault: function () { var TabTemp = []; var len = this.Tabs.length; for (var i = 0; i < len; i++) { if (this.Tabs[i].ID > 1) { this.Tabs[i].Delete() } else { TabTemp.push(this.Tabs[i]) } } if (TabTemp.length > 0) { this.Tabs = TabTemp } this.removeCookie(); if (this.Tabs[0].TabPanel.images.length == 0) this.Tabs[0].Refresh(); this.onSelect(this.Tabs[0]); this.addTab(false); if (this.Tabs[1].ID != -2) { this.addDraftTab() } else { this.Tabs[1].Refresh() } } }; TabBase = Class.create(); TabBase.prototype = { initialize: function (palette, id, type, isClosable, TabName, isNew, CatID, BrandGuid, BrandName, SearchText, Color, Tier2CatId, BrandType) { this.Palette = palette; this.ID = type == "New" ? 0 : id; this.TabID = "Tab_" + id; this.Type = type; this.Title = ""; this.IsClosable = isClosable; this.TabName = TabName; this.IsNew = isNew; this.CategoryID = CatID; this.selectTabBind = this.onSelectTab.bindAsEventListener(this); this.closeTabBind = this.onCloseTab.bindAsEventListener(this); this.addTabBind = this.onAddTab.bindAsEventListener(this); this.CreateTab(); this.TabPanel = type == "New" ? null : new TabPanel(this, this.CategoryID, BrandGuid, BrandName, SearchText, Color, Tier2CatId, BrandType); if (TabName.indexOf("rgb(") > -1) this.UpdateTabTitle(Color); this.ShowBusyMsg = true }, CreateTab: function () { var CloseX = ''; if (this.IsClosable) CloseX = Builder.node('span', { className: "close" }, "x"); var noWrap = Prototype.Browser.IE ? "white-space:nowrap;" : ""; var tabLeft = Builder.node('div', { id: "tl" + this.ID, className: this.ID == 0 ? "tabLeftNew" : "tabLeftOff" }); var tabCenter = Builder.node('div', { id: "tc" + this.ID, className: this.ID == 0 ? "tabCenterNew" : "tabCenterOff" }, [Builder.node('a', { id: this.TabID, style: "cursor: hand;" + noWrap }, [Builder.node('span', { title: this.TabName }, this.TabName), CloseX])]); var tabRight = Builder.node('div', { id: "tr" + this.ID, className: this.ID == 0 ? "tabRightNew" : "tabRightOff" }); var tabCl = Builder.node('div', { className: "clearer" }); var tab = Builder.node('div', { className: "tabMain" }, [tabLeft, tabCenter, tabRight, tabCl]); if (this.ID == -2 && this.IsNew) { var Ele = document.getElementById('Tab_-1').parentNode.parentNode; Ele.parentNode.insertBefore(tab, Ele) } else if (this.IsNew) { var Ele = document.getElementById('Tab_0').parentNode.parentNode; Ele.parentNode.insertBefore(tab, Ele) } else { this.Palette.TabContainer.appendChild(tab); if (this.ID == 0) { this.Palette.TabContainer.appendChild(Builder.node('div', { className: "clearer" })); try { if (Prototype.Browser.IE) $(tab).setStyle({ width: "70px" }) } catch (e) { } } } if (this.IsClosable) Event.observe(CloseX, 'click', this.closeTabBind); if (this.ID == 0) Event.observe(this.TabID, 'click', this.addTabBind); else Event.observe(this.TabID, 'click', this.selectTabBind) }, onSelectTab: function () { this.Palette.onSelect(this) }, onCloseTab: function () { Event.stopObserving(this.TabID, 'click', this.selectTabBind); $(this.TabID).descendants()[1].stopObserving(); this.Palette.onClose(this) }, onAddTab: function () { this.Palette.addTab(true) }, Show: function () { $('tl' + this.ID).removeClassName('tabLeftOff'); $('tc' + this.ID).removeClassName('tabCenterOff'); $('tr' + this.ID).removeClassName('tabRightOff'); $('tl' + this.ID).addClassName('tabLeftOn'); $('tc' + this.ID).addClassName('tabCenterOn'); $('tr' + this.ID).addClassName('tabRightOn'); this.TabPanel.Show() }, Hide: function () { $('tl' + this.ID).removeClassName('tabLeftOn'); $('tc' + this.ID).removeClassName('tabCenterOn'); $('tr' + this.ID).removeClassName('tabRightOn'); $('tl' + this.ID).addClassName('tabLeftOff'); $('tc' + this.ID).addClassName('tabCenterOff'); $('tr' + this.ID).addClassName('tabRightOff'); this.TabPanel.Hide() }, Delete: function () { if (this.ID == 0) Event.stopObserving(this.TabID, 'click', this.addTabBind); else Event.stopObserving(this.TabID, 'click', this.selectTabBind); var PEle = $(this.TabID).parentNode.parentNode; $(this.TabID).remove(); $(PEle).remove(); this.TabPanel.Delete() }, ChangeTitle: function (newTitle, CatID) { this.CategoryID = CatID; this.UpdateTabTitle(newTitle) }, UpdateTabTitle: function (newTitle) { var title = $(this.TabID).firstDescendant(); if (newTitle.indexOf("rgb(") < 0) { $(title).innerHTML = newTitle; $(title).writeAttribute("title", newTitle); $(title).setStyle({ width: "", height: "", backgroundColor: "" }) } else { $(title).innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; $(title).setStyle({ width: "18px", height: "14px", backgroundColor: newTitle }); $(title).writeAttribute("title", "Color") } this.TabName = newTitle; this.Palette.ResizeTabs() }, ShowLoading: function (blnVisible) { if (blnVisible) { $('divLoading').show(); this.TabPanel.ShowHint(false) } else $('divLoading').hide() }, Refresh: function () { this.ShowBusyMsg = false; this.TabPanel.loadItemsPalette(0); this.ShowBusyMsg = true } }; TabPanel = Class.create(); TabPanel.prototype = { initialize: function (tab, CatID, BrandGuid, BrandName, SearchText, Color, Tier2CatId, BrandType) { this.Tab = tab; this.images = []; this.draggableImages = []; this.categoryID = CatID; this.Tier2CatID = Tier2CatId; this.TabID = this.Tab.ID; this.ID = "P_" + this.TabID; this.SelectID = "C_" + this.ID; this.T2SelectID = "T2_" + this.ID; this.BTSelect = "BT_" + this.ID; this.ImageContainer = "imgC_" + this.ID; this.node = Builder.node('div', { id: this.ID, style: "display:none;" }); this.Tab.Palette.PanelContainer.appendChild(this.node); this.TotalPages = 0; this.currentPageNumber = 1; this.BrandGuid = BrandGuid; this.BrandName = BrandName; this.BrandType = BrandType; this.Color = Color; this.SearchText = SearchText; this.PopupcontainerDiv = null; this.OnItemDrag = false; this.El; this.FilterContainer = "fltr_" + this.ID; this.autocomplete; this.BrandsJSON = AffiliateBrands; Event.observe($$('body')[0], 'click', this.hideOverlay.bindAsEventListener(this)); Event.observe($$('body')[0], 'keypress', this.OnKeyPress.bindAsEventListener(this)); this.onNextBind = this.onNext.bindAsEventListener(this); this.onPrevBind = this.onPrev.bindAsEventListener(this); this.onCatChangeBind = this.onCatChange.bindAsEventListener(this); this.onClearFilterBind = this.onClearFilter.bindAsEventListener(this); this.getDetailsItemBind = this.overlay.bindAsEventListener(this); this.onSearchClickBind = this.onSearchClick.bindAsEventListener(this); this.onTier2CatChangeBind = this.onTier2CatChange.bindAsEventListener(this); this.onBranTypeChangeBind = this.onBrandTypeChange.bindAsEventListener(this); this.node.appendChild(Builder.node('div', { id: "Ldg_" + this.ID, className: "LoadingText" })); if (this.TabID > -2) { this.node.appendChild(Builder.node('div', { id: this.FilterContainer, className: "clothesFilter" })); if (this.TabID > 0) this.CreateCategoryDDL(); this.CreateColorPalette(); this.CreateSearchBox(); $(this.FilterContainer).appendChild(Builder.node('div', { className: "clearer" })); if (this.TabID > 0) this.CreateTier2CategoryDDL(); if (this.TabID > 1) this.CreateBrandTypeDDL(); $(this.FilterContainer).appendChild(Builder.node('div', { className: "clearer" })); if (this.TabID > 0) this.CreateFilterBox(); if (this.TabID > 1 && this.categoryID == 0) this.categoryID = -1 } this.node.appendChild(Builder.node('div', { id: this.ImageContainer, className: "clothesContainer" })); this.CreatePagingElements(); $(this.ImageContainer).appendChild(Builder.node('div', { className: "getSomeFavourites", id: "M_" + this.ID, style: "display:none;width:300px" }, "None found.")); $(this.ImageContainer).appendChild(Builder.node('div', { className: "clothesInstructions", id: "Df_" + this.ID, style: "display:none;" }, "1. Select clothes to view")); this.UpdateImagePalette(false); if (this.TabID > 0) this.initializeFilters() }, initializeFilters: function () { if (this.TabID > -1) this.setCategory(); if (this.TabID > 1) this.setBrandType(); if (this.TabID > 1) { if (this.categoryID > 0) this.AddFilter("C"); if (this.BrandName != "") this.AddFilter("B"); if (this.SearchText != "") this.AddFilter("S"); if (this.Color != "") this.AddFilter("Cl") } }, CreateCategoryDDL: function () { var Cat = Builder.node('select', { id: this.SelectID }, [Builder.node('option', { value: "0", selected: "selected" }, "Select category")]); var catItems = Categories.evalJSON(); catItems.each(function (item) { $(Cat).appendChild(Builder.node('option', { value: item.ID }, item.Name)) }); var CatContainer = Builder.node('div', { className: "filterCategory" }, [Cat]); $(this.FilterContainer).appendChild(CatContainer); Event.observe(this.SelectID, 'change', this.onCatChangeBind) }, CreateSearchBox: function () { if (this.TabID > 1) { var SrchID = "Srch_" + this.ID; var InputBox = Builder.node('input', { id: SrchID }); var InputBtn = Builder.node('a', { id: "b_" + SrchID, title: "Search brands" }, [Builder.node('img', { className: "searchButton", src: '/App_Themes/Av7/images/all-lang/outfit_creator/button_search.gif' })]); var SrchContainer = Builder.node('div', { className: "filterSearch" }, [InputBox, InputBtn]); $(this.FilterContainer).appendChild(SrchContainer); Event.observe("b_" + SrchID, 'click', this.onSearchClickBind); this.autocomplete = new AutoComplete(SrchID, this) } }, CreatePagingElements: function () { var bPrev = Builder.node('div', { className: "buttonCenter buttonPaging" }, [Builder.node('a', { id: "aP_" + this.ID }, "Previous")]); var bNext = Builder.node('div', { className: "buttonCenter buttonPaging" }, [Builder.node('a', { id: "aN_" + this.ID }, "Next")]); var NextButton = Builder.node('div', { className: "buttonMain buttonFloat", id: 'divN_' + this.ID }, [Builder.node('div', { className: "buttonLeft" }), bNext, Builder.node('div', { className: "buttonRight" })]); var PrevButton = Builder.node('div', { className: "buttonMain buttonFloat", id: 'divP_' + this.ID }, [Builder.node('div', { className: "buttonLeft" }), bPrev, Builder.node('div', { className: "buttonRight" })]); var txtPageNum = Builder.node('input', { id: 'txtP_' + this.ID, type: "text", style: "width:35px;" }); var PagingHint = Builder.node('div', { className: "clothesSelectionPagingText", id: "hint_" + this.ID, style: "visibility:hidden" }, [txtPageNum, Builder.node('span', { id: "hnt_" + this.ID })]); var divPagingContainer = Builder.node('div', { id: "div_paging_" + this.ID, className: "clothesSelectionPaging" }, [PrevButton, PagingHint, NextButton]); this.node.appendChild(divPagingContainer); Event.observe('aP_' + this.ID, "click", this.onPrevBind); Event.observe('aN_' + this.ID, "click", this.onNextBind); Event.observe('txtP_' + this.ID, "keypress", this.Paging_KeyPress.bindAsEventListener(this)) }, CreateFilterBox: function () { var cat = Builder.node('span', { className: "filtercontrol category", title: "Click to remove Category filter" }, [Builder.node('span', { id: 'f_c_' + this.ID, style: "float:left" }), Builder.node('a', { id: 'f_c_c_' + this.ID, className: "close", style: "float:left" }, "x")]); var Brand = Builder.node('span', { className: "filtercontrol brand", title: "Click to remove Brand filter" }, [Builder.node('span', { id: 'f_b_' + this.ID, style: "float:left" }), Builder.node('a', { id: 'f_b_c_' + this.ID, className: "close", style: "float:left" }, "x")]); var filter = Builder.node('span', { className: "filtercontrol search", title: "Click to remove Search filter" }, [Builder.node('span', { id: 'f_s_' + this.ID, style: "float:left" }), Builder.node('a', { id: 'f_s_c_' + this.ID, className: "close", style: "float:left" }, "x")]); var color = Builder.node('span', { className: "filtercontrol color", title: "Click to remove Color filter" }, [Builder.node('span', { id: 'f_cl_' + this.ID, style: "float:left;width:18px;height:14px;" }), Builder.node('a', { id: 'f_cl_c_' + this.ID, className: "close", style: "float:left" }, "x")]); var cAll = Builder.node('span', { className: "filtercontrol", title: "Click to remove all filters", style: "float:right" }, [Builder.node('a', { id: 'f_all_c_' + this.ID, className: "clickable close", style: "float:left" }, "clear all")]); var divFilterContainer = Builder.node('div', { className: "filterSelection" }, [cat, Brand, filter, color, cAll]); $(this.FilterContainer).appendChild(divFilterContainer); $(this.FilterContainer).appendChild(Builder.node('div', { className: "clearer" })); Event.observe('f_c_c_' + this.ID, "click", this.onClearFilterBind); Event.observe('f_b_c_' + this.ID, "click", this.onClearFilterBind); Event.observe('f_s_c_' + this.ID, "click", this.onClearFilterBind); Event.observe('f_cl_c_' + this.ID, "click", this.onClearFilterBind); Event.observe('f_all_c_' + this.ID, "click", this.onClearFilterBind) }, CreateColorPalette: function () { if (this.TabID > 0 || this.TabID == -1) { var InputBtn = Builder.node('a', { id: "c_" + this.ID, title: "Select color" }, [Builder.node('img', { className: "colorButton", src: '/App_Themes/Av7/images/all-lang/outfit_creator/button_colour.gif' })]); var SrchContainer = Builder.node('div', { className: this.TabID == -1 ? "" : "filterColor" }, [InputBtn]); $(this.FilterContainer).appendChild(SrchContainer); ColorContainer($(this.FilterContainer), this, "cp_" + this.ID); Event.observe(InputBtn, 'click', this.ShowColorPalette.bindAsEventListener(this)) } }, CreateTier2CategoryDDL: function () { var Tier2Cat = Builder.node('select', { id: this.T2SelectID, style: "display:none" }, [Builder.node('option', { value: "0", selected: "selected" }, "Select sub-category")]); var CatContainer = Builder.node('div', { className: "filterTier2Category" }, [Tier2Cat, new Element("span").update("&nbsp;")]); $(this.FilterContainer).appendChild(CatContainer); Event.observe(this.T2SelectID, 'change', this.onTier2CatChangeBind); this.UpdateTier2Category(); if (this.TabID == 1) { if ($('userName').value != "88888888-8888-8888-8888-888888888888") $(this.FilterContainer).appendChild(Builder.node('div', { id: "divMngeFav", className: "", style: "float:right" }, [Builder.node('a', { href: "/AddNewProduct" }, "Upload item"), Builder.node('span', " - "), Builder.node('a', { href: "Personal/MyFavouriteClothes/" + $('userName').value }, "Manage favorites")])) } }, CreateBrandTypeDDL: function () { var BrandTypeOptions = '<option value="3">All</option><option value="0">Purchasable</option><option value="1">Community Added</option>'; if ($('userName').value != "88888888-8888-8888-8888-888888888888") BrandTypeOptions += '<option value="2">Added by friends</option>'; var BTSelect = Builder.node('select', { id: this.BTSelect }); var span = Builder.node('span', "Show "); var CatContainer = Builder.node('div', { className: "filterBrandType" }, [span, BTSelect]); $(BTSelect).update(BrandTypeOptions); $(this.FilterContainer).appendChild(CatContainer); Event.observe(this.BTSelect, 'change', this.onBranTypeChangeBind) }, ShowColorPalette: function (event) { var ClrPalette = "cp_" + this.ID; $(ClrPalette).show(); var offset = $("c_" + this.ID).cumulativeOffset(); var sleft = offset.left; var stop = offset.top + 20; if (this.TabID == -1) { sleft = offset.left } else { sleft = offset.left - $(ClrPalette).getWidth() + 20; if (Prototype.Browser.IE) { sleft = offset.left + $(ClrPalette).getWidth() - 26 } } $(ClrPalette).setStyle({ top: stop + "px", left: sleft + "px" }); Event.stop(event) }, onColorItemClick: function (event) { var ele = Event.element(event); this.Color = $(ele).getStyle("backgroundColor"); if (this.TabID == -1) { var sClr = this.Color; this.images.each(function (image) { var src = image.src; var index = src.indexOf("rgb("); src = src.substring(0, index) + sClr; $(image).writeAttribute("Color", sClr); image.src = src }) } else { this.UpdateImagePalette(true); this.AddFilter("Cl"); this.Tab.Palette.AddAnalytics(70) } }, ShowHint: function (blnVisible) { if (blnVisible) { $("M_" + this.ID).show(); if (this.Tab.Type == "Fav") $("M_" + this.ID).innerHTML = "None found.<p>You can add any product to your favorites.</p>"; else $("M_" + this.ID).innerHTML = "None found." } else $("M_" + this.ID).hide() }, Show: function () { $(this.ID).show(); if (this.categoryID >= 0 || this.BrandName != "" || this.SearchText != "" || this.Color != "") $('instructions').update('Drag clothes over here.'); else $('instructions').update('2. Drag clothes over here.') }, Hide: function () { $(this.ID).hide() }, Delete: function () { $(this.node).remove() }, UpdateImagePalette: function (blnSaveTabDetails) { $("Df_" + this.ID).hide(); this.TotalPages = 0; this.currentPageNumber = 1; this.Tab.ShowLoading(false); this.enablePaging(this.currentPageNumber, this.TotalPages); if (this.AjaxRequest != null) { var executor = this.AjaxRequest.get_executor(); if (executor.get_started()) { executor.abort() } } if (blnSaveTabDetails) this.Tab.Palette.saveCookie(); if ((this.TabID > 1 && (this.categoryID >= 0 || this.Tier2CatID > 0 || this.BrandName != "" || this.SearchText != "" || this.Color != "" || (blnSaveTabDetails && this.BrandType >= 0))) || this.TabID == 1 || this.TabID < 0) { this.loadItemsPalette(1) } else { this.clearPalette(); this.ShowHint(false); $("Df_" + this.ID).show(); $$("#cp_" + this.ID + " a").each(function (clrItem) { var colorItem = clrItem.descendants(); $(colorItem[0]).show(); $(colorItem[1]).hide() }) } }, UpdateTier2Category: function () { $$('#' + this.T2SelectID + ' option').each(function (ele) { if (ele.value > 0) $(ele).remove(); else { $(ele).innerHTML = "Select sub-category"; ele.selected = true } }); var catItems = Tier2Categories.evalJSON(); var obj = this; catItems.each(function (Tier2Item) { if (Tier2Item != undefined && Tier2Item != null && Tier2Item != "") { if (Tier2Item.CatId == obj.categoryID) $(obj.T2SelectID).appendChild(Builder.node('option', { value: Tier2Item.ID }, Tier2Item.Name)) } }); $(this.T2SelectID).firstDescendant().selected = true; if ($(this.T2SelectID).length > 1) $(this.T2SelectID).show(); else $(this.T2SelectID).hide() }, onCatChange: function () { this.categoryID = $F(this.SelectID); this.Tier2CatID = 0; this.UpdateTier2Category(); this.ChangeCategoryDefaultText(); if (this.Tab.Type != "Fav") { this.Tab.UpdateTabTitle(this.getSelectedCategory()) } this.UpdateImagePalette(true); if (this.TabID > 1) { this.AddFilter("C") } this.Tab.Palette.AddAnalytics(70) }, onTier2CatChange: function () { this.Tier2CatID = $F(this.T2SelectID); this.ChangeCategoryDefaultText(); this.UpdateImagePalette(true); if (this.TabID > 1) { this.AddFilter("C") } this.Tab.Palette.AddAnalytics(70) }, onBrandSearch: function (BrandGuid, BrandName) { this.BrandGuid = BrandGuid; this.BrandName = BrandName; this.Tab.BrandGuid = BrandGuid; this.UpdateImagePalette(true); this.autocomplete.insertMessage(); this.AddFilter("B"); this.Tab.Palette.AddAnalytics(70) }, onBrandTypeChange: function () { this.BrandType = $F(this.BTSelect); this.UpdateImagePalette(true); if (this.TabID > 1) { this.AddFilter("BT") } this.Tab.Palette.AddAnalytics(70) }, onProductSearch: function (event) { var key = Prototype.Browser.IE ? window.event.keyCode : event.which; if (key == 13) { this.onSearchClick(); this.Tab.Palette.AddAnalytics(70) } return false }, onSearchClick: function () { var SrchID = "Srch_" + this.ID; var srcText = $(SrchID).value; if (srcText != "" && srcText != "Search brands") { this.onBrandSearch("10000000-0000-0000-0000-000000000000", srcText) } return false }, onClearFilter: function (event) { var ele = Event.element(event); $(ele.parentNode).hide(); switch ($(ele).id) { case "f_c_c_" + this.ID: if (this.Tier2CatID > 0) { this.Tier2CatID = 0; this.AddFilter("C") } else this.categoryID = 0; this.setCategory(); break; case "f_b_c_" + this.ID: this.BrandGuid = ""; this.BrandName = ""; this.Tab.BrandGuid = ""; break; case "f_s_c_" + this.ID: this.SearchText = ""; break; case "f_cl_c_" + this.ID: this.Color = ""; break; default: $("f_c_c_" + this.ID).parentNode.style.display = "none"; $("f_b_c_" + this.ID).parentNode.style.display = "none"; $("f_s_c_" + this.ID).parentNode.style.display = "none"; $("f_cl_c_" + this.ID).parentNode.style.display = "none"; if (this.Tab.ID != 1) this.categoryID = -1; else this.categoryID = 0; this.Tier2CatID = 0; this.setCategory(); this.BrandGuid = ""; this.BrandName = ""; this.Tab.BrandGuid = ""; this.SearchText = ""; this.Color = ""; this.BrandType = 3; this.setBrandType(); this.ChangeCategoryDefaultText(); break } if (this.Tab.ID != 1) { var TabName = "All clothes"; if (this.categoryID > 0 || this.Tier2CatID > 0) TabName = this.getSelectedCategory(); else if (this.BrandName != "") TabName = this.BrandName; else if (this.SearchText != "") TabName = this.SearchText; else if (this.Color != "") TabName = this.Color; else { $('f_all_c_' + this.ID).parentNode.style.display = "none"; this.BrandType = 3; this.setBrandType() } $("Srch_" + this.ID).value = ""; this.autocomplete.insertMessage(); this.Tab.UpdateTabTitle(TabName) } else $('f_all_c_' + this.ID).parentNode.style.display = "none"; this.UpdateImagePalette(true); return false }, AddFilter: function (type) { switch (type) { case "C": var id = 'f_c_' + this.ID; $(id).parentNode.style.display = "none"; var Category = this.getSelectedCategory(); if (this.categoryID > 0 || this.Tier2CatID > 0) { $(id).parentNode.style.display = "block"; $(id).innerHTML = Category } if (this.Tab.ID != 1) { this.Tab.UpdateTabTitle(Category) } break; case "B": var id = 'f_b_' + this.ID; $(id).parentNode.style.display = "block"; $(id).innerHTML = this.BrandName; this.Tab.UpdateTabTitle(this.BrandName); break; case "S": var id = 'f_s_' + this.ID; $(id).parentNode.style.display = "block"; $(id).innerHTML = this.SearchText; this.Tab.UpdateTabTitle(this.SearchText); break; case "Cl": var id = 'f_cl_' + this.ID; $(id).parentNode.style.display = "block"; $(id).setStyle({ backgroundColor: this.Color }); if (this.Tab.ID != 1) { this.Tab.UpdateTabTitle(this.Color) } break; case "BT": break } $('f_all_c_' + this.ID).parentNode.style.display = "none"; if (this.categoryID > 0 || this.BrandName != "" || this.SearchText != "" || this.Color != "") $('f_all_c_' + this.ID).parentNode.style.display = "block" }, getSelectedCategory: function () { var Output = ""; if (this.Tier2CatID > 0) { var T2item = $$('#' + this.T2SelectID + ' option').find(function (ele) { return !!ele.selected }); Output = T2item.innerHTML } if (this.Tier2CatID <= 0) { var item = $$('#' + this.SelectID + ' option').find(function (ele) { return !!ele.selected }); Output = item.innerHTML; if (Output == "Select category.." || Output == "All") Output = "All clothes" } return Output }, setCategory: function () { if (this.TabID != -1) { var CatID = this.categoryID; $$('#' + this.SelectID + ' option').each(function (ele) { if (ele.value == CatID || (ele.value == "0" && CatID == -1)) { ele.selected = true } }); var T2CatID = this.Tier2CatID; if (CatID > 0) { $$('#' + this.T2SelectID + ' option').each(function (ele) { if (ele.value == T2CatID || (ele.value == "0" && T2CatID == -1)) { ele.selected = true } }) } else $(this.T2SelectID).hide(); this.ChangeCategoryDefaultText() } }, getSelectedBranType: function () { var Output = ""; if (this.BTSelect != 3) { var BTitem = $$('#' + this.BTSelect + ' option').find(function (ele) { return !!ele.selected }); Output = BTitem.innerHTML } return Output }, setBrandType: function () { if (this.TabID > 1) { var BT = this.BrandType; $$('#' + this.BTSelect + ' option').each(function (ele) { if (ele.value == BT) { ele.selected = true } }) } }, ChangeCategoryDefaultText: function () { if (this.categoryID == -1) $(this.SelectID).firstDescendant().innerHTML = "Select category.."; if (this.categoryID >= 0) $(this.SelectID).firstDescendant().innerHTML = "All"; if (this.Tier2CatID > 0) $(this.T2SelectID).firstDescendant().innerHTML = "All" }, Paging_KeyPress: function (event) { var e = window.event || event; var charCode = e.which || e.keyCode; if (charCode == 13) { var curPage = parseInt($("txtP_" + this.ID).value); if (curPage > this.TotalPages) curPage = this.TotalPages; this.currentPageNumber = curPage; this.loadItemsPalette(curPage); return false } if (charCode > 31 && (charCode < 48 || charCode > 57)) { Event.stop(event); return false } return true }, onNext: function () { var curPage = parseInt($("txtP_" + this.ID).value); if (curPage > this.TotalPages) curPage = this.TotalPages; if (curPage == this.currentPageNumber) this.loadItemsPalette(this.currentPageNumber + 1); else { this.currentPageNumber = curPage; this.loadItemsPalette(this.currentPageNumber) } return false }, onPrev: function () { var curPage = parseInt($("txtP_" + this.ID).value); if (curPage > this.TotalPages) curPage = this.TotalPages; if (curPage == this.currentPageNumber) this.loadItemsPalette(this.currentPageNumber - 1); else { this.currentPageNumber = curPage; this.loadItemsPalette(this.currentPageNumber) } return false }, enablePaging: function (pageNumber, numPages) { var idNext = 'divN_' + this.ID; var idPrevious = 'divP_' + this.ID; var idHint = "hint_" + this.ID; var pagHint = "hnt_" + this.ID; var txtPag = "txtP_" + this.ID; if ($(idHint)) { $(txtPag).value = pageNumber; $(pagHint).innerHTML = " of " + numPages } if ((pageNumber == numPages) && (numPages == 1)) { if ($(idNext)) $(idNext).setStyle({ visibility: "hidden" }); if ($(idPrevious)) $(idPrevious).setStyle({ visibility: "hidden" }) } if ((pageNumber == numPages) && (numPages > 1)) { if ($(idNext)) $(idNext).setStyle({ visibility: "hidden" }); if ($(idPrevious)) $(idPrevious).setStyle({ visibility: "visible" }) } if ((pageNumber == 1) && (numPages > 1)) { if ($(idNext)) $(idNext).setStyle({ visibility: "visible" }); if ($(idPrevious)) $(idPrevious).setStyle({ visibility: "hidden" }) } if ((pageNumber > 1) && (pageNumber < numPages)) { if ($(idNext)) $(idNext).setStyle({ visibility: "visible" }); if ($(idPrevious)) $(idPrevious).setStyle({ visibility: "visible" }) } if (numPages == 0) { if ($(idNext)) $(idNext).setStyle({ visibility: "hidden" }); if ($(idPrevious)) $(idPrevious).setStyle({ visibility: "hidden" }); if ($(idHint)) $(idHint).setStyle({ visibility: "hidden" }) } else { $(idHint).setStyle({ visibility: "visible" }) } }, loadItemsPalette: function (pageNumber) { this.cookieData = ""; this.clearPalette(); if (this.Tab.ShowBusyMsg) this.Tab.ShowLoading(true); this.currentPageNumber = this.currentPageNumber == undefined ? 1 : this.currentPageNumber; if (pageNumber == 0) pageNumber = this.currentPageNumber; if (this.Tab.Type == "Fav") { if ($('userName').value != "88888888-8888-8888-8888-888888888888") { this.AjaxRequest = Avenue7_Presentation.OutfitService.LoadElementsInPalette("image", pageNumber, global.TOTAL_ITEMS_IN_PALETTE, this.categoryID, "", this.Tier2CatID, this.Color, this.loadItemsPaletteOC, this.loadItemsPaletteOE, this) } else { cookieNumFavs = readCookie("numFavs"); if (cookieNumFavs) this.cookieData = ""; else cookieNumFavs = 0; if (cookieNumFavs == 0) this.cookieData = "None"; else { for (i = 0; i < cookieNumFavs; i++) { this.cookieData += readCookie("Favourite" + (i + 1)) + "%25" } } this.AjaxRequest = Avenue7_Presentation.OutfitService.LoadElementsInPalette("image", pageNumber, global.TOTAL_ITEMS_IN_PALETTE, this.categoryID, this.cookieData, this.Tier2CatID, this.Color, this.loadItemsPaletteOC, this.loadItemsPaletteOE, this) } } else if (this.Tab.Type == "Text") { this.AjaxRequest = Avenue7_Presentation.OutfitService.LoadFontsInPalette(pageNumber, global.TOTAL_TEXTITEMS_IN_PALETTE, this.TotalPages, this.loadItemsPaletteOC, this.loadItemsPaletteOE, this) } else if (this.Tab.Type == "Draft") { this.AjaxRequest = Avenue7_Presentation.OutfitService.LoadOutfitDraftsInPalette(pageNumber, global.TOTAL_ITEMS_IN_PALETTE, this.TotalPages, this.loadItemsPaletteOC, this.loadItemsPaletteOE, this) } else { this.AjaxRequest = Avenue7_Presentation.OutfitService.LoadProductsInPalette(pageNumber, global.TOTAL_ITEMS_IN_PALETTE, this.TotalPages, this.categoryID, this.BrandGuid, this.SearchText, this.Color, this.Tier2CatID, this.BrandType, this.loadItemsPaletteOC, this.loadItemsPaletteOE, this) } window.setTimeout(this.RetrieveFilterData.bind(this), 500) }, loadItemsPaletteOC: function (arg, context) { context.clearPalette(); var itemsInPalette = arg.evalJSON(); context.enablePaging(itemsInPalette.PageNumber, itemsInPalette.NumPages); context.currentPageNumber = itemsInPalette.PageNumber; context.TotalPages = itemsInPalette.NumPages; context.ShowHint(false); if (context.TotalPages != 0) context.drawPalette(itemsInPalette); else if (context.TotalPages == 0 && context.currentPageNumber - 1 > 0) context.loadItemsPalette(context.currentPageNumber - 1); else context.ShowHint(true); context.Tab.ShowLoading(false); if (context.Tab.Palette.OnInitialLoad && context.Tab.ID == 1) { context.Tab.Palette.OnInitialLoad = false; if (context.TotalPages != 0) context.Tab.Palette.onSelect(context.Tab) } }, loadItemsPaletteOE: function (arg, context) { context.Tab.ShowLoading(false); if (context.Tab.ID > 1) context.Tab.onCloseTab(); var msg = "There was an unexpected error occured while dealing with your request, please try again later."; if (context.Tab.ID == -2) msg = msg.replace("dealing with your request", "retrieving the draft details"); else if (context.Tab.ID == -1) msg = msg.replace("dealing with your request", "retrieving the text details"); MM.showMessage(msg, messages.ERROR) }, drawPalette: function (palette) { var id = this.Tab.Type == "Text" ? "_text_" : this.Tab.Type == "Draft" ? "_draft_" : "_image_"; palette.ItemsPalette.each(function (item) { var idElement = this.ID + id + item.ItemPK; var image = Builder.node('img', { id: idElement, src: item.ImageFile, className: "clothesImage", title: item.ItemName, ImgP: item.imageProportion }); if (this.Tab.Type == "Text") { $(image).writeAttribute("Color", "rgb(0, 0, 0)"); $(image).setStyle({ height: "45px" }) } $(this.ImageContainer).appendChild(image); this.images.push(image); Event.observe(idElement, 'click', this.getDetailsItemBind); this.draggableImages.push(new Draggable(image, { revert: true, onStart: function () { ie_apply_zindex(image, image.style.zIndex) } .bind(this), onDrag: function (element) { this.OnItemDrag = true } .bind(this), onEnd: function (element) { } .bind(this) })) } .bind(this)) }, clearPalette: function () { this.draggableImages.each(function (draggableImage) { draggableImage.destroy() }); this.images.each(function (image) { Event.stopObserving(image.id, 'click', this.getDetailsItemBind); $(image.id).remove() } .bind(this)); this.draggableImages = []; this.images = [] }, RetrieveFilterData: function () { if (this.Tab.Type != "Text") { var blnIsFavTab = false; if (this.Tab.Type == "Fav") { blnIsFavTab = true } Avenue7_Presentation.OutfitService.LoadProductFiltersInPalette(this.categoryID, this.BrandGuid, this.SearchText, this.Color, this.Tier2CatID, this.cookieData, blnIsFavTab, this.loadItemFiltersOC, this.loadItemFiltersOE, this) } }, loadItemFiltersOC: function (arg, context) { try { var filters = arg.evalJSON(); var ClrPalette = "cp_" + context.ID; var i = 0; var CurObj = context; if (filters) { filters.each(function (filter) { if (context.Color == "") { filter.colorFilter.each(function (color) { var colorItem = $$("#" + ClrPalette + " a")[i].descendants(); if (color == "x") { $(colorItem[0]).hide(); $(colorItem[1]).show() } else { $(colorItem[0]).show(); $(colorItem[1]).hide() } i++ }) } if (context.TabID > 1) { if (context.BrandGuid == "") { context.BrandsJSON = filter.brandFilter; if (filter.brandFilter.length == 0) { $("Srch_" + context.ID).disable(); $("b_Srch_" + context.ID).disable() } else { $("Srch_" + context.ID).enable(); $("b_Srch_" + context.ID).enable() } } } }) } } catch (e) { } }, loadItemFiltersOE: function (arg, context) { }, overlay: function (event) { if ($('divPopup')) $('divPopup').remove(); if (this.OnItemDrag == false) { this.El = Event.element(event); var idElement = get_PK_HTML_element($(this.El).id); this.PopupcontainerDiv = new Element('div', { id: 'divPopup', style: 'position:absolute;', className: 'av7popup' }).update('<div class="popOverLoadingTempDiv">loading ...<div>'); if (this.Tab.Type == "Text") { var textJSON = []; textJSON.title = $(this.El).readAttribute("title"); textJSON.imageFile = $(this.El).readAttribute("src").replace("width=85", "width=150"); textJSON.color = $(this.El).readAttribute("Color"); textJSON.visible = "block"; textJSON.buyvisible = "none"; this.TextPopup(textJSON) } else if (this.Tab.Type == "Draft") { var textJSON = []; textJSON.ID = idElement; textJSON.imageFile = this.El.src.replace("width=85", "width=150").replace("height=85", "height=150"); textJSON.DraftPicture = ""; var temp = this.El.src.toQueryParams().file; var index = temp.lastIndexOf("/"); if (index > -1) textJSON.DraftPicture = temp.substring(index + 1); this.OutfitDraftPopup(textJSON) } else { Avenue7_Presentation.ProductService.ProductDetailsByProductID(idElement, this.OnSuccess, this.OnFailure, this) } if (!event) var event = window.event; event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation(); var top = $(this.El).positionedOffset().top + $(this.El).getHeight() / 2; var left = $(this.El).positionedOffset().left + $(this.El).getWidth() / 2; this.PopupcontainerDiv.setStyle({ top: top + "px", left: left + "px" }); $(this.El).parentNode.appendChild(this.PopupcontainerDiv); this.PopupcontainerDiv.show() } this.OnItemDrag = false; return false }, TextPopup: function (args) { var templateProduct = new Template('<div class="popupImage">' + '<img classname="bordered" src="#{imageFile}">' + '</div><div class="popupContent"><p class="popupTitle">#{title}</p>' + '<ul class="popupLinks">' + '<li style="display:#{visible}"><a class="popupLink" id="aAdd" onclick="av7design.AddTextToCanvas(\'#{color}\',\'#{title}\')">Add item to canvas</a> </li>' + '<li style="display:#{buyvisible}"><a class="popupLink" href="javascript:void()">Buy this item</a> </li>' + '</ul></div>' + '<div style="float:right"><a onclick="av7design.palette.SelectedTab.TabPanel.hideOverlay();"><img src="http://static.avenue7.co.uk/App_Themes/Av7/images/all-lang/outfit_creator/button_close.gif" alt="Close"></a></div>' + '<div class="clearer"></div>'); try { this.PopupcontainerDiv.update(templateProduct.evaluate(args)) } catch (e) { context.hideOverlay() } }, OutfitDraftPopup: function (args) { var templateProduct = new Template('<div class="popupImage">' + '<img classname="bordered" src="#{imageFile}">' + '</div><div class="popupContent">' + '<ul class="popupLinks">' + '<li><a class="popupLink" id="aEdit" onclick="av7design.getOutfitDraftFromServer(#{ID}, \'#{DraftPicture}\')">Edit</a> </li>' + '<li><a class="popupLink" id="aDelete" onclick="av7design.canvas.DeleteDraft(#{ID})">Delete</a> </li>' + '</ul></div>' + '<div style="float:right"><a onclick="av7design.palette.SelectedTab.TabPanel.hideOverlay();"><img src="http://static.avenue7.co.uk/App_Themes/Av7/images/all-lang/outfit_creator/button_close.gif" alt="Close"></a></div>' + '<div class="clearer"></div>'); try { this.PopupcontainerDiv.update(templateProduct.evaluate(args)) } catch (e) { context.hideOverlay() } }, OnSuccess: function (args, context) { var templateProduct = new Template('<div class="popupImage">' + '<a target="_blank" title="#{title}" href="#{productURL}"> ' + '<img height="150" width="150" classname="bordered" src="#{imageFile}"></a>' + '</div><div class="popupContent"><p class="popupTitle">#{title}</p>' + '<p class="popupDesc">#{description} <a target="_blank" class="popupLink" href="#{productURL}">More details...</a></p>' + '<ul class="popupLinks">' + '<li><a class="popupLink" id="aAdd" onclick="av7design.canvas.addItemMiddleCanvas(\'' + $(context.El).id + '\')">Add item to canvas</a> </li>' + '<li><a class="popupLink" id="aFav" PID="#{GUID}">Add to my favorites</a></li> ' + '<li><a class="popupLink" id="areport" onclick="MW.showBoxP(\'/ModalContent/ReportItem.aspx?productID=#{GUID}&Url=' + escape(Url) + '\');">Report item</a></li> ' + '</ul></div>' + '<div style="float:right"><a onclick="av7design.palette.SelectedTab.TabPanel.hideOverlay();"><img src="http://static.avenue7.co.uk/App_Themes/Av7/images/all-lang/outfit_creator/button_close.gif" alt="Close"></a></div>' + '<div class="clearer"></div>'); try { var data = args.evalJSON(); context.PopupcontainerDiv.update(templateProduct.evaluate(data)); Event.observe("aFav", 'click', context.AddToFavourites.bindAsEventListener(context)); if (context.Tab.ID == 1) { $($("aFav").parentNode).hide() } } catch (e) { context.hideOverlay() } }, OnFailure: function (args, context) { }, hideOverlay: function () { if ($('divPopup')) $('divPopup').remove(); if ($("cp_" + this.ID)) $("cp_" + this.ID).hide(); if ($("ClrPalette")) $("ClrPalette").hide(); this.HideFontSelection() }, OnKeyPress: function (event) { event = event || window.event; var keyCode = event.which || event.keyCode; if (keyCode == 27) this.hideOverlay() }, AddToFavourites: function (event) { var ele = Event.element(event); var Pid = $(ele).readAttribute("PID"); this.hideOverlay(); if ($('LoggedInCheck')) { ret = Avenue7_Presentation.FavouriteService.FavouritesAddTo(Pid, this.OnFavSuccess, function (args) { }) } else if ($('LoggedOutCheck')) { var aCookie = (unescape(document.cookie)).split("; "); for (var i = 0; i < aCookie.length; i++) { var aCrumb = aCookie[i].split("="); if (Pid == aCrumb[1]) { MM.showMessage("This item is already in your favourites!", "Item Already Added"); return false } } var numFavs = 0; cookieNumFavs = readCookie("numFavs"); if (cookieNumFavs) numFavs = parseInt(cookieNumFavs) + 1; else numFavs = 1; createCookie("numFavs", numFavs, 9); createCookie("Favourite" + numFavs, Pid, 9); ret = Avenue7_Presentation.FavouriteService.FavouritesAddToCookie(numFavs, this.OnFavSuccess, function () { }); return false } return false }, DeleteItemFromFavourites: function (event) { var ele = Event.element(event); var Pid = $(ele).readAttribute("PID"); if (confirm("Are you want to delete this item from your favorites?")) { ret = Avenue7_Presentation.FavouriteService.FavouriteItemRemove(Pid, this.OnFavSuccess, function (args) { }); this.hideOverlay() } return false }, OnFavSuccess: function (args) { av7design.palette.RefreshTabDetails(1) }, HideFontSelection: function () { $("sFont").hide() } }; AutoComplete = Class.create(); AutoComplete.prototype = { selector: null, input: null, _timeout: null, visible: false, drawn: false, _hideTimeout: null, options: null, initialize: function (input, panel) { this.input = $(input); this.input.autocomplete = "off"; this.options = new AutoComplete.Options(); this.TabPanel = panel; this.defaultColor = "#000"; this.selector = document.createElement('select'); Event.observe(this.input, 'focus', this._onInputFocus.bindAsEventListener(this)); Event.observe(this.input, 'keydown', this._onInputKeyDown.bindAsEventListener(this)); Event.observe(this.input, 'blur', this._onInputBlur.bindAsEventListener(this)); Event.observe(this.input, 'change', this._onInputBlur.bindAsEventListener(this)); Event.observe(this.selector, 'focus', this._onSelectorFocus.bindAsEventListener(this)); Event.observe(this.selector, 'change', this._onSelectorChange.bindAsEventListener(this)); Event.observe(window, 'resize', this._reposition.bind(this)); Event.observe(window, 'scroll', this._reposition.bind(this)); this.insertMessage() }, insertMessage: function () { if (this.input.value.length == 0 || this.input.value == this.options.text) { this.input.value = this.options.text; this.input.setStyle({ color: this.options.color }) } else this.input.setStyle({ color: this.defaultColor }) }, _onInputFocus: function (event) { this.input.value = ""; this._onSelectorFocus(event) }, _onSelectorBlur: function (event) { this._onInputBlur(event) }, _onInputBlur: function (event) { this.insertMessage() }, _checkOnBlur: function () { this._hideTimeout = null; this.hide() }, _onInputKeyUp: function (event) { this._suggest(event) && Event.stop(event) }, _onInputKeyDown: function (event) { this._suggest(event) && Event.stop(event) }, _onSelectorFocus: function (event) { if (this._hideTimeout) { clearTimeout(this._hideTimeout); this._hideTimeout = null } }, _onSelectorChange: function (event) { this.select() }, draw: function () { if (this.drawn) return; if (this.options.cssClass) this.selector.className = this.options.cssClass; Element.setStyle(this.selector, { display: 'none', position: 'absolute', fontSize: '11px', width: this.input.offsetWidth + 'px' }); this.selector.size = this.options.size; document.body.appendChild(this.selector); this.input.autocomplete = 'off'; this.drawn = true }, hide: function () { if (!this.drawn || !this.visible) return; this.visible = false; if (window.Scriptaculous) { new Effect.BlindUp(this.selector, { duration: this.options.delay, queue: 'end', afterFinish: function (event) { Element.setStyle(this.selector, { display: 'none' }); this.selector.options.length = 0; setTimeout(this._restoreFocus.bind(this), 50) } .bind(this) }) } else { Element.setStyle(this.selector, { display: 'none' }); this.selector.options.length = 0; setTimeout(this._restoreFocus.bind(this), 50) } }, _restoreFocus: function () { this.input.focus() }, show: function () { if (!this.drawn) this.draw(); var trigger = null; if (this.selector.options.length) { if (window.Scriptaculous) { new Effect.BlindDown(this.selector, { duration: this.options.delay, queue: 'end' }) } else { Element.setStyle(this.selector, { display: 'inline' }) } this._reposition(); this.visible = true } }, _cancelTimeout: function () { if (this._timeout) { clearTimeout(this._timeout); this._timeout = null } }, _suggest: function (event) { this._cancelTimeout(); var key = Event.keyPressed(event); var ignoreKeys = [20, 16, 17, 18, 91, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 45, 36, 35, 33, 34, 144, 145, 44, 19, 93, ]; if (ignoreKeys.indexOf(key) > -1) return false; switch (key) { case Event.KEY_LEFT: case Event.KEY_RIGHT: return false; break; case Event.KEY_TAB: case Event.KEY_RETURN: if (this.visible) { if (this.selector.selectedIndex > -1) this.select(); else { if (this.selector.length > 0) { this.selector.selectedIndex = 0; this.select() } else this.cancel(); this.insertMessage() } return true } else { this.cancel(); Event.stop(event); this.insertMessage() } return false; break; case Event.KEY_ESC: this.cancel(); return true; break; case Event.KEY_UP: case Event.KEY_DOWN: this._interact(event); return true; break; default: break } if (this.input.value.length <= 1 && (key == Event.KEY_BACKSPACE || key == 46)) { this.cancel(); return false } if (this.input.value.length >= this.options.threshold - 1) { this._timeout = setTimeout(this._sendRequest.bind(this), 1000 * this.options.delay) } return false }, _sendRequest: function () { var result = []; var ArrObj = this.TabPanel.BrandsJSON; var entry = this.input.value; var count = 0; for (var i = 0; i < ArrObj.length; i++) { var elem = ArrObj[i]; var elem_name = elem.name; var elem_value = elem.id; var foundPos = elem_name.toLowerCase().indexOf(entry.toLowerCase()); var temp = []; while (foundPos != -1) { if (foundPos == 0) { temp.Guid = elem_value; temp.Name = elem_name; result.push(temp); break } foundPos = elem_name.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) } } this._process(result, this) }, _reposition: function () { if (!this.drawn) return; var pos = Position.cumulativeOffset(this.input); pos.push(pos[0] + this.input.offsetWidth); pos.push(pos[1] + this.input.offsetHeight); Element.setStyle(this.selector, { left: pos[0] + 'px', top: pos[3] + 'px' }) }, _process: function (responseText, context) { context.selector.options.length = 0; try { context._parseJSON(responseText); if (context.selector.options.length > (context.options.size)) context.selector.size = context.options.size; else context.selector.size = context.selector.options.length > 1 ? context.selector.options.length : 2; if (context.selector.options.length) { context.selector.selectedIndex = -1; context.show() } else context.cancel() } catch (e) { context.cancel() } }, _parseJSON: function (json) { if (!json) json = []; for (i = 0; i < json.length; i++) this._addOption(json[i].Guid, json[i].Name) }, _addOption: function (value, suggestion) { var opt = new Option(suggestion, value); Prototype.Browser.IE ? this.selector.add(opt) : this.selector.add(opt, null) }, cancel: function () { this.hide() }, select: function () { if (this.selector.selectedIndex > -1) { if (this.selector.options.length) this.input.value = this.selector.options[this.selector.selectedIndex].text; this.cancel(); this.TabPanel.onBrandSearch(this.selector.options[this.selector.selectedIndex].value, this.input.value); if (typeof this.options.onSelect == 'function') { this.options['onSelect'](this.input) } } else { this.cancel() } this.insertMessage() }, _interact: function (event) { if (!this.visible) return; var key = Event.keyPressed(event); if (key != Event.KEY_UP && key != Event.KEY_DOWN) return; var mx = this.selector.options.length; if (key == Event.KEY_UP) { if (this.selector.selectedIndex == 0) this.selector.selectedIndex = this.selector.options.length - 1; else this.selector.selectedIndex-- } else { if (this.selector.selectedIndex == this.selector.options.length - 1) this.selector.selectedIndex = 0; else this.selector.selectedIndex++ } } }; AutoComplete.Options = Class.create({ size: 15, cssClass: "fontAllTexts", onSelect: null, threshold: 1, delay: .1, text: "Search brands", color: "#aaa", initialize: function (overrides) { Object.extend(this, overrides || {}) } }); Object.extend(Event, { KEY_BACKSPACE: 8, KEY_TAB: 9, KEY_RETURN: 13, KEY_ESC: 27, KEY_LEFT: 37, KEY_UP: 38, KEY_RIGHT: 39, KEY_DOWN: 40, KEY_DELETE: 46, KEY_SHIFT: 16, KEY_CONTROL: 17, KEY_CAPSLOCK: 20, KEY_SPACE: 32, keyPressed: function (event) { return Prototype.Browser.IE ? window.event.keyCode : event.which } }); function getElementXYPos(ele) { var point = []; if (ele.getBoundingClientRect) { var box = ele.getBoundingClientRect(); var doc = document; var TopPos = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop); var LeftPos = Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft); if (Prototype.Browser.IE) { box.left -= 2; box.top -= 2 } point.x = box.left + LeftPos; point.y = box.top + TopPos } else { var offsetVal = []; offsetVal.x = ele.offsetLeft; offsetVal.y = ele.offsetTop; var NodeParentOffset = ele.offsetParent; var IsWebkit = Prototype.Browser.WebKit; var StyleDet = this.RetrieveStyleAttributeDetails(ele, "position") == "absolute"; if (NodeParentOffset != ele) { while (NodeParentOffset) { offsetVal.x += NodeParentOffset.offsetLeft; offsetVal.y += NodeParentOffset.offsetTop; if (IsWebkit && !StyleDet && this.RetrieveStyleAttributeDetails(NodeParentOffset, "position") == "absolute") { StyleDet = true } NodeParentOffset = NodeParentOffset.offsetParent } } if (IsWebkit && StyleDet) { offsetVal.x -= document.body.offsetLeft; offsetVal.y -= document.body.offsetTop } NodeParentOffset = node.parentNode; while (NodeParentOffset && NodeParentOffset.tagName != "HTML" && NodeParentOffset.tagName != "BODY") { if (this.RetrieveStyleAttributeDetails(NodeParentOffset, "display") != "inline") { offsetVal.x -= NodeParentOffset.scrollLeft; offsetVal.y -= NodeParentOffset.scrollTop } NodeParentOffset = NodeParentOffset.parentNode } point = offsetVal } return point } function RetrieveStyleAttributeDetails(ele, prop) { if (ele.style && ele.style[attribute]) { return ele.style[attribute] } else { if (ele.currentStyle) { return ele.currentStyle[attribute] } else { if (document.defaultView && document.defaultView.getComputedStyle) { attribute = attribute.replace(/([A-Z])/g, "-$1"); attribute = attribute.toLowerCase(); var s = document.defaultView.getComputedStyle(ele, ""); return s && s.getattributeertyValue(attribute) } else { return null } } } }