﻿// JScript File
//Ajax functions
function ajax() { }
ajax.prototype.requestSync = _ajaxRequestSync;
ajax.prototype.requestASync = _ajaxRequestASync;
ajax.prototype.requestAsyncForUrl = _ajaxRequestAsyncForUrl
function _ajaxGetReqObj() {
    var lObj = new Object(false);

    if (window.ActiveXObject) {
        try { lObj = new ActiveXObject("Msxml2.XMLHTTP") }
        catch (e) {
            try { lObj = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) { }
        }
    } else if (window.XMLHttpRequest) {
        lObj = new XMLHttpRequest();
        if (lObj.overrideMimeType) {
            lObj.overrideMimeType('text/xml');
        }
    }
    return lObj
}
function _getUrlForAjaxCall(clientControlId, functionName) {
    var url = document.location.href
    url = window.ContensisControlsNamespace.Utilities.RemoveHashFromUrl(url)
    var parts = url.split('?');
    if (window.ContensisControlsNamespace.Utilities.EndsWith(url, "/")) {
        url += "default.aspx"
    }
    else {
        if (window.ContensisControlsNamespace.Utilities.EndsWith(parts[0], "/")) {
            parts[0] += 'default.aspx';
            url = parts.join('?');
        }
    }
    url = window.ContensisControlsNamespace.Utilities.AppendQueryToUrl(url, "AjaxID", clientControlId)
    url = window.ContensisControlsNamespace.Utilities.AppendQueryToUrl(url, "function", functionName)

    var regEx = new RegExp('&DialogueID=', 'gi');
    if (!regEx.exec(url)) // check to see if dialogue is already set
    {
        var hiddenDialogueID = document.getElementById('DialogueID');
        if (hiddenDialogueID) {
            url = window.ContensisControlsNamespace.Utilities.AppendQueryToUrl(url, 'DialogueID', hiddenDialogueID.value);
        }
    }
    if (typeof (jQuery) != 'undefined') {
        jQuery('[GlobalAjaxParam]').each(function() {
            var paramName = jQuery(this).attr('GlobalAjaxParam');
            if (paramName) {
                var paramValue = jQuery(this).val();
                if (paramValue) {
                    url = window.ContensisControlsNamespace.Utilities.AppendQueryToUrl(url, paramName, paramValue);
                }
            }
        });
    }
    return url;
}

function _ajaxRequestSync(clientControlId, functionName, nvCollection, callBack) {
    var lReq = _ajaxGetReqObj();
    if (!lReq) {
        alert('An XMLHTTP instance could not be created.');
    } else {
            var url = _getUrlForAjaxCall(clientControlId, functionName);

            lReq.open('POST', url, false);
            lReq.send(nvCollection.toXML());
            if (lReq.readyState == 4) {
                if (lReq.status == 200) {
                    if (lReq.responseText.indexOf("<?xml") == 0) {
                        var nvc = new nameValueCollection(lReq.responseText)
                        var ClientScript = nvc.item('ClientScript')
                        if (ClientScript.value.length > 0) {
                            //Append the script to the page.....
                            window.ContensisControlsNamespace.Utilities.AddBodyScript(ClientScript.value)
                        }
                        if (callBack) {
                            callBack(nvc);
                        } else {
                            return nvc;
                        }
                    } else {
                        //this is probably because of session timeout...
                        var nvc = new nameValueCollection()
                        nvc.add('ErrorCode', '1')
                        nvc.add('ErrorMessage', 'There was a problem with the request. The response returned was invalid, this could be caused by a session timeout, please refresh and re-login if neccecary.')
                        return nvc
                    }
                } else {
                    var nvc = new nameValueCollection()
                    nvc.add('ErrorCode', '1')
                    nvc.add('ErrorMessage', 'There was a problem with the request. This could be caused by a loss of network connectivity.')
                    return nvc
                }
        }
    }
}

function _ajaxRequestASync(clientControlId, functionName, nvCollection, callBack, context) {
    var lReq = _ajaxGetReqObj();
    if (!lReq) { alert('An XMLHTTP instance could not be created.'); }
    else {
        var callbackArgs = [];
        if (arguments.length > 5) {
            callbackArgs[0] = null;
            for (var i = 5; i < arguments.length; i++) {
                callbackArgs[callbackArgs.length] = arguments[i];
            }
        }
        var url = _getUrlForAjaxCall(clientControlId, functionName);
        lReq.open('POST', url, true);
        lReq.send(nvCollection.toXML());
        lReq.onreadystatechange = function() {
            if (lReq.readyState == 4) {
                if (lReq.status == 200) {
                    if (lReq.responseText.indexOf("<?xml") == 0) {
                        var nvc = new nameValueCollection(lReq.responseText);
                        if (typeof (callBack) != 'undefined') {
                            if (callbackArgs.length > 0) {
                                callbackArgs[0] = nvc;
                                callBack.apply(context, callbackArgs);
                            }
                            else {
                                callBack.call(context, nvc);
                            }
                        }
                    }
                }
            }
        }
    }
}

function _ajaxRequestAsyncForUrl(Url, callBack) {
    var lReq = _ajaxGetReqObj();
    if (!lReq) {
        alert('An XMLHTTP instance could not be created.');
    } else {
        lReq.open('GET', Url, true);
        lReq.setRequestHeader("Content-Type", "application/json; charset=utf-8")
        lReq.send(null)
    }
}


//Global Functions to be moved to new JS

function _Global() {
    this.CurrentProjectID = 49
    this.Utils = window.ContensisControlsNamespace.Utilities
    this.Popups = new nameValueCollection()
    this.PopupCount = Math.ceil(Math.random() * 1000); // 0
    this.Overlay = null
    this.CurrentModal = null
    this.Resources = new nameValueCollection();
    this.LostSessionDocuments = new Array();
}
_Global.prototype.ajax = new ajax();
_Global.prototype.StartModal = _StartModal
_Global.prototype.EndModal = _EndModal
_Global.prototype.LaunchAuditTrail = _LaunchAuditTrail
_Global.prototype.InformationDialogue = _InformationDialogue
_Global.prototype.LaunchPopupCenter = _LaunchPopupCenter
_Global.prototype.LaunchPopup = _LaunchPopup
_Global.prototype.LaunchModalDialogue = _LaunchModalDialogue
_Global.prototype.LaunchDialogue = _LaunchDialogue
_Global.prototype.LaunchFolderProperties = _LaunchFolderProperties
_Global.prototype.Helpers = new _Helpers()
_Global.prototype.ErrorDialogue = ErrorDialogue
_Global.prototype.LaunchStandardAjaxDialogue = _Global_LaunchStandardAjaxDialogue
_Global.prototype.Preview = _Preview
_Global.prototype.Preview_CompletePreview = _Preview_CompletePreview
_Global.prototype.DualView = _DualView;
_Global.prototype.OpenInViewer = _OpenInViewer
_Global.prototype.OpenDialogueInViewer = _Global_OpenDialogueInViewer
_Global.prototype.Viewer = _Viewer
_Global.prototype.CurrentDialogueType = _Global_CurrentDialogueType
_Global.prototype.CurrentDialogueTypeIsCmsEditor = _Global_CurrentDialogueTypeIsCmsEditor
_Global.prototype.HandleToolItemClick = _Global_HandleToolItemClick
_Global.prototype.GetWindowSize = _Global_GetWindowSize
_Global.prototype.CheckUI = _Global_CheckUI
_Global.prototype.LogOut = _Global_LogOut
_Global.prototype.HandleUserInterfaceContentActionButton = _Global_HandleUserInterfaceContentActionButton
_Global.prototype.ExecuteUserInterfaceContentActionButton = _Global_ExecuteUserInterfaceContentActionButton
_Global.prototype.LaunchContentEditor = _Global_LaunchContentEditor
_Global.prototype.LaunchQAReport = _Global_LaunchQAReport
_Global.prototype.CheckIn = _Global_CheckIn
_Global.prototype.ReloadViewer = _Global_ReloadViewer
_Global.prototype.AddOnLoad = _Global_AddOnLoad
_Global.prototype.SetParentIframeAndUI = _Global_SetParentIframeAndUI
_Global.prototype.LaunchDialogeFromDialogueButton = _Global_LaunchDialogeFromDialogueButton
_Global.prototype.GetDialogueUrl = _Global_GetDialogueUrl
_Global.prototype.LaunchPopupDialogue = _Global_LaunchPopupDialogue
_Global.prototype.ExecutePopupClose = _Global_ExecutePopupClose
_Global.prototype.HandlePopupClose = _Global_HandlePopupClose
_Global.prototype.LaunchModalDialogueWithCallback = _LaunchModalDialogueWithCallback
_Global.prototype.LaunchModalDialogueWithCallbackAndWindowOptions = _LaunchModalDialogueWithCallbackAndWindowOptions
_Global.prototype.IsUIInstance = _Global_IsUIInstance
_Global.prototype.HandleModalCallback = _Global_HandleModalCallback
_Global.prototype.SetKeyValueQuery = _Global_SetKeyValueQuery
_Global.prototype.MakeAjaxRequest = _Global_MakeAjaxRequest
_Global.prototype.MakeASyncAjaxRequest = _Global_MakeASyncAjaxRequest
_Global.prototype.PersistNameValueCollectionToSession = _Global_PersistNameValueCollectionToSession
_Global.prototype.GetAnchors = _Global_GetAnchors
_Global.prototype.GetAjaxAnchors = _Global_GetAjaxAnchors
_Global.prototype.GetResourceAsString = _Global_GetResourceAsString;
_Global.prototype.GetLabelResourceAsString = _Global_GetLabelResourceAsString;
_Global.prototype.GetContentID = _Global_GetContentID
_Global.prototype.FormatString = _Global_FormatString
_Global.prototype.CheckSession = _Global_CheckSession
_Global.prototype.GetContentInformationHtml = _Global_GetContentInformationHtml
_Global.prototype.LaunchModalDialogueWithCallbackFromUrl = _Global_LaunchModalDialogueWithCallbackFromUrl
_Global.prototype.HandleMetaTreeTextboxFocus = _Global_HandleMetaTreeTextboxFocus
_Global.prototype.HandleFolderPropertyTreeTextboxFocus = _Global_HandleFolderPropertyTreeTextboxFocus
_Global.prototype.HandleMetaUrlTextboxFocus = _Global_HandleMetaUrlTextboxFocus
_Global.prototype.RevertToVersion = _Global_RevertToVersion
_Global.prototype.LaunchAuditTrailDialogueAsPopup = _Global_LaunchAuditTrailDialogueAsPopup
_Global.prototype.ExecuteRevertToVersion = _Global_ExecuteRevertToVersion
_Global.prototype.SetPreviewPage = _Global_SetPreviewPage
_Global.prototype.GetPath = _Global_GetPath
_Global.prototype.ApproveDeclineContent = _Global_ApproveDeclineContent
_Global.prototype.LaunchPropagateDialog = _Global_LaunchPropagateDialog
_Global.prototype.RepublishFolder = _Global_RepublishFolder
_Global.prototype.KillSession = _Global_KillSession
_Global.prototype.SessionLost = _Global_SessionLost
_Global.prototype.SessionLostOnLoad = _Global_SessionLostOnLoad
_Global.prototype.ClearInvalidLostSessionDocuments = _Global_ClearInvalidLostSessionDocuments
_Global.prototype.UpdateUiTreeNode = _Global_UpdateUiTreeNode
_Global.prototype.UpdateEditorState = _Global_UpdateEditorState
_Global.prototype.LaunchUnarchiveDialogue = _Global_LaunchUnarchiveDialogue;
_Global.prototype.ImageSelected = _Global_ImageSelected;

