﻿var KEYCODE_ESC = 27;
(function($) {
    $.extend({
        RatingSelect: function() {
            $(".cedRating li").click(function() {
                if ($("#oqRating").length > 0 && $("#cedCorrectAnswer").length == 0) {
                    $("a[id*='lnkbtnSubmitAnswer']").removeClass('hiddenBtn');
                }
                if ($("input[id*='hdfShowCheckAnswer']").val()) {
                    $("a[id*='lnkbtnCheckAnswer']").removeClass('hiddenBtn');
                } else {
                    $("a[id*='lnkbtnSubmitAnswer']").removeClass('hiddenBtn');
                }
                if (!$("input[id*='disableReflection']").val()) {
                    $(".cedRating li").removeClass("cedSelected");
                    if ($("input[id*='hdfReflection']").length) {
                        $("input[id*='hdfReflection']").val(this.children[0].className);
                    }
                    $(this).addClass("cedSelected");
                }
                return false;
            });
            $(".cedRating li").dblclick(function() {
                if (!$("input[id*='disableReflection']").val()) {
                    $(".cedRating li").removeClass("cedSelected");
                }
                return false;
            });
            $(".cedRating li a").click(function() {
                if ($("#oqRating").length > 0 && $("#cedCorrectAnswer").length == 0) {
                    $("a[id*='lnkbtnSubmitAnswer']").removeClass('hiddenBtn');
                }
                if ($("input[id*='hdfShowCheckAnswer']").val()) {
                    $("a[id*='lnkbtnCheckAnswer']").removeClass('hiddenBtn');
                } else {
                    $("a[id*='lnkbtnSubmitAnswer']").removeClass('hiddenBtn');
                }
                if (!$("input[id*='disableReflection']").val()) {
                    $(".cedRating li").removeClass("cedSelected");
                    if ($("input[id*='hdfReflection']").length) {
                        $("input[id*='hdfReflection']").val(this.className);
                    }
                    $(this.parentNode).addClass("cedSelected");
                }
                return false;
            });
        },
        CloseMessage: function() {
            $(".cedContent-b .cedClose-b").click(function() {
                $(".cedContainer .cedContent-b .cedOverlay").height($(".cedContent-b").height());
                var messageTop = ($(".cedContent-b").height() - $(".cedContainer .cedContent-b #cedLaptopLogout").height()) / 2;
                $(".cedContainer .cedContent-b #cedLaptopLogout").css({ top: messageTop });
                $(".cedContainer .cedContent-b .cedOverlay").show();
                $(".cedContainer .cedContent-b #cedLaptopLogout").show();
                return false;
            });
            $(".cedContainer .cedContent-b #cedAlertCaller").click(function() {
                $(".cedContainer .cedContent-b .cedOverlay").height($(".cedContent-b").height());
                var messageTop = ($(".cedContent-b").height() - $(".cedContainer .cedContent-b #cedAlert").height()) / 2;
                $(".cedContainer .cedContent-b #cedAlert").css({ top: messageTop });
                $(".cedContainer .cedContent-b .cedOverlay").show();
                $(".cedContainer .cedContent-b #cedAlert").show();
                return false;
            });
            $(".cedContainer .cedContent-b #cedAlertOk").click(function() {
                $(".cedContainer .cedContent-b .cedOverlay").hide();
                $(".cedContainer .cedContent-b #cedAlert").hide();
                return false;
            });
            $(".cedContainer .cedContent-b #cedLaptopLogoutNo").click(function() {
                $(".cedContainer .cedContent-b .cedOverlay").hide();
                $(".cedContainer .cedContent-b #cedLaptopLogout").hide();
                return false;
            });
        },
        ShowLoginBlock: function() {
            $(".cedReception-b .cedLogin-l").click(function() {
                $(".cedLogin-b").show();
                $(".cedLogin-b .cedField")[0].focus();
                $(".cedOverlay1").height($(window).height());
                $(".cedOverlay1").show();
                return false;
            });
            $(".cedOverlay1").click(function() {
                $(".cedLogin-b").hide();
                $(".cedOverlay1").hide();
                return false;
            });
            $(".cedLogin-b .cedCloseButton").click(function() {
                $(".cedLogin-b").hide();
                $(".cedOverlay1").hide();
                return false;
            });
        },
        ShowUploadBlock: function() {
            $(".cedKantoor-b .cedPhotoUpload").click(function() {
                $(".cedUpload-b").show();
                $(".cedOverlay1").height($(window).height());
                $(".cedOverlay1").show();
                return false;
            });
            $(".cedOverlay1").click(function() {
                $(".cedUpload-b").hide();
                $(".cedOverlay1").hide();
                return false;
            });
            $(".cedUpload-b .cedCloseButton").click(function() {
                $(".cedUpload-b").hide();
                $(".cedOverlay1").hide();
                return false;
            });
        },
        HelpMessage: function() {
            $(".cedHelp-icon").click(function() {
                $(".cedOverlay1").height($(window).height());
                var messageTop = ($(window).height() - $(".cedHelp-b").height()) / 2;
                $(".cedHelp-b").css({ top: messageTop });
                $(".cedOverlay1").show();
                $(".cedHelp-b").show();
                return false;
            });
            $(".cedContainer .cedStartscherm-b .cedHelp-icon").click(function() {
                $(".cedOverlay1").height($(window).height());
                $(".cedHelp-b").css({ top: 'auto' });
                $(".cedOverlay1").show();
                $(".cedHelp-b").show();
                return false;
            });
            $(".cedHelp-l").click(function() {
                $(".cedOverlay1").height($(window).height());
                $(".cedOverlay1").show();
                $(".cedHelp-b").show();
                return false;
            });
            $(".cedOverlay1").click(function() {
                $(".cedOverlay1").hide();
                $(".cedHelp-b").hide();
                return false;
            });
            $(".cedHelp-b .cedTitle-b .cedClose-b").click(function() {
                $(".cedOverlay1").hide();
                $(".cedHelp-b").hide();
                return false;
            });
            $(".cedHelp-b .cedTitle-b .cedClose-help").click(function() {
                $(".cedOverlay1").hide();
                $(".cedHelp-b").hide();
                return false;
            });
        },
        SearchBlock: function() {
            $(".cedSearch-l").click(function() {
                $(".cedOverlay1").height($(window).height());
                var messageTop = ($(window).height() - $(".cedHelp-b").height()) / 2;
                $(".cedSearch-b").css({ top: messageTop });
                $(".cedOverlay1").show();
                $(".cedSearch-b").show();
                return false;
            });
            $(".cedOverlay1").click(function() {
                $(".cedOverlay1").hide();
                $(".cedSearch-b").hide();
                return false;
            });
            $(".cedSearch-b .cedTitle-b .cedClose-b").click(function() {
                $(".cedOverlay1").hide();
                $(".cedSearch-b").hide();
                return false;
            });
        },
        ExtraBlock: function() {
            $(".cedContent-b .cedNav-b li").each(function(index) {
                $(this).click(function() {
                    $(".cedContent-b .cedNav-b li").not(this).removeClass("cedSelected");
                    $(this).toggleClass("cedSelected");
                    var ExtraBlockHeight = $(".cedContent-b").height() - $(".cedContent-b .cedTitle-b").height() - $(".cedContent-b .cedNav-b").height() - 50;
                    $(".cedExtra-container li.cedExtra-b").not("[class$=" + (index + 1) + "]").hide();
                    $(".cedExtra-container li[class$=" + (index + 1) + "]").toggle();
                    $(".cedExtra-container li[class$=" + (index + 1) + "]").height(ExtraBlockHeight);
                    return false;
                });
            });
        },
        ButtonsDisable: function() {
            $("input.cedAgreeBtn").click(function() {
                $("input.cedAgreeBtn").css({ 'background-position': '0 0', 'color': '#FFFFFF' });
                $("input.cedDisagreeBtn").css({ 'background-position': '0 -75px', 'color': '#dad8d8' });
            });
            $("input.cedDisagreeBtn").click(function() {
                $("input.cedDisagreeBtn").css({ 'background-position': '0 0', 'color': '#FFFFFF' });
                $("input.cedAgreeBtn").css({ 'background-position': '0 -75px', 'color': '#dad8d8' });
            });
        },
        ChoosePictureTextPosition: function() {
            $(".cedPhotoPreviewControl .cedControls").each(function(ind1) {
                var PrevEl = $("> .cedRow > input", this);
                $("> .cedRow > input", this).each(function(index) {
                    $(this).change(function() {
                        PrevEl.removeAttr('checked');
                        $(this).attr({ checked: 'checked' });
                        var PicturePosition = -(161 * index);
                        $(".cedPhotoPreview:eq(" + ind1 + ")").css({ 'background-position': '0 ' + PicturePosition + 'px' });
                    });
                });
            });
        },
        TerminHeight: function() {
            $(".cedMatch-b .cedDescriptionBlock .cedDescription").each(function() {
                var height = $(this).height();
                $(".cedMatch-b .cedTerminBlock .cedTermin").each(function() {
                    $(this).height(height - 10);
                });
            });
        },
        equalHeight: function() {
            var equalColumnLeft = $(".cedContainerMain .cedContentBlock .cedLeftColumn .cedInside").height();
            var equalColumnRight = $(".cedContainerMain .cedContentBlock .cedRightColumn").height();
            var containerHeight = $(window).height();
            var difference = 75 + $(".cedContainerMain .cedHeader").height();
            $(".cedContainerMain .cedContentBlock .cedLeftColumn .cedInside").height(containerHeight - difference);
            $(".cedContainerMain .cedContentBlock .cedRightColumn").height(containerHeight - difference);
        },
        scrollContent: function() {
            var ColumnLeftHeight = $('.cedContainerMain .cedContentBlock .cedLeftColumn').height() - 40;
            var TitleLeftHeight = $('.cedContainerMain .cedContentBlock .cedLeftColumn .cedMainTitle').height() + 10;
            $('.cedLeftColumn .cedMenu').height(ColumnLeftHeight - TitleLeftHeight);
            var ColumnRightHeight = $('.cedContainerMain .cedContentBlock .cedRightColumn').height() - 40;
            var TitleRightHeight = $('.cedContainerMain .cedContentBlock .cedRightColumn .cedMainTitle').height() + 10;
            var TabsHeigth = $('.cedContainerMain .cedNavBlock .cedTabs').height() + 10;
            $('.cedRightColumn .cedContent-d').height(ColumnRightHeight - TitleRightHeight - TabsHeigth);
        },
        containerWidth: function() {
            if ($(document).width() < 1002) {
                $(".cedContainerMain").width(980);
            }
            if ($(document).width() > 1278) {
                $(".cedContainerMain").width(1256);
            }
            else {
                $(".cedContainerMain").width(100 + '%');
            }
            if ($(document).width() < 1002) {
                $(".cedFooterMain").width(980);
            }
            if ($(document).width() > 1278) {
                $(".cedFooterMain").width(1256);
            }
            else {
                $(".cedFooterMain").width(100 + '%');
            }
        },
        MagazineTitleHeight: function() {
            $(".cedContentBox .cedTitleRow").each(function() {
                var maxHeight = 0;
                $(".cedContentBox .cedTitleRow").each(function() {
                    if ($(this).height() > maxHeight) {
                        maxHeight = $(this).height();
                    }
                });
                $(this).height(maxHeight);
            });
        },
        init: function() {
            $(window).resize(function() {
                var messageTop1 = ($(window).height() - $(".cedHelp-b").height()) / 2;
                $(".cedHelp-b").css({ top: messageTop1 });
                $(".cedContent-b .cedHelp-b").css({ top: 'auto' });
                $(".cedOverlay1").height($(window).height());
                $.equalHeight();
                $.scrollContent();
                $.containerWidth();
            });
            $(window).scroll(function() {
                var messageTop1 = ($(window).height() - $(".cedHelp-b").height()) / 2 + $(window).scrollTop();
                $(".cedHelp-b").css({ top: messageTop1 });
                $(".cedContent-b .cedHelp-b").css({ top: 'auto' });
            });
            $(window).load(function() {
                $(document).keypress(function(event) {
                    if (event.keyCode == '27') { $(".cedPopUp .cedClose1").click(); $(".cedPopUp .cedClose").click(); }
                });
                $(".cedMessage-b1 .cedButton2").click(function() {
                    hideMessage();
                });
                $.RatingSelect();
                $.CloseMessage();
                $.ShowLoginBlock();
                $.HelpMessage();
                $.SearchBlock();
                $.ShowUploadBlock();
                $.ExtraBlock();
                $.ButtonsDisable();
                $.ChoosePictureTextPosition();
                $.TerminHeight();
                $.containerWidth();
                if ($(".cedClicableTable tr").length) $(".cedItemsTable tr").clickable();
                $.equalHeight();
                $.scrollContent();
                $("#cedDatepicker").DatePicker({
                    format: 'm-d-Y',
                    date: $('#cedDatepicker').val(),
                    current: $('#cedDatepicker').val(),
                    position: 'r',
                    onBeforeShow: function() {
                        $('#cedDatepicker').DatePickerSetDate($('#cedDatepicker').val(), true);
                    },
                    onChange: function(formated, dates) {
                        $('#cedDatepicker').val(formated);
                        $('#cedDatepicker').DatePickerHide();
                    }
                });
                $("#DatePickerBtn").click(function() {
                    $("#cedDatepicker").DatePickerShow();
                });
                $("#cedDatepicker1").DatePicker({
                    format: 'm-d-Y',
                    date: $('#cedDatepicker1').val(),
                    current: $('#cedDatepicker1').val(),
                    position: 'r',
                    onBeforeShow: function() {
                        $('#cedDatepicker1').DatePickerSetDate($('#cedDatepicker1').val(), true);
                    },
                    onChange: function(formated, dates) {
                        $('#cedDatepicker1').val(formated);
                        $('#cedDatepicker1').DatePickerHide();
                    }
                });
                $("#DatePickerBtn1").click(function() {
                    $("#cedDatepicker1").DatePickerShow();
                });
                var loginTop = -$("body.cedLoginPage .cedLoginBlock").height() / 2;
                $("body.cedLoginPage .cedLoginBlock").css({
                    'margin-top': loginTop
                });
                $.MagazineTitleHeight();
                $(".cedUploadField .cedHiddenField input").change(function() {
                    var fieldValue = $(this).val();
                    $(".cedUploadField .cedTextField").val(fieldValue);
                });
                var inputs = $("input[type='text']");
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].onfocus = function() {
                        if ($(this).attr("alt") && this.value.indexOf($(this).attr("alt")) == 0) { this.value = ''; }
                    };
                    inputs[i].onblur = function() {
                        if (this.value == '') { this.value = $(this).attr("alt"); }
                    };
                }
                $('.cedMatchText .cedInsideBlock').height('auto');
                var maxHeight = 0;
                $('.cedMatchText .cedInsideBlock').each(function() {
                    if ($(this).height() > maxHeight) {
                        maxHeight = $(this).height();
                    }
                });
                $('.cedMatchText .cedInsideBlock').height(maxHeight);
                $(".cedWoordewebStartBlock .cedWordButton").each(function() {
                    $(".cedWoordewebStartBlock .cedWordButton").hover(function() {
                        var Title = $(this).text();
                        var Description = $(this).attr("title");
                        $(".cedWordDescription .cedInsideMiddle h5").html(Title);
                        $(".cedWordDescription .cedInsideMiddle p").html(Description);
                    });
                });
                var subNavWidth = 0;
                $(".cedSubNav li").each(function() {
                    var subNavElWidth = $(this).width() + 21;
                    subNavWidth += subNavElWidth;
                });
                $(".cedSubNav ul").width(subNavWidth);
                $(".cedBottomMenu  li").hover(
function() {
    $(this).addClass("cedHover");
    $("> ul", this).show();
},
function() {
    $(this).removeClass("cedHover");
    $("> ul", this).hide();
}
);
                var textareas = $("textarea");
                for (var i = 0; i < textareas.length; i++) {
                    textareas[i].onfocus = function() {
                        if ($(this).attr("alt") && (this.value == $(this).attr("alt"))) { this.value = ''; }
                    };
                    textareas[i].onblur = function() {
                        if (this.value == '') { this.value = $(this).attr("alt"); }
                    };
                }
            });
        }
    });
})(jQuery);
jQuery(function($) {
    $.init();
});
function initTreeMenu() {
    $(".cedLeftColumn .cedMenu li a").each(function() {
        if (!$(this).parent("li").hasClass("menuProcessed")) {
            $(this).parent("li").addClass("menuProcessed");
            if (!$(this).parent("li").has("ul").length) {
                $(this).addClass("NoBg");
            }
            $(this).click(function() {
                if ($(this).parent("li").has("ul").length) {
                    if ($(this).parent("li").parent("ul").attr('id') == 'cedTeacherMenu') {
                        $('#cedTeacherMenu li').removeClass("cedCurrent");
                    } else {
                        children = $(this).parent("li").parent("ul").children();
                        for (var i = 0; i < children.length; i++) {
                            $(children[i]).removeClass("cedCurrent");
                        }
                    }
                    $(this).parent("li").addClass("cedCurrent");
                    $.equalHeight();
                }
                if ($(this).parent("li").hasClass("cedCurrent") || !$(this).parent("li").has("ul").length) {
                    var PrevSelected = $(".cedLeftColumn .cedMenu li a.cedSelected");
                    if (this == PrevSelected[0])
                        return;
                    $(this).addClass("cedSelected");
                    PrevSelected.removeClass("cedSelected");
                    PrevSelected = $(this);
                }
            });
        }
    });
}
function cedAlert(message, title) {
    if (!message) {
        message = $("input[id*='hdfAlertMessage']").val();
    }
    $('#cedAlertMessage').html(message);
    if (!title) {
        title = $('title').html().replace('CED', '');
    }
    $('#cedAlertTitle').html(title);
    $(".cedContainer .cedContent-b .cedOverlay").height($(".cedContent-b").height());
    var messageTop = ($(".cedContent-b").height() - $(".cedContainer .cedContent-b #cedAlert").height()) / 2;
    $(".cedContainer .cedContent-b #cedAlert").css({ top: messageTop });
    $(".cedContainer .cedContent-b .cedOverlay").show();
    $(".cedContainer .cedContent-b #cedAlert").show();
}
function cedSmileQuestionResult(correct, total) {
    if (correct == total) {
        $('.cedFirst').parent().addClass('cedSetSelected')
    } else if (correct == 0) {
        $('.cedThird').parent().addClass('cedSetSelected')
    } else {
        $('.cedSecond').parent().addClass('cedSetSelected')
    }
}
function showMessage() {
    $(".cedMessage-b1").show();
    $(".cedOverlay1").show();
}
function hideMessage() {
    $(".cedMessage-b1").hide();
    $(".cedOverlay1").hide();
}
function closeMagazine() {
    var l = window.history.length;
    if ($.browser.msie)
        l++;
    if (l > 1) {
        window.history.back();
    } else {
        window.close();
    }
}
