﻿function ValidateSearchBox() {
    if ($('.searchinput').val() == '') {
        return false;
    }
    else {
        return true;
    }
}

function Search(item) {
        if (item == 'pages') {
            if (ValidateSearchBox()) {
                document.location = '/search/pages.aspx?keywords=' + encodeURIComponent($('.searchinput').val());
            }
            else 
            {
                alert('Indtast venligst et søgeord')
            }
        }
        else {
            document.location = '/search/' + item + '.aspx?searchinput=' +  encodeURIComponent($('.searchinput').val())
        }
        return false;
}

$(document).ready(function () {
    if ($.browser.msie && $.browser.version < 7) {
        DD_belatedPNG.fix('#frontpageimageoverlay');
        DD_belatedPNG.fix('#searchcontainer');
        DD_belatedPNG.fix('#logo img');
        DD_belatedPNG.fix('#menubanner ul ul li');
        DD_belatedPNG.fix('#bannerheading');
        DD_belatedPNG.fix('.cats input');
        DD_belatedPNG.fix('#leftbar');
        DD_belatedPNG.fix('#educationimageoverlay');
        DD_belatedPNG.fix('#bannergraphicleft');
        DD_belatedPNG.fix('#bannergraphicright');
        DD_belatedPNG.fix('#addthisfeatures a');
        DD_belatedPNG.fix('#topbanner');
        DD_belatedPNG.fix('.coursetypeaction');
        DD_belatedPNG.fix('.coursetypeitem');
        DD_belatedPNG.fix('.courseitemaction');
        DD_belatedPNG.fix('.focusitemoverlay');


    }
    /*Main Menu Start*/
    $("ul.Main li.haschildren").hover(
        function () { $(this).addClass("menuhover"); },
        function () { $(this).removeClass("menuhover"); }
    );
    $("ul.Main > li").hover(
        function () { $(this).find('ul').css({ 'display': 'block' }); },
        function () { $(this).find('ul').css({ 'display': 'none' }); }
    );

    $("ul.Main ul.Sub li a").hover(
        function () { $(this).addClass("subhover"); },
        function () { $(this).removeClass("subhover"); }
    );
    /*Main Menu End*/



    /*Autocomplete Start*/
    $(".cats").hover(
        function () { $(this).addClass("catshover"); },
        function () { $(this).removeClass("catshover"); }
    );

    $('.searchinput, #autosuggestion').focus(function () {
        $("#autosuggestion").show();
    });

    $('.searchinput').click(function (e) { e.stopPropagation(); });



    /*Trick til at ungå event bubbeling*/
    $('.searchinput').bind('keypress', function (e) {
        if (e.keyCode == 13) {
            Search('pages');
            return false;
        }
    });


    $("div.cats").click(function () {

    });
    $(". catonebutton").click(function () {
        event.stopPropagation();
    });

    $('html, body').click(function () {
        $("#autosuggestion").hide();
    });
    /*Autocomplete End*/


    /*Submenu Start*/
    $("#submenu ul li:not('.active') ").hover(
        function () {
            $(this).addClass("submenuhover");
            $(this).find("a").css("color", "#FFFFFF");
        },
        function () {
            $(this).removeClass("submenuhover");
            $(this).find("a").css("color", "black");
        });
    /*Submenu End*/

    /*Nyhedsboks Start*/
    var currenthovertab = "";
    $(".boxcontainer .tab span:not('.selected')").parent().hover(
        function () {
            currenthovertab = $(this).attr("class").split(" ")[0];
            if (currenthovertab == "articletab") {
                $(this).addClass("articletabhover");
            } else if (currenthovertab == "calendertab") {
                $(this).addClass("calendertabhover");
            } else if (currenthovertab == "newslettertab") {
                $(this).addClass("newslettertabhover");
            }
        },
        function () {
            if (currenthovertab == "articletab") {
                $(this).removeClass("articletabhover");
            } else if (currenthovertab == "calendertab") {
                $(this).removeClass("calendertabhover");
            } else if (currenthovertab == "newslettertab") {
                $(this).removeClass("newslettertabhover");
            }
        });

    $('.tab').click(function (e) {
        $(".tab span").removeClass("selected");
        $(this).find("span").addClass("selected");
        selectedtab = $(this).attr("class").split(" ")[0];
        $(".boxcontent").removeClass("displaynone");
        $(".boxcontent").addClass("displaynone");
        if (selectedtab.trim() == "articletab") {
            $(".articlecontainer").removeClass("displaynone");
        } else if (selectedtab.trim() == "calendertab") {
            $(".calendercontainer").removeClass("displaynone");
        } else if (selectedtab.trim() == "newslettertab") {
            $(".newslettercontainer").removeClass("displaynone");
        }
    });
    /*Nyhedsboks Slut*/

    /*Kursusoversigt Start*/
    $(".coursetypeitem").hover(
        function () {
            $(this).addClass("coursetypeitemhover");
        },
        function () {
            $(this).removeClass("coursetypeitemhover");

        });

    $(".courseitem").hover(
        function () {
            $(this).css("background-color", "#005da4");
            $(this).addClass("courseitemhover");

        },
        function () {
            $(this).css("background-color", "#b9c9d2");
            $(this).removeClass("courseitemhover");

        });

    $(".coursetypeitem").click(function () {
        if ($(this).hasClass("coursetypeitemactive")) {
            $(this).removeClass("coursetypeitemactive");
            $(this).parent().find(".courseitemcontainer").addClass("displaynone");
            $(this).parent().find(".coursetypeaction").show();
        }
        else {
            $(this).addClass("coursetypeitemactive");
            $(this).parent().find(".courseitemcontainer").removeClass("displaynone");
            $(this).parent().find(".coursetypeaction").hide();
        }
    });
    $(".courseitem").click(function () {
        /*lokalt
        window.location = '/kursussogning.aspx?searchinput=' + $(this).find(".coursenumber").html();*/

        /*drift*/
        window.location = '/kursossogning.aspx?searchinput=' + $(this).find(".coursenumber").html();

    });
    /*Kursusoversigt End*/


    $(".gradenavigation .navigationitem").click(function () {
        ScrollGallery($(this));
    });

    $(".navigationarrowleft").click(function () {
        if ($(".buttonimageselected").find(".imagebuttonset").html() != 1) {
            ScrollGallery($(".buttonimageselected").prev());

        }
    });
    $(".navigationarrowright").click(function () {

        if ($(".buttonimageselected").find(".imagebuttonset").html() >= 1 && parseInt($(".buttonimageselected").find(".imagebuttonset").html()) < parseInt($(".navigationitem:last ").find(".imagebuttonset").html())) {
            ScrollGallery($(".buttonimageselected").next());

        }
    });




    /*Footer*/
    //setTimeout("SetTopMarginOnFooter()", 10);

    //    if ($(".maincontainer").length != 0) {
    //        //alert("test");
    //        maincontainerheight = $(".maincontainer").height();
    //        maincontainermargintop = parseInt($(".maincontainer").css("margin-top").replace("px", ""));
    //        calculatefootermargintop = maincontainerheight + maincontainermargintop + 20;
    //        $(".footercontainer").css("margin-top", calculatefootermargintop);
    //    }

});