_Global.prototype.PopupLoginButtonClick = _Global_PopupLoginButtonClick
_Global.prototype.UpdateUserProject = _Global_UpdateUserProject;
_Global.prototype.MultiplePublish = _Global_MultiplePublish;

function _Global_MultiplePublish(buttonID, imageID, messageID, completeButtonText, completeImage, completeMessage, data) {
    var requestCount = data.length;
    $j(new Image()).load(function() {
    }).error(function() {
    }).attr('src', completeImage);
    
    for (var i = 0, ilen = data.length; i < ilen; i++) {
        var querystring = 'contentversionid=' + data[i].ContentVersionID
                + '&contentid=' + data[i].ContentID
                + '&contenttypeid=' + data[i].ContentTypeID
                + '&serverid=' + data[i].ServerID
                + '&runningdebugmode=False'
                + '&previewpagecontentversionid=0'
                + '&dualviewing=False';
        $j.ajax({
            type: 'GET',
            dataType: 'html',
            url: '/Publish.axd',
            data: querystring,
            error: function(xhr, status, exception) {
                requestCount -= 1;
                if (requestCount <= 0) {
                    $j('#' + buttonID).attr('disabled', false);
                    $j('#' + messageID).text(completeMessage);
                }
            },
            success: function(data, status) {
                requestCount -= 1;
                if (requestCount <= 0) {
                    $j('#' + buttonID).val(completeButtonText).attr('disabled', false);
                    $j('#' + imageID).attr('src', completeImage);
                    $j('#' + messageID).text(completeMessage);
                }
            }
        });
    }
}

function _Global_UpdateUiTreeNode(ContentId, ContentMode) {
    if (top.window.ContensisControlsNamespace.TreeviewNavigator) {
        top.window.ContensisControlsNamespace.TreeviewNavigator.UpdateNode(ContentId, ContentMode)
    }
}
function _Global_KillSession() {
    var ReturnNVC = this.MakeAjaxRequest('KillSession', new nameValueCollection());
}
function _Global_SessionLostOnLoad(e) {
    ContensisControlsNamespace.Global.SessionLost(false, document)
}
function _Global_SessionLost(AjaxRequest, Document, NV, topitem) {
    if (topitem) {
        if (!AjaxRequest) {
            this.LostSessionDocuments[this.LostSessionDocuments.length] = Document;
        }
        this.StartModal()

        //Add the Login Screen over the top....
        this.PopupLogin = document.getElementById("contensis_popup_login");
        this.PopupLoginPassword = document.getElementById("contensis_popup_login_password");
        this.PopupLoginErrorMessage = document.getElementById("contensis_popup_errorcontainer");
        if (this.PopupLoginErrorMessage) {
            window.ContensisUtility.setInnerHTML(this.PopupLoginErrorMessage, "");
        }

        if (this.PopupLogin) {
            this.PopupLogin.style.display = "block";
            this.PopupLoginPassword.focus();
            this.PopupLoginPassword.select();
        }
    } else {
        if (top.window.ContensisControlsNamespace.Global) {
            top.window.ContensisControlsNamespace.Global.SessionLost(AjaxRequest, Document, NV, true)
            if (top.window.ContensisControlsNamespace.Utilities.IsPopup()) {
                ResizeModal(350)
            }
        } else {
            ContensisControlsNamespace.Global.SessionLost(AjaxRequest, Document, NV, true)
            ResizeModal(300)
        }

    }

}

function _Global_RepublishFolder(folderid, preventConfirmation) {
    if (preventConfirmation) {
        var nv = new nameValueCollection();
        nv.add('FolderID', folderid);
        var ReturnNVC = this.MakeAjaxRequest('RepublishFolder', nv);
        //show any errors etc....
        //window.ContensisControlsNamespace.Global.LaunchStandardAjaxDialogue(returnNvc)
    } else {
        var callBackItem = new CallBackItem();
        callBackItem.CallbackContext = this;
        callBackItem.CallbackID = 'RepublishFolderConfirm';
        callBackItem.FolderID = folderid
        this.LaunchModalDialogueWithCallback(callBackItem, 71, 450, 100, 'ErrorMessage', 'Are you sure you wish to republish the folder?', 'ErrorType', '2', 'ErrorTitle', 'Confirm')
    }
}
function _Global_PopupLoginButtonClick(obj) {
    var Nvc = new nameValueCollection()
    Nvc.add("password", this.PopupLoginPassword.value)
    var Rnvc = this.MakeAjaxRequest('PopupLogin', Nvc);
    this.PopupLoginPassword.value = ""
    //Clear the password box
    if (Rnvc.item("LoginResult")) {
        var result = Rnvc.item("LoginResult").value
        if (result == 0) {
            this.PopupLogin.style.display = "none";
            this.EndModal()
            this.ClearInvalidLostSessionDocuments();
            if (this.LostSessionDocuments.length > 0) {
                for (var i = 0; i < this.LostSessionDocuments.length; i++) {
                    //this.LostSessionDocuments[i].location.reload();
                    this.LostSessionDocuments[i].location.href = ContensisControlsNamespace.Utilities.AppendQueryToUrl(this.LostSessionDocuments[i].location.href, "Randomiser", Math.floor(Math.random() * 1000001))
                }
            }
        } else {
            if (result == 2) {
                alert("Password Change Required. Redirecting to main login screen.")
                document.location.reload();
            } else {
                window.ContensisUtility.setInnerHTML(this.PopupLoginErrorMessage, Rnvc.item("LoginResultText").value);
            }
        }
    }

    window.ContensisControlsNamespace.Utilities.KillEvent(Object);
    return false;
}

function _Global_ClearInvalidLostSessionDocuments() {
    for (var i = 0; i < this.LostSessionDocuments.length; i++) {

    }
    var remArr = new Array();

    for (var i = 0; i < this.LostSessionDocuments.length; i++) {
        try {
            var test = this.LostSessionDocuments[i].location.href;
        }
        catch (e) {
            remArr[remArr.length] = i;
        }
    }
    for (var i = remArr.length - 1; i > -1; i--) {
        this.LostSessionDocuments.splice(remArr[i], 1)
        //alert('removing:' + i)
    }
}

function _Global_MakeAjaxRequest(Action, NameValueCollection) {
    var returnNvc = this.ajax.requestSync('Global_Ajax', Action, NameValueCollection);
    this.LaunchStandardAjaxDialogue(returnNvc);
    return returnNvc;
}

function _Global_MakeASyncAjaxRequest(Action, NameValueCollection, func, context) {
    var args = [];
    args[args.length] = 'Global_Ajax';
    for (var i = 0; i < arguments.length; i++) {
        args[args.length] = arguments[i];
    }
    this.ajax.requestASync.apply(this.ajax, args);
    //this.ajax.requestASync('Global_Ajax', Action, NameValueCollection, func, context);
}

function _Global_PersistNameValueCollectionToSession(NameValueCollection) {
    var ReturnNVC = this.MakeAjaxRequest('PersistNameValueCollection', NameValueCollection)
    return ReturnNVC.item('guid').value
}
function _Global_GetContentInformationHtml(ContentID, WorkflowType, DisplayType, ContentVersionID) {
    var nv = new nameValueCollection();
    nv.add('WorkflowType', WorkflowType);
    nv.add('ContentID', ContentID);
    nv.add('DisplayType', DisplayType);
    nv.add('ContentVersionID', ContentVersionID);

    var ReturnNVC = this.MakeAjaxRequest('ContentInformation', nv)
    return ReturnNVC.item('Html').value
}

function _Global_HandleModalCallback(CallbackID, Callback, PopupItem) {
    var returnVal = PopupItem.ReturnValue
    if (CallbackID == 'preview') {
        this.Preview_CompletePreview()
    }
    if (CallbackID == 'logoutconfirm') {
        if (returnVal.toLowerCase() == 'yes') {
            this.LogOut(true, true)
        } else {
            this.LogOut(false, true)
        }
    }
    if (CallbackID == 'RevertToVersionConfirm') {
        if (returnVal.toLowerCase() == 'yes') {
            this.ExecuteRevertToVersion(Callback)
        } else {
            //do nothing...
        }
    }
    if (CallbackID == 'RepublishFolderConfirm') {
        if (returnVal.toLowerCase() == 'yes') {
            this.RepublishFolder(Callback.FolderID, true)
        } else {
            //do nothing...
        }
    }
    if (CallbackID == 'ApproveContent') {
        if (returnVal.toLowerCase() == 'yes') {
            this.ApproveDeclineContent(Callback.contentId, Callback.contentTypeId, Callback.workflowType, true, true);
        }
    }
    if (CallbackID == 'SendDeclineMessage') {
        if (returnVal.toLowerCase() == 'messagesent') {
            var url = this.GetDialogueUrl(3, 80, "ContentFilterType", 9)
            return this.OpenInViewer(url);
        } else {

        }
    }
    if (CallbackID == 'Unarchive') {
        if (returnVal.toLowerCase() == 'yes') {
            var unarchiveController = new UnarchiveController(Callback.ContentId, Callback.WorkflowType);
            unarchiveController.Unarchive();
        }
    }
}
function _Global_IsUIInstance() {
    if (this.Viewer() != null) {
        return true;
    } else {
        return false;
    }
}
function _Global_SetParentIframeAndUI(object) {
    object.ParentIframe = null
    if (document.frames) {//ie
        object.ParentIframe = document.frames.frameElement
    } else {
        object.ParentIframe = window.frameElement
    }
    window.ContensisUtility.RegisterHTMLProperty(object, 'ParentIframe');

    if (top.window.ContensisControlsNamespace.UserInterface) {
        object.ParentUI = top.window.ContensisControlsNamespace.UserInterface
        if (typeof (object.OnResize) == 'function') {
            object.ParentUI.AddAfterResizeHandler(object);
        }
        object.____Exists = function() { return true; };
    }
    object.HasParentIfameTabset = false
    if (object.ParentIframe) {
        if (object.ParentIframe.TabSet) {
            object.HasParentIfameTabset = true
            object.HasTabset = true
            object.ParentIfameTabset = object.ParentIframe.TabSet
            if (object.OnShow) {
                object.ParentIframe.TabSet.AddAfterTabShowHandler(object)
            }
        }
        if (object.ParentIframe.SplitScreen) {
            object.HasParentIfameSplitScreen = true
            object.HasSplitScreen = true
        }
    }
}
function _Global_AddOnLoad(functionitem) {
    // for Mozilla browsers
    if (document.addEventListener) {
        document.addEventListener("DOMContentLoaded", functionitem, false);
    } else {
        //For IE
        window.onload = functionitem
    }

}

