﻿function OpenPopup(url, id, winwidth, winheight, scrollbars, modal) {
    var winleft = (screen.width - winwidth) / 2;
    var wintop = (screen.height - winheight) / 2;
    if (modal == true) {
        if (window.showModalDialog) {
            window.showModalDialog(url, id, 'dialogWidth:255px;dialogHeight:250px');
        } else {
            NewWindow = window.open(url, id, 'left=' + winleft + ',top=' + wintop + ',modal=yes,toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=no,copyhistory=no,width=' + winwidth + ',height=' + winheight)
            NewWindow.focus();
        }
    }
    else {
        NewWindow = window.open(url, id, 'left=' + winleft + ',top=' + wintop + ',toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=no,copyhistory=no,width=' + winwidth + ',height=' + winheight)
        NewWindow.focus();
    }
}

function CMSPageLevelGo(cmsAction, menuID) {
    if(cmsAction == 'LogOut')
    {
        window.location.href = window.location.pathname + '?logout=true';
    }
    else if(cmsAction == 'NewPage')
    {
        OpenPopup('/ControlPanel/EditPageProperties.aspx?edit_menu_id=0', 'EditPageProperties', 770, 410, 'no')
    }
    else if (cmsAction == 'NewExternalMenuLink') {
    OpenPopup('/ControlPanel/EditExternalMenuLink.aspx?edit_menu_id=0', 'EditExternalMenuLink', 770, 180, 'no')
    }
    else if (cmsAction == 'EditPageProperties')
    {
        OpenPopup('/ControlPanel/EditPageProperties.aspx?edit_menu_id=' + menuID, 'EditPageProperties', 770, 380, 'no')
    }
    else if (cmsAction == 'EditExternalMenuLink') {
    OpenPopup('/ControlPanel/EditExternalMenuLink.aspx?edit_menu_id=' + menuID, 'EditExternalMenuLink', 770, 180, 'no')
    }
    else if (cmsAction == 'EditPageContent')
    {
        OpenPopup('/ControlPanel/EditPageContent.aspx?edit_menu_id=' + menuID, 'EditPageContent', 730, 610, 'no')
    }    
    else if (cmsAction == 'MoveUpMenu') {
        window.location.href = window.location.pathname + '?move_up_id=' + menuID;
    }
    else if(cmsAction == 'MoveDownMenu')
    {
        window.location.href = window.location.pathname + '?move_down_id=' + menuID;    
    }
    else if(cmsAction == 'DeletePage')
    {
        OpenPopup('/ControlPanel/Delete.aspx?item_type=page&item_id=' + menuID, 'Delete', 400, 136, 'no')
    }
    else if (cmsAction == 'EditNewsItems')
    {
        OpenPopup('/ControlPanel/NewsItems.aspx?item_id=' + menuID, 'NewsItems', 992, 628, 'no')
    }
    else if (cmsAction == 'EditPublicDownloads') {
        OpenPopup('/ControlPanel/PublicDownloads.aspx?item_id=' + menuID, 'EditPublicDownloads', 992, 628, 'no')
    }
    else if (cmsAction == 'EditGlobalMetaTags') {
        OpenPopup('/ControlPanel/EditGlobalMetaTags.aspx?edit_menu_id=' + menuID, 'EditGlobalMetaTags', 770, 300, 'no')
    }
}

var vScrollPosition = 0;
var hScrollPosition = 0;
var doSetGrid = false;
var currentPage = -1;
var currentRowIndex = -1;
function RefreshGrid(setGrid, page, rowIndex) {
    doSetGrid = setGrid;
    currentPage = page;
    currentRowIndex = rowIndex;
    try {
        vScrollPosition = obGrid.GridBodyContainer.scrollTop;
        hScrollPosition = obGrid.GridBodyContainer.scrollLeft;
        if (page > -1) {
            if (page == obGrid.CurrentPageIndex || typeof (obGrid.CurrentPageIndex) == "undefined") {
                window.setTimeout("obGrid.refresh()", 1);
            }
            else {
                window.setTimeout("obGrid.changePage(" + page + ")", 1);
            }
        }
        else {
            window.setTimeout("obGrid.refresh()", 1);
        }
    }
    catch (err) {
    }
}

function SetGrid() {
    if (doSetGrid == true) {
        try {
            var selectedRow = obGrid.SelectedRecords[0];
            var rowIndex;
            if (currentRowIndex > -1) {
                rowIndex = currentRowIndex;
                if (currentPage == 0 && rowIndex == 0) {
                    vScrollPosition = 0;
                    hScrollPosition = 0;
                }
            }
            else {
                rowIndex = selectedRow.row_index;
            }
            if (obGrid.selectRecord(rowIndex)) {
                window.setTimeout("obGrid.selectRecord(" + rowIndex + ")", 1);
            }
            window.setTimeout("obGrid.GridBodyContainer.scrollTop = " + vScrollPosition, 1);
            window.setTimeout("obGrid.GridBodyContainer.scrollLeft = " + hScrollPosition, 1);
            vScrollPosition = 0;
            hScrollPosition = 0;
            doSetGrid = false;
            currentPage = -1;
            currentRowIndex = -1;
        }
        catch (err) {
        }
    }
}

function SelectRow(rowID) {
    try {
        setTimeout("obGrid.selectRecord(" + rowID + ")", 1);
    }
    catch (err) {
    }
}

function DeselectRow(rowID) {
    try {
        setTimeout("obGrid.deselectRecord(" + rowID + ")", 1);
    }
    catch (err) {
    }
}
