//Created by: s63174
//Date: 2001-02-22
//Changes by: k81825
//Date: 2008-07-02
//Changes: 
// - Added onload handler 
// - Added fixHeadingImages() to fix remaining h1 heading images when using sifr
// - Added setIframeClass() to set headframe class on top menu iframe if not present (used by Codan Forsikring, disabled for TH)

//Google analytics (tracking uses googleTrackpage() below)
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

//Onload handler
window.onload = function() {
	//Fix headings
	fixHeadingImages();
	//Set iframe class
	setIframeClass();
	//Track page
	googleTrackPage();
}
//Fix image headings inside h1 when using sifr
var newImage = null;
var insertPosition = null;
function fixHeadingImages() {
	var cHeadings = document.getElementsByTagName('H1');
	var cImage = null;
	for (var i=0;i<cHeadings.length;i++) {
		cImage = cHeadings[i].getElementsByTagName('IMG');
		if (cImage.length == 1) {
			//create an ID for bookmark link to create an insert position
			cHeadings[i].parentNode.id = 'BM' + i;
			insertPosition = cHeadings[i].parentNode.id;
			//create image HTML from current image
			var sImage = '<img src="' + cImage[0].src + '" border="0" alt="' + cImage[0].alt + '">';
			//clear current bookmark link innerHTML and insert new image HTML
			document.getElementById(insertPosition).innerHTML = null;
			document.getElementById(insertPosition).innerHTML = sImage;
			document.getElementById(insertPosition).style.display = 'block';
		}
	}
}
//Set class to headframe for page top menu div, set style for frame
function setIframeClass() {
	//Set document to top location document
	var oDoc = null;
	if (location.href == top.location.href) {
		oDoc = document;
	}
	else {
		oDoc = parent.document;
	}
	//Check if frame/sitemap or page
	var isFrame = false;
	if (oDoc.location.href.toLowerCase().indexOf('/frame') != '-1') {
		isFrame = true;
	}
	if (oDoc.location.href.toLowerCase().indexOf('/sitemap') != '-1') {
		isFrame = true;
	}
	//Set class or style
	var cIframes = oDoc.getElementsByTagName('IFRAME');
	for (var i=0;i<cIframes.length;i++) {
		if (cIframes[i].id.indexOf('headnav') != '-1') {
			if (isFrame) {
				//ie
				if (oDoc.all) {
					cIframes[i].runtimeStyle.cssText = 'height: 168px;';
				}
				//other
				else {
					cIframes[i].style.height = '168px;';	
				}
			}
			else {
				if (cIframes[i].className != 'headframe') {
					cIframes[i].className = 'headframe';
				}
			}
			break;
		}
	}
}

//Track page with google analytics
var pageTracker = null;
function googleTrackPage() {
	pageTracker = _gat._getTracker("UA-4717685-1");
	pageTracker._initData();
	pageTracker._trackPageview();
}

//Script belongs to xsl Prodinfo TH, images and grey links
function image(image)
{
  var image2;
  image2 = "<TR><TD WIDTH='35'><IMG WIDTH='33' HEIGHT='25' HSPACE='0' VSPACE='0' ALIGN='left' SRC='" + image + "'><IMG SRC='../images/invis.gif' WIDTH='1' HEIGHT='5' /></TD>";
  document.write(image2);
}

function info(info)
{
  document.write("<TD WIDTH='340' class='grey'><IMG SRC='../images/invis.gif' WIDTH='10' HEIGHT='5' />" + info + "</TD></TR><TR><TD><IMG SRC='../images/invis.gif' WIDTH='5' HEIGHT='6' /></TD><TD></TD></TR>");
}

//Script belongs to attached pages in WAMPYR
function GoAway(x, y)
{	
	var myURL;
	var mystring;
	var topp = top.location.href;
	var dok = document.location.href;

	myURL = x
	mystring = y				
		
	if (myURL.charAt(0) == "*")
	{
		myURL = myURL.substring(1, myURL.length);
	}
	else
	{
		myURL = "Document/" + mystring
	}

	if(mystring != "" && topp == dok)
	{
		mystring = dok
		frametest(mystring);
	}
	else
	{
		window.location.replace(myURL);
	}
}

//Script belongs to all xsl
function frametest(x)
{
	var topp = top.location.href;
	var dok = document.location.href;
	var sPage = x;

	if(topp == dok)
	{
		window.location.replace("index.asp#" + sPage)
	}
}

//Script belongs to all xsl
function libtest(lib)
{
	var topp = top.location.href;
	var dok = document.location.href;

	if(topp == dok)
	{
	}
	else
	{
		var sLib = lib;
		if (top.parent.left.nowLoaded)
		{
			top.parent.left.viewMenu('M'+sLib);
		}
		else
		{
			setTimeout("libtest("+sLib+")",500);
		}
	}
}



//Script belongs to all Förstasida
function getStartTD()
{
document.write('<td width="303" background="../images/privat/sb'+whichStart+'-bg.jpg">');
}

function getCloseTD()
{
document.write('</td>');
}

//Script belongs to Forms that uses wwwthse/forms/help/help.asp
function OpenHelp(id)
{
	var url = "/forms/help/help_hem.asp?id=" + id;
	window.open(url,null,"height=300,width=300,resizable=0,scrollbars=yes,menubar=0,status=0");
}	

//Script belongs to pages with green right side TH-ST-Haelsa
function greenTable(x)
{
	var sUpDown = x
	if(sUpDown == "top")
	{
		document.write('</TABLE><TABLE WIDTH="150" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD class="right" width="9"><IMG SRC="../images/invis.gif" WIDTH="9" HEIGHT="1" /></TD><TD class="right" width="136">');
	}
	if(sUpDown == "down")
	{
		document.write('</TD><TD class="right" width="5"><IMG SRC="../images/invis.gif" WIDTH="5" HEIGHT="1" /></TD></TR></TABLE><TABLE WIDTH="150" BORDER="0" CELLSPACING="0" CELLPADDING="0">');
	}
}

//Script belongs to pages with instadia-script
function translateTitle(sTitle)
{
	temp = "" + sTitle; // temporary holder

	out = "å"; // replace this
	add = "&aring;"; // with this

	while (temp.indexOf(out)>-1) 
	{
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}

	out = "ä"; // replace this
	add = "&auml;"; // with this

	while (temp.indexOf(out)>-1) 
	{
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}

	out = "ö"; // replace this
	add = "&ouml;"; // with this

	while (temp.indexOf(out)>-1) 
	{
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}

	document.write("<TITLE>" + temp + "</TITLE>");
}
function MenuTest()
{
	var sPage = self.location.hash;
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("nomenu=");

	// Se om cookien existerar
	if(pos != -1) 
	{
		var start = pos + 7;
		var end = allcookies.indexOf(";", start);
		if (end == -1) {end = allcookies.length;}
		var cookieValue = allcookies.substring(start, end);
		cookieValue = unescape(cookieValue);
		//alert("Cookien innehaoller: "+cookieValue); // Taend denna foer att fao en alert som visar cookiens innehaoll.
	}

	if (cookieValue == "ja")
	{
		HideMenu();
	}

	if(sPage == "#nomenu")
	{
		// Om den inte finns sao skapas den
		document.cookie = "nomenu=ja"; // Kommentera bort detta foer att ta bort cookien.
		HideMenu();
	}
}

function HideMenu()
{
	var sHeadnav = 'headnav_noprint';
	var domSHide = findDOM(sHeadnav,1);
	domSHide.display = 'none';
	var sMenu = 'menu_noprint';
	var domSHide = findDOM(sMenu,1);
	domSHide.display = 'none';
}