function _Global_HandleUserInterfaceContentActionButton(contentid, workflowType, ContentTypeID, Action, ServerId, QAWebpageId, controlid, selectedTabIndex) {
    if (top) {
        if (top.window.ContensisControlsNamespace) {
            if (top.window.ContensisControlsNamespace.Global) {
                top.window.ContensisControlsNamespace.Global.ExecuteUserInterfaceContentActionButton(contentid, workflowType, ContentTypeID, Action, ServerId, QAWebpageId, controlid, selectedTabIndex);
                return;
            }
        }
    }
    this.ExecuteUserInterfaceContentActionButton(contentid, workflowType, ContentTypeID, Action, ServerId, QAWebpageId, controlid, selectedTabIndex);
}

function _Global_ExecuteUserInterfaceContentActionButton(contentid, workflowType, ContentTypeID, Action, ServerId, QAWebpageId, controlid, selectedTabIndex) {
    if (Action == 'Edit') {
        this.LaunchContentEditor(contentid, workflowType, ContentTypeID);
    }
    if (Action == 'Info') {
        this.InformationDialogue(contentid, workflowType);
    }
    if (Action == 'Checkin') {
        this.CheckIn(contentid, workflowType, ContentTypeID);
        //this.ReloadViewer();
    }
    if (Action == 'Preview') {
        this.Preview(contentid, 0, ContentTypeID, true, 1);
        //this.ReloadViewer();
    }
    if (Action == 'QAReport') {
        this.LaunchQAReport(contentid, ServerId, workflowType, QAWebpageId, selectedTabIndex);
    }
    if (Action == 'Unarchive') {
        this.LaunchUnarchiveDialogue(contentid, workflowType);
    }
    if (Action == 'RevokeAndEdit') {
        this.LaunchContentEditor(contentid, workflowType, ContentTypeID, null, true);
    }
    return false;
}
function _Global_ReloadViewer() {
    this.OpenInViewer(this.Viewer().src)
}
function _Global_CheckIn(ContentID, WorkflowType, ContentTypeID, node) {
    var nv = new nameValueCollection();
    nv.add('WorkflowType', WorkflowType);
    nv.add('ContentTypeID', ContentTypeID);
    nv.add('ContentID', ContentID);
    top.window.ContensisControlsNamespace.TreeviewNavigator.NodeCheckIn(null, null, nv)
}

function _Global_LaunchContentEditor(contentID, WorkflowType, ContentTypeID, node, doRevoke) {
    if (typeof (ContentTypeID) == 'undefined') {
        ContentTypeID = -1
    }
    var ContentIdObj = new ContentID(contentID, WorkflowType, ContentTypeID)
    top.window.ContensisControlsNamespace.TreeviewNavigator.SubNodeEditClick(null, ContentIdObj, doRevoke)
}
function _Global_LaunchQAReport(contentID, ServerID, WorkflowType, QAWebpageId, selectedTabIndex) {
    var url = this.GetDialogueUrl(4, 115, "ServerID", ServerID, "QualityAssuranceWebpageID", QAWebpageId, "ContentID", contentID, "WorkflowType", WorkflowType, "SelectedTabIndex", selectedTabIndex)

    var windowOpenOptions = new WindowOpenOptions(800, 600, null, null)
    windowOpenOptions.resizable = 1
    windowOpenOptions.scrollbars = 0
    windowOpenOptions.status = 0
    windowOpenOptions.toolbar = 0

    return this.LaunchPopupCenter(url, windowOpenOptions, null, false)
}
function _Global_GetWindowSize() {
    var winWidth = 0, winHeight = 0;
    //check for modal windows....
    //try added as window.external.dialogueHeight behaving weirdly in some browsers....
    try {
        if (window.external) {
            if (window.external.dialogHeight) {
                //we must be in a modal...
                winWidth = window.external.dialogWidth.substring(0, window.external.dialogWidth.length - 2);
                winHeight = window.external.dialogHeight.substring(0, window.external.dialogHeight.length - 2);
                if (!window.ContensisControlsNamespace.Browser.IsIE7OrAbove) {
                    if (window.ContensisControlsNamespace.Browser.IsIE) {
                        winHeight = winHeight - 30
                    }
                }
                return [winWidth, winHeight];
            }
        }
    } catch (e) { }
    if (typeof (window.innerWidth) == 'number') {
        winWidth = window.innerWidth;
        winHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        winWidth = document.documentElement.clientWidth;
        winHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        winWidth = document.body.clientWidth;
        winHeight = document.body.clientHeight;
    }
    return [winWidth, winHeight];
}

function _StartModal() {
    if (ContensisControlsNamespace.Utilities.IsPopup()) {
        this.Utils.ShowFullScreenOverlay()
    } else {
        top.window.ContensisControlsNamespace.Utilities.ShowFullScreenOverlay()
    }
}

function _EndModal() {
    if (ContensisControlsNamespace.Utilities.IsPopup()) {
        this.Utils.HideFullScreenOverlay()
    } else {
        top.window.ContensisControlsNamespace.Utilities.HideFullScreenOverlay()
    }

}
function _Viewer() {
    return document.getElementById(this.GlobalUiID + '_Viewer')
}
function _OpenInViewer(Url, backbutton, isPreview) {
    if (typeof (backbutton) == 'undefined') {
        backbutton = false;
    }
    if (isPreview) {
        this.Viewer().setAttribute('scrolling', 'yes');
    }
    else {
        this.Viewer().setAttribute('scrolling', 'no');
    }
    var qs = new QueryStringObject(Url);
    var dialogType = qs.item('DialogueType');
    if (dialogType) {
        this.Viewer().setAttribute('DialogueType', dialogType.value);
    }
    else {
        this.Viewer().removeAttribute('DialogueType');
    }
    this.Viewer().src = Url
}

function _Global_CurrentDialogueType() {
    var result = this.Viewer().getAttribute('DialogueType');
    return result;
}

function _Global_CurrentDialogueTypeIsCmsEditor() {
    var dialogType = this.CurrentDialogueType();
    var result = false;
    if (dialogType) {
        if (dialogType == '79') {
            result = true;
        }
    }
    return result;
}

function _Global_OpenDialogueInViewer(dialogueID) {
    var Url = this.GetDialogueUrl(1, dialogueID);
    this.OpenInViewer(Url);
}

function _Global_LogOut(CheckInContent, ForceLogout) {
    if (typeof (CheckInContent) == 'undefined') {
        CheckInContent = false
    }
    if (typeof (ForceLogout) == 'undefined') {
        ForceLogout = false
    }
    if (this.CheckUI) {
        var NameValueCollection = new nameValueCollection();
        if (CheckInContent) {
            NameValueCollection.add('CheckInContent', 'true');
        } else {
            NameValueCollection.add('CheckInContent', 'false');
        }
        if (ForceLogout) {
            NameValueCollection.add('ForceLogout', 'true');
        } else {
            NameValueCollection.add('ForceLogout', 'false');
        }
        var returnNvc = window.ContensisControlsNamespace.Global.ajax.requestSync(this.GlobalUiID + '_Ajax', 'LogOut', NameValueCollection);
        if (returnNvc.item('errorCode').value == 2) {
            var callBackItem = new CallBackItem();
            callBackItem.CallbackContext = this;
            callBackItem.CallbackID = 'logoutconfirm';
            this.ErrorDialogue(returnNvc.item('errorCode').value, returnNvc.item('errorMessage').value, returnNvc.item('ErrorTitle').value, callBackItem);
        } else {
            document.location.href = this.Utils.AppendQueryToUrl(document.location.href, "logoff", "true")
            //document.location.reload()
        }
    }
}
function _Global_CheckUI() {
    if (this.GlobalUiID) {
        return true;
    } else {
        alert('No UI Available...');
        return false;
    }
}

function _Global_HandleLogout(SuccessUrl, SuccessKeys) {
    //are we in a popup?

}
function _Preview(ContentID, ContentVersionID, ContentTypeID, Popup, ServerStatus, initDualView, dualviewiframe, DoDualview, isSiteMigrationMode, previewMaster) {
    if (this.CheckUI) {
        //this happens to tell the publisher to publish the current edit version if applicable and then jump
        //to the dual view screen rather than the actual item...
        if (initDualView) {
            this.initDualView = true
        } else {
            this.initDualView = false
        }
        var DualViewing = false
        if (dualviewiframe) {
            //this is for dual view screen
            this.dualviewiframe = dualviewiframe
            DualViewing = true
        } else {
            this.dualviewiframe = null
            if (DoDualview) {
                DualViewing = true
            } else {
                DualViewing = false
            }

        }
        isSiteMigrationMode = !!isSiteMigrationMode;
        previewMaster = !!previewMaster;

        this.PreviewPopup = Popup
        this.PreviewContentID = ContentID
        this.PreviewContentTypeID = ContentTypeID

        var NameValueCollection = new nameValueCollection();
        NameValueCollection.add('ContentID', ContentID);
        NameValueCollection.add('ContentVersionID', ContentVersionID);
        NameValueCollection.add('ContentTypeID', ContentTypeID);
        NameValueCollection.add('Popup', Popup);
        NameValueCollection.add('ServerType', ServerStatus);
        NameValueCollection.add('DualViewing', DualViewing);
        NameValueCollection.add('IsSiteMigrationMode', isSiteMigrationMode);
        NameValueCollection.add('PreviewMaster', previewMaster);

        var returnNvc = null;

        returnNvc = window.ContensisControlsNamespace.Global.MakeAjaxRequest('Preview', NameValueCollection);


        var LaunchedDialogue = ContensisControlsNamespace.Global.LaunchStandardAjaxDialogue(returnNvc, null)
        if (!LaunchedDialogue) {
            //Do Whatever
            var url = returnNvc.item('url')
            var LaunchPublisher = returnNvc.item('LaunchPublisher')
            this.PreviewUrl = url.value

            if (typeof (LaunchPublisher) != 'undefined') {
                if (LaunchPublisher.value == 'true') {
                    var publisherLaunchUrl = "/publish.axd" + this.Helpers.ConvertNvToQuerystring(returnNvc)

                    var windowOpenOptions = new WindowOpenOptions(400, 200, null, null)
                    windowOpenOptions.resizable = 0
                    windowOpenOptions.scrollbars = 0
                    windowOpenOptions.status = 0
                    windowOpenOptions.toolbar = 0
                    var callBackItem = new CallBackItem();
                    callBackItem.CallbackContext = this;
                    callBackItem.CallbackID = 'preview';

                    return this.LaunchPopupDialogue(publisherLaunchUrl, windowOpenOptions, callBackItem)
                }
            }
            else {
                var LaunchDialogue = returnNvc.item('LaunchDialogue');
                if (typeof (LaunchDialogue) != 'undefined') {
                    if (LaunchDialogue.value == 'true') {
                        return this.LaunchModalDialogueWithCallbackFromUrl(url.value);
                    }
                }
            }
            this.Preview_CompletePreview()
        }
    }
}
function _Preview_CompletePreview() {
    if (this.initDualView) {
        var workflowMode = 0
        if (this.PreviewContentTypeID == 0) {
            workflowMode = 2
        }
        this.initDualView = null
        this.DualView(this.PreviewContentID, 0, workflowMode)
    } else {
        if (this.dualviewiframe) {
            this.dualviewiframe.src = this.PreviewUrl
        } else {
            if (this.PreviewPopup) {
                top.window.ContensisControlsNamespace.PreviewWindow = window.open(this.PreviewUrl, 'PreviewWindow');
            } else {
                this.OpenInViewer(this.PreviewUrl, null, true)
            }
        }
    }
}
function _DualView(ContentID, ContentVersionID, WorkflowType) {
    var url = this.GetDialogueUrl(3, 141, "ContentID", ContentID, "ContentVersionID", ContentVersionID, "WorkflowType", WorkflowType)
    var height = (top.window.screen.availHeight / 100) * 90
    var width = (top.window.screen.availWidth / 100) * 90

    var windowOpenOptions = new WindowOpenOptions(width, height, null, null)
    windowOpenOptions.resizable = 1
    windowOpenOptions.scrollbars = 0
    windowOpenOptions.status = 0
    windowOpenOptions.toolbar = 0

    return this.LaunchPopupCenter(url, windowOpenOptions, null, false)

}


