﻿
function ConfirmSubmit(btn, strQuestion) {
    if (undefined != btn) {
        btn.disabled = true;
        if (confirm(strQuestion)) {
            btn.form.__EVENTTARGET.value = btn.name;
            btn.form.submit();
            return true;
        }
        btn.disabled = false;
        return false;
    }
}

function OpenCloseSections(openAll) {
    if (openAll) {
        $(".area").show();
        $(".openclose").toggleClass("arrowup");
    }
    else {
        $(".area").hide();
        $(".openclose").toggleClass("arrowdown");
    }
    $(".openclose").click(function () {
        var area = $(this).nextAll(".area");
        var isVisible = area.is(':visible');

        if (isVisible) {
            area.hide();
        }
        else {
            area.show();
        }
        $(this).toggleClass("arrowdown");
        $(this).toggleClass("arrowup");
    });
}

function RelocateTopInFrameElement(url) {
    if (frameElement != null) {
        if (window.top != null) {
            window.top.location = url;
        }
    }
}

function SetFckEditor(el) {
    if (undefined != el) {
        var oFCKeditor = new FCKeditor(el.name, el.style.width, el.style.height);
        oFCKeditor.BasePath = '/include/FCKeditor/';
        oFCKeditor.ToolbarSet = "Advance"
        if (el.getAttribute("ToolbarSet")) oFCKeditor.ToolbarSet = el.getAttribute("ToolbarSet")
        oFCKeditor.ReplaceTextarea();
    }
}

function SetWidthWithClientWidth(fromObjId, toObjId, offSetWidth, maxWidth) {
    var width = document.getElementById(fromObjId).clientWidth + (isNaN(offSetWidth) ? 0 : offSetWidth);

    if (!isNaN(maxWidth) && (width > maxWidth))
        width = maxWidth;

    document.getElementById(toObjId).style.width = '1px';
    document.getElementById(toObjId).style.width = width + 'px';
}

function ShowOrHide(selectorForComparableObj, selectorForViewableObj, trueValue, delay) {
    if (!selectorForComparableObj)
        throw new "selectorForComparableObj is missing!"

    if (!selectorForViewableObj)
        throw new "selectorForViewableObj is missing!"

    if (trueValue == undefined)
        throw new "trueValue is missing!"

    if (!delay)
        delay = 0;

    var show = ($(selectorForComparableObj).val() == trueValue);
    show ? $(selectorForViewableObj).show(delay) : $(selectorForViewableObj).hide(delay);
}
