
/*
Typer av popups
---------------
1. Inlinebilder som ska förstoras (där bilden växer)
2. Inlineinnehåll som ska visas (utan bilder: det visas bara en popup med det tillkommande innehållet)
3. Interna länkar i kolumnlayoutläge (vanliga sidor eller noter)

*/

var POPUP = {};

POPUP.OffsetTop = -30; // change this variable adjust the top position of inline-popups in column-layout pages
POPUP.CurrentPopup = null;
POPUP.Animation = null;
POPUP.Width = 0;

// add click event listener to each non-external link to make it open a preview popup instead of navigating to the page
POPUP.InitInternalLinks = function() {
	var links = document.getElementById('content').getElementsByTagName('A');
	for (var i = 0; i < links.length; i++) {
		if (links[i].attributes['rel'] && links[i].attributes['rel'].value == 'inline')
			EVENT.Add(links[i], 'click', POPUP.Show);
	}
};

POPUP.Show = function(e) {
	POPUP.Close();
	var anchor = (e.srcElement) ? e.srcElement : e.target;
	while (anchor.tagName.toLowerCase() != 'a')
		anchor = anchor.parentNode;

	// Firefox bug
	if (anchor.parentNode.tagName == 'H2') {
		anchor = anchor.parentNode.parentNode;
	}

	anchor.blur();

	// define variables
	var top = 0; left = 0; width = 0; height = 0;
	var changeLeft = 0; changeTop = 0; changeWidth = 0; changeHeight = 0;
	var duration = 25; // animation duration

	// create the popup
	POPUP.CurrentPopup = document.createElement('div');
	POPUP.CurrentPopup.id = 'popup';
	POPUP.CurrentPopup.className = 'popup';
	POPUP.CurrentPopup.innerHTML = '<div class="pop-corner-tr"></div><div class="pop-corner-br"></div><div class="pop-corner-bl"></div><div class="pop-corner-tl"></div><div class="pop-top"></div><div class="pop-main"></div><div class="pop-bottom"></div><div class="pop-right"></div><div class="pop-left"></div><div class="pop-close" onclick="POPUP.AnimateClose();"><span>' + TRANSLATE.GetValue('Close') + '</span></div><h2 id="pop-topic"></h2><div id="pop-content"></div>';
	document.getElementById('content').appendChild(POPUP.CurrentPopup);
	var popupHeader = POPUP.CurrentPopup.childNodes[10];
	var popupContent = POPUP.CurrentPopup.childNodes[11];

	// populate the popup with content
	if (anchor.id == 'pdflink') { // this is the popup for the pdf download form
		POPUP.Width = 1012;
		POPUP.CurrentPopup.style.top = '90px';
		var pdfmenupopup = document.createElement('div');
		var pdfmenu = document.getElementById('menuitems').cloneNode(true);
		pdfmenu.className = 'pdfmenu';
		pdfmenu.removeChild(pdfmenu.getElementsByTagName('li')[0]);
		pdfmenupopup.appendChild(pdfmenu);
		pdfmenupopup.id = 'pdfmenu';

		var div = document.createElement('div');
		div.className = 'downloadpanel';
		div.innerHTML = '<div><span id="countpdfpages">5</span> ' + TRANSLATE.GetValue('DownloadPages') + '<br /><br /><input type="button" class="button" onclick="POPUP.DownloadPDF();" value="' + TRANSLATE.GetValue('DownloadPDF') + '" />' +
			'<a href="' + TRANSLATE.GetValue('DownloadSampoLink') + '">' + TRANSLATE.GetValue('DownloadSampo') + '</a>' +
			'<a href="' + TRANSLATE.GetValue('DonwoadIfLink') + '">' + TRANSLATE.GetValue('DownloadIf') + '</a>' +
			'<a href="' + TRANSLATE.GetValue('DownloadMandatumLink') + '">' + TRANSLATE.GetValue('DownloadMandatum') + '</a>' +
			'</div>';
		pdfmenupopup.appendChild(div);

		popupContent.appendChild(pdfmenupopup);

		var link = pdfmenu.getElementsByTagName('a');
		if (document.body.className.indexOf('fi') > -1) {
			var j = 0;
			var newMenuitems = Array('Sampo-konserni', 'Hallinto ja johto', 'Hallituksen toimintakertomus', 'Riskienhallinta', 'Tilinpäätös', 'Sijoittajalle');

			for (var i = 0; i < link.length; i++) {

				if (link[i].id && link[i].id != '') {
					link[i].innerHTML = newMenuitems[j];
					j++;
				}

			}
		}

		for (var i = 0; link.length > 0; i++) {
			if (link[0].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id == 'pdfmenu') {
				link[0].parentNode.parentNode.removeChild(link[0].parentNode);
			}
			else {
				var input = document.createElement('input');
				input.type = 'checkbox';

				//input.id = 'input_' + i;
				input.checked = true;
				var attr = '';
				if (link[0].parentNode.parentNode.parentNode.id != 'pdfmenu') {
					attr = link[0].getAttribute('rel');
					if (attr == null || attr == '') {
						link[0].parentNode.parentNode.removeChild(link[0].parentNode);
						continue;
					}
					input.setAttribute('rel', attr);
				}

				var label = document.createElement('label');
				label.innerHTML = link[0].innerHTML;
				var li = link[0].parentNode;
				li.removeChild(link[0]);
				li.insertBefore(label, li.firstChild);
				li.insertBefore(input, li.firstChild);

				//label.setAttribute('for', 'input_' + i);
				EVENT.Add(input, 'click', POPUP.SwapPdfCheckbox);
			}
		}
		popupHeader.innerHTML = TRANSLATE.GetValue('CreatePDF');
		popupHeight = 640;
	}
	else if (anchor.href == 'javascript:;') { // we don't have to get the content from another url
		popupContent.innerHTML = anchor.innerHTML;
		popupHeight = popupContent.offsetHeight + popupContent.offsetTop + POPUP.CurrentPopup.childNodes[0].offsetHeight + POPUP.CurrentPopup.childNodes[1].offsetHeight;

		// Find the icon header and make it a popup header
		var iconheader = anchor.getElementsByTagName('h2');
		if (iconheader[0])
			popupHeader.innerHTML = iconheader[0].innerHTML;

		// Find the dimension and position of the anchorlink
		var anchorTop = 0; anchorLeft = 0;
		var anchorContainer = anchor;
		while (anchorContainer.offsetParent) {
			anchorLeft += anchorContainer.offsetLeft;
			anchorTop += anchorContainer.offsetTop;
			anchorContainer = anchorContainer.offsetParent;
		}

		// Align the popup's center with the thumb's center
		POPUP.CurrentPopup.style.top = (anchorTop + (anchor.offsetHeight / 2) - (popupContent.offsetHeight / 2) - popupHeader.offsetHeight - 20) + 'px';

		// If we are in column-mode, make sure the popup stays within the scrollpanel
		if (COLUMNLAYOUT.scrollPanel) {
			anchorLeft -= COLUMNLAYOUT.scrollPanel.scrollLeft
			if (POPUP.CurrentPopup.offsetTop < COLUMNLAYOUT.scrollPanel.offsetTop)
				POPUP.CurrentPopup.style.top = COLUMNLAYOUT.scrollPanel.offsetTop + 'px';
		}

		// but not so they will exceed the screen
		if (POPUP.CurrentPopup.offsetTop + popupHeight > document.documentElement.clientHeight)
			POPUP.CurrentPopup.style.top = (document.documentElement.clientHeight - popupHeight) + 'px';
		if (POPUP.CurrentPopup.offsetTop < 0)
			POPUP.CurrentPopup.style.top = '0px';

		// if the content contains an image that are zoomable, that image should be animated
		var images = popupContent.getElementsByTagName('img');
		if (images.length > 0 && images[0].className == 'zoomable') {
			POPUP.Width = popupContent.scrollWidth + POPUP.CurrentPopup.childNodes[0].offsetWidth + POPUP.CurrentPopup.childNodes[3].offsetWidth;

			if (!isIE)
				duration = 2; // firefox and crome are bad at animating images...

			thumbImg = anchor.getElementsByTagName('img')[0];
			POPUP.Animation = images[0].cloneNode(true);
			POPUP.Animation.id = 'popupAnimation';
			left = anchorLeft + thumbImg.offsetLeft - thumbImg.parentNode.offsetLeft + 10;
			top = anchorTop + thumbImg.offsetTop - thumbImg.parentNode.offsetTop;
			width = thumbImg.offsetWidth;
			height = thumbImg.offsetHeight;
			endLeft = parseInt(left + anchor.parentNode.offsetWidth / 2 - POPUP.Width / 2);

			// adjust so that the element won't exceed the screen's limits
			if (endLeft < 0)
				endLeft = 0;
			else if (endLeft + popupContent.scrollWidth + 30 > document.documentElement.clientWidth)
				endLeft = document.documentElement.clientWidth - popupContent.scrollWidth - 30;


			POPUP.CurrentPopup.style.left = endLeft + 'px';
			changeLeft = (POPUP.CurrentPopup.offsetLeft + popupContent.offsetLeft - left);
			changeTop = (POPUP.CurrentPopup.offsetTop + popupContent.offsetTop + images[0].offsetTop - top);
			changeWidth = (images[0].offsetWidth - width);
			changeHeight = (images[0].offsetHeight - height);
		}
		else {
			if (COLUMNLAYOUT.scrollPanel) {
				// increase the popup width if it is narrower than the width of a column
				if (POPUP.CurrentPopup.offsetWidth < COLUMNLAYOUT.ColumnWidth + COLUMNLAYOUT.ColumnMargin) {
					POPUP.Width = COLUMNLAYOUT.ColumnWidth + POPUP.CurrentPopup.childNodes[0].offsetWidth + POPUP.CurrentPopup.childNodes[3].offsetWidth;
				}

				// force internal scroolbar if the popup height exceeds the height of the scrollpanel (minus the horisontal scrollbar height)
				if (COLUMNLAYOUT.scrollPanel && COLUMNLAYOUT.scrollPanel.offsetHeight < popupHeight) {
					popupHeight = COLUMNLAYOUT.scrollPanel.offsetHeight;
					POPUP.CurrentPopup.style.top = (COLUMNLAYOUT.scrollPanel.offsetTop + POPUP.OffsetTop) + 'px';
				}
			}
			else { // this is not column layout: check on which side the popup should open
				if (e.clientX - document.body.offsetLeft > 635) { // open in mid column
					POPUP.Width = 450;
					POPUP.CurrentPopup.style.left = (document.body.offsetLeft + 160) + 'px';
					var arr = document.createElement('div');
					arr.className = 'arrowright';
					POPUP.CurrentPopup.appendChild(arr);
				}
				else { // open in right column
					POPUP.Width = 300;

				}
			}
			// if the content contains a table, make sure the popup is wide enough
			var table = popupContent.getElementsByTagName('table');
			if (table.length > 0) {
				var lastrow = table[0].rows[table[0].rows.length - 1];
				POPUP.Width = 226;
				for (var i = 1; i < lastrow.cells.length; i++) {
					POPUP.Width += 63;
				}
			}
		}
	}
	else { // this is a link to another document. Get it's content by ajax
		if (COLUMNLAYOUT.scrollPanel) {
			popupHeight = COLUMNLAYOUT.scrollPanel.offsetHeight;  //popupContent.offsetHeight - POPUP.CurrentPopup.offsetHeight + COLUMNLAYOUT.scrollPanel.offsetHeight - 20;
			POPUP.Width = COLUMNLAYOUT.ColumnWidth + POPUP.CurrentPopup.childNodes[0].offsetWidth + POPUP.CurrentPopup.childNodes[3].offsetWidth;

			POPUP.CurrentPopup.style.top = (COLUMNLAYOUT.scrollPanel.offsetTop + POPUP.OffsetTop) + 'px';
		}
		else if (document.body.id == 'tablepage') {
			/*popupHeight = document.documentElement.clientHeight - document.getElementById('outerwrap').offsetTop - 40;
			POPUP.Width = TABLELAYOUT.Table.offsetWidth;

			POPUP.CurrentPopup.style.top = (document.getElementById('outerwrap').offsetTop + document.documentElement.scrollTop) + 'px';
			POPUP.CurrentPopup.style.left = (TABLELAYOUT.Table.offsetWidth + 20) + 'px';*/
			popupHeight = document.documentElement.clientHeight - 30;
			POPUP.Width = 760;

			POPUP.CurrentPopup.style.top = (20 + document.documentElement.scrollTop) + 'px';
			POPUP.CurrentPopup.style.left = (e.clientX - (POPUP.Width)) + 'px';
		}
		POPUP.PopulateExternalContent(anchor.href);
		EVENT.Abort(e); // prevents the transfer to another web page
	}

	POPUP.CurrentPopup.style.height = popupHeight + 'px';
	POPUP.CurrentPopup.style.width = POPUP.Width + 'px';

	popupHeight -= (POPUP.CurrentPopup.childNodes[0].offsetHeight + POPUP.CurrentPopup.childNodes[1].offsetHeight);
	POPUP.CurrentPopup.childNodes[5].style.height = popupHeight + 'px'; // Main
	POPUP.CurrentPopup.childNodes[7].style.height = popupHeight + 'px'; // Right
	POPUP.CurrentPopup.childNodes[8].style.height = popupHeight + 'px'; // Left
	popupHeight -= (popupContent.offsetTop - POPUP.CurrentPopup.childNodes[0].offsetHeight);
	popupContent.style.height = popupHeight + 'px';

	POPUP.Width -= (POPUP.CurrentPopup.childNodes[0].offsetWidth + POPUP.CurrentPopup.childNodes[3].offsetWidth);
	POPUP.CurrentPopup.childNodes[5].style.width = POPUP.Width + 'px'; // Main
	POPUP.CurrentPopup.childNodes[4].style.width = POPUP.Width + 'px'; // Top
	POPUP.CurrentPopup.childNodes[6].style.width = POPUP.Width + 'px'; // Bottom
	popupContent.style.width = POPUP.Width + 'px';

	if (anchor.id != 'loginlink' && anchor.id != 'additionalinfo' && COLUMNLAYOUT.scrollPanel && POPUP.Animation == null) {
		// place the popup to the right of the clicked column, but only if this is not a zoomable image
		left = COLUMNLAYOUT.scrollPanel.offsetParent.offsetLeft;
		while (left < e.clientX) {
			left += COLUMNLAYOUT.ColumnWidth + COLUMNLAYOUT.ColumnMargin;
		}
		// center it between two columns
		left -= parseInt((POPUP.CurrentPopup.childNodes[0].offsetWidth + POPUP.CurrentPopup.childNodes[3].offsetWidth) / 2);
		// if the click was in the rightmost column, move it to the left side instead
		if (left + POPUP.CurrentPopup.offsetWidth > document.documentElement.clientWidth) {
			left -= ((COLUMNLAYOUT.ColumnWidth + COLUMNLAYOUT.ColumnMargin) * 2);
			if (left < 0)
				left = 0;
		}
		POPUP.CurrentPopup.style.left = left + 'px';
	}

	// create the animation effect
	if (POPUP.Animation == null) {
		// if it is a zoomable image, this has already been defined 
		POPUP.Animation = document.createElement('div');
		POPUP.Animation.id = 'popupAnimation';
		left = e.clientX - 10;
		top = e.clientY - 10 + document.documentElement.scrollTop;
		width = 20;
		height = 20;
		changeLeft = (POPUP.CurrentPopup.offsetLeft - left);
		changeTop = (POPUP.CurrentPopup.offsetTop - top);
		changeWidth = (POPUP.CurrentPopup.offsetWidth - width);
		changeHeight = (POPUP.CurrentPopup.offsetHeight - height);
	}

	// set the start dimensions as a name to be used later when the close animation occurs
	POPUP.CurrentPopup.name = left + ':' + top + ':' + width + ':' + height + ':' + anchor.id;

	document.body.appendChild(POPUP.Animation);

	POPUP.Animate(0, left, top, width, height, changeLeft, changeTop, changeWidth, changeHeight, duration, true);
};
POPUP.Animate = function(Time, Left, Top, Width, Height, ChangeLeft, ChangeTop, ChangeWidth, ChangeHeight, Duration, Show) {
	if (Time < Duration) {
		POPUP.Animation.style.left = parseInt(cubicInOut(Time, Left, ChangeLeft, Duration)) + 'px';
		POPUP.Animation.style.top = parseInt(cubicInOut(Time, Top, ChangeTop, Duration)) + 'px';
		POPUP.Animation.style.width = parseInt(cubicInOut(Time, Width, ChangeWidth, Duration)) + 'px';
		POPUP.Animation.style.height = parseInt(cubicInOut(Time, Height, ChangeHeight, Duration)) + 'px';
		Time++;
		setTimeout("POPUP.Animate(" + Time + ", " + Left + ", " + Top + ", " + Width + ", " + Height + ", " + ChangeLeft + ", " + ChangeTop + ", " + ChangeWidth + ", " + ChangeHeight + ", " + Duration + ", " + Show + ")", 15);
	}
	else {
		document.body.removeChild(POPUP.Animation);
		POPUP.Animation = null;
		if (Show) { // the same animation function is called when closing the popup
			POPUP.CurrentPopup.style.visibility = 'visible';
		}
	}
};