function _Global_HandlePopupClose(Popupid, ReturnValue) {
    //alert('popup close fired for :' + Popupid + ' ReturnValue:' + ReturnValue)    
    var popup = this.Popups.item(Popupid)
    //alert('close');
    if (popup) {
        popup = popup.value
        popup.ReturnValue = ReturnValue
        popup.ExecuteClose()

        //alert('dispose');
        popup.Dispose();
    }

    this.Popups.remove(Popupid)
    this.CurrentModal = null
    if (this.Utils.IsPopup()) {
        if (opener) {
            opener.ContensisControlsNamespace.Global.CurrentModal.Show()
        }
    }

    if (typeof (CollectGarbage) != 'undefined') {
        CollectGarbage();
    }
}
function _Global_ExecutePopupClose(Popupid, ReturnValue, bubbledExecution) {
    if (window.ContensisControlsNamespace.Browser.DialogSupport) {
        if (window.ContensisControlsNamespace.Browser.IsFirefox3) {
            window.top.returnValue = ReturnValue
            window.top.close();
            return;
        }
        if (window.ContensisControlsNamespace.Browser.IsChrome) {
            window.top.returnValue = ReturnValue
            window.top.close();
            return;
        }
        window.top.returnValue = ReturnValue;
        window.top.close(); //self.close();        
        return;
    }
    if (this.Utils.IsUndefinedOrNull(bubbledExecution)) {
        bubbledExecution = false;
        if (top.window.ContensisControlsNamespace) {
            if (top.window.ContensisControlsNamespace.Global) {
                top.window.ContensisControlsNamespace.Global.ExecutePopupClose(Popupid, ReturnValue, true);
                return;
            }
        }
    }

    if (this.Utils.IsUndefinedOrNull(Popupid)) {
        Popupid = this.Utils.PopupID();
    }

    if (opener) {
        opener.ContensisControlsNamespace.Global.HandlePopupClose(Popupid, ReturnValue)
    }
}

function _LaunchPopupCenter(url, options, callback, modal) {
    if (this.Utils.IsUndefinedOrNull(options)) {
        options = new WindowOpenOptions(null, null, null, null)
    }
    options.left = screen.availWidth / 2 - options.width / 2;
    options.top = screen.availHeight / 2 - options.height / 2;
    return this.LaunchPopup(url, options, callback, modal)
}
function _LaunchPopup(url, options, callback, modal) {
    if (this.IsUIInstance() || this.Utils.IsPopup()) {

        if (this.Utils.IsUndefinedOrNull(modal)) {
            modal = false;
        }
        if (this.Utils.IsUndefinedOrNull(options)) {
            options = new WindowOpenOptions(null, null, null, null)
        }
        this.PopupCount += 1

        var windowName = '';
        if (this.Utils.IsPopup()) {
            windowName += this.Utils.PopupID()
        }
        windowName += 'p_' + this.PopupCount

        //append the popupid
        if (url.indexOf('?') > 0) {
            url += '&popupid=' + windowName
        } else {
            url += '?popupid=' + windowName
        }
        var NewWindow = window.open(url, windowName, options.GetFetaureList());
        var PopupItemClass = new PopupItem(NewWindow, windowName, url, callback)

        this.CurrentModal = PopupItemClass
        this.Popups.add(windowName, PopupItemClass)

        return NewWindow;

    } else {
        return top.window.ContensisControlsNamespace.Global.LaunchPopup(url, options, callback, modal)
    }

}
function _Global_LaunchDialogeFromDialogueButton(Url, Width, Height, Type, Callback) {
    var Options = new WindowOpenOptions(Width, Height, null, null);
    Options.resizable = 0;
    Options.scrollbars = 0;
    Options.status = 0;
    Options.toolbar = 0;
    if (Type == 1) {
        //popup
        this.LaunchPopupCenter(Url, Options, Callback)
    }
    if (Type == 2) {
        //Modal
        this.LaunchPopupDialogue(Url, Options, Callback)
    }
    if (Type == 3) {
        //Viewer
        this.OpenInViewer(Url)
    }
}

function _Global_LaunchPopupDialogue(url, options, callback) {

    //this.StartModal();
    var returnVal;
    if (window.ContensisControlsNamespace.Browser.DialogSupport) {
        if (url.indexOf('?') > 0) {
            url += '&Initialise=true'
        }
        this.PopupCount += 1
        var windowName = 'p_' + this.PopupCount
        //append the popupid
        if (url.indexOf('?') > 0) {
            url += '&popupid=' + windowName
        } else {
            url += '?popupid=' + windowName
        }
        //used to diferentiate between popup windows and modal dialogues servers side....
        url += '&dialogueid=' + windowName
        if (window.ContensisControlsNamespace.Browser.IsFirefox3) {
            url += '&firefox3=true';
        }
        //if you get invalid pointer this could be because the url is too long...

        try {
            returnVal = window.showModalDialog(url, returnVal, options.GetFeatureListForDialogue());
            var PopupItemClass = new PopupItem(null, windowName, url, callback);
            this.Popups.add(windowName, PopupItemClass);

            this.HandlePopupClose(windowName, returnVal);
        }
        catch (ex) { }
        return returnVal;

    } else {
        this.LaunchPopupCenter(url, options, callback, true)
    }

}

function _Global_LaunchModalDialogueWithCallbackFromUrl(url, callback, options) {
    if (typeof (options) == 'undefined') {
        options = new WindowOpenOptions(800, 600, null, null)
        options.resizable = 0
        options.scrollbars = 0
        options.status = 0
        options.toolbar = 0
    }
    return this.LaunchPopupDialogue(url, options, callback)
}
function _LaunchModalDialogueWithCallback(Callback, DialogueType, Width, Height, Keyname1, Keyvalue1, Keyname2, Keyvalue2, Keyname3, Keyvalue3, Keyname4, Keyvalue4, Keyname5, Keyvalue5, Keyname6, Keyvalue6) {
    var url = this.GetDialogueUrl(1, DialogueType, Keyname1, Keyvalue1, Keyname2, Keyvalue2, Keyname3, Keyvalue3, Keyname4, Keyvalue4, Keyname5, Keyvalue5, Keyname6, Keyvalue6) + "&DialogueHeight=" + Height

    var windowOpenOptions = new WindowOpenOptions(Width, Height, null, null)
    windowOpenOptions.resizable = 0
    windowOpenOptions.scrollbars = 0
    windowOpenOptions.status = 0
    windowOpenOptions.toolbar = 0

    return this.LaunchPopupDialogue(url, windowOpenOptions, Callback)

}
function _LaunchModalDialogueWithCallbackAndWindowOptions(windowOpenOptions, Callback, DialogueType, Width, Height, Keyname1, Keyvalue1, Keyname2, Keyvalue2, Keyname3, Keyvalue3, Keyname4, Keyvalue4, Keyname5, Keyvalue5, Keyname6, Keyvalue6) {
    var url = this.GetDialogueUrl(1, DialogueType, Keyname1, Keyvalue1, Keyname2, Keyvalue2, Keyname3, Keyvalue3, Keyname4, Keyvalue4, Keyname5, Keyvalue5, Keyname6, Keyvalue6) + "&DialogueHeight=" + Height
    return this.LaunchPopupDialogue(url, windowOpenOptions, Callback)
}
function _LaunchModalDialogue(DialogueType, Width, Height, Keyname1, Keyvalue1, Keyname2, Keyvalue2, Keyname3, Keyvalue3, Keyname4, Keyvalue4, Keyname5, Keyvalue5, Keyname6, Keyvalue6) {
    var url = this.GetDialogueUrl(1, DialogueType, Keyname1, Keyvalue1, Keyname2, Keyvalue2, Keyname3, Keyvalue3, Keyname4, Keyvalue4, Keyname5, Keyvalue5, Keyname6, Keyvalue6)

    var windowOpenOptions = new WindowOpenOptions(Width, Height, null, null)
    windowOpenOptions.resizable = 0
    windowOpenOptions.scrollbars = 0
    windowOpenOptions.status = 0
    windowOpenOptions.toolbar = 0

    return this.LaunchPopupDialogue(url, windowOpenOptions, null)

}
function _LaunchDialogue(DialogueType, Keyname1, Keyvalue1, Keyname2, Keyvalue2, Keyname3, Keyvalue3, Keyname4, Keyvalue4, Keyname5, Keyvalue5, Keyname6, Keyvalue6) {
    var url = this.GetDialogueUrl(3, DialogueType, Keyname1, Keyvalue1, Keyname2, Keyvalue2, Keyname3, Keyvalue3, Keyname4, Keyvalue4, Keyname5, Keyvalue5, Keyname6, Keyvalue6)
    this.OpenInViewer(url)
}
function _Global_SetKeyValueQuery(Value) {
    var query = this.Helpers.IsNull(Value, '');
    if (query.length > 0) {
        query = window.ContensisControlsNamespace.Utilities.UrlEncode(query);
    }
    return query;
}
function _Global_GetDialogueUrl(DialogueMode, DialogueType, Keyname1, Keyvalue1, Keyname2, Keyvalue2, Keyname3, Keyvalue3, Keyname4, Keyvalue4, Keyname5, Keyvalue5, Keyname6, Keyvalue6) {
    var url = '/CMSEngine/Dialogue/Dialogue.aspx?DialogueType=' + DialogueType + '&DialogueDisplayMode=' + DialogueMode


    if (typeof (Keyname1) != 'undefined') {
        if (Keyname1 != null) {
            url = url + '&DialogueKey_' + Keyname1 + '=' + this.SetKeyValueQuery(Keyvalue1);
        }
    }
    if (typeof (Keyname2) != 'undefined') {
        if (Keyname2 != null) {
            url = url + '&DialogueKey_' + Keyname2 + '=' + this.SetKeyValueQuery(Keyvalue2);
        }
    }
    if (typeof (Keyname3) != 'undefined') {
        if (Keyname3 != null) {
            url = url + '&DialogueKey_' + Keyname3 + '=' + this.SetKeyValueQuery(Keyvalue3);
        }
    }

    if (typeof (Keyname4) != 'undefined') {
        if (Keyname4 != null) {
            url = url + '&DialogueKey_' + Keyname4 + '=' + this.SetKeyValueQuery(Keyvalue4);
        }
    }
    if (typeof (Keyname5) != 'undefined') {
        if (Keyname5 != null) {
            url = url + '&DialogueKey_' + Keyname5 + '=' + this.SetKeyValueQuery(Keyvalue5);
        }
    }
    if (typeof (Keyname6) != 'undefined') {
        if (Keyname6 != null) {
            url = url + '&DialogueKey_' + Keyname6 + '=' + this.SetKeyValueQuery(Keyvalue6);
        }
    }
    url = url + '&DialogueKey_ProjectId=' + this.CurrentProjectID
    return url
}
function _LaunchFolderProperties(folderId) {
    this.LaunchDialogue(31, "FolderID", folderId)
}
function _LaunchAuditTrail(Id, Mode) {
    this.LaunchDialogue(5, "ContentID", Id, "Mode", Mode)
}

