

/* *******************************************************************************************
 *         Generic scripts                                                                   *
 ******************************************************************************************* */


function popWinOpen(winW,winH,sUrl,sName,iResize,iScroll,iStatus) {
	var winX, winY ;
	if (screen) {
		if (winW <= 0) {
			winW = screen.width - 20 ;
		}
		if (winH <= 0) {
			winH = screen.height - 80 ;
		}
		if ((screen.height - winH) < 150) {
			winX = (screen.width - winW) / 2;
			winY = 0;
		} else {
			winX = (screen.width - winW) / 2;
			winY = (screen.height - winH) / 2;
		}
		var popWindow = window.open(sUrl,sName,"resizable=" + iResize + ",menubar=0,scrollbars=" + iScroll + ",status=" + iStatus + ",width=" + winW + ",height=" + winH + ",top=" + winY + ",left=" + winX + "");
		if (popWindow) popWindow.focus();
	} else {
		window.open(sUrl,sName,"resizable=" + iResize + ",menubar=0,scrollbars=" + iScroll + ",status=" + iStatus + ",width=" + winW + ",height=" + winH);
	}
}


function tipFriend(path, isEng) {
	popWinOpen(360,400,"/jsp/tip_friend/?path=" + path + (isEng ? "&lang=eng" : ""),"tipFriendWin",1,0,1) ;
}
function openMail(sId, meta_id) {
	popWinOpen(500,500,"/jsp/mail_formular.jsp?id=" + sId + "&meta_id=" + meta_id,"mailWin",1,0,1) ;
}
function openClock() {
	window.open("/user/clock/") ;
}



/* *******************************************************************************************
 *         DocHead plates                                                                    *
 ******************************************************************************************* */

var oFadeInTimer = null ;
var oFadeOutTimer = null ;
var plateVisible = false ;
var showDelay = 1500 ;
var hideDelay = 200 ;

function plateOver(obj, no) {
	try {
		if (obj.className != "plate plate_act") {
			obj.className = "plate plate_hover" ;
		}
		window.clearTimeout(oFadeInTimer) ;
		window.clearTimeout(oFadeOutTimer) ;
		hideAllPlatesAndShow(0) ;
		oFadeInTimer = window.setTimeout(function() { hoverInfoDivFadeIn(no); }, showDelay) ;
	} catch (e) {}
}

function hoverInfoDivFadeIn(no) {
	if ($("hoverInfoDiv1")) {
		hideSelectBoxesIe.defer() ;
		var oHoverInfoDiv = $("hoverInfoDiv" + (no > 0 ? no : 1)) ;
		if (oHoverInfoDiv) {
			var oMain = $("content_container") ;
			if (oMain) {
				try {
					var mainWidth  = oMain.offsetWidth ;
					var mainHeight = oMain.offsetHeight ;
					var mainPosX   = getElementLeft(oMain) ;
					var mainPosY   = getElementTop(oMain) ;
					if (no > 0) {
						oHoverInfoDiv.style.left    = mainPosX + "px" ;
						oHoverInfoDiv.style.top     = mainPosY + "px" ;
					}
					oHoverInfoDiv.style.width   = mainWidth + "px" ;
					oHoverInfoDiv.style.height  = mainHeight + "px" ;
					oHoverInfoDiv.style.display = "block" ;
				} catch (e) {}
			}
			if (no > 0) new Effect.Opacity("hoverInfoDiv" + no, {duration:0.5, from:0.0, to:0.93}) ;
		}
	}
}

function plateOut(obj, no) {
	try {
		if (obj.className != "plate plate_act") {
			obj.className = "plate" ;
		}
		window.clearTimeout(oFadeInTimer) ;
		window.clearTimeout(oFadeOutTimer) ;
		oFadeOutTimer = window.setTimeout(function() { hoverInfoDivFadeOut(no); }, hideDelay) ;
	} catch (e) {}
}

