$(document).ready(function () {

	var sHeadline = $('.page-navigator').find('a').eq(2).html();

	if ((sHeadline==null))
		sHeadline = $('.page-navigator').find('b').html();

	if (sHeadline!="")	
	{
		$("#lasfHeaderContainer").html( sHeadline );
	}

	// initialize Input fields
	inputInitValue();
	$("#eid241737 #form_3328").attr("readonly","true");
	
});

/*******************************************
FUNCTIONS
*******************************************/


/* Clear and set initial value of input fields */
function inputInitValue() {

	$("*[@behaviours='inputInitValue']").focus(function() {

		if (!$(this).attr("oldValue")) {
			$(this).attr("oldValue", $(this).attr("value"));
		}
		
		if ($(this).attr("value") == $(this).attr("oldValue")) {
			$(this).attr("value", "");
		}
	});
	
	$("*[@behaviours='inputInitValue']").blur(function() {
	
		if (!$(this).attr("value")) {
				$(this).attr("value", $(this).attr("oldValue"));
		}
	});
}

/*******************************************
Pop up - medlemmer/nyhedsbrev
*******************************************/


var tab;
var dimmer;
var content;

$(document).ready(function() {

	tab = $(".adZone .tab");
	dimmer = $(".bgDimmer");
	adZone = $(".adZone");
	content = $(".adZone .content");
	btn_close = $(".adZone .close");
	
	//initPopup();
	btn_close.click(function(){
		tab.click();						 
	})


});

function getUserNewsletter() {
	var loggedIn = $(".top .logininfo .brugernavn");
	
	if (loggedIn.length > 0) {
		$.getJSON("/sw/frontend/user_newsletter.asp", function(json) {

			//alert("JSON Data: " + json.user_newsletter.length);
			if(json.user_newsletter.length <= 0) {
					initPopup();
			}
			//alert("JSON Data: " + json.user_id);
		});
	}
}

function initPopup() {
	var dimmerHideByUser = getCookie("dimmerHideByUser");
	//alert(dimmerHideByUser);
	if (dimmerHideByUser != "true") {
		openPopup();
		tab.toggle(closePopup, openPopup);
	} 
	else {
		tab.toggle(openPopup, closePopup);
	}

}

function closePopup() {

	tab.removeClass("active");
	adZone.hide("slow");
	dimmer.fadeTo("slow", 0.00, function(){dimmer.hide()});
	setCookie("dimmerHideByUser", "true");
}

function openPopup() {

	//alert(dimmerHideByUser);
	tab.addClass("active");
	adZone.show("slow");
	dimmer.show();
	dimmer.fadeTo("slow", 0.90);
	delCookie("dimmerHideByUser");
}


function setCookie (name, value) {
    document.cookie = name + "=" + escape (value) + "; path=/";
	//alert(value);
}

function getCookie (name) {
    var dcookie = document.cookie; 
    var cname = name + "=";
    var clen = dcookie.length;
    var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
            if (dcookie.substring(cbegin, vbegin) == cname) { 
            var vend = dcookie.indexOf (";", vbegin);
                if (vend == -1) vend = clen;
            return unescape(dcookie.substring(vbegin, vend));
            }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
            if (cbegin == 0) break;
        }
    return '';
    }
	
function delCookie (name) {
    var expireNow = new Date();
    document.cookie = name + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}