function _InformationDialogue(Id, Mode) {
    var url = this.GetDialogueUrl(1, 4, "ContentID", Id, "Mode", Mode)

    //550, 760
    var windowOpenOptions = new WindowOpenOptions(550, 760, null, null) // 550, 560
    windowOpenOptions.resizable = 1
    windowOpenOptions.scrollbars = 0
    windowOpenOptions.status = 0
    windowOpenOptions.toolbar = 0

    return this.LaunchPopupCenter(url, windowOpenOptions, null, false)
}

function ErrorDialogue(DialogueErrorType, ErrorText, ErrorTitle, CallBack, CallBackID) {
    if (this.Utils.IsUndefinedOrNull(ErrorTitle)) {
        ErrorTitle = "An Error has occured";
    }
    if (ErrorTitle.length == 0) {
        ErrorTitle = "An Error has occured";
    }
    if (this.Utils.IsUndefinedOrNull(CallBack)) {
        var callBackItem = new CallBackItem();
        callBackItem.CallbackContext = this;
        if (this.Utils.IsUndefinedOrNull(CallBackID)) {
            CallbackID = DialogueErrorType
        }
        callBackItem.CallbackID = CallBackID;
    }
    return this.LaunchModalDialogueWithCallback(CallBack, 71, 450, 100, "ErrorMessage", ErrorText, "ErrorType", DialogueErrorType, "ErrorTitle", ErrorTitle)
}
//This function returns false if an error is not handled
function _Global_LaunchStandardAjaxDialogue(data, Callback) {
    if (data.ErrorAlreadyThrown) {
        return true;
    }
    var nv = new nameValueCollection();
    nv.Load(data);
    var errorCode = nv.item('ErrorCode')
    var errorMessage = nv.item('ErrorMessage')
    var title = ""
    var titleitem = nv.item('ErrorTitle')
    if (titleitem) {
        title = titleitem.value
    }

    if (title.length = 0) {
        title = null
    }
    if (errorCode.value < 20) {
        if (errorCode.value > 0) {
            this.ErrorDialogue(errorCode.value, errorMessage.value, title, Callback);
            data.ErrorAlreadyThrown = true;
            return true;
        }
    }
    if (errorCode.value == 99) {
        this.SessionLost(true, null, nv)
        return true
    }
    return false;
}

function _Global_UpdateUserProject(projectID) {
    var nv = new nameValueCollection()
    nv.add('ProjectID', projectID);
    this.MakeAjaxRequest('UpdateUserProject', nv);
}

function _Global_HandleToolItemClick(ClickedTool, e) {
    var KeyName1
    var KeyValue1
    var KeyName2
    var KeyValue2
    var KeyName3
    var KeyValue3
    var KeyName4;
    var KeyValue4;

    var i = 0
    for (i = 0; i < ClickedTool.ParamCollection.count(); i++) {
        var item = ClickedTool.ParamCollection.itemByIndex(i);
        var keyname = 'dialoguekey_'
        var keyIndex = item.name.toLowerCase().indexOf(keyname)
        if (keyIndex > -1) {
            var DialogueKeyName = item.name.substring(keyname.length)
            if (i == 0) {
                KeyName1 = DialogueKeyName
                KeyValue1 = item.value
            }
            if (i == 1) {
                KeyName2 = DialogueKeyName
                KeyValue2 = item.value
            }
            if (i == 2) {
                KeyName3 = DialogueKeyName
                KeyValue3 = item.value
            }
            if (i == 3) {
                KeyName4 = DialogueKeyName
                KeyValue4 = item.value
            }

        }
    }

    if (ClickedTool.DialogueTypeId > 0) {
        if (ClickedTool.DialogueDisplayMode == 1) {
            ContensisControlsNamespace.Global.LaunchModalDialogue(ClickedTool.DialogueTypeId, ClickedTool.DialogueWidth, ClickedTool.DialogueHeight, KeyName1, KeyValue1, KeyName2, KeyValue2, KeyName3, KeyValue3, KeyName4, KeyValue4);
            return
        } else {
            ContensisControlsNamespace.Global.LaunchDialogue(ClickedTool.DialogueTypeId, KeyName1, KeyValue1, KeyName2, KeyValue2, KeyName3, KeyValue3, KeyName4, KeyValue4);
            return
        }
    }
    else {
        if (ClickedTool.Url.length > 0) {
            if (ClickedTool.CommandName.toLowerCase() == 'scansystem') {
                var windowOpenOptions = new WindowOpenOptions(ClickedTool.DialogueWidth, ClickedTool.DialogueHeight, null, null)
                windowOpenOptions.resizable = 0
                windowOpenOptions.scrollbars = 0
                windowOpenOptions.status = 1
                windowOpenOptions.toolbar = 0
                this.LaunchPopupCenter(ClickedTool.Url, windowOpenOptions)
                return
            }
            ContensisControlsNamespace.Global.OpenInViewer(ClickedTool.Url)
            return
        }
    }

    if (ClickedTool.CommandName.toLowerCase() == 'changeproject') {
        this.CurrentProjectID = ClickedTool.ParamCollection.item("projectid").value;
        this.UpdateUserProject(this.CurrentProjectID)
        var RootNode = ContensisControlsNamespace.TreeviewNavigator.GetRootNode();
        RootNode.Id = ClickedTool.ParamCollection.item("rootfolderid").value;
        RootNode.SaveState();
        RootNode.UpdateState();
        RootNode.RefreshNode();
        ContensisControlsNamespace.UserInterface.UpdateProjectName(ClickedTool.Name);
    }
    if (ClickedTool.CommandName.toLowerCase() == 'shownavigatorpane') {
        ContensisControlsNamespace.UserInterface.ShowNavigatorPanel(ClickedTool.Name)
        return
    }
    if (ClickedTool.CommandName.toLowerCase() == 'logout') {
        this.LogOut()
        return
    }
    if (ClickedTool.CommandName.toLowerCase() == 'killsession') {
        this.KillSession()
        return
    }
    ContensisControlsNamespace.UserInterface.HandleToolClick(ClickedTool, e)
}
function _Helpers() { }
_Helpers.prototype.ConvertIntToBool = _ConvertIntToBool;
_Helpers.prototype.ConvertBoolToint = _ConvertBoolToInt;
_Helpers.prototype.parseXml = _Helpers_parseXml;
_Helpers.prototype.newXmlDocument = _Helpers_newXmlDocument;
_Helpers.prototype.ConvertNvToQuerystring = _Helpers_ConvertNvToQuerystring;
_Helpers.prototype.IsNull = _Helpers_isnull;

function _Helpers_isnull(value, replacement) {
    if (value == null) {
        return replacement
    } else {
        return value
    }
}

function _Helpers_newXmlDocument(rootTagName, namespaceURL) {
    if (!rootTagName) rootTagName = "";
    if (!namespaceURL) namespaceURL = "";

    if (document.implementation && document.implementation.createDocument) {
        // This is the W3C standard way to do it
        return document.implementation.createDocument(namespaceURL, rootTagName, null);
    }
    else { // This is the IE way to do it
        // Create an empty document as an ActiveX object
        // If there is no root element, this is all we have to do
        var doc = new ActiveXObject("MSXML2.DOMDocument");

        // If there is a root tag, initialize the document
        if (rootTagName) {
            // Look for a namespace prefix 
            var prefix = "";
            var tagname = rootTagName;
            var p = rootTagName.indexOf(':');
            if (p != -1) {
                prefix = rootTagName.substring(0, p);
                tagname = rootTagName.substring(p + 1);
            }

            // If we have a namespace, we must have a namespace prefix
            // If we don't have a namespace, we discard any prefix
            if (namespaceURL) {
                if (!prefix) prefix = "a0"; // What Firefox uses
            }
            else prefix = "";

            // Create the root element (with optional namespace) as a
            // string of text
            var text = "<" + (prefix ? (prefix + ":") : "") + tagname +
                (namespaceURL
                 ? (" xmlns:" + prefix + '="' + namespaceURL + '"')
                 : "") +
                "/>";
            // And parse that text into the empty document
            doc.loadXML(text);
        }
        return doc;
    }
};

function _Helpers_parseXml(text) {
    if (typeof DOMParser != "undefined") {
        // Mozilla, Firefox, and related browsers
        return (new DOMParser()).parseFromString(text, "application/xml");
    }
    else if (typeof ActiveXObject != "undefined") {
        // Internet Explorer.
        var doc = this.newXmlDocument();   // Create an empty document
        doc.loadXML(text);              //  Parse text into it
        return doc;                     // Return it
    }
    else {
        // As a last resort, try loading the document from a data: URL
        // This is supposed to work in Safari. Thanks to Manos Batsis and
        // his Sarissa library (sarissa.sourceforge.net) for this technique.
        var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text);
        var request = new XMLHttpRequest();
        request.open("GET", url, false);
        request.send(null);
        return request.responseXML;
    }
};

function _Helpers_ConvertNvToQuerystring(NameValueCollection) {
    var ReturnStr = '';
    var Delimeter = "?";
    for (i = 0; i < NameValueCollection.count(); i++) {
        var item = NameValueCollection.itemByIndex(i);
        ReturnStr += Delimeter + item.name + "=" + item.value
        Delimeter = "&";
    }
    return ReturnStr;
}


function _ConvertIntToBool(value) {
    if (value == 1) {
        return true
    } else {
        return false
    }
}
function _ConvertBoolToInt(value) {
    if (value) {
        return 1
    } else {
        return 0
    }
}


