﻿var PreviousSize = 0;
var PreviewModeOn = false;

function resize() {
    if (document != null && document.body != null && document.documentElement != null) {
        var htmlheight = document.body.scrollHeight;
        var windowheight = document.documentElement.clientHeight;
        // indien je een 2é scrollbalk wil zodat het volledige hoofdmenu zichtbaar is: volgende regel uit commentaar zetten
        //  en in de stylesheet bij "body" de overflow op auto zetten.
        //if(windowheight < 700) windowheight = 700;
        var correctiefactor = 30;
        var headerHeight = 206;

        var hoofdMenu = document.getElementById("hoofdMenu");
        var content = document.getElementById("content");
        var menuItem = document.getElementById("menuItem");
        
        var contentHeight = windowheight - headerHeight;
        if (contentHeight < 0) contentHeight = 0;
        var hoofdMenuHeight = windowheight - headerHeight;
        if (hoofdMenuHeight < 0) contentHeight = 0;
        var menuItemHeight = windowheight - headerHeight + correctiefactor;

        document.body.style.height = windowheight + "px";
        if (hoofdMenu != null) hoofdMenu.style.height = hoofdMenuHeight + "px";
        if (content != null) content.style.height = contentHeight + "px";
        if (menuItem != null) {
            menuItem.style.height = menuItemHeight + "px";

            if (content != null) content.style.width = 600 + "px";
        }
        else {
            if (content != null) content.style.width = 740 + "px";
        }
    }
}

function initLightbox(relAttribute) {

    // Use this example, or...
    $('a[@rel*=' + relAttribute + ']').lightBox(); // Select all links that contains lightbox in the attribute rel
    // This, or...
    //$('#gallery a').lightBox(); // Select all links in object with gallery ID
    // This, or...
    //$('a.lightbox').lightBox(); // Select all links with lightbox class
    // This, or...
    //$('a').lightBox(); // Select all links in the page
    // ... The possibility are many. Use your creative or choose one in the examples above
}

function resizeCms() {
    if (document != null && document.body != null && document.documentElement != null) {
        var htmlheight = document.body.scrollHeight;
        var windowheight = document.documentElement.clientHeight;
        var correctiefactor = 70;
        var headerHeight = 40;
        //alert("htmlheight: " + htmlheight + " windowheight: " + windowheight);

        var centerScreen = document.getElementById("cmsCenterScreen");
        var hoofdMenu = document.getElementById("ctl00_cmsHoofdMenu");
        var content = document.getElementById("ctl00_cmsInhoudHolder");
        var previewTab = document.getElementById("ctl00_ContentPlaceHolder1_tcMenu_tbPreview");
        if (previewTab == null) {
            previewTab = document.getElementById("ctl00_ContentPlaceHolder1_tcMenuitem_tbPreview");
        }
        //alert("centerscreen: " + centerScreen + " hoofdMenu: " + hoofdMenu + " content: " + content + " previewTab: " + previewTab);
        
        var centerScreenHeight = windowheight;
        if (centerScreenHeight < 0) centerScreenHeight = 0;
        var hoofdMenuHeight = windowheight - headerHeight;
        if (hoofdMenuHeight < 0) centerScreenHeight = 0;
        document.body.style.height = windowheight + "px";
        if (centerScreen != null) centerScreen.style.height = centerScreenHeight + "px";
        if (hoofdMenu != null) hoofdMenu.style.height = hoofdMenuHeight + "px";
        if (content != null) content.style.height = centerScreenHeight - headerHeight + "px";
        if (previewTab != null) {
            previewTab.style.height = centerScreenHeight - headerHeight - correctiefactor + "px";
        }
                
        //alert("centerScreenHeight: " + centerScreenHeight + " hoofdMenuHeight: " + hoofdMenuHeight);
        //alert("document.body.style.height: " + document.body.style.height + " content.style.height: " + content.style.height);
        //alert("centerScreen.style.height: " + centerScreen.style.height);
    }
}

function SelectDate(calendarClientID, inputClientID) {
    var calendar = Sys.Application.findComponent(calendarClientID.id); //"ctl00_ContentPlaceHolder1_tcNieuws_tbInstellingen_frmViewNieuwsInstellingen_calDatum"
    var input = document.getElementById(inputClientID.id);
    calendar.popupBeside(input, C1.Web.UI.PositioningMode.bottomLeft);
}

function CalendarClosed(sender, eventArgs) {
    var calendar = Sys.Application.findComponent(sender._element.id);
    var textInput = document.getElementById(sender._element.id + "Txt");
   // var calendar = Sys.Application.findComponent(calendarClientID.id);  //"ctl00_ContentPlaceHolder1_tcNieuws_tbInstellingen_frmViewNieuwsInstellingen_calDatum"
   // var input = document.getElementById(inputClientID.id);
    // input.value = calendar.get_selectedDate().toLocaleDateString();
    textInput.value = calendar.get_selectedDate().toLocaleDateString();
    var form = document.getElementById("aspnetForm");
    form.submit();   
}

function textboxMultilineMaxNumber(txt, maxLen) {
    try {
        if (txt.value.length > (maxLen - 1)) {
            if (window.event) {
                event.returnValue = false;
            }
            else {
                return false;
            }
        }
    } catch (e) {
    }
}

function OpenC1Window(clientID) {
    var C1Win = $get(clientID).control;
    C1Win.show();
}

function CloseC1Window(clientID) {
    var C1Win = $get(clientID).control;
    C1Win.hide();
}

function NewMailing(editorID) {
    var editor = Sys.Application.findComponent(editorID.id);
    editor.set_text("");
}

function OpenMailing(editorID) {
    var editor = Sys.Application.findComponent(editorID.id);
    PageMethods.OpenMailingWebMethod(OpenMailingSucceeded, OpenMailingFailed);

    function OpenMailingSucceeded(mailingText, userContext, methodName) {
        if (editor != null) {
            editor.set_text("");
            editor.insertHTML(mailingText);
        }
        //editor.set_editorMode("WYSIWYG");
    }
    function OpenMailingFailed(error, userContext, methodName) {
        alert("fout tijdens ophalen opgeslagen mailing ("+error+")");
    }
}

function InitInsertImage(editorID) {
    var editor = Sys.Application.findComponent(editorID.id);
    PageMethods.InsertImageWebMethod(editor.get_text(), InitInsertImageSucceeded, InitInsertImageFailed);

    function InitInsertImageSucceeded(link, userContext, methodName) {
        document.location.href = link;       
    }
    function InitInsertImageFailed(error, userContext, methodName) {        
        alert("fout tijdens invoegen foto. Contacteer de beheerder van het CMS indien deze fout zich blijft voordoen. (" + error + ")");
    }
}