POPUP.Close = function() {
	if (POPUP.CurrentPopup != null) {
		document.getElementById('content').removeChild(POPUP.CurrentPopup);
		POPUP.CurrentPopup = null;
	}
};

// this function will only be invoked from the close-button in a popup.
POPUP.AnimateClose = function() {
	if (POPUP.CurrentPopup && POPUP.CurrentPopup.name) {
		var duration = 25; // animation duration
		var dimensions = POPUP.CurrentPopup.name.split(':');
		if (dimensions[4] == 'additionalinfo') {
			COLUMNLAYOUT.HideAdditionalInfo();
		}
		var left = POPUP.CurrentPopup.offsetLeft;
		var top = POPUP.CurrentPopup.offsetTop;
		var width = POPUP.CurrentPopup.offsetWidth;
		var height = POPUP.CurrentPopup.offsetHeight;

		var images = POPUP.CurrentPopup.getElementsByTagName('img');
		if (images.length > 0 && images[0].className == 'zoomable') {
			if (!isIE)
				duration = 2; // firefox and crome are bad at animating images...

			POPUP.Animation = images[0].cloneNode(true);
			POPUP.Animation.id = 'popupAnimation';
			left += POPUP.CurrentPopup.childNodes[8].offsetWidth;
			height = images[0].offsetHeight;
			width = images[0].offsetWidth;
			top += POPUP.CurrentPopup.childNodes[11].offsetTop;
		}
		else {
			POPUP.Animation = document.createElement('div');
			POPUP.Animation.id = 'popupAnimation';
		}

		var changeLeft = (parseInt(dimensions[0]) - left);
		var changeTop = (parseInt(dimensions[1]) - top);
		var changeWidth = (parseInt(dimensions[2]) - width);
		var changeHeight = (parseInt(dimensions[3]) - height);

		document.body.appendChild(POPUP.Animation);
		POPUP.Animate(0, left, top, width, height, changeLeft, changeTop, changeWidth, changeHeight, duration, false);
	}
	POPUP.Close();
};