if (typeof window.ContensisControlsNamespace == "undefined") {
    window.ContensisControlsNamespace = {};
}
if (typeof (window.ContensisControlsNamespace.Global) == "undefined" || typeof (window.ContensisControlsNamespace.Global) == null) {
    window.ContensisControlsNamespace.Global = new _Global();
}

function nameValueCollection(text) {
    this._innerNameList = new Array();
    this._innerNameIndexList = new Array();
    this._innerValueList = new Array();
    this._findName = _nv_findName;
    this._dataDecode = _nv_dataDecode;
    this._dataEncode = _nv_dataEncode;
    this._nvRegex = new RegExp('([^,]+),([^;]*)(?:;|$)', 'gi');
    //no safari support....
    //this._nvRegex.compile('([^,]+),([^;]*)(?:;|$)','gi');

    if (text) {
        var doc = window.ContensisControlsNamespace.Global.Helpers.parseXml(text);
        if (doc.documentElement.text) {
            text = doc.documentElement.text;
        } else {
            text = doc.documentElement.textContent;
        }
        while (arrMatch = this._nvRegex.exec(text)) {
            this.add(this._dataDecode(arrMatch[1]), this._dataDecode(arrMatch[2]))
        }
    }
}
nameValueCollection.prototype.add = _nv_add;
nameValueCollection.prototype.containsName = _nv_containsName;
nameValueCollection.prototype.containsValue = _nv_containsValue;
nameValueCollection.prototype.count = _nv_count;
nameValueCollection.prototype.item = _nv_item;
nameValueCollection.prototype.itemByIndex = _nv_itemByIndex;
nameValueCollection.prototype.remove = _nv_remove;
nameValueCollection.prototype.removeAt = _nv_removeAt;
nameValueCollection.prototype.toXML = _nv_toXML;

nameValueCollection.prototype.IsContensisNameValueCollection = true;

nameValueCollection.prototype.Copy = function(copyFrom) {
    if (copyFrom) {
        for (var i = 0; i < copyFrom._innerValueList.length; i++) {
            var item = copyFrom._innerValueList[i];
            if (this.containsName(item.name)) {
                var currentItem = this.item(item.name);
                currentItem.value = item.value;
            }
            else {
                this.add(item.name, item.value);
            }
        }
    }
}

nameValueCollection.prototype.Load = function(nv) {
    if (nv.constructor === nameValueCollection) {
        this.Copy(nv);
        return;
    }
    if (nv.IsContensisNameValueCollection) {
        this.Copy(nv);
        return;
    }
    for (var propName in nv) {
        if (nv.hasOwnProperty(propName)) {
            if (this.containsName(propName)) {
                var currentItem = this.item(propName);
                currentItem.value = nv[propName];
            }
            else {
                this.add(propName, nv[propName]);
            }
        }
    }
}

function _nv_add(name, value) {
    var insPoint;
    insPoint = this._findName(name.toLowerCase());
    if (insPoint >= 0) {
        throw ('An item with the name \'' + name + '\' has already been added to this collection.');
    } else {
        var oName = name;
        name = name.toLowerCase();
        insPoint = Math.abs(insPoint) - 1;
        this._innerNameList.splice(insPoint, 0, name);
        this._innerNameIndexList.splice(insPoint, 0, this._innerValueList.length);
        this._innerValueList[this._innerValueList.length] = new nvItem(name, value, oName);
        return true;
    }
}
function _nv_containsName(name) {
    return (this._findName(name.toLowerCase()) >= 0);
}
function _nv_containsValue(value) {
    for (i = 0; i < this._innerValueList.length; i++) {
        if (this._innerValueList[i].value === value) {
            return true;
        }
    }
    return false;
}
function _nv_count(value) {
    return this._innerValueList.length;
}
function _nv_dataDecode(text) {
    text = String(text);
    text = text.replace(/\[%%Comma%%\]/g, ',');
    text = text.replace(/\[%%SemiColon%%\]/g, ';');
    text = text.replace(/\[%%GreaterThan%%\]/g, '>');
    text = text.replace(/\[%%LessThan%%\]/g, '<');
    text = text.replace(/\[%%NewLine%%]/g, '\n');
    text = text.replace(/\[%%DollarSign%%]/g, '$');

    return text
}
function _nv_dataEncode(text) {
    text = String(text);
    text = text.replace(/,/g, '[%%Comma%%]');
    text = text.replace(/;/g, '[%%SemiColon%%]');
    text = text.replace(/>/g, '[%%GreaterThan%%]');
    text = text.replace(/</g, '[%%LessThan%%]');
    text = text.replace(/\n/g, '[%%NewLine%%]');
    text = text.replace(/\$/g, '[%%DollarSign%%]');
    return text
}
function _nv_findName(name) {
    var left = -1, right = this._innerNameList.length, mid;

    while (right - left > 1) {
        // Bit shift right and zero fill left
        mid = (left + right) >>> 1;
        if (this._innerNameList[mid] == name) break;
        if (this._innerNameList[mid] < name) left = mid; else right = mid;
    }

    return this._innerNameList[mid] != name ? -(right + 1) : mid;
}
function _nv_item(name) {
    return this.itemByIndex(this._innerNameIndexList[this._findName(name.toLowerCase())]);
}
function _nv_itemByIndex(index) {
    return this._innerValueList[index];
}
function _nv_remove(name) {
    var namePos = this._findName(name.toLowerCase());

    if (namePos >= 0) {
        var indexPos = this._innerNameIndexList[namePos];

        if (indexPos < (this._innerNameIndexList.length - 1)) {
            for (i = 0; i < this._innerNameIndexList.length; i++) {
                if (this._innerNameIndexList[i] > indexPos) this._innerNameIndexList[i] -= 1;
            }
        }
        this._innerNameList.splice(namePos, 1);
        this._innerNameIndexList.splice(namePos, 1);
        this._innerValueList.splice(indexPos, 1);
        return true;
    } else {
        return false;
    }
}
function _nv_removeAt(index) {
    return this.remove(this.item(index).name);
}
function _nv_toXML() {
    var data = '';
    for (i = 0; i < this._innerValueList.length; i++) {
        data += this._dataEncode(this._innerValueList[i].name) + ',' + this._dataEncode(this._innerValueList[i].value) + ';'
    }
    data = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><nvData><![CDATA[' + data + ']]></nvData>'
    return data;
}

function nvItem(name, value, originalName) {
    this.name = name;
    this.value = value;
    if (originalName) {
        this.originalName = originalName;
    }
    else {
        this.originalName = name;
    }
}

_Global.prototype.ContensisXMLDecode = _nv_dataDecode;
_Global.prototype.ContensisXMLEncode = _nv_dataEncode;
_Global.prototype.ContensisHTMLDecode = function(text) {
    text = String(text);
    text = text.replace(/\[%%%Comma%%%\]/g, ',');
    text = text.replace(/\[%%%SemiColon%%%\]/g, ';');
    text = text.replace(/\[%%%GreaterThan%%%\]/g, '>');
    text = text.replace(/\[%%%LessThan%%%\]/g, '<');
    text = text.replace(/\[%%%NewLine%%%]/g, '\n');
    text = text.replace(/\[%%%DollarSign%%%]/g, '$');

    return text
};

_Global.prototype.ContensisHTMLEncode = function(text) {
    text = String(text);
    text = text.replace(/,/g, '[%%%Comma%%%]');
    text = text.replace(/;/g, '[%%%SemiColon%%%]');
    text = text.replace(/>/g, '[%%%GreaterThan%%%]');
    text = text.replace(/</g, '[%%%LessThan%%%]');
    text = text.replace(/\n/g, '[%%%NewLine%%%]');
    text = text.replace(/\$/g, '[%%%DollarSign%%%]');
    return text
};


function ContentType(id, name, description, extensions, canBeInsertedIntoWebpages, canBePublished, canPreview, canSaveAs, workflowType, saveMode, editType, allowArchive) {
    this.ID = id
    this.Name = name
    this.Description = description
    this.Extensions = extensions
    this.CanBeInsertedIntoWebpages = canBeInsertedIntoWebpages
    this.CanBePublished = canBePublished
    this.CanPreview = canPreview
    this.CanSaveAs = canSaveAs
    this.WorkflowType = workflowType
    this.SaveMode = saveMode
    this.EditType = editType
    this.AllowArchive = allowArchive
}

function WindowOpenOptions(width, height, top, left) {
    this.Utils = window.ContensisControlsNamespace.Utilities
    if (this.Utils.IsUndefinedOrNull(width)) {
        width = 150
    }
    if (this.Utils.IsUndefinedOrNull(height)) {
        height = 150
    }
    if (this.Utils.IsUndefinedOrNull(top)) {
        top = 0
    }
    if (this.Utils.IsUndefinedOrNull(left)) {
        left = 0
    }
    this.resizable = 1
    this.scrollbars = 1
    this.status = 1
    this.toolbar = 1
    this.top = top
    this.left = left
    this.height = height
    this.width = width
}
WindowOpenOptions.prototype.GetFetaureList = _WindowOpenOptions_GetFetaureList
WindowOpenOptions.prototype.GetFeatureListForDialogue = _WindowOpenOptions_GetFeatureListForDialogue
WindowOpenOptions.prototype.GetYesNo = _WindowOpenOptions_GetYesNo
function _WindowOpenOptions_GetFetaureList() {
    var returnval = ''
    returnval += 'resizable=' + this.GetYesNo(this.resizable) + ','
    returnval += 'scrollbars=' + this.GetYesNo(this.scrollbars) + ','
    returnval += 'status=' + this.GetYesNo(this.status) + ','
    returnval += 'toolbar=' + this.GetYesNo(this.toolbar) + ','
    returnval += 'top=' + this.top + ','
    returnval += 'left=' + this.left + ','
    returnval += 'height=' + this.height + ','
    returnval += 'width=' + this.width + ','
    returnval = this.Utils.TrimEnd(returnval, ',')
    return returnval
}
function _WindowOpenOptions_GetFeatureListForDialogue() {
    //'dialogHeight: ' + Height + 'px; dialogWidth:' + Width + 'px; dialogTop: px; dialogLeft: px; scroll:No ; unadorned:No; edge: Raised; center: Yes; help: No; resizable: No; status: No;
    var returnval = ''
    returnval += 'dialogHeight=' + this.height + 'px; '
    returnval += 'dialogWidth=' + this.width + 'px; '
    if (this.top > 0) {
        returnval += 'dialogTop=' + this.top + 'px; '
    }

    if (this.left > 0) {
        returnval += 'dialogLeft=' + this.left + 'px; '
    }
    returnval += 'scroll:' + this.GetYesNo(this.scrollbars) + '; '
    returnval += 'center:' + 'yes' + '; '
    returnval += 'help:' + 'no' + '; '
    returnval += 'resizable:' + this.GetYesNo(this.resizable) + '; '
    if (!window.ContensisControlsNamespace.Browser.IsFirefox3) {
        returnval += 'unadorned:' + 'no' + '; '
        returnval += 'edge:' + 'raised' + '; '
        returnval += 'status:' + this.GetYesNo(this.status) + '; '
    }
    else {
        // firefox 3 has a problem launcing dialogs in the center so position it instead
        if (this.top == 0) {
            var top = (screen.availHeight / 2) - (this.height / 2);
            returnval += 'dialogTop=' + top + 'px; '
        }
        if (this.left == 0) {
            var left = (screen.availWidth / 2) - (this.width / 2);
            returnval += 'dialogLeft=' + left + 'px; '
        }
    }
    return returnval
}

