jQuery.ajaxSetup( { cache: false} );

var DG_variables = {};
var DG_Functions = {};

//setting focus on popup-window, can be disabled
DG_Functions.focusPopupWindow = function () {
    var doAction = true;
    if (window.focusPopupWindow_Callback) {
        doAction = focusPopupWindow_Callback();
    }
    if (doAction) {
        window.focus();
    }
}

// css class for overlib element, it is a td
var ol_textfontclass = "overlibTdClass";
var ol_border = "0";


// Simple cookie handling
function setCookie(stName, stValue, ExpDays){
    stNewCookie = stName + "=" + escape(stValue)
    if (ExpDays){
        var exDate = new Date()
        exDate.setDate(exDate.getDate()+ExpDays)
        stNewCookie += "; expires=" + exDate.toGMTString()
    }
    document.cookie = stNewCookie
}

var myCookie = document.cookie
function getCookie(name) {
    var index = myCookie.indexOf(name + "=")
    if (index == -1) return null
    index = myCookie.indexOf("=", index) + 1
    var endstr = myCookie.indexOf(";", index)
    if (endstr == -1) endstr = myCookie.length
    return unescape(myCookie.substring(index, endstr))
}
// end Simple cookie handling

function formatDate (formatDate, formatString) {
    if(formatDate instanceof Date) {
        var months = new Array("Jan","Feb","Mar","Apr","Maj","Jun","Jul","Aug","Sep","Okt","Nov","Dec");
        var yyyy = formatDate.getFullYear();
        var yy = yyyy.toString().substring(2);
        var m = formatDate.getMonth() + 1;
        var mm = m < 10 ? "0" + m : m;
        var mmm = months[m - 1];
        var d = formatDate.getDate();
        var dd = d < 10 ? "0" + d : d;
        
        var h = formatDate.getHours();
        var hh = h < 10 ? "0" + h : h;
        var n = formatDate.getMinutes();
        var nn = n < 10 ? "0" + n : n;
        var s = formatDate.getSeconds();
        var ss = s < 10 ? "0" + s : s;
        
        formatString = formatString.replace(/yyyy/i, yyyy);
        formatString = formatString.replace(/yy/i, yy);
        formatString = formatString.replace(/mmm/i, mmm);
        formatString = formatString.replace(/mm/i, mm);
        formatString = formatString.replace(/m/i, m);
        formatString = formatString.replace(/dd/i, dd);
        formatString = formatString.replace(/d/i, d);
        formatString = formatString.replace(/hh/i, hh);
        formatString = formatString.replace(/h/i, h);
        formatString = formatString.replace(/nn/i, nn);
        formatString = formatString.replace(/n/i, n);
        formatString = formatString.replace(/ss/i, ss);
        formatString = formatString.replace(/s/i, s);
        
        return formatString;
    } else {
        return "";
    }
}

function doOpenClose(identifier) {
    var myDiv = $('#' + identifier);
    var myLink = $('#openclose_' + identifier);
    if (myDiv) {
        doAction = true;
        if (window.ad_OpenClose_Callback) {
            doAction = (ad_OpenClose_Callback(identifier));
        }
        if (window.cv_OpenClose_Callback) {
            doAction = (cv_OpenClose_Callback(identifier));
        }
        if (window.education_ad_OpenClose_Callback) {
            doAction = (education_ad_OpenClose_Callback(identifier));
        }
        if (doAction) {
            var display = myDiv.toggle().css("display");
            if (display == 'block') {
                myLink.addClass('opened');
                myLink.removeClass('closed');
            } else {
                myLink.addClass('closed');
                myLink.removeClass('opened');
            }
        }
    }
}

DG_Functions.getPopupSize = function (strClassname, defaultWidth, defaultHeight) {
    var popDiv = document.createElement('div');
    popDiv.className = strClassname;
    $(popDiv).css('display','none');
    document.body.appendChild(popDiv);
    var width = $(popDiv).css('width');
    var height = $(popDiv).css('height');
    document.body.removeChild(popDiv);
    if (width.indexOf('px') == width.length - 2) {
        width = width.substring(0, width.indexOf('px'));
    } else {
        width = defaultWidth;
    }
    if (height.indexOf('px') == height.length - 2) {
        height = height.substring(0, height.indexOf('px'));
    } else {
        height = defaultHeight;
    }
    var strWidth = (width) ? 'width=' + width + ',' : '';
    var strHeight = (height) ? 'height=' + height + ',' : '';
    return {attrWidth: strWidth, attrHeight: strHeight};
}