POPUP.PopulateExternalContent = function(url) {
	if (!url) return;
	url = url.toString();  //.toLowerCase();
	//if (url.indexOf('#bm_') != -1) {
	//	url = '../_popups/' + url.substring(url.indexOf('#bm_') + 1) + '.html?cache=' + Math.random();
	//} else {
	url = url.substring(url.indexOf('#') + 1);

	//url = 'bm_note' + url + '.html';
	url = url + '.html'
	var fileName = url.substring(url.lastIndexOf('/'));
	fileName = fileName.replace('/', '');
	url = '../_popups/' + fileName + '?cache=' + Math.random();
	
	//}
	var longUrl = 'http://' + document.domain;

	if (typeof XMLHttpRequest == 'undefined') {
		XMLHttpRequest = function() {
			try { return new ActiveXObject("MSXML3.XMLHTTP") } catch (e) { }
			try { return new ActiveXObject("MSXML2.XMLHTTP.3.0") } catch (e) { }
			try { return new ActiveXObject("MSXML2.XMLHTTP.4.0") } catch (e) { }
			try { return new ActiveXObject("Msxml2.XMLHTTP") } catch (e) { }
			try { return new ActiveXObject("Microsoft.XMLHTTP") } catch (e) { }
			return null;
		};
	}
	var responseXml = null;
	var httpRequest = new XMLHttpRequest();
	if (httpRequest.overrideMimeType) httpRequest.overrideMimeType('text/xml');
	httpRequest.onreadystatechange = function() {
		var thisFunction = arguments.callee;
		if (!thisFunction.loopCount) thisFunction.loopCount = 0;
		thisFunction.loopCount++;
		if (thisFunction.loopCount > 10) {
			POPUP.CurrentPopup.childNodes[10].innerHTML = '404'; // popup header
			POPUP.CurrentPopup.childNodes[11].innerHTML = ''; // popup content
			return;
		}
		if (httpRequest.readyState == 4) {
			if (httpRequest.status == 200) {
				if (httpRequest.responseXML == null) return;
				responseXml = httpRequest.responseXML.documentElement;
				if (!responseXml) {
					var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async = false;
					xmlDoc.loadXML(httpRequest.responseText);
					if (xmlDoc.documentElement !== null) {
						responseXml = xmlDoc.documentElement;
					}
				}
				if (responseXml) {
					var strTopic = '', strText = '', oContent;
					strTopic = responseXml.getElementsByTagName('title')[0].firstChild.nodeValue;
					oContent = responseXml.getElementsByTagName('content')[0]; //.getElementsByTagName('p');
					strText = oContent.xml;
					if (typeof strText == 'undefined') {
						strText = new XMLSerializer().serializeToString(oContent);
					}
					POPUP.CurrentPopup.childNodes[10].innerHTML = strTopic; // popup header
					POPUP.CurrentPopup.childNodes[11].innerHTML = strText; // popup content

					// adjust width for wide popups to avoid horisontal scrollbar
					EVENT.Add(POPUP.CurrentPopup.childNodes[11], 'scroll', POPUP.AdjustWidth);
				}
			} else if (httpRequest.status == 404) {
				var ErrorUrl = longUrl + url.replace('..', '');
				POPUP.CurrentPopup.childNodes[10].innerHTML = '404 Page Not Found!'; // popup header
				POPUP.CurrentPopup.childNodes[11].innerHTML = '<p>The requested file was not found on this server.<br /><code>' + ErrorUrl + '</code></p>'; // popup content
			}
		}
	};
	httpRequest.open('GET', url, true);
	httpRequest.send(null);
};

