﻿jQuery("html").addClass("js");
jQuery.noConflict();

// Format date
(function ($) {
    $.fn.formaterDato = function () {
        return this.each(function () {
            var dato = new Date($(this).text());
            $(this).empty().append(pad2(dato.getDate()) + "-" + (pad2(dato.getMonth() + 1)) + "-" + dato.getFullYear());
        });
    };
})(jQuery);

function pad2(number) {
    return (number < 10 ? '0' : '') + number
}

/*
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* http://cherne.net/brian/resources/jquery.hoverIntent.html
*/
(function ($) { $.fn.hoverIntent = function (f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function (ev) { cX = ev.pageX; cY = ev.pageY; }; var compare = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]); } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval); } }; var delay = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]); }; var handleHover = function (e) { var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; while (p && p != this) { try { p = p.parentNode; } catch (e) { p = this; } } if (p == this) { return false; } var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } if (e.type == "mouseover") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval); } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function () { delay(ev, ob); }, cfg.timeout); } } }; return this.mouseover(handleHover).mouseout(handleHover); }; })(jQuery);

/*
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*/
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend(jQuery.easing,
{
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    }
});

jQuery(function ($) {
    Engine = {
        fixes: {
            dates: function () {
                $('#press span.date').formaterDato();
                // $('#press span.date, #content span.date').formaterDato();
            }
        },
        ui: {
            searchBox: function () {
                $("#q")
          .attr("value", $("#q").attr("title"))
          .focus(function () {
              if (this.value == $('#q').attr("title")) {
                  this.value = "";
              }
          })
          .blur(function () {
              if (this.value == "") {
                  this.value = $("#q").attr("title");
              }
          });
            },
            menu: function () {
                $('#navi-main ul li:first').hoverIntent(function () {
                    $(this).find("ul:first")
                .stop(true, true)
                .slideDown(500, "easeOutExpo");
                }, function () {
                    $(this).find("ul:first")
                .stop(true, true)
                .slideUp(300, "easeOutExpo");
                });
            },
            tabs: function () {
                var tabContainers = $('div.tabs > div');
                tabContainers.hide().filter(':first').show();

                $('div.tabs ul.tabNavigation a').click(function () {
                    tabContainers.hide();
                    tabContainers.filter(this.hash).show();
                    $('div.tabs ul.tabNavigation a').removeClass('selected');
                    $(this).addClass('selected');
                    return false;
                }).filter(':first').click();
            },
            showhide: function () {
                var hiddendivs = $('div.hidden'); //selector for all the hidden div's
                var showmore = $('a.showhidden');

                showmore.live('click', function () {
                    $(this).toggleClass('on')
                    $(this).parent().nextAll('div.hidden:first').slideToggle(500)
                    if ($(this).html() == 'Skjul datoer og pris') {
                        $(this).html("Vis datoer og pris");
                    } else {
                        $(this).html("Skjul datoer og pris");
                    }
                    this.blur()
                    return false;
                })
            },

            qtip: function () {
                $('.kursus-navn [title]').qtip();
                $('.kursus-wrap img[title]').qtip({ style: { classes: 'ui-tooltip-dark' }, position: { my: 'bottom center', at: 'top center'} });
                $('.easyhold [title]').qtip({ style: { classes: 'ui-tooltip-dark' }, position: { my: 'bottom center', at: 'top center'} });
                // $('#kursist-ledig').qtip({style:{classes:'ui-tooltip-dark'},position: {my:'bottom center',at:'top center'}},{content:{text:'NB: Som ledig kan du ikke tilmelde dig online. Klik for at læse om dine muligheder som ledig. Vælg en anden kursisttype for at tilmelde dig.'}});

                $('#kursist-ledig').qtip({ content: { text: 'NB: Som ledig kan du ikke tilmelde dig online.<br/>Klik for at læse om dine muligheder som ledig.<br/>Vælg en anden kursisttype for at tilmelde dig.' }, style: { classes: 'ui-tooltip-dark' }, position: { my: 'bottom center', at: 'top center'} });

                // $('.easyhold').qtip({content: {text: $('.qtip-big').html},style:{classes:'ui-tooltip-dark'},position: {my:'bottom center',at:'top center'}});
            },

            zebratable: function () {
                $("table.tablecolors tr:even").addClass("even");
                $("table.tablecolors tr:odd").addClass("odd"); //This is not required - you can avoid this if you have a table background
                $("table.tablecolors tr").hover(function () {
                    $(this).addClass("hovcolor");
                }, function () {
                    $(this).removeClass("hovcolor");
                });
                $("table.tablecolors tr").click(function () {
                    //$("table.tablecolors tr").removeClass("highlightcolor"); // Remove this line if you dont want to de-highlight the previously highlighted row
                    $(this).toggleClass("highlightcolor");
                });
            },

            print: function () {
                $("#print")
          .html("<a href='#' title='Udskriv (CTRL + P)'><span>Udskriv</span></a>")
          .click(function () { window.print(); return false; });
            }

        }
    }
});

/*  On DOM loaded */
jQuery(document).ready(function ($) {
    Engine.ui.menu();
    Engine.ui.searchBox();
    Engine.ui.tabs();
    Engine.ui.showhide();
    Engine.ui.qtip();
    Engine.ui.zebratable();
    Engine.ui.print();
});

/*  On WINDOW loaded */
jQuery(window).load(function ($) {
    Engine.fixes.dates();
});



/*
From DWscript.js
*/
function isRadioButtonChecked(theOption, theForm) {
    if (theForm.elements[theOption].checked) {
        return true;
    }
    else {
        for (i = 0; i < theForm.elements[theOption].length; i++) {
            if (theForm.elements[theOption][i].checked) {
                return true;
            }
        }
    }
    return false;
}
function validateEmail(email) {
    var regExp = /^[\w\-_]+(\.[\w\-_]+)*@[\w\-_]+(\.[\w\-_]+)*\.[a-z]{2,4}$/i;
    return regExp.test(email);
}
      