function SetTopMarginOnFooter() {
    if ($(".maincontainer").length != 0) {
        //alert("test");
        maincontainerheight = $(".maincontainer").height();
        maincontainermargintop = parseInt($(".maincontainer").css("margin-top").replace("px", ""));
        calculatefootermargintop = maincontainerheight + maincontainermargintop + 20;
        $(".footercontainer").css("margin-top", calculatefootermargintop);
    }
}


function SetSelectedTab() {
    $(".tab span").removeClass("selected");
    $(".newslettertab ").find("span").addClass("selected");
    $(".boxcontent").removeClass("displaynone");
    $(".boxcontent").addClass("displaynone");
    $(".newslettercontainer").removeClass("displaynone");
}
var currentimagepage = 1;
function ScrollGallery(selectedbutton) {
    $(".gradenavigation .navigationitem").removeClass("buttonimageselected").removeClass("buttonimage").addClass("buttonimage");
    $(selectedbutton).removeClass("buttonimage").addClass("buttonimageselected");


    if (currentimagepage != $(selectedbutton).find(".imagebuttonset").html()) {
        dir = currentimagepage < $(selectedbutton).find(".imagebuttonset").html() ? 1 : -1;
        //alert(Math.abs(currentimagepage - 1) * 8 * dir * 75);
        page = Math.abs(currentimagepage - $(selectedbutton).find(".imagebuttonset").html());
        scroll1 = page * 8 * dir * 86.25;
        //console.debug(scroll1);
        if (dir == 1) {
            scroll1 = scroll1 + (30 * page) ;
        }
        else {
            scroll1 = scroll1 - (30 * page);
        }

        //console.debug(scroll1);

        $(".gradeimages").animate({
            scrollLeft: "+=" + scroll1
        });
        //console.debug(scroll1);
        currentimagepage = $(selectedbutton).find(".imagebuttonset").html();
    }
}

function SetEventTab() {
    $(".tab span").removeClass("selected");
    $(".calendertab ").find("span").addClass("selected");
    $(".boxcontent").removeClass("displaynone");
    $(".boxcontent").addClass("displaynone");
    $(".calendercontainer").removeClass("displaynone");
}



// ePay Start

function ePayShow(ePaySettings) {

    var ePayForm = document.createElement("form");
    ePayForm.setAttribute("id", "ePay");
    ePayForm.setAttribute("name", "ePay");
    ePayForm.setAttribute("method", "post");
    ePayForm.setAttribute("action", "https://ssl.ditonlinebetalingssystem.dk/popup/default.asp");

    for (ePaySetting in ePaySettings) {
        var ePayHidden = document.createElement("input");
        ePayHidden.setAttribute("type", "hidden");
        ePayHidden.setAttribute("name", ePaySetting);
        ePayHidden.setAttribute("value", ePaySettings[ePaySetting]);
        ePayForm.appendChild(ePayHidden);
    }

    var ePayDiv = document.getElementById('ePayDiv');

    if (ePayDiv) {
        ePayDiv.innerHTML = "";
    }
    else {
        ePayDiv = document.createElement("div");
        ePayDiv.setAttribute("id", "ePayDiv");
    }

    ePayDiv.style.display = 'none';
    ePayDiv.appendChild(ePayForm);
    document.body.appendChild(ePayDiv);

    ePayForm.submit();
}

// ePay End