function _WindowOpenOptions_GetYesNo(value) {
    if (value == 1) {
        return "yes";
    }
    return "no"
}

function PopupItem(popup, PopupID, url, callback) {
    this.Id = PopupID
    this.Url = url
    this.CallBack = callback
    this.Popup = popup
    this.ReturnValue = null
}
PopupItem.prototype.ExecuteClose = _PopupItem_ExecuteClose
PopupItem.prototype.Show = _PopupItem_Show
PopupItem.prototype.Dispose = _PopupItem_Dispose;

function _PopupItem_Dispose() {
    this.Id = null;
    this.Url = null;
    this.CallBack = null;
    this.Popup = null;
    this.ReturnValue = null;
}

function _PopupItem_ExecuteClose() {
    if (this.ReturnValue != null) {
        if (typeof (this.ReturnValue) == 'string') {
            if (this.ReturnValue == 'cancel') {
                if (this.Popup != null) {
                    this.Popup.close()
                }
                ContensisControlsNamespace.Global.EndModal()
                return;
            }
        }

        //Execute callback...
        if (this.CallBack != null) {
            if (this.CallBack.CallbackContext != null) {
                if (this.CallBack.CallbackFunction) {
                    this.CallBack.CallbackFunction.call(this.CallBack.CallbackContext, this.CallBack.CallbackID, this.CallBack, this)
                } else {
                    //eval("this.CallBack.CallbackObject.' + this.CallBack.CallbackFunction + '(null,null)")
                    //this.CallBack.CallbackObject.myfunctionthatisastring(stuff,stuff)                    
                    this.CallBack.CallbackContext.HandleModalCallback(this.CallBack.CallbackID, this.CallBack, this)
                }
            }
        }

    }
    if (this.Popup != null) {
        this.Popup.close()
    }
    ContensisControlsNamespace.Global.EndModal()
}
function _PopupItem_Show() {
    if (this.Popup != null) {
        if (!this.Popup.closed) {
            //check if double layered popup????
            if (this.Popup.ContensisControlsNamespace.Global.CurrentModal) {
                this.Popup.ContensisControlsNamespace.Global.CurrentModal.Show();
            } else {
                this.Popup.focus()
            }
        }
    }
}
function CallBackItem() {
    this.CallbackContext = null
    this.CallbackID = null
    this.CallbackFunction = null
}
// Used to represent the server side CMS_API.Content.ContentID

function ContentID(contentID, workflowType, contentTypeID, contentVersionID) {
    this.Utils = window.ContensisControlsNamespace.Utilities
    this.ContentID = contentID
    this.WorkflowType = workflowType
    this.ContentTypeID = contentTypeID
    this.ContentVersionID = contentVersionID

    if (this.Utils.IsUndefinedOrNull(this.ContentTypeID)) {
        if (this.WorkflowType == 2) {
            this.ContentTypeID = 0
        }
    }

}

ContentID.FromNameValueCollection = function(nv) {
    var contentID = nv.item('ContentID').value;
    var workflowType = nv.item('WorkflowType').value;
    var contentTypeID = nv.item('ContentTypeID').value;
    var contentVersionID = nv.item('ContentVersionID').value;
    return new ContentID(contentID, workflowType, contentTypeID, contentVersionID);
}

ContentID.prototype.AsNameValueCollection = _ContentId_AsNameValueCollection

function _ContentId_AsNameValueCollection() {
    var nv = new nameValueCollection();
    nv.add('WorkflowType', this.WorkflowType);
    nv.add('ContentTypeID', this.ContentTypeID);
    nv.add('ContentID', this.ContentID);
    nv.add('ContentVesrionID', this.ContentVersionID);
    return nv;
}



//Generic Functions

function _Generic_MakeAjaxRequest(Action, NameValueCollection) {
    return window.ContensisControlsNamespace.Global.ajax.requestSync(this.Id + '_Ajax', Action, NameValueCollection);
}

function _Generic_MakeASyncAjaxRequest(Action, NameValueCollection, func, context) {
    return window.ContensisControlsNamespace.Global.ajax.requestASync(this.Id + '_Ajax', Action, NameValueCollection, func, context);
}

function _Global_GetAnchors(content) {
    var temp = document.createElement('div');
    window.ContensisUtility.setInnerHTML(temp, content);
    var anchorElements = temp.getElementsByTagName("A");
    var anchors = new Array();
    var idx = 0;
    for (var i = 0; i < anchorElements.length; i++) {
        var anchor = anchorElements[i];
        if (anchor.attributes['anchorname']) {
            if (anchor.attributes['anchorname'].value != '') {
                anchors[idx] = anchor.attributes['anchorname'].value;
                idx += 1;
            }
        }
        else {
            if (anchor.name) {
                if (anchor.name != '') {
                    anchors[idx] = anchor.name;
                    idx += 1;
                }
            }
        }
    }
    return anchors;
}

function _Global_GetAjaxAnchors(contentID, workflow) {
    var nv = new nameValueCollection();
    nv.add('ContentID', contentID);
    nv.add('Workflow', workflow);

    //only pages can have anchors...
    if (nv.item('Workflow').value == "0") {
        return null;
    }
    var ReturnNVC = this.MakeAjaxRequest('GetAnchors', nv);
    if (ReturnNVC.item('Anchors')) {
        var Anchors = ReturnNVC.item('Anchors').value
        if (Anchors.length == 0) {
            return null
        }
        return Anchors.split(",")
    }
    return null;
}

function _Global_GetResourceAsString(resourceID, resourceType) {
    var resourceName = resourceID + '_' + resourceType;
    if (this.Resources.item(resourceName)) {
        return this.Resources.item(resourceName).value;
    }

    var nv = new nameValueCollection();
    nv.add('ResourceID', resourceID);
    nv.add('ResourceType', resourceType);
    var ReturnNVC = this.MakeAjaxRequest('GetResource', nv);
    if (ReturnNVC.item('resource')) {
        var resource = ReturnNVC.item('resource').value;
        this.Resources.add(resourceName, resource);
        return resource;
    }
    return '';
}

function _Global_GetLabelResourceAsString(resourceID) {
    return this.GetResourceAsString(resourceID, 'Label');
}

function _Global_SetPreviewPage(ContentID, ContentTypeID, TargetContentID) {
    var nv = new nameValueCollection();
    nv.add('ContentID', ContentID);
    nv.add('ContentTypeID', ContentTypeID);
    nv.add('TargetContentID', TargetContentID);

    var ReturnNVC = this.MakeAjaxRequest('SetPreviewPage', nv);
    if (ReturnNVC.item('Path')) {
        return ReturnNVC.item('Path').value
    }
    return '';
}

function _Global_GetPath(ContentID, ContentTypeID) {
    var nv = new nameValueCollection();
    nv.add('ContentID', ContentID);
    nv.add('ContentTypeID', ContentTypeID);

    var ReturnNVC = this.MakeAjaxRequest('GetPath', nv);
    if (ReturnNVC.item('Path')) {
        return ReturnNVC.item('Path').value
    }
    return '';
}

function _Global_GetContentID(contentVersionID, contentTypeID) {
    var nv = new nameValueCollection();
    nv.add('ContentVersionID', contentVersionID);
    nv.add('ContentTypeID', contentTypeID);
    var ReturnNVC = this.MakeAjaxRequest('GetContentID', nv);
    if (ReturnNVC.item('ContentID')) {
        var contentID = ReturnNVC.item('ContentID').value;
        return contentID;
    }
    return '';
}

function _Global_FormatString() {
    var result = '';
    if (arguments.length > 0) {
        result = arguments[0];
        for (var i = 1; i < arguments.length; i++) {
            var idx = i - 1;
            var s = '{' + idx + '}';
            while (result.indexOf(s) >= 0) {
                result = result.replace(s, arguments[i]);
            }
        }
    }
    return result;
}

function _Global_CheckSession() {
    var isValid = false;
    var nv = new nameValueCollection();
    var ReturnNVC = this.MakeAjaxRequest('CheckSession', nv);
    if (ReturnNVC.item('IsValid')) {
        if (ReturnNVC.item('IsValid').value == 'true') {
            isValid = true;
        }
    }
    if (!isValid) {
        this.LaunchModalDialogue('153')
    }
}

function _Global_HandleMetaTreeTextboxFocus(textbox, hidden, MetaDataDefinitionID, ContentID, WorkflowType, folderID) {
    textbox.HandleModalCallback = function(CallbackID, Callback, PopupItem) {
        var nv = new nameValueCollection();
        nv.Copy(PopupItem.ReturnValue);
        if (CallbackID == 'updatevalue') {
            textbox.value = nv.item('text').value;
            hidden.value = nv.item('values').value;
        }
    }

    var AjaxNvCollection = new nameValueCollection()
    AjaxNvCollection.add("WorkflowType", WorkflowType)
    AjaxNvCollection.add("ContentID", ContentID)
    AjaxNvCollection.add("FolderID", folderID)
    AjaxNvCollection.add("MetaDataDefinitionID", MetaDataDefinitionID)
    AjaxNvCollection.add("Data", hidden.value)

    var callBackItem = new CallBackItem();
    callBackItem.CallbackContext = textbox;
    callBackItem.CallbackID = 'updatevalue';

    var guid = ContensisControlsNamespace.Global.PersistNameValueCollectionToSession(AjaxNvCollection)

    this.LaunchModalDialogueWithCallback(callBackItem, 183, 500, 600, 'StateGuid', guid)
}

function _Global_HandleFolderPropertyTreeTextboxFocus(textbox, hiddenID) {
    textbox.HandleModalCallback = function(CallbackID, Callback, PopupItem) {
        var nv = new nameValueCollection();
        nv.Copy(PopupItem.ReturnValue);
        if (CallbackID == 'updatevalue') {
            textbox.value = nv.item('Path').value;
            document.getElementById(hiddenID).value = nv.item('SiteID').value;
        }
    }

    var AjaxNvCollection = new nameValueCollection()
    AjaxNvCollection.add("Value", textbox.value)

    var callBackItem = new CallBackItem();
    callBackItem.CallbackContext = textbox;
    callBackItem.CallbackID = 'updatevalue';
    this.LaunchModalDialogueWithCallback(callBackItem, 255, 500, 600, 'Value', document.getElementById(hiddenID).value)
}

