function getCookieVal(offset) {
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1)
                endstr = document.cookie.length;
                return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie(name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
                return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0) break;
        }
        return null;
}



function SetCookie(name, value) {

	//alert(name + " = " + value);
	var exp = new Date();     //set new date object 
	exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 60));

	document.cookie = name + '[\'' + value + '\']' + "=" + escape(value) + "; path=/" + ((exp == null) ? "" : "; expires=" + exp.toGMTString()); 

	var removeCookie = '<A HREF=\"javascript: DeleteCookie(\'' + value + '\');\"><IMG SRC="/design_images/fjern_favorit.png" ALT="Fjern fra favoriter" BORDER=0></A>&nbsp;&nbsp;';
	var idName = 'ADD_REMOVE_' + value;

	if (document.getElementById) {
		document.getElementById(idName).innerHTML = removeCookie;
	} else if (document.all) {
		document.all[idName].innerHTML = removeCookie;
	}

	CookieCount();
}

function DeleteCookie(name) {

	tmpName = 'dkb_favorits[\'' + name + '\']';
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	//// This cookie is history
	var cval = GetCookie (tmpName);
	document.cookie = tmpName + "=" + cval + "; expires=" + exp.toGMTString();

	var addCookie = '<A HREF=\"javascript: SetCookie(\'dkb_favorits\', \'' + name + '\');\"><IMG SRC="/design_images/tilfoej_favorit.png" ALT="Tilføj til favoriter" BORDER=0></A>&nbsp;&nbsp;';
	var idName = 'ADD_REMOVE_' + name;

	if (document.getElementById) {
		document.getElementById(idName).innerHTML = addCookie;
	} else if (document.all) {
		document.all[idName].innerHTML = addCookie;
	}

	CookieCount();

}

function CookieCount() {

        var xCookie = document.cookie.split(';');
		var iCount = 0;

		for (i=0;i<xCookie.length;i++) {
	        if (xCookie[i].substring(1, 17) == 'dkb_favorits') {
			iCount += 1;
		}
        }


	if (document.getElementById) {
		document.getElementById("DKB_FAVORITS").innerHTML = iCount + '&nbsp;&nbsp;&nbsp;';
	} else if (document.all) {
		document.all["DKB_FAVORITS"].innerHTML = iCount + '&nbsp;&nbsp;&nbsp;';
	}
}


function showFavorits(value) {

        var xCookie = document.cookie.split(';');
	var iCount = 0;

	for (i=0;i<xCookie.length;i++) {
		if (xCookie[i].substring(1, 17) == 'dkb_favorits') {
			iCount += 1;
		}
        }


	if (iCount < 1) {
		alert("Du har ingen pladser i dine favoritter");
	
	} else {

		document.location.href ="mine-favoritter.html";
	}
}


function setPointerStyle(e, func) {

	if (func=='over') {
		cursortype = 'hand'
	} else if (func=='out') {
		cursortype = ''
    }
	e.style.cursor=cursortype;
}

function init() {

        var xCookie = document.cookie.split(';');
		var iCount = 0;
		var removeCookie = '';
		var idName = '';

		for (i=0;i<xCookie.length;i++) {
	        if (xCookie[i].substring(1, 17) == 'dkb_favorits') {
				iCount += 1;
				var cookieVal = xCookie[i].split("=");

				removeCookie = '<A HREF=\"javascript: DeleteCookie(\'' + cookieVal[1] + '\');\">Fjern fra favoritter</A>';
				idName = 'ADD_REMOVE_' + cookieVal[1];

				if (document.getElementById) document.getElementById(idName).innerHTML = removeCookie;
				else if (document.all) document.all[idName].innerHTML = removeCookie;
			}
        }

		if (document.getElementById) document.getElementById("DKB_FAVORITS").innerHTML = iCount + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		else if (document.all) document.all["DKB_FAVORITS"].innerHTML = iCount + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
}

function fill_bg_resize() {

	var iHeight = document.body.scrollHeight - 773;

	if (iHeight > 0) {

		document.all.LEFT_TOP_FILL_BG.style.height = 6;
		document.all.LEFT_MIDDLE_FILL_BG.style.height = iHeight;
		document.all.LEFT_BOTTOM_FILL_BG.style.height = 6;

		document.all.LEFT_TOP_FILL_BG.style.backgroundImage = 'url(/design_images/left_top_fill_bg.gif)';
		document.all.LEFT_MIDDLE_FILL_BG.style.backgroundImage = 'url(/design_images/left_middle_fill_bg.gif)';
		document.all.LEFT_BOTTOM_FILL_BG.style.backgroundImage = 'url(/design_images/left_bottom_fill_bg.gif)';
	}

	if (document.getElementById("Land")) opdaterOmraade();
}


function place_fill_bg_resize() {

	var iHeight = document.body.scrollHeight - 1041;

	if (iHeight > 0) {
		document.all.tblFACILITETER.style.height = iHeight;
	} else {
		document.all.tblFACILITETER.style.height = 50;
	}

	fill_bg_resize();
}


function makeCatalog(func, val_1, val_2) {

	var redirectString = '';
	if (func == 1) {
		redirectString = 'vac_place_pdf.php?PLADSNR=' + val_1;
	} else {
		redirectString = 'catalog_pdf.php?LAND=' + val_1 + '&STED=' + val_2;
	}

	Win1 = window.open(redirectString, "CalendarWindow", "toolbar=0, scrollbars=1, resizable=1, width=1024, height=768, left=0, top=0");

}