POPUP.AdjustWidth = function(e) {
	var realWidth = POPUP.CurrentPopup.childNodes[11].scrollWidth;
	if (realWidth > POPUP.Width) {
		realWidth += 20; /// adjust for vertical scrollbar
		POPUP.CurrentPopup.childNodes[5].style.width = realWidth + 'px'; // Main
		POPUP.CurrentPopup.childNodes[4].style.width = realWidth + 'px'; // Top
		POPUP.CurrentPopup.childNodes[6].style.width = realWidth + 'px'; // Bottom
		POPUP.CurrentPopup.childNodes[11].style.width = realWidth + 'px'; // Content

		realWidth += (POPUP.CurrentPopup.childNodes[0].offsetWidth + POPUP.CurrentPopup.childNodes[3].offsetWidth);
		POPUP.Width = realWidth;
		POPUP.CurrentPopup.style.width = realWidth + 'px';

		// the increased width might cause the popup to expand outside of the window area
		if (POPUP.CurrentPopup.offsetLeft + realWidth > document.documentElement.clientWidth)
			POPUP.CurrentPopup.style.left = (document.documentElement.clientWidth - realWidth) + 'px';
	}
}

POPUP.SwapPdfCheckbox = function(e) {
	var checkbox = (e.srcElement) ? e.srcElement : e.target;
	// is this heading checkbox?
	if (checkbox.parentNode.parentNode.className == 'pdfmenu') {
		var checkboxes = checkbox.parentNode.getElementsByTagName('input');
		var doCheck = false;
		for (var i = 1; i < checkboxes.length; i++) {
			if (!checkboxes[i].checked)
				doCheck = true;
		}
		var multiplicator = doCheck ? 1 : -1;
		for (var i = 1; i < checkboxes.length; i++) {
			if (checkboxes[i].checked != doCheck) {
				checkboxes[i].checked = doCheck;
				POPUP.CountPdfPages += (parseInt(checkboxes[i].attributes['rel'].value) * multiplicator);
			}
		}
		checkboxes[0].checked = doCheck;
		checkboxes[0].indeterminate = false;
	}
	else {
		var checkboxes = checkbox.parentNode.parentNode.parentNode.getElementsByTagName('input');
		var doCheck = checkbox.checked;
		var multiplicator = doCheck ? 1 : -1;
		POPUP.CountPdfPages += (parseInt(checkbox.attributes['rel'].value) * multiplicator);
		for (var i = 1; i < checkboxes.length; i++) {
			if (checkboxes[i].checked != doCheck) {
				checkboxes[0].checked = true;
				checkboxes[0].indeterminate = true;
				document.getElementById('countpdfpages').innerHTML = POPUP.CountPdfPages;
				return;
			}
		}
		checkboxes[0].checked = checkbox.checked;
		checkboxes[0].indeterminate = false;
	}
	document.getElementById('countpdfpages').innerHTML = POPUP.CountPdfPages;
};

POPUP.DownloadPDF = function() {
	var boxes = document.getElementById('pdfmenu').getElementsByTagName('ul')[0].getElementsByTagName('input');
	url = 'http://hhxen0103.halvarsson.se/getpdf.aspx?company=sampo2009' + TRANSLATE.Lang + '&p=';
	for (var i = 0; i < boxes.length; i++) {
		if (boxes[i].attributes['rel']) {
			if (boxes[i].checked == true) {
				url = url + "t";
			}
			url = url + ",";
		}
	}
	document.location = url;
};