function hoverInfoDivFadeOut(no) {
	if ($("hoverInfoDiv1")) {
		new Effect.Opacity("hoverInfoDiv" + no, {duration:0.2, from:0.93, to:0.0}) ;
		Element.hide.delay(0.2, "hoverInfoDiv" + no) ;
		hideAllPlatesAndShow.delay(0.4) ;
		showSelectBoxesIe.delay(1.0) ;
	}
}

function hideAllPlatesAndShow(no) {
	if ($("hoverInfoDiv1")) {
		for (var i = 1; i <= 4; i++) {
			$("hoverInfoDiv" + i).style.display = (no && no == i) ? "block" : "none" ;
		}
	}
}

function showSelectBoxesIe() {
	if (Prototype.Browser.IE) {
		$$('select').invoke('setStyle', {visibility: 'visible'}) ;
	}
}

function hideSelectBoxesIe() {
	if (Prototype.Browser.IE) {
		$$('select').invoke('setStyle', {visibility: 'hidden'}) ;
		if ($('findSelect')) $('findSelect').style.visibility = "visible" ;
	}
}

Event.observe(window, 'load', function() {
	Event.observe($("plate1"), 'mouseenter', function() {
		plateOver($("plate1"), 1) ;
	});
	Event.observe($("plate1"), 'mouseleave', function() {
		plateOut($("plate1"), 1) ;
	});
	/*Event.observe($("hoverInfoDiv1"), 'mouseover', function() {
		plateOut($("plate1")) ;
	});*/
	Event.observe($("plate2"), 'mouseenter', function() {
		plateOver($("plate2"), 2) ;
	});
	Event.observe($("plate2"), 'mouseleave', function() {
		plateOut($("plate2"), 2) ;
	});
	/*Event.observe($("hoverInfoDiv2"), 'mouseover', function() {
		plateOut($("plate2")) ;
	});*/
	Event.observe($("plate3"), 'mouseenter', function() {
		plateOver($("plate3"), 3) ;
	});
	Event.observe($("plate3"), 'mouseleave', function() {
		plateOut($("plate3"), 3) ;
	});
	/*Event.observe($("hoverInfoDiv3"), 'mouseover', function() {
		plateOut($("plate3")) ;
	});*/
	Event.observe($("plate4"), 'mouseenter', function() {
		plateOver($("plate4"), 4) ;
	});
	Event.observe($("plate4"), 'mouseleave', function() {
		plateOut($("plate4"), 4) ;
	});
	/*Event.observe($("hoverInfoDiv4"), 'mouseover', function() {
		plateOut($("plate4")) ;
	});*/
	
	if ($("bottomIcon14")) {
		if (!$("bottomIcon14").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon14"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon14"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon24")) {
		if (!$("bottomIcon24").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon24"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon24"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon34")) {
		if (!$("bottomIcon34").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon34"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon34"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon44")) {
		if (!$("bottomIcon44").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon44"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon44"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon18")) {
		if (!$("bottomIcon18").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon18"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon18"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon28")) {
		if (!$("bottomIcon28").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon28"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon28"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon38")) {
		if (!$("bottomIcon38").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon38"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon38"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon48")) {
		if (!$("bottomIcon48").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon48"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon48"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon58")) {
		if (!$("bottomIcon58").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon58"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon58"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon68")) {
		if (!$("bottomIcon68").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon68"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon68"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon78")) {
		if (!$("bottomIcon78").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon78"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon78"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
	if ($("bottomIcon88")) {
		if (!$("bottomIcon88").hasClassName("bottomIconAct")) {
			Event.observe($("bottomIcon88"), 'mouseenter', function() {
				this.removeClassName("bottomIconInact") ;
				this.addClassName("bottomIconAct") ;
			});
			Event.observe($("bottomIcon88"), 'mouseleave', function() {
				this.removeClassName("bottomIconAct") ;
				this.addClassName("bottomIconInact") ;
			});
		}
	}
});

function openHittaDirekt(targetAndHref) {
	var sTarget = targetAndHref.split("|")[0] ;
	var sHref   = targetAndHref.split("|")[1] ;
	if (sTarget == "_blank") {
		window.open(sHref) ;
	} else {
		document.location = sHref ;
	}
}


/* *******************************************************************************************
 *         DocHead links right                                                               *
 ******************************************************************************************* */


function topRightOver(objId) {
	if (objId.indexOf("btn3") != -1) {
		var objL = document.getElementById("btn3LDiv") ;
		var objR = document.getElementById("btn3RDiv") ;
		objL.className = "btn3L_hover" ;
		objR.className = "btn3R_hover" ;
		//window.status = objL.className + ", " + objR.className ;
	} else {
		var obj = document.getElementById(objId + "Div") ;
		obj.className = objId + "_hover" ;
	}
}
function topRightOut(objId) {
	if (objId.indexOf("btn3") != -1) {
		var objL = document.getElementById("btn3LDiv") ;
		var objR = document.getElementById("btn3RDiv") ;
		objL.className = "" ;
		objR.className = "" ;
	} else {
		var obj = document.getElementById(objId + "Div") ;
		obj.className = "" ;
	}
}


function boxHoverIe(id) {
	if (document.all) {
		try {
			document.getElementById(id).getElementsByTagName("TD")[0].className='boxHeadingHover';
		} catch (e) {}
	}
}
function boxOutIe(id) {
	if (document.all) {
		try {
			document.getElementById(id).getElementsByTagName("TD")[0].className='boxHeadingOut';
		} catch (e) {}
	}
}

function openLink(href) {
	document.location = href ;
}



function refreshCaptcha() {
	document.getElementById("captcha_image").src = '/kaptcha.jpg?' + Math.floor(Math.random()*100);
}


/* *******************************************************************************************
 *         Flash clock                                                                       *
 ******************************************************************************************* */

function loadClock() {
	try {
		var r = new FlashObject("/user/clock/klocka.swf", "klocka", "47", "47", 8, "FFFFFF");
		r.addParam("allowScriptAccess", "always");
		r.write("clock");
	} catch (e) {}
}
if (window.attachEvent) {
	window.attachEvent("onload",      function(){ loadClock(); }) ;
} else if (window.addEventListener) {
	window.addEventListener("load",   function(){ loadClock(); }, true) ;
}

/* *******************************************************************************************
 *         Digital Clock in DocHead                                                          *
 ******************************************************************************************* */

function writeDigitalClock(objId) {
	var obj = document.getElementById(objId) ;
	if (obj) {
		try {
			dNow   = new Date() ;
			sDay   = dNow.getDay() ;
			sMonth = dNow.getMonth()+1 ;
			sDate  = dNow.getDate() ;
			sYear  = dNow.getYear() ;
			sHour  = dNow.getHours() ;
			sMin   = dNow.getMinutes() ;
			if (sYear < 1000) {
				sYear = ("" + (sYear+11900)).substring(1,5) ;
			} else {
				sYear = ("" + (sYear+10000)).substring(1,5) ;
			}
			/*if (sHour == 0) {
				sHour = 12 ;
			} else if (sHour >= 13) {
				sHour -= 12 ;
			}*/
			if (sMin < 10) {
				sMin = "0" + sMin ;
			}
			obj.innerHTML = "" + sYear + "-" + (sMonth < 10 ? "0" + sMonth : sMonth) + "-" + (sDate < 10 ? "0" + sDate : sDate) + " " + sHour + ":" + sMin ;
			setTimeout("writeDigitalClock('" + objId + "')", 1000) ;
		} catch (e) {}
	}
}
if (window.attachEvent) {
	window.attachEvent("onload",      function(){ writeDigitalClock("date"); }) ;
} else if (window.addEventListener) {
	window.addEventListener("load",   function(){ writeDigitalClock("date"); }, true) ;
}

function tryIconOver(id) {
	try {
		var imgEl  = document.getElementById(id)
		var oldSrc = imgEl.src ;
		imgEl.src = oldSrc.replace(/(_)0(\.[\w]{3,4})$/, "$11$2") ;
	} catch (e) {}
}
function tryIconOut(id) {
	try {
		var imgEl  = document.getElementById(id)
		var oldSrc = imgEl.src ;
		imgEl.src = oldSrc.replace(/(_)1(\.[\w]{3,4})$/, "$10$2") ;
	} catch (e) {}
}



/* *******************************************************************************************
 *         Box adjustment                                                                    *
 ******************************************************************************************* */

function getFirstBox(arr) {
	if (arr != null) {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i]) return arr[i] ;
		}
	}
}


function getElementLeft(el) {
	try {
		if (!el && this) {
			el = this;
		}
		var posLeft = el.offsetLeft;
		var elPar = el.offsetParent;
		while (elPar != null) {
			posLeft += elPar.offsetLeft;
			elPar = elPar.offsetParent;
		}
		return isNaN(posLeft) ? -1 : posLeft;
	} catch (e) {
		return -1 ;
	}
}

function getElementTop(el) {
	try {
		if (!el && this) {
			el = this ;
		}
		var posTop = el.offsetTop ;
		var elPar = el.offsetParent ;
		while (elPar != null) {
			posTop += elPar.offsetTop ;
			elPar = elPar.offsetParent ;
		}
		return isNaN(posTop) ? -1 : posTop;
	} catch (e) {
		return -1 ;
	}
}

/* *******************************************************************************************
 *         Marquee script                                                                    *
 ******************************************************************************************* */

/**********************************************************************
                           Simple marquee script
                      By Mark Wilton-Jones 25/6/2005
***********************************************************************

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use

The <marquee> tag is not part of the HTML or XHTML standards, and as a result, it
is not supported cross browser. The marquee effect can be important for displaying
messages on devices with small screens, or in a position on web pages where space
is limited. This script produces a simple marquee effect that works cross browser
without invalidating your document. In addition, the effect is accessible, and
degrades gracefully in non-DOM browsers to show the text normally.

To use:

Inbetween the <head> tags, put:

	<script src="PATH TO SCRIPT/simplemarquee.js" type="text/javascript"></script>

Then wherever you want to define a marquee, use:

	<div class="dmarquee"><div><div>Marquee text</div></div></div>

You can create multiple marquees if needed. If you want to style the marquees, style
the outermost div (the script uses the inner divs to avoid box model problems). You
can use multiple classes to the outer div to facilitate additional styling:

	<div class="dmarquee myclass"><div><div>Marquee text</div></div></div>

To stop the marquees manually, run doMStop();
You can also restart them using doDMarquee();

You can set a few options using the variables below. I have no intention of making
additional options in this script. Marquees can be very annoying if used as a special
effect where they are not actually needed, and I do not want to encourage their use.
If you want to make additional options, you can go ahead, but I will not help you.
________________________________________________________________________________*/

var oMarquees = [], oMrunning,
	oMInterv =        20,     //interval between increments
	oMStep =          2,      //number of pixels to move between increments
	oStopMAfter =     60,     //how many seconds should marquees run (0 for no limit)
	oResetMWhenStop = false,  //set to true to allow linewrapping when stopping
	oMDirection =     'left'; //'left' for LTR text, 'right' for RTL text

/***     Do not edit anything after here     ***/

function doMStop() {
	clearInterval(oMrunning);
	for( var i = 0; i < oMarquees.length; i++ ) {
		oDiv = oMarquees[i];
		oDiv.mchild.style[oMDirection] = '0px';
		if( oResetMWhenStop ) {
			oDiv.mchild.style.cssText = oDiv.mchild.style.cssText.replace(/;white-space:nowrap;/g,'');
			oDiv.mchild.style.whiteSpace = '';
			oDiv.style.height = '';
			oDiv.style.overflow = '';
			oDiv.style.position = '';
			oDiv.mchild.style.position = '';
			oDiv.mchild.style.top = '';
		}
	}
	oMarquees = [];
}
function doDMarquee() {
	if( oMarquees.length || !document.getElementsByTagName ) { return; }
	var oDivs = document.getElementsByTagName('div');
	for( var i = 0, oDiv; i < oDivs.length; i++ ) {
		oDiv = oDivs[i];
		if( oDiv.className && oDiv.className.match(/\bdmarquee\b/) ) {
			if( !( oDiv = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
			if( !( oDiv.mchild = oDiv.getElementsByTagName('div')[0] ) ) { continue; }
			oDiv.mchild.style.cssText += ';white-space:nowrap;';
			oDiv.mchild.style.whiteSpace = 'nowrap';
			oDiv.style.display = 'block';
			oDiv.style.height = oDiv.offsetHeight + 'px';
			oDiv.style.overflow = 'hidden';
			oDiv.style.position = 'relative';
			oDiv.mchild.style.position = 'absolute';
			oDiv.mchild.style.top = '0px';
			oDiv.mchild.style[oMDirection] = oDiv.offsetWidth + 'px';
			oMarquees[oMarquees.length] = oDiv;
			i += 2;
		}
	}
	oMrunning = setInterval('aniMarquee()',oMInterv);
	if( oStopMAfter ) { setTimeout('doMStop()',oStopMAfter*1000); }
}
function aniMarquee() {
	var oDiv, oPos;
	for( var i = 0; i < oMarquees.length; i++ ) {
		oDiv = oMarquees[i].mchild;
		oPos = parseInt(oDiv.style[oMDirection]);
		if( oPos <= -1 * oDiv.offsetWidth ) {
			oDiv.style[oMDirection] = oMarquees[i].offsetWidth + 'px';
		} else {
			oDiv.style[oMDirection] = ( oPos - oMStep ) + 'px';
		}
	}
}
if( window.addEventListener ) {
	window.addEventListener('load',doDMarquee,false);
} else if( document.addEventListener ) {
	document.addEventListener('load',doDMarquee,false);
} else if( window.attachEvent ) {
	window.attachEvent('onload',doDMarquee);
}

/* *******************************************************************************************
 *         hassleholm scripts                                                                *
 ******************************************************************************************* */

/* *******************************************************************************************
 *         Right column height                                                               *
 ******************************************************************************************* */

function checkRightColumnBoxes() {
	try {
		var oBoxOuter1 = $("rightcol_top") ;
		var oBoxInner1 = $("rightcol_top_box_inner") ;
		var oBoxOuter2 = $("rightcol_bottom") ;
		var oBoxInner2 = $("rightcol_bottom_box_inner") ;
		var oIframe    = $("mediaIframe") ;
		if (oBoxInner2 && oIframe && oBoxOuter1) {
			var box1Y = getElementTop(oBoxOuter1) ;
			var box2Y = getElementTop(oBoxOuter2) ;
			var boxBottomH = 294 - (box2Y - box1Y) ;
			if (boxBottomH > 35) {
				oBoxInner2.style.height     = boxBottomH + "px" ;
				//oIframe.style.height        = "80px" ;
				oIframe.style.height        = (boxBottomH - 50) + "px" ;
				//alert("YEPP: " + box1Y + " - " + box2Y + " - " + boxBottomH) ;
			} else {
				//alert("NOOP: " + box1Y + " - " + box2Y + " - " + boxBottomH) ;
			}
		} else if (oBoxInner1 && oBoxInner2) {
			var currentRightHeight = oBoxInner1.offsetHeight + oBoxInner2.offsetHeight ;
			if (currentRightHeight < 294) {
				oBoxInner2.style.height = (oBoxInner2.offsetHeight + (294 - currentRightHeight) - 12) + "px" ;
			}
		} else if (oBoxInner1 && oBoxOuter1) {
			oBoxInner1.style.height       = "294px" ;
			oBoxOuter1.style.marginBottom = 0 ;
		}
	} catch (e) {}
}
if (window.attachEvent) {
	window.attachEvent("onload",      function(){ checkRightColumnBoxes(); }) ;
} else if (window.addEventListener) {
	window.addEventListener("load",   function(){ checkRightColumnBoxes(); }, true) ;
}



