﻿/**
* LP specifik javascript
**/
if (!editMode) {
    try {
        Cufon.replace('.topnavInner a', { fontFamily: 'Klavika Rg', hover: { color: '#88d0cc'} });
        Cufon.replace('.erDuMenu h3', { fontFamily: 'Klavika Rg' });
        Cufon.replace('.erDuMenu a', { fontFamily: 'Klavika Lt' });
    }
    catch (err) {
        log('Cufon fejler: ' + err.Description);
    }
}
var Lp = {
    /**
    * @title newsCQWP
    * @description fjerner mellemrum mellem nyheds query wpparts
    **/
    tableFix: function () {
        if ($('.ms-listviewtable')) {
            $('.ms-listviewtable > tbody > tr:not(.ms-viewheadertr) td:odd').each(function () {
                $(this).addClass('odd');
            });
        }
        if ($('table.results')) {
            $('table.results').each(function () {
                $(this).find('tr:not(.expandable,.tfoot,.thead):odd').addClass('odd');
            });
        }
    },
    newsCQWP: {
        init: function () {
            $('.newsWP,.contentCol .nyhedscqwp').closest('td[id^=MSOZoneCell]').find('.ms-PartSpacingVertical').hide();
        }
    },
    async: {
        endHandler: function (sender, args) {
            var senderID = sender._postBackSettings.panelID;
            if (senderID.indexOf('Sitemap') > 1) {
                var sitemapWidget = $('div[id$=sitemapWidget]').attr('id'),
                senderType = senderID.split('Alfabetisk');
                if (owp.common !== undefined) {
                    if (sitemapWidget !== 'undefined') { owp.common.siteMap.init(sitemapWidget, senderType); }
                }
            }
        }
    },
    searchAreaField: function (searchArea) {
        var parentEle = searchArea,
            thisEle = searchArea.find('input.searchField');
        thisEle.focus(function () {
            $(this).css('background-position', '-5px -200px');
        });
        thisEle.blur(function () {
            var ele = $(this),
                value = ele.val();
            if (value == '') {
                ele.css('background-position', '-5px 0');
            }
        });
    },
    highlightErrors: function (notvalid) {
        try {
            var notvalid = notvalid;
            for (i = 0; i < notvalid.length; i++) {
                var thisEle = $(notvalid[i]),
                    thisParent = $(notvalid[i]).parent(),
                    formLine = thisEle.closest('.formLine');
                formLine.find('input:not([type=radio],[type=checkbox]),textarea').addClass('error').blur(function () {
                    formLine = $(this).closest('.formLine');
                    if (formLine.find('.notvalid:visible').length == 0) { $(this).removeClass('error'); }
                });
                formLine.prepend(thisParent);
            }
        }
        catch (err) {
            log(err);
        }
    },
    init: function () {
        var sitemapWidget = $('div[id$=sitemapWidget]').attr('id'),
            newsCQWP = $('.newsQuery'),
            searchArea = $('#search'),
            footerZone = $('#footerZone'),
            footerZoneChildren = footerZone.children();
        if (owp.common !== undefined) {
            if (sitemapWidget !== 'undefined') { owp.common.siteMap.init(sitemapWidget); }
        }
        if (newsCQWP.length > 0) { Lp.newsCQWP.init(); }
        if (footerZoneChildren.length == 0) { footerZone.closest('.footer').addClass('noWP'); }
        if (searchArea.is(':has(.searchFieldContainer)')) { Lp.searchAreaField(searchArea); }
        $('#aspnetForm').submit(function () {
            var notvalid = $('.notvalid:visible');
            if (notvalid.length > 0) { Lp.highlightErrors(notvalid); }
        });
        Lp.tableFix();
        if ($('.wizardWrapper').length != 0) { $('.wizardWrapper .btnWrapper:has(input[value=Tilbage])').addClass('backBtn'); }
        if ($('.pagecontent a').length != 0) {
            $('.pagecontent a').each(function () {
                if ($(this).attr('href').indexOf('?nostyle') != -1) {
                    log('hej');
                    $(this).bind('click', function (e) {
                        e.preventDefault();
                        var myUrl = $(this).attr('href');
                        window.open(myUrl, '_blank', 'width=570,height=450,left=400,top=200,location=no,toolbar=no,menubar=no,resizable=yes,scrollbars=yes');
                    });
                };
            });
        }
    }
}
$(document).ready(function () {
    if (editMode == undefined) {
        var editMode = $('#contentArea').is(':has(.ms-SPZone,.ms-formfieldvaluecontainer)');
    }
    if (editMode !== true) {
        Lp.init();
    }
    var lpRequestInstance;
    try {
        lpRequestInstance = Sys.WebForms.PageRequestManager.getInstance();
        lpRequestInstance.add_endRequest(Lp.async.endHandler);
    }
    catch (err) {
        log('Could not set request handlers: ' + err.Message);
    }
});