function _Global_HandleMetaUrlTextboxFocus(textbox, Url) {

    textbox.HandleModalCallback = function(CallbackID, Callback, PopupItem) {
        if (CallbackID == 'updatevalue') {
            this.value = PopupItem.ReturnValue
        }
    }

    var callBackItem = new CallBackItem();
    callBackItem.CallbackContext = textbox;
    callBackItem.CallbackID = 'updatevalue';

    var windowOpenOptions = new WindowOpenOptions(800, 600, 0, 0)
    windowOpenOptions.resizable = 0
    windowOpenOptions.scrollbars = 0
    windowOpenOptions.status = 0
    windowOpenOptions.toolbar = 0

    var dialogueUrl = this.GetDialogueUrl(3, 196, "NavigateUrl", Url)
    dialogueUrl += "&DialogueHeight=600&DialogueScroll=true"

    if (ContensisControlsNamespace.Browser.IsFirefox3) {
        dialogueUrl = Url;
    }

    this.LaunchModalDialogueWithCallbackFromUrl(dialogueUrl, callBackItem, windowOpenOptions)
}

function _Global_RevertToVersion(contentID, contentVersionID, workflowType) {
    var keyName1 = 'ErrorMessage';
    //RESOURCE: Are you sure you wish to revert to this version?
    var keyValue1 = '1789';
    var keyName2 = 'ErrorType'
    var keyValue2 = '2'
    var keyName3 = 'ErrorTitle';
    //RESOURCE: Revert to previous version
    var keyValue3 = '1788';
    if (top.window.ContensisControlsNamespace.CMSEditor) {
        top.window.ContensisControlsNamespace.CMSEditor.SuppressNavigationMessage = true;
    }

    var callBackItem = new CallBackItem();
    callBackItem.CallbackContext = this;
    callBackItem.CallbackID = 'RevertToVersionConfirm';
    callBackItem.contentID = contentID
    callBackItem.contentVersionID = contentVersionID
    callBackItem.workflowType = workflowType

    this.LaunchModalDialogueWithCallback(callBackItem, 71, 450, 100, keyName1, keyValue1, keyName2, keyValue2, keyName3, keyValue3)
}

function _Global_ExecuteRevertToVersion(callBackItem) {
    var NameValueCollection = new nameValueCollection();
    NameValueCollection.add('ContentID', callBackItem.contentID);
    NameValueCollection.add('ContentVersionID', callBackItem.contentVersionID);
    NameValueCollection.add('WorkflowType', callBackItem.workflowType);

    var returnNameValueCollection = this.MakeAjaxRequest('RevertToVersion', NameValueCollection);
    if (returnNameValueCollection.item('hasBeenReverted') && returnNameValueCollection.item('hasBeenReverted').value == 'true') {
        this.LaunchContentEditor(callBackItem.contentID, callBackItem.workflowType, -1)
    }
}

function _Global_LaunchAuditTrailDialogueAsPopup(contentId, workflowType, projectId) {
    var s = '';
    // - RichC Taken out projet id as cant see why required....?
    var url = this.GetDialogueUrl(3, 5, "ContentID", contentId, "WorkflowType", workflowType)
    var height = 600
    var width = 1180

    var windowOpenOptions = new WindowOpenOptions(width, height, null, null)
    windowOpenOptions.resizable = 1
    windowOpenOptions.scrollbars = 0
    windowOpenOptions.status = 0
    windowOpenOptions.toolbar = 0

    return this.LaunchPopupCenter(url, windowOpenOptions, null, false)

}

function _Global_ApproveDeclineContent(contentId, contentTypeId, workflowType, approve, approveIgnoreWarnings) {
    if (approve) {
        if (approveIgnoreWarnings) {
            var nVCollection = new nameValueCollection();
            nVCollection.add('ContentID', contentId);
            nVCollection.add('ContentTypeID', contentTypeId);
            nVCollection.add('IgnoreWarnings', approveIgnoreWarnings)
            var returnNameValueCollection = this.MakeAjaxRequest('ApproveDeclineContent', nVCollection);
            var url = this.GetDialogueUrl(3, 80, "ContentFilterType", 9);
            return this.OpenInViewer(url);
        }
        else {
            var nVCollection = new nameValueCollection();
            nVCollection.add('ContentID', contentId);
            nVCollection.add('ContentTypeID', contentTypeId);

            var returnNameValueCollection = this.MakeAjaxRequest('ApproveDeclineContent', nVCollection);
            var dialogueDisplayMode = returnNameValueCollection.item("DialogueDisplayMode").value;

            if (dialogueDisplayMode == 2) {
                var callBackItem = new CallBackItem();
                callBackItem.CallbackContext = this;
                callBackItem.CallbackID = 'ApproveContent';
                callBackItem.contentId = contentId
                callBackItem.contentTypeId = contentTypeId
                callBackItem.workflowType = workflowType
                this.ErrorDialogue(dialogueDisplayMode, returnNameValueCollection.item('message').value, returnNameValueCollection.item('title').value, callBackItem);
            }
            else {
                this.ErrorDialogue(dialogueDisplayMode, returnNameValueCollection.item('message').value, returnNameValueCollection.item('title').value);

                if (dialogueDisplayMode == 4) {
                    var url = this.GetDialogueUrl(3, 80, "ContentFilterType", 9);
                    return this.OpenInViewer(url);
                }
            }
        }
    }
    else {
        var callBackItem = new CallBackItem();
        callBackItem.CallbackContext = this;
        callBackItem.CallbackID = 'SendDeclineMessage';
        callBackItem.contentID = contentId
        callBackItem.contentTypeId = contentTypeId
        callBackItem.workflowType = workflowType

        return this.LaunchModalDialogueWithCallback(callBackItem, 168, 550, 100, "ContentID", contentId, "WorkflowType", workflowType, "ContentTypeId", contentTypeId)
    }
}

function _Global_LaunchPropagateDialog(folderId, selectedItems, workflowType, dialogToLaunch) {
    this.LaunchModalDialogue(dialogToLaunch, 550, 100, "FolderId", folderId, "SelectedItems", selectedItems, "workflowType", workflowType)
}

function _Global_UpdateEditorState(ContentID) {
    if (ContensisControlsNamespace.CurrentEditor) {
        var UpdateEditor = false
        if (this.Utils.IsUndefinedOrNull(ContentID)) {
            UpdateEditor = true
        } else {
            if (ContensisControlsNamespace.CurrentEditor.ContentID == ContentID) {
                UpdateEditor = true
            }
        }
        if (UpdateEditor) {
            try {
                //could fall over if freed script....
                ContensisControlsNamespace.CurrentEditor.UpdateState();
            } catch (e) { }
        }
    }
}

function _Global_LaunchUnarchiveDialogue(contentId, workflowType) {
    var unarchiveController = new UnarchiveController(contentId, workflowType);
    var testResult = unarchiveController.CanUnarchive();
    var callbackItem = new CallBackItem();
    callbackItem.ContentId = contentId;
    callbackItem.WorkflowType = workflowType;
    callbackItem.CallbackContext = this;
    callbackItem.CallbackID = 'Unarchive';

    switch (testResult.value) {
        case "1":
            //RESOURCE Do you wish to unarchive this item?
            //RESOURCE Confirm Unarchive
            this.ErrorDialogue(2, this.GetLabelResourceAsString(2288), this.GetLabelResourceAsString(2289), callbackItem)
            break;
        case "2":
            //RESOURCE You do not have the neccessary permissions to unarchive this item
            //RESOURCE Permission Denied
            this.ErrorDialogue(1, this.GetLabelResourceAsString(2290), this.GetLabelResourceAsString(2291), callbackItem)
            break;
        case "8": case "16": case "24":
            ContensisControlsNamespace.Global.LaunchModalDialogueWithCallback(callbackItem, 189, 500, 300, "WorkflowType", workflowType, "ContentID", contentId, "RestoreResultMode", testResult.value)
            //this.ReloadViewer();
            break;
        default:
            //RESOURCE An unspecified error has occurred. Please contact your system administrator
            //RESOURCE Permission Denied
            this.ErrorDialogue(1, this.GetLabelResourceAsString(2292), this.GetLabelResourceAsString(2293), callbackItem)
            break;
    }
}

function _Global_ImageSelected(imageID, imageVersionID, isSubImage, parentImageID, parentImageVersionID) {
    var s = ''
    if (top.window.ContensisControlsNamespace.Global.CurrentDialogueTypeIsCmsEditor()) {
        //window.focus();      
        top.window.ContensisControlsNamespace.CMSEditor.EditorTools.ImageLibrary(imageID, imageVersionID, isSubImage, parentImageID, parentImageVersionID);
    }
    else {
    }
}
//Unarchive Controller 
function UnarchiveController(contentId, workflowType) {
    this.ContentId = contentId;
    this.WorkflowType = workflowType;
    this.Global = window.top.ContensisControlsNamespace.Global;
}

UnarchiveController.prototype.CanUnarchive = _UnarchiveController_CanUnarchive;
UnarchiveController.prototype.Unarchive = _UnarchiveController_Unarchive;

function _UnarchiveController_CanUnarchive() {
    var nameValue = new nameValueCollection();
    nameValue.add('ContentID', this.ContentId);
    nameValue.add('WorkflowType', this.WorkflowType);
    nameValue.add('Simulate', true)
    var returnNameValueCollection = null;

    returnNameValueCollection = this.Global.MakeAjaxRequest('Unarchive', nameValue);
    return returnNameValueCollection.item("Result");
}

function _UnarchiveController_Unarchive(folderId, label) {
    var nameValue = new nameValueCollection();
    nameValue.add('ContentID', this.ContentId);
    nameValue.add('WorkflowType', this.WorkflowType);
    nameValue.add('Simulate', false)
    if (folderId != undefined) {
        nameValue.add('FolderId', folderId)
    }
    if (label != undefined) {
        nameValue.add('Label', label)
    }

    var returnNameValueCollection = null;

    returnNameValueCollection = this.Global.MakeAjaxRequest('Unarchive', nameValue);
}

function ReloadCmsDataview(DialogueRetunValue) {

    //ImageSelectedCaller = {Caller: editor.Funcs, Func: ImageLibrary }; 

    alert(DialogueRetunValue);
}
// leave at end
//window.ContensisControlsNamespace.Global.AddOnLoad(window.ContensisControlsNamespace.Global.CheckSession());
//window.ContensisControlsNamespace.Global.Utils.AddEvent(window.document.body,'click',window.ContensisControlsNamespace.Global.CheckSession());

function WorkFlowState(workflowAction, displayHtml) {
    this.WorkflowAction = workflowAction
    this.DisplayHtml = displayHtml
}

_Global.prototype.RegisterDropable = function(el) {
    alert(el.outerHTML);
    el.onmouseover = function() {
        if (window.top.ContensisControlsNamespace.TreeviewNavigator.NodeDragItem) {
            el.style.cursor = 'pointer';
        }
    };
    el.ondragover = function() {
        if (window.top.ContensisControlsNamespace.TreeviewNavigator.NodeDragItem) {
            el.style.cursor = 'pointer';
        }
    };
}

