var LiveAdMaker = {
  SelectedSection: null,
  SupportedViews: [ "ViewList", "ViewBubbleImage", "ViewTable", "ViewThumbnail" ],
  hasSupportedViews: function( aNavigationParams ) {
    if ( !aNavigationParams.DisabledNavigationArray ) return true;
    var zSupportsView = false;
    var zViewCount = 0;
    LiveAdMaker.SupportedViews.forEach( function( aViewId ) {
      if ( !zSupportsView ) {
        var zDisabledView = aNavigationParams.DisabledNavigationArray.get( aViewId, "Id")[0];
        if ( !zDisabledView ) {
          zSupportsView = true;
          zViewCount++;
        }
      }
    });
    if ( zViewCount == (LiveAdMaker.SupportedViews.length - 1 ) ) return false;
    return zSupportsView;
  },
  updateBrowserTitle:function(aSection){
    var zSection = aSection || "";
    if(zSection) {
      zSection = " - " + zSection
    }
    document.title = "Intel Corp."+zSection;
  },
  receiveNewItem:function(aResults,aParams){
    if(aResults && aResults != undefined){
      var zReceiveNewFunction;
      if(aParams.Params.SelectedItem) {
        if(aResults.NodeParent=="") {
          aResults.NodeParent = aParams.Params.SelectedItem.Id;
        }
        if(aParams.Params.SelectedItem.HasSubItems=="Y" && aParams.Params.SelectedItem.SubItemsLoaded!="Y") {
          aParams.Params.CreatedItem = aResults;
          if(LiveAdMaker[aParams.Params.Section].requestChildNodes) {
            LiveAdMaker[aParams.Params.Section].requestChildNodes(null, aParams.Params);
            return true;
          }
        }
        aParams.Params.SelectedItem.OpenContainer = "Y";
        if(aParams.Params.AddNewAsChild && aParams.Params.AddNewAsChild=="Y" && aParams.Params.SelectedItem.NodeType=="ChildNode") {
          aParams.Params.SelectedItem.NodeType = "ParentNode";
        }
      }
      if(aParams.Params.SubSection) {
        if(aParams.ResetItems == 'Y') {
          if(LiveAdMaker[aParams.Params.Section][aParams.Params.SubSection].SubItemList.ItemArray.length > 0) {
            LiveAdMaker[aParams.Params.Section][aParams.Params.SubSection].SubItemList.ItemArray = [];
          }
        }
        if(aParams.InsertAt || aParams.InsertAt == 0) {
          LiveAdMaker[aParams.Params.Section][aParams.Params.SubSection].SubItemList.ItemArray.insertAt(aResults,aParams.InsertAt);
        } else {
          LiveAdMaker[aParams.Params.Section][aParams.Params.SubSection].SubItemList.ItemArray.set(aResults,aResults.Id);
        }
        aParams.Params.SubItem = aResults.Id;
        URI.replaceHashValue("SubItem", aResults.Id, false);
        aParams.Params.ReDrawSubSection = true;
        if(LiveAdMaker[aParams.Params.Section][aParams.Params.SubSection].receiveNewItem) {
          zReceiveNewFunction = LiveAdMaker[aParams.Params.Section][aParams.Params.SubSection].receiveNewItem;
        }
        else if(LiveAdMaker[aParams.Params.SubSection] && LiveAdMaker[aParams.Params.SubSection].receiveNewItem) {
          zReceiveNewFunction = LiveAdMaker[aParams.Params.SubSection].receiveNewItem;
        }
        aParams.Params.UseDefaultSubAction = true;
      } else {
        if(aParams.ResetItems == 'Y') {
          if(LiveAdMaker[aParams.Section].Items.length > 0) {
            LiveAdMaker[aParams.Section].Items = [];
          }
        }
        if(aParams.InsertAt || aParams.InsertAt == 0) {
          LiveAdMaker[aParams.Section].Items.insertAt(aResults,aParams.InsertAt);
        } else {
          LiveAdMaker[aParams.Section].Items.set(aResults,aResults.Id);
        }
        aParams.Params.Item = aResults.Id;
        URI.replaceHashValue("Item", aResults.Id, false);
        aParams.Params.Redraw = true;
        if(LiveAdMaker[aParams.Params.Section].receiveNewItem) {
          zReceiveNewFunction = LiveAdMaker[aParams.Params.Section].receiveNewItem;
        }
        aParams.Params.UseDefaultAction = true;
      }
      LiveAdMaker.drawSection(aParams.Params);
      if(zReceiveNewFunction) {
        zReceiveNewFunction(aResults,aParams);
      }
    }
  },
  receiveArchiveItem:function(aResults,aParams){
    if(aResults && aResults != undefined){
      var zSection, zList;
      var zReceiveArchiveFunction;
      if(aParams.SubSection) {
        zSection = LiveAdMaker[aParams.Section][aParams.SubSection];
        zList = zSection.SubItemList;
      } else {
        zSection = LiveAdMaker[aParams.Section];
        zList = zSection.List;
      }
      zList.ItemArray = zList.ItemArray.filter(function(aItem){
        return (aItem.Id!=aParams.ItemId&&aItem.NodeParent!=aParams.ItemId);
      });
      zSection.Items = zList.ItemArray;
      if (zSection.QuickSearch) {
        zSection.QuickSearch.List.ItemArray = zList.ItemArray
      }
      if(aParams.SubSection) {
        if (zList.ItemArray[0]) {
          aParams.SubItem = zList.ItemArray[0].Id;
          URI.replaceHashValue("SubItem", zList.ItemArray[0].Id);
        }
        else {
          aParams.SubItem = null;
          URI.replaceHashValue("SubItem", "");
        }
        aParams.ReDrawSubSection = true;
        aParams.Redraw = true;
        if(LiveAdMaker[aParams.Section][aParams.SubSection].receiveArchiveItem) {
          zReceiveArchiveFunction = LiveAdMaker[aParams.Section][aParams.SubSection].receiveArchiveItem;
        }
        else if(LiveAdMaker[aParams.SubSection] && LiveAdMaker[aParams.SubSection].receiveArchiveItem) {
          zReceiveArchiveFunction = LiveAdMaker[aParams.SubSection].receiveArchiveItem;
        }
        aParams.SubItem = aParams.PreviousItemId;
        URI.replaceHashValue("SubItem", aParams.PreviousItemId);
      } else {
        aParams.Redraw=true;
        aParams.Item = aParams.PreviousItemId;
        URI.replaceHashValue("Item", aParams.PreviousItemId);
      }
      LiveAdMaker.drawSection(aParams);
      if(zReceiveArchiveFunction) {
        zReceiveArchiveFunction(aResults,aParams);
      }
    }
  },
  receiveSectionData: function(aData, aParams){
    if(aData && aParams.Section && LiveAdMaker[aParams.Section]) {
      if(aData.Items) {
        if(aParams.Params.isChildRequest=="Y") {
          if(aParams.Section && !aParams.Params.SubSection) {
            aData.Items.forEach(function(aNewItem){
              LiveAdMaker[aParams.Section].Items.set(aNewItem, aNewItem.Id);
            });
            aParams.Params.Redraw = true;
          } else if(aParams.Section && aParams.Params.SubSection) {
            aData.Items.forEach(function(aNewItem){
              LiveAdMaker[aParams.Section][aParams.Params.SubSection].List.ItemArray.set(aNewItem, aNewItem.Id);
            });
            aParams.Params.ReDrawSubSection = true;
          }
        } else {
          LiveAdMaker[aParams.Section].Items = aData.Items.makeUnique('Id');
        }
        LiveAdMaker[aParams.Section].ItemPath = LiveAdMaker[aParams.Section].ItemPath || aData.ItemPath;
        LiveAdMaker[aParams.Section].ItemObjectCode = LiveAdMaker[aParams.Section].ItemObjectCode || aData.ItemObjectCode;
      }
      if(aData.Fields) {
        LiveAdMaker[aParams.Section].Fields = aData.Fields;
      }
      if(aData.DisabledNavigationArray) {
        aParams.Params.DisabledNavigationArray = aData.DisabledNavigationArray
      }
      if(aParams.Function) {
        aParams.Function(aParams.Params);
      }
    }
    return true;
  },
  selectAddInsertionDataSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.addInsertionData(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Media.addInsertionData(aParams);
        break;
      default:
    }
    return true;
  },
  selectTrackFieldChangeSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.trackFieldChange(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Media.trackFieldChange(aParams);
        break;
      default:
    }
    return true;
  },
  selectPreviewChangeWireFrameSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.previewChangeWireFrame(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.previewChangeWireFrame(aParams);
        break;
      default:
    }
    return true;
  },
  selectPreviewChangePageSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.previewChangePage(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.previewChangePage(aParams);
        break;
      default:
    }
    return true;
  },
  selectShowPreviewSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.showPreview(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.showPreview(aParams);
        break;
      default:
    }
    return true;
  },
  selectSingleSelectCompleteSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.singleSelectComplete(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.singleSelectComplete(aParams);
        break;
      default:
    }
    return true;
  },
  selectSingleEntryCompleteSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.singleEntryComplete(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.singleEntryComplete(aParams);
        break;
      default:
    }
    return true;
  },
  selectHighlightWireFrameAreaSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.highlightWireFrameArea(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.highlightWireFrameArea(aParams);
        break;
      default:
    }
    return true;
  },
  selectHighlightWireFrameAreaRemoveSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.highlightWireFrameAreaRemove(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.highlightWireFrameAreaRemove(aParams);
        break;
      default:
    }
    return true;
  },
  selectUploadAssetCompleteSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.uploadAssetComplete(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.uploadAssetComplete(aParams);
        break;
      default:
    }
    return true;
  },
  selectSaveCopyTextSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.saveCopyText(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.saveCopyText(aParams);
        break;
      default:
    }
    return true;
  },
  selectSaveEditTextSection: function(aParams){
    switch (LiveAdMaker.SelectedSectionId) {
      case "CreateAd" :
        LiveAdMaker.CreateAd.Customize.saveEditText(aParams);
        break;
      case "LocalCampaigns" :
        LiveAdMaker.LocalCampaigns.Customize.saveEditText(aParams);
        break;
      default:
    }
    return true;
  },
  createNewSectionItem: function(e,aParams){
    aParams = aParams || {};
    var zCreateNewParams = {
      Section: aParams.Section || LiveAdMaker.SelectedSectionId,
      SubSection: aParams.SubSection || "",
      Item: aParams.ItemId || "",
      ItemPath: aParams.ItemPath || "",
      Action: aParams.Action || "",
      OwnerObjectCode: aParams.OwnerObjectCode
    }
    if(aParams.SubSection) {
      zCreateNewParams.SelectedItem = LiveAdMaker[aParams.Section][aParams.SubSection].SubItemList.SelectedItem;
    }
    else {
      zCreateNewParams.SelectedItem = LiveAdMaker.SelectedSection.List.SelectedItem;
    }
    if(aParams.SubSection && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section][aParams.SubSection] && LiveAdMaker[aParams.Section][aParams.SubSection].createNewItem) {
      LiveAdMaker[aParams.Section][aParams.SubSection].createNewItem(zCreateNewParams);
    }
    else if(aParams.SubSection && LiveAdMaker[aParams.SubSection] && LiveAdMaker[aParams.SubSection].createNewItem) {
      LiveAdMaker[aParams.SubSection].createNewItem(zCreateNewParams);
    }
    else if(aParams.Section && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section].createNewItem) {
      LiveAdMaker[aParams.Section].createNewItem(zCreateNewParams);
    }
    else if (LiveAdMaker.SelectedSection && LiveAdMaker.SelectedSection.createNewItem){
      LiveAdMaker.SelectedSection.createNewItem(zCreateNewParams);
    }
    return true;
  },
  archiveSectionItem:function(e,aParams){
    if (!LiveAdMaker.SelectedSection) { return true };
    var zSection, zSelectedItem, zPreviousItemIndex, zList;
    aParams = aParams || {};
    var zArchiveParams = {
      Section: aParams.Section || LiveAdMaker.SelectedSectionId,
      SubSection: aParams.SubSection || "",
      Item: aParams.ItemId || "",
      Action: aParams.Action || "",
      View: aParams.View || ""
    }
    if(aParams.SubSection) {
      zSelectedItem = LiveAdMaker[aParams.Section][aParams.SubSection].SubItemList.SelectedItem;
      if(LiveAdMaker[aParams.Section][aParams.SubSection] && LiveAdMaker[aParams.Section][aParams.SubSection].archiveItem) {
        zSection = LiveAdMaker[aParams.Section][aParams.SubSection];
      }
      else if(LiveAdMaker[aParams.SubSection] && LiveAdMaker[aParams.SubSection].archiveItem) {
        zSection = LiveAdMaker[aParams.SubSection];
      }
    }
    else {
      zSelectedItem = LiveAdMaker.SelectedSection.List.SelectedItem;
      if(LiveAdMaker.SelectedSection && LiveAdMaker.SelectedSection.archiveItem) {
        zSection = LiveAdMaker.SelectedSection;
      }
    }
    if(zSection && zSelectedItem) {
      var zAllowArchive = true;
      if(LiveAdMaker.SelectedSection.allowArchive){
        zAllowArchive = LiveAdMaker.SelectedSection.allowArchive(zSelectedItem);
      }
      if(zAllowArchive) {
        if(zSection) {
          zList = (zSection.SubItemList) ? zSection.SubItemList : zSection.List;
          zPreviousItemIndex = Math.abs(zList.ItemArray.indexOf(zSelectedItem) - 1);
          zArchiveParams.PreviousItemId = (zList.ItemArray[zPreviousItemIndex]) ? zList.ItemArray[zPreviousItemIndex].Id : null;
        }
        var zConfirm = confirm("Are you sure you want to archive "+zSelectedItem.DisplayName+"?");
        if (zConfirm){
          zArchiveParams.SelectedItem = zSelectedItem;
          zArchiveParams.ItemId = zSelectedItem.Id;
          zSection.archiveItem(zArchiveParams);
        }
      } else {
          var zSelectedItemName = zSelectedItem.DisplayName;
          var zCannotArchiveText = zSelectedItemName + " cannot be archived.";
          var zCannotArchiveTitle = "Alert";
          DOM.Dialog.alert(zCannotArchiveText, "center", zCannotArchiveTitle, 300, 50);
      }
    }
    return true;
  },
  duplicateSectionItem:function(e,aParams){
    if (!LiveAdMaker.SelectedSection) {return true};
    aParams = aParams || {};
    var zCreateNewParams = {
      Section: aParams.Section || LiveAdMaker.SelectedSectionId,
      SubSection: aParams.SubSection || "",
      Item: aParams.ItemId || "",
      Action: aParams.Action || ""
    }
    if(aParams.SubSection) {
      zCreateNewParams.SelectedItem = LiveAdMaker[aParams.Section][aParams.SubSection].SubItemList.SelectedItem;
    }
    else {
      zCreateNewParams.SelectedItem = LiveAdMaker.SelectedSection.List.SelectedItem;
    }
    if(aParams.SubSection && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section][aParams.SubSection] && LiveAdMaker[aParams.Section][aParams.SubSection].duplicateItem) {
      LiveAdMaker[aParams.Section][aParams.SubSection].duplicateItem(zCreateNewParams);
    }
    else if(aParams.SubSection && LiveAdMaker[aParams.SubSection] && LiveAdMaker[aParams.SubSection].duplicateItem) {
      LiveAdMaker[aParams.SubSection].duplicateItem(zCreateNewParams);
    }
    else if(aParams.Section && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section].duplicateItem) {
      LiveAdMaker[aParams.Section].duplicateItem(zCreateNewParams);
    }
    else if (LiveAdMaker.SelectedSection && LiveAdMaker.SelectedSection.duplicateItem){
      LiveAdMaker.SelectedSection.duplicateItem(zCreateNewParams);
    }
  },
  undoSectionItem: function() {
    FormUI.History.undo();
  },
  redoSectionItem: function() {
    FormUI.History.redo();
  },
  addToSection: function(e,aParams){
    aParams = aParams || LiveAdMaker.SelectedSection;
    aParams.List = aParams.List || LiveAdMaker.SelectedSection.List;
    if (!aParams) {return true};
    var zAddToParams = {
      Section: aParams.Section || LiveAdMaker.SelectedSectionId,
      SubSection: aParams.SubSection || "",
      ItemPath: aParams.List.SelectedItem.ItemPath || LiveAdMaker.SelectedSection.ItemPath,
      AddToItemPath: aParams.List.SelectedItem.ItemPath || LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath
    };
    if(aParams.SubSection && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section][aParams.SubSection] && LiveAdMaker[aParams.Section][aParams.SubSection].addToSection) {
      LiveAdMaker[aParams.Section][aParams.SubSection].addToSection(zAddToParams);
    }
    else if(aParams.SubSection && LiveAdMaker[aParams.SubSection] && LiveAdMaker[aParams.SubSection].addToSection) {
      LiveAdMaker[aParams.SubSection].addToSection(zAddToParams);
    }
    else if(aParams.Section && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section].addToSection) {
      LiveAdMaker[aParams.Section].addToSection(zAddToParams);
    }
    else if (LiveAdMaker.SelectedSection && LiveAdMaker.SelectedSection.addToSection){
      LiveAdMaker.SelectedSection.addToSection(zAddToParams);
    }
    return true;
  },
  importexportSectionItem: function(e,aParams){
    if (!LiveAdMaker.SelectedSection) {return true};
    aParams = aParams || {};
    var zImportExportParams = {
      Section: aParams.Section || LiveAdMaker.SelectedSectionId,
      SubSection: aParams.SubSection || "",
      ItemPath: aParams.ItemPath || LiveAdMaker.SelectedSection.ItemPath,
      ImportExportToItemPath: aParams.ImportExportToItemPath || LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath
    };
    if(aParams.SubSection && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section][aParams.SubSection] && LiveAdMaker[aParams.Section][aParams.SubSection].importexportSectionItem) {
      LiveAdMaker[aParams.Section][aParams.SubSection].importexportSectionItem(zImportExportParams);
    }
    else if(aParams.SubSection && LiveAdMaker[aParams.SubSection] && LiveAdMaker[aParams.SubSection].importexportSectionItem) {
      LiveAdMaker[aParams.SubSection].importexportSectionItem(zImportExportParams);
    }
    else if(aParams.Section && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section].importexportSectionItem) {
      LiveAdMaker[aParams.Section].importexportSectionItem(zImportExportParams);
    }
    else if (LiveAdMaker.SelectedSection && LiveAdMaker.SelectedSection.importexportSectionItem){
      LiveAdMaker.SelectedSection.importexportSectionItem(zImportExportParams);
    }
    return true;
  },
  exportSectionItem: function(e,aParams){
    if (!LiveAdMaker.SelectedSection) {return true};
    aParams = aParams || {};
    var zExportParams = {
      Section: aParams.Section || LiveAdMaker.SelectedSectionId,
      SubSection: aParams.SubSection || "",
      ItemPath: aParams.ItemPath || LiveAdMaker.SelectedSection.ItemPath,
      ExportToItemPath: aParams.ExportToItemPath || LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath
    };
    if(aParams.SubSection && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section][aParams.SubSection] && LiveAdMaker[aParams.Section][aParams.SubSection].exportSectionItem) {
      LiveAdMaker[aParams.Section][aParams.SubSection].exportSectionItem(zExportParams);
    }
    else if(aParams.SubSection && LiveAdMaker[aParams.SubSection] && LiveAdMaker[aParams.SubSection].exportSectionItem) {
      LiveAdMaker[aParams.SubSection].exportSectionItem(zExportParams);
    }
    else if(aParams.Section && LiveAdMaker[aParams.Section] && LiveAdMaker[aParams.Section].exportSectionItem) {
      LiveAdMaker[aParams.Section].exportSectionItem(zExportParams);
    }
    else if(LiveAdMaker.SelectedSection && LiveAdMaker.SelectedSection.exportSectionItem){
      LiveAdMaker.SelectedSection.exportSectionItem(zExportParams);
    }
    return true;
  },
  drawSection: function(aParams){
    var zSection = LiveAdMaker[aParams.Section], zListType, zDrawParams;
    if (zSection.List) {
      zDrawParams = {Section: aParams.Section, ParentElement: null, Actions: LiveAdMaker[aParams.Section].Actions, Id: aParams.Section, DisabledNavigationArray: zSection.List.DisabledNavigationArray};
    } else {
      zDrawParams = {Section: aParams.Section, ParentElement: null, Actions: LiveAdMaker[aParams.Section].Actions, Id: aParams.Section};
    }
    var zIsCurrentHashValues = LiveAdMaker.matchCurrentHashValues(aParams,["Section"]);
    if(!aParams.Item && zSection.Items[0]) {
      if(zSection.List && zSection.List.SelectedItemId) {
        aParams.Item = zSection.List.SelectedItemId;
      } else {
        for(var i = 0; i < zSection.Items.length; i++) {
          if(zSection.Items[i].NodeType!="LabelNode") {
            aParams.Item = zSection.Items[i].Id;
            break;
          }
        }
      }
    }
    if(aParams.Item && !LiveAdMaker.getItemById(LiveAdMaker[aParams.Section].Items, aParams.Item)) {
      aParams.Item = zSection.Items[0].Id;
    }
    if (aParams.UseDefaultAction) {
      aParams.Action = LiveAdMaker[aParams.Section].Actions[0].Id;
    }
    if (!aParams.Action && LiveAdMaker[aParams.Section].Actions) {
      aParams.Action = LiveAdMaker[aParams.Section].SelectedAction ||
        Util.getCookieValue(aParams.Section + "_SelectedAction") ||
        LiveAdMaker[aParams.Section].DefaultAction ||
        LiveAdMaker[aParams.Section].Actions[0].Id;
    }
    var zGetItem = LiveAdMaker.getItemById(zSection.Items, aParams.Item);
    var zGetActions = LiveAdMaker.getActionsByType(zSection, (zGetItem ? zGetItem.Type : null));
    if (!zGetActions.getFirst(aParams.Action,"Id")) {
      aParams.Action = zGetActions[0].Id;
    }
    if(zIsCurrentHashValues) {
      if(LiveAdMaker.SelectedSection != zSection) {
        aParams.Redraw = true;
      }
      LiveAdMaker.SelectedSection = zSection;
      LiveAdMaker.SelectedSectionId = aParams.Section;
      document.body.setAttribute("class", "section-"+aParams.Section.toLowerCase());
      zDrawParams.ParentElement = $("Content");
    }
    var zMyViewCookie = Util.getCookieValue(aParams.Section+"_SelectedView");
    if (zMyViewCookie){
      var zViewTested = "view"+zMyViewCookie;
      if (aParams.DisabledNavigationArray) {
        for(var i=0; i<aParams.DisabledNavigationArray.length;i++){
              if(zViewTested==aParams.DisabledNavigationArray[i].Id.toLowerCase()){
                          zMyViewCookie=null;
              }
        }
      }
    }
        var zListViewType = zSection.SelectedView
                     || zMyViewCookie
                     || zSection.DefaultView
                     || "ActionsWithName";
    if($("Nav"+aParams.Section)) {
      LiveAdMaker.updateBrowserTitle($("Nav"+aParams.Section).innerHTML);
    }
    if(!zSection.List||aParams.Redraw) {
      switch (zListViewType) {
        case "ActionsWithName" :
          zDrawParams.ListType = "ActionUI";
          zDrawParams.View = "property";
          break;
        case "ActionsWithThumbnail" :
          zDrawParams.ListType = "ActionUI";
          zDrawParams.View = "thumbnailAndName";
          break;
        case "thumbnailAndName" :
          zDrawParams.ListType = "List";
          zDrawParams.View = "thumbnailAndName";
          zDrawParams.CreateContainerFunction = List.createLightbox;
          break;
        case "Calendar" :
          zListViewType = "Calendar";
          zDrawParams.ListType = "List";
          zDrawParams.CreateContainerFunction= List.createCalendar;
          break;
        default:
          zListViewType = "table";
          zDrawParams.ListType = "List";
          zDrawParams.CreateContainerFunction= List.createTable;
      }
      zDrawParams.Fields = zSection.Fields;
      zDrawParams.ItemArray = zSection.Items;
      zDrawParams.Sortable = true;
      zDrawParams.OnSortCompleteFunction = LiveAdMaker.sortItems;
      zDrawParams.OwnerItemPath = LiveAdMaker[aParams.Section].ItemPath;
      zDrawParams.OwnerObjectCode = zSection.ItemObjectCode || "";
      zDrawParams.ListOptions = zSection.ListOptions || {};
      if (zSection.FilterListItemPath){
        zDrawParams.FilterListItemPath = zSection.FilterListItemPath;
      }
      if (zSection.SearchCriteria){
        zDrawParams.SearchCriteria = zSection.SearchCriteria;
      }
      if (zSection.SearchCriteriaExtraParams){
        zDrawParams.SearchCriteriaExtraParams = zSection.SearchCriteriaExtraParams;
      }
      zDrawParams.SearchObjectItemPath = zSection.SearchObjectItemPath || "intel\\ModuleList\\Search";
      zDrawParams.SearchAction = zSection.SearchAction || "FilterListSearch";
      zDrawParams.SearchParams = zSection.SearchParams || null;
      zDrawParams.FilterOptionsArray = zSection.FilterOptionsArray || '';
      if(zSection.List && zSection.List.SelectedItemId) {
        aParams.Item = aParams.Item || zSection.List.SelectedItemId;
      }
      zSection.List = new List(zDrawParams);
      zDrawParams.List = zSection.List;
      if (LiveAdMaker.SelectedSection) {
        LiveAdMaker.SelectedSection.SelectedAction = aParams.Action;
      }
      zSection.List.draw(zDrawParams);
      DOM.addClass(zSection.List.ContainerElement, 'ListContainer_'+aParams.Section);
      LiveAdMaker.resizeInterface(null);
    } else {
      if($("Content").firstChild != zSection.List.ContainerElement) {
        DOM.replaceContent($("Content"), zSection.List.ContainerElement);
      }
    }
    var zItemSelected = false;
    if(aParams.Item && zDrawParams.ListType != "List") {
      zItemSelected = zSection.List.selectItem(aParams.Item);
      if (aParams.Redraw) {
        List.scrollToSelectedItem(zSection.List);
        aParams.ReDrawSubSection = true;
      }
    }
    if(aParams.Action && aParams.Item) {
      LiveAdMaker[aParams.Section].SelectedAction = aParams.Action;
      Util.setCookie(aParams.Section+"_SelectedAction", aParams.Action);
      var zAction = LiveAdMaker.getItemById(LiveAdMaker[aParams.Section].Actions, aParams.Action);
      var zItem = LiveAdMaker.getItemById(LiveAdMaker[aParams.Section].Items, aParams.Item);
      LiveAdMaker.selectItemInList(zItem, zSection, zSection.List);
      var zActionParams = {
        Item: zItem,
        ItemId: aParams.Item,
        Action: zAction,
        ActionId: aParams.Action,
        Section: zSection,
        SectionId: aParams.Section,
        List: zSection.List,
        ContentElement: zSection.List.ContentElement,
        SubItem: aParams.SubItem,
        SubAction: aParams.SubAction
      };
      var zActionSelected = zSection.List.selectAction(aParams);
      if(zActionSelected || zItemSelected) {
        if(!LiveAdMaker._tempSpan) {
          LiveAdMaker._tempSpan = DOM.createElement('span');
        }
        DOM.replaceContent(zSection.List.ContentElement,LiveAdMaker._tempSpan);
        List.LightboxView.removeZoom();
        if(zAction.DisplayFunction && zItem.BaseType != "VirtualNode") {
          zAction.DisplayFunction(zActionParams);
        } else {
            if(zActionParams.Item.ItemPath && zActionParams.Item.ItemPath!="") {
              FormUI.Request.GetForm(zActionParams.Item.ItemPath, 'Form'+zAction, zActionParams.ContentElement);
            }
        }
      }
      if (!LiveAdMaker[aParams.Section][aParams.Action] || !LiveAdMaker[aParams.Section][aParams.Action].SubItemList) {
        LiveAdMaker.SelectedSubSection = null;
      }
      if(aParams.SubItem && LiveAdMaker[aParams.Section][aParams.Action] && LiveAdMaker[aParams.Section][aParams.Action].SubItemList) {
        LiveAdMaker.selectSubItem({
          Section: aParams.Section,
          SubSection: aParams.Action,
          ItemId: aParams.SubItem,
          SubItem: aParams.SubItem,
          ActionId: aParams.SubAction,
          SubAction: aParams.SubAction,
          ParentItemId: aParams.Item,
          ParentActionId: aParams.Action,
          ReDrawSubSection: aParams.ReDrawSubSection,
          UseDefaultSubAction: aParams.UseDefaultSubAction
        });
      }
      var zDuration = 0;
      if (zSection.LoadStartTime) {
        var zTime = new Date();
        zDuration = zTime.valueOf() - zSection.LoadStartTime;
      }
      if (!aParams.SubItem) {
        URI.Track.send("LOCAL."+aParams.Section+"."+aParams.Action,null,null,zDuration,null);
      } else {
        if (aParams.SubAction) {
          URI.Track.send("LOCAL."+aParams.Section+"."+aParams.Action+"."+aParams.SubAction,null,null,zDuration,null);
        } else {
          URI.Track.send("LOCAL."+aParams.Section+"."+aParams.Action+".Details",null,null,zDuration,null);
        }
      }
    }
    var zTopNavContainer = $('TopNavButtonContainer');
    if (zTopNavContainer) {
      var zNavigationArray = [
        {Title: "List View", Id: "ViewList", IconId: "Icon_ViewList", Function: LiveAdMaker.toggleView, Params: {ViewName: "ActionsWithName"}, Attributes: {SelectGroup: "ToggleViewButton", ViewType: "ActionsWithName"}},
        {Title: "Thumbnail List View", Id: "ViewBubbleImage", IconId: "Icon_ViewBubbleImage", Function: LiveAdMaker.toggleView, Params: {ViewName: "ActionsWithThumbnail"}, Attributes: {SelectGroup: "ToggleViewButton", ViewType: "ActionsWithThumbnail"}},
        {Title: "Table View", Id: "ViewTable", IconId: "Icon_ViewTable", Function: LiveAdMaker.toggleView, Params: {List: this, Params: aParams, ViewName: "table"}, Attributes: {SelectGroup: "ToggleViewButton", ViewType: "table"}},
        {Title: "Lightbox View", Id: "ViewThumbnail", IconId: "Icon_ViewThumbnail", Function: LiveAdMaker.toggleView, Params: {List: this, Params: aParams, ViewName: "thumbnailAndName"}, Attributes: {SelectGroup: "ToggleViewButton", ViewType: "thumbnailAndName"}},
        {Title: "New", Id: "NewButton", IconId: "Icon_New", Label: "New", Function: LiveAdMaker.createNewSectionItem, Params: {OwnerObjectCode: zSection.ItemObjectCode}},
        {Title: "Add To", Id: "AddToButton", IconId: "Icon_AddToIcon", Label: "Add To", Function: LiveAdMaker.addToSection},
        {Title: "Duplicate", Id: "DuplicateButton", IconId: "Icon_Duplicate", Label: "Duplicate", Function: LiveAdMaker.duplicateSectionItem},
        {Title: "Archive", Id: "ArchiveButton", IconId: "Icon_Archive", Label: "Archive", Function: LiveAdMaker.archiveSectionItem},
        {Title: "Import", Id: "ImportExportButton", IconId: "Icon_ImportExport", Label: "Import", Function: LiveAdMaker.importexportSectionItem},
        {Title: "Export", Id: "ExportButton", IconId: "Icon_ImportExport", Label: "Export", Function: LiveAdMaker.exportSectionItem},
        {Title: "Undo", Id: "UndoButton", IconId: "Icon_Undo", Label: "Undo", Function: LiveAdMaker.undoSectionItem},
        {Title: "Redo", Id: "RedoButton", IconId: "Icon_Redo", Label: "Redo", Function: LiveAdMaker.redoSectionItem}
      ];
      aParams.NavigationArray = zNavigationArray;
      if ($('TopNavSubButtonContainer'))
        DOM.removeElement($('TopNavSubButtonContainer'));
      var zNavDiv = DOM.createElement("div","TopNavSubButtonContainer",null);
      aParams.NavDiv = zNavDiv;
      var zContainerElement_temp = zSection.List.ContainerElement;
      zSection.List.ContainerElement = zTopNavContainer;
      if (zSection.drawNavigation) {
        zSection.drawNavigation(aParams)
      }
      else {
        zSection.List.drawNavigation(aParams, zSection)
      }
      zSection.List.ContainerElement = zContainerElement_temp;
    }
    if(zIsCurrentHashValues) {
      LiveAdMaker.highlightSelectedView(zListViewType);
    }
    if (URI.User && URI.User.Settings.AutoHelpDisplay == "On")
      AutoHelp.getHelpText(aParams,zSection.Items.length);
    return true;
  },
  selectItemInList: function(aListItem, aSection, aList) {
    if (!aListItem) {return true};
    if (aList.onSelectItemFunction) {
      aList.onSelectItemFunction(aListItem, aSection);
    }
    return true;
  },
  getItemById: function(aList, aId){
    if(aList && aId){
      for(var i = 0; i < aList.length; i++) {
        if(aList[i].Id && aList[i].Id == aId) {
          return aList[i];
        }
      }
    }
    return null;
  },
  leftNavHeight: "",
  hide: function (aSelectedId, aDuration) {
    $(aSelectedId).style.display = "none";
    $("ClosedLeftNavLabel").IsOpen= "N";
  },
  show: function (aSelectedId, aDuration) {
    $(aSelectedId).style.display = "block";
    $("ClosedLeftNavLabel").IsOpen= "Y";
  },
  toggleLeftNav: function(aId, aStatus, aTween, aSelectedSectionId) {
    if (!aTween) {aTween = "Y"};
    var aTweenStartDelay = 0;
    var aTweenInterval = 2;
    if (!aStatus) {aStatus = "toggle"}
    else if (aStatus != "Show" && aStatus != "Hide") {
      return true;
    }
    if(LiveAdMaker.isLeftNavCollapsed && aStatus != "Hide") {
      $('ClosedLeftNavLabel').innerHTML = "";
      Event.remove($("ClosedLeftNavLabel"), "onmouseover");
      Event.remove($("Content"), "onmouseover");
      Event.remove($("TopNavContainer"), "onmouseover");
      LiveAdMaker.isLeftNavCollapsed = false;
      DOM.removeClass(document.body, "LeftNavCollapsed");
      LiveAdMaker.show("LeftNavContainer", aTweenInterval);
      DOM.removeClass($(aId), "Icon_MenuArrowDown");
      DOM.addClass($(aId), "Icon_MenuArrowUp");
      LiveAdMaker.resizeInterface(null);
    } else if (aStatus != "Show") {
      LiveAdMaker.isLeftNavCollapsed = true;
      LiveAdMaker.hide("LeftNavContainer", aTweenInterval);
      DOM.addClass(document.body, "LeftNavCollapsed");
      DOM.removeClass($(aId), "Icon_MenuArrowUp");
      DOM.addClass($(aId), "Icon_MenuArrowDown");
      LiveAdMaker.resizeInterface(null);
      DOM.addEvent($("ClosedLeftNavLabel"), "onmouseover", function(e) {
       LiveAdMaker.show("LeftNavContainer");
        DOM.removeClass($(aId), "Icon_MenuArrowDown");
        DOM.addClass($(aId), "Icon_MenuArrowUp");
        if (LiveAdMaker.SelectedSectionId) {
          $("ClosedLeftNavLabel").innerHTML = $('Nav' + LiveAdMaker.SelectedSectionId).getAttribute('SectionName');
        }
        return true;
      });
      DOM.addEvent($("Content"), "onmouseover", function(e) {
        if ($("ClosedLeftNavLabel").IsOpen =="Y"){
          LiveAdMaker.hide("LeftNavContainer");
          DOM.removeClass($(aId), "Icon_MenuArrowUp");
          DOM.addClass($(aId), "Icon_MenuArrowDown");
          if (LiveAdMaker.SelectedSectionId) {
            $("ClosedLeftNavLabel").innerHTML = $('Nav' + LiveAdMaker.SelectedSectionId).getAttribute('SectionName');
          }
          $("ClosedLeftNavLabel").IsOpen= "N";
        }
        return true;
      });
      DOM.addEvent($("TopNavContainer"), "onmouseover", function(e) {
        if ($("ClosedLeftNavLabel").IsOpen =="Y"){
          LiveAdMaker.hide("LeftNavContainer");
          DOM.removeClass($(aId), "Icon_MenuArrowUp");
          DOM.addClass($(aId), "Icon_MenuArrowDown");
          if (LiveAdMaker.SelectedSectionId) {
            $("ClosedLeftNavLabel").innerHTML = $('Nav' + LiveAdMaker.SelectedSectionId).getAttribute('SectionName');
          }
          $("ClosedLeftNavLabel").IsOpen= "N";
        }
        return true;
      });
      if (LiveAdMaker.SelectedSectionId||aSelectedSectionId) {
        var zSelectedSectionId = LiveAdMaker.SelectedSectionId || aSelectedSectionId;
        $("ClosedLeftNavLabel").innerHTML = $('Nav' + zSelectedSectionId).getAttribute('SectionName');
      }
    }
  },
  toggleMaximize: function(){
    if(DOM.hasAttribute(document.body, "class", "Maximized")) {
      DOM.removeClass(document.body, "Maximized");
    } else {
      DOM.addClass(document.body, "Maximized");
    }
    DOM.Resize.recurse();
    return true;
  },
  handleUpdatedHash: function(aValues){
    DOM.getElementsWithClassName("a","leftnavActivebutton",$("LeftNavContainer")).forEach(function (zLink){
      DOM.removeClass(zLink, "leftnavActivebutton");
      DOM.addClass(zLink, "leftnavbutton");
    });
    aValues = aValues || {};
    aValues.Section = aValues.Section || "Home";
    if (aValues.Maximize && isTrue(aValues.Maximize) && !DOM.hasAttribute(document.body, "class", "Maximized")) {
      LiveAdMaker.toggleMaximize();
    }
    if(LiveAdMaker[aValues.Section] && LiveAdMaker[aValues.Section].Load) {
      if ($("Nav"+aValues.Section)){
        DOM.removeClass($("Nav"+aValues.Section), "leftnavbutton");
        DOM.addClass($("Nav"+aValues.Section), "leftnavActivebutton");
      }
      DOM.Dialog.hide();
      var zTime = new Date();
      LiveAdMaker[aValues.Section].LoadStartTime = zTime.valueOf();
      LiveAdMaker[aValues.Section].Load(aValues);
    }
    if (aValues.Menu) {
      if (aValues.Menu == "Hide") {
        DOM.addClass(document.body, "LeftNavCollapsed");
      }
      LiveAdMaker.toggleLeftNav("MenuArrowDown", aValues.Menu, "N", aValues.Section);
    }
    return true;
  },
  matchCurrentHashValues: function(aParams,aCheckArray){
    var zMatches = true;
    var zCheckArray = aCheckArray || ["Section","Action","Item","SubAction","SubItem"];
    zCheckArray.forEach(function(aCheck){
      if(zMatches) {
        var zCurrentCheck = aParams[aCheck+"Id"] || aParams[aCheck];
        if(URI.CurrentHashValues[aCheck] && URI.CurrentHashValues[aCheck] != zCurrentCheck) {
          zMatches = false
        }
      }
    });
    return zMatches;
  },
  scheduleResizeInterface: function(){
    return true;
  },
  resizeInterface: function(aResizeInterfaceId){
    DOM.Resize.recurse();
    return true;
  },
  getAction:function(aAction,aSection){
    aSection = (aSection ? aSection : LiveAdMaker.SelectedSection.Name);
    if (LiveAdMaker[aSection].Actions&&LiveAdMaker[aSection].Actions.length>0){
      for (var x=0; x<LiveAdMaker[aSection].Actions.length; x++){
        if (LiveAdMaker[aSection].Actions[x].Id==aAction){
          var aMatching_Action = LiveAdMaker[aSection].Actions[x];
        }
      }
    }
    return aMatching_Action;
  },
  getActionsByType: function(aSection, aType) {
    if(aType=="SearchResults") {
      return LiveAdMaker.SearchResults.Actions
    }
    if(aSection.getActionsByType) {
      return LiveAdMaker.filterActions(aSection.getActionsByType(aType));
    }
    if(aSection.ActionsByType && aSection.ActionsByType[aType]) {
      return LiveAdMaker.filterActions(aSection.ActionsByType[aType]);
    }
    if (!aType) {
      if (aSection.Actions) {return LiveAdMaker.filterActions(aSection.Actions)}
      if (aSection.SubItemList.Actions) {return LiveAdMaker.filterActions(aSection.SubItemList.Actions)}
    }
    if(aSection.Actions) {
      var zActions = aSection.Actions.filter(function(aAction){
        return (aAction.Types && aAction.Types.contains(aType));
      });
      if(zActions.length) {
        return LiveAdMaker.filterActions(zActions);
      }
    }
    if(aSection.getActions) {
      return LiveAdMaker.filterActions(aSection.getActions());
    }
    return LiveAdMaker.filterActions(aSection.Actions);
  },
  filterActions: function(aActionArray) {
    if (aActionArray) {
      var aActionArray = aActionArray.filter(function(aAction){
        return (aAction.Id!="SearchResults");
      });
    }
    return aActionArray
  },
  sortItems: function(aNewItemArray,aParams){
    var zSection = LiveAdMaker[aParams.Section];
    if(aParams.SubSection) {
      zSection = zSection[aParams.SubSection];
      zSection.List.ItemArray = aNewItemArray;
      zSection.SubItemList.ItemArray = aNewItemArray;
    }
    else {
      zSection.Items = aNewItemArray;
      zSection.List.ItemArray = aNewItemArray;
    }
    var zSortAction = zSection.SortAction || "SortItems";
    var zItemPathsArray = [];
    aNewItemArray.forEach(function(aItem){
      zItemPathsArray.push(aItem.ItemPath);
    });
    if(zSection.ItemPath) {
      Ajax.makeRequest({
        URL: URI.pageURL(zSection.ItemPath, zSortAction),
        Function: function(){return true;},
        Method: "POST",
        PostValues: {aItems: zItemPathsArray.join(";")}
      });
    }
    return true;
  },
  requestSubItems: function(aParams){
    var zReceiveSubItemsFunction = aParams.ReceiveSubItemsFunction || LiveAdMaker.receiveSubItems;
    Ajax.makeRequest({
      URL: aParams.URL || aParams.Action.RequestSubItemsURL,
      Function: zReceiveSubItemsFunction,
      Params: aParams
    });
    return true;
  },
  receiveSubItems: function(aData,aParams){
    var zCheckHashArray = aParams.CheckHashArray || ["Section","Action","Item"];
    if(LiveAdMaker.matchCurrentHashValues(aParams, zCheckHashArray) || aParams.ForceDrawSubItems) {
      var zSubSection = LiveAdMaker[aParams.SectionId][aParams.ActionId];
      zSubSection.ItemPath = aData.ItemPath;
      var zDrawParams = Util.copyProperties({
        Id: aParams.ActionId+"List",
        ItemArray: aData.Items,
        OwnerItemPath: aData.ItemPath,
        Fields: aData.Fields,
        Actions: zSubSection.Actions || zSubSection.getActions(),
        ReDrawSubSection: true
      },aParams);
      if (!zDrawParams.DisabledNavigationArray&&aData.DisabledNavigationArray) {
        zDrawParams.DisabledNavigationArray = aData.DisabledNavigationArray
      }
      aParams.ForceDrawSubItems = false;
      zDrawParams.OwnerObjectCode = aData.ItemObjectCode || "";
      zDrawParams.ListOptions = zSubSection.ListOptions || {};
      LiveAdMaker.drawSubItemsList(zDrawParams);
    }
    return true;
  },
  drawSubItemsList: function(aParams){
    var zDrawParams = Util.copyProperties({
      Action: aParams.ActionId,
      SubSection: aParams.ActionId,
      ListType: aParams.List.Params.ListType,
      View: "subitem",
      ParentElement: aParams.ContentElement,
      OnSortCompleteFunction: LiveAdMaker.sortItems
    },aParams);
    if(zDrawParams.SectionId) {
      zDrawParams.Section = zDrawParams.SectionId;
    }
    if(aParams.ShowNavigation == false) {
      zDrawParams.ShowNavigation = false;
    } else {
      zDrawParams.ShowNavigation = true;
    }
    if(aParams.Sortable == false) {
      zDrawParams.Sortable = false;
    } else {
      zDrawParams.Sortable = true;
    }
    var zIsCurrentHashValues = LiveAdMaker.matchCurrentHashValues(aParams);
    var zSubSection = LiveAdMaker[zDrawParams.SectionId][zDrawParams.SubSection];
    var zListViewType = zSubSection.SelectedView
                     || Util.getCookieValue(zDrawParams.SectionId+"_"+zDrawParams.SubSection+"_SelectedView")
                     || zSubSection.DefaultView
                     || "ActionsWithName";
    switch (zListViewType) {
      case "table" :
        zDrawParams.ListType = "List";
        zDrawParams.CreateContainerFunction = List.createTable;
        zDrawParams.Fields = aParams.List.Fields;
        zDrawParams.View = "";
        zDrawParams.SubItemTable = true;
        break;
      case "thumbnailAndName" :
        zDrawParams.ListType = "List";
        zDrawParams.View = "";
        zDrawParams.SubItemTable = true;
        zDrawParams.CreateContainerFunction = List.createLightbox;
        break;
      case "Calendar" :
        zDrawParams.ListType = "List";
        zDrawParams.SubItemTable = true;
        zDrawParams.CreateContainerFunction = List.createCalendar;
        break;
      case "ActionsWithThumbnail" :
        zDrawParams.ListType = "ActionUI";
        zDrawParams.View = "subitemThumbnail";
        break;
      default:
        zDrawParams.ListType = "ActionUI";
        zDrawParams.View = "subitem";
        break;
    }
    zSubSection.SelectedView = zListViewType;
    var zSubItemList = new List(zDrawParams);
    zDrawParams.List = zSubItemList;
    zSubItemList.draw(zDrawParams);
    zDrawParams.ReDrawSubSection = false
    zSubSection.SubItemList = zSubItemList;
    zSubSection.List = zSubItemList;
    if ( zDrawParams.ListType == "ActionUI" ) {
      LiveAdMaker.selectSubItem(zDrawParams);
    }
    if(zIsCurrentHashValues) {
      LiveAdMaker.highlightSelectedSubItemView(zSubItemList, zListViewType);
    }
    return true;
  },
  requestTripleBubbleItems: function(aParams){
    Ajax.makeRequest({
      URL: aParams.URL || aParams.Action.RequestSubItemsURL,
      Function: LiveAdMaker.receiveTripleBubbleItems,
      Params: aParams
    });
    return true;
  },
  receiveTripleBubbleItems: function(aData,aParams){
    var zSubSection = LiveAdMaker[aParams.SectionId][aParams.ActionId][aParams.SubActionId];
    zSubSection.ItemPath = aData.ItemPath;
    var zDrawParams = Util.copyProperties({
      Id: aParams.ActionId+"List",
      ItemArray: aData.Items,
      OwnerItemPath: aData.ItemPath,
      Fields: aData.Fields,
      ReDrawSubSection: true
    },aParams);
    if (!zDrawParams.DisabledNavigationArray && aData.DisabledNavigationArray) {
      zDrawParams.DisabledNavigationArray = aData.DisabledNavigationArray
    }
    zDrawParams.NavigationArray = zDrawParams.NavigationArray || [
    ];
    zDrawParams.OwnerObjectCode = aData.ItemObjectCode || "";
    zDrawParams.ListOptions = zSubSection.ListOptions || {};
    LiveAdMaker.drawTripleBubbleItemsList(zDrawParams);
    return true;
  },
  drawTripleBubbleItemsList: function(aParams){
    var zDrawParams = Util.copyProperties({
      Action: aParams.ActionId,
      SubSection: aParams.ActionId,
      ListType: aParams.List.Params.ListType,
      View: "subitem",
      ParentElement: aParams.ContentElement,
      OnSortCompleteFunction: LiveAdMaker.sortItems
    },aParams);
    if(zDrawParams.SectionId) {
      zDrawParams.Section = zDrawParams.SectionId;
    }
    if(aParams.ShowNavigation == false) {
      zDrawParams.ShowNavigation = false;
    } else {
      zDrawParams.ShowNavigation = true;
    }
    if(aParams.Sortable == false) {
      zDrawParams.Sortable = false;
    } else {
      zDrawParams.Sortable = true;
    }
    zDrawParams.TripleBubble = true;
    var zIsCurrentHashValues = LiveAdMaker.matchCurrentHashValues(aParams);
    var zSubSection = LiveAdMaker[aParams.SectionId][aParams.ActionId][aParams.SubActionId];
    var zListViewType = aParams.ViewType || "thumbnailAndName";
    switch (zListViewType) {
      case "table" :
        zDrawParams.ListType = "List";
        zDrawParams.CreateContainerFunction = List.createTable;
        zDrawParams.Fields = aParams.List.Fields;
        zDrawParams.View = "";
        zDrawParams.SubItemTable = true;
        break;
      case "thumbnailAndName" :
        zDrawParams.ListType = "List";
        zDrawParams.View = "";
        zDrawParams.SubItemTable = true;
        zDrawParams.CreateContainerFunction = List.createLightbox;
        break;
    }
    zSubSection.SelectedView = zListViewType;
    var zSubItemList = new List(zDrawParams);
    zDrawParams.List = zSubItemList;
    zSubItemList.draw(zDrawParams);
    zSubSection.SubItemList = zSubItemList;
    zSubSection.List = zSubItemList;
    return true;
  },
  selectSubItem: function(aParams){
    var zSubSection = LiveAdMaker[aParams.Section][aParams.SubSection];
    var zSubItem = aParams.SubItem ? LiveAdMaker.getItemById(zSubSection.SubItemList.ItemArray, aParams.SubItem) : zSubSection.SubItemList.ItemArray[0];
    LiveAdMaker.SelectedSubSection = zSubSection;
    if(zSubItem) {
      if(aParams.ReDrawSubSection) {
        zSubSection.SubItemList.draw(zSubSection.SubItemList.Params);
        LiveAdMaker.resizeInterface(null);
      }
      zSubSection.SubItemList.selectItem(zSubItem.Id, true);
      if (aParams.ReDrawSubSection) {
        List.scrollToSelectedItem(zSubSection.SubItemList);
      }
      var zSubActionId = aParams.SubAction
                      || zSubSection.SelectedAction
                      || Util.getCookieValue(aParams.Section+"_"+aParams.SubSection+"_SelectedAction")
                      || zSubSection.SubItemList.Actions[0].Id;
      if(aParams.UseDefaultSubAction) {
        zSubActionId = zSubSection.SubItemList.Actions[0].Id;
      }
      if (zSubSection.SubItemList && zSubSection.SubItemList.ActionNavContainerElement && zSubSection.SubItemList.ActionNavContainerElement.childNodes && zSubSection.SubItemList.ActionNavContainerElement.childNodes.length>0) {
        for (var i=0; i<zSubSection.SubItemList.ActionNavContainerElement.childNodes.length; i++) {
          if (zSubSection.SubItemList.ActionNavContainerElement.childNodes[i].List_Action==zSubActionId) {
            var zActionExists = true
          }
        }
        if (!zActionExists) {
          zSubActionId = zSubSection.SubItemList.ActionNavContainerElement.childNodes[0].List_Action
        }
      }
      var zSubAction = LiveAdMaker.getItemById(zSubSection.SubItemList.Actions, zSubActionId);
      zSubSection.SelectedAction = zSubActionId;
      Util.setCookie(aParams.Section+"_"+aParams.SubSection+"_SelectedAction", zSubActionId);
      zSubSection.SubItemList.selectAction({Action:zSubAction.Id, ForceReDraw: aParams.ReDrawSubSection});
      LiveAdMaker.resizeInterface(null);
      var zSubActionParams = {
        Item: zSubItem,
        ItemId: zSubItem.Id,
        ParentItemId: aParams.Item,
        ParentActionId: aParams.Action,
        Action: zSubAction,
        ActionId: zSubAction.Id,
        List: zSubSection.SubItemList,
        ContentElement: zSubSection.SubItemList.ContentElement
      };
      List.LightboxView.removeZoom();
      if(zSubAction.DisplayFunction) {
        zSubAction.DisplayFunction(zSubActionParams);
      } else {
        if(zSubActionParams.Item.ItemPath && zSubActionParams.Item.ItemPath!="") {
          FormUI.Request.GetForm(zSubActionParams.Item.ItemPath, 'Form'+zSubAction.Id, zSubSection.SubItemList.ContentElement);
        }
      }
    }
    return true;
  },
  toggleSubItemView: function(e,aParams){
    if (aParams.ViewName=="thumbnailAndName" && LiveAdMaker.SelectedSectionId == "Calendar") {
      aParams.ViewName="Calendar";
    }
    switch (aParams.ViewName) {
      case "table" :
        aParams.ViewName = "table"
        aParams.List.Params.ListType = "List";
        aParams.List.Params.CreateContainerFunction = List.createTable;
        aParams.List.Params.Fields = aParams.List.Fields;
        aParams.List.Params.View = "";
        aParams.List.Params.SubItemTable = true;
        break;
      case "thumbnailAndName" :
        aParams.List.Params.ListType = "List";
        aParams.List.Params.View = "";
        aParams.List.Params.SubItemTable = true;
        aParams.List.Params.CreateContainerFunction = List.createLightbox;
        break;
      case "Calendar" :
        aParams.ViewName = "Calendar"
        aParams.List.Params.ListType = "List";
        aParams.List.Params.View = "calendarItem";
        aParams.List.Params.SubItemTable = true;
        break;
      case "ActionsWithThumbnail":
        aParams.List.Params.ListType = "ActionUI";
        aParams.List.Params.View = "subitemThumbnail";
        break;
      default:
        aParams.ViewName = "ActionsWithName";
        aParams.List.Params.ListType = "ActionUI";
        aParams.List.Params.View = "subitem";
        break;
    }
    if(aParams.List.Params.Section && aParams.List.Params.SubSection) {
      if(LiveAdMaker[aParams.List.Params.Section] && LiveAdMaker[aParams.List.Params.Section][aParams.List.Params.SubSection]) {
        LiveAdMaker[aParams.List.Params.Section][aParams.List.Params.SubSection].SelectedView = aParams.ViewName;
      }
      else if(LiveAdMaker[aParams.List.Params.SubSection]) {
        LiveAdMaker[aParams.List.Params.SubSection].SelectedView = aParams.ViewName;
      }
    }
    LiveAdMaker.updateView({
      ViewName: aParams.ViewName,
      List: aParams.List,
      Section: aParams.List.Params.Section,
      SectionId: LiveAdMaker[aParams.List.Params.Section],
      IsSubItem: true,
      CookieName: aParams.List.Params.Section+"_"+aParams.List.Params.SubSection
    });
    LiveAdMaker.highlightSelectedSubItemView(aParams.List, aParams.ViewName);
    return true;
  },
  toggleView: function(e,aParams){
    if (!LiveAdMaker.SelectedSection || !LiveAdMaker.SelectedSection.List) {return true};
    LiveAdMaker.SelectedSection.List.Params.View = "";
    LiveAdMaker.updateView({
      ViewName: aParams.ViewName,
      List: LiveAdMaker.SelectedSection.List,
      Section: LiveAdMaker.SelectedSection,
      SectionId: LiveAdMaker.SelectedSectionId
    });
    return true;
  },
  updateView: function(aParams){
    var zDrawParams = Util.copyObject(aParams.List.Params), zCurrentParentElement = aParams.List.ContainerElement.parentNode;
    zDrawParams.CreateContainerFunction = null;
    zDrawParams.CreateItemFunction = null;
    zDrawParams.DisplayFunction = null;
    if(!aParams.IsSubItem || aParams.ListType != "ActionUI") {
      switch (aParams.ViewName) {
        case "ActionsWithName" :
          zDrawParams.ListType = "ActionUI";
          zDrawParams.View = zDrawParams.View || "property";
          break;
        case "ActionsWithThumbnail" :
          zDrawParams.ListType = "ActionUI";
          zDrawParams.View = zDrawParams.View || "thumbnailAndName";
          break;
        case "thumbnailAndName" :
          zDrawParams.ListType = "List";
          zDrawParams.View = "thumbnailAndName";
          zDrawParams.CreateContainerFunction = List.createLightbox;
          break;
        case "Calendar" :
          aParams.ViewName = "Calendar"
          zDrawParams.ListType = "List";
          aParams.List.Params.View = "";
          zDrawParams.CreateContainerFunction= List.createCalendar;
          zDrawParams.Fields = aParams.List.Fields;
          break;
        default:
          aParams.ViewName = "table"
          zDrawParams.ListType = "List";
          zDrawParams.CreateContainerFunction= List.createTable;
          zDrawParams.Fields = aParams.List.Fields;
          zDrawParams.View = "";
      }
    }
    aParams.List.Type = zDrawParams.ListType;
    aParams.List.View = zDrawParams.View;
    aParams.List.draw(zDrawParams);
    LiveAdMaker.resizeInterface(null);
    var zSelectedItemId = aParams.List.SelectedItemId;
    if(zSelectedItemId && zDrawParams.ListType == "ActionUI") {
      aParams.List.SelectedItemId = null;
      var zSelectedAction = aParams.List.SelectedAction;
      aParams.List.selectItem(zSelectedItemId, aParams.IsSubItem);
      List.scrollToSelectedItem(aParams.List);
      if(zSelectedAction && zDrawParams.ListType == "ActionUI") {
        aParams.List.SelectedAction = null;
        aParams.List.selectAction({Action: zSelectedAction});
        var zAction = LiveAdMaker.getItemById(aParams.List.Actions, zSelectedAction);
        var zActionParams = {
          Item: aParams.List.SelectedItem,
          ItemId: aParams.List.SelectedItemId,
          Action: zAction,
          ActionId: zSelectedAction,
          Section: aParams.Section,
          SectionId: aParams.SectionId,
          List: aParams.List,
          ContentElement: aParams.List.ContentElement
        };
        List.LightboxView.removeZoom();
        if(zAction.DisplayFunction) {
          zAction.DisplayFunction(zActionParams);
        } else {
          if(zActionParams.Item.ItemPath && zActionParams.Item.ItemPath!="") {
            FormUI.Request.GetForm(zActionParams.Item.ItemPath, 'Form'+zAction, zActionParams.ContentElement);
          }
        }
      }
    }
    if(!aParams.IsSubItem) {
      LiveAdMaker.highlightSelectedView(aParams.ViewName);
    }
    aParams.Section.SelectedView = aParams.ViewName;
    var zCookieName = aParams.CookieName || aParams.SectionId;
    Util.setCookie(zCookieName+"_SelectedView", aParams.ViewName, "NEVER");
    return true;
  },
  highlightSelectedView: function(aViewType){
    aViewType = (aViewType != "Calendar") ? aViewType : "thumbnailAndName";
    DOM.getElementsWithAttribute("ViewType", aViewType, "a", $("TopNavButtonContainer")).forEach(function(aElement){
      DOM.selectElement(aElement, "ActiveButton", $("TopNavButtonContainer"));
    });
    return true;
  },
  highlightSelectedSubItemView: function(aList,aViewType){
    aViewType = (aViewType != "Calendar") ? aViewType : "thumbnailAndName";
    DOM.getElementsWithAttribute("SubViewType", aViewType, "a", aList.NavigationElement).forEach(function(aElement){
      DOM.selectElement(aElement, "ActiveButton", aList.NavigationElement);
    });
    return true;
  },
  resizeContent: function(aContentElement){
    if($("SystemFooterDiv")) {
      aContentElement.style.height = (aContentElement.offsetHeight - $("SystemFooterDiv").offsetHeight) + "px";
    }
    return true;
  },
  SystemType: "LOCAL",
  SystemMode: function() {
    var zStageMode = "N";
    var zDevMode = "N";
    var zSystemMode = "LIVE";
    if (zStageMode == "Y") {
      zSystemMode = "STAGING";
    }
    if (zDevMode == "Y") {
      zSystemMode = "DEV";
    }
    return zSystemMode;
  }(),
  archiveItem: function(aParams, aMoveToPath, aAdditionalPostValues) {
    var zPostValues = {
      aMoveToPath: unescape(aMoveToPath)
    }
    if (aAdditionalPostValues) {
      Util.copyProperties(zPostValues,aAdditionalPostValues)
    }
    if (aMoveToPath) {
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
        Function: LiveAdMaker.receiveArchiveItem,
        Params: aParams,
        PostValues: zPostValues,
        Method:'POST'
      });
    }
    return true
  },
  createNewItem: function(aParams, aMakeRequestItemPath, aNewAlias, aNewName, aObjectType, aAdditionalPostValues, aCreateNewAction) {
    var zSection = aParams.SubSection || aParams.Section;
    var zReceiveFunction = aParams.ReceiveFunction || LiveAdMaker.receiveNewItem;
    var zResetItems = aParams.ResetItems || '';
    var zReceiveFunctionParams = aParams.ReceiveFunctionParams || {Section: zSection, Function: LiveAdMaker.drawSection, ResetItems:zResetItems, Params: aParams};
    var zCreateNewAction = aCreateNewAction || "CreateItem";
    var zPostValues = {
      aObjectTypeAlias: aObjectType,
      aAlias: aNewAlias,
      inpAlias: aNewAlias,
      aName: aNewName,
      inpName: aNewName
    }
    if (aAdditionalPostValues) {
      Util.copyProperties(zPostValues,aAdditionalPostValues)
    }
    Ajax.makeRequest({
      URL: URI.pageURL(unescape(aMakeRequestItemPath), zCreateNewAction, null, true),
      Function: zReceiveFunction,
      Params: zReceiveFunctionParams,
      PostValues: zPostValues,
      Method:'POST'
    });
    return true
  },
  duplicateItem: function(aParams, aCopyToPath, aNewAlias, aNewName, aAdditionalPostValues) {
    var zSection = aParams.SubSection || aParams.Section;
    var zPostValues = {
      aCopyToPath: unescape(aCopyToPath),
      aAlias: aNewAlias,
      aName: aNewName
    }
    if (aAdditionalPostValues) {
      Util.copyProperties(zPostValues,aAdditionalPostValues)
    }
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: zSection, Function: LiveAdMaker.drawSection, Params: aParams},
      PostValues: zPostValues,
      Method:'POST'
    });
    return true
  },
  requestChildNodes: function(aRequestParams, aRequestItemPath, aParentItemPath, aAdditionalPostValues, aReceiveFunction, aDrawFunction) {
    var aParams = aRequestParams.Params || aRequestParams || {};
    aParams.SelectedItem = aRequestParams.ParentItem || aRequestParams.SelectedItem;
    aParams.isChildRequest = "Y";
    aParams.SelectedItem.SubItemsLoaded = "Y";
    if(this.onclickFunctions) {
      this.onclickFunctions = null;
      this.onclick = null;
    }
    var zRequestItemPath = aRequestItemPath || aParams.SelectedItem.ItemPath;
    var zParentItemPath = aParentItemPath || aParams.SelectedItem.ItemPath;
    var zPostValues = {
      aChildRequest: "Y",
      aParentItemPath: zParentItemPath,
      aOwnerObjectCode: aParams.OwnerObjectCode
    }
    if (aAdditionalPostValues) {
      Util.copyProperties(zPostValues,aAdditionalPostValues)
    }
    if (aDrawFunction) {
      var zDrawFunction = aDrawFunction
    } else {
      var zDrawFunction = (!aParams.SubSection) ? LiveAdMaker.drawSection : LiveAdMaker.drawSubItemsList;
    }
    var zReceiveFunction = aReceiveFunction || LiveAdMaker.receiveSectionData;
    Ajax.makeRequest({
      URL: URI.pageURL(zRequestItemPath, "GetList", null, true),
      Function: zReceiveFunction,
      Params: {Section: aParams.Section, Function: zDrawFunction, Params: aParams},
      PostValues: zPostValues,
      Method:'POST'
    });
  },
  showNewBaseItemDialog: function(aParams, aBaseObjectPath, aBaseObjectType, aNewObjectType, aAdditionalUrlParams, aOwnerObjectReference, aGetOwnerObjectReferenceFunction, aFormParams ) {
    var aURLParams                  = { AdditionalUrlParams: aAdditionalUrlParams};
    var zNewBaseItemDialogContainer = DOM.createElement("div","NewBaseItemDialogContainer");
    var zNewBaseItemDialog          = DOM.Dialog.showForm(zNewBaseItemDialogContainer,{position:"absolute",x:300,y:90},"New:",345,135,"CreateNew",aBaseObjectPath,aURLParams,aFormParams);
    zNewBaseItemDialog.returnedForm.NewItemParams               = aParams;
    zNewBaseItemDialog.returnedForm.NewItemParams.NewObjectType = aNewObjectType || "";
    if(aGetOwnerObjectReferenceFunction) {
      zNewBaseItemDialog.returnedForm.NewItemParams.aGetOwnerObjectReferenceFunction = aGetOwnerObjectReferenceFunction;
    } else if(aOwnerObjectReference) {
      zNewBaseItemDialog.returnedForm.NewItemParams.aOwnerObjectReference = aOwnerObjectReference || "";
    }
    zNewBaseItemDialog.returnedForm.NewItemParams.BaseObjectType = aBaseObjectType;
    return true;
  },
  toggleBaseItemType: function(aParams) {
    zElement   = aParams.Element;
    zForm      = zElement.Form;
    zTypeValue = zElement.Value;
    if(zTypeValue&&zTypeValue!="NEWTYPE") {
      FormUI.hide("NewType","FieldId",zForm,{IsRelativeContainer:true});
      FormUI.hide("BasedOn","FieldId",zForm,{IsRelativeContainer:true});
    } else {
      FormUI.show("NewType","FieldId",zForm,{IsRelativeContainer:true});
      FormUI.show("BasedOn","FieldId",zForm,{IsRelativeContainer:true});
    }
    return true;
  },
  createNewBaseItem: function(e, aParams) {
    setTimeout(function() { LiveAdMaker.setTimeoutCreateNewBaseItem(aParams); return true; }, 200);
    return true;
  },
  setTimeoutCreateNewBaseItem: function(aParams) {
    var zElement    = aParams.Element;
    var zForm       = zElement.Form;
    var zParams     = zForm.NewItemParams;
    var zItemPath   = zForm.NewItemParams.SelectedItem.ItemPath;
    var zAlias      = zForm.NewItemParams.BaseObjectType.makeUnique();
    var zName       = zForm.getElement("Name","FieldId").Value;
    var zObjectType = zForm.NewItemParams.NewObjectType ? "Base"+zForm.NewItemParams.NewObjectType : "";
    if(zForm.NewItemParams.aGetOwnerObjectReferenceFunction) {
      var zOwnerObjectData       = eval(zForm.NewItemParams.aGetOwnerObjectReferenceFunction)({ ItemPath: zItemPath, ObjectType: zObjectType, BaseTypePath: zForm.getElement("Type","FieldId").Value });
      var zOwnerObjectReference  = zOwnerObjectData.ObjectReference || "";
      var zOwnerObjectPath       = zOwnerObjectData.ItemPath || "";
      var zOwnerObjectId         = zOwnerObjectData.Id || "";
      var zOwnerObjectNodeParent = zOwnerObjectData.NodeParent || "";
    } else if(zForm.NewItemParams.aOwnerObjectReference) {
      var zOwnerObjectReference  = zForm.NewItemParams.aOwnerObjectReference ? zForm.NewItemParams.aOwnerObjectReference : "";
    }
    var aOwnerObjectReference = zOwnerObjectReference || "";
    var aOwnerObjectPath      = zOwnerObjectPath || "";
    zItemPath                 = aOwnerObjectPath || zItemPath;
    zForm.NewItemParams.SelectedItem.ItemPath   = zItemPath;
    zForm.NewItemParams.SelectedItem.Id         = zOwnerObjectId || zForm.NewItemParams.SelectedItem.Id;
    zForm.NewItemParams.SelectedItem.NodeParent = zOwnerObjectNodeParent || zForm.NewItemParams.SelectedItem.NodeParent;
    var zAdditionalPostValues = {
      aBaseTypePath         : zForm.getElement("Type","FieldId").Value,
      aNewBaseType          : zForm.getElement("NewType","FieldId").Value,
      aBasedOnTypePath      : zForm.getElement("BasedOn","FieldId").Value,
      aNodeParent           : zForm.NewItemParams.SelectedItem.Id,
      aNodeType             : "ChildNode",
      aOwnerObjectReference : aOwnerObjectReference,
      aOwnerObjectPath      : aOwnerObjectPath
    };
    if(aParams.AdditionalPostValues) {
      Util.copyProperties(zAdditionalPostValues, aParams.AdditionalPostValues, true);
    }
    LiveAdMaker.createNewItem(zParams, zItemPath, zAlias, zName, zObjectType, zAdditionalPostValues, "CreateBaseItem");
    DOM.Dialog.hide();
    return true;
  }
};
LiveAdMaker.Home = {
  Name: "Home",
  AreaList: []
,
  SplashSpacerUrl: '\/l.c.bin\/I\/564\/spacer.gif',
  SplashImageUrl: '\/l.c.bin\/F\/3587179\/IntelSplashgif.gif',
  SplashPageWidth: '757',
  SplashPageHeight: '413',
  SplashPageLayout: 'None',
  UseHomepageLayouts: '',
  UseDynamicHomepage: '',
  UseDynamicHomepageLiveWebsite: '',
  Load: function(aParams) {
    var zSplashImageUrl, zSystemType, zUserLanguage, zCollectionObjectReference, zPassLsAccessId, zHomepageInsertionPath;
    zSystemType = LiveAdMaker.SystemType;
    document.body.setAttribute("class", "section-home");
    if (URI.User) {
      zUserLanguage = URI.User.Language;
      zPassLsAccessId = true;
      if (zSystemType == "BRAND") {
        zCollectionObjectReference = "fMain_Object\\ContentList\\DigitalAssetLibrary\\CollectionLibrary\\Sys_Splash_Brand_Logged_In";
        zHomepageInsertionPath = "";
      } else {
          zCollectionObjectReference = "fMain_Object\\ContentList\\DigitalAssetLibrary\\CollectionLibrary\\Sys_Splash_Local_Logged_In";
          zHomepageInsertionPath = "";
      }
    } else {
        zUserLanguage = "en-us";
        zPassLsAccessId = false;
        if (zSystemType == "BRAND") {
          zCollectionObjectReference = "fMain_Object\\ContentList\\DigitalAssetLibrary\\CollectionLibrary\\Sys_Splash_Brand_Not_Logged_In";
          zHomepageInsertionPath = "";
        } else {
            zCollectionObjectReference = "fMain_Object\\ContentList\\DigitalAssetLibrary\\CollectionLibrary\\Sys_Splash_Local_Not_Logged_In";
            zHomepageInsertionPath = "";
        }
    }
    if (LiveAdMaker.Home.UseHomepageLayouts == 'Y') {
      if ($('Content') && zHomepageInsertionPath && !$('Canvas')) {
        var aSettings_Object = {
          ParentContainer: $('Content'),
          ContentURL: URI.pageURL(zHomepageInsertionPath, "ContentJSON", "aObjectTypeAlias=WebsitePage"),
          ColumnCount: 1
        };
        DOM.replaceContent($('Content'));
        var zHomePageLayout_Object =  new LiveGroup.Layout(aSettings_Object);
      }
    } else {
        if (LiveAdMaker.Home.UseDynamicHomepage == "Y") {
          var zContentContainer = $("Content");
          
            if (URI.User) {
              if (URI.User.isFirstLogin) {
                var zDefaultHomepagePath = "";
              }
              else {
                var zDefaultHomepagePath = "";
              }
            }
            else {
              var zDefaultHomepagePath = "";
            }
          
          if(!zDefaultHomepagePath || zDefaultHomepagePath==""){
            var zDefaultHomepagePath = "";
          }
          if (LiveAdMaker.Home.UseDynamicHomepageLiveWebsite == "Y") {
            if (zDefaultHomepagePath != "") {
              var MyHomepage = new LiveWebsite.PageLayout({
                ItemPath: zDefaultHomepagePath,
                PageContainer: zContentContainer,
                OnLoaded: function(){URI.trackLinks(zContentContainer);}
              });
              DOM.replaceContent(zContentContainer, MyHomepage.Website);
              MyHomepage.init();
            }
          } else {
              var zHomepageAdElementPath = "";
              if (zContentContainer && zDefaultHomepagePath && zHomepageAdElementPath) {
                var zHomepage = new LiveAdMaker.Website.Render.DisplayObject({
                  ItemPath:         zDefaultHomepagePath,
                  AdElementPath:    zHomepageAdElementPath
                });
                zHomepage.ParentContainer = zContentContainer;
                DOM.replaceContent(zContentContainer, zHomepage.Container);
                zHomepage.init();            
              }
          }
        } else {
            var zThreadHandler = new Ajax.ThreadHandler( [], 2, null, null, {Params:aParams});
            zThreadHandler.queue({
              URL: URI.pageURL("home", "GetSplashAssets", "aCollectionObjectReference="+escape(zCollectionObjectReference)
                                                        + "&aLanguage="+zUserLanguage
                                                        + "&aOutputType=JSON&aGetTopAssets_AssetType=imagery", zPassLsAccessId),
              Method:"GET",
              Function: LiveAdMaker.Home.drawSplash,
              Params: aParams
            });
        }
    }
    DOM.replaceContent($("SectionTitle"), "");
    DOM.replaceContent($("TopNavSubButtonContainer"), "");
    URI.Track.send("LOCAL.Home");
    return true;
  },
  forgottenPasswordTimer:function() {
    setTimeout(function() { LiveAdMaker.Home.forgottenPasswordForm(); return true; }, 200);
    return true;
  },
  forgottenPasswordForm:function() {
    var zName = document.getElementById('emailforpassword').value
    Ajax.makeRequest({
      URL: "/Home.GetForgottenPassword?aObjectTypeAlias=Userlink&zName="+zName,
      Function: LiveAdMaker.Home.displayPasswordAcknowledgement,
      Method: "GET"
    })
    return true;
  },
  displayPasswordAcknowledgement:function(aData) {
    setTimeout('300');
    var aAnswer = aData.ForgotPasswordText;
    DOM.Dialog.hide();
    var zForgotPassword = "<div style='position: absolute; left: 100px; top: 20px; z-index: 100;'>" + aAnswer + "<span id='btn-ForgottenPasswordButton' class='Button button FormUI-Field FormUI-Field-Button FormUI-ReadOnly' name='btn-ForgottenPasswordButton' OnClick='LiveAdMaker.Home.displayPasswordAcknowledgementRedux();' classname='Button button FormUI-Field FormUI-Field-Button' style='position: absolute; left: 30px; top: 30px; z-index: 100;'>Try Again</span></div>";
    DOM.Dialog.show(zForgotPassword, "center","","400","75");
  },
  displayPasswordAcknowledgementRedux:function() {
    DOM.Dialog.hide();
    var zForgotPassword = '<div><form id=forgottenform><br/><b>Please enter your email address:</b><input type="text" name="emailforpassword" id="emailforpassword"></form><span id="btn-ForgottenPasswordButton" class="Button button FormUI-Field FormUI-Field-Button FormUI-ReadOnly" name="btn-ForgottenPasswordButton" OnClick="LiveAdMaker.Home.forgottenPasswordTimer();" classname="Button button FormUI-Field FormUI-Field-Button" style="position: absolute; left: 125px; top: 50px; z-index: 100;">Send me my password</span></div>';
    DOM.Dialog.show(zForgotPassword, "center","","400","75");
 },
  setCartLink:function(){
    URI.goToHash("Section=CreateAd&Item=Object"+URI.User.LsAccessId+"&ForceSelected=true");
  },
  GetWIPLink:function(){
    Ajax.makeRequest({
      URL: "/Home.GetWIP?aObjectTypeAlias=Userlink",
      Function: LiveAdMaker.Home.SetWIPLink,
      Method: "GET"
    })
  },
  SetWIPLink:function(aData){
    URI.goToHash("Section=CreateAd&Item=Object"+ aData.WIPObjectCode+"&ForceSelected=true");
  },
  drawSplash:function(aResults,aParams) {
    if (aResults.Data.length > 0) {
      LiveAdMaker.Home.SplashImageUrl = aResults.Data[0].SplashUrl;
      LiveAdMaker.Home.SplashPageWidth = aResults.Data[0].SplashWidth;
      LiveAdMaker.Home.SplashPageHeight = aResults.Data[0].SplashHeight;
    }
    var zSSOSplashDiv = $('SSOSplashContainer');
    if ($('Content') && LiveAdMaker.Home.SplashImageUrl && LiveAdMaker.Home.SplashPageLayout != 'None' && !zSSOSplashDiv) {
      DOM.replaceContent($('Content'),DOM.createElement('div','SplashImageContainerDiv','','',''));
      var zSplashContainerDiv = $('SplashImageContainerDiv');
      var zSplashLinkImage = DOM.createElement("img","SplashImage",'','','');
      zSplashLinkImage.setAttribute("src", LiveAdMaker.Home.SplashImageUrl);
      zSplashLinkImage.setAttribute("width", LiveAdMaker.Home.SplashPageWidth);
      zSplashLinkImage.setAttribute("height", LiveAdMaker.Home.SplashPageHeight);
      zSplashContainerDiv.appendChild(zSplashLinkImage);
      var zSplashLinkViewOnlyUrl = '#Section=ViewOnly';
      for (var i=0; i<LiveAdMaker.Home.AreaList.length; i++) {
        var zSplashLinkArea = DOM.createElement('a','SplashLinkArea'+[i],'SplashLinkArea','','');
        var zSplashLinkUrl = LiveAdMaker.Home.AreaList[i].Href;
        DOM.addClass(zSplashLinkArea, 'HomePageSplashLink');
        zSplashLinkArea.style.width = LiveAdMaker.Home.AreaList[i].Width+'px';
        zSplashLinkArea.style.height = LiveAdMaker.Home.AreaList[i].Height+'px';
        zSplashLinkArea.style.top = LiveAdMaker.Home.AreaList[i].Top+'px';
        zSplashLinkArea.style.left = LiveAdMaker.Home.AreaList[i].Left+'px';
        zSplashLinkArea.style.position = 'absolute';
        var zSplashSpacer = DOM.createElement("img","SplashSpacer",'','','');
        zSplashSpacer.setAttribute("src", LiveAdMaker.Home.SplashSpacerUrl);
        zSplashSpacer.style.width = LiveAdMaker.Home.AreaList[i].Width+'px';
        zSplashSpacer.style.height = LiveAdMaker.Home.AreaList[i].Height+'px';
        zSplashSpacer.style.borderStyle = 'none';
        if (URI.User) {
          if (LiveAdMaker.Home.AreaList[i].JsFunc) {
            zSplashLinkArea.setAttribute('href','#');
            DOM.addEvent(zSplashLinkArea,'onclick',eval(zSplashLinkUrl));
          } else {
              zSplashLinkArea.setAttribute('href',zSplashLinkUrl);
          }
          if (LiveAdMaker.Home.AreaList[i].Target) {
            zSplashLinkArea.setAttribute('target','_blank');
          }
        } else {
            zSplashLinkArea.setAttribute('href',zSplashLinkViewOnlyUrl);
        }
        zSplashLinkArea.appendChild(zSplashSpacer);
        zSplashContainerDiv.appendChild(zSplashLinkArea);
      }
      URI.fixLinks();
    } else {
        if (!zSSOSplashDiv) {
          DOM.replaceContent($("Content"));
        }
    }
    if (aParams && URI.User && URI.User.Settings.AutoHelpDisplay == "On")
      AutoHelp.getHelpText(aParams,1);
  }
};
DOM.onLoad(function(){
  URI.startHashCheck(LiveAdMaker.handleUpdatedHash);
  return true;
});
  DOM.onLoad(function(){
    var showBrowserCheckDialog = false;
    var showFlashVersionCheckDialog = false;
    var showCheckDialog = false;
      var preferedBrowser = false;
      var isSupported = false;
      if(DOM.Browser.isFirefox && DOM.Browser.versionMinor >= 2){
        preferedBrowser = true;
      }
      if(DOM.Browser.isIE && DOM.Browser.versionMinor >= 7){
        preferedBrowser = true;
      }
      if(DOM.Browser.isOpera && DOM.Browser.versionMinor >= 8){
        preferedBrowser = true;
      }
      if(DOM.Browser.isSafari && DOM.Browser.versionMinor >= 2){
        preferedBrowser = true;
      }
      var zIgnoreBrowser = (Util.getCookieValue('BDetect') == 'N') ? true : false;
      if(!preferedBrowser && !zIgnoreBrowser) {
        if (DOM.Browser.isIE6x && DOM.Browser.isWin32){
          isSupported = true;
        }
        if(DOM.Browser.isFirefox && DOM.Browser.versionMinor >= 1.5){
          isSupported = true;
        }
        if(DOM.Browser.isSafari && DOM.Browser.versionMinor >= 1.3){
          isSupported = true;
        }
        if(DOM.Browser.isOpera && DOM.Browser.versionMinor >= 7){
          isSupported = true;
        }
        if(DOM.Browser.isNS && DOM.Browser.versionMinor <= 4.7){
          isSupported = false;
        }
        showBrowserCheckDialog = true;
      }else{
        showBrowserCheckDialog = false;
      }
      var zSuggestedBrowserHTML = '<ul><li>Internet Explorer 7 <a href="http://www.microsoft.com/windows/products/winfamily/ie/default.mspx" target="_blank">download</a></li><li>Mozilla Firefox 2 (1.5 minimum) <a href="http://www.getfirefox.com" target="_blank">download</a></li><li>Safari 3 (2 minimum) <a href="http://www.apple.com/safari/download/" target="_blank">download</a></li><li>Opera 9 (8 minimum) <a href="http://www.opera.com/download" target="_blank">download</a></li></ul>';
      var zBrowserCheckMessageContainer = DOM.createElement("div",'BrowserCheckMessageContainer','');
      if (isSupported){
        zBrowserCheckMessageContainer.innerHTML = '<div style="padding-left: 5px;"><b>Although LiveAdMaker will function on your current browser, like all systems it will be significantly faster if you are using the most recent version of your browser.<br>We suggest upgrading to one of the following:</b></div>'+zSuggestedBrowserHTML;
      }
      else {
        zBrowserCheckMessageContainer.innerHTML = '<div style="padding-left: 5px;"><b>You will need to upgrade your web browser to a more recent version in order to use LiveAdMaker.<br> We suggest upgrading to one of the following:</b></div>'+zSuggestedBrowserHTML;
      }
      var isSupportedVersion = false;
      if(DOM.Browser.flashVersion >= 8){
         isSupportedVersion = true;
      }
      var zIgnoreBrowser = (Util.getCookieValue('BDetect') == 'N') ? true : false;
      if (!isSupportedVersion && !zIgnoreBrowser) {
        showFlashVersionCheckDialog = true;
        var zFlashVersionCheckContainer = DOM.createElement("div",'FlashVersionCheckContainer','');
        zFlashVersionCheckContainer.innerHTML = '<div style="padding-left: 5px;margin-top: 15px;margin-bottom: 10px;"><b>LiveAdMaker requires Flash 8 or higher to display dynamic ad previews, which you do not currently have installed.<br> Please visit Adobe to install the latest version of flash:</b><br><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Download Flash 9</a></div>';
      }else{
        showFlashVersionCheckDialog = false;
      }
    if (showBrowserCheckDialog||showFlashVersionCheckDialog){
      var zBrowserCheckContainer = DOM.createElement('div','BrowserCheckContainer','BrowserCheckContainer');
      zBrowserCheckContainer.style.width = '300px';
      zBrowserCheckContainer.style.paddingBottom = '5px';
      if (showBrowserCheckDialog){
        zBrowserCheckContainer.appendChild(zBrowserCheckMessageContainer);
      }
      if (showFlashVersionCheckDialog){
        zBrowserCheckContainer.appendChild(zFlashVersionCheckContainer);
      }
      var zRemindMeButton = DOM.createElement("div", '', 'Button', '');
      zRemindMeButton.innerHTML = 'Close';
      DOM.addEvent(zRemindMeButton, "onclick", function(){
        Util.setCookie('BDetect', 'N', 0);
        DOM.Dialog.hide();
      });
      var zDontRemindButton = DOM.createElement("div", '', 'ButtonV2', '');
      zDontRemindButton.innerHTML = 'Don\'t Remind Me Again';
      DOM.addEvent(zDontRemindButton, "onclick", function(){
        Util.setCookie('BDetect', 'N', "NEVER");
        DOM.Dialog.hide();
      });
      zBrowserCheckContainer.appendChild(zDontRemindButton);
      zBrowserCheckContainer.appendChild(zRemindMeButton);
      DOM.Dialog.show(zBrowserCheckContainer,'center','Please Note','300','300');
    }
  });
DOM.addEvent(window, "onload", function(){
  if($("Content")) {
    $("Content").ResizeSettings = {
      Padding: 5,
      Width: "*",
      Height: "*",
      HideContents: true,
      OnResizeFunction: LiveAdMaker.resizeContent
    }
  }
  DOM.Resize.recurse();
  LiveAdMaker.scheduleResizeInterface();
  return true;
});
    // ---------------------- Begin Action_LiveAdMaker_AdstyleDetail --------------- //
LiveAdMaker.AdStyleDetails = {
  AdStyleDetailsForm: null,
  init:function(aParams){
    LiveAdMaker.AdStyleDetails.Section = aParams.Section;
    LiveAdMaker.AdStyleDetails.CurrentItem = aParams.Item;
    LiveAdMaker.AdStyleDetails.ContentElement = aParams.ContentElement;
    LiveAdMaker.AdStyleDetails.ListParams = aParams;
    LiveAdMaker.AreaLayout.CurrentPage = "1";
    aParams.Section.DetailsV2 = {};
    aParams.Section.DetailsV2.ContentElement = aParams.ContentElement;
    aParams.Section.DetailsV2.CurrentItem=aParams.Item;
    var aFormParams = {OnDisplayFunction: LiveAdMaker.AdStyleDetails.showFormFields}
    var aAdditionalUrlParams = '&aGetForm_ExecuteObjectType=LiveDigitalAsset_AdContent';
    LiveAdMaker.AdStyleDetails.AdStyleDetailsForm = FormUI.Request.getForm(aParams.Item.ItemPath,'AdStyleDetails', aParams.ContentElement,aAdditionalUrlParams,aFormParams);
   LiveAdMaker.AdStyleDetails.drawFlashWireFrame();
   return true;
  },
  drawFlashWireFrame: function (){
    var zImageContainer = DOM.createElement('div','LayoutImageContainer');
    zImageContainer.style.position = "absolute";
    zImageContainer.style.left = "475px";
    LiveAdMaker.AdStyleDetails.ContentElement.appendChild(zImageContainer);
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.AdStyleDetails.CurrentItem.ItemPath, "RequestArea", null, false),
      Function: LiveAdMaker.AreaLayout.SharedFunctions.flashLayout,
      Params: {
        ContentElement: zImageContainer,
        ActiveFunctions: "N",
        ContentFlashFunctions: null
      }
    });
    return true;
  },
  updateWireframe:function (aParams){
    if (aParams.Element.CSVRowNumber == undefined){
      LiveAdMaker.AreaLayout.CurrentPage = "1";
    }else{
      LiveAdMaker.AreaLayout.CurrentPage = aParams.Element.CSVRowNumber;
    }
    setTimeout(function() {
      var zFlashWireFrameContainer = $('LayoutImageContainer');
      zFlashWireFrameContainer.parentNode.removeChild(zFlashWireFrameContainer);
      LiveAdMaker.AdStyleDetails.drawFlashWireFrame();
    }, 500);
    return true;
  },
  showFormFields:function (aParams){
    var AdStyleDetailsForm = LiveAdMaker.AdStyleDetails.AdStyleDetailsForm;
    AdStyleDetailsForm.ElementArray.forEach(function(aElement){
      switch (aElement.SeqNo) {
        case 2 :
          if (aElement.DisplayValue == "2D Layout" || aElement.DisplayValue == "HTML"){
            var zElement_Language = AdStyleDetailsForm.ElementArray.get('AdStyleLanguage','FieldId');
            $("FormUI-RelativeContainer-"+zElement_Language[0].ElementId).style.marginTop="80px";
          }else{
          }
        break;
        default:
      }
    });
    return true;
  }
};
LiveAdMaker.AdStyleDetails.SharedFunctions = {
  setDimensionDisplay:function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath,'SetDimensions'),
      Function: LiveAdMaker.AdStyleDetails.SharedFunctions.setDimensionDisplayComplete,
      PostValues:{
        aConvertTo: aParams.Element.Value
      },
      Method:'POST'
    });
    return true;
  },
  setDimensionDisplayComplete:function (aTempPageList){
    aTempPageList.TempPageListArray.forEach(function(aPage){
      FormUI.ElementArray.forEach(function(aElement){
        if (aElement.CSVRowNumber == aPage.PageNumber){
          if (aElement.CSVColumnId =="DisplayWidth"){
            $(aElement.ElementId).innerHTML = aPage.DisplayWidth;
            $(aElement.ElementId).Value = aPage.DisplayWidth;
            aElement.Value = aPage.DisplayWidth;
          }
          if (aElement.CSVColumnId =="DisplayHeight"){
            $(aElement.ElementId).innerHTML = aPage.DisplayHeight;
            aElement.Value = aPage.DisplayHeight;
          }
        }
        if (aElement.CSVValue =="DisplayWidth"){
          $(aElement.ElementId).innerHTML = aPage.DisplayWidth;
          $(aElement.ElementId).Value = aPage.DisplayWidth;
          aElement.Value = aPage.DisplayWidth;
        }
        if (aElement.CSVValue =="DisplayHeight"){
          $(aElement.ElementId).innerHTML = aPage.DisplayHeight;
          aElement.Value = aPage.DisplayHeight;
        }
      });
    });
    return true;
  },
  setDPIValue:function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath,'SetDPI'),
      Function: LiveAdMaker.AdStyleDetails.SharedFunctions.setDPIValueComplete,
      PostValues:{
        aNewDPIValue: aParams.Element.Value,
        aOldDPIValue: aParams.Original
      },
      Method:'POST'
    });
    return true;
  },
  setDPIValueComplete:function (aTempPageList){
    if (aTempPageList.updateDisplay =="Y"){
      aTempPageList.TempPageListArray.forEach(function(aPage){
        FormUI.ElementArray.forEach(function(aElement){
          if (aElement.CSVRowNumber == aPage.PageNumber){
            if (aElement.CSVColumnId =="DisplayWidth"){
              $(aElement.ElementId).innerHTML = aPage.DisplayWidth;
              $(aElement.ElementId).Value = aPage.DisplayWidth;
              aElement.Value = aPage.DisplayWidth;
            }
            if (aElement.CSVColumnId =="DisplayHeight"){
              $(aElement.ElementId).innerHTML = aPage.DisplayHeight;
              aElement.Value = aPage.DisplayHeight;
            }
          }
          if (aElement.CSVValue =="DisplayWidth"){
            $(aElement.ElementId).innerHTML = aPage.DisplayWidth;
            $(aElement.ElementId).Value = aPage.DisplayWidth;
            aElement.Value = aPage.DisplayWidth;
          }
          if (aElement.CSVValue =="DisplayHeight"){
            $(aElement.ElementId).innerHTML = aPage.DisplayHeight;
            aElement.Value = aPage.DisplayHeight;
          }
        });
      });
    }
    setTimeout(function() {
      var zFlashWireFrameContainer = $('LayoutImageContainer');
      zFlashWireFrameContainer.parentNode.removeChild(zFlashWireFrameContainer);
      LiveAdMaker.AreaLayout.CurrentPage = "1";
      LiveAdMaker.AdStyleDetails.drawFlashWireFrame();
    }, 500);
    return true;
  }
}
    // ---------------------- End Action_LiveAdMaker_AdstyleDetail ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_AdstyleLayout --------------- //
LiveAdMaker.AreaLayout = {
  init:function(aParams,aAdStyleType){
  LiveAdMaker.AreaLayout.Section = aParams.Section;
    LiveAdMaker.AreaLayout.ListParams = aParams;
    LiveAdMaker.AreaLayout.CurrentAdStyle = aParams.Item;
    LiveAdMaker.AreaLayout.AdStyleType = aAdStyleType;
    if (LiveAdMaker.AreaLayout.AdStyleType == "Layouts"){
      LiveAdMaker.AreaLayout.ObjectTypeToUse = "Layout";
    }else{
      LiveAdMaker.AreaLayout.ObjectTypeToUse = "AdElements";
    }
    LiveAdMaker.AreaLayout.CurrentPage = "1";
    aParams.Section.LayoutV2 = {
      createNewItem: function(aParams) {
        Ajax.makeRequest({
          URL: URI.pageURL(LiveAdMaker.AreaLayout.CurrentAdStyle.ItemPath, "CreateNewAreaV2", null, true),
          Function: LiveAdMaker.receiveNewItem,
          Params: {Section: LiveAdMaker.AreaLayout.AdStyleType, Function:LiveAdMaker.drawSection,Params:aParams},
          PostValues:{
            aObjectTypeAlias: LiveAdMaker.AreaLayout.ObjectTypeToUse,
            aAlias:"Layouts".makeUnique(),
            aName:"Layouts "+LiveAdMaker.SelectedSection.Items.length,
            aCategory: "Imagery",
            aDislayName: "TempArea 1",
            aId: "Area".makeUnique(),
            aPageNumber: LiveAdMaker.AreaLayout.CurrentPage
          },
          Method:'POST'
        });
        return true;
      },
      archiveItem:function(aParams){
        var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
        Ajax.makeRequest({
          URL: URI.pageURL(zSelectedItem.ItemPath, "ArchiveAreaV2", null, true),
          Function: LiveAdMaker.receiveArchiveItem,
          Params: aParams,
          PostValues:{
            aAreaId: aParams.SelectedItem.Id,
            aAreaAlias: aParams.SelectedItem.AreaAlias
          },
          Method:'POST'
        });
      },
      duplicateItem: function(aParams) {
        var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
        Ajax.makeRequest({
          URL: URI.pageURL(zSelectedItem.ItemPath, "DuplicateAreaV2", null, true),
          Function: LiveAdMaker.receiveNewItem,
          Params: {Section: LiveAdMaker.AreaLayout.AdStyleType, Function: LiveAdMaker.drawSection, Params: aParams},
          PostValues: {
            aAreaId: aParams.SelectedItem.Id,
            aNewAreaId: "Area".makeUnique(),
            aDisplayName: "Copy of "+aParams.SelectedItem.DisplayName
          },
          Method:'POST'
        });
      }
    };
    aParams.Section.LayoutV2.ContentElement = aParams.ContentElement;
    aParams.Section.LayoutV2.CurrentItem=aParams.Item;
    aParams.Section.LayoutV2.ListParams = aParams;
    aParams.Section.LayoutV2.SubSection = {};
   if (LiveAdMaker.AreaLayout.AdStyleType == "Layouts"){
       aParams.Section.LayoutV2.DrawTimeLine = "Y";
      }
    LiveAdMaker.AreaLayout.getAreas(aParams,"1");
    return true;
  },
  getAreas: function(aParams,aSelectedPage) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "RequestArea", null, false),
      Function: LiveAdMaker.AreaLayout.receiveAreas,
      Params: {Params: aParams, SelectedPage: aSelectedPage}
    });
    return true;
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        LiveAdMaker.AreaLayout.Details.init(aParams);
        return true;
      }
    }
  ],
  receiveAreas: function (aAreas,aParams) {
    var SelectedPageAreaItems = new Array();
    aAreas.AreaItems.forEach(function(zArea){
      if (zArea.PageNumber == aParams.SelectedPage){
        SelectedPageAreaItems.push(zArea);
      }
      if (zArea.PageNumber == 0){
        SelectedPageAreaItems.push(zArea);
      }
    });
    if (aAreas.IsSequence =="Y"){
      aAreas.PageArray.forEach(function(zPage){
        if (zPage.PageNumber == aParams.SelectedPage){
          SelectedPageAreaItems.push(zPage);
        }
      });
    }
    if(!LiveAdMaker.AreaLayout.AreaList) {
      aParams.Params.Section.ItemPath = aAreas.ItemPath;
      LiveAdMaker.AreaLayout.ItemPath = aAreas.ItemPath;
      if (LiveAdMaker.AreaLayout.AdStyleType == "Layouts"){
        if (LiveAdMaker.Layouts.LayoutV2.DrawTimeLine == "Y"){
          LiveAdMaker.AreaLayout.TimeLine.drawTimeLine(aAreas,aParams);
        }
      }
      var zInnerBubbleContainer= DOM.createElement('div','InnerBubbleContainer');
      if (LiveAdMaker.AreaLayout.AdStyleType == "Layouts"){
        switch (aAreas.BackgroundCount) {
          case "" :
            zInnerBubbleContainer.ResizeSettings ={Height: -60}
          break;
          case "1" :
            zInnerBubbleContainer.ResizeSettings ={Height: -85}
          break;
          case "2" :
            zInnerBubbleContainer.ResizeSettings ={Height: -105}
          break;
          case "3" :
            zInnerBubbleContainer.ResizeSettings ={Height: -125}
          break;
          default:
        }
      }else{
        zInnerBubbleContainer.ResizeSettings ={Height: -5}
      }
      aParams.Params.Section.LayoutV2.ContentElement.appendChild(zInnerBubbleContainer);
      if (LiveAdMaker.AreaLayout.CurrentItem != undefined){
        var SelectedSubItem = LiveAdMaker.getItemById(SelectedPageAreaItems,LiveAdMaker.AreaLayout.CurrentItem.ItemId);
      }else{
        if (SelectedSubItem == null){
          var SelectedSubItem = SelectedPageAreaItems[0];
          LiveAdMaker.AreaLayout.CurrentItem = SelectedPageAreaItems[0];
        }
      }
      if (SelectedSubItem == null){
        var SelectedSubItem = LiveAdMaker.getItemById(aAreas.PageArray,LiveAdMaker.AreaLayout.CurrentItem.ItemId);
      }
      if (SelectedSubItem == null){
        var SelectedSubItem = SelectedPageAreaItems[0];
        LiveAdMaker.AreaLayout.CurrentItem = SelectedPageAreaItems[0];
      }
      var zDrawParams = {
        Section: aParams.Params.SectionId,
        SubSection: "LayoutV2",
        ItemId: aParams.Params.ItemId,
        ListType: "ActionUI",
        Fields: aAreas.Fields,
        SelectedArea: SelectedSubItem.Id,
        SelectedPage: aParams.SelectedPage,
        View: "subitem",
        ParentElement: zInnerBubbleContainer,
        Action: aParams.Params.ActionId,
        Id: "AreaList",
        ItemArray: SelectedPageAreaItems,
        Actions: LiveAdMaker.AreaLayout.Actions,
        Sortable: true,
        ShowNavigation: true,
        OnSortCompleteFunction: LiveAdMaker.AreaLayout.sortItems,
        SearchObjectItemPath: aParams.Params.Item.ItemPath
      };
      var zSubItemList = new List(zDrawParams);
      zSubItemList.draw(zDrawParams);
      aParams.Params.Section.LayoutV2.SubItemList = zSubItemList;
      LiveAdMaker.AreaLayout.SubItemList = zSubItemList;
      zSubItemList.selectItem(SelectedSubItem.Id, true);
      zSubItemList.selectAction({Action:zSubItemList.Actions[0].Id});
      LiveAdMaker.highlightSelectedSubItemView(zSubItemList, "ActionsWithName");
      LiveAdMaker.resizeInterface(null);
      var zActionParams = {
        Item: SelectedSubItem,
        ItemId: SelectedSubItem.Id,
        Action: zSubItemList.Actions[0],
        ActionId: zSubItemList.Actions[0].Id,
        Section: aParams.Params.Section,
        SectionId: aParams.Params.SectionId,
        List: zSubItemList,
        ContentElement: zSubItemList.ContentElement
      };
      if(zSubItemList.Actions[0].DisplayFunction) {
        zSubItemList.Actions[0].DisplayFunction(zActionParams);
      }
      else {
        FormUI.Request.getForm(zActionParams.Item.ItemPath, 'Form'+zSubItemList.Actions[0].Id, zActionParams.ContentElement);
      }
    }
    return true;
  },
  sortItems: function(aNewItemArray,aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zSortAction = "SortCurrentAreas";
    var zAreaArray = [];
    aNewItemArray.forEach(function(aItem){
      if (aItem.Category != undefined){
        zAreaArray.push(aItem.Id);
      }
    });
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, zSortAction),
      Function: function(){return true;},
      Method: "POST",
      PostValues: {aItems: zAreaArray.join(";")}
    });
    setTimeout(function() {
      Ajax.makeRequest({
        URL: URI.pageURL(zSelectedItem.ItemPath, "RequestArea", "aSize=500", false),
        Function: LiveAdMaker.AreaLayout.SharedFunctions.flashLayout,
        Params: {
          ContentElement: $('LayoutImageContainer'),
          Section: LiveAdMaker.AreaLayout.AdStyleType,
          Action: "LayoutV2",
          SelectedPage: LiveAdMaker.AreaLayout.CurrentPage,
          SelectedArea: aParams.SelectedArea
        }
      });
    }, 700);
    return true;
  }
};
LiveAdMaker.AreaLayout.TimeLine ={
  showOptions: function (e,aParams){
    var zOptionsContainer = DOM.createElement('div','OptionContainer');
    var zEditSegmentLink = DOM.createElement('div','','OptionLinkContainer');
    zEditSegmentLink.innerHTML = "Edit";
    zOptionsContainer.appendChild(zEditSegmentLink);
    DOM.addEvent(zEditSegmentLink,"onclick",LiveAdMaker.AreaLayout.TimeLine.loadCurrentPage,{CurrentPage: aParams.CurrentPage, TotalPages: aParams.TotalPages});
    var zNewLink = DOM.createElement('div','','OptionLinkContainer');
    zNewLink.innerHTML = "New";
    zOptionsContainer.appendChild(zNewLink);
    DOM.addEvent(zNewLink,"onclick",LiveAdMaker.AreaLayout.TimeLine.addPage,{TotalPages: aParams.TotalPages});
    var zDuplicateLink = DOM.createElement('div','','OptionLinkContainer');
    zDuplicateLink.innerHTML = "Duplicate";
    zOptionsContainer.appendChild(zDuplicateLink);
    DOM.addEvent(zDuplicateLink,"onclick",LiveAdMaker.AreaLayout.TimeLine.duplicatePage,{CurrentPage: aParams.CurrentPage, TotalPages: aParams.TotalPages});
    if (aParams.TotalPages != "1"){
      var zRemoveLink = DOM.createElement('div','','OptionLinkContainer');
      zRemoveLink.innerHTML = "Remove";
      zOptionsContainer.appendChild(zRemoveLink);
      DOM.addEvent(zRemoveLink,"onclick",LiveAdMaker.AreaLayout.TimeLine.removePage,{CurrentPage: aParams.CurrentPage, TotalPages: aParams.TotalPages});
    }
    DOM.Dialog.show(zOptionsContainer,e);
    return true;
  },
  loadCurrentPage: function(e,aParams){
    DOM.Dialog.hide();
    var zInnerBubbleReference = $("InnerBubbleContainer");
    zInnerBubbleReference.parentNode.removeChild(zInnerBubbleReference);
    var zTimeLineReference = $("TimeLineContainer");
    zTimeLineReference.parentNode.removeChild(zTimeLineReference);
    LiveAdMaker.AreaLayout.CurrentPage = aParams.CurrentPage;
    LiveAdMaker.AreaLayout.getAreas(LiveAdMaker.AreaLayout.ListParams,aParams.CurrentPage);
  },
  addPage:function (e,aParams){
    DOM.Dialog.hide();
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zNextPageCount = parseInt(aParams.TotalPages) + parseInt("1");
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "AddNewLayoutPage", null, true),
      Function: LiveAdMaker.AreaLayout.TimeLine.updateLayoutDetailsTab,
      PostValues: {aNextPage: zNextPageCount},
      Method:'POST'
    });
    return true;
  },
  duplicatePage:function (e,aParams){
    DOM.Dialog.hide();
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zNextPageCount = parseInt(aParams.TotalPages) + parseInt("1");
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "DuplicateNewLayoutPage", null, true),
      Function: LiveAdMaker.AreaLayout.TimeLine.updateLayoutDetailsTab,
      PostValues: {aCurrentPage: aParams.CurrentPage,aNextPage: zNextPageCount},
      Method:'POST'
    });
    return true;
  },
  removePage:function (e,aParams){
    DOM.Dialog.hide();
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zCurrentPage = aParams.CurrentPage;
    var zNextPageCount = "1";
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "RemoveNewLayoutPage", null, true),
      Function: LiveAdMaker.AreaLayout.TimeLine.updateLayoutDetailsTab,
      PostValues: {aRemovePage: zCurrentPage,aNextPage: zNextPageCount},
      Method:'POST'
    });
    return true;
  },
  updateLayoutDetailsTab:function (aParams){
    if (aParams.Status == "Success"){
      var zInnerBubbleReference = $("InnerBubbleContainer");
      zInnerBubbleReference.parentNode.removeChild(zInnerBubbleReference);
      var zTimeLineReference = $("TimeLineContainer");
      zTimeLineReference.parentNode.removeChild(zTimeLineReference);
      LiveAdMaker.AreaLayout.CurrentPage = aParams.CurrentPage;
      LiveAdMaker.AreaLayout.getAreas(LiveAdMaker.AreaLayout.ListParams,aParams.NextPage);
    }
    return true;
  },
  drawTimeLine: function (aAreas,aParams) {
    if (aAreas.IsSequence =="Y"){
      var zPageName="Scene"
      var zTotalDuration= aAreas.TotalDuration;
    }else{
      var zPageName="Page"
    }
    var zTimeLineContainer= DOM.createElement('div','TimeLineContainer');
    switch (aAreas.BackgroundCount) {
      case "" :
        zTimeLineContainer.style.height = "60px";
        break;
      case "1" :
        zTimeLineContainer.style.height = "85px";
        break;
      case "2" :
        zTimeLineContainer.style.height = "105px";
        break;
      case "3" :
        zTimeLineContainer.style.height ="125px";
        break;
      default:
    }
    var zAddPageContainer= DOM.createElement('div','AddPageContainer');
    if (zTotalDuration){
      var zAddMorePages = DOM.createActionElement('h1', LiveAdMaker.AreaLayout.TimeLine.addPage, zPageName+'s ('+(parseInt(zTotalDuration)/1000)+'s)', {TotalPages:aAreas.PageArray.length});
    }else{
      var zAddMorePages = DOM.createActionElement('h1', LiveAdMaker.AreaLayout.TimeLine.addPage, zPageName+'s', {TotalPages:aAreas.PageArray.length});
    }
    zAddPageContainer.appendChild(zAddMorePages);
    var zCurrentAdStylePageContainer = DOM.createElement('div','CurrentAdStylePageContainer');
    var zCurrentAvailableWidth = parseInt(aParams.Params.Section.LayoutV2.ContentElement.style.width) - parseInt("200");
    var zTotalSceneDuration = parseInt(aAreas.TotalDuration)/1000;
    var zMultiplierDuration = parseInt(zCurrentAvailableWidth)/parseInt(zTotalSceneDuration);
    aAreas.PageArray.forEach(function(aPage){
      var zPageWidth=100;
      var zPageContainer = DOM.createElement("div","PageSelection_"+aPage.PageNumber,"PageSelection");
      var zPageDisplayContainer = DOM.createElement("div","","PageNameDisplay");
      if (aPage.PageNumber == aParams.SelectedPage){
        zPageContainer.style.backgroundColor = "#a8a8a8";
        zPageDisplayContainer.style.color = "#3860a4";
      }
      if (aAreas.IsSequence =="Y"){
        var zSceneDuration = (parseInt(aPage.Duration)/1000);
        zPageDisplayContainer.innerHTML= zSceneDuration+'s';
      }else{
        zPageDisplayContainer.innerHTML=aPage.DisplayName;
      }
      zPageContainer.appendChild(zPageDisplayContainer);
      zCurrentAdStylePageContainer.appendChild(zPageContainer);
      DOM.addEvent(zPageContainer,"onclick",LiveAdMaker.AreaLayout.TimeLine.showOptions,{CurrentPage: aPage.PageNumber, TotalPages: aAreas.PageArray.length, IncrementPage: "Y"});
      if (aAreas.IsSequence =="Y"){
        var zNewSceneWidth = parseInt(zSceneDuration) * parseInt(zMultiplierDuration);
        zPageContainer.style.width = zNewSceneWidth+"px";
      }else{
        var zNewPageWidth = parseInt(zCurrentAvailableWidth) / parseInt(aAreas.PageCount);
        zPageContainer.style.width = zNewPageWidth+"px";
      }
    });
    var zBGAreaContainer = DOM.createElement('div','BackgroundAreaPageContainer');
    aAreas.AreaArray.forEach(function(aArea){
      if (aArea.PageNumber == "0"){
        var zBGArea= DOM.createElement('div','',"BackgroundContainers");
        var zEnableDisableBG = DOM.createActionElement('div', "", aArea.DisplayName,"");
        DOM.addClass(zEnableDisableBG, 'BGNameContainer');
        var zBGDisplayContainer = DOM.createElement("div","BGArea_"+aArea.Id,"BGSelection");
        zBGArea.appendChild(zEnableDisableBG);
        zBGArea.appendChild(zBGDisplayContainer);
        zBGAreaContainer.appendChild(zBGArea);
      }
    });
    zTimeLineContainer.appendChild(zAddPageContainer);
    zTimeLineContainer.appendChild(zCurrentAdStylePageContainer);
    zTimeLineContainer.appendChild(zBGAreaContainer);
    aParams.Params.Section.LayoutV2.ContentElement.appendChild(zTimeLineContainer);
    return true;
  }
}
LiveAdMaker.AreaLayout.Details = {
 AreaLayoutDetailsForm: null,
  init: function(aParams) {
   LiveAdMaker.AreaLayout.CurrentItem = aParams;
   if (aParams.Item.Id == "PageInput"+aParams.Item.PageNumber){
     var aAdditionalUrlParams = '&aRowId='+aParams.Item.Id+'&aCurrentPageNumber='+aParams.Item.PageNumber+'&aGetForm_ExecuteObjectType=LiveDigitalAsset_AdContent';
     FormUI.Request.getForm(LiveAdMaker.AreaLayout.ItemPath,'ScenePageDetails', aParams.ContentElement,aAdditionalUrlParams);
   }else{
      var aAdditionalUrlParams = '&aRowId='+aParams.Item.Id+'&aCurrentPageNumber='+aParams.Item.PageNumber+'&aGetForm_ExecuteObjectType=LiveDigitalAsset_AdContent';
      LiveAdMaker.AreaLayout.Details.AreaLayoutDetailsForm = FormUI.Request.getForm(LiveAdMaker.AreaLayout.ItemPath,'LayoutDetails', aParams.ContentElement,aAdditionalUrlParams);
      var zImageContainer = DOM.createElement('div','LayoutImageContainer');
      zImageContainer.style.position = "absolute";
      zImageContainer.style.left = "325px";
      aParams.ContentElement.appendChild(zImageContainer);
      Ajax.makeRequest({
        URL: URI.pageURL(LiveAdMaker.AreaLayout.ItemPath, "RequestArea", "aSize=500", false),
        Function: LiveAdMaker.AreaLayout.SharedFunctions.flashLayout,
        Params: {
          ContentElement: zImageContainer,
          Section: LiveAdMaker.AreaLayout.AdStyleType,
          Action: "LayoutV2",
          SelectedPage: aParams.Item.PageNumber,
          SelectedArea: aParams.Item.Id,
          Customizable: false
        }
      });
    }
    return true;
  }
}
LiveAdMaker.AreaLayout.SharedFunctions = {
  flashLayout: function(aLayout, aParams){
    LiveAdMaker.AreaLayout.SectionName = aParams.Section;
    LiveAdMaker.AreaLayout.ActionName = aParams.Action;
    var zLayoutContainerDiv = DOM.createElement('div');
    DOM.replaceContent(aParams.ContentElement,zLayoutContainerDiv);
    if (aParams.ActiveFunctions != "N"){
      var AdditionalFlashParams = {
        OnAreaSelectedFunction: LiveAdMaker.AreaLayout.SharedFunctions.flashAreaSelected,
        OnValueUpdatedFunction: LiveAdMaker.AreaLayout.SharedFunctions.flashValueUpdated,
        OnPageChangeFunction: LiveAdMaker.AreaLayout.SharedFunctions.flashPageChanged,
        OnAreaChangeFunction: LiveAdMaker.AreaLayout.SharedFunctions.flashAreaChanged,
        SelectedPageId: "PageInput"+aParams.SelectedPage,
        SelectedAreaId: aParams.SelectedArea
      }
    }else{
      var AdditionalFlashParams = aParams.ContentFlashFunctions;
    }
    var aFlashId = "LayoutFlash";
    aParams.ContentElement.ResizeSettings = aParams.ContentElement.ResizeSettings || {Width: "*", Height: "*"};
    zLayoutContainerDiv.style.width = "100%";
    zLayoutContainerDiv.style.height = "100%";
    LiveAdMaker.AreaLayout.Wireframe = Layout.FlashPreview.create(zLayoutContainerDiv,aFlashId,aLayout.PageArray,aLayout.AreaArray,"400","500","300",null,null,AdditionalFlashParams);
    DOM.Resize.recurse(aParams.ContentElement);
    return true;
  },
  flashPageChanged: function (aPageId){
    return true;
  },
  flashAreaChanged: function (aAreaObject){
    return true;
  },
  flashAreaSelected:function (aPageId, aAreaId, aFlashObject){
    return true;
  },
  flashValueUpdated:function(aNewValue){
    return true;
  },
  reloadWireframe: function(aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var getPageNumberArray= aParams.Element.Field.split("_");
    setTimeout(function() {
      Ajax.makeRequest({
        URL: URI.pageURL(zSelectedItem.ItemPath, "RequestArea", null, false),
        Function: LiveAdMaker.AreaLayout.SharedFunctions.flashLayout,
        Params: {
          ContentElement: $('LayoutImageContainer'),
          Section: LiveAdMaker.AreaLayout.AdStyleType,
          Action: "Layout",
          SelectedPage: getPageNumberArray[1],
          SelectedArea: aParams.Element.CSVRowId
       }
      });
    }, 700);
    return true;
  },
  updateFlashArea:function(aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "GetAreaValues", null, true),
      Function: LiveAdMaker.AreaLayout.SharedFunctions.updateFlashAreaCallBak,
      PostValues: {
        aCSVRowId: aParams.Element.CSVRowId,
        aAreaTitle: aParams.Element.FieldId
      },
      Method:'POST'
    });
    return true;
  },
  updateFlashAreaCallBak: function(aParams){
    Layout.FlashPreview.updateArea(aParams.AreaId, aParams.AreaFieldId, aParams.AreaValue);
    return true;
  },
  updateAreaDisplayName: function(aParams) {
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zInnerBubbleReference = $("InnerBubbleContainer");
    zInnerBubbleReference.parentNode.removeChild(zInnerBubbleReference);
    if (LiveAdMaker.AreaLayout.AdStyleType =="Layouts"){
      var zTimeLineReference = $("TimeLineContainer");
      zTimeLineReference.parentNode.removeChild(zTimeLineReference);
    }
    var getPageNumberArray= aParams.Element.Field.split("_");
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "RequestArea", "aSize=500", false),
      Function: LiveAdMaker.AreaLayout.SharedFunctions.updateAreaDisplayNameComplete,
      Params: {
        Params: aParams,
        SelectedArea: aParams.Element.CSVRowId,
        SelectedPage:  getPageNumberArray[1]
     }
    });
  },
  updateAreaDisplayNameComplete: function(aAreas,aParams){
    var SelectedPageAreaItems = new Array();
    aAreas.AreaItems.forEach(function(zArea){
      if (zArea.PageNumber == aParams.SelectedPage){
        SelectedPageAreaItems.push(zArea);
      }
    });
    if (aAreas.IsSequence =="Y"){
      aAreas.PageArray.forEach(function(zPage){
        if (zPage.PageNumber == aParams.SelectedPage){
          SelectedPageAreaItems.push(zPage);
        }
      });
    }
    var SelectedSubItem = LiveAdMaker.getItemById(SelectedPageAreaItems,aParams.SelectedArea);
    if (LiveAdMaker.AreaLayout.AdStyleType == "Layouts"){
      LiveAdMaker.Layouts.LayoutV2.ListParams.SubItem = SelectedSubItem;
      LiveAdMaker.Layouts.LayoutV2.DrawTimeLine = "Y";
      LiveAdMaker.AreaLayout.getAreas(LiveAdMaker.Layouts.LayoutV2.ListParams,aParams.SelectedPage);
    }else{
      LiveAdMaker.AdElements.LayoutV2.ListParams.SubItem = SelectedSubItem;
      LiveAdMaker.AreaLayout.getAreas(LiveAdMaker.AdElements.LayoutV2.ListParams,aParams.SelectedPage);
    }
  }
}
    // ---------------------- End Action_LiveAdMaker_AdstyleLayout ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_AdstyleContent --------------- //
LiveAdMaker.AreaContent = {
  init:function(aParams,aAdStyleType){
    LiveAdMaker.AreaContent.Section = aParams.Section;
    LiveAdMaker.AreaLayout.AdStyleType = aAdStyleType;
    LiveAdMaker.AreaContent.ListParams = aParams;
    aParams.Section.ContentV2 = {};
    aParams.Section.ContentV2.ContentElement = aParams.ContentElement;
    aParams.Section.ContentV2.CurrentItem=aParams.Item;
    aParams.Section.ContentV2.ListParams = aParams;
    aParams.Section.ContentV2.SubSection = {};
    LiveAdMaker.AreaContent.getContentV2(aParams);
    return true;
  },
  getContentV2: function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetContentAreas", null, false),
      Function: LiveAdMaker.AreaContent.receiveContentV2,
      Params: {Params: aParams}
    });
    return true;
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        LiveAdMaker.AreaContent.Details.init(aParams);
        return true;
      }
    }
  ],
  receiveContentV2: function (aAreas,aParams) {
    if(!LiveAdMaker.AreaContent.ContentList) {
      aParams.Params.Section.ItemPath = aAreas.ItemPath;
      LiveAdMaker.AreaContent.ItemPath = aAreas.ItemPath;
      if (LiveAdMaker.AreaContent.CurrentItem != undefined){
        var SelectedSubItem = LiveAdMaker.getItemById(aAreas.Items,LiveAdMaker.AreaContent.CurrentItem.ItemId);
      }else{
        if (SelectedSubItem == null){
          var SelectedSubItem = aAreas.Items[0];
          LiveAdMaker.AreaContent.CurrentItem = aAreas.Items[0];
        }
      }
      if (SelectedSubItem == null){
        var SelectedSubItem = aAreas.Items[0];
        LiveAdMaker.AreaContent.CurrentItem = aAreas.Items[0];
      }
      var zInnerBubbleContainer= DOM.createElement('div','InnerBubbleContainer');
      if (LiveAdMaker.AreaLayout.AdStyleType =="CampaignSetup"){
        LiveAdMaker.AreaContent.TimeLine.drawContentTimeLine(aAreas,aParams);
        zInnerBubbleContainer.ResizeSettings ={Height: -45}
      }else{
        zInnerBubbleContainer.ResizeSettings ={Height: -1}
      }
      aParams.Params.Section.ContentV2.ContentElement.appendChild(zInnerBubbleContainer);
      var zDrawParams = {
        Section: aParams.Params.SectionId,
        SubSection: "ContentV2",
        ItemId: aParams.Params.ItemId,
        ListType: "ActionUI",
        Fields: aAreas.Fields,
        View: "subitem",
        ParentElement: zInnerBubbleContainer,
        Action: aParams.Params.ActionId,
        Id: "ContentListV2",
        ItemArray: aAreas.Items,
        Actions: LiveAdMaker.AreaContent.Actions,
        Sortable: true,
        OnSortCompleteFunction: LiveAdMaker.AreaContent.sortItems,
        SearchObjectItemPath: aParams.Params.Item.ItemPath
      };
      var zSubItemList = new List(zDrawParams);
      zSubItemList.draw(zDrawParams);
      aParams.Params.Section.ContentV2.SubItemList = zSubItemList;
      LiveAdMaker.AreaContent.SubItemList = zSubItemList;
      zSubItemList.selectItem(SelectedSubItem.Id, true);
      zSubItemList.selectAction({Action:zSubItemList.Actions[0].Id});
      LiveAdMaker.resizeInterface(null);
      var zActionParams = {
        Item: SelectedSubItem,
        ItemId: SelectedSubItem.Id,
        Action: zSubItemList.Actions[0],
        ActionId: zSubItemList.Actions[0].Id,
        Section: aParams.Params.Section,
        SectionId: aParams.Params.SectionId,
        List: zSubItemList,
        ContentElement: zSubItemList.ContentElement
      };
      if(zSubItemList.Actions[0].DisplayFunction) {
        zSubItemList.Actions[0].DisplayFunction(zActionParams);
      }
      else {
        FormUI.Request.getForm(zActionParams.Item.ItemPath, 'Form'+zSubItemList.Actions[0].Id, zActionParams.ContentElement);
      }
    }
    return true;
  },
  sortItems: function(aNewItemArray,aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zSortAction = "SortContentItems";
    var zAreaArray = [];
    aNewItemArray.forEach(function(aItem){
      zAreaArray.push(aItem.Id);
    });
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, zSortAction),
      Function: function(){return true;},
      Method: "POST",
      PostValues: {aItems: zAreaArray.join(";")}
    });
    return true;
  }
};
LiveAdMaker.AreaContent.TimeLine ={
  drawContentTimeLine: function (aAreas,aParams) {
    var zTimeLineContainer= DOM.createElement('div','ContentTimeLineContainer');
    zTimeLineContainer.style.height = "45px";
    var zUpdateContainer= DOM.createElement('div','UpdateButtonContainer');
    DOM.addClass(zUpdateContainer,"Button");
    zUpdateContainer.style.marginTop = "10px";
    zUpdateContainer.style.marginLeft = "12px";
    zUpdateContainer.innerHTML = "Check for Updates";
    zTimeLineContainer.appendChild(zUpdateContainer);
    aParams.Params.Section.ContentV2.ContentElement.appendChild(zTimeLineContainer);
    DOM.addEvent(zUpdateContainer,"onclick",LiveAdMaker.AreaContent.TimeLine.displayAdstyleUpdateForm,{Areas: aAreas});
  },
  displayAdstyleUpdateForm: function(e,aParams){
    var zOptionsContainerV2 = DOM.createElement('div','UpdateInformationContainer');
    var zShowUpdateButton;
    aParams.Areas.EnabledLayouts.forEach(function(aAdStyles){
      var zAdStyleInfoContainer = DOM.createElement('div','','AdStyleNameDisplay');
      zAdStyleInfoContainer.innerHTML = aAdStyles.AdStyleName +' (AdStyle)';
      if (aAdStyles.UpdatedAdstyle=="Y"){
        zShowUpdateButton ="Y";
        if (aAdStyles.AreaNameUpdate != ''){
            var zInfoContainer1 = DOM.createElement('div','','AdStyleUpdatedInfo');
            zInfoContainer1.innerHTML = '- '+aAdStyles.AreaNameUpdate+ '(AdStyle)';
            zAdStyleInfoContainer.appendChild(zInfoContainer1);
        }
        if (aAdStyles.NewAreaUpdate != ''){
          var zInfoContainer2 = DOM.createElement('div','','AdStyleUpdatedInfo');
          zInfoContainer2.innerHTML = '- '+aAdStyles.NewAreaUpdate;
          zAdStyleInfoContainer.appendChild(zInfoContainer2);
        }
        if (aAdStyles.ArchivedAreaUpdate != ''){
          var zInfoContainer3 = DOM.createElement('div','','AdStyleUpdatedInfo');
          zInfoContainer3.innerHTML = '- '+aAdStyles.ArchivedAreaUpdate;
          zAdStyleInfoContainer.appendChild(zInfoContainer3);
        }
      }else{
        var zInfoContainer1 = DOM.createElement('div','','AdStyleUpdatedInfo');
        zInfoContainer1.innerHTML = '- No Changes Made';
        zAdStyleInfoContainer.appendChild(zInfoContainer1);
      }
      zOptionsContainerV2.appendChild(zAdStyleInfoContainer);
    });
    aParams.Areas.EnabledAdElements.forEach(function(aAdStyles){
      var zAdStyleInfoContainer = DOM.createElement('div','','AdStyleNameDisplay');
      zAdStyleInfoContainer.innerHTML = aAdStyles.AdStyleName + ' (AdElement)';
      if (aAdStyles.UpdatedAdstyle=="Y"){
        zShowUpdateButton ="Y";
        if (aAdStyles.AreaNameUpdate != ''){
            var zInfoContainer1 = DOM.createElement('div','','AdStyleUpdatedInfo');
            zInfoContainer1.innerHTML = '- '+aAdStyles.AreaNameUpdate;
            zAdStyleInfoContainer.appendChild(zInfoContainer1);
        }
        if (aAdStyles.NewAreaUpdate != ''){
          var zInfoContainer2 = DOM.createElement('div','','AdStyleUpdatedInfo');
          zInfoContainer2.innerHTML = '- '+aAdStyles.NewAreaUpdate;
          zAdStyleInfoContainer.appendChild(zInfoContainer2);
        }
        if (aAdStyles.ArchivedAreaUpdate != ''){
          var zInfoContainer3 = DOM.createElement('div','','AdStyleUpdatedInfo');
          zInfoContainer3.innerHTML = '- '+aAdStyles.ArchivedAreaUpdate;
          zAdStyleInfoContainer.appendChild(zInfoContainer3);
        }
      }else{
        var zInfoContainer1 = DOM.createElement('div','','AdStyleUpdatedInfo');
        zInfoContainer1.innerHTML = '- No Changes Made';
        zAdStyleInfoContainer.appendChild(zInfoContainer1);
      }
      zOptionsContainerV2.appendChild(zAdStyleInfoContainer);
    });
    if (zShowUpdateButton == "Y"){
      var zUpdateButtonContainer = DOM.createElement('div','','Button');
      zUpdateButtonContainer.innerHTML = 'Update Now';
      zOptionsContainerV2.appendChild(zUpdateButtonContainer);
    }
    DOM.addEvent(zUpdateButtonContainer,"onclick",LiveAdMaker.AreaContent.TimeLine.updateAllContent,{});
    DOM.Dialog.show(zOptionsContainerV2,e);
    return true;
  },
  updateAllContent: function(e,aParams){
    DOM.Dialog.hide();
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "setContentCSV", null, true),
      Function: LiveAdMaker.AreaContent.TimeLine.updateAllContentComplete,
      Method:'POST'
    });
    return true;
  },
  updateAllContentComplete:function (aParams){
    if (aParams.Status == "Success"){
      var zInnerBubbleReference = $("InnerBubbleContainer");
      zInnerBubbleReference.parentNode.removeChild(zInnerBubbleReference);
      var zTimeLineReference = $("ContentTimeLineContainer");
      zTimeLineReference.parentNode.removeChild(zTimeLineReference);
      LiveAdMaker.AreaContent.getContentV2(LiveAdMaker.AreaContent.ListParams);
    }
    return true;
  }
}
LiveAdMaker.AreaContent.Details = {
  AreaDetailsForm: null,
  init: function(aParams) {
    LiveAdMaker.AreaContent.CurrentItem = aParams;
    var aAdditionalUrlParams = '&aRowId='+aParams.Item.Id+'&aGetForm_ExecuteObjectType=LiveDigitalAsset_AdContent';
    var aFormParams = {OnDisplayFunction: LiveAdMaker.AreaContent.SharedFunctions.showFieldsOnload}
    LiveAdMaker.AreaContent.Details.AreaDetailsForm = FormUI.Request.getForm(LiveAdMaker.AreaContent.ItemPath,'ContentDetails', aParams.ContentElement,aAdditionalUrlParams,aFormParams);
    return true;
  }
}
LiveAdMaker.AreaContent.SharedFunctions = {
  getAssetSelection: function(aParams){
    if (aParams.Element.Value =="Asset"){
      var zControlElement = FormUI.ElementArray.get('Control','FieldId');
      if (zControlElement[0].Value =="Locked"){
        var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
        Ajax.makeRequest({
          URL: URI.pageURL(zSelectedItem.ItemPath,'GetCollectionAssetsV2'),
          Function: LiveAdMaker.AreaContent.SharedFunctions.showAssetSelection,
          PostValues:{
            aValue: aParams.Element.Value,
            aCSVRowId: aParams.Element.CSVRowId
          },
          Method:'POST'
        });
      }
    }else{
      var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
      Ajax.makeRequest({
        URL: URI.pageURL(zSelectedItem.ItemPath,'GetCollectionAssetsV2'),
        Function: LiveAdMaker.AreaContent.SharedFunctions.showAssetSelection,
        PostValues:{
          aValue: aParams.Element.Value,
          aCSVRowId: aParams.Element.CSVRowId
        },
        Method:'POST'
      });
    }
    return true;
  },
  showAssetSelection : function (aParams){
    if (aParams.HideAssetField =="Y"){
      var zAreaDetailsForm = LiveAdMaker.AreaContent.Details.AreaDetailsForm;
      zAreaDetailsForm.hide("SelectedAsset", "Field", {IsRelativeContainer: true});
    }else{
      var zLabelPosition = { Top: "0", Left: "0", Height: "3", Width:"30"}
      var zFieldPosition = { Top: "0", Left: "36", Height: "3", Width:"30"}
      var aElementProperties = {
       Enabled:             "Y",
       SeqNo:               "29",
       Label:               aParams.Label,
       LabelId:             aParams.LabelId,
       FieldId:             "SelectedAsset",
       Field:               "SelectedAsset",
       FieldType:           "CSVValue",
       DisplayFormat:       "Selection",
       IndexType:           "ExactMatch",
       Position:            "FlowsUnder",
       OptionsArray:        aParams.OptionArray,
       ReadPropertyPath:    ".Text.ContentCSV_Base64.Detail",
       WritePropertyPath:   ".Text.ContentCSV_Base64.Detail",
       CSVColumnId:         "AreaId",
       CSVRowId:            aParams.CSVRowId,
       CSVValue:            "SelectedAsset",
       CSVEncoding:         "Base64",
       LightBoxOptions:     "Y",
       CanEdit:             "Y"
      }
      var zElement = new FormUI.Element('Selection','', zFieldPosition,zLabelPosition, aElementProperties);
      FormUI.ElementArray.push(zElement);
      var FieldElement = FormUI.createElement(zElement, '', 'ContentDetails', true);
    }
    return true;
  },
  showControlFields: function (aParams){
    var zAreaDetailsForm = LiveAdMaker.AreaContent.Details.AreaDetailsForm;
    var zElement_Control = FormUI.ElementArray.get('Control','FieldId');
    var zElement_AreaType = FormUI.ElementArray.get('AreaType','FieldId');
    if (zElement_Control[0].Value == "Locked" || zElement_Control[0].Value == "For Preview Only"){
      zAreaDetailsForm.hide("UserPrompt", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.hide("ValuePrompt", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.hide("Blank", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.hide("SupportUpload", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.hide("SupportEntry", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.hide("SelectedAsset", "Field", {IsRelativeContainer: true});
    }else{
      zAreaDetailsForm.show("UserPrompt", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.show("ValuePrompt", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.show("Blank", "Field", {IsRelativeContainer: true});
      if (zElement_AreaType[0].Value == "Imagery"){
        zAreaDetailsForm.show("SupportUpload", "Field", {IsRelativeContainer: true});
      }else{
        zAreaDetailsForm.show("SupportEntry", "Field", {IsRelativeContainer: true});
      }
      var zSelectedAssetElement = FormUI.ElementArray.get('SelectedAsset','FieldId');
      if (zSelectedAssetElement[0]){
       $("label-"+zSelectedAssetElement[0].ElementId).style.display ="none";
       $(zSelectedAssetElement[0].ElementId).style.display = "none";
       var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
       Ajax.makeRequest({
         URL: URI.pageURL(zSelectedItem.ItemPath,'GetCollectionAssetsV2'),
         Function: LiveAdMaker.AreaContent.SharedFunctions.showAssetSelection,
         PostValues:{
           aValue: zSelectedAssetElement[0].Value,
           aCSVRowId: zSelectedAssetElement[0].CSVRowId
         },
         Method:'POST'
       });
      }
    }
    return true;
  },
  hideShowFilters:function (aParams){
    var zAreaDetailsForm = LiveAdMaker.AreaContent.Details.AreaDetailsForm;
    var zElement_Filters = FormUI.ElementArray.get('FilterType','FieldId');
    switch (zElement_Filters[0].Value) {
      case "Area Selected Collection" :
        zAreaDetailsForm.hide("FilterGroup", "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.show("FilterArea", "FieldId", {IsRelativeContainer: true});
        break;
      case "Group" :
        zAreaDetailsForm.hide("FilterArea", "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.show("FilterGroup", "FieldId", {IsRelativeContainer: true});
        break;
      default:
        zAreaDetailsForm.hide("FilterArea", "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FilterGroup", "FieldId", {IsRelativeContainer: true});
    }
    return true;
  },
  getMatchingAreaSelected:function (aPageId, aAreaId, aFlashObject){
    var zSubItem;
    LiveAdMaker.AreaContent.SubItemList.ItemArray.forEach(function(aArea){
      if (aArea.AreaId == aAreaId){
         zSubItem = aArea.Id;
      }
    });
    URI.goToHash('Section='+LiveAdMaker.AreaLayout.SectionName+'&Action='+LiveAdMaker.AreaLayout.ActionName+'&Item='+LiveAdMaker.SelectedSection.List.SelectedItemId+'&SubItem='+zSubItem);
  },
  flashLayoutAreaSelected:function (aContentAreas,aParams){
    aContentAreas.forEach(function(aArea){
      if (aParams.SelectedArea == aArea.AreaId){
        var zSubItem = aArea.Id;
      }
    });
    URI.goToHash('Section='+LiveAdMaker.AreaLayout.SectionName+'&Action='+LiveAdMaker.AreaLayout.ActionName+'&Item='+LiveAdMaker.AreaLayout.CurrentItem.Id+'&SubItem='+zSubItem);
  },
  showFieldsOnload: function(aParams){
    var zAreaDetailsForm = LiveAdMaker.AreaContent.Details.AreaDetailsForm;
    var zElement_AreaType = FormUI.ElementArray.get('AreaType','FieldId');
    switch (zElement_AreaType[0].Value) {
      case "Imagery" :
        zAreaDetailsForm.show("SupportUpload", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxCharacters", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxLines", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("LineHeight", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("TextFormat", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Style", "Field", {IsRelativeContainer: true});
        break;
      case "Copy" :
        zAreaDetailsForm.show("MaxCharacters", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.show("MaxLines", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.show("LineHeight", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.show("TextFormat", "Field", {IsRelativeContainer: true});
        var zElement_TextFormat = FormUI.ElementArray.getFirst('TextFormat','FieldId');
        if (zElement_TextFormat.Value=="Stylized") {
          zAreaDetailsForm.show("Style_StylizedCopy", "Field", {IsRelativeContainer: true});
        }
        else {
          zAreaDetailsForm.show("Style", "Field", {IsRelativeContainer: true});
        }
        zAreaDetailsForm.hide("SupportUpload", "Field", {IsRelativeContainer: true});
        break;
      default:
        zAreaDetailsForm.hide("MaxCharacters", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxLines", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("LineHeight", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("TextFormat", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Style", "Field", {IsRelativeContainer: true});
    }
    var zElement_Control = FormUI.ElementArray.get('Control','FieldId');
    if (zElement_Control[0].Value == "Locked" || zElement_Control[0].Value == "For Preview Only"){
      zAreaDetailsForm.hide("UserPrompt", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.hide("ValuePrompt", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.hide("Blank", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.hide("SupportUpload", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.hide("SupportEntry", "Field", {IsRelativeContainer: true});
    }else{
      zAreaDetailsForm.show("UserPrompt", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.show("ValuePrompt", "Field", {IsRelativeContainer: true});
      zAreaDetailsForm.show("Blank", "Field", {IsRelativeContainer: true});
      if (zElement_AreaType[0].Value == "Imagery"){
        zAreaDetailsForm.show("SupportUpload", "Field", {IsRelativeContainer: true});
      }else{
        zAreaDetailsForm.show("SupportEntry", "Field", {IsRelativeContainer: true});
      }
    }
    var zElement_Content = FormUI.ElementArray.get('Content','FieldId');
    switch (zElement_Content[0].Value) {
      case "Product" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.show("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        break;
      case "Company" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        break;
      case "Dealer" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        break;
      case "Listing" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        break;
      case "Legal" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        break;
      case "AdElement" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        break;
      case "Repeating AdElement" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.show("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.show("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.show("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.show("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        break;
      case "Collection" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.show("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        break;
      case "User" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        break;
      default:
        if (zElement_Content[0].Value =="AssetList"||zElement_Content[0].Value =="BusinessUnitList"||zElement_Content[0].Value =="ContentList"||zElement_Content[0].Value =="Content"||zElement_Content[0].Value =="CustomerList"||zElement_Content[0].Value =="EventList"||zElement_Content[0].Value =="GroupList"||zElement_Content[0].Value =="MediaOutletList"||zElement_Content[0].Value =="PersonList"||zElement_Content[0].Value =="ProductList"||zElement_Content[0].Value =="ProspectList"||zElement_Content[0].Value =="ServiceList"){
          var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
          Ajax.makeRequest({
            URL: URI.pageURL(zSelectedItem.ItemPath,'CreateMainObjectFields'),
            Function: LiveAdMaker.AreaContent.SharedFunctions.drawMainObjectField,
            PostValues:{
              aValue: zElement_Content[0].Value,
              aCSVColumnId: zElement_Content[0].CSVColumnId,
              aCSVEncoding: zElement_Content[0].CSVEncoding,
              aCSVRowId: zElement_Content[0].CSVRowId
            },
            Method:'POST'
          });
        }
    }
    var zElement_Filters = FormUI.ElementArray.get('FilterType','FieldId');
    switch (zElement_Filters[0].Value) {
      case "Area Selected Collection" :
        zAreaDetailsForm.show("FilterArea", "FieldId", {IsRelativeContainer: true});
        break;
      case "Group" :
        zAreaDetailsForm.show("FilterGroup", "FieldId", {IsRelativeContainer: true});
        break;
      default:
        zAreaDetailsForm.hide("FilterArea", "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FilterGroup", "FieldId", {IsRelativeContainer: true});
    }
    var zElement_UsedByAdStyles = FormUI.ElementArray.get('UsedByAdStyles','FieldId');
    if (zElement_UsedByAdStyles[0].Value == ""){
      zAreaDetailsForm.hide("UsedByAdStyles", "FieldId", {IsRelativeContainer: true});
    }
    var zElement_UsedByAdElements = FormUI.ElementArray.get('UsedByAdElements','FieldId');
    if (zElement_UsedByAdElements[0].Value == ""){
      zAreaDetailsForm.hide("UsedByAdElements", "FieldId", {IsRelativeContainer: true});
    }
    return true;
  },
  changeTextFormat: function(aParams, aResult) {
    var zForm = aParams.Element.Form;
    var zStyleField = zForm.ElementArray.getFirst("Style","FieldId");
    var zStyle_StylizedCopyField = zForm.ElementArray.getFirst("Style_StylizedCopy","FieldId");
    var zTextFormat = aParams.Element.Value;
    if (zTextFormat=="Stylized") {
      var zNewValue = zStyleField.Value;
      var zNewDisplayValue = zStyleField.DisplayValue;
      if (zNewValue&&zNewDisplayValue) {
        zStyle_StylizedCopyField.ValueArray.length = 0;
        zStyle_StylizedCopyField.ValueArray[0] = zNewValue;
        zStyle_StylizedCopyField.DisplayValueArray.length = 0;
        zStyle_StylizedCopyField.DisplayValueArray[0] = zNewDisplayValue;
        $(zStyle_StylizedCopyField.ElementId).innerHTML = zNewDisplayValue;
      }
      zForm.hide("Style", "Field", {IsRelativeContainer: true});
      zForm.show("Style_StylizedCopy", "Field", {IsRelativeContainer: true});
    }
    else {
      if (aParams.Original=="Stylized") {
        zStyleField.Value = zStyle_StylizedCopyField.ValueArray[0] || "";
        zStyleField.DisplayValue = zStyle_StylizedCopyField.DisplayValueArray[0] || "";
        $(zStyleField.ElementId).innerHTML = zStyleField.DisplayValue;
      }
      zForm.show("Style", "Field", {IsRelativeContainer: true});
      zForm.hide("Style_StylizedCopy", "Field", {IsRelativeContainer: true});
    }
  },
  hideShowContent: function(aParams){
   var zAreaDetailsForm = LiveAdMaker.AreaContent.Details.AreaDetailsForm;
    zAreaDetailsForm.hide(aParams.Original, "FieldId", {IsRelativeContainer: true});
    var zElement_Content = FormUI.ElementArray.get('Content','FieldId');
    switch (zElement_Content[0].Value) {
      case "Product" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.show("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
        break;
      case "Company" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
        break;
      case "Dealer" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
        break;
      case "Listing" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
        break;
      case "Legal" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
        break;
      case "AdElement" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
        break;
      case "Repeating AdElement" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.show("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.show("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.show("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.show("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
        break;
      case "Collection" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.show("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
        break;
      case "User" :
        zAreaDetailsForm.show(zElement_Content[0].Value, "FieldId", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
        break;
      default:
        if (zElement_Content[0].Value =="AssetList"||zElement_Content[0].Value =="BusinessUnitList"||zElement_Content[0].Value =="ContentList"||zElement_Content[0].Value =="Content"||zElement_Content[0].Value =="CustomerList"||zElement_Content[0].Value =="EventList"||zElement_Content[0].Value =="GroupList"||zElement_Content[0].Value =="MediaOutletList"||zElement_Content[0].Value =="PersonList"||zElement_Content[0].Value =="ProductList"||zElement_Content[0].Value =="ProspectList"||zElement_Content[0].Value =="ServiceList"){
          var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
          Ajax.makeRequest({
            URL: URI.pageURL(zSelectedItem.ItemPath,'CreateMainObjectFields'),
            Function: LiveAdMaker.AreaContent.SharedFunctions.drawMainObjectField,
            PostValues:{
              aValue: aParams.Element.Value,
              aOriginalValue: aParams.Original,
              aOriginalContent: aParams.OriginalContent,
              aCSVColumnId: aParams.Element.CSVColumnId,
              aCSVEncoding: aParams.Element.CSVEncoding,
              aCSVRowId: aParams.Element.CSVRowId
            },
            Method:'POST'
          });
        }else{
          if (zElement_Content[0].Value =="None"){
            var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
            Ajax.makeRequest({
              URL: URI.pageURL(zSelectedItem.ItemPath,'ClearContentValues'),
              Function: LiveAdMaker.AreaContent.SharedFunctions.updatedCSV,
              PostValues:{
                aValue: aParams.Element.Value,
                aOriginalValue: aParams.Original,
                aOriginalContent: aParams.OriginalContent,
                aCSVColumnId: aParams.Element.CSVColumnId,
                aCSVEncoding: aParams.Element.CSVEncoding,
                aCSVRowId: aParams.Element.CSVRowId
              },
              Method:'POST'
            });
          }
        }
        zAreaDetailsForm.hide("FlowDirection", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MinItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("MaxItems", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Expandtofit", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SpecificWhyBuysValue", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("SelectionType", "Field", {IsRelativeContainer: true});
        zAreaDetailsForm.hide("Source", "Field", {IsRelativeContainer: true});
    }
    return true;
  },
  drawMainObjectField: function(aParams){
    var zSourceElement = FormUI.ElementArray.get('Source','Field');
    if (zSourceElement != '') {
      var zForm = zSourceElement[0].Form;
      FormUI.ElementArray.remove(zSourceElement[0]);
      var zForm_SourceElement = zForm.ElementArray.get('Source','Field');
      zForm.ElementArray.remove(zForm_SourceElement[0]);
      var zRelativeContainerSource = $("FormUI-RelativeContainer-"+zSourceElement[0].ElementId);
      zRelativeContainerSource.parentNode.removeChild(zRelativeContainerSource);
    }
    var zLabelPosition = { Top: "0", Left: "3", Height: "3", Width:"25"};
    var zFieldPosition = { Top: "0", Left: "36", Height: "3", Width:"40"};
    var aElementProperties = {
     Enabled:             "Y",
     SeqNo:               "16",
     Label:               aParams.Label,
     LabelId:             aParams.LabelId,
     FieldId:             "Source",
     Field:               "Source",
     FieldType:           "Default",
     DisplayFormat:       "Selection",
     DisplayValue:        aParams.DisplayValue,
     DefaultValue:        aParams.DisplayValue,
     Value:               aParams.SelectedValue,
     OriginalContent:     aParams.DisplayValue,
     OriginalValue:       aParams.SelectedValue,
     Position:            "FlowsUnder",
     SelectPathLinkAlias: aParams.SelectPathLinkAlias,
     OptionsArray:        aParams.OptionArray,
     ValueArray:          aParams.ValueArray,
     DisplayValueArray:   aParams.DisplayValueArray,
     ReadPropertyPath:    aParams.ReadPropertyPath,
     WritePropertyPath:   aParams.WritePropertyPath,
     CSVColumnId:         aParams.CSVColumnId,
     CSVRowId:            aParams.CSVRowId,
     CSVValue:            "Source",
     CSVEncoding:         "Base64",
     OnChangeFunction:    "LiveAdMaker.AreaContent.SharedFunctions.saveMainObjectFieldValue",
     CanEdit:             "Y"
    }
    var zElement = new FormUI.Element(aParams.DisplayFormat,'', zFieldPosition,zLabelPosition, aElementProperties);
    FormUI.ElementArray.push(zElement);
    var FieldElement = FormUI.createElement(zElement, '', 'ContentDetails', true);
    if (aParams.DisplayValue != ""){
      var zSourceElement = FormUI.ElementArray.get('Source','Field');
      if (zSourceElement != undefined){
        $(zSourceElement[0].ElementId).innerHTML = aParams.DisplayValue;
      }
    }
  },
  saveMainObjectFieldValue: function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath,'SaveMainObjectField'),
      Function: LiveAdMaker.AreaContent.SharedFunctions.updatedCSV,
      PostValues:{
        aCSVColumnId: aParams.Element.CSVColumnId,
        aCSVEncoding: aParams.Element.CSVEncoding,
        aCSVRowId: aParams.Element.CSVRowId,
        aCSVValue: aParams.Element.CSVValue,
        aLinkAlias: aParams.Element.SelectPathLinkAlias,
        aDisplayValue: aParams.Element.DisplayValue,
        aValue: aParams.Element.Value
      },
      Method:'POST'
    });
    return true;
  },
  updatedCSV: function (aParams){
    return true;
  },
  saveContentValue: function(aParams){
    var zAreaDetailsForm = LiveAdMaker.AreaContent.Details.AreaDetailsForm;
    var zSelectedContentValue = zAreaDetailsForm.ElementArray.get('Content','Field');
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.AreaContent.ItemPath,'EditContentCSV'),
      Function: LiveAdMaker.AreaContent.SharedFunctions.saveContentValueComplete,
      PostValues:{
        aCSVColumnId: aParams.Element.CSVColumnId,
        aCSVEncoding: aParams.Element.CSVEncoding,
        aCSVRowId: aParams.Element.CSVRowId,
        aValue: aParams.Element.Value,
        aLinkAlias: aParams.Element.SelectPathLinkAlias,
        aUpdateType: "ListFields",
        aFieldType: aParams.Element.DisplayFormat,
        aSelectedField: zSelectedContentValue[0].Value+"Fields",
        aNewSelections: aParams.Element.ValueArray,
        aOldSelections:  aParams.Original,
        aDisplayValue: aParams.Element.DisplayValue
      },
      Params: {Params: aParams},
      Method:'POST'
    });
    return true;
  },  
  saveContentValueComplete: function(aResults,aParams){
    if (aResults.StandardContentFieldSaved != "Y"){
      if (aResults.Reload == "Y"){
        var zInnerBubbleReference = $("InnerBubbleContainer");
        zInnerBubbleReference.parentNode.removeChild(zInnerBubbleReference);
        var zTimeLineReference = $("ContentTimeLineContainer");
        zTimeLineReference.parentNode.removeChild(zTimeLineReference);
        LiveAdMaker.AreaContent.getContentV2(LiveAdMaker.AreaContent.ListParams);
      }else{
        aResults.Items.forEach(function(aSelectedArea){
          if (aSelectedArea.AddArea =="Y"){
            aParams.Function = LiveAdMaker.drawSection;
            aParams.Section = LiveAdMaker.AreaContent.SubItemList.Params.Section;
            aParams.Params.Action = LiveAdMaker.AreaContent.SubItemList.Params.Action;
            aParams.Params.Item = LiveAdMaker.AreaContent.SubItemList.Params.ItemId;
            aParams.Params.ItemPath = "";
            aParams.Params.Section = LiveAdMaker.AreaContent.SubItemList.Params.Section;
            aParams.Params.SubSection = LiveAdMaker.AreaContent.SubItemList.Params.SubSection;
            aParams.Params.SelectedItem = LiveAdMaker.AreaContent.CurrentItem;
            var aNewResults = {
              Id: aSelectedArea.Id,
              DisplayName: aSelectedArea.DisplayName,
              AreaId: aSelectedArea.AreaId
            }
            LiveAdMaker.receiveNewItem(aNewResults, aParams);
          }
        });
      }
    }
   return true;
  },
  onChangeFPOImage: function(aResults,aParams){
    var zItemPath = aResults.ItemPath;
    Ajax.makeRequest({
      URL: URI.pageURL(zItemPath,'SetFPOImagePreview', 'aObjectTypeAlias=LiveDigitalAsset_AdContent'),
      Function: LiveAdMaker.AreaContent.SharedFunctions.onChangeFPOImageComplete,
      PostValues:{
        aAreaId: aResults.Element.CSVRowId
      },
      Method:'POST'
    });
    return true;
  },
  onChangeFPOImageComplete: function(aResults,aParams){
    return true;
  }
}
    // ---------------------- End Action_LiveAdMaker_AdstyleContent ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_GenericSection --------------- //
LiveAdMaker.GenericSection = function(aSectionSetup) {
  this.SectionSetup = aSectionSetup;
  this.Name = aSectionSetup.Name;
  this.UseOwnedAssetCollections = "Y";
  this.ListOptions = { };
  this.resetListOptions = function() {
    this.ListOptions.DisplayHierarchy = (this.SectionSetup.DisplayHierarchy == "N") ? "N" : "Y";
  }
  this.reset = function(aParams) {
    this.resetListOptions();
    this.Items = null;
    var zLoadParams = {
      Section: this.Name,
      Redraw: true
    };
    if(aParams) {
      Util.copyProperties(zLoadParams, aParams, true);
    }
    this.Load(zLoadParams);
  }
  this.resetListOptions();
  this.Load = function(aParams) {
    aParams.DisabledNavigationArray = this.SectionSetup.DisabledNavigationArray;
    if (this.SectionSetup.LoadParamsFunction) {
      eval(this.SectionSetup.LoadParamsFunction)(aParams)
    }
    var zHierarchyObjectType = this.SectionSetup.HierarchyObjectType || "";
    var zExtraParams = "aObjectTypeAlias=" + zHierarchyObjectType + "&aTopNode=Y";
    if (this.SectionSetup.ExtraParams) {
      zExtraParams = zExtraParams + this.SectionSetup.ExtraParams;
    }
    var zSection = this;
    if(!zSection.Items) {
      this.StartItemPath = this.SectionSetup.CompanyPrefix ? URI.User.CompanyItemPath + this.SectionSetup.StartItemPath : this.SectionSetup.StartItemPath;
      Ajax.makeRequest({
        URL: URI.pageURL(this.StartItemPath, "GetHierarchy", zExtraParams, true),
        Function: LiveAdMaker.receiveSectionData,
        ReceiveFunctionName: "LiveAdMaker.recieveSectionData",
        CallerFunctionName: "LiveAdMaker.GenericSection.Load("+this.Name+")",
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
    }
    else {
      LiveAdMaker.drawSection(aParams);
    }
    if (this.SectionSetup.InitFunction){
      return eval(this.SectionSetup.InitFunction)(aParams);
    }
    return true;
  }
  this.requestChildNodes = function(e, aRequestParams, aRequestItemPath, aParentItemPath, aAdditionalPostValues, aReceiveFunction, aDrawFunction) {
    var zSection = (!aRequestParams.Params || !aRequestParams.Params.SubSection) ? LiveAdMaker[aRequestParams.Params.Section] : LiveAdMaker[aRequestParams.Params.Section][aRequestParams.Params.SubSection];
    var zRequestItemPath = aRequestItemPath;
    var zAddPostVal = aAdditionalPostValues;
    if (aRequestParams.ParentItem.BaseType == "VirtualNode") {
      zRequestItemPath = zSection.StartItemPath;
      zAddPostVal = {
        aIsOwner: "N",
        aExcludeSubItems: "Y",
        aExcludeItems: "Y",
        aForceNodeParent: aRequestParams.ParentItem.Id,
        aIsBaseData: "Y",
        aSubItemFilter: aRequestParams.ParentItem.SubItemFilter
      };
    }
    LiveAdMaker.requestChildNodes(aRequestParams, zRequestItemPath, aParentItemPath, zAddPostVal, aReceiveFunction, aDrawFunction);
  }
  this.disableNavigationItem = function(aItemId) {
    if (this.SectionSetup.DisabledNavigationArray == null) {
      this.SectionSetup.DisabledNavigationArray = new Array();
    }
    this.SectionSetup.DisabledNavigationArray.push({Id: aItemId, Disabled: "Y"});
  }
  this.disableNavigationItems = function(aItemIdArray) {
    for (x=0; x<aItemIdArray.length; x++) {
      this.disableNavigationItem(aItemIdArray[x])
    }
  }
  this.addAction = function(aId, aDisplayName, aFunction) {
    var zCreateNew = true;
    for (var i = 0; i < this.Actions.length; i++) {
      if (aId == this.Actions[i].Id) {
        this.Actions[i].DisplayName = aDisplayName;
        this.Actions[i].DisplayFunction = aFunction;
        zCreateNew = false;
      }
    }
    if (zCreateNew) {
      this.Actions.push({
        Id: aId,
        DisplayName: aDisplayName,
        DisplayFunction: aFunction
      });
    }
  }
  this.renameAction = function(aId, aNewName) {
    for (var i = 0; i < this.Actions.length; i++) {
      if (aId == this.Actions[i].Id) {
        this.Actions[i].DisplayName = aNewName;
      }
    }
  }
  this.removeAction = function(aId) {
    for (var i = 0; i < this.Actions.length; i++) {
      if (aId == this.Actions[i].Id) {
        this.Actions.splice(i, 1);
      }
    }
  }
  this.removeActions = function(aIdArray) {
    for (x=0; x<aIdArray.length; x++) {
      this.removeAction(aIdArray[x])
    }
  }
  this.Actions = [
      {
        Id: "Info",
        DisplayName: "Info",
        DisplayFunction: function(aParams){
          if (aParams.Section.Info && aParams.Section.Info.init && typeof aParams.Section.Info.init == 'function') {
            aParams.Section.Info.init(aParams);
          } else {
            aParams.Section.CurrentItem=aParams.Item;
            aParams.Section.ContentContainer=aParams.ContentElement;
            FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'Info', aParams.ContentElement, '', '');
          }
          return true;
        }
      }
,
      {
        Id: "Details",
        DisplayName: "Details",
        DisplayFunction: function(aParams){
          if (aParams.Section.Details && aParams.Section.Details.init && typeof aParams.Section.Details.init == 'function') {
            aParams.Section.Details.init(aParams);
          } else {
            aParams.Section.CurrentItem=aParams.Item;
            aParams.Section.ContentContainer=aParams.ContentElement;
            FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'Details', aParams.ContentElement, '', '');
          }
          return true;
        }
      }
,
      {
        Id: "Groups",
        DisplayName: "Layout",
        DisplayFunction: function(aParams){
          if (aParams.Section.Groups && aParams.Section.Groups.init && typeof aParams.Section.Groups.init == 'function') {
            aParams.Section.Groups.init(aParams);
          } else {
            aParams.Section.CurrentItem=aParams.Item;
            aParams.Section.ContentContainer=aParams.ContentElement;
            FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'Groups', aParams.ContentElement, '', '');
          }
          return true;
        }
      }
,
      {
        Id: "Restrictions",
        DisplayName: "Restrictions",
        DisplayFunction: function(aParams){
          if (aParams.Section.Restrictions && aParams.Section.Restrictions.init && typeof aParams.Section.Restrictions.init == 'function') {
            aParams.Section.Restrictions.init(aParams);
          } else {
            aParams.Section.CurrentItem=aParams.Item;
            aParams.Section.ContentContainer=aParams.ContentElement;
            FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'Restrictions', aParams.ContentElement, '', '');
          }
          return true;
        }
      }
,
      {
        Id: "Pricing",
        DisplayName: "Pricing",
        DisplayFunction: function(aParams){
          if (aParams.Section.Pricing && aParams.Section.Pricing.init && typeof aParams.Section.Pricing.init == 'function') {
            aParams.Section.Pricing.init(aParams);
          } else {
            aParams.Section.CurrentItem=aParams.Item;
            aParams.Section.ContentContainer=aParams.ContentElement;
            FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'Pricing', aParams.ContentElement, '', '');
          }
          return true;
        }
      }
,
      {
        Id: "SalesPoints",
        DisplayName: "Sales Points",
        DisplayFunction: function(aParams){
          if (aParams.Section.SalesPoints && aParams.Section.SalesPoints.init && typeof aParams.Section.SalesPoints.init == 'function') {
            aParams.Section.SalesPoints.init(aParams);
          } else {
            aParams.Section.CurrentItem=aParams.Item;
            aParams.Section.ContentContainer=aParams.ContentElement;
            FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'SalesPoints', aParams.ContentElement, '', '');
          }
          return true;
        }
      }
,
      {
        Id: "Customize",
        DisplayName: "Customize",
        DisplayFunction: function(aParams){
          if (aParams.Section.Customize && aParams.Section.Customize.init && typeof aParams.Section.Customize.init == 'function') {
            aParams.Section.Customize.init(aParams);
          } else {
            aParams.Section.CurrentItem=aParams.Item;
            aParams.Section.ContentContainer=aParams.ContentElement;
            FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'Customize', aParams.ContentElement, '', '');
          }
          return true;
        }
      }
,
      {
        Id: "Criteria",
        DisplayName: "Criteria",
        DisplayFunction: function(aParams){
          if (aParams.Section.Criteria && aParams.Section.Criteria.init && typeof aParams.Section.Criteria.init == 'function') {
            aParams.Section.Criteria.init(aParams);
          } else {
            aParams.Section.CurrentItem=aParams.Item;
            aParams.Section.ContentContainer=aParams.ContentElement;
            FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'Criteria', aParams.ContentElement, '', '');
          }
          return true;
        }
      }
    ,{
      Id: "Imagery",
      DisplayName: "Assets",
      DisplayFunction: function(aParams){
        aParams.Section.CurrentItem=aParams.Item;
        aParams.Section.ContentContainer=aParams.ContentElement;
        aParams.DisabledNavigationArray = [{Id:"ImportExportButton", Disabled:"Y"},{Id:"ExportButton", Disabled:"Y"}];
        aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetAssetList", "", true);
        aParams.ReceiveSubItemsFunction = LiveAdMaker.AssetsV2.Imagery.receiveSubItems;
        LiveAdMaker.requestSubItems(aParams);
        return true;
      }
    }
  ];
  this.Imagery = {
    AssetList: null,
    ContentElement: null,
    CurrentItem: null,
    DisplayListIcons: "Y",
    DefaultView: (LiveAdMaker.SystemType=="LOCAL") ? "thumbnailAndName" : "",
    getActions: function() {
      return LiveAdMaker.Imagery.Actions
    },
    archiveItem: function(aParams) {
      LiveAdMaker.Imagery.archiveItem(aParams);
      return true;
    },
    receiveSubItems: function(aData,aParams) {
      if (!aData.ShowMessage) {
        LiveAdMaker.receiveSubItems(aData,aParams)
      }
      else {
        aParams.Section.ContentContainer.innerHTML = aData.MessageText
      }
    }
  }
  this.archiveItem = function(aParams) {
    var zArchiveBaseType = this.SectionSetup.RootBaseType || this.SectionSetup.BaseType;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues: {
      aMoveToPath: "intel\\MainObjectList\\" + zArchiveBaseType + "List\\ArchivedItemList"
      },
      ReceiveFunctionName: "LiveAdMaker.recieveArchiveItem",
      CallerFunctionName: "LiveAdMaker.GenericSection.archiveItem("+this.Name+")",
      Method: 'POST'
    });
  }
  this.createNewItem = function(aParams) {
    aParams.AddNewAsChild = "Y";
    LiveAdMaker.showNewBaseItemDialog(aParams, aParams.SelectedItem.ItemPath, this.SectionSetup.BaseType,this.SectionSetup.ObjectType,this.SectionSetup.CreateNewFormExtraParams);
    return true;
  }
  this.importexportSectionItem = function(aParams){
    var zBaseImportDialogContainer = DOM.createElement("div","BaseImportDialogContainer");
    var zAdditionalPostValues = {
      OnDisplayFunction: LiveAdMaker.setBaseTypeOnInput
    }
    var zBaseImportDialog = DOM.Dialog.showForm(zBaseImportDialogContainer,"center","Import",400,400,"NewImportFile",aParams.ItemPath,"aPleaseReturn=Y",zAdditionalPostValues);
    return true;
  }
  this.getBaseTypePath = function() {
    var zRootBaseType = this.SectionSetup.RootBaseType || this.SectionSetup.BaseType;
    return "intel\\MainObjectList\\" + zRootBaseType + "List\\TypeList\\" + this.SectionSetup.BaseType;
  }
}
    // ---------------------- End Action_LiveAdMaker_GenericSection ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_Types --------------- //
LiveAdMaker.Types = {
  Name: "Types",
  Load: function(aParams){
    var zSection = LiveAdMaker.Types;
    if(!zSection.Items) {
      Ajax.makeRequest({
        URL: URI.pageURL("intel\\SystemReferenceList\\ContentTypeList", "GetList", "", true),
        Function: LiveAdMaker.receiveSectionData,
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
    }
    else {
      LiveAdMaker.drawSection(aParams);
    }
    return true;
  },
  draw: function(aParms){
    return true;
  },
  Actions:[
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        DOM.Dialog.hide();
        aParams.ContentElement.innerHTML="";
        FormUI.Request.getForm(aParams.Item.ItemPath, 'Types_Details', aParams.ContentElement, '&inpId='+aParams.Item.Id);
        return true;
      }
    },
    {
      Id: "SubItems",
      DisplayName: "Items",
      DisplayFunction: function(aParams){
        DOM.Dialog.hide();
        aParams.ContentElement.innerHTML="";
        if (aParams.Item.ItemsItemPath) {
          LiveAdMaker.Types.SubItems.CurrentItem = aParams.Item;
          LiveAdMaker.Types.ContentElement = aParams.ContentElement;
          aParams.URL = URI.pageURL(aParams.Item.ItemsItemPath, "GetList", "", true)
          LiveAdMaker.requestSubItems(aParams);
        } else {
          aParams.ContentElement.innerHTML="There are no item options for this item.";
        }
        return true;
      }
    },
    {
      Id: "Features",
      DisplayName: "Features",
      DisplayFunction: function(aParams){
        DOM.Dialog.hide();
        aParams.ContentElement.innerHTML="";
        if (aParams.Item.FeaturesItemPath) {
          LiveAdMaker.Types.Features.CurrentItem = aParams.Item;
          LiveAdMaker.Types.ContentElement = aParams.ContentElement;
          aParams.URL = URI.pageURL(aParams.Item.FeaturesItemPath, "GetList", "", true)
          LiveAdMaker.requestSubItems(aParams);
        } else {
          aParams.ContentElement.innerHTML="There are no features for this item.";
        }
        return true;
      }
    },
    {
      Id: "Pricing",
      DisplayName: "Pricing",
      DisplayFunction: function(aParams){
        DOM.Dialog.hide();
        aParams.ContentElement.innerHTML="";
        if (aParams.Item.PricingItemPath) {
          LiveAdMaker.Types.Pricing.CurrentItem = aParams.Item;
          LiveAdMaker.Types.ContentElement = aParams.ContentElement;
          aParams.URL = URI.pageURL(aParams.Item.PricingItemPath, "GetList", "", true)
          LiveAdMaker.requestSubItems(aParams);
        } else {
          aParams.ContentElement.innerHTML="There are no pricing options for this item.";
        }
        return true;
      }
    }
  ]
}
LiveAdMaker.Types.Features = {
  CurrentItem: "",
  SelectedAction: "Details",
  createNewItem: function(aParams) {
    var zMakeRequestItemPath = LiveAdMaker.Types.Features.CurrentItem.FeaturesItemPath;
    if (LiveAdMaker.Types.Features.CurrentItem.FeaturesObjectType) {
      Ajax.makeRequest({
        URL: URI.pageURL(zMakeRequestItemPath,"CreateItem",null,true),
        Function: LiveAdMaker.receiveNewItem,
        Params: {Section:"Features", Function:LiveAdMaker.drawSection, Params:aParams},
        PostValues: {
          aObjectTypeAlias:  LiveAdMaker.Types.Features.CurrentItem.FeaturesObjectType,
          aAlias: "Feature".makeUnique(),
          aName: "Feature "+ (LiveAdMaker.SelectedSection.Features.List.ItemArray.length + 1)
        },
        Method:'POST'
      });
    }
  },
  duplicateItem:function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Features", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aAlias:"Feature".makeUnique(),
        aName: aParams.SelectedItem.DisplayName + " copy",
        aSelectedItemPath:aParams.SelectedItem.ItemPath,
        aProductPath: LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath,
        aCopyComplete_OwnerObjectReference: "fThis_Object^Owner"
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    if (LiveAdMaker.Types.Features.CurrentItem.ArchiveFeaturesItemPath) {
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
        Function: LiveAdMaker.receiveArchiveItem,
        Params: aParams,
        PostValues: {
          aMoveToPath: LiveAdMaker.Types.Features.CurrentItem.ArchiveFeaturesItemPath
        },
        Method:'POST'
      });
    }
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "",
      DisplayFunction: function(aParams){
        FormUI.Request.getForm(aParams.Item.ItemPath, 'Types_FeatureDetails', aParams.ContentElement, '');
        return true;
      }
    }
  ]
}
LiveAdMaker.Types.Pricing = {
  CurrentItem: "",
  SelectedAction: "Details",
  createNewItem: function(aParams) {
    var zMakeRequestItemPath = LiveAdMaker.Types.Pricing.CurrentItem.PricingItemPath;
    if (LiveAdMaker.Types.Pricing.CurrentItem.PricingObjectType) {
      Ajax.makeRequest({
        URL: URI.pageURL(zMakeRequestItemPath,"CreateItem",null,true),
        Function: LiveAdMaker.receiveNewItem,
        Params: {Section:"Pricing", Function:LiveAdMaker.drawSection, Params:aParams},
        PostValues: {
          aObjectTypeAlias:  LiveAdMaker.Types.Pricing.CurrentItem.PricingObjectType,
          aAlias: "PricingType".makeUnique(),
          aName: "PricingType "+ (LiveAdMaker.SelectedSection.Pricing.List.ItemArray.length + 1)
        },
        Method:'POST'
      });
    }
  },
  duplicateItem:function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Pricing", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aAlias:"PricingType".makeUnique(),
        aName: aParams.SelectedItem.DisplayName + " copy",
        aSelectedItemPath:aParams.SelectedItem.ItemPath,
        aProductPath: LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath,
        aCopyComplete_OwnerObjectReference: "fThis_Object^Owner"
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    if (LiveAdMaker.Types.Pricing.CurrentItem.ArchivePricingItemPath) {
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
        Function: LiveAdMaker.receiveArchiveItem,
        Params: aParams,
        PostValues: {
          aMoveToPath: LiveAdMaker.Types.Pricing.CurrentItem.ArchivePricingItemPath
        },
        Method:'POST'
      });
    }
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "",
      DisplayFunction: function(aParams){
        FormUI.Request.getForm(aParams.Item.ItemPath, 'Types_PricingDetails', aParams.ContentElement, '');
        return true;
      }
    }
  ]
}
LiveAdMaker.Types.SubItems = {
  CurrentItem: "",
  SelectedAction: "Details",
  createNewItem: function(aParams) {
    var zMakeRequestItemPath = LiveAdMaker.Types.SubItems.CurrentItem.ItemsItemPath;
    if (LiveAdMaker.Types.SubItems.CurrentItem.ItemsObjectType) {
      Ajax.makeRequest({
        URL: URI.pageURL(zMakeRequestItemPath,"CreateItem",null,true),
        Function: LiveAdMaker.receiveNewItem,
        Params: {Section:"Items", Function:LiveAdMaker.drawSection, Params:aParams},
        PostValues: {
          aObjectTypeAlias:  LiveAdMaker.Types.SubItems.CurrentItem.ItemsObjectType,
          aAlias: LiveAdMaker.Types.SubItems.CurrentItem.DisplayName.makeUnique(),
          aName: LiveAdMaker.Types.SubItems.CurrentItem.DisplayName + (LiveAdMaker.SelectedSection.SubItems.List.ItemArray.length + 1)
        },
        Method:'POST'
      });
    }
  },
  duplicateItem:function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Items", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aAlias: LiveAdMaker.Types.SubItems.CurrentItem.DisplayName.makeUnique(),
        aName: aParams.SelectedItem.DisplayName + " copy",
        aSelectedItemPath:aParams.SelectedItem.ItemPath,
        aProductPath: LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath,
        aCopyComplete_OwnerObjectReference: "fThis_Object^Owner"
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    if (LiveAdMaker.Types.SubItems.CurrentItem.ArchiveItemsItemPath) {
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
        Function: LiveAdMaker.receiveArchiveItem,
        Params: aParams,
        PostValues: {
          aMoveToPath: LiveAdMaker.Types.SubItems.CurrentItem.ArchiveItemsItemPath
        },
        Method:'POST'
      });
    }
  },
  Actions: [
    {
      Id: "Info",
      DisplayName: "Info",
      DisplayFunction: function(aParams){
        FormUI.Request.getForm(aParams.Item.ItemPath, 'Info', aParams.ContentElement, '');
        return true;
      }
    },
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        FormUI.Request.getForm(aParams.Item.ItemPath, 'Details', aParams.ContentElement, '');
        return true;
      }
    },
    {
      Id: "AdStyles",
      DisplayName: "Ad Styles",
      DisplayFunction: function(aParams){
        FormUI.Request.getForm(aParams.Item.ItemPath, 'AdStyles', aParams.ContentElement, '');
        return true;
      }
    }
  ]
}
    // ---------------------- End Action_LiveAdMaker_Types ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_CustomLists --------------- //
LiveAdMaker.CustomLists = {
  Lists: [],
  SelectedList: "",
  CreateList: function(aName) {
    zListName = (aName) ? aName : "New List";
    if (!URI || !URI.User || URI.User.ItemPath) return true;
    Ajax.makeRequest({
      URL: URI.pageURL(URI.User.ItemPath, "CreateCustomList", null, true),
      Function: LiveAdMaker.CustomLists.CreateListComplete,
      Method: "POST",
      PostValues: {ListName: zListName}
    });
    return true;
  },
  CreateListComplete: function(aListData) {
    LiveAdMaker.CustomLists.Lists[LiveAdMaker.CustomLists.Lists.length] = new LiveAdMaker.CustomLists.List(aListData[0].NAME,aListData[0].OBJECTCODE,aListData[0].ITEMPATH);
    LiveAdMaker.CustomLists.SelectList(LiveAdMaker.CustomLists.Lists.length-1)
  },
  EmptyList: function() {
    if (LiveAdMaker.CustomLists.SelectedList&&confirm("Are you sure you want to empty "+LiveAdMaker.CustomLists.SelectedList.ListName+"?")) {
      LiveAdMaker.CustomLists.SelectedList.Items = [];
      LiveAdMaker.CustomLists.ListManagerUI.Draw()
    }
  },
  Init: function() {
    LiveAdMaker.CustomLists.AddItemsUI.Container = $('AddItemsUIContainer');
    LiveAdMaker.CustomLists.ListManagerUI.Container = $('ListManagerUIContainer');
    LiveAdMaker.CustomLists.LoadLists();
    return true
  },
  LoadLists: function() {
    if (!URI || !URI.User || URI.User.ItemPath) return true;
    Ajax.makeRequest({
      URL: URI.pageURL(URI.User.ItemPath, "LoadCustomLists", null, true),
      Function: LiveAdMaker.CustomLists.LoadListsComplete
    });
    return true
  },
  LoadListsComplete: function(aListData) {
    aListData.forEach(function(aList) {
      LiveAdMaker.CustomLists.Lists[LiveAdMaker.CustomLists.Lists.length] = new LiveAdMaker.CustomLists.List(aList.NAME,aList.OBJECTCODE,aList.ITEMPATH)
    })
    LiveAdMaker.CustomLists.ListManagerUI.Draw();
    return true
  },
  RemoveList: function() {
    if (confirm("Are you sure you want to remove "+LiveAdMaker.CustomLists.SelectedList.ListName+"?")&&LiveAdMaker.CustomLists.SelectedList.ItemPath) {
      Ajax.makeRequest({
        URL: URI.pageURL(LiveAdMaker.CustomLists.SelectedList.ItemPath, "Remove", null, true),
        Function: LiveAdMaker.CustomLists.RemoveListComplete,
        Method: "POST"
      });
    }
  },
  RemoveListComplete: function(aResponse) {
    if (!aResponse[0].ERROR) {
      LiveAdMaker.CustomLists.Lists.remove(LiveAdMaker.CustomLists.SelectedList);
      LiveAdMaker.CustomLists.SelectedList = null;
      LiveAdMaker.CustomLists.ListManagerUI.UpdateSelected();
    }
  },
  RenameList: function(aName) {
    if (LiveAdMaker.CustomLists.SelectedList) {
      LiveAdMaker.CustomLists.SelectedList.ListName = aName
    }
  },
  SelectList: function(aListIndex) {
    LiveAdMaker.CustomLists.SelectedList = LiveAdMaker.CustomLists.Lists[aListIndex];
    LiveAdMaker.CustomLists.ListManagerUI.UpdateSelected()
  },
  AddItemsUI: {
    Draw: function() {
    },
    Toggle: function() {
      if(this.Container) {
        this.Container.style.display = (this.Container.style.display!="block") ? "block" : "none"
      }
    }
  },
  CustomListsUI: {
    Draw: function() {
    }
  },
  ListManagerUI: {
    Draw: function(aListData) {
      if (this.Container) {
        zSelectedListContainer = DOM.createElement("div","SelectedListContainer","","");
        zSelectedListOptionsContainer = DOM.createElement("div","SelectedListOptionsContainer","","");
        zUnSelectedListsContainer = DOM.createElement("div","UnSelectedListsContainer","","");
        zEmptyListContainer = DOM.createElement("div","EmptyListContainer","","");
        zRemoveListContainer = DOM.createElement("div","RemoveListContainer","","");
        zNewListContainer = DOM.createElement("div","NewListContainer","","");
        zEmptyListLink = DOM.createElement("a","EmptyListLink","","");
        zRemoveListLink = DOM.createElement("a","RemoveListLink","","");
        zNewListLink = DOM.createElement("a","NewListLink","","");
        zNewListLink.href = "javascript:LiveAdMaker.CustomLists.CreateList()";
        zNewListLink.innerHTML = "New List";
        zEmptyListContainer.appendChild(zEmptyListLink);
        zRemoveListContainer.appendChild(zRemoveListLink);
        zNewListContainer.appendChild(zNewListLink);
        zSelectedListOptionsContainer.appendChild(zEmptyListContainer);
        zSelectedListOptionsContainer.appendChild(zRemoveListContainer);
        zSelectedListOptionsContainer.appendChild(zNewListContainer);
        this.Container.appendChild(zSelectedListContainer);
        this.Container.appendChild(zSelectedListOptionsContainer);
        this.Container.appendChild(zUnSelectedListsContainer);
        LiveAdMaker.CustomLists.SelectList(0)
      }
    },
    Toggle: function() {
      if(this.Container) {
        this.Container.style.display = (this.Container.style.display!="block") ? "block" : "none"
      }
    },
    UpdateSelected: function() {
      zSelectedListContainer = $('SelectedListContainer');
      zEmptyListLink = $('EmptyListLink');
      zRemoveListLink = $('RemoveListLink');
      zUnSelectedListsContainer = $('UnSelectedListsContainer');
      zSelectedListContainer.innerHTML = "";
      zEmptyListLink.innerHTML = "";
      zEmptyListLink.href = "javascript:void(0);"
      zRemoveListLink.innerHTML = "";
      zRemoveListLink.href = "javascript:void(0);"
      zUnSelectedListsContainer.innerHTML = "";
      if (LiveAdMaker.CustomLists.Lists.length>0) {
        if (!LiveAdMaker.CustomLists.SelectedList) {
          LiveAdMaker.CustomLists.SelectedList = LiveAdMaker.CustomLists.Lists[0]
        }
        zSelectedListIndex = LiveAdMaker.CustomLists.Lists.indexOf(LiveAdMaker.CustomLists.SelectedList);
        for (var i=0; i<LiveAdMaker.CustomLists.Lists.length; i++) {
          if (i==zSelectedListIndex) {
            zSelectedListName = LiveAdMaker.CustomLists.SelectedList.ListName;
            zSelectedListContainer.innerHTML = zSelectedListName;
            $('SelectedListName').innerHTML = zSelectedListName;
            zEmptyListLink.href = "javascript:LiveAdMaker.CustomLists.EmptyList("+i+")";
            zEmptyListLink.innerHTML = "Empty "+zSelectedListName;
            zRemoveListLink.href = "javascript:LiveAdMaker.CustomLists.RemoveList("+i+")";
            zRemoveListLink.innerHTML = "Remove "+zSelectedListName;
          }
          else {
            zListContainer = DOM.createElement("div","","UnSelectedListContainer","");
            zListLink = DOM.createElement("a","","UnSelectedListLink","");
            zListLink.href = "javascript:LiveAdMaker.CustomLists.SelectList("+i+")";
            zListLink.innerHTML = LiveAdMaker.CustomLists.Lists[i].ListName;
            zListContainer.appendChild(zListLink);
            zUnSelectedListsContainer.appendChild(zListContainer)
          }
        }
      }
    }
  },
  Item: function() {
    this.ItemName = "";
    this.ItemId = "";
    this.FileSize = ""
  },
  List: function(aName,aObjectCode,aItemPath) {
    this.ListName = aName;
    this.ListID = aObjectCode;
    this.ItemPath = aItemPath;
    this.Items = []
  }
};
DOM.onLoad(LiveAdMaker.CustomLists.Init);
    // ---------------------- End Action_LiveAdMaker_CustomLists ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_Imagery --------------- //
LiveAdMaker.Imagery = {
  Name: "Imagery",
  DisplayListIcons: 'Y',
  ListOptions: {
    DisplayHierarchy: 'Y'
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Imagery.Details.Params = aParams;
        LiveAdMaker.Imagery.Details.init(aParams);
        return true;
      }
    },
    {
      Id: "Groups",
      DisplayName: "Groups",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Imagery.Groups.init(aParams);
        return true;
      }
    },
    {
      Id: "Restrictions",
      DisplayName: "Restrictions",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Imagery.Restrictions.init(aParams);
        return true;
      }
    },
    {
      Id: "Annotations",
      DisplayName: "Annotations",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Imagery.Annotations.init(aParams);
        return true;
      }
    }
  ],
  Activity: {
    init: function(aParams) {
      LiveAdMaker.Imagery.Activity.CurrentItem = aParams.Item;
      LiveAdMaker.Imagery.Activity.ContentContainer = aParams.ContentElement;
      DOM.replaceContent(aParams.ContentElement,"");
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.Item.ItemPath, "GetAssetActivity", null, true),
        Function: LiveAdMaker.Imagery.DisplayActivity,
        Params: aParams,
        Method:'POST'
      });
      return true;
    }
  },
  DisplayActivity:function(aResults, aParams) {;
    var full=aResults.Items.length-1;
    var area=LiveAdMaker.Imagery.Activity.ContentContainer;
    area.innerHTML="<table id='ActivityDisplay'>\n<tr><th>Activity</th><th>Date</th><th>User</th><th>Field</th><th>Old Value</th><th>New Value</th></tr>\n</table>";
    var tableRef = document.getElementById("ActivityDisplay");
    var StartDay="39832.6836461921";
    for (i=0;i<=full;i++){
    if(aResults.Items[i].Date>=StartDay){
      var newRow = tableRef.insertRow(1);
      if(i % 2 == 0){
       newRow.className = "z1";
      }else{
       newRow.className = "z2";
      }
      var newCell = newRow.insertCell(0);
      newCell.innerHTML=aResults.Items[i].Activity;
      newCell = newRow.insertCell(1);
      newCell.innerHTML=aResults.Items[i].DisplayDate;
      newCell = newRow.insertCell(2);
      newCell.innerHTML=aResults.Items[i].User;
      newCell = newRow.insertCell(3);
      newCell.innerHTML=aResults.Items[i].Field;
      newCell = newRow.insertCell(4);
      newCell.innerHTML=aResults.Items[i].OldValue;
      newCell = newRow.insertCell(5);
      newCell.innerHTML=aResults.Items[i].NewValue;
      }
    }
  },
  Inventory: {
    init: function(aParams) {
      LiveAdMaker.Imagery.Inventory.CurrentItem = aParams.Item;
      LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData = {};
      LiveAdMaker.Imagery.Inventory.ContentContainer = aParams.ContentElement;
      DOM.replaceContent(aParams.ContentElement,"");
      LiveAdMaker.Imagery.Inventory.getBaseInventoryData();
      var zInventoryForm = new FormUI.Form(aParams.Item.ItemPath, 'Inventory', aParams.ContentElement);
      aInventoryFormParams = {};
      zInventoryForm.fetchForm(true, null, aInventoryFormParams);
      zInventoryForm.ElementArray.forEach(function(aInventoryField) {
        aInventoryField.OnChangeFunction = 'LiveAdMaker.Imagery.Inventory.getBaseInventoryData';
      });
      zInventoryForm.drawForm();
      return true;
    },
    displayGetAvailabilityForm: function(aParams){
      if ($('dv_GetAvailabilityFormContainer')){
        $('dv_GetAvailabilityFormContainer').innerHTML='';
        var zGetAvailabilityFormContainer = $('dv_GetAvailabilityFormContainer');
      }else{
        var zGetAvailabilityFormContainer = DOM.createElement('div','dv_GetAvailabilityFormContainer');
        LiveAdMaker.Imagery.Inventory.ContentContainer.appendChild(zGetAvailabilityFormContainer);
      }
      switch (LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData.InventoryType){
        case 'None':
          zGetAvailabilityFormContainer.innerHTML = '';
          break;
        case '':
          zGetAvailabilityFormContainer.innerHTML = '';
          break;
        default :
          var zGetAvailabilityHeading = DOM.createElement('div', 'dv_GetAvailabilityHeadingContainer');
          for (var i = 0; i < FormUI.FormList.length; i++){
            if (FormUI.FormList[i].FormType == 'GetAvailability_'+LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData.InventoryType){
              FormUI.FormList.splice(i, 1)
            }
          }
          var aNewGetAvailabilityFormParams = { ClearParentElement: true };
          var zGetAvailabilityForm = new FormUI.Form(LiveAdMaker.Imagery.Inventory.CurrentItem.ItemPath, 'GetAvailability_'+LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData.InventoryType, zGetAvailabilityFormContainer, aNewGetAvailabilityFormParams);
          aGetAvailabilityFormParams = {};
          zGetAvailabilityForm.fetchForm(true, null, aGetAvailabilityFormParams);
          zGetAvailabilityForm.drawForm();
          var zGetAvailabilityButton = DOM.createElement('div', 'dv_GetAvailabilityButtonContainer');
          zGetAvailabilityButton.style.clear = 'both';
          zGetAvailabilityButton.innerHTML = '<input type=\"button\" value=\"Get Availability\" name=\"btn_GetAvailability\" id=\"btn_GetAvailability\" onclick=\"LiveAdMaker.Imagery.Inventory.getAvailability()\;\" class=\"Button\">';
          zGetAvailabilityFormContainer.appendChild(zGetAvailabilityButton);
      }
    },
    getAvailability: function(aParams){
      var zGetAvailabilityFormList = FormUI.FormList.get('GetAvailability_'+LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData.InventoryType, 'FormType')
      var zGetAvailabilityForm = zGetAvailabilityFormList[0];
      var zReserveStartYear = '';
      var zReserveStartMonth = '';
      var zReserveStartDay = '';
      var zReserveStartHour = '';
      var zReserveEndYear = '';
      var zReserveEndMonth = '';
      var zReserveEndDay = '';
      var zReserveEndHour = '';
      Ajax.makeRequest({
        URL: URI.pageURL(LiveAdMaker.Imagery.Inventory.CurrentItem.ItemPath, "GetAvailability", null, true),
        Function: LiveAdMaker.Imagery.Inventory.receiveAvailability,
        Params: aParams,
        PostValues: {aRequestedUnits:aAssetCollectionChecked,aAssetCollectionPath:aCollectionPath}
      });
    },
    receiveAvailability: function(aResults,aParams){
      alert(aResults.toSource());
    },
    getBaseInventoryData: function(aParams){
      Ajax.makeRequest({
        URL: URI.pageURL(LiveAdMaker.Imagery.Inventory.CurrentItem.ItemPath, "GetBaseInventoryData", null, true),
        Function: LiveAdMaker.Imagery.Inventory.receiveBaseInventoryData,
        Params: aParams
      });
    },
    receiveBaseInventoryData: function(aResults,aParams){
      LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData.InventoryType = aResults.InventoryType || null;
      LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData.PeriodType = aResults.PeriodType || null;
      LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData.TotalUnits = aResults.TotalUnits || null;
      LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData.LeadPeriods = aResults.LeadPeriods || null;
      LiveAdMaker.Imagery.Inventory.CurrentItem.InventoryData.PostPeriods = aResults.PostPeriods || null;
      LiveAdMaker.Imagery.Inventory.displayGetAvailabilityForm();
      return true;
    }
  },
  Groups: {
    init: function(aParams) {
      LiveAdMaker.Imagery.Groups.CurrentItem = aParams.Item;
      LiveAdMaker.Imagery.Groups.ContentContainer = aParams.ContentElement;
      DOM.replaceContent(aParams.ContentElement,"");
      FormUI.Request.GetForm(aParams.Item.ItemPath, 'Groups', aParams.ContentElement);
      return true;
    }
  },
  Restrictions: {
    init: function(aParams) {
      LiveAdMaker.Imagery.Restrictions.CurrentItem = aParams.Item;
      LiveAdMaker.Imagery.Restrictions.ContentContainer = aParams.ContentElement;
      DOM.replaceContent(aParams.ContentElement);
      var zFormParams = {
        OnDisplayFunction: LiveAdMaker.Imagery.Restrictions.clearFixFields
      };
      var zRestrictionsForm =  FormUI.Request.getForm(aParams.Item.ItemPath, 'Restrictions', aParams.ContentElement, null, zFormParams);
      return true;
    },
    clearFixFields: function(aParams) {
      var zRestrictionsBoxesForm = aParams.Form;
      var zUsageFieldsDiv = DOM.createElement("div", "", "clearfix");
      var zUsageStartDateField = zRestrictionsBoxesForm.getElement("UsageRight_StartDate", "FieldId");
      if(zUsageStartDateField && zUsageStartDateField.RelativeContainer) {
        var zUsageStartDateContainer = zRestrictionsBoxesForm.ContentElement.removeChild(zUsageStartDateField.RelativeContainer);
        zUsageFieldsDiv.appendChild(zUsageStartDateContainer);
      }
      var zUsageEndDateField = zRestrictionsBoxesForm.getElement("UsageRight_EndDate", "FieldId");
      if(zUsageEndDateField && zUsageEndDateField.RelativeContainer) {
        var zUsageEndDateContainer = zRestrictionsBoxesForm.ContentElement.removeChild(zUsageEndDateField.RelativeContainer);
        zUsageFieldsDiv.appendChild(zUsageEndDateContainer);
      }
      zRestrictionsBoxesForm.ContentElement.insertBefore(zUsageFieldsDiv, zRestrictionsBoxesForm.ContentElement.firstChild);
      return true;
    }
  },
  createItem: function(e, aParams) {
    var zAddToParentPath = '';
    var zLinkToPath = '';
    DOM.Dialog.hide();
    if (aParams.Params.Section=="Offers" || aParams.Section=="Offers") {
      var zSelectedItemAliasArray = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath.split("\\");
      var zSelectedItemAlias = zSelectedItemAliasArray[zSelectedItemAliasArray.length-1];
      var zAddToPath = URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\OfferCollectionLibrary\\"+zSelectedItemAlias+"_Collection"
      if(LiveAdMaker.Offers.HasAssets == 'N') {
        aParams.Params.ResetItems = 'Y';
      }
      zAddToParentPath = URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\OfferCollectionLibrary";
      zLinkToPath = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath;
    }
    else if (aParams.Params.Section=="CampaignSetup" || aParams.Params.Section=="WebsiteSetup" || aParams.Params.Section=="CreateAd"){
      var zAddToPath = LiveAdMaker.SelectedSection.Imagery.ItemPath;
    }
    else if (aParams.Params.Section=="People" || aParams.Section=="People"){
      var zSelectedItemAliasArray = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath.split("\\");
      var zSelectedItemAlias = zSelectedItemAliasArray[zSelectedItemAliasArray.length-1];
      var zAddToPath = URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\PeopleCollectionLibrary\\"+zSelectedItemAlias+"_Collection"
      if(LiveAdMaker.People.HasAssets == 'N') {
        aParams.Params.ResetItems = 'Y';
      }
      zAddToParentPath = URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\PeopleCollectionLibrary";
      zLinkToPath = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath;
    }
    else if (aParams.Params.Section=="Approvals" || aParams.Section=="Approvals") {
      var zSelectedItemAliasArray = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath.split("\\");
      var zSelectedItemAlias = zSelectedItemAliasArray[zSelectedItemAliasArray.length-1];
      var zAddToPath = URI.User.ItemPath+"\\ContentList\\DigitalAssetLibrary\\ApprovalCollectionLibrary\\"+zSelectedItemAlias+"_Collection"
      zAddToParentPath = URI.User.ItemPath+"\\ContentList\\DigitalAssetLibrary\\ApprovalCollectionLibrary";
      zLinkToPath = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath;
      var zMakeRequestItemPath = URI.User.ItemPath+"\\ContentList\\DigitalAssetLibrary\\AssetLibrary";
      zMakeRequestItemPath += "\\"+aParams.LibraryAlias;
    }
    else if (LiveAdMaker[aParams.Params.Section].CollectionItemPath) {
      var zSelectedItemAliasArray = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath.split("\\");
      var zSelectedItemAlias = zSelectedItemAliasArray[zSelectedItemAliasArray.length-1];
      var zAddToPath = LiveAdMaker[aParams.Params.Section].CollectionItemPath+ "\\" +zSelectedItemAlias+"_Collection"
    }
    else if (LiveAdMaker[aParams.Params.Section].UseOwnedAssetCollections=="Y") {
      var zSelectedItemAliasArray = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath.split("\\");
      var zSelectedItemAlias = zSelectedItemAliasArray[zSelectedItemAliasArray.length-1];
      var zAddToPath = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath+ "\\" +zSelectedItemAlias+"_Collection"
    }
    else {
      var zAddToPath = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath
    }
    var zMakeRequestItemPath = (LiveAdMaker.SystemType=="BRAND") ? "intel\\ContentList\\DigitalAssetLibrary\\AssetLibrary" : URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\AssetLibrary";
    zMakeRequestItemPath += "\\"+aParams.LibraryAlias;
    aParams.Params.ReceiveFunction = aParams.ReceiveFunction;
    aParams.Params.ReceiveFunctionParams = aParams.ReceiveFunctionParams;
    LiveAdMaker.createNewItem(aParams.Params, zMakeRequestItemPath, aParams.AssetPrefix.makeUnique(), aParams.AssetPrefix+" "+LiveAdMaker.SelectedSection.Items.length, aParams.AssetObjectType, {aAddToPath: zAddToPath, aDefaultLanguage: URI.User.Language, aAddToParentPath: zAddToParentPath, aLinkToPath: zLinkToPath});
    return true
  },
  createNewItem: function(aParams) {
    var zCreateAssetContainer = DOM.createElement("div","","CreateAssetContainer","");
    var zImageLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zImageLink = DOM.createElement("a","","CreateAssetLink","");
    zImageLink_Container.appendChild(zImageLink);
    zCreateAssetContainer.appendChild(zImageLink_Container);
    zImageLink.href = "javascript:void(0)";
    zImageLink.innerHTML = "Image";
    DOM.addEvent(zImageLink, "onclick", LiveAdMaker.Imagery.createItem, {AssetPrefix:"Image", AssetObjectType:"LiveDigitalAsset_Image", LibraryAlias:"ImageryLibrary", Params:aParams});
    var zCopyLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zCopyLink = DOM.createElement("a","","CreateAssetLink","");
    zCopyLink_Container.appendChild(zCopyLink);
    zCreateAssetContainer.appendChild(zCopyLink_Container);
    zCopyLink.href = "javascript:void(0)";
    zCopyLink.innerHTML = "Copy";
    DOM.addEvent(zCopyLink, "onclick", LiveAdMaker.Imagery.createItem, {AssetPrefix:"Copy", AssetObjectType:"LiveDigitalAsset_RichText", LibraryAlias:"CopyLibrary", Params:aParams});
    var zLegalLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zLegalLink = DOM.createElement("a","","CreateAssetLink","");
    zLegalLink_Container.appendChild(zLegalLink);
    zCreateAssetContainer.appendChild(zLegalLink_Container);
    zLegalLink.href = "javascript:void(0)";
    zLegalLink.innerHTML = "Legal";
    DOM.addEvent(zLegalLink, "onclick", LiveAdMaker.Imagery.createItem, {AssetPrefix:"Legal", AssetObjectType:"LiveDigitalAsset_Legal", LibraryAlias:"LegalLibrary", Params:aParams});
    var zVideoLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zVideoLink = DOM.createElement("a","","CreateAssetLink","");
    zVideoLink_Container.appendChild(zVideoLink);
    zCreateAssetContainer.appendChild(zVideoLink_Container);
    zVideoLink.href = "javascript:void(0)";
    zVideoLink.innerHTML = "Video";
    DOM.addEvent(zVideoLink, "onclick", LiveAdMaker.Imagery.createItem, {AssetPrefix:"Video", AssetObjectType:"LiveDigitalAsset_Video", LibraryAlias:"VideoLibrary", Params:aParams});
    var zAudioLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zAudioLink = DOM.createElement("a","","CreateAssetLink","");
    zAudioLink_Container.appendChild(zAudioLink);
    zCreateAssetContainer.appendChild(zAudioLink_Container);
    zAudioLink.href = "javascript:void(0)";
    zAudioLink.innerHTML = "Audio";
    DOM.addEvent(zAudioLink, "onclick", LiveAdMaker.Imagery.createItem, {AssetPrefix:"Audio", AssetObjectType:"LiveDigitalAsset_Audio", LibraryAlias:"AudioLibrary", Params:aParams});
    var zFlashLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zFlashLink = DOM.createElement("a","","CreateAssetLink","");
    zFlashLink_Container.appendChild(zFlashLink);
    zCreateAssetContainer.appendChild(zFlashLink_Container);
    zFlashLink.href = "javascript:void(0)";
    zFlashLink.innerHTML = "Flash";
    DOM.addEvent(zFlashLink, "onclick", LiveAdMaker.Imagery.createItem, {AssetPrefix:"Flash", AssetObjectType:"LiveDigitalAsset_Flash", LibraryAlias:"FlashLibrary", Params:aParams});
    var zDocumentLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zDocumentLink = DOM.createElement("a","","CreateAssetLink","");
    zDocumentLink_Container.appendChild(zDocumentLink);
    zCreateAssetContainer.appendChild(zDocumentLink_Container);
    zDocumentLink.href = "javascript:void(0)";
    zDocumentLink.innerHTML = "Document";
    DOM.addEvent(zDocumentLink, "onclick", LiveAdMaker.Imagery.createItem, {AssetPrefix:"Document", AssetObjectType:"LiveDigitalAsset_Document", LibraryAlias:"DocumentLibrary", Params:aParams});
    DOM.Dialog.show(zCreateAssetContainer,'cursor','What would you like to add?','220','155');
    return true;
  },
  duplicateItem:function(aParams) {
    if (aParams.Section=="Offers") {
      var zSelectedItemAliasArray = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath.split("\\");
      var zSelectedItemAlias = zSelectedItemAliasArray[zSelectedItemAliasArray.length-1];
      var zAddToPath = URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\OfferCollectionLibrary\\"+zSelectedItemAlias+"_Collection"
    }
    else {
      var zAddToPath = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath
    }
    LiveAdMaker.duplicateItem(aParams, "", "Image".makeUnique(), "Copy of "+aParams.SelectedItem.DisplayName, {aAddToPath: zAddToPath})
  },
  archiveItem:function(aParams) {
    if(aParams.Section == 'Approvals') {
      var zMoveToPath = URI.User.ItemPath+"\\ContentList\\DigitalAssetLibraryArchive\\AssetLibraryArchive\\ImageryLibraryArchive";
    }
    else {
      var zMoveToPath = (LiveAdMaker.SystemType=="BRAND") ? "intel\\ContentList\\DigitalAssetLibraryArchive\\AssetLibraryArchive\\ImageryLibraryArchive" : URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibraryArchive\\AssetLibraryArchive\\ImageryLibraryArchive";
    }
    aParams.MoveToPath = zMoveToPath;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "CheckUsage", null, true),
      Function: LiveAdMaker.Imagery.archiveItemComplete,
      Params: aParams
    });
  },
  archiveItemComplete:function(aResults, aParams) {
    var MaxCount = aResults.MaxCount;
    var Protected = aResults.Protected;
    var CollectionCount = aResults.CollectionCount;
    var CollectionLink = aResults.CollectionLink;
    var InsertionsCount = aResults.InsertionsCount;
    var InsertionsLink = aResults.InsertionsLink;
    var LocalCampaignsCount = aResults.LocalCampaignsCount;
    var LocalCampaignsLink = aResults.LocalCampaignsLink;
    if(Protected != 'Y') {
      if (CollectionCount>0 || InsertionsCount>0 || LocalCampaignsCount>0) {
        var zMessage = "This asset is currently in use in the following locations:\n\n";
        if(CollectionCount<MaxCount) {
          for (var i=0; i<CollectionLink.length; i++) {
            zMessage += unescape(CollectionLink[i].ObjectName)+" collection\n";
          }
        } else {
          zMessage += CollectionCount+" collections\n";
        }
        if(InsertionsCount<MaxCount) {
          for (var i=0; i<InsertionsLink.length; i++) {
            zMessage += unescape(InsertionsLink[i].ObjectName)+" insertion\n";
          }
        } else {
          zMessage += InsertionsCount+" insertions\n";
        }
        if(LocalCampaignsCount<MaxCount) {
          for (var i=0; i<LocalCampaignsLink.length; i++) {
            zMessage += unescape(LocalCampaignsLink[i].ObjectName)+" local campaign\n";
          }
        } else {
          zMessage += LocalCampaignsCount+" local campaigns\n";
        }
        zMessage += "\nAre you sure you want to archive this asset?";
        if (confirm(zMessage)) {
          LiveAdMaker.archiveItem(aParams, aParams.MoveToPath)
        }
      } else {
        LiveAdMaker.archiveItem(aParams, aParams.MoveToPath)
      }
    } else {
      alert("This asset is protected.")
    }
  },
  Details: {
    init: function(aParams) {
      var aFormType = aParams.FormType || 'Details';
      LiveAdMaker.Assets.Details.CurrentItem = aParams.Item;
      LiveAdMaker.Assets.Details.ContentContainer = aParams.ContentElement;
      DOM.replaceContent(aParams.ContentElement,"");
      FormUI.Request.GetForm(aParams.Item.ItemPath, aFormType, aParams.ContentElement);
      return true;
    },
    refreshInnerBubble: function(){
      var aParams = LiveAdMaker.Imagery.Details.Params;
      LiveAdMaker.Imagery.Details.init(aParams);
      return true;
    }
  },
  addToSection: function(aParams) {
    LiveAdMaker.Imagery.AddToSection.init(aParams);
  },
  AddToSection: {
    init: function(aParams) {
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.AddToItemPath,'GetAssetCollectionJS'),
        Function: LiveAdMaker.Imagery.AddToSection.draw,
        Params: aParams,
        Method: 'POST'
      });
      return true;
    },
    draw: function(aResult,aParams) {
      var regExp = /\\/g;
      var zAddToAssetCollectionContainer = DOM.createElement('div',null,"AddToAssetCollectionContainer");
      var zAddToAssetCollectionTitle = DOM.createElement('div',null,"AddToAssetCollectionTitle");
      zAddToAssetCollectionTitle.innerHTML = aResult.ItemName;
      zAddToAssetCollectionContainer.appendChild(zAddToAssetCollectionTitle);
      var zAssetCollectionToDiv = DOM.createElement('div',null,"AddToAssetCollectionTo");
      zAssetCollectionToDiv.innerHTML = 'To:';
      zAddToAssetCollectionContainer.appendChild(zAssetCollectionToDiv);
      var zAssetCollectionContainer = DOM.createElement('div',null,"AssetCollectionContainer");
      zAddToAssetCollectionContainer.appendChild(zAssetCollectionContainer);
      if(aResult.Items.length > 0) {
        var zAssetCollectionTitle = DOM.createElement('div',null,"AssetCollectionDiv AssetCollectionTitle");
        zAssetCollectionTitle.innerHTML = 'My Materials'
        zAssetCollectionContainer.appendChild(zAssetCollectionTitle);
      };
      aResult.Items.forEach(function(aCollection) {
        if(aCollection.AssetCollection) {
          var zAssetCollectionChecked = ' checked';
        }else{
          var zAssetCollectionChecked = ' ';
        }
        var zAssetCollectionDiv = DOM.createElement('div',null,"AssetCollectionDiv");
        zAssetCollectionDiv.innerHTML = '<input type="checkbox" name="inpAddToAssetCollection" value="'
          +aCollection.ItemPath
          +'" onclick="LiveAdMaker.Imagery.AddToSection.addToCollection(this,\''
          +aCollection.ItemPath.replace(regExp,"\\\\")
          +'\',\''
          +aParams.ItemPath.replace(regExp,"\\\\")
          +'\');"'
          +zAssetCollectionChecked
          +'><span class="AssetCollectionDisplayName">'
          +aCollection.DisplayName
          +'</span>';
        zAssetCollectionContainer.appendChild(zAssetCollectionDiv);
      });
      if(aResult.OfferItems.length > 0) {
        var zOfferCollectionTitle = DOM.createElement('div',null,"AssetCollectionDiv AssetCollectionTitle");
        zOfferCollectionTitle.innerHTML = "Systems";
        zAssetCollectionContainer.appendChild(zOfferCollectionTitle);
      };
      aResult.OfferItems.forEach(function(aOfferCollection) {
        if(aOfferCollection.AssetCollection) {
          var zOfferCollectionChecked = ' checked';
        }else{
          var zOfferCollectionChecked = ' ';
        }
        var zOfferCollectionDiv = DOM.createElement('div',null,"AssetCollectionDiv");
        zOfferCollectionDiv.innerHTML = '<input type="checkbox" name="inpAddToAssetCollection" value="'
          +aOfferCollection.ItemPath
          +'" onclick="LiveAdMaker.Imagery.AddToSection.addToCollection(this,\''
          +aOfferCollection.ItemPath.replace(regExp,"\\\\")
          +'\',\''
          +aParams.ItemPath.replace(regExp,"\\\\")
          +'\');"'
          +zOfferCollectionChecked
          +'><span class="AssetCollectionDisplayName">'
          +aOfferCollection.DisplayName
          +'</span>';
        zAssetCollectionContainer.appendChild(zOfferCollectionDiv);
      });
      DOM.Dialog.show(zAddToAssetCollectionContainer,'center','Add:','275','390');
      return true;
    },
    addToCollection: function(aInput,aCollectionPath,aAssetPath) {
      if(aInput.checked == true){
        aAssetCollectionChecked = 'Y'
      }else{
        aAssetCollectionChecked = 'N'
      }
      Ajax.makeRequest({
        URL: URI.pageURL(aAssetPath,'AddToAssetCollectionJS'),
        Function: LiveAdMaker.Imagery.AddToSection.added,
        Method: 'POST',
        PostValues: {aAssetCollectionChecked:aAssetCollectionChecked,aAssetCollectionPath:aCollectionPath}
      });
      return true;
    },
    added: function(aResult) {
      return true;
    }
  }
}
LiveAdMaker.Imagery.Annotations = {
  init: function(aParams){
    Ajax.makeRequest({
      URL:aParams.Item.ItemPath.toPagePath()+".RequestAnnotations",
      Function: LiveAdMaker.Imagery.Annotations.receiveAnnotations,
      Params:aParams
    });
    return true;
  },
  receiveAnnotations: function(aResult,aParams){
    if(aResult) {
      aParams.CanEdit = aParams.CanEdit || aResult.CanEdit || "Y";
      var zAnnotationsContainer = DOM.createElement("div",null,"AnnotationsContainer");
      var zGeneralNotesContainer = DOM.createElement("div",null,"Annotations_GeneralNotesContainer");
      var zAllPagesContainer = DOM.createElement("div",null,"Annotations_AllPagesContainer");
      zAnnotationsContainer.appendChild(zAllPagesContainer);
      zAnnotationsContainer.appendChild(zGeneralNotesContainer);
      var zGeneralNotesForm = new FormUI.Form(aParams.Item.ItemPath, "Annotations_GeneralNotes", zGeneralNotesContainer);
      var zGeneralNotesInput = zGeneralNotesForm.createLongText(null, null, {
        DefaultValue: "General Asset Notations",
        Value: aResult.GeneralNotes,
        DisplayValue: aResult.GeneralNotes,
        DisplayFormat: "LongText",
        FieldId: "GeneralNotes", Field: "GeneralNote", FieldHeight: "0", FieldLeft: "0", FieldSize: "Standard", FieldTop: "0", FieldType: "Default", FieldWidth: "0",
        Label: "", LabelDefaultText: "", LabelHeight: "0", LabelId: "", LabelLeft: "0", LabelLocation: "", LabelSize: "Custom", LabelTextAlign: "", LabelTop: "0", LabelWidth: "0",
        ReadPropertyPath: ".Text.GeneralNotes.Detail",
        WritePropertyPath: ".Text.GeneralNotes.Detail",
        CanEdit: aParams.CanEdit
      });
      var zGeneralNotesInputElement = zGeneralNotesForm.appendChild(zGeneralNotesInput, zGeneralNotesContainer);
      var zAnnotationsData = {
        AnnotationsContainer: zAnnotationsContainer,
        GeneralNotesContainer: zGeneralNotesContainer,
        GeneralNotesForm: zGeneralNotesForm,
        GeneralNotes: aResult.GeneralNotes,
        AllPagesContainer: zAllPagesContainer,
        PageArray: [],
        CurrentPageIndex: 0,
        AnnotationsArray: aResult.AnnotationsArray.makeUnique("Id")
      };
      aParams.AnnotationsData = zAnnotationsData;
      LiveAdMaker.Imagery.Annotations.AnnotationsData = zAnnotationsData;
      aParams.AnnotationsData.AnnotationsArray.forEach(function(aAnnotation){
        aAnnotation.PageNumber = (aAnnotation.PageNumber) ? parseInt(aAnnotation.PageNumber) : 1;
      });
      if (aParams.ReplaceContent!="N") {
        DOM.replaceContent(aParams.ContentElement, zAnnotationsContainer);
      }
      else {
        aParams.ContentElement.appendChild(zAnnotationsContainer);
      }
      aResult.Data.forEach(function(aAssetData){
        var zPageIndex = zAnnotationsData.PageArray.length;
        var zPageNumber = (zPageIndex+1);
        var zPageContainer = DOM.createElement("div",null,"Annotations_PageContainer");
        var zAssetContainer = DOM.createElement("div",null,"Annotations_AssetContainer");
        var zNotesContainer = DOM.createElement("div",null,"Annotations_NotesContainer");
        var zImage = DOM.createImage(aAssetData.PreviewLargeURL, aAssetData.PreviewLargeWidth, aAssetData.PreviewLargeHeight);
        zAssetContainer.appendChild(zImage);
        zPageContainer.appendChild(zAssetContainer);
        zPageContainer.appendChild(zNotesContainer);
        zAssetContainer.style.width = (parseInt(aAssetData.PreviewLargeWidth)+20) + "px";
        zNotesContainer.style.left = (parseInt(aAssetData.PreviewLargeWidth)+30) + "px";
        if(aParams.CanEdit != "N") {
          DOM.addEvent(zImage, "onclick", LiveAdMaker.Imagery.Annotations.handleAssetClick, aParams);
        }
        zImage.style.margin = "10px";
        var zNotesForm = new FormUI.Form(aParams.Item.ItemPath, "Annotations_NotesForm_"+zPageNumber, zNotesContainer);
        zNotesForm._SectionParams = aParams;
        zAnnotationsData.PageArray.push({
          PageIndex: zPageIndex,
          PageNumber: zPageNumber,
          PageContainer: zPageContainer,
          AssetData: aAssetData,
          AssetContainer: zAssetContainer,
          NotesContainer: zNotesContainer,
          NotesForm: zNotesForm,
          Image: zImage,
          AnnotationsArray: aParams.AnnotationsData.AnnotationsArray.filter(function (aAnnotation) {
            return (aAnnotation.PageNumber == zPageNumber);
          })
        });
      });
      if(zAnnotationsData.PageArray.length > 1) {
        var zPageNavigationContainer = DOM.createElement("div",null,"Annotations_PageNavigationContainer");
        var zPageSelectionLeftArrow = DOM.createElement("div","PageSelectionLeftArrow","Annotations_PageSelectionLefttArrow");
        var zPageSelectionRightArrow = DOM.createElement("div","PageSelectionRightArrow","Annotations_PageSelectionRightArrow");
        zPageNavigationContainer.appendChild(zPageSelectionLeftArrow);
        zPageNavigationContainer.appendChild(zPageSelectionRightArrow);
        zAnnotationsContainer.insertBefore(zPageNavigationContainer, zAllPagesContainer);
        DOM.addEvent(zPageSelectionLeftArrow, "onclick", LiveAdMaker.Imagery.Annotations.decPage, aParams);
        DOM.addEvent(zPageSelectionRightArrow, "onclick", LiveAdMaker.Imagery.Annotations.incPage, aParams);
        zAnnotationsData.PageNavigationContainer = zPageNavigationContainer;
      }
      LiveAdMaker.Imagery.Annotations.selectPage(0,aParams);
    }
    return true;
  },
  selectPage: function(aPageIndex, aParams){
    aPageIndex = aPageIndex || 0;
    aPageIndex = Math.max(aPageIndex, 0);
    aPageIndex = Math.min(aPageIndex, aParams.AnnotationsData.PageArray.length - 1);
    var zPage = aParams.AnnotationsData.PageArray[aPageIndex];
    DOM.replaceContent(aParams.AnnotationsData.AllPagesContainer, zPage.PageContainer);
    aParams.AnnotationsData.CurrentPageIndex = aPageIndex;
    aParams.AnnotationsData.CurrentPage = zPage;
    if(!zPage.AnnotationsDrawn) {
      zPage.ImageCoords = DOM.getAbsolutePosition(zPage.Image);
      zPage.AnnotationsArray.forEach(function(aAnnotation){
        LiveAdMaker.Imagery.Annotations.drawAnnotation(aAnnotation,aParams)
      });
      zPage.AnnotationsDrawn = true;
    }
    return true;
  },
  drawAnnotation: function(aAnnotation, aSectionParams, aFocusInput){
    var zCurrentPage = aSectionParams.AnnotationsData.CurrentPage;
    var zForm = zCurrentPage.NotesForm;
    aAnnotation.Id = aAnnotation.Id || "Note".makeUnique(true);
    aAnnotation.Value = aAnnotation.Value || "";
    aAnnotation.Label = ((aAnnotation.UserName) ? (aAnnotation.UserName+" "+aAnnotation.DisplayDate) : "") || aAnnotation.Label || URI.User.Name + " " + (new Date().dateFormat('mm/dd/yy hh:iia')) + ": ";
    var zAnnotationInput = zForm.createText(null, null, {
      CSVColumnId: "Id",
      CSVRowId: aAnnotation.Id,
      CSVEncoding: "Base64",
      CSVValue: "Value",
      KeepTitleCase: "Y",
      DisplayValue: aAnnotation.Value,
      Value: aAnnotation.Value,
      ReadPropertyPath: ".Text.AnnotationsCSV_Base64.Detail",
      WritePropertyPath: ".Text.AnnotationsCSV_Base64.Detail",
      FieldType: "CSVValue",
      FieldId: aAnnotation.Id, Field: "Note", FieldHeight: "0", FieldLeft: "0", FieldSize: "Standard", FieldTop: "0", FieldWidth: "0",
      Label: aAnnotation.Label, LabelSize: "Custom", LabelWidth: "30", LabelHeight: "3",
      OnChangeFunction: LiveAdMaker.Imagery.Annotations.updateAnnotationValue,
      CanEdit: aSectionParams.CanEdit
    });
    aAnnotation.InputElement = zForm.appendChild(zAnnotationInput, zCurrentPage.NotesContainer);
    aAnnotation.LineElements = [];
    aAnnotation.LineElements.push(LiveAdMaker.Imagery.Annotations.drawLine(aAnnotation, aSectionParams, "#ccc"));
    aAnnotation.LineElements.push(LiveAdMaker.Imagery.Annotations.drawLine(aAnnotation, aSectionParams, "#666", 1));
    var zPushpin = DOM.createElement("div",null,"Annotations_Pushpin");
    zPushpin.style.left = (parseInt(aAnnotation.PreviewLeft)-5) + "px";
    zPushpin.style.top = (parseInt(aAnnotation.PreviewTop)-5) + "px";
    zCurrentPage.PageContainer.appendChild(zPushpin);
    aAnnotation.LineElements.push(zPushpin);
    if(aFocusInput) {
      zForm.focus(zAnnotationInput);
    }
    return true;
  },
  drawLine: function(aAnnotation, aSectionParams, aColor, aAdjust){
    var zInputCoords = DOM.getAbsolutePosition(aAnnotation.InputElement);
    if(!aSectionParams.AnnotationsData.AllPagesCoords) {
      aSectionParams.AnnotationsData.AllPagesCoords = DOM.getAbsolutePosition(aSectionParams.AnnotationsData.AllPagesContainer);
    }
    aAdjust = aAdjust || 0;
    return DOM.Graphics.drawLine(
      (parseInt(aAnnotation.PreviewLeft)+10),
      (parseInt(aAnnotation.PreviewTop)+10+aAdjust),
      (zInputCoords.x - aSectionParams.AnnotationsData.AllPagesCoords.x),
      (zInputCoords.y - aSectionParams.AnnotationsData.AllPagesCoords.y + aAdjust),
      1,
      aSectionParams.AnnotationsData.CurrentPage.PageContainer,
      aColor
    );
  },
  handleAssetClick: function(e,aParams){
    var zCurrentPage = aParams.AnnotationsData.CurrentPage;
    var zX = e.clientX - zCurrentPage.ImageCoords.x + aParams.ContentElement.scrollLeft;
    var zY = e.clientY - zCurrentPage.ImageCoords.y + aParams.ContentElement.scrollTop;
    var zDate = new Date();
    var zAnnotation = {
      Id: "Note".makeUnique(true),
      PreviewSize: "Large",
      PreviewLeft: zX,
      PreviewTop: zY,
      LeftPercent: zX / zCurrentPage.AssetData.PreviewLargeWidth,
      TopPercent: zY / zCurrentPage.AssetData.PreviewLargeHeight,
      PageNumber: zCurrentPage.PageNumber,
      UserName: URI.User.Name,
      Date: zDate.getValue(),
      DisplayDate: zDate.dateFormat('mm/dd/yy hh:iia')
    };
    zAnnotation.Id = "Note".makeUnique(true);
    aParams.AnnotationsData.AnnotationsArray.set(zAnnotation, zAnnotation.Id);
    zCurrentPage.AnnotationsArray.push(zAnnotation, zAnnotation.Id);
    Ajax.makeRequest({
      URL:aParams.Item.ItemPath.toPagePath()+".CreateAnnotation",
      Function: LiveAdMaker.Imagery.Annotations.receiveNewAnnotation,
      Method: "POST",
      PostValues: zAnnotation,
      Params: {
        AnnotationData: zAnnotation,
        SectionParams: aParams,
        Page: zCurrentPage
      }
    });
    return true;
  },
  receiveNewAnnotation: function(aResult,aParams){
    LiveAdMaker.Imagery.Annotations.drawAnnotation(aParams.AnnotationData, aParams.SectionParams, true);
    return true;
  },
  updateAnnotationValue: function(aFormElement, aResults){
    if(aFormElement && aFormElement.Element && aFormElement.Element.Value == "") {
      aFormElement.Element.Form.hide(aFormElement.Element.FieldId, "FieldId");
      var zAnnotation = aFormElement.Element.Form._SectionParams.AnnotationsData.AnnotationsArray.get(aFormElement.Element.FieldId);
      if(zAnnotation) {
        zAnnotation.Removed = "Y";
        zAnnotation.LineElements.forEach(function(aLineElement){
          DOM.removeElement(aLineElement);
        });
      }
    }
    return true;
  },
  incPage: function(e, aParams){
    LiveAdMaker.Imagery.Annotations.selectPage(aParams.AnnotationsData.CurrentPageIndex+1,aParams);
    return true;
  },
  decPage: function(e, aParams){
    LiveAdMaker.Imagery.Annotations.selectPage(aParams.AnnotationsData.CurrentPageIndex-1,aParams);
    return true;
  }
}
    // ---------------------- End Action_LiveAdMaker_Imagery ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_Assets --------------- //
LiveAdMaker.Assets = {
  Name: "Assets",
  QuickSearchOptions: {
    GetSearchCategoriesExtraParams: "aGetFormObjectType=LiveDigitalAsset_Collection",
    SearchObjectTypes: "LiveDigitalAsset_Collection"
  },
  Load: function(aParams) {
    var zSection = LiveAdMaker.Assets;
    var zMakeRequestItemPath = (LiveAdMaker.SystemType=="BRAND") ? "intel\\ContentList\\DigitalAssetLibrary\\CollectionLibrary" : URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\CollectionLibrary";
    var zExtraParams = (LiveAdMaker.SystemType=="BRAND") ? "&aShowGroupCollections=Y&aShowProductCollections=Y" : "&aShowSharedCollections=Y&aShowOfferCollections=Y";
    if(!zSection.Items||zSection.RefreshList) {
      aParams.Redraw = zSection.RefreshList ? true : false;
      zSection.RefreshList = false;
      zSection.SearchObjectItemPath = (LiveAdMaker.SystemType=="BRAND") ? "intel\\ContentList\\DigitalAssetLibrary\\CollectionLibrary" : URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\CollectionLibrary";
      zSection.FilterListItemPath = 'intel\\ContentList\\DigitalAssetLibrary\\CollectionLibrary\\FilterList';
      Ajax.makeRequest({
        URL: URI.pageURL(zMakeRequestItemPath, "GetList", zExtraParams, true),
        Function: LiveAdMaker.receiveSectionData,
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
    }else{
      LiveAdMaker.drawSection(aParams);
    }
    return true;
  },
  getDisabledNavigationArray: function(aList) {
    var zDisabledNavigationArray = [
      {Id: "ImportExportButton", Disabled: "Y"},
      {Id: "ExportButton", Disabled: "Y"}
    ]
    return zDisabledNavigationArray
  },
  createLiveCollectionItem: function(e, aParams) {
    var zSearchText;
    var zSearchCriteria;
    var zFilterOptionContainer_Save = DOM.createElement("div","LC_FilterOptionContainer_Save","FilterOptionContainer FilterOptionSave");
    var aSearchResultsCSV = new Array();
    var zSearchSplit;
    var aOriginalItemPath = aParams.Params.StartItemPath;
    var zSearchResults = "\"Phrase\",\"Category\",\"MatchType\"<br />";
    for (var i = 0;i < aParams.Params.SearchResults.length;i++){
      if (aParams.Params.SearchResults[i].Path){
        zSearchSplit = aParams.Params.SearchResults[i].Path;
        zSearchText  = zSearchSplit.split(",");
        zSearchCriteria = "Filter Criteria";
        for (var z = 0;z < zSearchText.length;z++){
          zSearchResults += "\"" + zSearchText[z] + "\"," + "\"" + zSearchCriteria + "\",\"equalto\"<br />";
        }
      }
      else {
        zSearchText = aParams.Params.SearchResults[i].SearchText;
        zSearchCriteria = aParams.Params.SearchResults[i].SearchCriteria;
        if (!zSearchCriteria){
          zSearchCriteria = "Name";
        }
        zSearchResults += "\"" + zSearchText + "\"," + "\"" + zSearchCriteria + "\",\"startswith\"<br />";
      }
    }
    LiveAdMaker.Assets.createCollectionItem(e, aParams, zSearchResults, aOriginalItemPath);
  },
  createCollectionItem: function(e, aParams, aSearchResults, aOriginalItemPath) {
    DOM.Dialog.hide();
    aParams.Section = "Assets";
    var zCollectionItemPath = (LiveAdMaker.SystemType=="BRAND") ? "intel\\ContentList\\DigitalAssetLibrary\\CollectionLibrary" : URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\CollectionLibrary";
    LiveAdMaker.createNewItem(aParams, zCollectionItemPath,aParams.AssetPrefix.makeUnique(), aParams.AssetPrefix+" Collection "+LiveAdMaker.SelectedSection.Items.length, aParams.CollectionObjectType, { aDefaultLanguage: URI.User.Language,  aCollectionType: aParams.CollectionType, aSearchResults: aSearchResults, aOriginalItemPath: aOriginalItemPath});
    return true
  },
  createNewItem: function(aParams, aDefaultLanguage) {
    var zCollectionItemPath = (LiveAdMaker.SystemType=="BRAND") ? "intel\\ContentList\\DigitalAssetLibrary\\CollectionLibrary" : URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\CollectionLibrary";
    var zCreateAssetContainer = DOM.createElement("div","","CreateAssetContainer","");
    var zBrandLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zBrandLink = DOM.createElement("a","","CreateAssetLink","");
    zBrandLink_Container.appendChild(zBrandLink);
    zCreateAssetContainer.appendChild(zBrandLink_Container);
    zBrandLink.href = "javascript:void(0)";
    zBrandLink.innerHTML = "Brand";
    DOM.addEvent(zBrandLink, "onclick", LiveAdMaker.Assets.createCollectionItem, {AssetPrefix:"Brand", CollectionObjectType:"LiveDigitalAsset_Collection", CollectionType:"Brand", Params:aParams});
    var zLocalLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zLocalLink = DOM.createElement("a","","CreateAssetLink","");
    zLocalLink_Container.appendChild(zLocalLink);
    zCreateAssetContainer.appendChild(zLocalLink_Container);
    zLocalLink.href = "javascript:void(0)";
    zLocalLink.innerHTML = "Local";
    DOM.addEvent(zLocalLink, "onclick", LiveAdMaker.Assets.createCollectionItem, {AssetPrefix:"Local", CollectionObjectType:"LiveDigitalAsset_Collection", CollectionType:"Local", Params:aParams});
    DOM.Dialog.show(zCreateAssetContainer,'cursor','Select a Type:','220','150');
    return true;
  },
  duplicateItem:function(aParams) {
    var zCopyToPath = (LiveAdMaker.SystemType=="BRAND") ? "intel\\ContentList\\DigitalAssetLibrary\\CollectionLibrary" : URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibrary\\CollectionLibrary";
    if (confirm('Do you want to make a copies of all the assets in this collection and link them to the new collection, or do you want to link the existing assets to the new collection?\n\n To make copies of all the assets click \'OK\'.\n\nTo link the existing assets click \'Cancel\'.')) {
      zCopyAssets = "Y"
    }
    else {
      zCopyAssets = "N"
    }
    LiveAdMaker.duplicateItem(aParams, zCopyToPath, "Collection".makeUnique(), "Copy of "+aParams.SelectedItem.DisplayName, {aCopyAssets:zCopyAssets})
  },
  archiveItem: function(aParams) {
    var zMoveToPath = (LiveAdMaker.SystemType=="BRAND") ? "intel\\ContentList\\DigitalAssetLibraryArchive\\CollectionLibraryArchive" : URI.User.CompanyItemPath+"\\ContentList\\DigitalAssetLibraryArchive\\CollectionLibraryArchive";
    aParams.MoveToPath = zMoveToPath;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "CheckUsage", null, true),
      Function: LiveAdMaker.Assets.archiveItemComplete,
      Params: aParams
    });
  },
  archiveItemComplete:function(aResults, aParams) {
    var MaxCount = aResults.MaxCount;
    var Protected = aResults.Protected;
    var CampaignsCount = aResults.CampaignsCount;
    var CampaignsLink = aResults.CampaignsLink;
    var LocalCampaignsCount = aResults.LocalCampaignsCount;
    var LocalCampaignsLink = aResults.LocalCampaignsLink;
    var LocalCollectionCount = aResults.LocalCollectionCount;
    var LocalCollectionLink = aResults.LocalCollectionLink;
    if(Protected != 'Y') {
      if (CampaignsCount>0 || LocalCampaignsCount>0 || LocalCollectionCount>0) {
        var zMessage = "This collection is currently in use in the following locations:\n\n";
        if(CampaignsCount<MaxCount) {
          for (var i = 0; i < CampaignsLink.length; i++) {
            zMessage += unescape(CampaignsLink[i].ObjectName)+" campaign\n"
          }
        } else {
          zMessage += CampaignsCount+" campaigns"+"\n"
        }
        if(LocalCampaignsCount<MaxCount) {
          for (var i = 0; i < LocalCampaignsLink.length; i++) {
            zMessage += unescape(LocalCampaignsLink[i].ObjectName)+" local campaign\n"
          }
        } else {
          zMessage += LocalCampaignsCount+" local campaigns"+"\n"
        }
        if(LocalCollectionCount<MaxCount) {
          for (var i = 0; i < LocalCollectionLink.length; i++) {
            zMessage += unescape(LocalCollectionLink[i].ObjectName)+" local collection\n"
          }
        } else {
          zMessage += LocalCampaignsCount+" local collections\n"
        }
        zMessage += "\nAre you sure you want to archive this collection?";
        if (confirm(zMessage)) {
          LiveAdMaker.archiveItem(aParams, aParams.MoveToPath)
        }
      } else {
        LiveAdMaker.archiveItem(aParams, aParams.MoveToPath)
      }
    } else {
      alert("This collection is protected.")
    }
  },
  addToSection: function(aParams) {
    LiveAdMaker.Assets.AddToSection.init(aParams);
  },
  ImportExportElementCounter: 2,
  exportSectionItem: function(aParams){
    var zExportTextContainer = DOM.createElement("div","ExportDiv","","text-align:center\;padding:3px\;");
    zExportTextContainer.innerHTML = "<img src=\"\/l.c.bin\/I\/912\/Export.gif\" border=0> <a href=\"javascript: void(0)\;\">Export materials to FTP site</a>";
    zExportTextContainer.onclick = function() {
      LiveAdMaker.Assets.exportAssetsToFTP(zExportTextContainer, aParams);
    }
    DOM.Dialog.show(zExportTextContainer,'center','Export','175','');
    return true;
  },
  exportAssetsToFTP: function(aDialogContainer, aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.List.ItemArray.filter(function(aItem){
      return (aItem.Id==LiveAdMaker.SelectedSection.List.SelectedItemId);
    });
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem[0].ItemPath,'CreateOrderFTPAccount'),
      Function: LiveAdMaker.Assets.confirmAssetsExport,
      Params: {DialogContainer: aDialogContainer, Params: aParams},
      Method: 'POST'
    });
    return true;
  },
  confirmAssetsExport: function(aResults, aParams){
    var zExportTextContainer = aParams.DialogContainer;
    if (aResults && aResults.Success && isTrue(aResults.Success)){
      if (parseFloat(aResults.FailedUploads) > 0 && parseFloat(aResults.FailedUploads) < parseFloat(aResults.TotalFiles)){
        zExportTextContainer.innerHTML = aResults.ResponseText;
        zExportTextContainer.innerHTML += "You will be sent an email with FTP information to download all of the assets from this order.";
      } else {
        zExportTextContainer.innerHTML = "You will be sent an email with FTP information to download all of the assets from this order.";
      }
    }else{
      if (parseFloat(aResults.FailedUploads) > 0 && parseFloat(aResults.FailedUploads) >= parseFloat(aResults.TotalFiles)){
        zExportTextContainer.innerHTML = aResults.ResponseText;
        zExportTextContainer.innerHTML += "There was an error creating the FTP account. Please contact LiveAdMaker support.";
      } else {
        zExportTextContainer.innerHTML = "There was an error creating the FTP account. Please contact LiveAdMaker support.";
      }
    }
    return true;
  },
  checkCollectionType: function(aParams){
    if(aParams.Element.Value == 'Local' && aParams.Input.value == 'Brand') {
      if(confirm("You will remove all empty local collections by changing the collection type to Brand. Are you sure you want to change the collection type?")) {
        return true;
      } else {
        aParams.Input.options[1].selected = true;
        return false;
      }
    } else {
      return true;
    }
  },
  importexportSectionItem: function(aParams){
    LiveAdMaker.Assets.ImportExportElementCounter = 2;
    if ($("ImportExportAssetsContainer")){
      $("ImportExportAssetsContainer").innerHTML="";
      var zImportExportAssetsContainer = $("ImportExportAssetsContainer");
    }else{
      var zImportExportAssetsContainer = DOM.createElement("div","ImportExportAssetsContainer","ImportExportAssetsContainer","");
    }
    DOM.Dialog.showForm(zImportExportAssetsContainer,'center','Import Assets','450','550','ImportAssets',aParams.ImportExportToItemPath);
    return true;
  },
  replaceTextOnSave: function(aParams) {
    if (RTE.replaceTextList.length>0 && aParams.Input.value!="") {
      aParams.Input.value = RTE.replaceTextOnSave(aParams.Input.value);
    }
    return true;
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Assets.Details.init(aParams);
        return true;
      }
    },
    {
      Id: "Imagery",
      DisplayName: "Materials",
      DisplayFunction: function(aParams) {
        aParams.AssetType = "LiveDigitalAsset_Image";
        aParams.Collection = aParams.Item.Id.replace(/Object/,'');
        aParams.SearchObjectItemPath = aParams.Item.ItemPath;
        aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetList", "", true)
        var aLightboxDisplayParams = {};
        aLightboxDisplayParams.PrimaryFunction = List.displayAssetPreview;
        aLightboxDisplayParams.PrimaryText = "Preview";
        aLightboxDisplayParams.PrimaryDescription = "Preview Asset";
        aLightboxDisplayParams.SecondaryText = "Options";
        aLightboxDisplayParams.SecondaryDescription = "Click for Options";
        var zLightboxDisplayObject = Util.Object.create(List.LightboxView.DisplayObject, aLightboxDisplayParams);
        zLightboxDisplayObject.displayLightboxSecondaryLink = function(aItem, aParams) {
          if (aItem.Asset_URL) {
            this.SecondaryFunction = LiveAdMaker.Assets.Imagery.secondaryLightboxFunction
          } else {
            this.SecondaryFunction = ""
          }
          return zLightboxDisplayObject.parent.displayLightboxSecondaryLink.call(this, aItem);
        }
        aParams.LightboxDisplayObject = zLightboxDisplayObject;
        aParams.FetchedLightboxData = true;
        LiveAdMaker.requestSubItems(aParams);
        LiveAdMaker.Assets.Imagery.init(aParams);
        return true;
      }
    },
    {
      Id: "Groups",
      DisplayName: "Groups",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Assets.Groups.init(aParams);
        return true;
      }
    }
  ]
};
LiveAdMaker.Assets.AddToSection = {
  init: function(aParams){
    LiveAdMaker.Assets.AddToSection.draw(aParams);
    return true;
  },
  draw: function(aParams){
    var zAssetAddToSectionContainer = DOM.createElement('div',null,"AssetAddToSectionContainer");
    var zSearchAssetsDiv = DOM.createElement('div',null,"SearchAssetsDiv");
    zAssetAddToSectionContainer.appendChild(zSearchAssetsDiv);
    var zAssetTypeDropDown = DOM.createElement('span',null,"AssetTypeDropDown");
    zAssetTypeDropDown.innerHTML = '<select id="inpAssetType" name="inpAssetType"><option value="all">All</option><option value="imagery">Imagery</option><option value="video">Video</option><option value="audio">Audio</option><option value="copy">Copy</option><option value="legal">Legal</option></select>';
    zSearchAssetsDiv.appendChild(zAssetTypeDropDown);
    var zAssetSearchInput = DOM.createElement("input","inpAssetSearchText","AssetSearchInput");
    zAssetSearchInput.setAttribute("name","inpAssetSearchText");
    zAssetSearchInput.setAttribute("type","text");
    zAssetSearchInput.setAttribute("value","");
    zSearchAssetsDiv.appendChild(zAssetSearchInput);
    var zAssetSearchButton = DOM.createElement("input",null,"AssetSearchButton");
    zAssetSearchButton.setAttribute("name","AssetSearchButton");
    zAssetSearchButton.setAttribute("type","button");
    zAssetSearchButton.setAttribute("value","Search");
    zSearchAssetsDiv.appendChild(zAssetSearchButton);
    var zSearchResultsTextDiv = DOM.createElement('div',null,"SearchResultsTextDiv");
    zAssetAddToSectionContainer.appendChild(zSearchResultsTextDiv);
    var zSearchResultsDiv = DOM.createElement('div',null,"SearchResultsDiv");
    zAssetAddToSectionContainer.appendChild(zSearchResultsDiv);
    DOM.addEvent(zAssetSearchInput, "onkeydown", LiveAdMaker.Assets.AddToSection.search, {AssetCollectionItemPath:aParams.AddToItemPath,AssetTypeInput:"inpAssetType",AssetSearchTextInput:"inpAssetSearchText",AssetSearchTextContainer:zSearchResultsTextDiv,AssetSearchResultContainer:zSearchResultsDiv});
    DOM.addEvent(zAssetSearchButton,"onclick",LiveAdMaker.Assets.AddToSection.search,{AssetCollectionItemPath:aParams.AddToItemPath,AssetTypeInput:"inpAssetType",AssetSearchTextInput:"inpAssetSearchText",AssetSearchTextContainer:zSearchResultsTextDiv,AssetSearchResultContainer:zSearchResultsDiv});
    DOM.Dialog.show(zAssetAddToSectionContainer,'center','Search Assets:','500','450');
    return true;
  },
  search: function(e,aParams){
    if(e.keyCode == 13 || e.type == 'click'){
      var zAssetType = $(aParams.AssetTypeInput).value;
      var zAssetSearchText = $(aParams.AssetSearchTextInput).value;
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.AssetCollectionItemPath, "GetAssets", null, true),
        Function: LiveAdMaker.Assets.AddToSection.receiveSearchResults,
        Method: "POST",
        PostValues: {aAssetType:zAssetType,aOutputType:'JSON',aSearchCollection:'N',aSearchName:zAssetSearchText,aLimitResultsTo:"200"},
        Params: aParams
      });
    }
    return true;
  },
  receiveSearchResults: function(aResult,aParams){
    var regExp = /\\/g;
    aAssetCollectionItemPath = aResult.ItemPath;
    aAssetSearchTotalResults = aResult.TotalResults;
    aResult = aResult.Data;
    if(aResult) {
      aParams.AssetSearchTextContainer.innerHTML = '';
      aParams.AssetSearchResultContainer.innerHTML = '';
      var zSearchResultsText = DOM.createElement('span',null,"SearchResultsText");
      if(aAssetSearchTotalResults < 200) {
        zSearchResultsText.innerHTML = 'Your search returned '+aResult.length+' results.';
      }else{
        zSearchResultsText.innerHTML = 'Your search returned more than 200 results. Please refine your search.';
      }
      aParams.AssetSearchTextContainer.appendChild(zSearchResultsText);
      aResult.forEach(function(aAsset) {
        var zSearchResultAssetDiv = DOM.createElement('div',null,"SearchResultsAssetDiv");
        aParams.AssetSearchResultContainer.appendChild(zSearchResultAssetDiv);
        var zSearchResultAssetImageDiv = DOM.createElement('div',null,"SearchResultAssetImageDiv");
        zSearchResultAssetDiv.appendChild(zSearchResultAssetImageDiv);
        var zAssetPreview = DOM.createElement('img');
        if(aAsset.ImageUrl) {
          zAssetPreview.setAttribute('src', aAsset.ImageUrl);
          if(aAsset.ImageHeight) {
            zAssetPreview.setAttribute('height', aAsset.ImageHeight);
          }
          if(aAsset.ImageWidth) {
            zAssetPreview.setAttribute('width', aAsset.ImageWidth);
          }
        }else{
          zAssetPreview.setAttribute('src', FormUI.AssetUtil.aNoPreviewURL);
        }
        zSearchResultAssetImageDiv.appendChild(zAssetPreview);
        if(aAsset.AssetCollection){
          var zAssetChecked = 'checked';
        }else{
          var zAssetChecked = '';
        }
        var zSearchResultAssetData = DOM.createElement('div',null,"SearchResultAssetData");
        zSearchResultAssetData.innerHTML = '<input type="checkbox" name="inpAddToAssetCollection" value="'
          +aAsset.ItemPath
          +'" onclick="LiveAdMaker.Imagery.AddToSection.addToCollection(this,\''
          +aAssetCollectionItemPath.replace(regExp,"\\\\")
          +'\',\''
          +aAsset.ItemPath.replace(regExp,"\\\\")
          +'\');"'
          +zAssetChecked
          +'><span class="SearchResultAssetName">'
          +aAsset.DisplayName
          +'</span>';
        zSearchResultAssetDiv.appendChild(zSearchResultAssetData);
      });
    }
    return true;
  }
};
LiveAdMaker.Assets.Details = {
  init: function(aParams) {
    LiveAdMaker.Assets.Details.CurrentItem = aParams.Item;
    LiveAdMaker.Assets.Details.ContentContainer = aParams.ContentElement;
    FormUI.Request.getForm(aParams.Item.ItemPath, 'Details', aParams.ContentElement, '', {OnDisplayFunction: LiveAdMaker.Assets.Details.getTopAssets, OnDisplayParams: aParams});
    return true;
  },
  getTopAssets: function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Assets.List.SelectedItem.ItemPath,'GetTopAssets'),
      Function: LiveAdMaker.Assets.Details.draw,
      Params: aParams,
      Method: 'POST',
      PostValues: {aOutputType:'JSON',aLanguage:URI.User.Language,aLimitResultsTo:'1000',aGetAssetTypeData:'Y',aGetProperThumbnails:'Y'}
    });
    return true;
  },
  draw: function(aResult,aParams) {
    var zAssetCount = 0;
    var zAssetDrawn = 0;
    var zSharedCollection = aResult.Shared;
    aResult = aResult.Data || aResult.Items;
    if(aResult) {
      var zAssetCollectionTable = DOM.createElement('table',null,"FormUI-AssetCollectionTable");
      aParams.ContentElement.appendChild(zAssetCollectionTable);
      zAssetCollectionTable.style.clear = 'both';
      zAssetCollectionTable.style.padding = '5px 5px 5px 5px';
      var zAssetCollectionTableBody = DOM.createElement('tbody',null,"FormUI-AssetCollectionTBody");
      zAssetCollectionTable.appendChild(zAssetCollectionTableBody);
      var zFirstAssetTR = DOM.createElement('tr',null,"FormUI-AssetCollectionTR");
      zAssetCollectionTableBody.appendChild(zFirstAssetTR);
      var zSecondAssetTR = DOM.createElement('tr',null,"FormUI-AssetCollectionTR");
      zAssetCollectionTableBody.appendChild(zSecondAssetTR);
      var aShowAssetOptions = true;
      if(aParams.ShowAssetOptions == 'N') {
        aShowAssetOptions = false;
      }
      while(zAssetCount<aResult.length){
        if(aResult[zAssetCount] && zAssetDrawn<5) {
          if(aResult[zAssetCount].ImageUrl || aResult[zAssetCount].ObjectType == 'LiveDigitalAsset_Audio') {
            aParams.drawPreviewLink = 'N';
            aParams.drawVideoPreviewLink = 'N';
            aParams.drawFlashPreviewLink = 'N';
            aParams.drawEditRequiredLengthLink = 'N';
            aParams.drawReThumbnailLink = 'N';
            aParams.drawEditRequiredAreaLink = 'N';
            aParams.drawSendAssetLink = 'N';
            var zShowAssetOptions = aShowAssetOptions;
            if(aResult[zAssetCount].ObjectType == 'LiveDigitalAsset_Legal' || aResult[zAssetCount].ObjectType == 'LiveDigitalAsset_RichText' || aResult[zAssetCount].ObjectType == 'WhyBuy') {
              zShowAssetOptions = false;
            }
            if(aResult[zAssetCount].DisableUpload) {
              aParams.DisableUpload = aResult[zAssetCount].DisableUpload;
            }
            if(aResult[zAssetCount].FileItemPath) {
              aParams.FileItemPath = aResult[zAssetCount].FileItemPath;
            }
            if(aResult[zAssetCount].ObjectType) {
              aParams.AssetType = aResult[zAssetCount].ObjectType.replace('LiveDigitalAsset_','');
            }
            if(aResult[zAssetCount].ObjectType=='LiveDigitalAsset_Image' || aResult[zAssetCount].ObjectType=='WhyBuy_Image' || aResult[zAssetCount].ObjectType=='BaseImagery') {
              aParams.drawPreviewLink = 'Y';
              aParams.drawReThumbnailLink = 'Y';
              aParams.drawEditRequiredAreaLink = 'Y';
              aParams.drawSendAssetLink = 'Y';
            }
            if(aResult[zAssetCount].ObjectType=='LiveDigitalAsset_Audio' || aResult[zAssetCount].ObjectType=='BaseAudio') {
              aParams.drawVideoPreviewLink = 'Y';
              aParams.drawSendAssetLink = 'Y';
            }
            if(aResult[zAssetCount].ObjectType=='LiveDigitalAsset_Video' || aResult[zAssetCount].ObjectType=='BaseVideo') {
              aParams.drawVideoPreviewLink = 'Y';
              aParams.drawReThumbnailLink = 'Y';
              aParams.drawEditRequiredLengthLink = 'Y';
              aParams.drawSendAssetLink = 'Y';
            }
            if (aResult[zAssetCount].ObjectType=='LiveDigitalAsset_Flash' || aResult[zAssetCount].ObjectType=='BaseFlash'){
              aParams.drawFlashPreviewLink = 'Y';
              aParams.drawSendAssetLink = 'Y';
            }
            if (aResult[zAssetCount].ObjectType=='LiveDigitalAsset_Document' || aResult[zAssetCount].ObjectType=='BaseDocument'){
              aParams.drawSendAssetLink = 'Y';
            }
            if ((aResult[zAssetCount].AssetSystemType=="BRAND" && LiveAdMaker.SystemType!="BRAND") || aResult[zAssetCount].AssetType=="ORDER") {
              aParams.drawEditRequiredAreaLink = 'N';
              aParams.drawEditRequiredLengthLink = 'N';
              aParams.drawReThumbnailLink = 'N';
              aParams.DisableUpload = 'Y';
            }
            if(zAssetCount == 0) {
              var zMainAssetTD = DOM.createElement('td','FormUI-MainAssetCollectionTD','FormUI-MainAssetCollectionTD');
              zMainAssetTD.rowSpan = 2;
              zMainAssetTD.setAttribute("align","center");
              zFirstAssetTR.appendChild(zMainAssetTD);
              var zImageURL = aResult[zAssetCount].ImageUrlMedium;
              var zImageHeight = aResult[zAssetCount].ImageHeightMedium;
              var zImageWidth = aResult[zAssetCount].ImageWidthMedium;
              var zImageSize = 'Medium';
              aParams.AssetPreviewContainer = zMainAssetTD;
              var zAssetContainerId = 'FormUI-MainAssetCollectionTD';
            }else{
              var zAssetTD = DOM.createElement('td','FormUI-AssetCollectionTD-'+zAssetCount,'FormUI-AssetCollectionTD');
              zAssetTD.setAttribute("align","center");
              if(zAssetCount < 3) {
                zFirstAssetTR.appendChild(zAssetTD);
              }else{
                zSecondAssetTR.appendChild(zAssetTD);
              }
              var zImageURL = aResult[zAssetCount].ImageUrl;
              var zImageHeight = aResult[zAssetCount].ImageHeight;
              var zImageWidth = aResult[zAssetCount].ImageWidth;
              var zImageSize = 'Small';
              aParams.AssetPreviewContainer = zAssetTD;
              var zAssetContainerId = 'FormUI-AssetCollectionTD-'+zAssetCount;
            }
            aParams.aItemId = aResult[zAssetCount].Id;
            aParams.aItemPath = aResult[zAssetCount].ItemPath;
            aParams.aAssetOwnerContainerId = zAssetContainerId;
            aParams.aAssetPreviewURL = zImageURL;
            aParams.aAssetDisplayName = aResult[zAssetCount].DisplayName;
            aParams.aAssetOptions = zShowAssetOptions;
            aParams.aHideFromContainer = aParams.ContentElement;
            aParams.aAssetPreviewHeight = zImageHeight;
            aParams.aAssetPreviewWidth = zImageWidth;
            aParams.aAssetPreviewSize = zImageSize;
            aParams.aDoNotPollImage = true;
            aParams.aNoBorder = '';
            aParams.aCenterAssetTable = '';
            aParams.aDrawFileUploadInput = 'Y';
            if (zSharedCollection == 'Y'){
              aParams.ShowViewLinksOnly = 'Y';
            }
            aParams.aAssetData = aResult[zAssetCount];
            FormUI.AssetUtil.drawAsset(aParams);
            zAssetDrawn++;
          }
        }
        zAssetCount++;
      }
    }
  }
}
LiveAdMaker.Assets.AdStyles = {
  init: function(aParams) {
    LiveAdMaker.Assets.AdStyles.CurrentItem = aParams.Item;
    LiveAdMaker.Assets.AdStyles.ContentContainer = aParams.ContentElement;
    FormUI.Request.GetForm(aParams.Item.ItemPath, 'AdStyles', aParams.ContentElement);
    return true;
  }
}
LiveAdMaker.Assets.Groups = {
  init: function(aParams) {
    LiveAdMaker.Assets.Groups.CurrentItem = aParams.Item;
    LiveAdMaker.Assets.Groups.ContentContainer = aParams.ContentElement;
    FormUI.Request.GetForm(aParams.Item.ItemPath, 'Groups', aParams.ContentElement);
    return true;
  }
}
LiveAdMaker.Assets.Imagery = {
  CurrentItem: null,
  ContentElement: null,
  AssetList: null,
  DisplayListIcons: 'Y',
  QuickSearchOptions: {
    GetSearchCategoriesExtraParams: "aGetFormObjectType=LiveDigitalAsset_Asset",
    SearchObjectTypes: "LiveDigitalAsset_Image,LiveDigitalAsset_Audio,LiveDigitalAsset_Video,LiveDigitalAsset_RichText,LiveDigitalAsset_Legal,LiveDigitalAsset_Flash,LiveDigitalAsset_Document"
  },
  init: function(aParams) {
    aParams.DisabledNavigationArray = [
      {Id: "ImportExportButton", Disabled: "Y"},
      {Id: "ExportButton", Disabled: "Y"}
    ];
    return true;
  },
  getActions: function(){
    return LiveAdMaker.Imagery.Actions;
  },
  draw: function(aParams) {
  },
  archiveItem: function(aParams) {
    LiveAdMaker.Imagery.archiveItem(aParams);
    return true;
  },
  secondaryLightboxFunction: function(e, aParams) {
    var zItem = aParams.Item;
    var zAssetOptionsContainer = DOM.createElement("div","","AssetOptionsContainer","");
    if (zItem.Asset_URL) {
      var zDownloadHiRes_Container = DOM.createElement("div","","AssetOptionsLinkContainer","");
      var zDownloadHiRes_Link = DOM.createElement("a","","AssetOptionsLink","");
      zDownloadHiRes_Container.appendChild(zDownloadHiRes_Link);
      zAssetOptionsContainer.appendChild(zDownloadHiRes_Container);
      zDownloadHiRes_Link.href = "/l.a/get/?cid=Live-intel&ru=" + URI.Track.LastPage + "&sr=" +URI.Track.ScreenRes + "&u=" + escape(zItem.DisplayName) + "&tu=" + zItem.Asset_URL + escape("?_LCforcesave=Y");
      zDownloadHiRes_Link.innerHTML = "Hi-Res (" + Util.formatFileSize(zItem.Asset_FileSize) + ")";
      zDownloadHiRes_Link.target = "_blank";
    }
    if (zItem.Asset_LowRes_URL && zItem.Type != "LiveDigitalAsset_Video") {
      var zDownloadLowRes_Container = DOM.createElement("div","","AssetOptionsLinkContainer","");
      var zDownloadLowRes_Link = DOM.createElement("a","","AssetOptionsLink","");
      zDownloadLowRes_Container.appendChild(zDownloadLowRes_Link);
      zAssetOptionsContainer.appendChild(zDownloadLowRes_Container);
      zDownloadLowRes_Link.href = "/l.a/get/?cid=Live-intel&ru=" + URI.Track.LastPage + "&sr=" +URI.Track.ScreenRes + "&u=" + escape(zItem.DisplayName) + "&tu=" + zItem.Asset_LowRes_URL + escape("?_LCforcesave=Y");
      zDownloadLowRes_Link.innerHTML = "Low-Res (" + Util.formatFileSize(zItem.Asset_LowRes_FileSize) + ")";
      zDownloadLowRes_Link.target = "_blank";
    }
    var zAssetOption_SendAsset_Container = DOM.createElement("div","","AssetOptionsLinkContainer","");
    var zAssetOption_SendAsset_Link = DOM.createElement("a","","AssetOptionSendAssetLink","");
    zAssetOption_SendAsset_Container.appendChild(zAssetOption_SendAsset_Link);
    zAssetOptionsContainer.appendChild(zAssetOption_SendAsset_Container);
    zAssetOption_SendAsset_Link.href = "javascript:void(0)";
    zAssetOption_SendAsset_Link.innerHTML = "Send Asset"
    DOM.addEvent(zAssetOption_SendAsset_Container,"onclick",FormUI.AssetUtil.Handler.AssetOptionsSendAsset,zItem);
    DOM.Dialog.show(zAssetOptionsContainer,'cursor','Download','180','80');
    return true;
  }
}
LiveAdMaker.ActivityUtil = {
  getActvity: function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.ItemPath, "GetApprovalActivityLog", "aOutputType=JSON", true),
      Function: LiveAdMaker.ActivityUtil.drawActivity,
      Params: aParams,
      Method:'POST'
    });
  },
  drawActivity: function(aResult,aParams) {
    var zActivities = aResult.Activities;
    if(zActivities.length > 0) {
      zMessageDiv = "";
      var zContent="";
      var count=0;
      var i;
      var zMessage="<tr><td colspan=2 bgcolor='#99CCFF'>No Comment</td></tr>";
      zActivities.forEach(function(aActivity) {
      if (count%2 == 0){
       i="class='Table_ActivityContent_Odd'";
      }else {
       i="class='Table_ActivityContent_Even'";
      }
      if (aActivity.Action){
        if (aActivity.Message){
          zMessage = "<tr><td colspan=2 bgcolor='#99CCFF'>"+aActivity.Message+"</td></tr>"
        }
        zContent += "<tr "+i+"><td>"+aActivity.Date+"</td><td>"+aActivity.Action+"</td></tr>"+zMessage;
        count++;
      }
      });
      zContent = "<table class='MessageText' id='Activity'><tr class='Table_ActivityTitle'><th>Date</th><th>Action</th></tr>"+zContent+"</table>";
    aParams.ContentElement.innerHTML=zContent;
    } else {
       var zMessageDiv = DOM.createElement("p","","MessageText","font-weight:bold;color:#808080;font-size: 12px;margin-top:0;");
      zMessageDiv.innerHTML = "No Activities";
      aParams.ContentElement.appendChild(zMessageDiv);
    }
    return true;
  }
}
LiveAdMaker.Assets.Review = {
  get: function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.ItemPath, "GetAssetDataNewUI", "", true),
      Function: LiveAdMaker.Assets.Review.draw,
      Params: aParams,
      Method:'POST'
    });
  },
  draw: function(aResult,aParams){
    var aResults = aResult.Data[0];
    var zAssetReviewContainer = DOM.createElement('div','AssetReviewContainer','AssetReviewContainer');
    aParams.ContentElement.appendChild(zAssetReviewContainer);
    aParams.aItemId = 'AssetReview';
    aParams.aAssetOwnerContainerId = 'AssetReviewContainer';
    aParams.aAssetPreviewURL = aResults.PreviewLargeURL;
    aParams.aAssetOptions = false;
    aParams.aAssetPreviewHeight = aResults.PreviewLargeHeight;
    aParams.aAssetPreviewWidth = aResults.PreviewLargeWidth;
    aParams.aAssetPreviewSize = 'Large';
    aParams.aDoNotPollImage = true;
    aParams.aNoBorder = 'Y';
    aParams.aCenterAssetTable = 'N';
    aParams.aDrawFileUploadInput = 'N';
    aParams.aAssetData = aResults;
    FormUI.AssetUtil.drawAsset(aParams);
    return true;
  },
  approve: function(e,aParams){
    aParams.ReviewStatus = 'Approved';
    LiveAdMaker.Assets.Review.setStatus(aParams);
    return true;
  },
  reject: function(e,aParams){
    aParams.ReviewStatus = 'Rejected';
    LiveAdMaker.Assets.Review.setStatus(aParams);
    return true;
  },
  setStatus: function(aParams) {
    aParams.ContentElement = aParams.Element.Form.ContentElement;
    aParams.ItemPath = aParams.Element.Form.ItemPath;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.ItemPath, "SetAssetReview", "aOutputType=JSON&aReviewStatus="+aParams.ReviewStatus, true),
      Function: LiveAdMaker.Assets.Review.complete,
      Params: aParams,
      Method:'POST'
    });
    return true;
  },
  complete: function(aResult,aParams){
    aParams.Element.Form.ElementArray.forEach(function(aFormItem){
      if (aFormItem.FieldId == 'AssetReviewStatus'){
        if(aResult.ReviewStatus) {
          aFormItem.DisplayValue = aResult.ReviewStatus;
          $(aFormItem.ElementId).innerHTML = aResult.ReviewStatus;
        }
      }
    });
    return true;
  }
}
LiveAdMaker.Assets.Requiredlength = {
  fLeftPos: 0,
  fRightPos: 0,
  fDuration: 0,
  fCurrentStart: 0,
  fCurrentEnd: 0,
  fFirstTimeVar: 0,
  FormId: null,
  FormParams: null,
  agent:  navigator.userAgent.toLowerCase(),
  mediaplayerVersion: 0,
  init:function(){
  },
  runReImage: function(aParams,aThumbnailContainer,aMessageContainer) {
    var zNoThumbnailContainer = $(aThumbnailContainer);
    var zNoThumbnailMessageContainer = $(aMessageContainer);
    zNoThumbnailContainer.removeChild(zNoThumbnailMessageContainer);
    var zImageContainer = DOM.createElement('div','ERL_ImageContainerDiv');
    var zLoadingImage = DOM.createElement('img','ERL_LoadingImage');
    zLoadingImage.setAttribute('src',"/l.c.bin/I/880/radar.gif");
    zImageContainer.appendChild(zLoadingImage);
    zNoThumbnailContainer.appendChild(zImageContainer);
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.ItemPath, "RunReImage","&aObjectTypeAlias=LiveDigitalAsset_Video", true),
      Function: LiveAdMaker.Assets.Requiredlength.reDrawPage,
      Params: aParams
    });
    return true;
  },
  reDrawPage: function(aResult, aParams) {
    window.location.reload();
    return true;
  },
  getElementWidth: function(aElement) {
    return (aElement.style.pixelWidth) ? aElement.style.pixelWidth : aElement.scrollWidth;
  },
  getElementLeft: function(aElement) {
    return aElement.offsetLeft;
  },
  getElementRight: function(aElement) {
    return LiveAdMaker.Assets.Requiredlength.getElementLeft(aElement) + LiveAdMaker.Assets.Requiredlength.getElementWidth(aElement);
  },
  showDragTimeline: function (aParams){
    if ( !$('DragLeftDiv') && !$('DragRightDiv') ){
      var zImages = $('ThumbnailContainer').getElementsByTagName('img');
      var zLength = zImages.length * 100;
      var zDragLeftDiv = DOM.createElement('div','DragLeftDiv','DragLeftDiv');
      var zDragRightDiv = DOM.createElement('div','DragRightDiv','DragRightDiv');
      var zTimeLineDiv = DOM.createElement('div', 'TimeLineDiv','RequiredTimeline');
      var zShowDurationDiv = DOM.createElement('div', 'ShowDurationDiv');
      zTimeLineDiv.style.position = 'relative';
      zTimeLineDiv.style.width = zLength +'px';
      var zTimeLineMarkerDiv = LiveAdMaker.Assets.Requiredlength.drawTimeMarkers(zLength,zImages.length,10);
      zTimeLineDiv.appendChild(zTimeLineMarkerDiv);
      var zBodyElement =  $('ThumbnailContainer').parentNode;
      zBodyElement.appendChild(zShowDurationDiv);
      zShowDurationDiv.style.position = 'absolute';
      zShowDurationDiv.style.left = '320px';
      zShowDurationDiv.style.top = '95px';
      zShowDurationDiv.style.width = '50px';
      zShowDurationDiv.style.fontSize = '11px';
      zDragLeftDiv.style.position = 'relative';
      zDragLeftDiv.style.left = LiveAdMaker.Assets.Requiredlength.fLeftPos +'px';
      zDragLeftDiv.innerHTML = '&#60;&#60;';
      zDragRightDiv.style.position = 'relative';
      zDragRightDiv.style.left = LiveAdMaker.Assets.Requiredlength.fRightPos +'px';
      zDragRightDiv.style.top =  '-95px';
      zDragRightDiv.innerHTML = '>>';
      $('ThumbnailContainer').appendChild(zDragLeftDiv);
      $('ThumbnailContainer').appendChild(zDragRightDiv);
      $('ThumbnailContainer').appendChild(zTimeLineDiv);
      Drag.init(zDragLeftDiv, null, 0, zLength, -75, -75,LiveAdMaker.Assets.Requiredlength.startDrag,LiveAdMaker.Assets.Requiredlength.moveLeftFrameSelector,LiveAdMaker.Assets.Requiredlength.resetFramePoints);
      Drag.init(zDragRightDiv, null, 27, zLength, -95, -95,LiveAdMaker.Assets.Requiredlength.startDrag,LiveAdMaker.Assets.Requiredlength.moveRightFrameSelector,LiveAdMaker.Assets.Requiredlength.resetFramePoints);
    }
    else {
      var zFrame = $('FrameSelector');
      $('DragLeftDiv').style.left =  $('FrameSelector').style.left;
      $('DragRightDiv').style.left = LiveAdMaker.Assets.Requiredlength.fRightPos +'px';
    }
    return true;
  },
  drawTimeMarkers: function(aLength, aBigInterval, aSmallInterval){
    var zBigIntervalWidth = aLength / aBigInterval;
    var zSmallIntervalWidth = zBigIntervalWidth / aSmallInterval;
    var zTimeLineContainer = DOM.createElement('div','TimeLineMarkContainer','TimeLineMarkContainer');
    for(var i = 0; i < aBigInterval; i++){
      var zTimelineMarker = DOM.createElement('div','TimelineMark_'+i,'TimelineMarker');
      zTimelineMarker.style.width = zBigIntervalWidth-1 +'px';
      zTimelineMarker.style.left = i * zBigIntervalWidth +'px';
      for (var j = 0; j < aSmallInterval; j++){
        var zSmallTimeMarker = DOM.createElement('div','SmallTimelineMark_' +i+ '_' +j,'SmallTimelineMark');
        zSmallTimeMarker.style.width = zSmallIntervalWidth-1 +'px';
        var zIntOffset = j * aSmallInterval;
        zSmallTimeMarker.style.left = LiveAdMaker.Assets.Requiredlength.getElementLeft(zTimelineMarker) + zIntOffset +'px';
        zTimelineMarker.appendChild(zSmallTimeMarker);
      }
      zTimeLineContainer.appendChild(zTimelineMarker);
      var zTimeLineMarkerNum = DOM.createElement('div','TimeLineMarkNum_' +i,'TimeLineMarkerNum');
      zTimeLineMarkerNum.style.left = zTimelineMarker.style.left;
      zTimeLineMarkerNum.innerHTML = i;
      zTimeLineContainer.appendChild(zTimeLineMarkerNum);
    }
    var zTimeLineMarkerNum = DOM.createElement('div', 'TimeLineMarkNum_' +i, 'TimeLineMarkerNum');
    zTimeLineMarkerNum.style.left = i * zBigIntervalWidth +'px';
    zTimeLineMarkerNum.innerHTML = i;
    zTimeLineContainer.appendChild(zTimeLineMarkerNum);
    return zTimeLineContainer;
  },
  startDrag: function(){
    return true;
  },
  moveLeftFrameSelector: function (nx, ny){
    var zFrame = $('FrameSelector');
    var zOldLeft = LiveAdMaker.Assets.Requiredlength.getElementLeft(zFrame);
    $('RequiredStartTime_' +LiveAdMaker.Assets.Requiredlength.FormId).innerHTML = (nx) / 100 +'s';
    var zStartTime = FormUI.Number.formatNumberSimple($('RequiredStartTime_'+LiveAdMaker.Assets.Requiredlength.FormId).innerHTML,'3');
    var zEndTime = FormUI.Number.formatNumberSimple($('RequiredEndTime_'+LiveAdMaker.Assets.Requiredlength.FormId).innerHTML,'3');
    var zDuration =  zEndTime - zStartTime;
    $('ShowDurationDiv').innerHTML = zDuration.toFixed(3) +'s';
    if (zOldLeft < nx) { 
       var zNewWidth = LiveAdMaker.Assets.Requiredlength.fRightPos - nx;
       zFrame.style.width = zNewWidth +'px';
    } else {
       var zNewWidth = LiveAdMaker.Assets.Requiredlength.fRightPos - nx;
       zFrame.style.width = zNewWidth +'px';
    }
    zFrame.style.left = nx +'px';
    return true;
  },
  moveRightFrameSelector: function(nx, ny){
    var zFrame = $('FrameSelector');
    $('RequiredEndTime_' +LiveAdMaker.Assets.Requiredlength.FormId).innerHTML = (nx) / 100 +'s';
    var zStartTime = FormUI.Number.formatNumberSimple($('RequiredStartTime_' +LiveAdMaker.Assets.Requiredlength.FormId).innerHTML,'3');
    var zEndTime = FormUI.Number.formatNumberSimple($('RequiredEndTime_' +LiveAdMaker.Assets.Requiredlength.FormId).innerHTML,'3');
    var zDuration =  zEndTime - zStartTime;
    $('ShowDurationDiv').innerHTML = zDuration.toFixed(3) +'s';
    zFrame.style.width = nx - LiveAdMaker.Assets.Requiredlength.fLeftPos +'px';
    return true;
  },
  resetFramePoints: function (nx, ny){
    var zFrame = $('FrameSelector');
    var zOldLeft = LiveAdMaker.Assets.Requiredlength.getElementLeft(zFrame);
    LiveAdMaker.Assets.Requiredlength.fLeftPos  = LiveAdMaker.Assets.Requiredlength.getElementLeft(zFrame);
    LiveAdMaker.Assets.Requiredlength.fRightPos = LiveAdMaker.Assets.Requiredlength.getElementLeft(zFrame) + parseInt(zFrame.style.width) +20;
    fCurrentStart = FormUI.Number.formatNumberSimple($('RequiredStartTime_'+LiveAdMaker.Assets.Requiredlength.FormId).innerHTML, '3');
    fCurrentEnd =  FormUI.Number.formatNumberSimple($('RequiredEndTime_'+LiveAdMaker.Assets.Requiredlength.FormId).innerHTML,'3');
    var aElementStart = $('RequiredStartTime_'+LiveAdMaker.Assets.Requiredlength.FormId).onclickFunctions[0].Params;
    var aElementEnd = $('RequiredEndTime_'+LiveAdMaker.Assets.Requiredlength.FormId).onclickFunctions[0].Params;
    $('RequiredStartTime_'+LiveAdMaker.Assets.Requiredlength.FormId).onclickFunctions[0].Function(null, aElementStart);
    $('RequiredEndTime_'+LiveAdMaker.Assets.Requiredlength.FormId).onclickFunctions[0].Function(null, aElementEnd);
    setTimeout('LiveAdMaker.Assets.Requiredlength.pause()',100);
    return true;
  },
  pause: function(){
    $('RequiredEndTime_'+LiveAdMaker.Assets.Requiredlength.FormId).firstChild.value = fCurrentEnd;
    $('RequiredStartTime_'+LiveAdMaker.Assets.Requiredlength.FormId).firstChild.value = fCurrentStart;
    $('RequiredStartTime_'+LiveAdMaker.Assets.Requiredlength.FormId).blur();
    $('RequiredEndTime_'+LiveAdMaker.Assets.Requiredlength.FormId).focus();
    $('RequiredEndTime_'+LiveAdMaker.Assets.Requiredlength.FormId).blur();
    return true;
  },
  setTimeline: function(aParams){
    if(aParams.Form){
      LiveAdMaker.Assets.Requiredlength.FormParams = aParams;
    }
    var zForm = aParams.Form || LiveAdMaker.Assets.Requiredlength.FormParams.Form;
    LiveAdMaker.Assets.Requiredlength.FormId = zForm.ItemId;
    if ( $('RequiredStartTime_' +zForm.ItemId) && $('RequiredEndTime_' +zForm.ItemId) ){
      var zStartTime = FormUI.Number.formatNumberSimple($('RequiredStartTime_' +zForm.ItemId).innerHTML,'3');
      var zEndTime = FormUI.Number.formatNumberSimple($('RequiredEndTime_' +zForm.ItemId).innerHTML, '3');
      var zDuration =  zEndTime - zStartTime;
      if (zDuration > 0){
        var zFrame = $('FrameSelector');
        zFrame.style.display = 'block';
        zFrame.style.left = zStartTime * 100 +'px';
        zFrame.style.width = zDuration * 100 +'px';
        LiveAdMaker.Assets.Requiredlength.fLeftPos = FormUI.Number.formatNumberSimple($('RequiredStartTime_' +zForm.ItemId).innerHTML,'3') * 100;
        LiveAdMaker.Assets.Requiredlength.fRightPos = FormUI.Number.formatNumberSimple($('RequiredEndTime_' +zForm.ItemId).innerHTML, '3') * 100;
        LiveAdMaker.Assets.Requiredlength.showDragTimeline(aParams);
        $('ShowDurationDiv').innerHTML = zDuration.toFixed(3) +'s';
      }
      else {
        $('RequiredEndTime_' +zForm.ItemId).blur();
      }
    }
    return true;
  },
  drawFrameSelector: function(){
  },
  showForm: function (){
    $('RequiredLengthContainer').style.display = 'block';
    $('RequiredLengthContainer').innerHTML = '';
    FormUI.Request.getForm("intel\\InterfaceList\\Live\\JavaScript", "RequiredLengthSelection",$('RequiredLengthContainer'),'',{OnDisplayFunction: LiveAdMaker.Assets.Requiredlength.setTimeline});
    return true;
  },
  ShowMediaPlayer: function(zWidth, zHeight, zUrl,aContainer){
    var zPlayerWidth = zWidth || 340;
    var zPlayerHeight = zHeight || 300;
    var zUrlSplit = zUrl.split(".");
    var zFileExtension = zUrlSplit[zUrlSplit.length-1].toLowerCase();
    if (zFileExtension=="mov") {
      LiveAdMaker.Assets.Requiredlength.EmbedMediaplayer('Quicktime',zPlayerHeight,zPlayerWidth,zUrl,aContainer);
    }
    else if (DOM.Browser.isWMP||DOM.Browser.WMPVer) {
      LiveAdMaker.Assets.Requiredlength.EmbedMediaplayer('MediaPlayer',zPlayerHeight,zPlayerWidth,zUrl,aContainer);
      Version = 'WM';
    }
    return true;
  },
  EmbedMediaplayer: function(PlayerType,zHeight,zWidth,zURL,aContainer) {
    var zMediaPlayerDiv = DOM.createElement('div','MediaPlayerDiv');
    aContainer.appendChild(zMediaPlayerDiv);
    if (PlayerType=="MediaPlayer") {
      if (typeof zMediaPlayerDiv.insertAdjacentHTML != 'undefined') {
        zMediaPlayerDiv.insertAdjacentHTML('beforeEnd', [
        '    <OBJECT id="MediaPlayer" width="'+ zWidth +'" height="'+ zHeight +'"',
        '    CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"',
        '    STANDBY="Loading Windows Media Player components..."',
        '    TYPE="application/x-oleobject">',
        '    <param name="bgcolor" value="#FFFFFF">',
        '    <param name="AutoStart" value="TRUE">',
        '    <param name="ShowStatusBar" value="true">',
        '    <param name="URL" value="' + zURL + '">',
        '    <embed TYPE="application/x-mplayer2"',
        '      id="embedMediaPlayer"',
        '      name="embedMediaPlayer"',
        '      width="'+ zWidth +'"',
        '      bgcolor="#FFFFFF"',
        '      SRC='+zURL,
        '      autostart=1',
        '      ShowStatusBar="1"',
        '      height="'+ zHeight +'"',
        '      EnableJavaSript="true">',
        '    <\/embed>',
        '<\/object>'
        ].join('\r\n'));
      }
      else {
        var zEmbed = DOM.createElement('embed','embedMediaPlayer');
        zEmbed.setAttribute("type","application/x-mplayer2");
        zEmbed.setAttribute("name","MediaPlayerName");
        zEmbed.setAttribute("width",zWidth);
        zEmbed.setAttribute("bgcolor","#FFFFFF");
        zEmbed.setAttribute("SRC",zURL);
        zEmbed.setAttribute("autostart","1");
        zEmbed.setAttribute("ShowStatusBar","1");
        zEmbed.setAttribute("height",zHeight);
        zEmbed.setAttribute("pluginspage","http://microsoft.com/windows/mediaplayer/en/download/");
        zEmbed.setAttribute("enablejavaScript","true");
        zMediaPlayerDiv.appendChild(zEmbed);
      }
    }
    else if (PlayerType=="Quicktime") {
      if (typeof zMediaPlayerDiv.insertAdjacentHTML != 'undefined') {
        zMediaPlayerDiv.insertAdjacentHTML('beforeEnd', [
        '<object classid="02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+ zWidth +'" height="'+ zHeight +'" codebase="http://www.apple.com/qtactivex/qtplugin.cab">',
        '  <param name="src" value="'+zURL+'">',
        '  <param name="autoplay" value="true">',
        '  <param name="controller" value="true">',
        '  <param name="loop" value="false">',
        '  <embed src="'+zURL+'" width="'+zWidth+'" height="'+zHeight+'" autoplay="true" controller="true" loop="false" bgcolor="#ffffff" pluginspage="http://www.apple.com/quicktime/download/"><\/embed>',
        '<\/object>'
        ].join('\r\n'));
      }
      else {
        var zEmbed = DOM.createElement('embed','embedQuicktimePlayer');
        zEmbed.setAttribute("src", zURL);
        zEmbed.setAttribute("width", zWidth);
        zEmbed.setAttribute("height", zHeight);
        zEmbed.setAttribute("autoplay", "true");
        zEmbed.setAttribute("controller", "true");
        zEmbed.setAttribute("loop", "false");
        zEmbed.setAttribute("bgcolor", "#ffffff");
        zEmbed.setAttribute("pluginspage", "http://www.apple.com/quicktime/download/");
        zMediaPlayerDiv.appendChild(zEmbed);
      }
    }
    return true;
  },
  HideDialog: function(e, aParams){
    var zPlayer = aParams.Element;
    if (zPlayer.controls.isAvailable('Stop')){
      zPlayer.controls.stop();
    }
    DOM.removeClass(aParams.Container,'Show');
    DOM.addClass(aParams.Container,'Hide');
    return true;
  }
}
LiveAdMaker.Assets.ShowFlashPreview = function(aWidth, aHeight, aVideoURL, aContainer){
  var zFlashPlayerDiv = DOM.createElement('div','FlashPlayerDiv');
  aContainer.appendChild(zFlashPlayerDiv);
  var zWidth = aWidth || '300';
  var zHeight = aHeight || '320';
  if (typeof zFlashPlayerDiv.insertAdjacentHTML != 'undefined') {
    var zObjectDiv = DOM.createElement('div');
    zFlashPlayerDiv.appendChild(zObjectDiv);
    zObjectDiv.outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
      + 'width='+zWidth+' height='+zHeight+' '
      + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
      + '<param name="movie" value="'+aVideoURL+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="wmode" value="transparent">'
      + '<embed src="'+aVideoURL+'" quality="high" bgcolor="##ffffff" '
      + 'width="'+zWidth+'" height="'+zHeight+'" align="left" wmode="transparent"'
      + 'play="true"'
      + 'loop="false"'
      + 'quality="high"'
      + 'allowScriptAccess="sameDomain"'
      + 'type="application/x-shockwave-flash"'
      + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
      + '<\/embed>'
      + '<\/object>';
  }
  else {
    var zEmbed = DOM.createElement('embed','embedFlashPlayer');
    zEmbed.setAttribute("type","application/x-shockwave-flash");
    zEmbed.setAttribute("name","FlashAsset");
    zEmbed.setAttribute("width",zWidth);
    zEmbed.setAttribute("bgcolor","#FFFFFF");
    zEmbed.setAttribute("SRC",aVideoURL);
    zEmbed.setAttribute("allowScriptAccess","sameDomain");
    zEmbed.setAttribute("wmode","transparent");
    zEmbed.setAttribute("play","true");
    zEmbed.setAttribute("loop","false");
    zEmbed.setAttribute("quality","high");
    zEmbed.setAttribute("height",zHeight);
    zEmbed.setAttribute("pluginspage","http://www.macromedia.com/go/getflashplayer");
    zFlashPlayerDiv.appendChild(zEmbed);
  }
  return true;
}
    // ---------------------- End Action_LiveAdMaker_Assets ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_Branding --------------- //
LiveAdMaker.Branding = new LiveAdMaker.GenericSection({
  Name: "Branding",
  BaseType: "Content",
  StartItemPath: "intel\\MainObjectList\\ContentList\\ItemList\\Sys_All_ContentList\\BrandResourceCenterList"
});
LiveAdMaker.Branding.ArchiveImagery = Util.copyObject(LiveAdMaker.Branding.Imagery);
LiveAdMaker.Branding.disableNavigationItems(["AddToButton","ImportExportButton","ExportButton"]);
LiveAdMaker.Branding.removeActions(["Details","Assets","Groups","Pricing","Restrictions","SalesPoints","Customize","Criteria","Imagery"]);
LiveAdMaker.Branding.Actions.push({
  Id: "Imagery",
  DisplayName: "Assets",
  DisplayFunction: function(aParams){
    aParams.Section.CurrentItem=aParams.Item;
    aParams.Section.ContentContainer=aParams.ContentElement;
    aParams.DisabledNavigationArray = [{Id:"ImportExportButton", Disabled:"Y"},{Id:"ExportButton", Disabled:"Y"}];
    aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetAssetList", "", true);
    aParams.ReceiveSubItemsFunction = LiveAdMaker.AssetsV2.Imagery.receiveSubItems;
    var aLightboxDisplayParams = {};
    aLightboxDisplayParams.PrimaryFunction = List.displayAssetPreview;
    aLightboxDisplayParams.PrimaryText = "Preview";
    aLightboxDisplayParams.PrimaryDescription = "Preview Asset";
    aLightboxDisplayParams.PrimaryParams = aParams;
    aLightboxDisplayParams.SecondaryText = "Options";
    aLightboxDisplayParams.SecondaryDescription = "Click for Options";
    var zLightboxDisplayObject = Util.Object.create(List.LightboxView.DisplayObject, aLightboxDisplayParams);
    zLightboxDisplayObject.displayLightboxSecondaryLink = function(aItem, aParams) {
      if (aItem.Asset_URL) {
        this.SecondaryFunction = LiveAdMaker.Assets.Imagery.secondaryLightboxFunction;
      } else {
        this.SecondaryFunction = "";
      }
      return zLightboxDisplayObject.parent.displayLightboxSecondaryLink.call(this, aItem);
    }
    aParams.LightboxDisplayObject = zLightboxDisplayObject;
    aParams.FetchedLightboxData = true;
    LiveAdMaker.requestSubItems(aParams);
    return true;
  }
});
LiveAdMaker.Branding.Actions.push({
  Id: "ArchiveImagery",
  DisplayName: "Asset Archive",
  DisplayFunction: function(aParams){
    aParams.Section.CurrentItem=aParams.Item;
    aParams.Section.ContentContainer=aParams.ContentElement;
    aParams.DisabledNavigationArray = [{Id:"ImportExportButton", Disabled:"Y"},{Id:"ExportButton", Disabled:"Y"},{Id:"NewButton", Disabled:"Y"},{Id:"AddToButton", Disabled:"Y"},{Id:"DuplicateButton", Disabled:"Y"}];
    aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetAssetList", "aCollectionType=_ArchiveCollection", true);
    aParams.ReceiveSubItemsFunction = LiveAdMaker.AssetsV2.Imagery.receiveSubItems;
    var aLightboxDisplayParams = {};
    aLightboxDisplayParams.PrimaryFunction = List.displayAssetPreview;
    aLightboxDisplayParams.PrimaryText = "Preview";
    aLightboxDisplayParams.PrimaryDescription = "Preview Asset";
    aLightboxDisplayParams.PrimaryParams = aParams;
    aLightboxDisplayParams.SecondaryText = "Options";
    aLightboxDisplayParams.SecondaryDescription = "Click for Options";
    var zLightboxDisplayObject = Util.Object.create(List.LightboxView.DisplayObject, aLightboxDisplayParams);
    zLightboxDisplayObject.displayLightboxSecondaryLink = function(aItem, aParams) {
      if (aItem.Asset_URL) {
        this.SecondaryFunction = LiveAdMaker.Assets.Imagery.secondaryLightboxFunction;
      } else {
        this.SecondaryFunction = "";
      }
      return zLightboxDisplayObject.parent.displayLightboxSecondaryLink.call(this, aItem);
    }
    aParams.LightboxDisplayObject = zLightboxDisplayObject;
    aParams.FetchedLightboxData = true;
    LiveAdMaker.requestSubItems(aParams);
    return true;
  }
});
LiveAdMaker.Branding.addAction("Preview", "Preview", function(aParams) {
  LiveAdMaker.Branding.CurrentItem=aParams.Item;
  LiveAdMaker.Branding.ContentContainer=aParams.ContentElement;
  zDisplayObject = new LiveAdMaker.Website.Render.DisplayObject({
    ItemPath: aParams.Item.ItemPath
  });
  zDisplayObject.ParentContainer = aParams.ContentElement;
  aParams.ContentElement.appendChild(zDisplayObject.Container);
  zDisplayObject.init();
  return true;
});
LiveAdMaker.Branding.addAction("Restrictions", "Restrictions", function(aParams) {
  LiveAdMaker.Branding.Restrictions.init(aParams);
  return true;
});
LiveAdMaker.Branding.drawBRCNavigation = function(aParams, aBRCSectionIdList, aBRCSectionNameList, aSelectedSectionId) {
  var zNavDiv = aParams.NavDiv;
  $("TopNavButtonContainer").appendChild(zNavDiv);
  var zNavList = DOM.createElement("ul",null,"BRCNavList");
  zNavList.style.position = "absolute";
  zNavDiv.appendChild(zNavList);
  for (i=0; i<aBRCSectionIdList.length; i++) {
    var zNavItem = DOM.createElement("li",null,"BRCNavItem");
    zNavList.appendChild(zNavItem);
    var zNavItemClass = "BRCNavLink" + (aBRCSectionIdList[i]==aSelectedSectionId ? " selected" : "");
    var zNavLink = DOM.createElement("a",null,zNavItemClass);
    zNavLink.setAttribute("href","#Section="+aBRCSectionIdList[i]);
    zNavItem.appendChild(zNavLink);
    zNavLink.innerHTML = aBRCSectionNameList[i]
  }
  URI.fixLinks(zNavList)
}
LiveAdMaker.Branding.fixLocalBrandingNavigation = function(aBRCSection) {
  DOM.getElementsWithClassName("a","leftnavActivebutton",$("LeftNavContainer")).forEach(function (zLink) {
    DOM.removeClass(zLink, "leftnavActivebutton");
    DOM.addClass(zLink, "leftnavbutton")
  });
  if ($("Nav"+aBRCSection)) {
    DOM.removeClass($("Nav"+aBRCSection), "leftnavbutton");
    DOM.addClass($("Nav"+aBRCSection), "leftnavActivebutton")
  }
}
LiveAdMaker.Branding.Assets = {
  AssetList: null,
  ContentElement: null,
  CurrentItem: null,
  DisplayListIcons: "Y",
  DefaultView: (LiveAdMaker.SystemType=="LOCAL") ? "thumbnailAndName" : "",
  ListOptions: {
    DisplayHierarchy: "Y"
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Imagery.Details.init(aParams);
        return true;
      }
    }
  ],
  init: function(aParams) {
    LiveAdMaker.Branding.CurrentItem = aParams.Item;
    LiveAdMaker.Branding.ContentElement = aParams.ContentElement;
    aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetAssetList", "", true)
    LiveAdMaker.requestSubItems(aParams);
  },
  archiveItem: function(aParams) {
    LiveAdMaker.Imagery.archiveItem(aParams);
    return true;
  }
}
LiveAdMaker.Branding.Restrictions = {
  CurrentItem: null,
  ContentElement: null,
  init: function(aParams) {
    LiveAdMaker.Branding.Restrictions.CurrentItem = aParams.Item;
    LiveAdMaker.Branding.Restrictions.ContentElement = aParams.ContentElement;
    LiveAdMaker.Branding.Restrictions.ContentElement.innerHTML = '';
    FormUI.Request.getForm(aParams.Item.ItemPath, 'Restrictions', aParams.ContentElement,'','');
    return true;
  }
}
    // ---------------------- End Action_LiveAdMaker_Branding ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_Dealers --------------- //
LiveAdMaker.Dealers = {
  Name: 'Dealers',
  ListOptions: {
    DisplayHierarchy: 'Y'
  },
  QuickSearchOptions: {
    GetSearchCategoriesExtraParams: "aObjectTypeAlias=CompanyGroup&aGetFormObjectType=Company&aFormType=StagingDealerDetails",
    SearchExtraParams: "aObjectTypeAlias=CompanyGroup",
    SearchObjectTypes: "Company"
  },
  getDisabledNavigationArray: function(aList) {
    var zDisabledNavigationArray = [
      {Id: "ViewBubbleImage", Disabled: "Y"},
      {Id: "ViewTable", Disabled: "Y"},
      {Id: "ViewThumbnail", Disabled: "Y"},
      {Id: "AddToButton", Disabled: "Y"}
    ]
    if (""=="Y"&&LiveAdMaker.SystemMode=="LIVE"&&LiveAdMaker.SystemType=="BRAND"){
      zDisabledNavigationArray.push({Id: "ArchiveButton", Disabled: "Y"});
    }
    if (LiveAdMaker.SystemType=="LOCAL"&&URI.User.AccessGroupName!="System Administrator") {
      zDisabledNavigationArray.push({Id: "DuplicateButton", Disabled: "Y"});
      zDisabledNavigationArray.push({Id: "ImportExportButton", Disabled: "Y"});
      zDisabledNavigationArray.push({Id: "ExportButton", Disabled: "Y"});
    }
    return zDisabledNavigationArray
  },
  Load: function(aParams) {
    var zSection = LiveAdMaker.Dealers;
    if(!zSection.Items) {
      Ajax.makeRequest({
        URL: URI.pageURL(URI.User.CompanyItemPath, "GetHierarchy", "", true),
        Function: LiveAdMaker.receiveSectionData,
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
    }
    else {
      LiveAdMaker.drawSection(aParams);
    }
    return true;
  },
  draw: function(aParms) {
    return true;
  },
  requestChildNodes: function(e, aRequestParams) {
    var aParams = aRequestParams || {};
    aParams.isChildRequest = "Y";
    if(!aParams.SelectedItem) {
      aParams.SelectedItem =  aParams.ParentItem;
    }
    if(!aParams.Section) {
      if(aParams.Params.SubSection){
        aParams.Section =  aParams.Params.SubSection;
      } else {
        aParams.Section =  aParams.Params.Section;
      }
    }    
    aParams.SelectedItem.SubItemsLoaded = "Y";
    if(this.onclickFunctions) {
      this.onclickFunctions = null;
      this.onclick = null;
    }
    var zParentItemPath = aParams.SelectedItem.ItemPath;
    Ajax.makeRequest({
      URL: URI.pageURL(zParentItemPath, "GetList", null, true),
      Function: LiveAdMaker.receiveSectionData,
      Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams},
      PostValues: {
        aChildRequest: "Y"
      },
      Method:'POST'
    });
  },
  createNewItem: function(aCreateNewParams) {
    var zDealerCount = LiveAdMaker.SelectedSection.Items.length;
    var aParams = {
      View:"ActionsWithName",
      Section: aCreateNewParams.Section || "Dealers",
      Action: aCreateNewParams.SubSection || "Details",
      SubSection: aCreateNewParams.SubSection || ""
    }
    var zAddNewAsChild, zParentItemPath;
    Ajax.makeRequest({
      URL: URI.pageURL("intel\\ContentList\\CompanyList", "CreateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: aCreateNewParams.Section || "Dealers", Function:LiveAdMaker.drawSection,Params:aParams},
      PostValues: {
        aObjectTypeAlias:"CompanyLink",
        inpObjectTypeAlias:"CompanyLink",
        aCreateCompanyContact:"N",
        aNoAction:"Y",
        aNoRedirect:"Y",
        aFastMode:"Y",
        inpName:"OEM " + ++zDealerCount,
        aAddNewAsChild: zAddNewAsChild,
        aParentItemPath: zParentItemPath
      },
      Method:'POST'
    });
  },
  duplicateItem:function() {
    var zDealerCount = LiveAdMaker.SelectedSection.Items.length;
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var aParams = {
      View:"ActionsWithName",
      Section:"Dealers",
      Action:"Details"
    }
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Dealers", Function:LiveAdMaker.drawSection,Params:aParams},
      PostValues:{
        aAlias:"OEM".makeUnique(),
        aName:"OEM " + ++zDealerCount
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    var zMoveToPath = "intel\\SystemReferenceList\\ArchivedCompanyList"
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues:{
        aMoveToPath: zMoveToPath
      },
      Method:'POST'
    });
  },
  exportSectionItem: function(aParams){
    var zExportTextContainer = DOM.createElement("div","ExportDiv",null,"padding:5px;");
    var zExportIconSrc = "\/l.c.bin\/I\/912\/Export.gif";
    var zExportIconWidth= "";
    var zExportIconHeight = "";
    var zExportImg = DOM.createImage(zExportIconSrc,zExportIconWidth,zExportIconHeight,"ExportImg");
    var zExportLink = DOM.createTextElement("span","ExportLink",null,null,"Click to export dealer data to FTP site");
    var zReceiveFunction = (aParams.ReceiveFunction) ? aParams.ReceiveFunction : LiveAdMaker.Dealers.exportDealersToFTP;
    zExportTextContainer.style.cursor = 'pointer';
    zExportTextContainer.style.cursor = 'hand';
    zExportTextContainer.appendChild(zExportImg);
    zExportTextContainer.appendChild(zExportLink);
    DOM.addEvent(zExportLink,"onclick", zReceiveFunction, {ExportTextContainer:zExportTextContainer});
    DOM.addEvent(zExportImg,"onclick", zReceiveFunction, {ExportTextContainer:zExportTextContainer});
    DOM.Dialog.show(zExportTextContainer,'center','Export','400',null);
    return true;
  },
  exportDealersToFTP: function(e,aParams){
    Ajax.makeRequest({
      URL: URI.pageURL("intel\\ContentList\\CompanyList", "ExportList", null, true),
      Function: LiveAdMaker.Dealers.confirmDealersExport,
      Params: aParams,
      PostValues: {},
      Method:'POST'
    });
    return true;
  },
  confirmDealersExport: function(aResult,aParams) {
    var zExportTextContainer, zExportConfirmText;
    if (aResult.Success == "Y") {
      zExportConfirmText = DOM.createTextElement("div","ConfirmExportDiv",null,null,"Your export is now running.  You will receive an email with information on how to retrieve your file from the FTP server when this is complete.  Please be patient as data exports can take several minutes.");
    } else {
        zExportConfirmText = DOM.createTextElement("div","ConfirmExportDiv",null,null,"An unexpected error occurred while setting up your export.  Please try again.");
    }
    zExportTextContainer = aParams.ExportTextContainer;
    DOM.replaceContent(zExportTextContainer, zExportConfirmText);
    DOM.Dialog.show(zExportTextContainer, 'center', 'Export','250',null);
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Dealers.Details.ItemPath = aParams.Item.TruePath;
        LiveAdMaker.Dealers.Details.PointerPath = aParams.Item.ItemPath;
        FormUI.Request.getForm(aParams.Item.TruePath, 'StagingDealerDetails', aParams.ContentElement,"&aPointerPath="+LiveAdMaker.Dealers.Details.PointerPath, {OnDisplayParams: aParams});
        return true;
      }
    },
    {
      Id: "Users",
      DisplayName: "Users",
      DisplayFunction: function(aParams) {
        aParams.DisabledNavigationArray = [
          {Id: "ViewThumbnail", Disabled: "Y"},
          {Id: "ViewTable", Disabled: "Y"},
          {Id: "ImportExportButton", Disabled: "Y"},
          {Id: "ExportButton", Disabled: "Y"},
          {Id: "AddToButton", Disabled: "Y"},
          {Id: "DuplicateButton", Disabled: "Y"}
        ];
        if (LiveAdMaker.SystemType=="LOCAL"&&URI.User.AccessGroupName!="System Administrator") {
          aParams.DisabledNavigationArray.push({Id: "NewButton", Disabled: "Y"});
          aParams.DisabledNavigationArray.push({Id: "ArchiveButton", Disabled: "Y"});
        }
        if (""=="Y"&&LiveAdMaker.SystemMode=="LIVE"&&LiveAdMaker.SystemType=="BRAND"){
          aParams.DisabledNavigationArray.push({Id: "ArchiveButton", Disabled: "Y"});
        }
        if (aParams.Section) {
          aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetUserList", "aList_OrderBy=DisplayName&aList_OrderType=S", true)
          aParams.SearchObjectItemPath = aParams.Item.ItemPath;
          LiveAdMaker.requestSubItems(aParams);
        }
        else {
          zMessageDiv = DOM.createElement("p",null,"MessageText","font-weight:bold;color:#808080;font-size:12px;margin-top:5px;margin-left:5px;");
          zMessageDiv.innerHTML = "To view Users<br />please go to the OEMs tab in the left navigation and then click on Users";
          DOM.replaceContent(aParams.ContentElement, zMessageDiv);
        }
        return true;
      }
    },
    {
      Id: "Groups",
      DisplayName: "Groups",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Dealers.Groups.init(aParams);
        return true;
      }
    },
    {
      Id: "Orders",
      DisplayName: "Orders",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Dealers.Orders.init(aParams);
        return true;
      }
    }
  ],
  updateDealerDisplayName: function(aParams) {
    if (LiveAdMaker.SelectedSubSection) {
      LiveAdMaker.SelectedSubSection.List.updateDisplayName(aParams.Element.Value, aParams.Original);
    } else if (LiveAdMaker.SelectedSection) {
      LiveAdMaker.SelectedSection.List.updateDisplayName(aParams.Element.Value, aParams.Original);
    }
  }
};
LiveAdMaker.Dealers.Groups = {
  init: function(aParams) {
    FormUI.Request.getForm(aParams.Item.TruePath, 'Groups', aParams.ContentElement);
    return true;
  }
}
LiveAdMaker.Dealers.Features = {
  init: function(aParams) {
    FormUI.Request.getForm(aParams.Item.TruePath, 'Features', aParams.ContentElement);
    return true;
  }
}
LiveAdMaker.Dealers.Orders = {
  getActions: function(){
    var zActions = [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Orders.Details.init(aParams);
        return true;
      }
    },
    {
      Id: "Ads",
      DisplayName: "Ads",
      DisplayFunction: function(aParams) {
      aParams.SectionId   = "Dealers";
      aParams.ActionId    = "Orders";
      aParams.SubActionId = "Ads";
      aParams.URL = URI.pageURL(aParams.List.SelectedItem.ItemPath + '\\InsertionList',"GetList", "&aIsOwner=N", true),
      aParams.TripleBubble = true;
      LiveAdMaker.requestTripleBubbleItems(aParams);
      LiveAdMaker.Orders.Ads.init(aParams);
      return true;
      }
    }
    ];
    return zActions;
  },
  Ads: {},
  init: function(aParams) {
    if (aParams.Section) {
      aParams.DisabledNavigationArray = [
        {Id: "NewButton", Disabled: "Y"},
        {Id: "AddToButton", Disabled: "Y"},
        {Id: "DuplicateButton", Disabled: "Y"}
      ];
      aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetOrderList", "", true)
      LiveAdMaker.requestSubItems(aParams);
    }
    return true;
  },
  draw: function(aParams) {
    return true;
  }
};
LiveAdMaker.Dealers.Details = {
  ItemPath: "",
  PointerPath: "",
  showLocalLogin: function (aParams) {
  }
}
LiveAdMaker.Dealers.Media = {
  Dealer_ItemPath: null,
  MediaTypeList : [],
  getActions: function(){return LiveAdMaker.MediaLocations.Actions;},
  createNewItem: function(aParams) {
    var zNewMediaOutletContainer = ($('NewMediaOutletContainer')) ? $('NewMediaOutletContainer') : DOM.createElement('div','NewMediaOutletContainer','NewMediaOutletContainer');
    DOM.Dialog.showForm(zNewMediaOutletContainer, 'cursor', 'Search For New Media Outlet', 400, 400, 'MediaOutletAdd', this.Dealer_PointerPath, {AdditionalUrlParams:"&aGetForm_ExecuteObjectType=MediaLocation"});
    zNewMediaOutletContainer.childNodes[0].style.paddingLeft = '0px';
    return true;
  },
  addToSection: function() {
    LiveAdMaker.Dealers.Media.createNewItem();
  },
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Dealers.Media.Dealer_ItemPath, "MapToMediaOutlet", 'inpDealerPointerPath=' + LiveAdMaker.Dealers.Media.Dealer_PointerPath + '&inpMediaItemPath=' + LiveAdMaker.MediaLocations.CurrentItem.ItemPath + '&inpAddMode=false', true),
      Function: LiveAdMaker.Dealers.Media.updateMediaDisplay,
      Params: { Media_ItemPath: aParams.MediaItemPath, MediaType: null, AddMode: false }
    });
  },
  exportSectionItem: function(aParams){
    return true;
  },
  init: function(aParams) {
    LiveAdMaker.Dealers.Media.Dealer_ItemPath = aParams.Item.TruePath;
    LiveAdMaker.Dealers.Media.Dealer_PointerPath = aParams.Item.ItemPath;
    var MediaHeader;
    var zContentContainer = aParams.ContentElement;
    Ajax.makeRequest({
      URL: URI.pageURL("intel\\SystemReferenceList\\MediaTypeList", "GetList", "", true),
      Function: LiveAdMaker.MediaLocations.setMediaTypes,
      Params: {Section: aParams.Section, Params: aParams}
    });
    aParams.URL = URI.pageURL(aParams.Item.TruePath, "GetMediaData", "aList_OrderBy=DisplayName", true);
    LiveAdMaker.requestSubItems(aParams);
    return true;
  },
  addMediaType: function(e,aParams) {
    var zAddMediaTypeParams = {Container:aParams.MediaContainer}
    if (!$('MediaActionHeader')) {
      var zMediaActionHeader = DOM.createActionElement('h1', LiveAdMaker.Dealers.Media.addMediaType, 'Media', {MediaContainer:zAddMediaTypeParams.Container});
      zMediaActionHeader.setAttribute('id','MediaActionHeader');
      zAddMediaTypeParams.Container.appendChild(zMediaActionHeader);
    } else {
        var zMediaActionHeader = $('MediaActionHeader');
    }
    DOM.Dialog.hide();
    if ($('MediaTypeSelectContainer') != zMediaActionHeader.parentNode.childNodes[1] && $('MediaTypeSelectContainer')) {
      $('MediaTypeSelectContainer').parentNode.removeChild($('MediaTypeSelectContainer'));
    }
    if ($('MediaLocationSearchContainer') != zMediaActionHeader.parentNode.childNodes[2] && $('MediaLocationSearchContainer')) {
      $('MediaLocationSearchContainer').parentNode.removeChild($('MediaLocationSearchContainer'));
    }
    if (!$('MediaTypeSelectContainer')) {
      var zMediaTypeSelect = LiveAdMaker.Dealers.Media.drawMediaTypeSelect();
      zMediaActionHeader.parentNode.insertBefore(zMediaTypeSelect, zMediaActionHeader.parentNode.firstChild.nextSibling);
    } else {
        if ($('MediaTypeSelectContainer').style.display == 'none') {
          $('MediaTypeSelectContainer').style.display = 'block';
        } else {
          $('MediaTypeSelectContainer').style.display = 'none';
        }
    }
    if (!$('MediaLocationSearchContainer')) {
      LiveAdMaker.Dealers.Media.addMediaSearch('',{Container:zAddMediaTypeParams.Container});
      zMediaActionHeader.parentNode.insertBefore($('MediaLocationSearchContainer'), zMediaActionHeader.parentNode.firstChild.nextSibling.nextSibling);
    } else {
        if ($('MediaLocationSearchContainer').style.display == 'none') {
          $('MediaLocationSearchContainer').style.display = 'block';
        } else {
          $('MediaLocationSearchContainer').style.display = 'none';
        }
    }
  },
  drawMediaTypeSelect: function(aParentRef) {
    if (!$('MediaTypeSelectContainer')) {
      var zMediaTypeSelectContainer = DOM.createElement('div','MediaTypeSelectContainer');
      if (LiveAdMaker.MediaTypeArray.length > 1) {
        var zMediaTypeSelect = DOM.createElement("select","inpMediaType");
        zMediaTypeSelectContainer.appendChild(zMediaTypeSelect);
        LiveAdMaker.MediaTypeArray.forEach(function(aMediaType){
          var zMediaTypeOption = DOM.createElement("option");
          zMediaTypeOption.value = aMediaType.Id;
          zMediaTypeOption.innerHTML = aMediaType.DisplayName;
          zMediaTypeSelect.appendChild(zMediaTypeOption);
        });
      } else {
          var zMediaTypeHiddenInput = DOM.createElement("input","inpMediaType");
          zMediaTypeHiddenInput.setAttribute("type","hidden");
          zMediaTypeHiddenInput.setAttribute("value",LiveAdMaker.MediaTypeArray[0].Id);
          zMediaTypeSelectContainer.appendChild(zMediaTypeHiddenInput);
      }
      if (aParentRef) {
        aParentRef.appendChild(zMediaTypeSelectContainer);
      } else {
          return zMediaTypeSelectContainer;
      }
    }
    else {
      if ($('MediaTypeSelectContainer').style.display == 'none') {
        $('MediaTypeSelectContainer').style.display = 'block';
      }
      else {
        $('MediaTypeSelectContainer').style.display = 'none';
      }
    }
  },
  requestMediaArray:function(aParams) {
    var zContentContainer = aParams.ContentElement;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.TruePath, "GetMediaData", null, true),
      Function: LiveAdMaker.Dealers.Media.drawMediaData,
      Params: {Section:aParams.Section, Params:aParams, ContentElement:zContentContainer}
    });
  },
  getMediaTypes: function(e, aParams) {
  },
  receiveMediaTypeData: function(aReceiveData, aParams) {
    var mediaTypeList = LiveAdMaker.Dealers.Media.MediaTypeList;
    var aItemsArray = aReceiveData.Items;
    for(var i = 0; i < aItemsArray.length; i++) {
      if (aItemsArray[i].Disabled != 'Y') {
        mediaTypeList[aItemsArray[i].Id] = {
          DisplayName: aItemsArray[i].DisplayName,
          MediaTypeUsed : ''
        }
      }
    }
  },
  drawMediaHeader: function(aParentContainer) {
    if (LiveAdMaker.MediaTypeArray.length > 0) {
      MediaHeader = DOM.createActionElement('h1', LiveAdMaker.Dealers.Media.addMediaType, 'Media', {MediaContainer:aParentContainer});
      MediaHeader.setAttribute('id','MediaActionHeader');
    } else {
        MediaHeader = DOM.createTextElement('h1','MediaActionHeader','action-element','','Media');
    }
    aParentContainer.insertBefore(MediaHeader, aParentContainer.firstChild);
  },
  drawMediaType: function(aParams) {
    var zMediaSelectContainerId = 'MediaTypeSelectContainer';
    var zMediaTypeHeader = $(aParams.MediaAlias);
    if (!zMediaTypeHeader) {
      var zMediaTypeHeader = DOM.createActionElement('h2', LiveAdMaker.Dealers.Media.addMediaLocationSearch, aParams.DisplayName, {MediaAlias:aParams.MediaAlias, Id:aParams.MediaAlias});
      zMediaTypeHeader.setAttribute('id', aParams.MediaAlias);
      aParams.Container.appendChild(zMediaTypeHeader);
    }
    return zMediaTypeHeader;
  },
  drawMedia: function(aMediaItem) {
    mediaElement = DOM.createElement('div', 'mediaoutlet-' + aMediaItem.Id, 'media');
    mediaElement.setAttribute('itempath', aMediaItem.ItemPath);
    mediaElement.onmouseover = function() {
      DOM.addClass(this, 'hover');
    }
    mediaElement.onmouseout = function() {
      DOM.removeClass(this, 'hover');
    }
    mediaElement.setAttribute('mediaid', aMediaItem.Id);
    mediaElementContent = DOM.createElement('div', 'mediaoutletitem-' + aMediaItem.Id, 'media');
    mediaElementContent.innerHTML = aMediaItem.DisplayName;
    mediaElementContent.setAttribute('mediaid', aMediaItem.Id);
    mediaElementContent.setAttribute('itempath', aMediaItem.ItemPath);
    mediaElementContent.onclick = function() {
      var zId = 'remove-' + this.getAttribute('mediaid');
      var zRemoveElement = $('remove-' + this.getAttribute('mediaid'));
      DOM.getElementsWithClassName('span', 'remove-element-item').forEach(function(aElement) {
        if (!zRemoveElement) {
          aElement.style.display = 'none';
        }
        else {
          if(zRemoveElement.getAttribute('id')!=aElement.getAttribute('id')){
            aElement.style.display = 'none';
          }
        }
      });
      if (!zRemoveElement) {
        DOM.createRemoveElement(this.parentNode, 'remove-' + this.getAttribute('mediaid'), LiveAdMaker.Dealers.Media.removeMedia, {MediaItemPath:this.getAttribute('itempath')});
      }
      else {
        if (zRemoveElement.style.display == 'none') {
          zRemoveElement.style.display = 'block';
        }
        else {
          zRemoveElement.style.display = 'none';
        }
      }
    }
    mediaElement.appendChild(mediaElementContent);
    return mediaElement;
  },
  drawMediaData: function(aReceiveData,aParams) {
    if (aReceiveData) {
      var zEnabledMediaTypes = aReceiveData.GlobalMediaTypes.filter(function(aMediaType) {
        return (aMediaType.Disabled != "Y");
      });
      var mediaTypeList = aReceiveData.MediaTypes;
      var mediaList = aReceiveData.Media;
      LiveAdMaker.MediaTypeArray = zEnabledMediaTypes.makeUnique('Id');
    }
    var mediaId, mediaHeader, mediaElement, mediaElementContent;
    LiveAdMaker.Dealers.Media.drawMediaHeader(aParams.ContentElement);
    for(var i = 0; i < mediaTypeList.length; i++) {
      mediaId = mediaTypeList[i].Id;
      mediaAlias = mediaTypeList[i].ItemAlias;
      mediaHeader = LiveAdMaker.Dealers.Media.drawMediaType({MediaAlias:mediaAlias, DisplayName:mediaTypeList[i].DisplayName, Container:aParams.ContentElement});
      for(var j = 0; j < mediaList[mediaId].length; j++) {
        mediaElement = LiveAdMaker.Dealers.Media.drawMedia(mediaList[mediaId][j]);
        mediaHeader.appendChild(mediaElement);
      }
      aParams.ContentElement.appendChild(mediaHeader);
    }
    return true;
  },
  receiveMediaData: function(aReceiveData, aParams) {
    if (aReceiveData) {
      var mediaTypeList = aReceiveData.MediaTypes;
      aMediaList = aReceiveData.Media;
      var mediaId;
      var mediaHeader;
      var mediaElement;
      var mediaElementContent;
      for(var i = 0; i < mediaTypeList.length; i++) {
        mediaId = mediaTypeList[i].Id;
        mediaAlias = mediaTypeList[i].ItemAlias;
        mediaContainer = DOM.createElement('div', 'media-container');
        for(var j = 0; j < aMediaList[mediaId].length; j++) {
          mediaElement = LiveAdMaker.Dealers.Media.drawMedia(aMediaList[mediaId][j]);
          mediaContainer.appendChild(mediaElement);
          aParams.ContentElement.appendChild(mediaContainer);
        }
        mediaHeader = DOM.createActionElement('h2', LiveAdMaker.Dealers.Media.addMediaSearch, mediaTypeList[i].DisplayName, {MediaType:mediaAlias, Container:mediaContainer} );
        aParams.ContentElement.appendChild(mediaHeader);
        mediaHeader.appendChild(mediaContainer);
     }
     LiveAdMaker.Dealers.Media.MediaTypeList = mediaTypeList;
   }
    return true;
  },
  removeMedia: function(e, aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Dealers.Media.Dealer_ItemPath, "MapToMediaOutlet", 'inpDealerPointerPath=' + LiveAdMaker.Dealers.Media.Dealer_PointerPath + '&inpMediaItemPath=' + aParams.MediaItemPath + '&inpAddMode=false', true),
      Function: LiveAdMaker.Dealers.Media.updateMediaDisplay,
      Params: { Media_ItemPath: aParams.MediaItemPath, MediaType: null, AddMode: false }
    });
  },
  addMediaLocationSearch: function(e, aParams) {
    DOM.Dialog.hide();
    if (aParams.Id) {
      var zMediaLocationSearchContainer = $(aParams.Id);
    } else {
        var zMediaLocationSearchContainer = aParams.Container;
    }
    if ($('MediaTypeSelectContainer')) {
      $('MediaTypeSelectContainer').parentNode.removeChild($('MediaTypeSelectContainer'));
    }
    if ($('MediaLocationSearchContainer') != zMediaLocationSearchContainer.lastChild && $('MediaLocationSearchContainer')) {
      $('MediaLocationSearchContainer').parentNode.removeChild($('MediaLocationSearchContainer'));
    }
    LiveAdMaker.Dealers.Media.addMediaSearch('',{MediaType:aParams.MediaAlias, Container:zMediaLocationSearchContainer});
  },
  addMediaSearch: function(e, aParams) {
    var zMediaTypeAddParams = {
      Container:aParams.Container,
      MediaType:aParams.MediaType
    }
    if (!$('MediaLocationSearchContainer')) {
      var zMediaLocationSearchContainer = DOM.createElement("div","MediaLocationSearchContainer");
      if (zMediaTypeAddParams.MediaType) {
        var zMediaTypeSelect = DOM.createElement("input","inpMediaType");
        zMediaTypeSelect.setAttribute("type","hidden");
        zMediaTypeSelect.value = zMediaTypeAddParams.MediaType;
        zMediaLocationSearchContainer.appendChild(zMediaTypeSelect);
      }
      var zLocationSearchInput = DOM.createElement("input","inpKeywords", "ResizingRuleSelectsContainer");
      zLocationSearchInput.type="text";
      DOM.addEvent(zLocationSearchInput,"onkeypress",LiveAdMaker.Dealers.Media.addMedia,{KeyEvent:true, ReceiveFunction:aParams.ReceiveFunction, aMediaType:zMediaTypeAddParams.MediaType, Container:zMediaTypeAddParams.Container, aFilterByRegion:'N'});
      zMediaLocationSearchContainer.appendChild(zLocationSearchInput);
      var zLocationSearchButton = DOM.createTextElement("div","inpSearchMediaButton","Button_Medium","","Search");
      zMediaLocationSearchContainer.appendChild(zLocationSearchButton);
      zMediaTypeAddParams.Container.appendChild(zMediaLocationSearchContainer);
      DOM.addEvent(zLocationSearchButton, "onclick", LiveAdMaker.Dealers.Media.addMedia, {ReceiveFunction:aParams.ReceiveFunction, aMediaType:zMediaTypeAddParams.MediaType, Container:zMediaTypeAddParams.Container, aFilterByRegion:'N'});
    }
    else {
      var zMediaLocationSearch = $('MediaLocationSearchContainer');
      if (zMediaLocationSearch.style.display == 'none') {
        zMediaLocationSearch.style.display = 'block';
      }
      else {
        zMediaLocationSearch.style.display = 'none';
      }
    }
  },
  addMedia: function(e, params) {
    if (params.KeyEvent && e.keyCode != 13){return true;}
    var aKeywords = (params.aMediaOutletKeywords) ? params.aMediaOutletKeywords : ($('inpKeywords')) ? $('inpKeywords').value : "";
    if (aKeywords!="") {
      if (params.aMediaType) {
        var aMediaType = params.aMediaType;
      } else {
          var zMediaTypeDisplayName = (params.aSelectedMediaTypeDisplayName) ? params.aSelectedMediaTypeDisplayName : LiveAdMaker.MediaTypeArray.get($('inpMediaType').value).DisplayName;
          var aMediaType = (params.aSelectedMediaTypeAlias) ? params.aSelectedMediaTypeAlias : LiveAdMaker.MediaTypeArray.get($('inpMediaType').value).ObjectAlias;
      }
      var zSearchParams = 'aObjectTypeAlias=MediaLocationList&inpKeywords='+aKeywords+'&aMediaTypeAlias='+aMediaType;
      zSearchParams += params.aFilterByRegion=='N' ? '&aFilterByRegions=N' : '';
      var ReceiveFunction = params.ReceiveFunction;
      if (!params.ReceiveFunction)
        var ReceiveFunction = LiveAdMaker.Dealers.Media.receiveMediaLocations;
        var zLoadingIcon = DOM.createElement('div', 'SearchWaitingLoading', 'WaitingDialogLoading');
        zLoadingIcon.style.cssFloat = 'left';
        zLoadingIcon.style.styleFloat = 'left';
        zLoadingIcon.style.clear = 'both';
        params.Container.appendChild(zLoadingIcon);
      Ajax.makeRequest({
        URL: URI.pageURL('Javascript', "GetSearchResults", zSearchParams, true),
        Function: ReceiveFunction,
        Params: {Keywords:aKeywords, MediaType:aMediaType, MediaTypeDisplayName:zMediaTypeDisplayName, MediaTypeId:'', Container:params.Container, Event: {x : 620, y : 200} }
      });
    }
    return true;
  },
  receiveMediaLocations: function(aReceiveData, aParams) {
    var zMediaLocationSearchContainer = $('NewMediaOutletContainer');
    if ($('SearchWaitingLoading')) {
      DOM.removeElement($('SearchWaitingLoading'));
    }
    if ($('medialocation-searchresults')) {
      DOM.removeElement($('medialocation-searchresults'));
    }
    var zSearchResults = aReceiveData.Results;
    var zSearchResultContainer = DOM.createElement('div', 'medialocation-searchresults', 'searchresults-container');
    var zSearchResultUnorderedList = DOM.createElement('ul', null, 'medialocation-list');
    zSearchResultUnorderedList.style.paddingLeft = '0px';
    zSearchResultUnorderedList.style.marginLeft = '0px';
    zSearchResultUnorderedList.style.listStyle = 'none';
    zSearchResultContainer.style.cssFloat = 'left';
    zSearchResultContainer.style.styleFloat = 'left';
    for(var i = 0; i < zSearchResults.length; i++) {
      mediaItem = DOM.createElement('li', null, 'media');
      mediaLabel = DOM.createElement('label');
      mediaLabel.setAttribute('for', 'inpMediaLocation_' + zSearchResults[i].ObjectCode);
      mediaInput = DOM.createElement('input');
      mediaInput.name = 'inpMediaLocation';
      mediaInput.type = 'checkbox';
      mediaInput.setAttribute('id', 'inpMediaLocation_' + zSearchResults[i].ObjectCode);
      mediaInput.value = zSearchResults[i].ItemPath;
      mediaInput.onclick = function() {
        Ajax.makeRequest({
          URL: URI.pageURL(LiveAdMaker.Dealers.Media.Dealer_ItemPath, "MapToMediaOutlet", 'inpDealerPointerPath=' + LiveAdMaker.Dealers.Media.Dealer_PointerPath + '&inpMediaItemPath=' + this.value + '&inpAddMode=' + this.checked, true),
          Function: LiveAdMaker.Dealers.Media.updateMediaDisplay,
          Params: { Media_ItemPath:this.value, MediaType:aParams.MediaType, MediaTypeDisplayName:aParams.MediaTypeDisplayName, AddMode:this.checked, Container:aParams.Container }
        });
      }
      mediaTxt = document.createTextNode(zSearchResults[i].DisplayName);
      mediaLabel.appendChild(mediaInput);
      mediaLabel.appendChild(mediaTxt);
      mediaItem.appendChild(mediaLabel);
      zSearchResultUnorderedList.appendChild(mediaItem);
    }
    zSearchResultContainer.appendChild(zSearchResultUnorderedList);
    zMediaLocationSearchContainer.appendChild(zSearchResultContainer);
  },
  updateMediaDisplay: function(aReceiveData, aParams) {
    if (aReceiveData) {
      if(aReceiveData.NewPub=="Y") {
        LiveAdMaker.MediaLocations.Items = null;
        LiveAdMaker.MediaLocations.List = null;
      }
      if (aParams.AddMode) {
        LiveAdMaker.receiveNewItem(aReceiveData,{Params:{Section:"Dealers",SubSection:"Media"}});
      }
      else {
        LiveAdMaker.receiveArchiveItem(aReceiveData,{Section:"Dealers",SubSection:"Media",ItemId:aReceiveData.Id});
      }
    }
  },
  setAddMediaParams: function(e, aParams) {
    var zSelectedMediaType = e.Element.Form.getElement('MediaType','FieldId');
    var zMediaTypeOptionsArray = e.Element.Form.getElement('MediaType','FieldId').OptionsArray;
      for (var i=0; i<zMediaTypeOptionsArray.length; i++) {
        if (zMediaTypeOptionsArray[i].DisplayName == zSelectedMediaType.DisplayValue || zMediaTypeOptionsArray[i].DisplayName == zSelectedMediaType.Value) {
          var zSelectedMediaTypeItemPath = zMediaTypeOptionsArray[i].ItemPath;
        }
      }
    var zMediaOutletKeywords = e.Element.Form.getElement('MediaOutletSearch','FieldId').Value;
    var zSelectedMediaTypePathArray =  zSelectedMediaTypeItemPath.split('\\');
    var zSelectedMediaTypeAlias =  zSelectedMediaTypePathArray[zSelectedMediaTypePathArray.length - 1];
    var zSelectedMediaTypeDisplayName = e.Element.Form.getElement('MediaType','FieldId').DisplayValue;
    if (LiveAdMaker.SelectedSectionId == "Dealers") {
      var zParams = {
                      Container:                     $('NewMediaOutletContainer'),
                      aSelectedMediaTypeDisplayName: zSelectedMediaTypeDisplayName,
                      aSelectedMediaTypeAlias:       zSelectedMediaTypeAlias,
                      aMediaOutletKeywords:          zMediaOutletKeywords
                    };
    } else {
        var zParams = {
                        ReceiveFunction:               LiveAdMaker.MediaLocations.New.receiveSearchResults,
                        Container:                     $('NewMediaOutletContainer'),
                        aFilterByRegion:               'N',
                        aSelectedMediaTypeDisplayName: zSelectedMediaTypeDisplayName,
                        aSelectedMediaTypeAlias:       zSelectedMediaTypeAlias,
                        aMediaOutletKeywords:          zMediaOutletKeywords
                      };
    }
    LiveAdMaker.Dealers.Media.addMedia(e, zParams);
    return true;
  }
};
LiveAdMaker.Dealers.Users = {
  CurrentItem: null,
  ContentElement: null,
  AssetList: null,
  QuickSearchOptions: {
    GetSearchCategoriesExtraParams: "aObjectTypeAlias=UserGroup&aGetFormObjectType=UserLink&aFormType=StagingUserDetails",
    SearchExtraParams: "aObjectTypeAlias=UserGroup",
    SearchObjectTypes: "User"
  },
  Actions: [
    {
      Id: "Info",
      DisplayName: "Details",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Users.Info.init(aParams);
        return true;
      }
    },
    {
      Id: "Access",
      DisplayName: "Access",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Users.Access.init(aParams);
        return true;
      }
    },
    {
      Id: "Groups",
      DisplayName: "Groups",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Users.Groups.init(aParams);
        return true;
      }
    },
    {
      Id: "Approvers",
      DisplayName: "Approvers",
      DisplayFunction: function(aParams) {
        FormUI.Request.getForm(aParams.Item.ItemPath, 'SetupApprovers', aParams.ContentElement,"", "");
        return true;
      }
    },
    {
      Id: "Restrictions",
      DisplayName: "Restrictions",
      DisplayFunction: function(aParams){
        LiveAdMaker.Dealers.Users.Restrictions.init(aParams);
        return true;
      }
    },
    {
      Id: "Orders",
      DisplayName: "Orders",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Dealers.Users.Orders.init(aParams);
        return true;
      }
    },
    {
      Id: "History",
      DisplayName: "History",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Dealers.Users.History.init(aParams);
        return true;
      }
    }
  ],
  draw: function(aParams) {
  },
  archiveItem:function(aParams){
    var zMoveToPath = LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath+"\\ArchivedUserList"
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues:{
        aMoveToPath: zMoveToPath,
        aUserPath: aParams.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  }
}
LiveAdMaker.Dealers.Users.Restrictions = {
  CurrentItem: null,
  ContentElement: null,
  init: function(aParams) {
    LiveAdMaker.Dealers.Users.Restrictions.CurrentItem = aParams.Item;
    LiveAdMaker.Dealers.Users.Restrictions.ContentElement = aParams.ContentElement;
    LiveAdMaker.Dealers.Users.Restrictions.ContentElement.innerHTML = '';
    FormUI.Request.getForm(aParams.Item.ItemPath, 'Restrictions', aParams.ContentElement,'','');
    return true;
  }
}
LiveAdMaker.Dealers.Users.Orders = {
  init: function(aParams) {
    aParams.SectionId    = "Dealers";
    aParams.ActionId     = "Users";
    aParams.SubActionId  = "Orders";
    aParams.ViewType     = "table";
    aParams.ShowNavigation = false;
    aParams.URL          = URI.pageURL(aParams.Item.ItemPath, "GetOrderList", null, true);
    aParams.TripleBubble = true;
    LiveAdMaker.requestTripleBubbleItems(aParams);
    return true;
  }
}
LiveAdMaker.Dealers.Users.History = {
  init: function(aParams) {
    LiveAdMaker.Dealers.Users.History.CurrentItem = aParams.Item;
    LiveAdMaker.Dealers.Users.History.ContentContainer = aParams.ContentElement;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetUserHistory", null, true),
      Function: LiveAdMaker.Dealers.Users.History.drawUserHistory,
      Params: {Section: aParams.Section, Params: aParams}
    });
    return true;
  },
  drawUserHistory: function(aResults,aParams) {
    if (aResults&&aResults.Data){
      if (aResults.Data.length>0) {
        var zUserHistoryTable = DOM.createElement("table","tb_UserHistory","UserHistoryTable","");
        DOM.replaceContent(LiveAdMaker.Dealers.Users.History.ContentContainer, zUserHistoryTable);
        var zUserHistoryTableBody = DOM.createElement("tbody");
        zUserHistoryTable.appendChild(zUserHistoryTableBody);
        zUserHistoryRow = DOM.createElement("tr","","","");
        zUserHistoryDateTimeHeader = DOM.createElement("th","","","");
        zUserHistoryUserHeader = DOM.createElement("th","","","");
        zUserHistoryTableBody.appendChild(zUserHistoryRow);
        zUserHistoryRow.appendChild(zUserHistoryDateTimeHeader);
        zUserHistoryDateTimeHeader.innerHTML = "Date &amp; Time";
        zUserHistoryRow.appendChild(zUserHistoryUserHeader);
        zUserHistoryUserHeader.innerHTML = "User";
        for (var i=0; i<aResults.Data.length; i++) {
          var zDateTime = aResults.Data[i].DateTime;
          var zUser     = aResults.Data[i].User;
          zUserHistoryRow = DOM.createElement("tr","","","");
          zUserHistoryDateTime = DOM.createElement("td","","","");
          zUserHistoryUser = DOM.createElement("td","","","");
          zUserHistoryTableBody.appendChild(zUserHistoryRow);
          zUserHistoryRow.appendChild(zUserHistoryDateTime);
          zUserHistoryDateTime.innerHTML = zDateTime;
          zUserHistoryRow.appendChild(zUserHistoryUser);
          zUserHistoryUser.innerHTML = zUser;
        }
      } else {
          var zMessageContainer = DOM.createTextElement("div", "NoHistoryMessageContainer", "", "", "No Login History Available");
          DOM.replaceContent(LiveAdMaker.Dealers.Users.History.ContentContainer, zMessageContainer);
          zMessageContainer.style.marginTop = '15px';
          zMessageContainer.style.marginLeft = '15px';
      }
    }
    return true;
  }
}
LiveAdMaker.Dealers.Members = {
  CurrentItem: null,
  ContentElement: null,
  init: function(aParams) {
    LiveAdMaker.Dealers.Members.CurrentItem = aParams.Item;
    LiveAdMaker.Dealers.Members.ContentElement = aParams.ContentElement;
    FormUI.Request.getForm(aParams.Item.ItemPath, 'Members', aParams.ContentElement,'','');
    return true;
  }
}
LiveAdMaker.Dealers.Actions.Imagery = {
  init:function(aParams){
    LiveAdMaker.Dealers.Actions.Imagery.CurrentItem=aParams.Item;
    LiveAdMaker.Dealers.Actions.Imagery.ContentContainer=aParams.ContentElement;
    LiveAdMaker.Dealers.Actions.Imagery.ContentContainer.innerHTML="";
    var zURL = LiveAdMaker.Dealers.Actions.Imagery.CurrentItem.PointerPath ? LiveAdMaker.Dealers.Actions.Imagery.CurrentItem.PointerPath : LiveAdMaker.Dealers.Actions.Imagery.CurrentItem.ItemPath;
    Ajax.makeRequest({
      URL: URI.pageURL(zURL,'getImages'),
      Function: LiveAdMaker.Dealers.Actions.Imagery.drawImages
    });
    return true;
  },
  drawImages: function (aProductSettings) {
    if ($("ImageAssetTableContainer")){
      $("ImageAssetTableContainer").innerHTML="";
      var zTableContainer = $("ImageAssetTableContainer");
    }else{
      var zTableContainer = DOM.createElement("div","ImageAssetTableContainer");
    }
    zTableContainer.style.display = "none";
    var zTable = DOM.createElement("table","ImageAssetTable");
    zTableContainer.appendChild(zTable);
    LiveAdMaker.Dealers.Actions.Imagery.ContentContainer.appendChild(zTableContainer);
    var zTableBody = DOM.createElement("tbody");
    zTable.appendChild(zTableBody);
    var zArrayCount ="0";
    aProductSettings.Assets.forEach(function(aImageAsset) {
      if (aImageAsset.ImageURL){
        if((zArrayCount%3)==0) {
          var zImageAssetRow = DOM.createElement("tr");
          zTableBody.appendChild(zImageAssetRow);
          zTableBody.CurrentRow = zImageAssetRow;
          var zImageAssetNameRow = DOM.createElement("tr");
          zTableBody.appendChild(zImageAssetNameRow);
          zTableBody.CurrentRow2 = zImageAssetNameRow;
        }
       if (aImageAsset.ImageURL){
        var zImageAssetTD = DOM.createElement("td","","ImageAssetTD");
        zImageAssetTD.innerHTML += '<img src='+aImageAsset.ImageURL_Medium+'>';
        var zImageParams={
          Element: aImageAsset
        }
        DOM.addEvent(zImageAssetTD,"onclick",LiveAdMaker.Dealers.Actions.Imagery.editImage,zImageParams);
        zTableBody.CurrentRow.appendChild(zImageAssetTD);
        var zImageAssetNameTD = DOM.createElement("td","","ImageAssetNameTD");
        zImageAssetNameTD.innerHTML = aImageAsset.DisplayName;
        zTableBody.CurrentRow2.appendChild(zImageAssetNameTD);
      }
      zArrayCount++
     }
    });
    zTableContainer.style.display = "block";
  },
  showDetails: function (e,aParams){
    var zDetailsContainer = DOM.createElement('div','DetailsContainer','ImageDetails');
    var zEditImageLink = DOM.createElement('div','','DetailsLinkContainer');
    zEditImageLink.innerHTML = "Edit Image";
    zDetailsContainer.appendChild(zEditImageLink);
    DOM.addEvent(zEditImageLink,"onclick",LiveAdMaker.Dealers.Actions.Imagery.editImage,aParams);
    DOM.Dialog.show(zDetailsContainer,e);
  },
  editImage: function (e,aParams){
    DOM.Dialog.hide();
    var newWindow = window.open(aParams.Element.ItemPath.toPagePath()+ ".EditImage?","RequiredArea","status=1,resizable=1,scrollbars=1,height=650,width=900");
    if (window.focus) {newWindow.focus()}
  }
}
    // ---------------------- End Action_LiveAdMaker_Dealers ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_Layouts --------------- //
LiveAdMaker.Layouts = {
  CurrentPage: "1",
  Name: "Layouts",
  QuickSearchOptions: {
    GetSearchCategoriesExtraParams: "aGetFormObjectType=Layout&aFormType=AdStyleDetails",
    SearchObjectTypes: "Layout"
  },
  Load: function(aParams){
    var zSection = LiveAdMaker.Layouts;
    if(!zSection.Items) {
      Ajax.makeRequest({
        URL: URI.pageURL(unescape('intel\\SystemReferenceList\\LayoutList'), "GetList", "", true),
        Function: LiveAdMaker.receiveSectionData,
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
    }
    else {
      LiveAdMaker.drawSection(aParams);
    }
    return true;
  },
  draw: function(aParms){
    return true;
  },
  createNewItem: function(aParams) {
    var zAdstyleTypeContainer = DOM.createElement('div','AdstyleTypeContainer');
    var zAnimatedGifLink = DOM.createElement('div','','AdStyleLinkContainer');
    zAnimatedGifLink.innerHTML = "Animated Gif - Online Ads";
    zAdstyleTypeContainer.appendChild(zAnimatedGifLink);
    DOM.addEvent(zAnimatedGifLink,"onclick",LiveAdMaker.Layouts.createAdstyle,{Params: aParams, Type: "Animated Gif", TotalBackgrounds: "0", BackgroundType: "", AssetType: "GIF", IsSequence: "Y"});
    var z2DLayoutLink = DOM.createElement('div','','AdStyleLinkContainer');
    z2DLayoutLink.innerHTML = "2D Layout - Print Ads";
    zAdstyleTypeContainer.appendChild(z2DLayoutLink);
    DOM.addEvent(z2DLayoutLink,"onclick",LiveAdMaker.Layouts.createAdstyle,{Params: aParams, Type: "2D Layout", TotalBackgrounds: "0", BackgroundType: "", AssetType: "PDF", IsSequence: "N"});
    var zHTMLLink = DOM.createElement('div','','AdStyleLinkContainer');
    zHTMLLink.innerHTML = "HTML - Website";
    zAdstyleTypeContainer.appendChild(zHTMLLink);
    DOM.addEvent(zHTMLLink,"onclick",LiveAdMaker.Layouts.createAdstyle,{Params: aParams, IsWebsite: "Y", Type: "HTML", TotalBackgrounds: "0", BackgroundType: "", AssetType: "HTML", IsSequence: "N"});
    var zAudioLink = DOM.createElement('div','','AdStyleLinkContainer');
    zAudioLink.innerHTML = "Audio - Radio Ads";
    zAdstyleTypeContainer.appendChild(zAudioLink);
    DOM.addEvent(zAudioLink,"onclick",LiveAdMaker.Layouts.createAdstyle,{Params: aParams, Type: "Audio", TotalBackgrounds: "1", BackgroundType: "Audio", AssetType: "Audio", IsSequence: "Y"});
    var zVideoLink = DOM.createElement('div','','AdStyleLinkContainer');
    zVideoLink.innerHTML = "Video - Tv Ads";
    zAdstyleTypeContainer.appendChild(zVideoLink);
    DOM.addEvent(zVideoLink,"onclick",LiveAdMaker.Layouts.createAdstyle,{Params: aParams, Type: "Video", TotalBackgrounds: "2", BackgroundType: "Audio,Video", AssetType: "Video", IsSequence: "Y"});
    DOM.Dialog.show(zAdstyleTypeContainer,'cursor','What AdStyle type would you like to add?','320','150');
    return true;
  },
  createAdstyle: function(e,aCreateParams){
    DOM.Dialog.hide();
    Ajax.makeRequest({
      URL: URI.pageURL("intel\\SystemReferenceList\\LayoutList", "CreateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Layouts", Function:LiveAdMaker.drawSection, Params:aCreateParams.Params},
      PostValues: {
        aObjectTypeAlias: "Layout",
        aAlias: "Layouts".makeUnique(),
        aName: "Layout "+(LiveAdMaker.SelectedSection.Items.length+1),
        aAdStyleType: aCreateParams.Type,
        aTotalBackgrounds: aCreateParams.TotalBackgrounds,
        aBackgroundTypes: aCreateParams.BackgroundType,
        aIsSequence: aCreateParams.IsSequence,
        aIsWebsite: aCreateParams.IsWebsite,
        aAssetType: aCreateParams.AssetType
      },
      Method:'POST'
    });
    return true;
  },
  duplicateItem: function(aParams) {
    if (aParams && aParams.CopyToPath) {
      var zCopyToPath = aParams.CopyToPath
    }
    else {
      var zCopyToPath = "intel\\SystemReferenceList\\LayoutList"
    }
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var aParams = {
      View: "ActionsWithName",
      Section: "Layouts",
      Action: "Details"
    }
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Layouts", Function: LiveAdMaker.drawSection, Params: aParams},
      PostValues: {
        aAlias: "Layout".makeUnique(),
        aName: "Copy of "+zSelectedItem.DisplayName,
        aCopyToPath: unescape(zCopyToPath)
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    var zMoveToPath = "intel\\SystemReferenceList\\ArchivedLayoutList"
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues:{
        aMoveToPath: zMoveToPath
      },
      Method:'POST'
    });
  },
  Actions: [
    {
      Id: "DetailsV2",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        LiveAdMaker.AdStyleDetails.init(aParams);
        return true;
      }
    },
    {
      Id: "LayoutV2",
      DisplayName: "Layout",
      DisplayFunction: function(aParams){
        LiveAdMaker.AreaLayout.init(aParams,LiveAdMaker.Layouts.Name);
        return true;
      }
    },
    {
      Id: "Resizing",
      DisplayName: "Resizing",
      DisplayFunction: function(aParams){
        LiveAdMaker.Layouts.Resizing.init(aParams);
        return true;
      }
    },
    {
      Id: "Groups",
      DisplayName: "Groups",
      DisplayFunction: function(aParams){
        LiveAdMaker.Layouts.Groups.init(aParams);
        return true;
      }
    }
  ],
  AreaActions: [
    {
      Id: "AreaDetails",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
         LiveAdMaker.Layouts.AreaDetails.init(aParams);
         return true;
      }
    }
  ],
  generateLayout: function(aData, aParams){
    var zLayout = {
      Layout: aData,
      AspectRatio: aData.AspectRatio,
      IdField: 'Id',
      MaxWidth:  aParams.MaxWidth || 300,
      MaxHeight: aParams.MaxHeight || 500,
      ElementTag: aParams.ElementTag || "a",
      UseBackground: false,
      DrawOnSamePage: true,
      PageSpacing:0
    };
    var zLayoutContainerDiv = DOM.createElement('div');
    zLayoutContainerDiv.style.top = '10px';
    zLayoutContainerDiv.style.right = '10px';
    LiveAdMaker.Layouts.Wireframe = Layout.createWireframe(zLayout);
    LiveAdMaker.Layouts.Wireframe.PageArray.forEach(function(aPage){
      DOM.removeClass(aPage.EmptyArea,"Show");
      DOM.addClass(aPage.EmptyArea,"Hide");
      aPage.AreaArray.forEach(function(aArea){
      DOM.removeClass(aArea,"Show");
        DOM.addClass(aArea,"Hide");
      });
    });
    var zEnabledPage = LiveAdMaker.Layouts.Wireframe.PageArray.get("Page"+aParams.SelectedPage);
    DOM.removeClass(zEnabledPage.EmptyArea,"Hide");
    DOM.addClass(zEnabledPage.EmptyArea,"Show");
    zEnabledPage.AreaArray.forEach(function(aEnabledArea){
      if (aEnabledArea.PageNumber !="0"){
        DOM.removeClass(aEnabledArea,"Hide");
        DOM.addClass(aEnabledArea,"Show");
      }
    });
    if (aParams.SetAreas != 'N'){
      aData.AreaArray.forEach(function(aArea){
        if (aArea.PageNumber !="0"){
          LiveAdMaker.Layouts.setupArea(aArea,aParams.Section);
        }
      });
      if (aParams.AreaUpdated == "Y"){
        setTimeout(function() {
          DOM.getElementsWithClassName("a","selectedArea").forEach(function (zAreaLink){
            DOM.removeClass(zAreaLink, "selectedArea");
          });
          var zSelectedArea2 = $(aParams.SelectedPage+'_'+aParams.SelectedAreaId);
          if (zSelectedArea2){
            DOM.addClass (zSelectedArea2,"selectedArea");
          }
        }, 700);
      }
    }
    zLayoutContainerDiv.appendChild(LiveAdMaker.Layouts.Wireframe.Container);
    DOM.replaceContent(aParams.ContentElement,zLayoutContainerDiv);
    return true;
  },
  setupArea: function (aArea,SectionName){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zSectionReference = "Layouts";
    var zItemIdReference = zSelectedItem.Id;
    var zAreaWireframe = LiveAdMaker.Layouts.Wireframe.AreaList[aArea.Id];
    DOM.makeHoverable(zAreaWireframe);
    zAreaWireframe.setAttribute("Id",aArea.PageNumber+'_'+aArea.Id);
    var aGoToHash = '#Section='+zSectionReference+'&Item='+zItemIdReference+'&Action='+SectionName+'&SubItem='+aArea.Id;
    URI.setHashLink(zAreaWireframe,aGoToHash);
    zAreaWireframe.innerHTML = '<span id="AreaDisplayName">'+aArea.DisplayName+'</span>';
  },
  reloadLayout: function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var getPageNumberArray= aParams.Element.Field.split("_");
    setTimeout(function() {
      Ajax.makeRequest({
        URL: URI.pageURL(zSelectedItem.ItemPath, "RequestArea", "aSize=500", false),
        Function: LiveAdMaker.Layouts.generateLayout,
        Params: {ContentElement: $('LayoutImageContainer'), Section: "Layout", SelectedPage: getPageNumberArray[1], SelectedAreaId: aParams.Element.CSVRowId, AreaUpdated: "Y"}
      });
    }, 700);
    return true;
  },
  updateDisplayName: function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zSelectedSection="Layout";
    var zSelectedContentElement =$('LayoutImageContainer');
    setTimeout(function() {
      Ajax.makeRequest({
        URL: URI.pageURL(zSelectedItem.ItemPath, "RequestArea", "aSize=500", false),
        Function: LiveAdMaker.Layouts.generateLayout,
        Params: {ContentElement: zSelectedContentElement, Section: zSelectedSection, SelectedPage: LiveAdMaker.Layouts.CurrentPage}
      });
    }, 500);
    return true;
  },
  trackAdElementCount: function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath,'TrackAdElementCount'),
      Function: function(){return true;},
      PostValues:{
        aValue: aParams.Element.Value,
        aOriginalValue: aParams.Original,
        aCSVColumnId: aParams.Element.CSVColumnId,
        aCSVEncoding: aParams.Element.CSVEncoding,
        aCSVRowId: aParams.Element.CSVRowId
      },
      Method:'POST'
    });
    LiveAdMaker.Layouts.showAdditionalFields();
    return true;
  },
  reDrawLayout:function (aParams){
    if (aParams.Element.CSVRowNumber == undefined){
      var zSelectedPageNumber = "1";
    }else{
      var zSelectedPageNumber = aParams.Element.CSVRowNumber;
    }
    setTimeout(function() {
      var zWireFrameReference = $("WireFrameContainer");
      zWireFrameReference.parentNode.removeChild(zWireFrameReference);
      LiveAdMaker.Layouts.Details.getAreas(zSelectedPageNumber);
    }, 500);
    return true;
  },
  setAdstyleType:function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath,'setLayoutType'),
      Function: function(){return true;},
      PostValues:{
        aValue: aParams.Element.Value
      },
      Method:'POST'
    });
    LiveAdMaker.Layouts.showSequenceFields(aParams);
    return true;
  },
  updateDimensionDisplay:function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath,'UpdateAdstyleDimensions'),
      Function: LiveAdMaker.Layouts.changeDimensionDisplay,
      PostValues:{
        aConvertTo: aParams.Element.Value
      },
      Method:'POST'
    });
    return true;
  },
  changeDimensionDisplay:function (aTempPageList){
    aTempPageList.TempPageListArray.forEach(function(aPage){
      FormUI.ElementArray.forEach(function(aElement){
        if (aElement.CSVRowNumber == aPage.PageNumber){
          if (aElement.CSVColumnId =="DisplayWidth"){
            $(aElement.ElementId).innerHTML = aPage.DisplayWidth;
            $(aElement.ElementId).Value = aPage.DisplayWidth;
            aElement.Value = aPage.DisplayWidth;
          }
          if (aElement.CSVColumnId =="DisplayHeight"){
            $(aElement.ElementId).innerHTML = aPage.DisplayHeight;
            aElement.Value = aPage.DisplayHeight;
          }
        }
      });
    });
    return true;
  },
  updateDPIValue:function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath,'UpdateDimensionsDPI'),
      Function: LiveAdMaker.Layouts.changeDPIDisplay,
      PostValues:{
        aNewDPIValue: aParams.Element.Value,
        aOldDPIValue: aParams.Original
      },
      Method:'POST'
    });
    return true;
  },
  changeDPIDisplay:function (aTempPageList){
    if (aTempPageList.updateDisplay =="Y"){
      aTempPageList.TempPageListArray.forEach(function(aPage){
        FormUI.ElementArray.forEach(function(aElement){
          if (aElement.CSVRowNumber == aPage.PageNumber){
            if (aElement.CSVColumnId =="DisplayWidth"){
              $(aElement.ElementId).innerHTML = aPage.DisplayWidth;
              $(aElement.ElementId).Value = aPage.DisplayWidth;
              aElement.Value = aPage.DisplayWidth;
            }
            if (aElement.CSVColumnId =="DisplayHeight"){
              $(aElement.ElementId).innerHTML = aPage.DisplayHeight;
              aElement.Value = aPage.DisplayHeight;
            }
          }
        });
      });
    }
    setTimeout(function() {
      var zWireFrameReference = $("WireFrameContainer");
      zWireFrameReference.parentNode.removeChild(zWireFrameReference);
      LiveAdMaker.Layouts.Details.getAreas("1");
    }, 500);
    return true;
  },
  showSequenceFields:function (aData, aParams){
    var zLayoutDetailsForm = LiveAdMaker.Layouts.Details.DetailsForm;
    zLayoutDetailsForm.ElementArray.forEach(function(aElement){
      switch (aElement.SeqNo) {
        case 2 :
          if (aElement.DisplayValue == "2D Layout" || aElement.DisplayValue == "HTML"){
            var zDurationElement = zLayoutDetailsForm.ElementArray.get('Layout_AdStyleDuration','FieldId');
            if (zDurationElement[0].ElementId){
              $("label-"+zDurationElement[0].ElementId).style.display ="none";
              $(zDurationElement[0].ElementId).style.display = "none";
            }
            var zDimensionElement = zLayoutDetailsForm.ElementArray.get('AdStyleDimensions','FieldId');
            if (zDimensionElement[0].ElementId){
              $("label-"+zDimensionElement[0].ElementId).style.display ="none";
              $(zDimensionElement[0].ElementId).style.display = "none";
            }
            var zWidthElement = zLayoutDetailsForm.ElementArray.get('AdStyleWidth','FieldId');
            if (zWidthElement[0].ElementId){
              $("label-"+zWidthElement[0].ElementId).style.display ="none";
              $(zWidthElement[0].ElementId).style.display = "none";
            }
            var zHeightElement = zLayoutDetailsForm.ElementArray.get('AdStyleHeight','FieldId');
            if (zHeightElement[0].ElementId){
              $("label-"+zHeightElement[0].ElementId).style.display ="none";
              $(zHeightElement[0].ElementId).style.display = "none";
            }
            var zLoopElement = zLayoutDetailsForm.ElementArray.get('AdStyleLoopCount','FieldId');
            if (zLoopElement[0].ElementId){
              $("label-"+zLoopElement[0].ElementId).style.display ="none";
              $(zLoopElement[0].ElementId).style.display = "none";
            }
          }else{
            var zDurationElement = zLayoutDetailsForm.ElementArray.get('Layout_AdStyleDuration','FieldId');
            var zTotalDuration = (parseInt($(zDurationElement[0].ElementId).innerHTML)/1000);
            if (zDurationElement[0].ElementId){
              $(zDurationElement[0].ElementId).innerHTML = zTotalDuration+'s';
            }
            var zUnitElement = zLayoutDetailsForm.ElementArray.get('AdStyleUnit','FieldId');
            if (zUnitElement[0].ElementId){
              $("label-"+zUnitElement[0].ElementId).style.display ="none";
              $(zUnitElement[0].ElementId).style.display = "none";
            }
            var zMediaTypeElement = zLayoutDetailsForm.ElementArray.get('AdstyleMediaType','FieldId');
            if (zMediaTypeElement[0].ElementId){
              $("label-"+zMediaTypeElement[0].ElementId).style.display ="none";
              $(zMediaTypeElement[0].ElementId).style.display = "none";
            }
            $("CSVTable").style.display = "none";
          }
          break;
        default:
      }
    });
    return true;
  },
  showAdditionalFields:function (aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "RequestArea", "aSize=500", false),
      Function: LiveAdMaker.Layouts.showValues
    });
  },
  showValues:function (aData){
    FormUI.ElementArray.forEach(function(aElement){
      switch (aElement.SeqNo) {
        case 2 :
        if (aData != undefined){
          if (aData.AssetType == "Video"){
            if (aElement.DisplayValue == "Video"||aElement.DisplayValue == "Audio"){
              var zStretchtoFitFullAreaElement = FormUI.ElementArray.get('StretchtoFitFullArea','FieldId');
              if (zStretchtoFitFullAreaElement[0].ElementId){
                $("label-"+zStretchtoFitFullAreaElement[0].ElementId).style.display ="none";
                $(zStretchtoFitFullAreaElement[0].ElementId).style.display = "none";
              }
            }else{
              var zStretchtoFitFullAreaElement = FormUI.ElementArray.get('StretchtoFitFullArea','FieldId');
              if (zStretchtoFitFullAreaElement[0].ElementId){
                $("label-"+zStretchtoFitFullAreaElement[0].ElementId).style.display ="block";
                $(zStretchtoFitFullAreaElement[0].ElementId).style.display = "block";
              }
            }
          }else{
            var zStretchtoFitFullAreaElement = FormUI.ElementArray.get('StretchtoFitFullArea','FieldId');
            if (zStretchtoFitFullAreaElement[0].ElementId){
              $("label-"+zStretchtoFitFullAreaElement[0].ElementId).style.display ="none";
              $(zStretchtoFitFullAreaElement[0].ElementId).style.display = "none";
            }
          }
        }else{
          var zStretchtoFitFullAreaElement = FormUI.ElementArray.get('StretchtoFitFullArea','FieldId');
          if (zStretchtoFitFullAreaElement[0].ElementId){
            $("label-"+zStretchtoFitFullAreaElement[0].ElementId).style.display ="none";
            $(zStretchtoFitFullAreaElement[0].ElementId).style.display = "none";
          }
        }
          break;
        case 5 :
          var zLeftElement = FormUI.ElementArray.get('Left','FieldId');
          if (zLeftElement[0].ElementId){
            $("label-"+zLeftElement[0].ElementId).innerHTML ="Left ("+aData.Unit+")";
          }
          break;
        case 6 :
          var zTopElement = FormUI.ElementArray.get('Top','FieldId');
          if (zTopElement[0].ElementId){
            $("label-"+zTopElement[0].ElementId).innerHTML ="Top ("+aData.Unit+")";
          }
          break;
        case 7 :
          var zWidthElement = FormUI.ElementArray.get('Width','FieldId');
          if (zWidthElement[0].ElementId){
            $("label-"+zWidthElement[0].ElementId).innerHTML ="Width ("+aData.Unit+")";
          }
          break;
        case 8 :
          var zHeightElement = FormUI.ElementArray.get('Height','FieldId');
          if (zHeightElement[0].ElementId){
            $("label-"+zHeightElement[0].ElementId).innerHTML ="Height ("+aData.Unit+")";
          }
          break;
        default:
      }
    });
  }
};
LiveAdMaker.Layouts.Details = {
  DetailsForm: null,
  init:function(aParams){
    LiveAdMaker.Layouts.Details.ContentElement=aParams.ContentElement;
    LiveAdMaker.Layouts.Details.CurrentItem=aParams.Item;
    var aFormParams = {OnDisplayFunction: LiveAdMaker.Layouts.showSequenceFields}
    LiveAdMaker.Layouts.Details.DetailsForm = FormUI.Request.getForm(aParams.Item.ItemPath, 'DevAdStyleDetails', aParams.ContentElement,'',aFormParams);
    LiveAdMaker.Layouts.Details.getAreas("1");
    return true;
  },
  loadSelectedPage: function(e,aParams){
    if (aParams.IncrementPage == "Y"){
      if (aParams.CurrentPage == aParams.TotalPages){
        var zNextPage = aParams.TotalPages;
        var zDoNothing = "Y";
      }else {
        var zNextPage = parseInt(aParams.CurrentPage) + parseInt("1");
        var zDoNothing = "N";
      }
    }else{
      if (aParams.CurrentPage == "1"){
        var zNextPage = aParams.CurrentPage;
        var zDoNothing = "Y";
      }else {
        var zNextPage = parseInt(aParams.CurrentPage) - parseInt("1");
        var zDoNothing = "N";
      }
    }
    aCurrentPage = zNextPage;
    if (zDoNothing != "Y"){
      var zWireFrameReference = $("WireFrameContainer");
      zWireFrameReference.parentNode.removeChild(zWireFrameReference);
      LiveAdMaker.Layouts.Details.getAreas(zNextPage);
    }
  },
  getAreas: function(aPageNumber) {
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Layouts.Details.CurrentItem.ItemPath, "RequestArea", null, false),
      Function: LiveAdMaker.Layouts.Details.showWireframes,
      Params: {SelectedPage: aPageNumber}
    });
    return true;
  },
  showWireframes: function(aAreas,aParams){
    var zWireFrameContainer = DOM.createElement('div','WireFrameContainer');
    zWireFrameContainer.style.marginLeft = "435px";
    var zPageSelectionContainer = DOM.createElement('div','PageSelectionContainer2');
    var zPageSelection = DOM.createElement('div','PageSelection2');
    var zPageDisplayName = "";
    aAreas.PageArray.forEach(function(aPage){
      if (aPage.PageNumber == aParams.SelectedPage){
        zPageDisplayName = aPage.DisplayName;
      }
    });
    zPageSelection.innerHTML = '<div id="PageSelectionLeftArrow"></div><div id="PageName" style="float:left;">'+zPageDisplayName+'</div><div id="PageSelectionRightArrow"></div>';
    zPageSelectionContainer.appendChild(zPageSelection);
    zWireFrameContainer.appendChild(zPageSelectionContainer);
    LiveAdMaker.Layouts.Details.ContentElement.appendChild(zWireFrameContainer);
    var zImageContainer = DOM.createElement('div','DetailsLayoutImageContainer');
    zWireFrameContainer.appendChild(zImageContainer);
    var Params ={
      ElementTag: 'div',
      SetAreas: "N",
      ContentElement: zImageContainer,
      Section: "Layout",
      SelectedPage: aParams.SelectedPage,
      IsDetailsPage: "Y",
      MaxWidth: "200",
      MaxHeight: "350"
    };
    LiveAdMaker.Layouts.generateLayout(aAreas,Params);
    DOM.addEvent($('PageSelectionRightArrow'),"onclick",LiveAdMaker.Layouts.Details.loadSelectedPage,{CurrentPage: aParams.SelectedPage, TotalPages: aAreas.PageArray.length, IncrementPage: "Y"});
    DOM.addEvent($('PageSelectionLeftArrow'),"onclick",LiveAdMaker.Layouts.Details.loadSelectedPage,{CurrentPage: aParams.SelectedPage, TotalPages: aAreas.PageArray.length, IncrementPage: "N"});
    return true;
  }
}
LiveAdMaker.Layouts.AreaDetails = {
  init: function(aParams) {
    LiveAdMaker.Layouts.AreaDetails.CurrentItem = aParams.Item;
    LiveAdMaker.Layouts.AreaDetails.ContentContainer = aParams.ContentElement;
    DOM.getElementsWithClassName("a","selectedArea").forEach(function (zAreaLink){
      DOM.removeClass(zAreaLink, "selectedArea");
    });
    DOM.getElementsWithClassName("div","selectedArea2").forEach(function (zAreaLink2){
      DOM.removeClass(zAreaLink2, "selectedArea2");
    });
   var zSelectedArea = $(aParams.Item.PageNumber+'_'+aParams.Item.Id);
   if (zSelectedArea){
     DOM.addClass (zSelectedArea,"selectedArea");
   }
   var zSelectedBackground = $("BGArea_"+aParams.Item.Id);
   if (zSelectedBackground){
     DOM.addClass (zSelectedBackground,"selectedArea2");
   }
   if (aParams.Item.Id == "PageInput"+aParams.Item.PageNumber){
     var aAdditionalUrlParams = '&aRowId='+aParams.Item.Id;
     FormUI.Request.getForm(LiveAdMaker.Layouts.Layout.ItemPath,'LayoutPageDetails', aParams.ContentElement,aAdditionalUrlParams);
   }else{
     var aFormParams = {OnDisplayFunction: LiveAdMaker.Layouts.showAdditionalFields}
     var aAdditionalUrlParams = '&aRowId='+aParams.Item.Id+'&aCurrentPageNumber='+aParams.Item.PageNumber;
     FormUI.Request.getForm(LiveAdMaker.Layouts.Layout.ItemPath,'LayoutAreaDetails', aParams.ContentElement,aAdditionalUrlParams,aFormParams);
   }
   return true;
  },
  draw: function(aParams) {
  }
}
LiveAdMaker.Layouts.Layout = {
  AreaList: null,
  CurrentItem: null,
  ContentElement: null,
  init:function(aParams){
    if (!LiveAdMaker.Layouts.Layout.CurrentItem||LiveAdMaker.Layouts.Layout.CurrentItem.Id!=aParams.Item.Id){
        LiveAdMaker.Layouts.Layout.ContentElement=aParams.ContentElement;
        LiveAdMaker.Layouts.Layout.CurrentItem=aParams.Item;
    }
    LiveAdMaker.Layouts.Layout.ContentElement=aParams.ContentElement;
    LiveAdMaker.Layouts.Layout.SubSection = {};
    LiveAdMaker.Layouts.Layout.ListParams = aParams;
    LiveAdMaker.Layouts.Layout.getAreas("1");
    return true;
  },
  createNewItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Layouts.Layout.CurrentItem.ItemPath, "CreateNewArea", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Layouts", Function:LiveAdMaker.drawSection,Params:aParams},
      PostValues:{
        aObjectTypeAlias:"Layout",
        aAlias:"Layouts".makeUnique(),
        aName:"Layouts "+LiveAdMaker.SelectedSection.Items.length,
        aCategory: "Imagery",
        aDislayName: "Imagery",
        aId: "Area".makeUnique(),
        aPageNumber: LiveAdMaker.Layouts.CurrentPage
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "ArchiveArea", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues:{
        aAreaId: aParams.SelectedItem.Id
      },
      Method:'POST'
    });
  },
  duplicateItem: function(aParams) {
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "DuplicateArea", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Layouts", Function: LiveAdMaker.drawSection, Params: aParams},
      PostValues: {
        aAreaId: aParams.SelectedItem.Id,
        aNewAreaId: "Area".makeUnique(),
        aDisplayName: "Copy of "+aParams.SelectedItem.DisplayName
      },
      Method:'POST'
    });
  },
  receiveArchiveItem:function(aResults,aParams){
    DOM.removeClass(LiveAdMaker.Layouts.Layout.SubItemList.ContainerElement,"ActionUI_HasNavigation");
    LiveAdMaker.Layouts.Layout.SubItemList.NavigationElement.style.display = "none";
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Layouts.Layout.CurrentItem.ItemPath, "RequestArea", "aSize=500", false),
      Function: LiveAdMaker.Layouts.generateLayout,
      Params: {ContentElement: $("LayoutImageContainer"), Section: "Layout", SelectedPage: aResults.PageNumber}
    });
    return true;
  },
  receiveNewItem:function(aResults,aParams){
    DOM.removeClass(LiveAdMaker.Layouts.Layout.SubItemList.ContainerElement,"ActionUI_HasNavigation");
    LiveAdMaker.Layouts.Layout.SubItemList.NavigationElement.style.display = "none";
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Layouts.Layout.CurrentItem.ItemPath, "RequestArea", "aSize=500", false),
      Function: LiveAdMaker.Layouts.generateLayout,
      Params: {ContentElement: $('LayoutImageContainer'), Section: "Layout", SelectedPage: aResults.PageNumber}
    });
    return true;
  },
  sortItems: function(aNewItemArray,aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zSortAction = "SortAreas";
    var zAreaArray = [];
    aNewItemArray.forEach(function(aItem){
      if (aItem.Category != undefined){
        zAreaArray.push(aItem.Id);
      }
    });
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, zSortAction),
      Function: function(){return true;},
      Method: "POST",
      PostValues: {aItems: zAreaArray.join(";")}
    });
    setTimeout(function() {
      Ajax.makeRequest({
        URL: URI.pageURL(zSelectedItem.ItemPath, "RequestArea", "aSize=500", false),
        Function: LiveAdMaker.Layouts.generateLayout,
        Params: {ContentElement: $('LayoutImageContainer'), Section: "Layout", SelectedPage: LiveAdMaker.Layouts.CurrentPage}
      });
    }, 700);
    return true;
  },
  UpdateSceneDuration:function(aParams){
    var getPageNumberArray= aParams.Element.Field.split("_");
    LiveAdMaker.Layouts.Layout.getAreas(getPageNumberArray[1]);
    return true;
  },
  showOptions: function (e,aParams){
    var zOptionsContainer = DOM.createElement('div','OptionContainer');
    var zEditSegmentLink = DOM.createElement('div','','OptionLinkContainer');
    zEditSegmentLink.innerHTML = "Edit";
    zOptionsContainer.appendChild(zEditSegmentLink);
    DOM.addEvent(zEditSegmentLink,"onclick",LiveAdMaker.Layouts.Layout.loadCurrentPage,{CurrentPage: aParams.CurrentPage, TotalPages: aParams.TotalPages});
    var zNewLink = DOM.createElement('div','','OptionLinkContainer');
    zNewLink.innerHTML = "New";
    zOptionsContainer.appendChild(zNewLink);
    DOM.addEvent(zNewLink,"onclick",LiveAdMaker.Layouts.Layout.addPage,{TotalPages: aParams.TotalPages});
    var zDuplicateLink = DOM.createElement('div','','OptionLinkContainer');
    zDuplicateLink.innerHTML = "Duplicate";
    zOptionsContainer.appendChild(zDuplicateLink);
    DOM.addEvent(zDuplicateLink,"onclick",LiveAdMaker.Layouts.Layout.duplicatePage,{CurrentPage: aParams.CurrentPage, TotalPages: aParams.TotalPages});
    if (aParams.TotalPages != "1"){
      var zRemoveLink = DOM.createElement('div','','OptionLinkContainer');
      zRemoveLink.innerHTML = "Remove";
      zOptionsContainer.appendChild(zRemoveLink);
      DOM.addEvent(zRemoveLink,"onclick",LiveAdMaker.Layouts.Layout.removePage,{CurrentPage: aParams.CurrentPage, TotalPages: aParams.TotalPages});
    }
    DOM.Dialog.show(zOptionsContainer,e);
    return true;
  },
  loadCurrentPage: function(e,aParams){
    DOM.Dialog.hide();
    LiveAdMaker.Layouts.CurrentPage = aParams.CurrentPage;
    LiveAdMaker.Layouts.Layout.getAreas(aParams.CurrentPage);
  },
  loadSelectedPage: function(e,aParams){
    if (aParams.IncrementPage == "Y"){
      if (parseInt(aParams.CurrentPage) == aParams.TotalPages){
        var zNextPage = aParams.TotalPages;
        var zDoNothing = "Y";
      }else {
        var zNextPage = parseInt(aParams.CurrentPage) + parseInt("1");
        var zDoNothing = "N";
      }
    }else{
      if (aParams.CurrentPage == "1"){
        var zNextPage = aParams.CurrentPage;
        var zDoNothing = "Y";
      }else {
        var zNextPage = parseInt(aParams.CurrentPage) - parseInt("1");
        var zDoNothing = "N";
      }
    }
    LiveAdMaker.Layouts.CurrentPage = zNextPage;
    if (zDoNothing != "Y"){
      LiveAdMaker.Layouts.Layout.getAreas(zNextPage);
    }
  },
  addPage:function (e,aParams){
    DOM.Dialog.hide();
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zNextPageCount = parseInt(aParams.TotalPages) + parseInt("1");
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "SetLayoutPage", null, true),
      Function: LiveAdMaker.Layouts.Layout.AddPageComplete,
      PostValues: {aNextPage: zNextPageCount},
      Method:'POST'
    });
    return true;
  },
  AddPageComplete:function (aParams){
    if (aParams.Status == "Success"){
      LiveAdMaker.Layouts.Layout.getAreas(aParams.NextPage);
    }
    return true;
  },
  duplicatePage:function (e,aParams){
    DOM.Dialog.hide();
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zCurrentPage = aParams.CurrentPage;
    var zNextPageCount = parseInt(aParams.TotalPages) + parseInt("1");
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "DuplicateLayoutPage", null, true),
      Function: LiveAdMaker.Layouts.Layout.duplicatePageComplete,
      PostValues: {aCurrentPage: zCurrentPage,aNextPage: zNextPageCount},
      Method:'POST'
    });
    return true;
  },
  duplicatePageComplete:function(aParams){
    if (aParams.Status == "Success"){
      LiveAdMaker.Layouts.Layout.getAreas(aParams.NextPage);
    }
    return true;
  },
  removePage:function (e,aParams){
    DOM.Dialog.hide();
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    var zCurrentPage = aParams.CurrentPage;
    var zNextPageCount = "1";
    Ajax.makeRequest({
      URL: URI.pageURL(zSelectedItem.ItemPath, "RemoveLayoutPage", null, true),
      Function: LiveAdMaker.Layouts.Layout.removePageComplete,
      PostValues: {aRemovePage: zCurrentPage,aNextPage: zNextPageCount},
      Method:'POST'
    });
    return true;
  },
  removePageComplete:function(aParams){
    if (aParams.Status == "Success"){
      LiveAdMaker.Layouts.Layout.getAreas(aParams.NextPage);
    }
    return true;
  },
  reloadPage:function(aParams){
    var getPageNumberArray= aParams.Element.Field.split("_");
    setTimeout(function() {
      LiveAdMaker.Layouts.Layout.getAreas(getPageNumberArray[1],aParams.Element.CSVRowId);
    }, 700);
    return true;
  },
  getAreas: function(aPageNumber,aCurrentSelection) {
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Layouts.Layout.CurrentItem.ItemPath, "RequestArea", null, false),
      Function: LiveAdMaker.Layouts.Layout.receiveAreas,
      Params: {SelectedPage: aPageNumber, CurrentItem: aCurrentSelection, CurrentParams: LiveAdMaker.Layouts.Layout.ListParams}
    });
    return true;
  },
  receiveAreas: function (aAreas,aParams) {
    if (aAreas || LiveAdMaker.matchCurrentHashValues(aParams.CurrentParams)){
      SelectedPageAreaItems = new Array();
      aAreas.AreaItems.forEach(function(zArea){
        if (zArea.PageNumber == aParams.SelectedPage){
          SelectedPageAreaItems.push(zArea);
        }
        if (zArea.PageNumber == 0){
          SelectedPageAreaItems.push(zArea);
        }
      });
      if (aAreas.IsSequence =="Y"){
        aAreas.PageArray.forEach(function(zPage){
          if (zPage.PageNumber == aParams.SelectedPage){
            SelectedPageAreaItems.push(zPage);
          }
        });
      }
      if(!LiveAdMaker.Layouts.Layout.AreaList) {
        LiveAdMaker.Layouts.Layout.ItemPath = aAreas.ItemPath;
        if (aAreas.IsSequence =="Y"){
          var zPageName="Scene"
          var zTotalDuration= aAreas.TotalDuration;
        }else{
          var zPageName="Page"
        }
        var zInnerBubbleContainer = DOM.createElement('div','InnerBubbleContainer');
        zInnerBubbleContainer.style.height = LiveAdMaker.Layouts.Layout.ContentElement.style.height;
        var zTimeLineContainer= DOM.createElement('div','TimeLineContainer');
        switch (aAreas.BackgroundCount) {
          case "" :
            zTimeLineContainer.style.height = "60px";
            break;
          case "1" :
            zTimeLineContainer.style.height = "85px";
            break;
          case "2" :
            zTimeLineContainer.style.height = "105px";
            break;
          case "3" :
            zTimeLineContainer.style.height = "125px";
            break;
          default:
        }
        var zAddPageContainer= DOM.createElement('div','AddPageContainer');
        if (zTotalDuration){
          var zAddMorePages = DOM.createActionElement('h1', LiveAdMaker.Layouts.Layout.addPage, zPageName+"s ("+(parseInt(zTotalDuration)/1000)+"s)", {TotalPages:aAreas.PageArray.length});
        }else{
          var zAddMorePages = DOM.createActionElement('h1', LiveAdMaker.Layouts.Layout.addPage, zPageName+"s", {TotalPages:aAreas.PageArray.length});
        }
        zAddPageContainer.appendChild(zAddMorePages);
        var zCurrentAdStylePageContainer = DOM.createElement('div','CurrentAdStylePageContainer');
        var zCurrentAvailableWidth = "498";
        var zTotalSceneDuration = parseInt(aAreas.TotalDuration)/1000;
        var zMultiplierDuration = parseInt(zCurrentAvailableWidth)/parseInt(zTotalSceneDuration);
        aAreas.PageArray.forEach(function(aPage){
          var zPageWidth=100;
          var zPageContainer = DOM.createElement("div","PageSelection_"+aPage.PageNumber,"PageSelection");
          var zPageDisplayContainer = DOM.createElement("div","","PageNameDisplay");
          if (aAreas.IsSequence =="Y"){
            var zSceneDuration = (parseInt(aPage.Duration)/1000);
            zPageDisplayContainer.innerHTML= zSceneDuration+'s';
          }else{
            zPageDisplayContainer.innerHTML=aPage.DisplayName;
          }
          zPageContainer.appendChild(zPageDisplayContainer);
          zCurrentAdStylePageContainer.appendChild(zPageContainer);
          DOM.addEvent(zPageContainer,"onclick",LiveAdMaker.Layouts.Layout.showOptions,{CurrentPage: aPage.PageNumber, TotalPages: aAreas.PageArray.length, IncrementPage: "Y"});
          if (aAreas.IsSequence =="Y"){
            var zNewSceneWidth = parseInt(zSceneDuration) * parseInt(zMultiplierDuration);
            zPageContainer.style.width = zNewSceneWidth+"px";
          }else{
            zPageContainer.style.width = zPageWidth+"px";
          }
        });
        var zBGAreaContainer = DOM.createElement('div','BackgroundAreaPageContainer');
        aAreas.AreaArray.forEach(function(aArea){
         if (aArea.PageNumber == "0"){
           var zBGArea= DOM.createElement('div','',"BackgroundContainers");
           var zEnableDisableBG = DOM.createActionElement('div', "", aArea.DisplayName,"");
           DOM.addClass(zEnableDisableBG, 'BGNameContainer');
           var zBGDisplayContainer = DOM.createElement("div","BGArea_"+aArea.Id,"BGSelection");
           zBGArea.appendChild(zEnableDisableBG);
           zBGArea.appendChild(zBGDisplayContainer);
           zBGAreaContainer.appendChild(zBGArea);
         }
        });
        zTimeLineContainer.appendChild(zAddPageContainer);
        zTimeLineContainer.appendChild(zCurrentAdStylePageContainer);
        zTimeLineContainer.appendChild(zBGAreaContainer);
        zInnerBubbleContainer.appendChild(zTimeLineContainer);
        var zAdStyleWireFrameContainer = DOM.createElement('div','AdStyleWireFrameContainer');
        var zPageSelectionContainer = DOM.createElement('div','PageSelectionContainer');
        var zPageSelection = DOM.createElement('div','PageSelection');
        var zPageDisplayName;
        aAreas.PageArray.forEach(function(aPage){
          if (aPage.PageNumber == aParams.SelectedPage){
            zPageDisplayName = aPage.DisplayName;
          }
        });
        zPageSelection.innerHTML = '<div id="PageSelectionLeftArrow"></div><div id="PageName" style="float:left;">'+zPageDisplayName+'</div><div id="PageSelectionRightArrow"></div>';
        zPageSelectionContainer.appendChild(zPageSelection);
        zAdStyleWireFrameContainer.appendChild(zPageSelectionContainer);
        var zLayoutImageContainer = DOM.createElement('div','LayoutImageContainer');
        zLayoutImageContainer.style.marginTop = '50px';
        zLayoutImageContainer.style.marginLeft = '10px';
        zAdStyleWireFrameContainer.appendChild(zLayoutImageContainer);
        zInnerBubbleContainer.appendChild(zAdStyleWireFrameContainer);
        var zInnerBubbleFormDiv = DOM.createElement('div','InnerBubbleFormDiv');
        zInnerBubbleFormDiv.style.marginTop = '10px';
        zInnerBubbleFormDiv.style.marginLeft = '325px';
        var zFormHeight = parseInt(LiveAdMaker.Layouts.Layout.ContentElement.style.height)- parseInt(zTimeLineContainer.style.height)- parseInt("50");
        zInnerBubbleFormDiv.style.height = zFormHeight+"px";
        zInnerBubbleContainer.appendChild(zInnerBubbleFormDiv);
        var SelectedSubItem = LiveAdMaker.getItemById(SelectedPageAreaItems,LiveAdMaker.Layouts.Layout.ListParams.SubItem);
        if (aParams.CurrentItem == undefined){
          if (SelectedSubItem == null){
            var SelectedSubItem = SelectedPageAreaItems[0];
          }
        }else{
          var SelectedSubItem = LiveAdMaker.getItemById(SelectedPageAreaItems,aParams.CurrentItem);
        }
        zDrawParams = {
          Section: LiveAdMaker.Layouts.Layout.ListParams.SectionId,
          SubSection: "Layout",
          ItemId: LiveAdMaker.Layouts.Layout.ListParams.ItemId,
          ListType: "ActionUI",
          Fields: aAreas.Fields,
          View: "subitem",
          ParentElement: zInnerBubbleFormDiv,
          Action: LiveAdMaker.Layouts.Layout.ListParams.ActionId,
          Id: "AreaList",
          ItemArray: SelectedPageAreaItems,
          Actions: LiveAdMaker.Layouts.AreaActions,
          Sortable: true,
          ShowNavigation: true,
          OnSortCompleteFunction: LiveAdMaker.Layouts.Layout.sortItems
        };
        Ajax.makeRequest({
          URL: URI.pageURL(LiveAdMaker.Layouts.Layout.ItemPath, "RequestArea", "", false),
          Function: LiveAdMaker.Layouts.generateLayout,
          Params: {ContentElement: zLayoutImageContainer, Section: "Layout", SelectedPage: aParams.SelectedPage}
        });
        DOM.replaceContent(LiveAdMaker.Layouts.Layout.ContentElement,zInnerBubbleContainer);
        var zTotalPages = aAreas.PageArray.length;
        var zCurrentPages = aParams.SelectedPage;
        DOM.addEvent($('PageSelectionRightArrow'),"onclick",LiveAdMaker.Layouts.Layout.loadSelectedPage,{CurrentPage: zCurrentPages, TotalPages: zTotalPages, IncrementPage: "Y"});
        DOM.addEvent($('PageSelectionLeftArrow'),"onclick",LiveAdMaker.Layouts.Layout.loadSelectedPage,{CurrentPage: zCurrentPages, TotalPages: zTotalPages, IncrementPage: "N"});
        var zSubItemList = new List(zDrawParams);
        zSubItemList.draw(zDrawParams);
        LiveAdMaker.Layouts.Layout.SubItemList = zSubItemList;
        zSubItemList.selectItem(SelectedSubItem.Id, true);
        zSubItemList.selectAction({Action:zSubItemList.Actions[0].Id});
        var zActionParams = {
          Item: SelectedSubItem,
          ItemId: SelectedSubItem.Id,
          Action: zSubItemList.Actions[0],
          ActionId: zSubItemList.Actions[0].Id,
          Section: LiveAdMaker.Layouts.Layout.ListParams.Section,
          SectionId: LiveAdMaker.Layouts.Layout.ListParams.SectionId,
          List: zSubItemList,
          ContentElement: zSubItemList.ContentElement
        };
        DOM.removeClass(zSubItemList.ContainerElement,"ActionUI_HasNavigation");
        zSubItemList.NavigationElement.style.display = "block";
        zSubItemList.NavigationElement.style.marginTop= "0px";
        zInnerBubbleContainer.insertBefore(zSubItemList.NavigationElement,zTimeLineContainer);
        LiveAdMaker.resizeInterface(null);
        if(zSubItemList.Actions[0].DisplayFunction) {
          zSubItemList.Actions[0].DisplayFunction(zActionParams);
        }
        else {
          FormUI.Request.GetForm(zActionParams.Item.ItemPath, 'Form'+zSubItemList.Actions[0].Id, zActionParams.ContentElement);
        }
          DOM.getElementsWithClassName("div","selectedArea").forEach(function (zPageSelection){
          DOM.removeClass(zPageSelection, "selectedArea");
        });
        var zSelectedPageObject2 = $("PageSelection_"+aParams.SelectedPage);
        DOM.addClass(zSelectedPageObject2, "selectedArea");
      }
      return true;
    }
  }
}
LiveAdMaker.Layouts.Groups = {
  init: function(aParams) {
    FormUI.Request.getForm(aParams.Item.ItemPath, 'Groups', aParams.ContentElement);
    return true;
  }
}
Util.debug.Enabled = true;
LiveAdMaker.Layouts.Resizing = {
  ResizingRulesArray:    [],
  CurrentItem:           null,
  ContentElement:        null,
  FormContainer:         null,
  WireframeContainer:    null,
  DropdownOrderArray:    ["Area","Variable","Relationship","Area","Variable","Function"],
  VariableArray:         ["","Left","Top","Bottom","Right","Width","Height","ContentHeight","AspectRatio","ConstrainProportions","FitToContents","SizeToContents","LeftMin","LeftMax","TopMin","TopMax","BottomMin","BottomMax","WidthMin","WidthMax","HeightMin","HeightMax","HeightIncrease","HeightIncreaseFactor","WidthIncrease","WidthIncreaseFactor"],
  RelationshipArray:     ["","SetTo","LinkTo","SetAndLinkTo"],
  RelationshipArrayV2:   [{"DisplayName": "","ItemPath": ""},{"DisplayName": "= SetTo","ItemPath": "="},{"DisplayName": "~ LinkTo","ItemPath": "~"},{"DisplayName": "^ RelativeTo","ItemPath": "^"}],
  RelationshipArrayV3:   ["","=","~","=~"],
  FunctionArray:         ["","+","-","/","x","Min","Max"],
  AreaArray:             [],
  DropdownArray:         [],
  RemoveInit:            0,
  ToggleArray:           ["Select Boxes","Free Form Text"],
  LayoutImageContainer:  null,
  init: function (aParams) {
    LiveAdMaker.Layouts.Resizing.ItemPath = aParams.Item.ItemPath;
    LiveAdMaker.Layouts.Resizing.CurrentItem = null;
    LiveAdMaker.Layouts.Resizing.ContentElement = null;
    LiveAdMaker.Layouts.Resizing.FormContainer = null;
    LiveAdMaker.Layouts.Resizing.WireframeContainer = null;
    LiveAdMaker.Layouts.Resizing.AreaArray = [];
    LiveAdMaker.Layouts.Resizing.DropdownArray = [];
    LiveAdMaker.Layouts.Resizing.ResizingRulesArray = [];
    LiveAdMaker.Layouts.Resizing.LayoutImageContainer = null;
    LiveAdMaker.Layouts.Resizing.requestAreas(aParams);
    return true;
  },
  requestAreas: function (aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "RequestArea", null, false),
      Function: LiveAdMaker.Layouts.Resizing.receiveAreasV2,
      Params: aParams
    });
    return true;
  },
  receiveAreasAndRules: function (aData, aParams) {
    LiveAdMaker.Layouts.Resizing.receiveAreas(aData[0], aParams);
    LiveAdMaker.Layouts.Resizing.drawForm(aData[1], aParams);
    return true;
  },
  receiveAreasV2: function(aData,aParams) {
    aParams.SelectedPage ="1";
    LiveAdMaker.Layouts.Resizing.setInnerBubble(aData,aParams);
    LiveAdMaker.Layouts.generateLayout(aData, {ContentElement: LiveAdMaker.Layouts.Resizing.LayoutImageContainer,Section: "Resizing",SelectedPage: '1'});
    LiveAdMaker.Layouts.Resizing.AreaArray = aData.AreaArray;
    FormUI.FormItemPath = aParams.Item.ItemPath;
    var AreaDisplayNameArray = [];
    AreaDisplayNameArray[0] = '';
    AreaDisplayNameArray[1] = 'Value';
    AreaDisplayNameArray[2] = 'Page';
    for (var i = 3; i < aData.AreaArray.length + 3; i++) {
      AreaDisplayNameArray[i] = aData.AreaArray[i-3].DisplayName;
    }
    LiveAdMaker.Layouts.Resizing.DropdownArray = [ {Title: "Area", ValueArray: AreaDisplayNameArray},
                                                   {Title: "Variable", ValueArray: LiveAdMaker.Layouts.Resizing.VariableArray},
                                                   {Title: "Relationship", ValueArray: LiveAdMaker.Layouts.Resizing.RelationshipArray},
                                                   {Title: "Area", ValueArray: AreaDisplayNameArray},
                                                   {Title: "Variable", ValueArray: LiveAdMaker.Layouts.Resizing.VariableArray},
                                                   {Title: "Function", ValueArray: LiveAdMaker.Layouts.Resizing.FunctionArray}
                                                 ];
    var zToggleArray = LiveAdMaker.Layouts.Resizing.ToggleArray;
    var zToggleContainer = DOM.createElement('div','ToggleContainer');
    zToggleContainer.innerHTML = "View: ";
    zToggleContainer.style.padding = '10px';
    var zMySelect = DOM.createElement('select','myselection');
    DOM.addEvent(zMySelect,'onchange',LiveAdMaker.Layouts.Resizing.ToggleOnChange,{Params: aParams, Select: zMySelect});
    for (i = 0; i < zToggleArray.length; i++){
      zMySelect.options[i] = new Option (zToggleArray[i], i);
    }
    var SelectionID = (aData.SelectionID) ? aData.SelectionID : 1 ;
    zMySelect.options[SelectionID].selected = true;
    zToggleContainer.appendChild(zMySelect);
    LiveAdMaker.Layouts.Resizing.FormContainer.appendChild(zToggleContainer);
    LiveAdMaker.Layouts.Resizing.ToggleOnChange(null,{Params: aParams, Select: zMySelect});
    return true;
  },
  ToggleOnChange: function(e, aParams){
    var zElementValue = aParams.Select.value;
    if (zElementValue == 0){
      if ( $('ResizingTextArea') ){
        $('ResizingTextArea').style.display = 'none';
        $('ResizingTextArea').style.visibility = 'hidden';
      }
       if ($('TextAreaContainer')){
         LiveAdMaker.Layouts.Resizing.FormContainer.removeChild($('TextAreaContainer'));
       }
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.Params.Item.ItemPath, "GetResizingRules", "&aSelectionValue="+zElementValue, false),
        Function: LiveAdMaker.Layouts.Resizing.drawForm,
        Params: aParams.Params
      });
    } else if (zElementValue == 1) {
       if ($('selectBoxContainer')){
         LiveAdMaker.Layouts.Resizing.FormContainer.removeChild($('selectBoxContainer'));
       }
       LiveAdMaker.Layouts.Resizing.ResizingRulesArray = [];
       LiveAdMaker.Layouts.Resizing.getResizingRules(aParams.Params,zElementValue);
    }
    return true;
  },
  getResizingRules: function(aParams,zElementValue){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetTextAreaResizingRules", "&aSelectionValue="+zElementValue, false),
      Function: LiveAdMaker.Layouts.Resizing.drawFreeFormText,
      Params: aParams
    });
  },
  drawFreeFormText: function(aResizingData, aParams){
    if (aResizingData){
      var zSelectedOption = aResizingData.SelectID ||'0';
      if ($('myselection')){
        $('myselection').options[zSelectedOption].selected = true;
      }
      var SelectID = (aResizingData.TextArea[0])?aResizingData.TextArea[0].ID : 1;
      var value = '';
      for (var i = 0; i < aResizingData.TextArea.length; i++) {
        if (aResizingData.TextArea[i].Script)
          value += aResizingData.TextArea[i].Script +'\r';
      }
      if ( !($('TextAreaContainer')) ) {
        var zTextAreaContainer = DOM.createElement('div', 'TextAreaContainer');
        LiveAdMaker.Layouts.Resizing.FormContainer.appendChild(zTextAreaContainer);
      }
      if ( !($('ResizingTextArea')) ){
        var zPosition = { Top: "8", Left: "10", Height: "40", Width: "90"}
        var zResizeUI_Form = new FormUI.Form(aParams.Item.ItemPath, "ResizeUI", zTextAreaContainer);
        var zSelectElementProperties = { SeqNo: 1,
                                         ReadPropertyPath: '.Text.ResizingRulesV2Default_CSV.Detail',
                                         WritePropertyPath: '.Text.ResizingRulesV2Default_CSV.Detail',
                                         FieldType: 'CSVVALUE',
                                         DisplayFormat: 'LongText',
                                         CSVColumnId: 'ID',
                                         CSVValue: 'ROW',
                                         CSVRowId: SelectID,
                                         CSVEncoding: 'Base64',
                                         SaveFormType: 'ResizingTextArea',
                                         Value: value,
                                         OnChangeFunction: '',
                                         Form: zResizeUI_Form
                                       };
        var zSelect = new FormUI.Element('Text', 'ResizingTextArea' , zPosition, '', zSelectElementProperties);
        var zSelectElement = FormUI.createElement(zSelect, zTextAreaContainer, zResizeUI_Form.Id, false);
      } else {
        $('ResizingTextArea').innerHTML = value;
        $('ResizingTextArea').style.display = 'block';
        $('ResizingTextArea').style.visibility = 'visible';
      }
    }
    zSelectElement.blur();
    return true;
  },
  receiveAreas:function (aData, aParams) {
    LiveAdMaker.Layouts.Resizing.drawWireframe(aData, LiveAdMaker.Layouts.Resizing.LayoutImageContainer);
    LiveAdMaker.Layouts.Resizing.AreaArray = aData.AreaArray;
    var AreaDisplayNameArray = [];
    AreaDisplayNameArray[0] = '';
    for (var i = 1; i < aData.AreaArray.length + 1; i++) {
      AreaDisplayNameArray[i] = aData.AreaArray[i-1].DisplayName;
    }
    LiveAdMaker.Layouts.Resizing.DropdownArray = [ {Title: "Area", ValueArray: AreaDisplayNameArray},
                                                   {Title: "Variable", ValueArray: LiveAdMaker.Layouts.Resizing.VariableArray},
                                                   {Title: "Relationship", ValueArray: LiveAdMaker.Layouts.Resizing.RelationshipArrayV3},
                                                   {Title: "Area", ValueArray: AreaDisplayNameArray},
                                                   {Title: "Variable", ValueArray: LiveAdMaker.Layouts.Resizing.VariableArray},
                                                   {Title: "Function", ValueArray: LiveAdMaker.Layouts.Resizing.FunctionArray}
                                                 ];
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetResizingRules", null, false),
      Function: LiveAdMaker.Layouts.Resizing.drawForm,
      Params: aParams
    });
    return true;
  },
  getDropdownType: function (aItem){
   var zAreaIndex = LiveAdMaker.Layouts.Resizing.DropdownArray[0].ValueArray.indexOf(aItem);
    if (zAreaIndex >= 0) {
      return {'Type': 'Area', 'Index': '0'};
    } else {
      var zVariableIndex = LiveAdMaker.Layouts.Resizing.DropdownArray[1].ValueArray.indexOf(aItem);
      if (zVariableIndex >= 0){
        return {'Type': 'Variable', 'Index': '1'};
      } else {
        var zRelationshipIndex = LiveAdMaker.Layouts.Resizing.RelationshipArrayV3.indexOf(aItem);
        if (zRelationshipIndex >= 0){
          return {'Type': 'Relationship', 'Index': '2','Value': LiveAdMaker.Layouts.Resizing.RelationshipArrayV3[zRelationshipIndex]};
        } else {
          var zFunctionIndex = LiveAdMaker.Layouts.Resizing.FunctionArray.indexOf(aItem);
          if (zFunctionIndex >= 0){
            return {'Type': 'Function','Index': '5'};
          } else {
            return {'Type': 'Area','Index': '0'};
          }
        }
      }
    }
    return true;
  },
  getNextElementType: function(aItem,aLocation){
    var zType, zIndex;
    switch (aItem){
      case 'Area':
            zType = 'Variable';
            zIndex = '1';
            break;
      case 'Variable':
            if (aLocation > 1){
              zType = 'Function';
              zIndex = '5';
            } else {
              zType = 'Relationship';
              zIndex = '2';
            }
            break;
      case 'Relationship':
            zType = 'Area';
            zIndex = '0';
            break;
      case 'Function':
            zType = 'Area';
            zIndex = '0';
            break;
      case 'Value':
            zType = 'Function';
            zIndex = '5';
            break;
    }
    return {'Type': zType, 'Index': zIndex};
  },
  drawForm: function (aResizingData, aParams) {
    if (!$('selectBoxContainer')){
      var selectBoxContainer = DOM.createElement('div','selectBoxContainer');
      LiveAdMaker.Layouts.Resizing.FormContainer.appendChild(selectBoxContainer);
    }
    for (var i = 0; i < aResizingData.length; i++) {
      var zResizingRule = new LiveAdMaker.Layouts.Resizing.ResizingRule(aResizingData[i], i, false);
      zResizingRule.drawRule($('selectBoxContainer'));
    }
    LiveAdMaker.Layouts.Resizing.appendEmptyRule();
    return true;
  },
  ResizingRule: function (aElementValueArray, aRuleId, aEnabled) {
    this.RuleId       = aRuleId;
    this.Elements     = [];
    if (aEnabled)
      this.Enabled    = true;
    else this.Enabled = false;
    this.Enabled      = aEnabled;
    this.divElement   = null;
    for (var i = 0; i < aElementValueArray.length; i++) {
      this.Elements[i] = new LiveAdMaker.Layouts.Resizing.ResizingRuleElement(aElementValueArray[i],this.RuleId,i,null,this.Enabled);
    }
    LiveAdMaker.Layouts.Resizing.ResizingRulesArray[aRuleId] = this;
    return true;
  },
  ResizingRuleElement: function (aElementValue, aRuleNumber, aIndex, aElementType, aEnabled) {
    var zIndexType     = LiveAdMaker.Layouts.Resizing.getDropdownType(aElementValue);
    this.Value         = (zIndexType.Value)? zIndexType.Value : aElementValue;
    this.Display       = aElementValue;
    this.Type          = (aElementType)?aElementType.Type : zIndexType.Type ;
    this.RuleNumber    = aRuleNumber;
    this.Index         = (aElementType)? aElementType.Index : zIndexType.Index;
    this.Id            = Math.floor(Math.random()*100001);
    this.ElementId        = aIndex;
    this.selectElement = {};
    this.Enabled       = aEnabled;
    return true;
  },
  inputOnBlur: function(e, aParams){
    var zResizingArray = LiveAdMaker.Layouts.Resizing.ResizingRulesArray;
    var zRuleObject = zResizingArray[aParams.Element.RuleNumber];
    var zElementObject = zRuleObject.Elements[aParams.Element.ItemId];
    zElementObject.Value = aParams.Element.Value;
    var zString='';
    var zHasElement = false;
    for (var i = 0; i < zResizingArray.length; i++){
      if (i > 0 && zResizingArray[i].Elements.length > 1){
        zString += '\n';
      }
      for (var j = 0; j < zResizingArray[i].Elements.length; j++){
        zHasElement = true;
        var zElement = zResizingArray[i].Elements[j];
        if (zElement.Type == 'Variable'){
          zString += '.' + zElement.Value;
        }else if (zElement.Type == 'Area' && zElement.Value == 'Value'){
          zString += ' ' + $('ValueInput_' + zElement.RuleNumber + '_' + zElement.Index + '_' +zElement.Id).value; //+'px';
          zElementObject.Value = $('ValueInput_' + zElement.RuleNumber + '_' + zElement.Index + '_' +zElement.Id).value; //+'px';
        }else {
          if (zElement.Value != '')
            zString += ' ' + zElement.Value;
        }
      } 
      zHasElement = false;
    } 
    var zInput  = $('ValueInput_' + zElementObject.RuleNumber + '_' + zElementObject.Index + '_' +zElementObject.Id);
    zInput.style.display = 'none';
    zElementObject.ResizingString = zString;
    aParams.Element.ResizingString = zString;
    aParams.Element.InputSave = 'Y';
    FormUI.SubmitElementArray = new Array();
    FormUI.SubmitElementArray.set(aParams.Element,aParams.Element.SeqNo);
    FormUI.Save.submitFormInput(null, aParams);
    zElementObject.toggleElement(false);
    return true;
  },
  dropdownOnBlur: function(aParams) {
    var zResizingArray = LiveAdMaker.Layouts.Resizing.ResizingRulesArray;
    var zRuleObject = zResizingArray[aParams.Element.RuleNumber];
    var zElementObject = zRuleObject.Elements[aParams.Element.ItemId];
    if (zElementObject.Type == "Area" && aParams.Element.Value == "Value"){
    }else{
      zElementObject.Value = aParams.Element.Value;
      var zString='';
      var zHasElement = false;
      for (var i = 0; i < zResizingArray.length; i++){
        if (i > 0 && zResizingArray[i].Elements.length > 1){
          zString += '\n';
        }
        for (var j = 0; j < zResizingArray[i].Elements.length; j++){
          zHasElement = true;
          var zElement = zResizingArray[i].Elements[j];
          if (zElement.Type == 'Variable'){
            zString += '.' + zElement.Value;
          }else {
            if (zElement.Value != '')
              zString += ' ' + zElement.Value;
          }
        } 
        zHasElement = false;
      } 
      zElementObject.ResizingString = zString;
      aParams.Element.ResizingString = zString;
      FormUI.SubmitElementArray = new Array();
      FormUI.SubmitElementArray.set(aParams.Element,aParams.Element.SeqNo);
      FormUI.Save.submitFormInput(null, aParams);
    }
    return true;
  },
  dropdownOnChange: function (aParams) {
    if (LiveAdMaker.Layouts.Resizing.RemoveInit == 1){
      Ajax.makeRequest({
        URL: URI.pageURL(LiveAdMaker.Layouts.Resizing.ItemPath, "GetResizingRules", "&aSelectionValue=0", false),
        Function: LiveAdMaker.Layouts.Resizing.drawForm,
        Params: null
      });
     LiveAdMaker.Layouts.Resizing.RemoveInit = 0;
    } else {
      var zRuleObject = LiveAdMaker.Layouts.Resizing.ResizingRulesArray[aParams.Element.RuleNumber];
      var zElementObject = zRuleObject.Elements[aParams.Element.ItemId];
      if (zElementObject.Id != aParams.Element.UId){
         aParams.Element.ItemId = aParams.Element.ItemId+1;
         zElementObject = zRuleObject.Elements[aParams.Element.ItemId];
      }
      if (zElementObject.Type == "Area" && aParams.Element.Value == "Value"){
        var zSelect = $('SelectContainer_' + zElementObject.RuleNumber + '_' + zElementObject.Index + '_' +zElementObject.Id);
        var zInput  = $('ValueInput_' + zElementObject.RuleNumber + '_' + zElementObject.Index + '_' +zElementObject.Id);
        zSelect.style.display = 'none';
        if (aParams.Element.InputSave == 'Y')
          zInput.style.display = 'none';
        else
          zInput.style.display = 'inline';
        var zNewElementType = LiveAdMaker.Layouts.Resizing.getNextElementType("Value",zElementObject.ElementId);
        if (zElementObject.Value && zElementObject.ElementId == zRuleObject.Elements.length - 1) {
          var zNewElement = new LiveAdMaker.Layouts.Resizing.ResizingRuleElement('',zRuleObject.RuleId,zRuleObject.Elements.length,zNewElementType,true);
          zRuleObject.Elements.push(zNewElement);
          zNewElement.drawElement(zRuleObject.divElement.childNodes[0].childNodes[2]);
        }
      } else {
        zElementObject.Value = aParams.Element.Value;
        var zNewElementType = LiveAdMaker.Layouts.Resizing.getNextElementType(zElementObject.Type,zElementObject.ElementId);
        if (zElementObject.Type == "Area" && zElementObject.Value) {
          var zInput  = $('ValueInput_' + zElementObject.RuleNumber + '_' + zElementObject.Index + '_' +zElementObject.Id);
          if (zInput.value != ''){
            zInput.value = '';
            zInput.style.display = 'none';
            var zElementIndex = zElementObject.ElementId+1;
            var zNewElement = new LiveAdMaker.Layouts.Resizing.ResizingRuleElement('',zRuleObject.RuleId,zElementIndex,zNewElementType,true);
            zRuleObject.Elements.splice(zElementIndex,0,zNewElement);
            zNewElement.drawElement(zRuleObject.divElement.childNodes[0].childNodes[2],zRuleObject.Elements[zElementIndex+1]);
            zRuleObject.Elements[zElementIndex+1].ElementId = zElementIndex+1;
            aParams.Element.ItemId = zRuleObject.Elements[zElementIndex+1].ElementId;
          } else {
            if (zElementObject.Value && zElementObject.ElementId == zRuleObject.Elements.length - 1) {
              var zNewElement = new LiveAdMaker.Layouts.Resizing.ResizingRuleElement('',zRuleObject.RuleId,zRuleObject.Elements.length,zNewElementType,true);
              zRuleObject.Elements.push(zNewElement);
              zNewElement.drawElement(zRuleObject.divElement.childNodes[0].childNodes[2]);
            }
          }
        } else {
          if (zElementObject.Value && zElementObject.ElementId == zRuleObject.Elements.length - 1) {
           var zNewElement = new LiveAdMaker.Layouts.Resizing.ResizingRuleElement('',zRuleObject.RuleId,zRuleObject.Elements.length,zNewElementType,true);
           zRuleObject.Elements.push(zNewElement);
           zNewElement.drawElement(zRuleObject.divElement.childNodes[0].childNodes[2]);
          }
        }
      }
      if (zElementObject.Type == "Area" && aParams.Element.Value == "Value"){
      }else{
        zElementObject.toggleElement(false);
      }
    }
    return true;
  },
  setInnerBubble: function (aAreas,aParams) {
    if (!LiveAdMaker.Layouts.Resizing.CurrentItem||LiveAdMaker.Layouts.Resizing.CurrentItem.Id!=aParams.Item.Id){
      LiveAdMaker.Layouts.Resizing.ContentElement = aParams.ContentElement;
      LiveAdMaker.Layouts.Resizing.CurrentItem = aParams.Item;
    }
    LiveAdMaker.Layouts.Resizing.ContentElement = aParams.ContentElement;
    LiveAdMaker.Layouts.Resizing.SubSection = {};
    LiveAdMaker.Layouts.Resizing.ListParams = aParams;
    var zInnerBubbleContainer = DOM.createElement('div','InnerBubbleContainer');
    DOM.addClass(zInnerBubbleContainer, 'ActionUI_Container');
    zInnerBubbleContainer.style.height = LiveAdMaker.Layouts.Resizing.ContentElement.style.height;
    zInnerBubbleContainer.style.overflowY= 'auto';
    var zPageSelectionContainer = DOM.createElement('div','ResizingPageSelectionContainer');
    var zPageDisplayName = "";
    aAreas.PageArray.forEach(function(aPage){
      if (aPage.PageNumber == aParams.SelectedPage){
        zPageDisplayName = aPage.DisplayName;
      }
    });
    var zPageSelection = DOM.createElement('div','PageSelection');
    zPageSelection.innerHTML = '<span id="PageSelectionLeftArrow"></span><span id="PageName" style="float:left;" >' +zPageDisplayName+ '</span><span id="PageSelectionRightArrow"></span>';
    zPageSelectionContainer.appendChild(zPageSelection);
    zInnerBubbleContainer.appendChild(zPageSelectionContainer);
    var zLayoutImageContainer = DOM.createElement('div','LayoutImageContainer');
    zLayoutImageContainer.style.marginTop = '50px';
    zLayoutImageContainer.style.marginLeft = '10px';
    zLayoutImageContainer.style.width = '315px';
    zLayoutImageContainer.style.height = '400px';
    zLayoutImageContainer.style.paddingLeft = '5px';
    zInnerBubbleContainer.appendChild(zLayoutImageContainer);
    var zInnerBubbleFormDiv = DOM.createElement('div','InnerBubbleFormDiv');
    zInnerBubbleFormDiv.style.marginLeft = '310px';
    zInnerBubbleFormDiv.style.height = LiveAdMaker.Layouts.Resizing.ContentElement.style.height;
    zInnerBubbleContainer.appendChild(zInnerBubbleFormDiv);
    var zDrawParams = {
      Section: LiveAdMaker.Layouts.Resizing.ListParams.SectionId,
      SubSection: "ResizingBubble",
      ItemId: LiveAdMaker.Layouts.Resizing.ListParams.ItemId,
      ListType: "ActionUI",
      Fields: aParams.Fields,
      View: "subitem",
      ParentElement: zInnerBubbleFormDiv,
      Action: LiveAdMaker.Layouts.Resizing.ListParams.ActionId,
      Id: "ResizingBubble",
      ItemArray: [],
      Actions: [],
      Sortable: false,
      OnSortCompleteFunction: LiveAdMaker.sortItems,
      ShowNavigation: false
    };
    LiveAdMaker.Layouts.Resizing.LayoutImageContainer = zLayoutImageContainer;
    DOM.replaceContent(LiveAdMaker.Layouts.Resizing.ContentElement,zInnerBubbleContainer);
    var zSubItemList = new List(zDrawParams);
    zSubItemList.draw(zDrawParams);
    LiveAdMaker.resizeInterface(null);
    zSubItemList.ContentElement.style.backgroundColor = '#F3F3F5';
    LiveAdMaker.Layouts.Resizing.FormContainer = zSubItemList.ContentElement;
    return true;
  },
  DeleteRule: function(e, aRuleId){
    var zRulesArray = LiveAdMaker.Layouts.Resizing.ResizingRulesArray;
    var zElement =  zRulesArray[0].Elements[0];
    LiveAdMaker.Layouts.Resizing.ResizingRulesArray.splice(aRuleId,1);
    $('selectBoxContainer').removeChild($('ResizingRuleContainer_' +aRuleId));
    var zSelect = $('inp_ResizingDropdown_' +  zElement.RuleNumber + '_' +  zElement.Index + '_' + zElement.Id);
    var zDivSelect = $('ResizingDropdown_' +  zElement.RuleNumber + '_' +  zElement.Index + '_' + zElement.Id);
    LiveAdMaker.Layouts.Resizing.dropdownOnBlur({Element: zElement.FormUISelect});
    LiveAdMaker.Layouts.Resizing.FormContainer.removeChild($('selectBoxContainer'));
    LiveAdMaker.Layouts.Resizing.ResizingRulesArray = [];
    LiveAdMaker.Layouts.Resizing.RemoveInit = 1;
    return true;
  },
  appendEmptyRule: function() {
    var zRulesArray = LiveAdMaker.Layouts.Resizing.ResizingRulesArray;
    var zEmptyRule = false;
    for (var i = 0; i < zRulesArray.length; i++) {
      if (zRulesArray[i].Elements.length < 2)
        zEmptyRule = zRulesArray[i];
    }
    if (!zEmptyRule) {
      var zNewRuleId = LiveAdMaker.Layouts.Resizing.ResizingRulesArray.length;
      var zEmptyRule = new LiveAdMaker.Layouts.Resizing.ResizingRule([''], zNewRuleId, true);
      zEmptyRule.drawRule($('selectBoxContainer'));
    }
    LiveAdMaker.Layouts.Resizing.enableRuleElement(null, {RuleId: zEmptyRule.RuleId, ElementId: '0'});
    return true;
  },
  drawWireframe: function(aData, aContainer) {
    if (aData) {
      var zLayout = {
        Layout: aData,
        AspectRatio: aData.AspectRatio,
        IdField: 'Id',
        MaxWidth: 300,
        MaxHeight: 500,
        MinWidth: 10,
        MinHeight: 10,
        UseBackground: false
      };
      var zImageContainerDiv = DOM.createElement('div');
      LiveAdMaker.Layouts.Wireframe = Layout.createWireframe(zLayout);
      zImageContainerDiv.appendChild(LiveAdMaker.Layouts.Wireframe.Container);
      DOM.replaceContent(aContainer,zImageContainerDiv);
    }
    return true;
  },
  enableRuleElement: function(e, aElement) {
    var zRulesArray = LiveAdMaker.Layouts.Resizing.ResizingRulesArray;
    for (var i = 0; i < zRulesArray.length; i++){
      for (var j = 0; j < zRulesArray[i].Elements.length; j++){
        if (aElement.RuleId == zRulesArray[i].RuleId && aElement.ElementId == zRulesArray[i].Elements[j].ElementId){
          zRulesArray[i].Elements[j].toggleElement(true);
        } else {
          zRulesArray[i].Elements[j].toggleElement(false);
        }
      }
    }
    return true;
  },
  enableRule: function(e, aRuleIndex) {
    var zRulesArray = LiveAdMaker.Layouts.Resizing.ResizingRulesArray;
    for (var i = 0; i < zRulesArray.length; i++) {
      if (aRuleIndex == zRulesArray[i].RuleId)
        zRulesArray[i].toggleRule(true);
      else zRulesArray[i].toggleRule(false);
    }
    return true;
  },
  customSubmitFormInput: function(e, aParams) {
    aParams.Element.Value = aParams.DropdownElement.value;
    aParams.Element.NewValue = aParams.DropdownElement.value;
    FormUI.SubmitElementArray = new Array();
    FormUI.SubmitElementArray.set(aParams.Element,aParams.Element.SeqNo);
    FormUI.Save.submitFormInput(null, aParams);
    return true;
  }
};
LiveAdMaker.Layouts.Resizing.ResizingRule.prototype = {
  drawRule: function (aContainer) {
    var selectBoxContainer = DOM.createElement('div','selectBoxContainer');
    var selectInterfaceContainer = DOM.createElement('div', 'ResizingRuleSelectInterfaceContainer_' + this.RuleId, 'ResizingRuleSelectInterfaceContainer');
    var plusSignContainer = DOM.createElement('div', 'ResizingRulePlusSignContainer_' + this.RuleId, 'ResizingRulePlusSignContainer');
    var closeSignContainer = DOM.createElement('div', 'ResizingRuleCloseSignContainer_' + this.RuleId,'ResizingRuleCloseSignContainer');
    var selectsContainer = DOM.createElement('div', 'ResizingRuleSelectsContainer_' + this.RuleId, 'ResizingRuleSelectsContainer');
    var scriptContainer =  DOM.createElement('div', 'ResizingRuleScriptContainer_' + this.RuleId, 'ResizingRuleScriptContainer');
    var zIntercaceClearer = DOM.createElement('div','InterfaceClearer_' + this.RuleId,'FloatClearer');
    selectInterfaceContainer.appendChild(plusSignContainer);
    selectInterfaceContainer.appendChild(closeSignContainer);
    selectInterfaceContainer.appendChild(selectsContainer);
    selectInterfaceContainer.appendChild(zIntercaceClearer);
    closeSignContainer.innerHTML = 'X';
    DOM.addClass(scriptContainer, 'Clickable');
    DOM.addEvent(plusSignContainer, 'onclick', LiveAdMaker.Layouts.Resizing.appendEmptyRule);
    DOM.addEvent(closeSignContainer, 'onclick', LiveAdMaker.Layouts.Resizing.DeleteRule,this.RuleId);
    var currentRow = DOM.createElement('div', 'ResizingRuleContainer_' + this.RuleId, 'ResizingRuleContainer');
    currentRow.appendChild(selectInterfaceContainer);
    currentRow.appendChild(scriptContainer);
    this.divElement = currentRow;
    currentRow.RuleObject = new Object();
    currentRow.RuleObject = this;
    aContainer.appendChild(currentRow);
    for (var i = 0; i < this.Elements.length; i++) {
      this.Elements[i].drawElement(selectsContainer);
    }
    var zClearer = DOM.createElement('div','RuleClearer_' + this.RuleId,'FloatClearer');
    selectsContainer.appendChild(zClearer);
    return true;
  },
  toggleRule: function(aEnabled) {
    var zSelectsContainer = $('ResizingRuleSelectInterfaceContainer_' + this.RuleId);
    var zScriptContainer = $('ResizingRuleScriptContainer_' + this.RuleId);
    if (zSelectsContainer && zScriptContainer) {
      if (aEnabled) {
        zSelectsContainer.style.display = 'block';
        zScriptContainer.style.display = 'none';
      } else {
        zSelectsContainer.style.display = 'none';
        zScriptContainer.style.display = 'block';
        var zScript = '';
        var zElementsArray = this.Elements;
        for (var i = 0; i < zElementsArray.length; i++) {
          var zElement = zElementsArray[i];
          if (zElement.Type == 'Variable')
            zScript += '.' + zElement.Value;
          else zScript += ' ' + zElement.Value;
        }
        zScriptContainer.innerHTML = zScript;
      }
    }
    return true;
  }
};
LiveAdMaker.Layouts.Resizing.ResizingRuleElement.prototype = {
  drawElement: function (aContainer,aSelectItem) {
    var zSelectPosition = {Left: '0', Top: '0', Height: '3', Width: '25'};
    var theDropdownArray = LiveAdMaker.Layouts.Resizing.DropdownArray;
    var zSelectContainer = DOM.createElement('div', 'SelectContainer_' + this.RuleNumber + '_' + this.Index + '_' +this.Id);
    var selectScriptContainer = DOM.createElement('div', 'SelectScriptContainer_' + this.RuleNumber + '_' + this.Index + '_' +this.Id);
    var zResizeUI_Form = new FormUI.Form(LiveAdMaker.Layouts.Resizing.ItemPath, "ResizeUI" +this.RuleNumber+ '_' + this.Index + '_' +this.Id, zSelectContainer);
    var zSelectElementProperties = { SeqNo: this.RuleNumber + '' + this.Index,
                                     ReadPropertyPath: '.Text.ResizingRulesV2Old_CSV.Detail',
                                     WritePropertyPath: '.Text.ResizingRulesV2Old_CSV.Detail',
                                     FieldType: 'CSVValue',
                                     DisplayFormat: 'Selection',
                                     CSVColumnId: 'ID',
                                     CSVValue: 'ROW',
                                     CSVRowId: '0',
                                     CSVEncoding: 'None',
                                     OnChangeFunction: LiveAdMaker.Layouts.Resizing.dropdownOnChange,
                                     OnBlurFunction: LiveAdMaker.Layouts.Resizing.dropdownOnBlur,
                                     DisplayValue: this.Display,
                                     Value: this.Value,
                                     SaveFormType: 'ResizingForm',
                                     ItemId: this.ElementId,
                                     UId: this.Id,
                                     RuleNumber: this.RuleNumber,
                                     OptionsArray: (this.Type == "Relationship")?LiveAdMaker.Layouts.Resizing.RelationshipArrayV2:[],
                                     Form: zResizeUI_Form,
                                     Options: theDropdownArray[this.Index%6].ValueArray.join(',') };
    var zSelect = new FormUI.Element('Text', 'ResizingDropdown_' + this.RuleNumber + '_' + this.Index + '_' +this.Id, zSelectPosition, '', zSelectElementProperties);
    zSelect.OnChangeFunction = LiveAdMaker.Layouts.Resizing.dropdownOnChange;
    if (this.Type == "Area"){
      var zValueInput = DOM.createElement('input','ValueInput_' + this.RuleNumber + '_' + this.Index + '_' +this.Id);
      zValueInput.setAttribute('type','text');
      zValueInput.setAttribute('value',this.Value);
      zValueInput.style.display = 'none';
      DOM.addClass(zValueInput, 'ResizingElementScript');
    }
    DOM.addEvent(selectScriptContainer, 'onclick', LiveAdMaker.Layouts.Resizing.enableRuleElement, {RuleId: this.RuleNumber, ElementId: this.ElementId});
    DOM.addClass(selectScriptContainer, 'Clickable');
    DOM.addClass(selectScriptContainer, 'ResizingElementScript');
    DOM.addClass(zSelectContainer, 'ResizingSelectContainer');
    var zRuleClearer = $('RuleClearer_' + this.RuleNumber);
    if (aSelectItem){
      var zOldSelect = $('SelectContainer_' + aSelectItem.RuleNumber + '_' + aSelectItem.Index + '_' +aSelectItem.Id);
      aContainer.insertBefore(zSelectContainer, zOldSelect);
      aContainer.insertBefore(selectScriptContainer, zOldSelect);
      if (this.Type == "Area")
        aContainer.insertBefore(zValueInput, zOldSelect);
    } else {
      if (zRuleClearer) {
        aContainer.insertBefore(zSelectContainer, zRuleClearer);
        aContainer.insertBefore(selectScriptContainer, zRuleClearer);
        if (this.Type == "Area")
          aContainer.insertBefore(zValueInput, zRuleClearer);
      } else {
        aContainer.appendChild(zSelectContainer);
        aContainer.appendChild(selectScriptContainer);
        if (this.Type == "Area")
          aContainer.appendChild(zValueInput);
      }
    }
    var zSelectElement = FormUI.createElement(zSelect,"", "ResizeUI" +this.RuleNumber+ '_' + this.Index + '_' +this.Id, false);
    DOM.addClass(zSelectElement, 'ResizingSelectElement');
    DOM.addClass(zSelectContainer.childNodes[0], 'ResizingSelectForm');
    zSelectContainer.ElementObject = new Object();
    zSelectContainer.ElementObject = this;
    var zActualDropdownElement = $('inp_ResizingDropdown_' + this.RuleNumber + '_' + this.Index + '_' +this.Id);
    zActualDropdownElement.value = this.Value;
    zActualDropdownElement.InputObject = zActualDropdownElement;
    this.selectElement = zActualDropdownElement;
    this.FormUISelect = zSelect;
    DOM.addEvent(zActualDropdownElement, 'onchange', LiveAdMaker.Layouts.Resizing.customSubmitFormInput, {Element: zSelect, DropdownElement:zActualDropdownElement});
    DOM.removeEvent(zActualDropdownElement, 'onblur', FormUI.Save.timeoutFormInput);
    if (this.Type == "Area")
      DOM.addEvent(zValueInput, 'onblur', LiveAdMaker.Layouts.Resizing.inputOnBlur, {Element: zSelect, DropdownElement:zActualDropdownElement});
    this.toggleElement(this.Enabled);
    return true;
  },
  toggleElement: function(aEnabled){
    var zSelect = $('SelectContainer_' + this.RuleNumber + '_' + this.Index + '_' +this.Id);
    var zScriptContainer = $('SelectScriptContainer_' + this.RuleNumber + '_' + this.Index + '_' +this.Id);
    if (aEnabled){
      zSelect.style.display = 'block';
      if (this.Type == 'Area' && this.ResizingString){
        this.selectElement.options[0].selected = true;
        var zInput  = $('ValueInput_' + this.RuleNumber + '_' + this.Index + '_' +this.Id);
        zInput.style.display = 'inline';
      }
      zScriptContainer.style.display = 'none';
    } else {
      if (this.Value != ''){
        zSelect.style.display = 'none';
        zScriptContainer.style.display = 'inline';
        var zScript = '';
        if (this.Type == 'Variable')
            zScript += '.' + this.Value;
        else zScript += '&nbsp;' + this.Value;
        zScriptContainer.innerHTML = zScript;
      }
    }
    return true;
  }
};
    // ---------------------- End Action_LiveAdMaker_Layouts ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_MediaLocations --------------- //
Util.debug.Enabled = true;
LiveAdMaker.MediaLocations =  {
  Name: "Media",
  CurrentItem: null,
  Load: function(aParams){
    var zSection = LiveAdMaker.MediaLocations;
    zSection.SearchObjectItemPath = "intel\\ContentList\\MediaLocationsList";
    if(!zSection.Items) {
        var zMediaLocationsListPath = "intel\\ContentList\\MediaLocationsList";
      Ajax.makeRequest({
        URL: URI.pageURL(zMediaLocationsListPath, "GetList", "aObjectTypeAlias=MediaLocationList", true),
        Function: LiveAdMaker.receiveSectionData,
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
      Ajax.makeRequest({
        URL: URI.pageURL("intel\\SystemReferenceList\\MediaTypeList", "GetList", "", true),
        Function: LiveAdMaker.MediaLocations.setMediaTypes,
        Params: {Section: aParams.Section, Params: aParams}
      });
    }
    else {
      LiveAdMaker.drawSection(aParams);
    }
    return true;
  },
  draw: function(aParms){
    return true;
  },
  Actions:[
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        LiveAdMaker.MediaLocations.CurrentItem = aParams.Item;
        aParams.ContentElement.innerHTML="";
        FormUI.Request.getForm(aParams.Item.ItemPath, 'MediaOutletDetails', aParams.ContentElement);
        return true;
      }
    },
    {
      Id: "Specs",
      DisplayName: "Specs",
      DisplayFunction: function(aParams){
        LiveAdMaker.MediaLocations.CurrentItem = aParams.Item;
        DOM.Dialog.hide();
        aParams.ContentElement.innerHTML="";
        LiveAdMaker.MediaLocations.Specs.init(aParams);
        return true;
      }
    },
    {
      Id: "Specs2",
      DisplayName: "New Specs",
      DisplayFunction: function(aParams){
        LiveAdMaker.MediaLocations.CurrentItem = aParams.Item;
        LiveAdMaker.MediaLocations.ContentElement = aParams.ContentElement;
        aParams.SearchObjectItemPath = aParams.Item.ItemPath;
        LiveAdMaker.MediaLocations.checkMediaSizeList(aParams);
        if (aParams.Item.HasMediaSizeList == "N") {
          LiveAdMaker.MediaLocations.createMediaSizeList(aParams);
        }
        aParams.URL = URI.pageURL(aParams.Item.ItemPath + unescape('\\MediaSizeList'), "GetList", "aSearchObjectTypeAlias=MediaSize", true)
        LiveAdMaker.requestSubItems(aParams);
        return true;
      }
    },
    {
      Id: "ShippingInfo",
      DisplayName: "Shipping Info",
      DisplayFunction: function(aParams){
        LiveAdMaker.MediaLocations.CurrentItem = aParams.Item;
        FormUI.Request.getForm(aParams.Item.ItemPath, 'ShippingPricingInfo', aParams.ContentElement);
        return true;
      }
    },
    {
      Id: "Trafficking",
      DisplayName: "Trafficking",
      DisplayFunction: function(aParams){
        LiveAdMaker.MediaLocations.CurrentItem = aParams.Item;
        DOM.Dialog.hide();
        aParams.ContentElement.innerHTML="";
        LiveAdMaker.MediaLocations.Trafficking.init(aParams);
        return true;
      }
    },
    {
      Id: "Purchasing",
      DisplayName: "Purchasing",
      DisplayFunction: function(aParams){
        LiveAdMaker.MediaLocations.CurrentItem = aParams.Item;
        DOM.Dialog.hide();
        FormUI.Request.GetForm(aParams.Item.ItemPath, 'MediaOutletPurchasing', aParams.ContentElement);
        return true;
      }
    }
  ],
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues: {
        aMoveToPath:"intel\\SystemReferenceList\\ArchivedMediaLocationsList"
      },
      Method:'POST'
    });
  },
  setMediaTypes: function(aResult,aParams) {
    if (aResult) {
      var zEnabledMediaTypes = aResult.Items.filter(function(aMediaType) {
        return (aMediaType.Disabled != "Y");
      });
      var zSortArray = zEnabledMediaTypes.makeUnique('Id');
      var compare = function(a, b) {
        return (b.DisplayName < a.DisplayName) - (a.DisplayName < b.DisplayName);
      };
      zSortArray.sort(compare);
      LiveAdMaker.MediaTypeArray = zSortArray;
    }
  },
  createNewItem: function(aParams) {
    var zNewMediaOutletContainer = ($('NewMediaOutletContainer')) ? $('NewMediaOutletContainer') : DOM.createElement('div','NewMediaOutletContainer','NewMediaOutletContainer');
    DOM.Dialog.showForm(zNewMediaOutletContainer, 'cursor', 'Search For New Media Outlet', 400, 400, 'MediaOutletAdd', 'intel\/ContentList\/MediaLocationsList', {AdditionalUrlParams:"&aGetForm_ExecuteObjectType=MediaLocation"});
    zNewMediaOutletContainer.childNodes[0].style.paddingLeft = '0px';
    return true;
  },
  importexportSectionItem: function(aParams){
    if (LiveAdMaker.SelectedSection.SelectedAction == "Customize") {
      LiveAdMaker.MediaLocations.Customize.importexportSectionItem(aParams);
    }
    return true;
  },
  exportSectionItem: function(aParams){
    DOM.Dialog.hide();
    var zExportTextContainer = $('ExportDiv');
    if (!zExportTextContainer) {
      var zExportTextContainer = DOM.createElement("div","ExportDiv");
    }
    DOM.Dialog.showForm(zExportTextContainer,{x:250, y:200},'Export','650',null,'MediaOutletExport','intel\\SettingsObject\\KnowledgeBaseTypeList\\MediaLocation');
    return true;
  },
  confirmMediaLocationsExport: function(aParams,aResult) {
    DOM.Dialog.hide();
    var zExportTextContainer, zExportConfirmText;
    if (aResult.Params.Success == "Y") {
      zExportConfirmText = DOM.createTextElement("div","ConfirmExportDiv",null,null,"Your export is now running.  You will receive an email with information on how to retrieve your file from the FTP server when this is complete.  Please be patient as data exports can take several minutes.");
    } else {
        zExportConfirmText = DOM.createTextElement("div","ConfirmExportDiv",null,null,"An unexpected error occurred while setting up your export.  Please try again.");
    }
    zExportTextContainer = $('ExportDiv');
    if (!zExportTextContainer) {
      var zExportTextContainer = DOM.createElement("div","ExportDiv");
    }
    DOM.replaceContent(zExportTextContainer, zExportConfirmText);
    DOM.Dialog.show(zExportTextContainer, 'center', 'Export','250',null);
  },
  checkMediaSizeList: function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "CheckMediaSizeList", null, true),
      Function: LiveAdMaker.MediaLocations.confirmMediaSizeList,
      Params: {Asynchronous: false},
      Method:'POST'
    });    
  },
  confirmMediaSizeList: function(aResults,aParams){
    LiveAdMaker.MediaLocations.CurrentItem.HasMediaSizeList = aResults.HasList;
  },   
  createMediaSizeList: function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "CreateItem", null, true),
      Function: LiveAdMaker.MediaLocations.confirmMediaAdSizeList,
      Params: {Asynchronous: false},
      PostValues: {
        aObjectTypeAlias: "MediaSizeGroup",
        aAlias: "MediaSizeList",
        aName: "MediaSizeList"
      },
      Method:'POST'
    });    
  },
  confirmMediaAdSizeList: function(aParams){
   LiveAdMaker.MediaLocations.CurrentItem.HasMediaSizeList = "Y";
  }
}
LiveAdMaker.MediaLocations.New = {
  receiveSearchResults: function(aResults,aParams) {
    var NewMediaOutletContainer = $('NewMediaOutletContainer');
    var zSearchResults = aResults.Results;
    if ($('SearchWaitingLoading')) {
     DOM.removeElement($('SearchWaitingLoading'));
    }
    zSearchResultContainer = $('NewMediaSearchResultsContainer');
    if (!zSearchResultContainer)
      var zSearchResultContainer = DOM.createElement('div','NewMediaSearchResultsContainer','NewMediaSearchResultsContainer');
    else
      zSearchResultContainer.innerHTML = '';
    var zSearchResultUnorderedList = DOM.createElement('ul', null, 'medialocation-list');
    zSearchResultUnorderedList.style.paddingLeft = '0px';
    zSearchResultUnorderedList.style.marginLeft = '0px';
    zSearchResultUnorderedList.style.listStyle = 'none';
    zSearchResultContainer.style.cssFloat = 'left';
    zSearchResultContainer.style.styleFloat = 'left';
    var zMediaType = aParams.MediaType;
    var zMediaOutletKeywordsValue = aParams.Keywords;
    if ($('inpMediaType')) {
      var zMediaTypeId = $('inpMediaType').value;
      for (var i=0; i<LiveAdMaker.MediaTypeArray.length; i++) {
        if (LiveAdMaker.MediaTypeArray[i].Id == zMediaTypeId) {
          var zMediaTypeDisplay = LiveAdMaker.MediaTypeArray[i].DisplayName;
        }
      }
    } else {
        var zMediaTypeDisplay = aParams.MediaTypeDisplayName;
    }
    var zAddNewMediaOutletButton = DOM.createElement("div",'inpAddNewMediaOutletButton',"Button");
    var zAddNewMediaOutletTxt = document.createTextNode("Add New " + zMediaTypeDisplay);
    zAddNewMediaOutletButton.setAttribute('name','inpAddNewMediaOutletButton');
    zAddNewMediaOutletButton.onclick = function() {
      var zNewName = prompt("Please enter a name for this " + zMediaType, zMediaOutletKeywordsValue.toString().trim());
      var aParams = {View:"ActionsWithName",Section:"MediaLocations",Action:"Details"}
      if(zNewName) {
        zNewName = zNewName.toString().trim();
        Ajax.makeRequest({
          URL: URI.pageURL("intel\\ContentList\\MediaLocationsList", "CreateItem", 'inpName=' + zNewName + '&inpMediaType=' + zMediaType + '&aObjectTypeAlias=MediaLocation', true),
          Function: LiveAdMaker.receiveNewItem,
          Params: {Section:"MediaLocations",Function:LiveAdMaker.drawSection,Params:aParams}
        });
      }
      DOM.Dialog.hide();
    }
    zAddNewMediaOutletButton.appendChild(zAddNewMediaOutletTxt);
    zSearchResultUnorderedList.appendChild(zAddNewMediaOutletButton);
    for(var i = 0; i < zSearchResults.length; i++) {
      mediaItem = DOM.createElement('li', null, 'media');
      mediaLabel = DOM.createElement('label');
      mediaLabel.setAttribute('for', 'inpMediaLocation_' + zSearchResults[i].ObjectCode);
      mediaInput = DOM.createElement('input');
      mediaInput.name = 'inpMediaLocation';
      mediaInput.type = 'checkbox';
      mediaInput.setAttribute('id', 'inpMediaLocation_' + zSearchResults[i].ObjectCode);
      mediaInput.value = zSearchResults[i].ItemPath;
      mediaInput.onclick = function() {
        Ajax.makeRequest({
          URL: URI.pageURL(this.value, "AddToClientSystem", 'inpAddMode='+this.checked),
          Function: LiveAdMaker.MediaLocations.New.updateMediaOutletList
        });
      }
      mediaTxt = document.createTextNode(zSearchResults[i].DisplayName);
      mediaLabel.appendChild(mediaInput);
      mediaLabel.appendChild(mediaTxt);
      mediaItem.appendChild(mediaLabel);
      zSearchResultUnorderedList.appendChild(mediaItem);
    }
    zSearchResultContainer.appendChild(zSearchResultUnorderedList);
    NewMediaOutletContainer.style.height = '350px';
    NewMediaOutletContainer.appendChild(zSearchResultContainer);
  },
  updateMediaOutletList: function(aResult) {
    if(aResult) {
      if(aResult.RefreshList=='Y') {
        var aParams = {
          Params: {
            View: "ActionsWithName",
            Section: "MediaLocations",
            Action: "Details"
          },
          Section: "MediaLocations"
        }
        LiveAdMaker.receiveNewItem(aResult,aParams);
      }
    }
  }
}
LiveAdMaker.MediaLocations.Specs = {
  AdSizeTotal: '',
  SpecForm: null,
  init: function(aParams) {
    LiveAdMaker.MediaLocations.Specs.AdSizeTotal = 0;
    FormUI.FormItemPath = aParams.Item.ItemPath;
    FormUI.ElementArray.length = 0;
    LiveAdMaker.MediaLocations.Specs.SpecForm = new FormUI.Form(aParams.Item.ItemPath, "SpecFormDetails");
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetSpecForm", "", false),
      Function: LiveAdMaker.MediaLocations.Specs.receiveSpecForm,
      Params: {Section: aParams.Section, Params: aParams}
    });
  },
  receiveSpecForm: function(aResult,aParams) {
    var zSpecForm = LiveAdMaker.MediaLocations.Specs.SpecForm;
    var ContentElement = aParams.Params.ContentElement;
    zSpecForm.ContentElement = ContentElement;
    var Seq = 0;
     if(aResult && LiveAdMaker.matchCurrentHashValues(aParams.Params)) {
      for (var i = 0; i < aResult.length; i++ ){
        var SpecDataTable = DOM.createElement('table','SpecForm'+aResult[i].Title+'Table','CSVTable MediaSpecTable');
        SpecDataTable.setAttribute('cellPadding','3');
        SpecDataTable.setAttribute('cellSpacing','0');
        SpecDataTable.style.marginBottom = (1 * FormUI.GridMultiplier) +'px';
        var SpecDataTableTitles = DOM.createElement('thead');
        var SpecDataTableBody = DOM.createElement('tbody');
        var SpecDataHeaderRow = DOM.createElement('tr','','CSVTitleRow','');
        SpecDataTableTitles.appendChild(SpecDataHeaderRow);
        SpecDataTable.appendChild(SpecDataTableTitles);
        SpecDataTable.appendChild(SpecDataTableBody);
        LiveAdMaker.MediaLocations.Specs[aResult[i].Title + "ColumnArray"] = new Array();
        SpecDataHeaderRow.appendChild(DOM.createActionElement('th',LiveAdMaker.MediaLocations.Specs["createNew"+aResult[i].Title],'',{TableBody: SpecDataTableBody, Title: aResult[i].Title}));
        for (var j = 0; j < aResult[i].Data.DisplayTitles.length; j++) {
          var HeaderCell = DOM.createTextElement('th','','','',aResult[i].Data.DisplayTitles[j]);
          if (aResult[i].Title == "VariableAdSizes" && aResult[i].Data.TitleAlias[j] == "Columns")
            HeaderCell.colSpan = 2;
          if (aResult[i].Data.TitleAlias[j] == "Columns" || aResult[i].Data.TitleAlias[j] == "Size")
            HeaderCell.style.width= '40%';
          SpecDataHeaderRow.appendChild(HeaderCell);
          LiveAdMaker.MediaLocations.Specs[aResult[i].Title + "ColumnArray"].push(aResult[i].Data.TitleAlias[j]);
        }
        for (var j = 0; j < aResult[i].Data.Items.length; j++) {
          var DataItemRow = DOM.createElement('tr','','','');
          DataItemRow.appendChild(DOM.createElement('td','','','',''));
          for (var k = 0; k < aResult[i].Data.TitleAlias.length; k++) {
            var TitleAlias = aResult[i].Data.TitleAlias[k];
            var CellText = aResult[i].Data.Items[j][TitleAlias];
            if (CellText != "Any" && TitleAlias != "DisplayName") {
              var FieldContainer = DOM.createElement('td','','','');
              DataItemRow.appendChild(FieldContainer);
              var zElementWidth = "10";
              if (TitleAlias == "Size") {
                zElementWidth = "35";
                LiveAdMaker.MediaLocations.Specs.AdSizeTotal++;
              }
              if (TitleAlias == "Columns") {
                zElementWidth = "2.5";
                FieldContainer.style.width =  (zElementWidth * FormUI.GridMultiplier) + 'px';
                var ColumnsFieldContainer = DOM.createTextElement('td','','','','Column');
                DataItemRow.appendChild(ColumnsFieldContainer);
                LiveAdMaker.MediaLocations.Specs.AdSizeTotal++;
              }
              Seq++;
              var zPosition = { Top: "-1", Left: "0", Height: "3", Width: zElementWidth}
              var aElementProperties = {
                 FieldType: "CSVVALUE",
                 CSVColumnId: "Id",
                 CSVRowId: aResult[i].Data.Items[j].Id,
                 CSVValue: TitleAlias,
                 CSVEncoding: "Base64",
                 DisplayValue: CellText,
                 Value: CellText,
                 GroupId: aResult[i].Title,
                 OnRemoveFunction: "LiveAdMaker.MediaLocations.Specs.removeAdSizeRow",
                 SeqNo: Seq,
                 Form: zSpecForm
              }
              var zElement = new FormUI.Element('Text', aResult[i].Title+'_'+TitleAlias + LiveAdMaker.MediaLocations.Specs.AdSizeTotal, zPosition, '', aElementProperties);
              zElement.setPath('.Text.SupportedAdSizesCSV_Base64.Detail');
              FieldContainer.style.height = (4 * FormUI.GridMultiplier) + 'px';
              var FieldElement = FormUI.createElement(zElement, FieldContainer, 'SpecForm'+aResult[i].Title+'_'+TitleAlias + LiveAdMaker.MediaLocations.Specs.AdSizeTotal, true);
              DOM.addClass(FieldElement.parentNode,'InputCellContainer');
              FormUI.ElementArray.push(FieldElement);
            }
            else {
              var CellId = '';
              if (aResult[i].Title == "ColorSpaces") {
                CellId = aResult[i].Data.Items[j].ColorSpace;
              }
              var Cell = DOM.createTextElement('td',CellId,'','',CellText);
              Cell.style.height = (4 * FormUI.GridMultiplier) + 'px';
              DataItemRow.appendChild(Cell);
            }
          }
          SpecDataTableBody.appendChild(DataItemRow);
        }
        SpecDataTable.width = "100%";
        ContentElement.appendChild(SpecDataTable);
      }
    }
  },
  createNewAdSize: function (aParams,AdSizeArray) {
    SpecDataTableBody = aParams.TableBody;
    var zSpecForm = LiveAdMaker.MediaLocations.Specs.SpecForm;
    var DataItemRow = DOM.createElement('tr','','','');
    DataItemRow.appendChild(DOM.createElement('td','','','',''));
    for (var k = 0; k < AdSizeArray.length; k++) {
      var TitleAlias = AdSizeArray[k];
      if (!(aParams.Title == "VariableAdSizes" && TitleAlias == "Height")) {
        var zElementWidth = "10";
        var CellText = "";
        var DisplayStatus = true;
        var FieldContainer = DOM.createElement('td','','','');
        DataItemRow.appendChild(FieldContainer);
        if (TitleAlias == "Size" || TitleAlias == "Columns") {
          zElementWidth = "35";
          DisplayStatus = false;
          LiveAdMaker.MediaLocations.Specs.AdSizeTotal++;
          if (TitleAlias == "Columns") {
            DataItemRow.appendChild(DOM.createTextElement('td','','','','Column'));
            zElementWidth = "3";
          }
        }
        var AdSizeNumber = LiveAdMaker.MediaLocations.Specs.AdSizeTotal;
        var zPosition = { Top: "-1", Left: "0", Height: "3", Width: zElementWidth}
        var aElementProperties = {
           FieldType: "CSVVALUE",
           CSVColumnId: "Id",
           CSVRowId: "AdSize"+AdSizeNumber,
           CSVValue: TitleAlias,
           CSVEncoding: "Base64",
           DisplayValue: CellText,
           Value: CellText,
           GroupId: aParams.Title,
           Form: zSpecForm
        }
        var zElement = new FormUI.Element('Text', aParams.Title +'_'+ TitleAlias + AdSizeNumber, zPosition, '', aElementProperties);
        zElement.setPath('.Text.SupportedAdSizesCSV_Base64.Detail');
        FieldContainer.style.height = (4 * FormUI.GridMultiplier) + 'px';
        var FieldElement = FormUI.createElement(zElement, FieldContainer, 'SpecForm'+ aParams.Title + '_' + TitleAlias + AdSizeNumber, DisplayStatus);
        if(DisplayStatus==false)
          var ClassElement = FieldElement.parentNode.parentNode;
        else
          var ClassElement = FieldElement.parentNode;
        DOM.addClass(ClassElement,'InputCellContainer');
      }
      else {
        var Cell = DOM.createTextElement('td','','','','Any');
        Cell.style.height = (4 * FormUI.GridMultiplier) + 'px';
        DataItemRow.appendChild(Cell);
      }
    }
    SpecDataTableBody.appendChild(DataItemRow);
    return FieldElement;
  },
  createNewStandardAdSizes: function(e, aParams){
    var AdSizeArray = LiveAdMaker.MediaLocations.Specs.StandardAdSizesColumnArray;
    NewElement = LiveAdMaker.MediaLocations.Specs.createNewAdSize(aParams,AdSizeArray);
    return true;
  },
  createNewVariableAdSizes: function(e, aParams){
    var AdSizeArray = LiveAdMaker.MediaLocations.Specs.VariableAdSizesColumnArray;
    NewElement = LiveAdMaker.MediaLocations.Specs.createNewAdSize(aParams,AdSizeArray);
    return true;
  },
  removeAdSizeRow: function(e,aParams) {
    FormUI.cancelBubble(e, aParams);
    var aElement = aParams.Element;
    var WritePropertyPath =  escape(aElement.WritePropertyPath);
    var CSVRowId = escape(aElement.CSVRowId);
    var CSVColumnId = escape(aElement.CSVColumnId);
    var CSVEncoding = escape(aElement.CSVEncoding);
    var aGetVars = "inpWritePropertyPath="+WritePropertyPath+"&inpCSVColumnId="+CSVColumnId+"&inpCSVRowId="+CSVRowId+"&inpCSVEncoding="+CSVEncoding;
    var DataItemRow = aParams.Container.parentNode.parentNode.parentNode;
    Ajax.makeRequest({
      URL: URI.pageURL(FormUI.FormItemPath, "RemoveAdSize", aGetVars, true),
      Function: LiveAdMaker.MediaLocations.Specs.updateAdSizeRow,
      Params: {DataItemRow: DataItemRow}
    });
  },
  updateAdSizeRow: function(aResult,aParams) {
    if(aResult) {
      if(aResult.Success=="Y") {
        var DataItemRow = aParams.DataItemRow;
        DataItemRow.parentNode.removeChild(DataItemRow);
      }
    }
  },
  ColorSpaceArray: [
    { DisplayName: '4 Color',Alias: '4color' },
    { DisplayName: 'B&W',Alias: 'bw' },
    { DisplayName: 'Spot Color',Alias: 'spotcolor' }
  ],
  createNewColorSpaces: function(e, aParams){
    var AddColorSpaceContainer = DOM.createElement('div', 'colorspace-searchresults', '');
    var ColorSpaceUnorderedList = DOM.createElement('ul', null, 'colorspace-list');
    var zColorSpaceArray = LiveAdMaker.MediaLocations.Specs.ColorSpaceArray;
    for(var i = 0; i < zColorSpaceArray.length; i++) {
      colorItem = DOM.createElement('li', null, 'color');
      colorLabel = DOM.createElement('label');
      colorLabel.setAttribute('for', 'inpColor_' + zColorSpaceArray[i].Alias);
      colorInput = DOM.createElement('input');
      colorInput.name = 'inpColor' + zColorSpaceArray[i].Alias;
      colorInput.type = 'checkbox';
      colorInput.setAttribute('id', 'inpColor_' + zColorSpaceArray[i].Alias);
      colorInput.setAttribute('displayname', zColorSpaceArray[i].DisplayName);
      colorInput.value = zColorSpaceArray[i].Alias;
      colorInput.onclick = function() {
        var zSearchParams = 'inpAddMode=' + this.checked + '&inpColorSpaceAlias=' + this.value;
        Ajax.makeRequest({
          URL: URI.pageURL(FormUI.FormItemPath, "SetColorSpaceData", zSearchParams, true),
          Function: LiveAdMaker.MediaLocations.Specs.updateColorSpaceDisplay,
          Params: { TableBody: aParams.TableBody, ContentElement: aParams.ContentElement, ColorAlias: this.value, AddMode: this.checked, DisplayName: this.getAttribute("displayname") }
        });
      }
      var ExistingColorItemCell = $(zColorSpaceArray[i].Alias);
      if (ExistingColorItemCell && ExistingColorItemCell.parentNode.style.display != 'none') {
        colorInput.checked = true;
      }
      colorTxt = document.createTextNode(zColorSpaceArray[i].DisplayName);
      colorLabel.appendChild(colorInput);
      colorLabel.appendChild(colorTxt);
      colorItem.appendChild(colorLabel);
      ColorSpaceUnorderedList.appendChild(colorItem);
    }
    AddColorSpaceContainer.appendChild(ColorSpaceUnorderedList);
    DOM.Dialog.show(AddColorSpaceContainer, 'center', 'Add Color Space:');
  },
  getColorSpaceData: function(aItemPath,aParams){
    Ajax.makeRequest({
      URL: aItemPath.toPagePath()+".GetColorSpaceData",
      Function: LiveAdMaker.MediaLocations.Specs.drawColorSpaceData,
      Params: {ContentElement: aParams.ContentElement}
    });
  },
  drawColorSpaceData: function(aResults,aParams){
    if(aResults){
      var ColorSpaceContainer= DOM.createElement('div','ColorSpaceContainer','ColorSpaceContainer');
      aParams.ContentElement.appendChild(ColorSpaceContainer);
      for(var i = 0; i < aResults.length; i++) {
        var ColorSpaceItem = DOM.createTextElement('div',aResults[i].ColorSpace,'FormUI-Field FormUI-Field-Text','',aResults[i].DisplayName);
        ColorSpaceContainer.appendChild(ColorSpaceItem);
      }
    }
  },
  updateColorSpaceDisplay: function(aResults,aParams){
    if(aResults.Success=='Y'){
      var CellText= aParams.DisplayName;
      var CellId = aParams.ColorAlias;
      var ExistingColorItemCell = $(CellId.toLowerCase());
      if (ExistingColorItemCell) {
        var ExistingColorItemRow = ExistingColorItemCell.parentNode;
      }
      if(!ExistingColorItemRow){
        if(aParams.AddMode==true){
          var SpecDataTableBody = aParams.TableBody;
          var DataItemRow = DOM.createElement('tr','','','');
          var Cell = DOM.createTextElement('td',CellId.toLowerCase(),'','',CellText);
          Cell.style.height = (4 * FormUI.GridMultiplier) + 'px';
          DataItemRow.appendChild(DOM.createElement('td','','',''));
          DataItemRow.appendChild(Cell);
          SpecDataTableBody.appendChild(DataItemRow);
        }
      }
      else {
        if(aParams.AddMode==true){
          ExistingColorItemRow.style.display = '';
        }
        else {
          ExistingColorItemRow.style.display = 'none';
        }
      }
    }
    else {
    }
  }
}
LiveAdMaker.MediaLocations.Specs2 = {
  CurrentItem: null,
  ContentElement: null,
  AssetList: null,
  createNewItem: function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.MediaLocations.CurrentItem.ItemPath, "CreateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"MediaLocations", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aObjectTypeAlias: "MediaSize",
        aAlias: "MediaSize".makeUnique(),
        aName: "MediaSize "+(LiveAdMaker.SelectedSection.Items.length+1)
      },
      Method:'POST'
    });
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "",
      DisplayFunction: function(aParams) {
        LiveAdMaker.MediaLocations.Specs2.Details.init(aParams);
        return true;
      }
    }
  ],
  getActions: function(){
    return LiveAdMaker.MediaLocations.Specs2.Actions;
  },
  draw: function(aParams) {
  },
  archiveItem: function(aParams) {
    LiveAdMaker.MediaLocations.Specs2.archiveItem(aParams);
    return true;
  },
  togglePrintAdType: function(aParams) {
    var zElement = aParams.Element;
    var zForm    = aParams.Element.Form;
    var zColumnElementArray = zForm.ElementArray.get("Columns", "Field");
    var zColumnElement      = zColumnElementArray[0];    
    var zHeightElementArray = zForm.ElementArray.get("Height", "Field");
    var zHeightElement      = zHeightElementArray[0];    
    if (zElement.Value == "Standard Size"){
      $(zHeightElement.ElementId).style.display = "block";
      $(zColumnElement.ElementId).style.display = "none";
    }
    else {
      zColumnElement.CanEdit = "Y";
      zColumnElement.DisplayValue = "";
      $(zColumnElement.ElementId).style.display = "block";
      $(zHeightElement.ElementId).style.display = "none";
      zHeightElement.DisplayValue = "Any";    
    }              
    return true;
  },  
  onListDrawFunction: function(aParams) {
    aParams.TopContainer = this.ActionNavContainerElement.parentNode;
    aParams.ActionNavContainerElement = this.ActionNavContainerElement;
    return true;
  }
}
LiveAdMaker.MediaLocations.Specs2.Details = {
  init:function(aParams){
    FormUI.Request.getForm(aParams.Item.ItemPath, 'Details', aParams.ContentElement,'','');
  }
}
LiveAdMaker.MediaLocations.Dealers = {
  CurrentItem: null,
  ContentElement: null,
  AssetList: null,
  getActions: function(){return LiveAdMaker.Dealers.Actions;},
  draw: function(aParams) {},
  createNewItem: function() {
    DOM.Dialog.hide();
    var zCompanySearchContainer = $('CompanySearchContainer');
    if (!zCompanySearchContainer) {
      var zCompanySearchContainer = DOM.createElement('div','CompanySearchContainer');
    }
    DOM.Dialog.showForm(zCompanySearchContainer,{x:250, y:100},'Search Companies','600',null,'CompanySearch','intel\\ContentList\\CompanyList');
  },
  addToSection: function() {
    LiveAdMaker.MediaLocations.Dealers.createNewItem();
  },
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.MediaLocations.CurrentItem.ItemPath, "MapToDealer", 'inpDealerItemPath=' + LiveAdMaker.Dealers.Details.ItemPath + '&inpAddMode=false&inpInnerBubble=Y', true),
      Function: LiveAdMaker.MediaLocations.Dealers.updateDealerDisplay,
      Params: {AddMode:false}
    });
  },
  updateDealerDisplay: function(aReceiveData,aParams) {
    if (aReceiveData) {
      if (aParams.AddMode) {
        LiveAdMaker.receiveNewItem(aReceiveData,aParams);
      }
      else {
        LiveAdMaker.receiveArchiveItem(aReceiveData,{Section:"MediaLocations",SubSection:"Dealers",ItemId:aReceiveData.Id});
      }
    }
  },
  receiveDealerSearchResults: function(aParams, aResults) {
    if ($("dealer-searchresults")) {
        DOM.removeElement($("dealer-searchresults"));
    }
    var zResults = aResults.Params;
    var zCompanySearchContainer = $("CompanySearchContainer");
    var zSearchResultContainer = DOM.createElement("div", "dealer-searchresults", "");
    var zSearchResultTable = DOM.createElement("table", null, "dealer-list");
    var zSearchResultTableHeader = DOM.createElement("thead");
    var zSearchResultTableBody = DOM.createElement("tbody");
    zSearchResultTable.style.clear = 'both';
    zSearchResultHeader = DOM.createElement("tr", null, "", "font-weight: bold;");
    zSearchResultHeaderNameCol = DOM.createElement("td", null, "");
    zSearchResultHeaderNameCol.innerHTML = "Company Name";
    zSearchResultHeaderAddressCol = DOM.createElement("td", null, "");
    zSearchResultHeaderAddressCol.innerHTML = "Full Address";
    zSearchResultHeaderPhoneCol = DOM.createElement("td", null, "");
    zSearchResultHeaderPhoneCol.innerHTML = "Phone Number";
    zSearchResultHeader.appendChild(zSearchResultHeaderNameCol);
    zSearchResultHeader.appendChild(zSearchResultHeaderAddressCol);
    zSearchResultHeader.appendChild(zSearchResultHeaderPhoneCol);
    zSearchResultTable.appendChild(zSearchResultTableHeader);
    zSearchResultTable.appendChild(zSearchResultTableBody);
    zSearchResultTableBody.appendChild(zSearchResultHeader);
    for (var i = 0; i < zResults.length; i++) {
        dealerTableRow = DOM.createElement("tr", null, "dealer");
        dealerTableRowNameCol = DOM.createElement("td", null, "dealer");
        dealerTableRowAddressCol = DOM.createElement("td", null, "dealer");
        dealerTableRowPhoneCol = DOM.createElement("td", null, "dealer");
        dealerTableRow.appendChild(dealerTableRowNameCol);
        dealerTableRow.appendChild(dealerTableRowAddressCol);
        dealerTableRow.appendChild(dealerTableRowPhoneCol);
        dealerLabel = DOM.createElement("label");
        dealerLabel.setAttribute("for", "inpDealerPath_" + zResults[i].Identifier);
        dealerInput = DOM.createElement("input");
        dealerInput.name = "inpDealerPath" + zResults[i].Identifier;
        dealerInput.type = "checkbox";
        dealerInput.style.verticalAlign = "top";
        dealerInput.setAttribute("id", "inpDealerPath_" + zResults[i].Identifier);
        dealerInput.setAttribute("objectcode", zResults[i].Identifier);
        dealerInput.setAttribute("displayname", zResults[i].DisplayName);
        dealerInput.value = zResults[i].ItemPath;
        dealerInput.onclick = function() {
          var zSearchParams = 'inpAddMode=' + this.checked + '&inpDealerItemPath=' + this.value + '&inpInnerBubble=Y';
          Ajax.makeRequest({
            URL: URI.pageURL(LiveAdMaker.MediaLocations.CurrentItem.ItemPath, "MapToDealer", zSearchParams, true),
            Function: LiveAdMaker.receiveNewItem,
            Params: { ContentElement: aParams.ContentElement, SearchContainer: zSearchResultContainer, Identifier: this.getAttribute("objectcode"), AddMode: this.checked, DisplayName: this.getAttribute("displayname"), ItemPath: this.getAttribute("value"), Params:{Section:"MediaLocations",SubSection:"Dealers"}}
          });
        }
        dealerLabel.appendChild(dealerInput);
        dealerTxt = document.createTextNode(zResults[i].DisplayName);
        dealerLabel.appendChild(dealerTxt);
        dealerTableRowNameCol.appendChild(dealerLabel);
        dealerAddress = document.createTextNode(zResults[i].FullAddress);
        dealerTableRowAddressCol.appendChild(dealerAddress);
        dealerPhone = document.createTextNode(zResults[i].PhoneNumber);
        dealerTableRowPhoneCol.appendChild(dealerPhone);
        zSearchResultTableBody.appendChild(dealerTableRow);
    }
    if(zResults.length) {
      zSearchResultContainer.appendChild(zSearchResultTable);
    } else {
      zSearchResultContainer.appendChild(document.createTextNode("No Results Found"));
    }
    zCompanySearchContainer.appendChild(zSearchResultContainer);
  },
  exportSectionItem: function(aParams){
    aParams.ReceiveFunction = LiveAdMaker.MediaLocations.Dealers.exportDealersToFTP;
    LiveAdMaker.Dealers.exportSectionItem(aParams);
  },
  exportDealersToFTP: function(e,aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.MediaLocations.CurrentItem.ItemPath, "ExportDetails", null, true),
      Function: LiveAdMaker.MediaLocations.Dealers.confirmDealersExport,
      Params: aParams,
      PostValues: {},
      Method:'POST'
    });
    return true;
  },
  confirmDealersExport: function(aResult,aParams) {
    var zExportTextContainer, zExportConfirmText;
    if (aResult.Success == "Y") {
      zExportConfirmText = DOM.createTextElement("div","ConfirmExportDiv",null,null,"Your export is now running.  You will receive an email with information on how to retrieve your file from the FTP server when this is complete.  Please be patient as data exports can take several minutes.");
    } else {
        zExportConfirmText = DOM.createTextElement("div","ConfirmExportDiv",null,null,"An unexpected error occurred while setting up your export.  Please try again.");
    }
    zExportTextContainer = aParams.ExportTextContainer;
    DOM.replaceContent(zExportTextContainer, zExportConfirmText);
    DOM.Dialog.show(zExportTextContainer, 'center', 'Export','250',null);
  }
}
LiveAdMaker.MediaLocations.Trafficking = {
  init: function(aParams){
    if (aParams.Item.TraffickingType) {
      var TraffickingType = aParams.Item.TraffickingType;
      TraffickingType = TraffickingType.replace(/\s/g,'');
    }
    else {
      var TraffickingType = "LiveAdMakerFTP"
    }
    var zFormParams = {
      OnDisplayFunction:LiveAdMaker.MediaLocations.Trafficking.drawFTPTest,
      OnDisplayParams:{DisplayParams:aParams,TraffickingType:TraffickingType}
    }
    FormUI.Request.getForm(aParams.Item.ItemPath, 'MediaOutletTrafficking_'+TraffickingType, aParams.ContentElement,'',zFormParams);
    LiveAdMaker.MediaLocations.Trafficking.getHistory(aParams);
    return true;
  },
  setTraffickingType: function(aParams) {
    var Item = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Item.TraffickingType = aParams.Element.Value;
    var zTraffickingType = aParams.Element.Value.replace(/\s/g,'');
    aParams.Item = Item;
    var zFormParams = {
      OnDisplayFunction:LiveAdMaker.MediaLocations.Trafficking.drawFTPTest,
      OnDisplayParams:{DisplayParams:aParams,TraffickingType:zTraffickingType}
    }
    FormUI.Request.getForm(Item.ItemPath, 'MediaOutletTrafficking_'+zTraffickingType, FormUI.ContentElement,'',zFormParams);
    return true;
  },
  getHistory: function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetTraffickingHistory", '', true),
      Function: LiveAdMaker.MediaLocations.Trafficking.drawHistory,
      Params: { ContentElement: aParams.ContentElement }
    });
  },
  drawHistory: function(aResults,aParams){
    var TraffickingHistoryContainer = DOM.createElement('div','TraffickingContainer','');
    var TraffickingHistoryHeaderText = DOM.createTextElement('div','TraffickingHeaderText','TraffickingHeaderText','','Checkout History');
    TraffickingHistoryContainer.appendChild(TraffickingHistoryHeaderText);
    var TraffickingHistoryTable = DOM.createElement('table','TraffickingHistoryTable','TraffickingHistoryTable');
    TraffickingHistoryTable.setAttribute('cellPadding','0');
    TraffickingHistoryTable.setAttribute('cellSpacing','0');
    var TraffickingTableTitles= DOM.createElement('thead');
    var TraffickingTableBody= DOM.createElement('tbody');
    var TraffickingHeaderRow= DOM.createElement('tr');
    TraffickingTableTitles.appendChild(TraffickingHeaderRow);
    TraffickingHistoryTable.appendChild(TraffickingTableBody);
    TraffickingHistoryTable.appendChild(TraffickingTableTitles);
    TraffickingHeaderRow.appendChild(DOM.createTextElement('th','','','','Date'));
    TraffickingHeaderRow.appendChild(DOM.createTextElement('th','','','','Traffick Type'));
    TraffickingHeaderRow.appendChild(DOM.createTextElement('th','','','','Insertion #'));
    TraffickingHeaderRow.appendChild(DOM.createTextElement('th','','','','Ticket #'));
    TraffickingHeaderRow.appendChild(DOM.createTextElement('th','','','','File'));
    TraffickingHeaderRow.appendChild(DOM.createTextElement('th','','','','Status'));
    TraffickingHeaderRow.appendChild(DOM.createTextElement('th','','','','Run Date'));
    TraffickingHistoryContainer.appendChild(TraffickingHistoryTable);
    aParams.ContentElement.appendChild(TraffickingHistoryContainer);
    if(aResults.HaveHistory=='Yes'){
      for (var i = 0; i < aResults.HistoryArray.length; i++) {
        var TraffickingBodyRow = DOM.createElement('tr');
        TraffickingBodyRow.appendChild(DOM.createTextElement('td','','','',aResults.HistoryArray[i].InsertionDate));
        TraffickingBodyRow.appendChild(DOM.createTextElement('td','','','',aResults.HistoryArray[i].TraffickType));
        TraffickingBodyRow.appendChild(DOM.createTextElement('td','','','',aResults.HistoryArray[i].Insertion));
        TraffickingBodyRow.appendChild(DOM.createTextElement('td','','','',aResults.HistoryArray[i].TicketNumber));
        var FileLink = DOM.createTextElement('a','','','',aResults.HistoryArray[i].FileName);
        FileLink.setAttribute('href',unescape(aResults.HistoryArray[i].FileURL));
        var TraffickingLinkCell= DOM.createElement('td');
        TraffickingLinkCell.appendChild(FileLink);
        TraffickingBodyRow.appendChild(TraffickingLinkCell);
        TraffickingBodyRow.appendChild(DOM.createTextElement('td','','','',aResults.HistoryArray[i].Confirmed));
        TraffickingBodyRow.appendChild(DOM.createTextElement('td','','','',aResults.HistoryArray[i].AdRun));
        TraffickingTableBody.appendChild(TraffickingBodyRow);
      }
    }
    else {
      var TraffickingBodyRow= DOM.createElement('tr');
      TraffickingBodyRow.appendChild(DOM.createTextElement('td','','','','No checkout history available.'));
      TraffickingTableBody.appendChild(TraffickingBodyRow);
    }
  },
  drawFTPTest: function(aFormParams){
    var zDrawTestFTPLink = false;
    var aParams=aFormParams.DisplayParams;
    var TraffickingType=aFormParams.TraffickingType;
    switch (TraffickingType){
      case "LiveAdMakerFTP":
        zDrawTestFTPLink=true;
        break;
      case "PublicationsFTP":
        zDrawTestFTPLink=true;
        break;
      default :
        zDrawTestFTPLink=false;
        break;
    }
    if (zDrawTestFTPLink){
      var FTPLinkText = DOM.createTextElement('a','TestFTPLink','TestFTPLink_'+TraffickingType,'','Test FTP');
      FTPLinkText.setAttribute('href','javascript:void(0);');
      FTPLinkText.onclick = function () {
        LiveAdMaker.MediaLocations.Trafficking.performFTPTest(aParams,TraffickingType);
      }
        FormUI.ContentElement.appendChild(FTPLinkText);
    }
    return true;
  },
  performFTPTest: function(aParams,TraffickingType){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "TestFTP", 'inpTraffickingType='+TraffickingType, true),
      Function: LiveAdMaker.MediaLocations.Trafficking.displayFTPTestResult,
      Params: { ContentElement: aParams.ContentElement }
    });
    return true;
  },
  displayFTPTestResult: function(aResult,aParams) {
    var FTPResultMessage = DOM.createTextElement('div','','ftp-testresults','','<span>FTP Test:</span> '+aResult.FTPConnect);
    DOM.Dialog.show(FTPResultMessage, 'center', '');
    return true;
  }
}
LiveAdMaker.MediaLocations.Customize = {
  importexportSectionItem: function(aParams){
    DOM.Dialog.hide();
    var zCustomizeImportTextContainer = $("CustomizeImportDiv");
    if (!zCustomizeImportTextContainer) {
      var zCustomizeImportTextContainer = DOM.createElement("div","CustomizeImportDiv");
    }
    DOM.Dialog.showForm(zCustomizeImportTextContainer,{x:250, y:250},'Import Rotations','650','100','ImportRotations',LiveAdMaker.MediaLocations.CurrentItem.ItemPath);
    return true;
  },
  startRotationsImport: function(aResult) {
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.MediaLocations.CurrentItem.ItemPath, "ImportRotations", "inpRotationFileOwnerPath=" + aResult.ItemPath, true),
      Function: LiveAdMaker.MediaLocations.Customize.confirmImportSectionItem,
      Params: ""
    });
    return true;
  },
  confirmImportSectionItem: function(aResult) {
    var zCustomizeImportConfirmText, zCustomizeImportTextContainer;
    zCustomizeImportTextContainer = $("CustomizeImportDiv");
    if (aResult.Success == "Y") {
      zCustomizeImportConfirmText = DOM.createTextElement("div","ConfirmCustomizeImportDiv",null,null,"Your import is now running and you will receive an email when complete.  Please be patient as imports may take several minutes.");
    } else {
        zCustomizeImportConfirmText = DOM.createTextElement("div","ConfirmCustomizeImportDiv",null,null,"An unexpected error occurred while setting up your import.  Please try again.");
    }
    if (!zCustomizeImportTextContainer) {
      zCustomizeImportTextContainer = DOM.createElement("div","CustomizeImportDiv");
    }
    zCustomizeImportTextContainer.appendChild(zCustomizeImportConfirmText);
    return true;
  }
}
    // ---------------------- End Action_LiveAdMaker_MediaLocations ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_Options --------------- //
LiveAdMaker.Options = {
  Name: "Options",
  Load: function(aParams){
    var zSection = LiveAdMaker.Options;
    zSection.SearchObjectItemPath = URI.User.ItemPath;
    if(!zSection.Items) {
      Ajax.makeRequest({
        URL: URI.pageURL(URI.User.ItemPath, "GetList", "", true),
        Function: LiveAdMaker.receiveSectionData,
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
    }
    else {
      LiveAdMaker.drawSection(aParams);
    }
    return true;
  },
  draw: function(aParms){
    return true;
  },
  Actions: [
    {
      Id: "Payment",
      DisplayName: "Payment",
      DisplayFunction: function(aParams){
        FormUI.Request.GetForm("intel\\SystemReferenceList\\PaymentTypeList", 'PaymentTypeDetails', aParams.ContentElement);
        return true;
      }
    },
    {
      Id: "Help",
      DisplayName:"Help",
      DisplayFunction: function(aParams){
        aParams.URL = '/intel/SystemContentList/HelpManager.GetList?aLanguage=en%2Dus&LSAccessID=';
        aParams.SearchObjectItemPath = "intel\\SystemContentList\\HelpManager";
        LiveAdMaker.requestSubItems(aParams);
        return true;
      }
    },
    {
      Id: "Styles",
      DisplayName:"Styles",
      DisplayFunction: function(aParams){
        LiveAdMaker.Options.Styles.init(aParams);
      }
    },
    {
      Id: "Approval",
      DisplayName:"Approval Setup",
      DisplayFunction: function(aParams){
        LiveAdMaker.Options.Approval.init(aParams);
      }
    },
    {
      Id: "Support",
      DisplayName:"Support",
      DisplayFunction: function(aParams){
        LiveAdMaker.Options.Support.SupportDetails.init(aParams);
      }
    },
    {
      Id: "MediaGroups",
      DisplayName:"Media Groups",
      DisplayFunction: function(aParams) {
        aParams.URL = URI.pageURL('intel\\SystemReferenceList\\MediaTypeList', "GetList", "", true);
        LiveAdMaker.requestSubItems(aParams);
        return true;
      }
    }
  ]
};
LiveAdMaker.Options.Help = {
  CurrentItem: null,
  ContentElement: null,
  HelpItemsList: null,
  createNewItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL('intel\\SystemContentList\\HelpManager', "CreateItem", "aObjectTypeAlias=HelpItem", true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Options.Help", Function:LiveAdMaker.drawSection,Params:aParams},
      PostValues:{
        aAlias:"HelpItem".makeUnique(),
        aName:"Help Item"+LiveAdMaker.Options.Help.SubItemList.ItemArray.length
      },
      Method:'POST'
    });
  },
  duplicateItem: function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Options", Function: LiveAdMaker.drawSection, Params: aParams},
      PostValues: {
        aAlias: "HelpItem".makeUnique(),
        aName: "Copy of "+aParams.SelectedItem.DisplayName,
        aCopyToPath:"intel\\SystemContentList\\HelpManager",
        aSelectedItemPath: aParams.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues: {
        aMoveToPath:"intel\\SystemReferenceList\\ArchivedHelpItemsList",
        aProductPath: aParams.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  },
  Actions: [
    {
      Id: "General",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        FormUI.Request.GetForm(aParams.Item.ItemPath, 'GeneralHelpDetail', aParams.ContentElement);
        return true;
      }
    }
  ]
};
LiveAdMaker.Options.Languages = {
  CurrentItem: null,
  ContentElement: null,
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details"
    },
    {
      Id: "Terminology",
      DisplayName: "Terminology"
    },
    {
      Id: "MainNav",
      DisplayName: "Main Nav"
    },
    {
      Id: "NavTabs",
      DisplayName: "Nav Tabs"
    },
    {
      Id: "UserInterface",
      DisplayName: "User Interface"
    },
    {
      Id: "Labels",
      DisplayName: "Labels"
    }
  ]
};
LiveAdMaker.Options.Styles = {
  Actions: [
    {
      Id: "StylesDetails",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
         LiveAdMaker.Options.Styles.StylesDetails.init(aParams);
         return true;
      }
    }
  ],
  StylesDetails:{
    init:function(aParams){
      LiveAdMaker.Options.Styles.StylesDetails.CurrentItem = aParams.Item;
      LiveAdMaker.Options.Styles.StylesDetails.ContentContainer = aParams.ContentElement;
      var aAdditionalUrlParams = '&aRowId='+aParams.Item.Id;
      FormUI.Request.getForm(LiveAdMaker.Options.Styles.ItemPath,'StylesFormV2', aParams.ContentElement,aAdditionalUrlParams);
      return true;
    }
  },
  AreaList: null,
  CurrentItem: null,
  ContentElement: null,
  init:function(aParams){
    if (!LiveAdMaker.Options.Styles.CurrentItem||LiveAdMaker.Options.Styles.CurrentItem.Id!=aParams.Item.Id){
        LiveAdMaker.Options.Styles.ContentElement=aParams.ContentElement;
        LiveAdMaker.Options.Styles.CurrentItem=aParams.Item;
    }
    LiveAdMaker.Options.Styles.ContentElement=aParams.ContentElement;
    LiveAdMaker.Options.Styles.SubSection = {};
    LiveAdMaker.Options.Styles.ListParams = aParams;
    LiveAdMaker.Options.Styles.getStyles();
    return true;
  },
  getStyles: function() {
    Ajax.makeRequest({
      URL: URI.pageURL('intel\\SystemReferenceList\\Styles', "GetStyles", null, false),
      Function: LiveAdMaker.Options.Styles.receiveStyles
    });
    return true;
  },
  createNewItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Options.Styles.ItemPath, "CreateNewStyle", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Options", Function:LiveAdMaker.drawSection,Params:aParams},
      PostValues:{
        aUniqueId : "".makeUnique(),
        aDisplayName : "Style"+(LiveAdMaker.Options.Styles.SubItemList.ItemArray.length+1),
        aFont:"Arial",
        aFontSize:"10",
        aLineHeight:"",
        aLetterSpacing:"",
        aFontColor_HEX:"000000",
        aHorizontalAlignment:"left",
        aVerticalAlignment:"top"
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    var zSelectedItem = LiveAdMaker.SelectedSection.Items.get(LiveAdMaker.SelectedSection.List.SelectedItemId);
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Options.Styles.ItemPath, "ArchiveStyle", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues:{
        aStyleId: aParams.SelectedItem.Id
      },
      Method:'POST'
    });
  },
  duplicateItem: function(aParams) {
    var zSelectedItem = LiveAdMaker.Options.Styles.StylesDetails.CurrentItem;
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Options.Styles.ItemPath, "CreateNewStyle", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Options", Function:LiveAdMaker.drawSection,Params:aParams},
      PostValues:{
        aUniqueId : "".makeUnique(),
        aDisplayName : "Style"+(LiveAdMaker.Options.Styles.SubItemList.ItemArray.length+1),
        aFont:(zSelectedItem.Font ? zSelectedItem.Font:""),
        aFontSize: (zSelectedItem.FontSize ? zSelectedItem.FontSize:""),
        aLineHeight: (zSelectedItem.LineHeight ? zSelectedItem.LineHeight:""),
        aLetterSpacing: (zSelectedItem.LetterSpacing ? zSelectedItem.LetterSpacing:""),
        aFontColor_HEX: (zSelectedItem.FontColor_HEX ? zSelectedItem.FontColor_HEX:""),
        aHorizontalAlignment: (zSelectedItem.HorizontalAlignment ? zSelectedItem.HorizontalAlignment:""),
        aVerticalAlignment: (zSelectedItem.VerticalAlignment ? zSelectedItem.VerticalAlignment:""),
        aMinimumFontSize:(zSelectedItem.MinimumFontSize ? zSelectedItem.MinimumFontSize:""),
        aMaximumFontSize:(zSelectedItem.MaximumFontSize ? zSelectedItem.MaximumFontSize:""),
        aPageWidth:(zSelectedItem.PageWidth ? zSelectedItem.PageWidth:""),
        aPageHeight:(zSelectedItem.PageHeight ? zSelectedItem.PageHeight:"")
      },
      Method:'POST'
    });
  },
  receiveStyles: function (aResults) {
    LiveAdMaker.Options.Styles.ItemPath = aResults.ItemPath;
    LiveAdMaker.Options.Styles.FontArray = aResults.Fonts;
    zDrawParams = {
      Section: LiveAdMaker.Options.Styles.ListParams.SectionId,
      SubSection: "Styles",
      ItemId: LiveAdMaker.Options.Styles.ListParams.ItemId,
      ListType: "ActionUI",
      View: "subitem",
      ParentElement: LiveAdMaker.Options.Styles.ContentElement,
      Action: LiveAdMaker.Options.Styles.ListParams.ActionId,
      Id: "StyleList",
      ItemArray: aResults.Items,
      Actions: LiveAdMaker.Options.Styles.Actions,
      Sortable: false,
      ShowNavigation: true,
      OnSortCompleteFunction: LiveAdMaker.sortItems,
      SearchObjectItemPath: "intel\\SystemReferenceList\\Styles"
    };
    var zSubItemList = new List(zDrawParams);
    zSubItemList.draw(zDrawParams);
    LiveAdMaker.Options.Styles.SubItemList = zSubItemList;
    zSubItemList.selectItem(aResults.Items[0].Id, true);
    zSubItemList.selectAction({Action:zSubItemList.Actions[0].Id});
    LiveAdMaker.highlightSelectedSubItemView(zSubItemList, "ActionsWithName");
    LiveAdMaker.resizeInterface(null);
    var zActionParams = {
      Item: aResults.Items[0],
      ItemId: aResults.Items[0].Id,
      Action: zSubItemList.Actions[0],
      ActionId: zSubItemList.Actions[0].Id,
      Section: LiveAdMaker.Options.Styles.ListParams.Section,
      SectionId: LiveAdMaker.Options.Styles.ListParams.SectionId,
      List: zSubItemList,
      ContentElement: zSubItemList.ContentElement
    };
    if(zSubItemList.Actions[0].DisplayFunction) {
      zSubItemList.Actions[0].DisplayFunction(zActionParams);
    }
    else {
      FormUI.Request.GetForm(zActionParams.Item.ItemPath, 'Form'+zSubItemList.Actions[0].Id, zSubItemList.ContentElement);
    }
    return true;
  }
}
LiveAdMaker.Options.Approval = {
  Actions: [
    {
      Id: "ApprovalDetails",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
         LiveAdMaker.Options.Approval.ApprovalDetails.init(aParams);
         return true;
      }
    }
  ],
  ApprovalDetails:{
    init:function(aParams){
      LiveAdMaker.Options.Approval.ApprovalDetails.CurrentItem = aParams.Item;
      LiveAdMaker.Options.Approval.ApprovalDetails.ContentContainer = aParams.ContentElement;
      FormUI.Request.getForm(LiveAdMaker.Options.Approval.ApprovalDetails.CurrentItem.ItemPath,'ApprovalForm', aParams.ContentElement);
      return true;
    }
  },
  AreaList: null,
  CurrentItem: null,
  ContentElement: null,
  init:function(aParams){
    if (!LiveAdMaker.Options.Approval.CurrentItem||LiveAdMaker.Options.Approval.CurrentItem.Id!=aParams.Item.Id){
        LiveAdMaker.Options.Approval.ContentElement=aParams.ContentElement;
        LiveAdMaker.Options.Approval.CurrentItem=aParams.Item;
    }
    LiveAdMaker.Options.Approval.ContentElement=aParams.ContentElement;
    LiveAdMaker.Options.Approval.SubSection = {};
    LiveAdMaker.Options.Approval.ListParams = aParams;
    LiveAdMaker.Options.Approval.getApproval();
    return true;
  },
  getApproval: function() {
    Ajax.makeRequest({
      URL: URI.pageURL("", "GetList", null, false),
      Function: LiveAdMaker.Options.Approval.receiveApproval
    });
    return true;
  },
  createNewItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.Options.Approval.ItemPath, "CreateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Options", Function:LiveAdMaker.drawSection,Params:aParams},
      PostValues:{
        aUniqueId : "".makeUnique(),
        aName : "New Approval",
        aAlias: "Approval"+(LiveAdMaker.Options.Approval.SubItemList.ItemArray.length+1),
        aObjectTypeAlias : "Approval"
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    if(aParams.SelectedItem.ItemPath) {
      var zMoveToPath = "";
      LiveAdMaker.archiveItem(aParams, zMoveToPath)
    }
  },
  duplicateItem: function(aParams) {
    if(aParams.SelectedItem.ItemPath) {
      var zCopyToPath = "";
      LiveAdMaker.duplicateItem(aParams, zCopyToPath, "Approval"+(LiveAdMaker.Options.Approval.SubItemList.ItemArray.length+1), "Copy of "+aParams.SelectedItem.DisplayName)
    }
  },
  receiveApproval: function (aResults) {
    LiveAdMaker.Options.Approval.ItemPath = aResults.ItemPath;
    zDrawParams = {
      Section: LiveAdMaker.Options.Approval.ListParams.SectionId,
      SubSection: "Approval",
      ItemId: LiveAdMaker.Options.Approval.ListParams.ItemId,
      ListType: "ActionUI",
      View: "subitem",
      ParentElement: LiveAdMaker.Options.Approval.ContentElement,
      Action: LiveAdMaker.Options.Approval.ListParams.ActionId,
      Id: "ApprovalList",
      ItemArray: aResults.Items,
      Actions: LiveAdMaker.Options.Approval.Actions,
      Sortable: false,
      ShowNavigation: true,
      OnSortCompleteFunction: LiveAdMaker.sortItems,
      OwnerItemPath: LiveAdMaker.Options.Approval.ItemPath,
      DisabledNavigationArray: [
        {Id: "AddToButton", Disabled: "Y"},
        {Id: "ImportExportButton", Disabled: "Y"},
        {Id: "UndoButton", Disabled: "Y"},
        {Id: "RedoButton", Disabled: "Y"}
      ]
    };
    var zSubItemList = new List(zDrawParams);
    zSubItemList.draw(zDrawParams);
    LiveAdMaker.Options.Approval.SubItemList = zSubItemList;
    zSubItemList.selectItem(aResults.Items[0].Id, true);
    zSubItemList.selectAction({Action:zSubItemList.Actions[0].Id});
    LiveAdMaker.highlightSelectedSubItemView(zSubItemList, "ActionsWithName");
    LiveAdMaker.resizeInterface(null);
    var zActionParams = {
      Item: aResults.Items[0],
      ItemId: aResults.Items[0].Id,
      Action: zSubItemList.Actions[0],
      ActionId: zSubItemList.Actions[0].Id,
      Section: LiveAdMaker.Options.Approval.ListParams.Section,
      SectionId: LiveAdMaker.Options.Approval.ListParams.SectionId,
      List: zSubItemList,
      ContentElement: zSubItemList.ContentElement
    };
    if(zSubItemList.Actions[0].DisplayFunction) {
      zSubItemList.Actions[0].DisplayFunction(zActionParams);
    }
    else {
      FormUI.Request.GetForm(zActionParams.Item.ItemPath, 'Form'+zSubItemList.Actions[0].Id, zSubItemList.ContentElement);
    }
    return true;
  }
};
LiveAdMaker.Options.Support = {
  Actions: [
    {
      Id: "SupportDetails",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
         LiveAdMaker.Options.Support.SupportDetails.init(aParams);
         return true;
      }
    }
  ],
  SupportDetails:{
    init:function(aParams){
      LiveAdMaker.Options.Support.SupportDetails.CurrentItem = aParams.Item;
      LiveAdMaker.Options.Support.SupportDetails.ContentContainer = aParams.ContentElement;
      FormUI.Request.getForm('intel\\SystemReferenceList\\CustomizeSystem','Support', aParams.ContentElement);
      return true;
    }
  }
}
LiveAdMaker.Options.CostCenters = {
  CurrentItem: null,
  ContentElement: null,
  CostCentersItemList: null,
  createNewItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL('intel\\SystemReferenceList\\CostCenterList', "CreateItem", "aObjectTypeAlias=CostCenter", true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Options.CostCenters", Function:LiveAdMaker.drawSection,Params:aParams},
      PostValues:{
        aAlias:"CostCenter".makeUnique(),
        aName:"CostCenter"+LiveAdMaker.Options.CostCenters.SubItemList.ItemArray.length
      },
      Method:'POST'
    });
  },
  duplicateItem: function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: "Settings.CostCenters", Function: LiveAdMaker.drawSection, Params: aParams},
      PostValues: {
        aAlias: "CostCenter".makeUnique(),
        aName: "Copy of "+aParams.SelectedItem.DisplayName,
        aCopyToPath:"intel\\SystemReferenceList\\CostCenterList",
        aSelectedItemPath: aParams.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues: {
        aMoveToPath:"intel\\SystemReferenceList\\ArchivedCostCenterList",
        aProductPath: aParams.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  },  
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        FormUI.Request.GetForm(aParams.Item.ItemPath, 'Details', aParams.ContentElement);
        return true;
      }
    }
  ]
}
LiveAdMaker.Options.MediaGroups = {
  CurrentItem: null,
  ContentElement: null,
  CostCentersItemList: null,
  Actions: [
    {
      Id: "Groups",
      DisplayName: "Groups",
      DisplayFunction: function(aParams){
        FormUI.Request.GetForm(aParams.Item.ItemPath, 'MediaGroups', aParams.ContentElement);
        return true;
      }
    }
  ]
}
    // ---------------------- End Action_LiveAdMaker_Options ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_Products --------------- //
LiveAdMaker.Products = {
  Name: 'Products',
  CurrentItem: null,
  ContentElement: null,
  CollectionItemPath: 'intel\\ContentList\\DigitalAssetLibrary\\ProductCollectionLibrary',
  Load: function(aParams){
    var zSection = LiveAdMaker.Products;
    zSection.SearchParams = {aItemType: 'Product'};
    zSection.SearchCriteriaExtraParams = {aItemType: 'Product'};
    if(!zSection.Items) {
      Ajax.makeRequest({
        URL: URI.pageURL("intel\\ContentList\\ProductList", "GetList", "", true),
        Function: LiveAdMaker.receiveSectionData,
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
    }
    else {
      LiveAdMaker.drawSection(aParams);
    }
    return true;
  },
  draw: function(aResult,aParams){
    LiveAdMaker.Assets.Details.draw(aResult,aParams);
    return true;
  },
  createNewItem: function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL("intel\\ContentList\\ProductList", "CreateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Products", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aObjectTypeAlias: "Product",
        aAlias: "Product".makeUnique(),
        aName: "Product "+LiveAdMaker.SelectedSection.Items.length
      },
      Method:'POST'
    });
  },
  duplicateItem:function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Products", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aAlias:"Product".makeUnique(),
        aCopyToPath:"intel\\ContentList\\ProductList",
        aSelectedItemPath:aParams.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues: {
        aMoveToPath:"intel\\SystemReferenceList\\ArchivedProductList",
        aProductPath: aParams.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        LiveAdMaker.Products.CurrentItem = aParams.Item;
        LiveAdMaker.Products.ContentElement = aParams.ContentElement;
        FormUI.Request.GetForm(aParams.Item.ItemPath, 'ProductDetails', aParams.ContentElement);
        Ajax.makeRequest({
          URL: URI.pageURL(LiveAdMaker.Products.List.SelectedItem.ItemPath,'GetTopAssets'),
          Function: LiveAdMaker.Products.draw,
          Params: aParams,
          Method: 'POST',
          PostValues: {aOutputType:'JSON',aLanguage:URI.User.Language,aLimitResultsTo:'1000'}
        });
        return true;
      }
    },
    {
      Id: "Pricing",
      DisplayName: "Pricing",
      DisplayFunction: function(aParams){
        LiveAdMaker.Products.CurrentItem = aParams.Item;
        LiveAdMaker.Products.ContentElement = aParams.ContentElement;
        LiveAdMaker.Products.Pricing.CurrentItemPath = aParams.Item.ItemPath;
        aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetPricingList", "", true)
        aParams.DisabledNavigationArray = [
          {Id: "AddToButton", Disabled: "Y"},
          {Id: "ImportExportButton", Disabled: "Y"},
          {Id: "ExportButton", Disabled: "Y"},
          {Id: "UndoButton", Disabled: "Y"},
          {Id: "RedoButton", Disabled: "Y"}
        ];
        LiveAdMaker.requestSubItems(aParams);
        return true;
      }
    },
    {
      Id: "Features",
      DisplayName: "Features",
      DisplayFunction: function(aParams){
        LiveAdMaker.Products.CurrentItem = aParams.Item;
        LiveAdMaker.Products.ContentElement = aParams.ContentElement;
        LiveAdMaker.Products.Features.CurrentItemPath = aParams.Item.ItemPath;
        aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetFeaturesList", "", true)
        aParams.DisabledNavigationArray = [
          {Id: "AddToButton", Disabled: "Y"},
          {Id: "ImportExportButton", Disabled: "Y"},
          {Id: "ExportButton", Disabled: "Y"},
          {Id: "UndoButton", Disabled: "Y"},
          {Id: "RedoButton", Disabled: "Y"}
        ];
        LiveAdMaker.requestSubItems(aParams);
        return true;
      }
    },
    {
      Id: "WhyBuys",
      DisplayName: "Why Buys",
      RequestSubItemsURL: '',
      DisplayFunction: function(aParams){
        LiveAdMaker.Products.CurrentItem = aParams.Item;
        LiveAdMaker.Products.ContentElement = aParams.ContentElement;
        aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetList", "aGetWhyBuys=Y&aGetAssets=N", true);
        aParams.DisabledNavigationArray = [
          {Id: "ImportExportButton", Disabled: "Y"},
          {Id: "ExportButton", Disabled: "Y"}
        ];
        LiveAdMaker.requestSubItems(aParams);
        return true;
      }
    },
    {
      Id: "Imagery",
      DisplayName: "Materials",
      DisplayFunction: function(aParams){
        LiveAdMaker.Products.CurrentItem = aParams.Item;
        LiveAdMaker.Products.ContentElement = aParams.ContentElement;
        aParams.DisabledNavigationArray = [
          {Id: "ImportExportButton", Disabled: "Y"},
          {Id: "ExportButton", Disabled: "Y"}
        ];
        aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetAssetList", "", true)
        LiveAdMaker.requestSubItems(aParams);
        return true;
      }
    },
    {
      Id: "Groups",
      DisplayName: "Groups",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Products.Groups.init(aParams);
        return true;
      }
    }
  ]
};
LiveAdMaker.Products.Imagery = {
  CurrentItem: null,
  ContentElement: null,
  AssetList: null,
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Imagery.Details.init(aParams);
        return true;
      }
    },
    {
      Id: "Features",
      DisplayName: "Features",
      DisplayFunction: function(aParams) {
        LiveAdMaker.Products.Imagery.Features.init(aParams);
        return true;
      }
    }
  ],
  getActions: function(){
    return LiveAdMaker.Products.Imagery.Actions;
  },
  draw: function(aParams) {
  },
  archiveItem: function(aParams) {
    LiveAdMaker.Imagery.archiveItem(aParams);
    return true;
  },
  Features: {
    CurrentItem: null,
    ContentElement: null,
    init: function(aParams){
      LiveAdMaker.Products.Imagery.Features.CurrentItem = aParams.Item;
      LiveAdMaker.Products.Imagery.Features.ContentElement = aParams.ContentElement;
      FormUI.Request.getForm(aParams.Item.ItemPath, 'AssetFeatures', aParams.ContentElement, '&aProductPath='+LiveAdMaker.Products.CurrentItem.ItemPath);
      return true;
    }
  },
  drawEditableSortableForm: function(aDataObj, aParams) {
    if (FormUI.ContentElement) var zActionFormUIContent = FormUI.ContentElement;
    var zTopContainer = aParams.TopContainer;
    var zActionNavContainerElement = aParams.ActionNavContainerElement;
    aParams = aParams.Params;
    var zEditableSortableContainer = DOM.createElement("DIV", "Imagery-EditableSortableContainer");
    var zEditable_Position = { Top: "1", Left: "12", Height: "3", Width: "10"}
    var zEditable_LabelPosition = { Top: "1", Left: "2", Height: "3", Width: "15"}
    var aEditable_ElementProperties_ = {
      FieldId: 'ImageryListEditable',
      FieldType: "Selection",
      OptionsArray: [
        {
          DisplayName: 'Yes',
          Id: 'Yes',
          ItemPath: 'Y'
        },
        {
          DisplayName: 'No',
          Id: 'No',
          ItemPath: 'N'
        }
      ],
      DisplayValue: (aDataObj.Editable == 'Y' || aDataObj.Editable == '') ? 'Yes' : 'No',
      Value: aDataObj.Editable,
      DefaultValue: 'Yes',
      LabelID: 'Editable',
      Label: 'Editable',
      SaveFormItemPath: aParams.Item.ItemPath,
      SaveFormType: 'ProductImageryEditableSortable'
    }
    var zEditable_Element = new FormUI.Element("Selection", 'ImageryListEditable', zEditable_Position, zEditable_LabelPosition, aEditable_ElementProperties_);
    zEditable_Element.setPath('.ObjectFlags.Editable_Imagery.Flag1');
    var zEditable_FieldElement = FormUI.createElement(zEditable_Element, zEditableSortableContainer, 'edit', true);
    var zSortable_Position = { Top: "1", Left: "38", Height: "3", Width: "10"}
    var zSortable_LabelPosition = { Top: "1", Left: "27", Height: "3", Width: "15"}
    var aSortable_ElementProperties = {
      FieldId: 'ImageryListSortable',
      FieldType: "Selection",
      OptionsArray: [
        {
          DisplayName: 'Yes',
          Id: 'Yes',
          ItemPath: 'Y'
        },
        {
          DisplayName: 'No',
          Id: 'No',
          ItemPath: 'N'
        }
      ],
      DisplayValue: (aDataObj.Sortable == 'Y' || aDataObj.Sortable == '') ? 'Yes' : 'No',
      Value: aDataObj.Sortable,
      DefaultValue: 'Yes',
      LabelID: 'Sortable',
      Label: 'Sortable',
      SaveFormItemPath: aParams.Item.ItemPath,
      SaveFormType: 'ProductImageryEditableSortable'
    }
    var zSortable_Element = new FormUI.Element("Selection", 'ImageryListEditable', zSortable_Position, zSortable_LabelPosition, aSortable_ElementProperties);
    zSortable_Element.setPath('.ObjectFlags.Sortable_Imagery.Flag1');
    var zSortable_FieldElement = FormUI.createElement(zSortable_Element, zEditableSortableContainer, 'edit', true);
    zTopContainer.insertBefore(zEditableSortableContainer, zActionNavContainerElement);
    if (zActionFormUIContent) FormUI.ContentElement = zActionFormUIContent;
    return true;
  },
  onListDrawFunction: function(aParams) {
    aParams.TopContainer = this.ActionNavContainerElement.parentNode;
    aParams.ActionNavContainerElement = this.ActionNavContainerElement;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetEditableSortableData", "aListType=Imagery", true),
      Function: LiveAdMaker.Products.Imagery.drawEditableSortableForm,
      Params: {Params: aParams,  TopContainer: this.ActionNavContainerElement.parentNode, ActionNavContainerElement: this.ActionNavContainerElement }
    });
    return true;
  }
}
LiveAdMaker.Products.WhyBuys = {
  SortAction: "SortWhyBuys",
  ListOptions: {
    DisplayHierarchy: 'Y'
  },
  draw: function(aParms){
    return true;
  },
  createItem: function(e,aParams) {
    DOM.Dialog.hide();
    var zMakeRequestItemPath = "intel\\ContentList\\DigitalAssetLibrary\\AssetLibrary";
    zMakeRequestItemPath += "\\" + aParams.LibraryAlias;
    Ajax.makeRequest({
      URL: URI.pageURL(zMakeRequestItemPath,"CreateItem",null,true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"WhyBuys", Function:LiveAdMaker.drawSection, Params:aParams.Params},
      PostValues: {
        aObjectTypeAlias: aParams.AssetObjectType,
        aAlias: "WhyBuy".makeUnique(),
        aName: "WhyBuy "+ LiveAdMaker.SelectedSection.Items.length,
        aProductPath: LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  },
  createNewItem: function(aParams) {
    var zCreateAssetContainer = DOM.createElement("div","","CreateAssetContainer","");
    var zCopyLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zCopyLink = DOM.createElement("a","","CreateAssetLink","");
    var zImageLink_Container = DOM.createElement("div","","CreateAssetLinkContainer","");
    var zImageLink = DOM.createElement("a","","CreateAssetLink","");
    zCopyLink_Container.appendChild(zCopyLink);
    zCreateAssetContainer.appendChild(zCopyLink_Container);
    zCopyLink.href = "javascript:void(0)";
    zCopyLink.innerHTML = "WhyBuy Copy"
    DOM.addEvent(zCopyLink, "onclick", LiveAdMaker.Products.WhyBuys.createItem, {AssetObjectType:"WhyBuy", LibraryAlias:"CopyLibrary", Params:aParams});
    zImageLink_Container.appendChild(zImageLink);
    zCreateAssetContainer.appendChild(zImageLink_Container);
    zImageLink.href = "javascript:void(0)";
    zImageLink.innerHTML = "WhyBuy Image"
    DOM.addEvent(zImageLink, "onclick", LiveAdMaker.Products.WhyBuys.createItem, {AssetObjectType:"WhyBuy_Image", LibraryAlias:"ImageryLibrary", Params:aParams});
    DOM.Dialog.show(zCreateAssetContainer,'cursor','What would you like to add?','220','150');
    return true;
  },
  duplicateItem:function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"WhyBuys", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aAlias:"WhyBuy".makeUnique(),
        aSelectedItemPath:aParams.SelectedItem.ItemPath,
        aProductPath: LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues: {
        aMoveToPath:"intel\\SystemReferenceList\\ArchivedWhyBuyList",
        aProductPath: LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath
      },
      Method:'POST'
    });
  },
  drawEditableSortableForm: function(aDataObj, aParams) {
    if (FormUI.ContentElement) var zActionFormUIContent = FormUI.ContentElement;
    var zTopContainer = aParams.TopContainer;
    var zActionNavContainerElement = aParams.ActionNavContainerElement;
    aParams = aParams.Params;
    var zEditableSortableContainer = DOM.createElement("DIV", "WhyBuy-EditableSortableContainer");
    var zEditable_Position = { Top: "1", Left: "12", Height: "3", Width: "10"}
    var zEditable_LabelPosition = { Top: "1", Left: "2", Height: "3", Width: "15"}
    var aEditable_ElementProperties_ = {
      FieldId: 'WhyBuyListEditable',
      FieldType: "Selection",
      OptionsArray: [
        {
          DisplayName: 'Yes',
          Id: 'Yes',
          ItemPath: 'Y'
        },
        {
          DisplayName: 'No',
          Id: 'No',
          ItemPath: 'N'
        }
      ],
      DisplayValue: (aDataObj.Editable == 'Y' || aDataObj.Editable == '') ? 'Yes' : 'No',
      Value: aDataObj.Editable,
      DefaultValue: 'Yes',
      LabelID: 'Editable',
      Label: 'Editable',
      SaveFormItemPath: aParams.Item.ItemPath,
      SaveFormType: 'ProductEditableSortable'
    }
    var zEditable_Element = new FormUI.Element("Selection", 'WhyBuyListEditable', zEditable_Position, zEditable_LabelPosition, aEditable_ElementProperties_);
    zEditable_Element.setPath('.ObjectFlags.Editable_WhyBuys.Flag1');
    var zEditable_FieldElement = FormUI.createElement(zEditable_Element, zEditableSortableContainer, 'edit', true);
    var zSortable_Position = { Top: "1", Left: "38", Height: "3", Width: "10"}
    var zSortable_LabelPosition = { Top: "1", Left: "27", Height: "3", Width: "15"}
    var aSortable_ElementProperties = {
      FieldId: 'WhyBuyListSortable',
      FieldType: "Selection",
      OptionsArray: [
        {
          DisplayName: 'Yes',
          Id: 'Yes',
          ItemPath: 'Y'
        },
        {
          DisplayName: 'No',
          Id: 'No',
          ItemPath: 'N'
        }
      ],
      DisplayValue: (aDataObj.Sortable == 'Y' || aDataObj.Sortable == '') ? 'Yes' : 'No',
      Value: aDataObj.Sortable,
      DefaultValue: 'Yes',
      LabelID: 'Sortable',
      Label: 'Sortable',
      SaveFormItemPath: aParams.Item.ItemPath,
      SaveFormType: 'ProductEditableSortable'
    }
    var zSortable_Element = new FormUI.Element("Selection", 'WhyBuyListEditable', zSortable_Position, zSortable_LabelPosition, aSortable_ElementProperties);
    zSortable_Element.setPath('.ObjectFlags.Sortable_WhyBuys.Flag1');
    var zSortable_FieldElement = FormUI.createElement(zSortable_Element, zEditableSortableContainer, 'edit', true);
    zTopContainer.insertBefore(zEditableSortableContainer, zActionNavContainerElement);
    if (zActionFormUIContent) FormUI.ContentElement = zActionFormUIContent;
    return true;
  },
  onListDrawFunction: function(aParams) {
    aParams.TopContainer = this.ActionNavContainerElement.parentNode;
    aParams.ActionNavContainerElement = this.ActionNavContainerElement;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetEditableSortableData", "aListType=WhyBuys", true),
      Function: LiveAdMaker.Products.WhyBuys.drawEditableSortableForm,
      Params: {Params: aParams,  TopContainer: this.ActionNavContainerElement.parentNode, ActionNavContainerElement: this.ActionNavContainerElement }
    });
    return true;
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        FormUI.Request.GetForm(aParams.Item.ItemPath, 'ProductWhyBuyDetails', aParams.ContentElement);
        return true;
      }
    },
    {
      Id: "Features",
      DisplayName: "Features",
      DisplayFunction: function(aParams){
        FormUI.Request.getForm(aParams.Item.ItemPath, 'AssetFeatures', aParams.ContentElement, '&aProductPath='+LiveAdMaker.Products.CurrentItem.ItemPath);
        return true;
      }
    }
   ]
};
LiveAdMaker.Products.Pricing = {
  CurrentItemPath: null,
  SelectedAction: "Details",
  SortAction: "SortPricingTypes",
  createNewItem: function(aParams) {
    var zMakeRequestItemPath = "intel\\SystemReferenceList\\ProductPricingTypeList";
    Ajax.makeRequest({
      URL: URI.pageURL(zMakeRequestItemPath,"CreateItem",null,true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Pricing", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aObjectTypeAlias: "ProductPricingType",
        aAlias: "PricingType".makeUnique(),
        aName: "PricingType "+ (LiveAdMaker.SelectedSection.Pricing.List.ItemArray.length + 1)
      },
      Method:'POST'
    });
  },
  duplicateItem:function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Pricing", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aAlias:"Pricing".makeUnique(),
        aName: aParams.SelectedItem.DisplayName + " copy",
        aSelectedItemPath:aParams.SelectedItem.ItemPath,
        aProductPath: LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath,
        aCopyComplete_OwnerObjectReference: "fThis_Object^Owner"
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues: {
        aMoveToPath: "intel\\SystemReferenceList\\ArchivedProductPricingTypeList"
      },
      Method:'POST'
    });
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        FormUI.Request.getForm(aParams.Item.ItemPath, 'Details', aParams.ContentElement, '&aProductPath='+LiveAdMaker.Products.Pricing.CurrentItemPath);
        return true;
      }
    }
  ],
  drawEditableSortableForm: function(aDataObj, aParams) {
    if (FormUI.ContentElement) var zActionFormUIContent = FormUI.ContentElement;
    var zTopContainer = aParams.TopContainer;
    var zActionNavContainerElement = aParams.ActionNavContainerElement;
    aParams = aParams.Params;
    var zEditableSortableContainer = DOM.createElement("DIV", "Pricing-EditableSortableContainer");
    var zEditable_Position = { Top: "1", Left: "12", Height: "3", Width: "10"}
    var zEditable_LabelPosition = { Top: "1", Left: "2", Height: "3", Width: "15"}
    var aEditable_ElementProperties_ = {
      FieldId: 'PricingListEditable',
      FieldType: "Selection",
      OptionsArray: [
        {
          DisplayName: 'Yes',
          Id: 'Yes',
          ItemPath: 'Y'
        },
        {
          DisplayName: 'No',
          Id: 'No',
          ItemPath: 'N'
        }
      ],
      DisplayValue: (aDataObj.Editable == 'Y' || aDataObj.Editable == '') ? 'Yes' : 'No',
      Value: aDataObj.Editable,
      DefaultValue: 'Yes',
      LabelID: 'Editable',
      Label: 'Editable',
      SaveFormItemPath: aParams.Item.ItemPath,
      SaveFormType: 'ProductPricingEditableSortable'
    }
    var zEditable_Element = new FormUI.Element("Selection", 'PricingListEditable', zEditable_Position, zEditable_LabelPosition, aEditable_ElementProperties_);
    zEditable_Element.setPath('.ObjectFlags.Editable_Pricing.Flag1');
    var zEditable_FieldElement = FormUI.createElement(zEditable_Element, zEditableSortableContainer, 'edit', true);
    var zSortable_Position = { Top: "1", Left: "38", Height: "3", Width: "10"}
    var zSortable_LabelPosition = { Top: "1", Left: "27", Height: "3", Width: "15"}
    var aSortable_ElementProperties = {
      FieldId: 'PricingListSortable',
      FieldType: "Selection",
      OptionsArray: [
        {
          DisplayName: 'Yes',
          Id: 'Yes',
          ItemPath: 'Y'
        },
        {
          DisplayName: 'No',
          Id: 'No',
          ItemPath: 'N'
        }
      ],
      DisplayValue: (aDataObj.Sortable == 'Y' || aDataObj.Sortable == '') ? 'Yes' : 'No',
      Value: aDataObj.Sortable,
      DefaultValue: 'Yes',
      LabelID: 'Sortable',
      Label: 'Sortable',
      SaveFormItemPath: aParams.Item.ItemPath,
      SaveFormType: 'ProductPricingEditableSortable'
    }
    var zSortable_Element = new FormUI.Element("Selection", 'PricingListEditable', zSortable_Position, zSortable_LabelPosition, aSortable_ElementProperties);
    zSortable_Element.setPath('.ObjectFlags.Sortable_Pricing.Flag1');
    var zSortable_FieldElement = FormUI.createElement(zSortable_Element, zEditableSortableContainer, 'edit', true);
    zTopContainer.insertBefore(zEditableSortableContainer, zActionNavContainerElement);
    if (zActionFormUIContent) FormUI.ContentElement = zActionFormUIContent;
    return true;
  },
  onListDrawFunction: function(aParams) {
    aParams.TopContainer = this.ActionNavContainerElement.parentNode;
    aParams.ActionNavContainerElement = this.ActionNavContainerElement;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetEditableSortableData", "aListType=Pricing", true),
      Function: LiveAdMaker.Products.Pricing.drawEditableSortableForm,
      Params: {Params: aParams,  TopContainer: this.ActionNavContainerElement.parentNode, ActionNavContainerElement: this.ActionNavContainerElement }
    });
    return true;
  }
}
LiveAdMaker.Products.Features = {
  CurrentItemPath: null,
  SelectedAction: "Details",
  SortAction: "SortFeatures",
  createNewItem: function(aParams) {
    var zMakeRequestItemPath = "intel\\SystemReferenceList\\FeatureList";
    Ajax.makeRequest({
      URL: URI.pageURL(zMakeRequestItemPath,"CreateItem",null,true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Features", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aObjectTypeAlias: "IndustryManager_Feature",
        aAlias: "Feature".makeUnique(),
        aName: "Feature "+ (LiveAdMaker.SelectedSection.Features.List.ItemArray.length + 1)
      },
      Method:'POST'
    });
  },
  duplicateItem:function(aParams) {
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section:"Features", Function:LiveAdMaker.drawSection, Params:aParams},
      PostValues: {
        aAlias:"Feature".makeUnique(),
        aName: aParams.SelectedItem.DisplayName + " copy",
        aSelectedItemPath:aParams.SelectedItem.ItemPath,
        aProductPath: LiveAdMaker.SelectedSection.List.SelectedItem.ItemPath,
        aCopyComplete_OwnerObjectReference: "fThis_Object^Owner"
      },
      Method:'POST'
    });
  },
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues: {
        aMoveToPath: "intel\\SystemReferenceList\\ArchivedFeatureList"
      },
      Method:'POST'
    });
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        FormUI.Request.getForm(aParams.Item.ItemPath, 'Details', aParams.ContentElement, '&aProductPath='+LiveAdMaker.Products.Features.CurrentItemPath);
        return true;
      }
    }
  ],
  drawEditableSortableForm: function(aDataObj, aParams) {
    if (FormUI.ContentElement) var zActionFormUIContent = FormUI.ContentElement;
    var zTopContainer = aParams.TopContainer;
    var zActionNavContainerElement = aParams.ActionNavContainerElement;
    aParams = aParams.Params;
    var zEditableSortableContainer = DOM.createElement("DIV", "Features-EditableSortableContainer");
    var zEditable_Position = { Top: "1", Left: "12", Height: "3", Width: "10"}
    var zEditable_LabelPosition = { Top: "1", Left: "2", Height: "3", Width: "15"}
    var aEditable_ElementProperties_ = {
      FieldId: 'FeaturesListEditable',
      FieldType: "Selection",
      OptionsArray: [
        {
          DisplayName: 'Yes',
          Id: 'Yes',
          ItemPath: 'Y'
        },
        {
          DisplayName: 'No',
          Id: 'No',
          ItemPath: 'N'
        }
      ],
      DisplayValue: (aDataObj.Editable == 'Y' || aDataObj.Editable == '') ? 'Yes' : 'No',
      Value: aDataObj.Editable,
      DefaultValue: 'Yes',
      LabelID: 'Editable',
      Label: 'Editable',
      SaveFormItemPath: aParams.Item.ItemPath,
      SaveFormType: 'ProductFeaturesEditableSortable'
    }
    var zEditable_Element = new FormUI.Element("Selection", 'FeaturesListEditable', zEditable_Position, zEditable_LabelPosition, aEditable_ElementProperties_);
    zEditable_Element.setPath('.ObjectFlags.Editable_Features.Flag1');
    var zEditable_FieldElement = FormUI.createElement(zEditable_Element, zEditableSortableContainer, 'edit', true);
    var zSortable_Position = { Top: "1", Left: "38", Height: "3", Width: "10"}
    var zSortable_LabelPosition = { Top: "1", Left: "27", Height: "3", Width: "15"}
    var aSortable_ElementProperties = {
      FieldId: 'FeaturesListSortable',
      FieldType: "Selection",
      OptionsArray: [
        {
          DisplayName: 'Yes',
          Id: 'Yes',
          ItemPath: 'Y'
        },
        {
          DisplayName: 'No',
          Id: 'No',
          ItemPath: 'N'
        }
      ],
      DisplayValue: (aDataObj.Sortable == 'Y' || aDataObj.Sortable == '') ? 'Yes' : 'No',
      Value: aDataObj.Sortable,
      DefaultValue: 'Yes',
      LabelID: 'Sortable',
      Label: 'Sortable',
      SaveFormItemPath: aParams.Item.ItemPath,
      SaveFormType: 'ProductFeaturesEditableSortable'
    }
    var zSortable_Element = new FormUI.Element("Selection", 'FeaturesListEditable', zSortable_Position, zSortable_LabelPosition, aSortable_ElementProperties);
    zSortable_Element.setPath('.ObjectFlags.Sortable_Features.Flag1');
    var zSortable_FieldElement = FormUI.createElement(zSortable_Element, zEditableSortableContainer, 'edit', true);
    zTopContainer.insertBefore(zEditableSortableContainer, zActionNavContainerElement);
    if (zActionFormUIContent) FormUI.ContentElement = zActionFormUIContent;
    return true;
  },
  onListDrawFunction: function(aParams) {
    aParams.TopContainer = this.ActionNavContainerElement.parentNode;
    aParams.ActionNavContainerElement = this.ActionNavContainerElement;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath, "GetEditableSortableData", "aListType=Features", true),
      Function: LiveAdMaker.Products.Features.drawEditableSortableForm,
      Params: {Params: aParams,  TopContainer: this.ActionNavContainerElement.parentNode, ActionNavContainerElement: this.ActionNavContainerElement }
    });
    return true;
  }
};
LiveAdMaker.Products.Groups = {
  init: function(aParams) {
    FormUI.Request.getForm(aParams.Item.ItemPath, 'Groups', aParams.ContentElement);
    return true;
  }
}
    // ---------------------- End Action_LiveAdMaker_Products ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_Customers --------------- //
LiveAdMaker.Customers = {
  Name: "Customers",
  EditableMembers: true,
  ListOptions: {
    DisplayHierarchy: 'Y'
  },
  Load: function(aParams) {
    aParams.DisabledNavigationArray = [
      {Id: "AddToButton", Disabled: "Y"},
      {Id: "ImportExportButton", Disabled: "N"},
      {Id: "ExportButton", Disabled: "Y"},
    ];
    var zSection = LiveAdMaker.Customers;
    if(!zSection.Items) {
      Ajax.makeRequest({
        URL: URI.pageURL(URI.User.CompanyItemPath+"\\ContentList\\Contacts\\CustomerGroupList", "GetList", null, true),
        Function: LiveAdMaker.receiveSectionData,
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
    }
    else {
      LiveAdMaker.drawSection(aParams);
    }
    return true;
  },
  requestChildNodes: function(e, aRequestParams) {
    LiveAdMaker.requestChildNodes(aRequestParams, "", "", "")
  },
  Actions: [
    {
      Id: "Info",
      DisplayName: "Info",
      DisplayFunction: function(aParams){
        LiveAdMaker.Customers.CurrentItem=aParams.Item;
        LiveAdMaker.Customers.ContentContainer=aParams.ContentElement;
        FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'Info', aParams.ContentElement, '', '');
        return true;
      }
    },
    {
      Id: "Details",
      DisplayName: "Details",
      DisplayFunction: function(aParams){
        LiveAdMaker.Customers.CurrentItem=aParams.Item;
        LiveAdMaker.Customers.ContentContainer=aParams.ContentElement;
        FormUI.Request.getBaseTypeForm(aParams.Item.ItemPath, 'Details', aParams.ContentElement, '', '');
        return true;
      }
    },
    {
      Id: "Assets",
      DisplayName: "Assets",
      DisplayFunction: function(aParams){
        LiveAdMaker.Customers.CurrentItem=aParams.Item;
        LiveAdMaker.Customers.ContentContainer=aParams.ContentElement;
        FormUI.Request.getForm(aParams.Item.ItemPath, 'Assets', aParams.ContentElement, '', '');
        return true;
      }
    },
    {
      Id: "Groups",
      DisplayName: "Layout",
      DisplayFunction: function(aParams){
        LiveAdMaker.Customers.CurrentItem=aParams.Item;
        LiveAdMaker.Customers.ContentContainer=aParams.ContentElement;
        FormUI.Request.getForm(aParams.Item.ItemPath, 'Groups', aParams.ContentElement, '', '');
        return true;
      }
    }
  ],
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Params: aParams,
      PostValues: {
        aMoveToPath: URI.User.CompanyItemPath+'\\MainObjectList\\CustomerList\\ArchivedItemList'
      },
      Method: 'POST'
    });
  },
  createNewItem: function(aParams) {
    LiveAdMaker.showNewBaseItemDialog(aParams, aParams.SelectedItem.ItemPath, "Customer");
    return true
  },
  importexportSectionItem:function(aParams){
    var zBaseImportDialogContainer = DOM.createElement("div","BaseImportDialogContainer");
    var zBaseImportDialog = DOM.Dialog.showForm(zBaseImportDialogContainer,"center","Import",400,400,"NewImportFile",LiveAdMaker.SelectedSection.CurrentItem.ItemPath);
    return true
  },
  updateFileSubmitDetails : function(aParams,aResults){
    var zUploadFileElement = FormUI.ElementArray[2];
    zUploadFileElement[aParams.Element.FieldId] = aParams.Element.Value;
  }
}
    // ---------------------- End Action_LiveAdMaker_Customers ----------------- //
    // ---------------------- Begin Action_LiveAdMaker_LocalCampaigns --------------- //
LiveAdMaker.LocalCampaigns = {};
      // ---------------------- Begin Action_LiveAdMaker_LocalCampaigns_Main --------------- //
LiveAdMaker.LocalCampaigns = {
  Name: "Campaigns",
  DefaultView: "ActionsWithThumbnail",
  ResetItems: false,
  Load: function(aParams){
    aParams.DisabledNavigationArray = [
        {Id: "DuplicateButton", Disabled: "Y"},
      {Id: "NewButton", Disabled: "Y"},
      {Id: "AddToButton", Disabled: "Y"}
    ];
    var zSection = LiveAdMaker.LocalCampaigns;
    zSection.SearchObjectItemPath = URI.User.ItemPath+"\\ContentList\\CampaignDraftList";
    if(!zSection.Items || zSection.ResetItems) {
      Ajax.makeRequest({
        URL: URI.pageURL(unescape('intel\\ContentList\\CampaignList'), "RequestLocalCampaigns", "aObjectTypeAlias=CampaignDraftList", true),
        Function: LiveAdMaker.receiveSectionData,
        Title: "Loading Local Campaigns",
        Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams}
      });
    }
    else {
      LiveAdMaker.drawSection(aParams);
    }
    return true;
  },
  draw: function(aParams){
    return true;
  },
  duplicateItem:function(aParams){
    var zTestMePlease = false;
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "DuplicateItem", null, true),
      Function: LiveAdMaker.receiveNewItem,
      Params: {Section: aParams.Section, Function: LiveAdMaker.drawSection, Params: aParams},
      Title: "Creating Duplicate",
      PostValues: {
        aAlias: aParams.SelectedItem.Id.makeUnique(),
        aName: "Copy of " + aParams.SelectedItem.DisplayName,
        aSelectedItemPath: aParams.SelectedItem.ItemPath,
        aCopyToPath: URI.User.ItemPath +'\\ContentList\\CampaignDraftList'
      },
      Method:'POST'
    });
    return true;
  },
  archiveItem:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.SelectedItem.ItemPath, "ArchiveItem", null, true),
      Function: LiveAdMaker.receiveArchiveItem,
      Title: "Archiving",
      Params: aParams,
      PostValues:{
        aMoveToPath:URI.User.ItemPath +'\\ContentList\\ArchivedCampaignDraftList'
      },
      Method:'POST'
    });
  },
  Actions: [
    {
      Id: "Details",
      DisplayName: "Details"
        ,
        DisplayFunction: function(aParams){
          
  LiveAdMaker.LocalCampaigns.getOrderStatus(aParams);
  var zFormParams = {
    OnDisplayFunction:LiveAdMaker.LocalCampaigns.Details.getTopAssets,
    OnDisplayParams:aParams
  }
  FormUI.Request.getForm(aParams.Item.ItemPath, 'FormDetails', aParams.ContentElement,'',zFormParams);

          return true;
        }
    }
    ,
    {
      Id: "Offers",
      DisplayName: "My Systems"
        ,
        DisplayFunction: function(aParams){
          
  LiveAdMaker.LocalCampaigns.getOrderStatus(aParams);
  aParams.URL = URI.pageURL(URI.User.CompanyItemPath + '\\ContentList\\OfferList',"GetList", "aExcludeItems=Y&aExclusionListLocation=" + aParams.Item.ItemPath, true);
  LiveAdMaker.requestSubItems(aParams);

          return true;
        }
    }
    ,
    {
      Id: "Customize",
      DisplayName: "Customize"
        ,
        DisplayFunction: function(aParams){
          
      LiveAdMaker.LocalCampaigns.getOrderStatus(aParams);
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.Item.ItemPath, "GetVersion", null, true),
        Function: LiveAdMaker.LocalCampaigns.Customize.receiveVersion,
        Params: aParams
      });
    
          return true;
        }
    }
    ,
    {
      Id: "Media",
      DisplayName: "Media"
        ,
        DisplayFunction: function(aParams){
          
  LiveAdMaker.LocalCampaigns.getOrderStatus(aParams);
  LiveAdMaker.LocalCampaigns.Media.init(aParams);

          return true;
        }
    }
    ,
    {
      Id: "Build",
      DisplayName: "Preview"
        ,
        DisplayFunction: function(aParams){
          
  LiveAdMaker.LocalCampaigns.getOrderStatus(aParams);
  LiveAdMaker.LocalCampaigns.Build.init(aParams);

          return true;
        }
    }
    ,
    {
      Id: "Pay",
      DisplayName: "Checkout"
        ,
        DisplayFunction: function(aParams){
          
  LiveAdMaker.LocalCampaigns.getOrderStatus(aParams);
  LiveAdMaker.LocalCampaigns.Pay.init(aParams);

          return true;
        }
    }
    ,
    {
      Id: "",
      DisplayName: ""
    }
  ],
  exportSectionItem: function(aParams){
    var zBuiltAdsArray = [];
    LiveAdMaker.LocalCampaigns.Build.CurrentItem.TrafficArray.forEach(function(aInsertion){
      if (aInsertion.Active&&aInsertion.Active=='Y'&&aInsertion.InsertionPath&&aInsertion.InsertionPath!=''&&aInsertion.PreviewURL&&aInsertion.PreviewURL!=''){
        if(aInsertion.Removed&&aInsertion.Removed=='Y'){
        }else{
          zBuiltAdsArray.set(aInsertion,aInsertion.Id);
        }
      }
    });
    var zExportTextContainer = DOM.createElement("div","ExportDiv","","text-align:center\;padding:3px\;");
    if (zBuiltAdsArray.length>0){
      zExportTextContainer.innerHTML = "<img src=\"\/l.c.bin\/I\/912\/Export.gif\" border=0> <a href=\"javascript: void(0)\;\">Export materials to FTP site</a>";
      zExportTextContainer.onclick = function() {
        LiveAdMaker.LocalCampaigns.exportAssetsToFTP(zExportTextContainer, aParams);
      }
    }else{
      zExportTextContainer.innerHTML = "<img src=\"\/l.c.bin\/I\/912\/Export.gif\" border=0> At least one ad must either be previewed or built before you can export.";
    }
    DOM.Dialog.show(zExportTextContainer,'center','Export','175','');
    return true;
  },
  exportAssetsToFTP: function(aDialogContainer, aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(LiveAdMaker.LocalCampaigns.Build.CurrentItem.ItemPath,'CreatePreviewFTPAccount'),
      Function: LiveAdMaker.LocalCampaigns.confirmAssetsExport,
      Params: {DialogContainer: aDialogContainer, Params: aParams},
      Method: 'POST'
    });
    return true;
  },
  confirmAssetsExport: function(aResults, aParams){
    var zExportTextContainer = aParams.DialogContainer;
    if (aResults && aResults.Success && isTrue(aResults.Success)){
      if (parseFloat(aResults.FailedUploads) > 0 && parseFloat(aResults.FailedUploads) < parseFloat(aResults.TotalFiles)){
        zExportTextContainer.innerHTML = aResults.ResponseText;
        zExportTextContainer.innerHTML += "You will be sent an email with FTP information to download all of the assets from this order.";
      } else {
        zExportTextContainer.innerHTML = "You will be sent an email with FTP information to download all of the assets from this order.";
      }
    }else{
      if (parseFloat(aResults.FailedUploads) > 0 && parseFloat(aResults.FailedUploads) >= parseFloat(aResults.TotalFiles)){
        zExportTextContainer.innerHTML = aResults.ResponseText;
        zExportTextContainer.innerHTML += "There was an error creating the FTP account. Please contact LiveAdMaker support.";
      } else {
        zExportTextContainer.innerHTML = "There was an error creating the FTP account. Please contact LiveAdMaker support.";
      }
    }
    return true;
  },
  getOrderStatus: function(aParams){
    if (aParams.Item.OrderStatus&&(aParams.Item.OrderStatus=="Pending"||aParams.Item.OrderStatus=="Completed"||aParams.Item.OrderStatus=="Cancelled"||aParams.Item.OrderStatus=="Active"||aParams.Item.OrderStatus=="Fulfilled")){
      var zResetCampaignTextContainer = DOM.createElement("div","ResetCampaignDiv","","text-align:center\;padding:6px\;");
      zResetCampaignTextContainer.innerHTML = "<a href=\"javascript: void(0)\;\">Run a new copy of this campaign</a>";
      zResetCampaignTextContainer.onclick = function() {
        LiveAdMaker.LocalCampaigns.resetLocalCampaign(zResetCampaignTextContainer, aParams);
      }
      DOM.Dialog.show(zResetCampaignTextContainer,'center','Order Checked Out','225','');
    }
    return true;
  },
  resetLocalCampaign: function(aDialogContainer, aParams){
    var zResetCampaignTextContainer = aDialogContainer;
    zResetCampaignTextContainer.innerHTML = "Reloading Campaigns";
    if (aParams.Item.AutoCompleteOrder&&aParams.Item.AutoCompleteOrder=='Y'){
      var aParams = {DialogContainer: aDialogContainer, Params: aParams};
      var aResults = {Success: 'Y'};
      LiveAdMaker.LocalCampaigns.confirmResetLocalCampaign(aResults, aParams)
    }else{
      Ajax.makeRequest({
        URL: URI.pageURL(aParams.Item.ItemPath,'UpdateOrderStatus'),
        Function: LiveAdMaker.LocalCampaigns.confirmResetLocalCampaign,
        Params: {DialogContainer: aDialogContainer, Params: aParams},
        PostValues:{
          aNewStatus: "Fulfilled",
          aOutputCreateNewCopyJSON: "Y",
          aSendNotificationEmail: "N"
        },
        Method: 'POST'
      });
    }
    return true;
  },
  confirmResetLocalCampaign: function(aResults, aParams){
    var zResetCampaignTextContainer = aParams.DialogContainer;
    if (aResults && aResults.Success && isTrue(aResults.Success)){
      zResetCampaignTextContainer.innerHTML = "Reloading Campaigns";
      LiveAdMaker.LocalCampaigns.List=null;
      LiveAdMaker.LocalCampaigns.Items=null;
      URI.goToHash('Section=LocalCampaigns&Action=Details');
    }else{
      zResetCampaignTextContainer.innerHTML = "There was an error resetting the campaign. Please contact LivaAdMaker Support.";
    }
    return true;
  }
};
LiveAdMaker.LocalCampaigns.Details = {
  getTopAssets:function(aParams){
    Ajax.makeRequest({
      URL: URI.pageURL(aParams.Item.ItemPath,'GetTopAssets','aOutputType=JSON&aLanguage='+URI.User.Language,true),
      Function: LiveAdMaker.LocalCampaigns.Details.drawTopAssets,
      Title: "Getting top assets",
      Params: aParams,
      Method: 'GET'
    });
  },
  drawTopAssets: function(aResult,aParams){
    if (aResult&&parseInt(aResult.TotalResults)>0){
      if (LiveAdMaker.matchCurrentHashValues(aParams)) {
        aParams.ShowViewLinksOnly="Y";
        LiveAdMaker.Assets.Details.draw(aResult,aParams);
      }
    }
    return true;
  }
}
LiveAdMaker.LocalCampaigns.People = {
  DealerList: null,
  CurrentItem: null,
  ContentElement: null,
  draw: function(aParams) {
    return true;
  },
  init: function(aParams) {
    aParams.URL = URI.pageURL(URI.User.CompanyItemPath+"\\ContentList\\People\\PeopleList", "GetList", null, true);
    aParams.DisabledNavigationArray = [
      {Id: "NewButton", Disabled: "Y"},
      {Id: "AddToButton", Disabled: "Y"},
      {Id: "DuplicateButton", Disabled: "Y"},
      {Id: "ArchiveButton", Disabled: "Y"},
      {Id: "ImportExportButton", Disabled: "Y"},
      {Id: "ExportButton", Disabled: "Y"},
      {Id: "UndoButton", Disabled: "Y"},
      {Id: "RedoButton", Disabled: "Y"}
    ];
    aParams.Sortable = true;
    LiveAdMaker.requestSubItems(aParams);
    return true;
  },
  getActions: function(){
    return LiveAdMaker.People.Actions;
  }
};
LiveAdMaker.LocalCampaigns.Offers = {
  ProductList: null,
  CurrentItem: null,
  ContentElement: null,
  getActions: function(){
    return LiveAdMaker.Offers.Actions;
  },
  setOfferSort: function(aSelect){
    Ajax.makeRequest({
      URL: URI.appendToURL(URI.pageURL(URI.User.CompanyItemPath + '\\ContentList\\OfferList',"UpdateRanks", null, true), "aProducts="+aSelect.SortSelect_NewOrder),
      Function: LiveAdMaker.LocalCampaigns.Offers.receiveProductSort
    });
    return true;
  },
  receiveProductSort: function(aResults){
    return true;
  },
  Assets: {
    DisplayFunction: function(aParams) {
      aParams.SectionId   = "LocalCampaigns";
      aParams.ActionId    = "Offers";
      aParams.SubActionId = "Assets";
      LiveAdMaker.Offers.getEditableSortableData('Imagery', 'LiveAdMaker.LocalCampaigns.Offers.Assets.init', aParams);
      return true;
    },
    init: function(aParams) {
      aParams.URL = URI.pageURL(aParams.Item.ItemPath, "GetAssetList", "aGetWhyBuys=Y&aGetAssets=Y", true);
      aParams.TripleBubble = true;
      LiveAdMaker.requestTripleBubbleItems(aParams);
      return true;
    }
  }
};
LiveAdMaker.LocalCampaigns.ServiceOffers = {
  ProductList: null,
  CurrentItem: null,
  ContentElement: null,
  getActions: function(){
    return LiveAdMaker.ServiceOffers.Actions;
  },
  setOfferSort: function(aSelect){
    Ajax.makeRequest({
      URL: URI.appendToURL(URI.pageURL(URI.User.CompanyItemPath + '\\ContentList\\ServiceOfferList',"UpdateRanks", null, true), "aServices="+aSelect.SortSelect_NewOrder),
      Function: LiveAdMaker.LocalCampaigns.ServiceOffers.receiveServiceSort
    });
    return true;
  },
  receiveServiceSort: function(aResults){
    return true;
  }
};
LiveAdMaker.LocalCampaigns.LocalContent = {
  ContentList: null,
  CurrentItem: null,
  ContentElement: null,
  getActions: function(){
    return LiveAdMaker.LocalContent.Actions;
  },
  setOfferSort: function(aSelect){
    Ajax.makeRequest({
      URL: URI.appendToURL(URI.pageURL(URI.User.CompanyItemPath + '\\ContentList\\ContentOfferList',"UpdateRanks", null, true), "aContents="+aSelect.SortSelect_NewOrder),
      Function: LiveAdMaker.LocalCampaigns.LocalContent.receiveContentSort
    });
    return true;
  },
  receiveContentSort: function(aResults){
    return true;
  }
};
LiveAdMaker.LocalCampaigns.Customize = {
  CurrentItem: null,
  ContentElement: null,
  Lightbox: null,
  init: function (aParams) {
    LiveAdMaker.LocalCampaigns.Customize.ContentElement=aParams.ContentElement;
    LiveAdMaker.LocalCampaigns.Customize.CurrentItem=aParams.Item;
    LiveAdMaker.LocalCampaigns.Customize.Params=aParams;
    DOM.replaceContent(LiveAdMaker.LocalCampaigns.Customize.ContentElement,'')
    var zNewInsertion = '';
    var zFormParams = {
      OnDisplayFunction:LiveAdMaker.LocalCampaigns.Customize.setContainers,
      OnDisplayParams:zNewInsertion
    }
    FormUI.Request.getForm(aParams.Item.ItemPath, 'Customize', LiveAdMaker.LocalCampaigns.Customize.ContentElement,'', zFormParams);
    var zExtraParams = DOM.createElement('input','inpSortOrder');
    zExtraParams.name = 'inpSortOrder';
    zExtraParams.value = 'top';
    zExtraParams.type = 'hidden';
    LiveAdMaker.LocalCampaigns.Customize.ContentElement.appendChild(zExtraParams);
    return true;
  },
  getLightboxUploadElement: function( aLightbox_Element, aIsLabel ) {
    var zForm = aLightbox_Element.Form;
    var zElementArray = zForm.ElementArray.get( aLightbox_Element.FieldId + "_Upload", "FieldId");
    if ( zElementArray[0] ) {
      var zElementId = ( aIsLabel ) ? "label-" + zElementArray[0].ElementId : zElementArray[0].ElementId;
      return $( zElementId );
    } else {
      return false;
    }
  },
  lightboxHideNormal: function(aParams) {
    if (LiveAdMaker.LocalCampaigns.Customize.Lightbox.Container) {
      if (!aParams)
        var aParams = LiveAdMaker.LocalCampaigns.Customize.Lightbox.Params;
      DOM.removeClass(LiveAdMaker.LocalCampaigns.Customize.Lightbox.Container,'Show');
      DOM.addClass(LiveAdMaker.LocalCampaigns.Customize.Lightbox.Container,'Hide');
      if ($("dvLightBoxContainer_"+aParams.Element.ElementId)) {
        $("dvLightBoxContainer_"+aParams.Element.ElementId).style.display = 'none';
        LiveAdMaker.LocalCampaigns.Customize.ContentElement.appendChild($("dvLightBoxContainer_"+aParams.Element.ElementId));
      }
      var zContainer = $(aParams.Element.ElementId);
      var zUploadContainer = LiveAdMaker.LocalCampaigns.Customize.getLightboxUploadElement( aParams.Element );
      if (zContainer)
        zContainer.style.zIndex = 100;
      if (zUploadContainer)
        zUploadContainer.style.zIndex = 100;
      LiveAdMaker.LocalCampaigns.Customize.Lightbox.Container = null;
      DOM.Dialog.Container = null;
    }
    return true;
  },
  lightboxHide: function() {
    if (LiveAdMaker.LocalCampaigns.Customize.Lightbox.Container) {
      DOM.removeClass(LiveAdMaker.LocalCampaigns.Customize.Lightbox.Container,'Show');
      DOM.addClass(LiveAdMaker.LocalCampaigns.Customize.Lightbox.Container,'Hide');
      var aParams = LiveAdMaker.LocalCampaigns.Customize.Lightbox.Params;
      if ($("dvLightBoxContainer_"+aParams.Element.ElementId)) {
        $("dvLightBoxContainer_"+aParams.Element.ElementId).style.display = 'none';
        LiveAdMaker.LocalCampaigns.Customize.ContentElement.appendChild($("dvLightBoxContainer_"+aParams.Element.ElementId));
      }
      var zElementParams = [];
      zElementParams.Container = aParams.Element.ElementId;
      zElementParams.Element = aParams.Element;
      zElementParams.Input = aParams.Element;
      zElementParams.OriginalDisplay = aParams.Element.DisplayValue;
      zElementParams.Original = zElementParams.Input.value;
      var zContainer = $(zElementParams.Container);
      var zUploadContainer = $(zElementParams.Container+"_Upload");
      if (zUploadContainer)
        zUploadContainer.style.zIndex = 100;
      var zLabel = $('label-'+aParams.Element.ElementId);
      if (zContainer) {
        zContainer.style.zIndex = 100;
        DOM.addClass(zContainer, 'FormUI-Editable');
        if (!DOM.Browser.isSafari) {
          DOM.removeEvent(zContainer,"onclick",FormUI.Draw.timeoutEditElement,{Container:zElementParams.Container,Element:zElementParams.Element});
          DOM.addEvent(zContainer,"onclick",FormUI.Draw.timeoutEditElement,{Container:zElementParams.Container,Element:zElementParams.Element});
        } else {
          setTimeout(function(){DOM.addEvent(zContainer,"onclick",FormUI.Draw.timeoutEditElement,{Container:zElementParams.Container,Element:zElementParams.Element});},0)
        }
        zContainer.innerHTML = zElementParams.OriginalDisplay;
        DOM.addEvent(zContainer, "onmouseover", FormUI.Hover.mouseOver, zContainer);
        DOM.addEvent(zContainer, "onmouseout", FormUI.Hover.mouseOut, zContainer);
      }
      if (zLabel) {
        DOM.addEvent(zLabel,"onclick",FormUI.Draw.timeoutEditElement,{Container:zElementParams.Container,Element:zElementParams.Element});
        DOM.addEvent(zLabel, "onmouseover", FormUI.Hover.mouseOver, zContainer);
        DOM.addEvent(zLabel, "onmouseout", FormUI.Hover.mouseOut, zContainer);
      }
      LiveAdMaker.LocalCampaigns.Customize.Lightbox.Container = null;
      DOM.Dialog.Container = null;
    }
    return true;
  },
  displayLightBoxView: function(aPar