﻿/*
jonk 2009
*/
function topLocationControl() {
	var myLocation = location.href;
	if (myLocation.indexOf('int.scan.se') == -1) { //don't run on intranet
	    var topLocation = top.location.href;
	    if (topLocation == myLocation) {
			if (myLocation.indexOf('dnr=') > -1) {
			    Idnr = myLocation.split('dnr=');
			    Idnr = Idnr[1];
			    window.location.replace("/sitebase/default.aspx?idnr=" + Idnr);
			} else {
				myLocation = myLocation.replace("http://","")
				domainLen = myLocation.indexOf('/')+1;
				Page = myLocation.substring(domainLen,myLocation.length)
				if (typeof pageId != "undefined" && Page.indexOf('pageId') == -1) {
				    if (Page.indexOf('?') == -1) {
				        pageId = '?pageId=' + pageId;
				    } else {
				        pageId = '&pageId=' + pageId;
				    }
				} else {
					pageId = '';
				}
			    window.location.replace("/sitebase/default.aspx?page=" + Page + pageId);
			}
	    }
	}
}
function setAllDotNetLinks() {
    /*
    replace all "/aciro/websidor/visasida.asp" width "/sitebase/default.aspx"
    */
    var within = document.getElementById('mainContainer');
    if (within) {
        var elem = within.getElementsByTagName('a');
        for(var i = 0; i < elem.length; i++) {
            thisLink = elem[i].href;
            thisLinkLc = thisLink.toLowerCase();
            if (thisLinkLc.indexOf("/aciro/websidor/visasida.asp") > -1) {
                thisLink = "/sitebase/default.aspx" + thisLink.substr(thisLinkLc.indexOf("/aciro/websidor/visasida.asp")+28);
                elem[i].href = thisLink;
		    }
        }
    }
}
function getThirdMenu() {
    /*
    Show the third menu on visasida
    */
	if (parent.thirdMenuStr) {
	    if (document.getElementById("thirdMenu")) {
	        if (parent.thirdMenuStr.indexOf("/sitebase/") > -1) {
	            document.getElementById("thirdMenu").innerHTML = parent.thirdMenuStr;
			    document.getElementById("thirdMenu").style.display = 'block';
			    document.getElementById("thirdMenuDivider").style.display = 'block';
			}
	    }
	}
}
function googleCustomSearch(inputId, addMore) {
	/*
	Function to add a more-tag to the search
	*/
    if (document.getElementById(inputId)) {
        if (document.getElementById(inputId).value.indexOf(' more:') == -1) {
            document.getElementById(inputId).value = document.getElementById(inputId).value + ' more:' + addMore;
        }
    }
}

function cleanGoogleCustomSearch() {
	/*
	Function to clean the input from the more-tag
	*/
	var within = document.getElementById('content');
    if (within) {
        var elem = within.getElementsByTagName('input');
        for(var i = 0; i < elem.length; i++) {
			thisValue = elem[i].value;
			if (thisValue.indexOf(' more:') > -1) {
	            inputArr = thisValue.split(' more:');
	            elem[i].value = inputArr[0];
	        }
        }
    }
}

function printId(idToPrint) {
    if (document.getElementById(idToPrint)) {
	    var a = window.open('','','width=640,height=500');
	    a.document.open("text/html");
	    a.document.write('<html>');
	    a.document.write('<head>');
	    a.document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>');
	    a.document.write('<link rel="stylesheet" href="/sitebase/sifr/css/sifr.css" type="text/css">');
        a.document.write('<link rel="stylesheet" href="/sitebase/css/visasida.css" type="text/css" media="all" />');
        a.document.write('<scr'+'ipt src="/sitebase/sifr/js/sifr.js" type="text/javascript"></scri'+'pt>');
        a.document.write('<scr'+'ipt src="/sitebase/sifr/js/sifr-debug.js" type="text/javascript"></scri'+'pt>');
        a.document.write('<scr'+'ipt src="/sitebase/sifr/js/sifr-config.js" type="text/javascript"></scri'+'pt>');
        a.document.write('<style type="text/css">');
	    a.document.write('body, #mainContainer, #mainContainer #mainInnerContainer {background:url("") #fff;}');
	    a.document.write('#mainContainer .innerPadding {padding:0px 0px 0px 0px;}');
	    a.document.write('#recepieActionsTable {display:none;}');
	    a.document.write('</style>');
	    a.document.write('</head>');
	    a.document.write('<body>');
	    a.document.write('<div id="mainOuterContainer">');
	    a.document.write('<div id="mainContainer">');
	    a.document.write('<div id="mainInnerContainer">');
	    a.document.write('<div class="innerPadding">');
	    a.document.write('<div id="content">');
	    a.document.write(document.getElementById(idToPrint).innerHTML);
	    a.document.write('</div>');
	    a.document.write('</div>');
	    a.document.write('</div>');
	    a.document.write('</div>');
	    a.document.write('</div>');
	    a.document.write('</body>');
	    a.document.write('</html>');
	    a.document.close();
	    a.print();
	    a.close();
	} else {
	    alert('Utskriftsområde saknas');
	}
}

function showAnswer(openThisDiv,resetId) {
	resetAllLinksAndDivs(openThisDiv,resetId);
	if (document.getElementById('link'+ openThisDiv).className=="down") {
		document.getElementById('link'+ openThisDiv).className="links";
		document.getElementById('Div'+ openThisDiv).style.display="none";
	} else {
		document.getElementById('link'+ openThisDiv).className="down";
		document.getElementById('Div'+ openThisDiv).style.display="block";
	}
}		

function resetAllLinksAndDivs(excludeId,within) {
    var within = document.getElementById(within);
    if (within) {
        var elem = within.getElementsByTagName('a');
        for(var i = 0; i < elem.length; i++) {
			if (elem[i].id != 'link'+excludeId) {
            	elem[i].className="links";
			}
        }
		var elem = within.getElementsByTagName('div');
        for(var i = 0; i < elem.length; i++) {
			if (elem[i].id != 'Div'+excludeId) {
				elem[i].style.display="none";
			}
        }
    }
}

//a function to load flashmovies. it also prevents ie from adding the ugly border
function CreateFlash(FlashVars,movie,width,height) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '">');
    document.write('<param name="movie" value="'+ movie +'" />');
    document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="FlashVars" value="'+ FlashVars +'">');
	document.write('<param name="wmode" value="transparent">');
    document.write('<embed src="'+ movie +'" wmode="transparent" quality="high" menu="false" flashvars="'+ FlashVars +'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" />');
    document.write('</object>');
}

function showBox(boxId) {
    var within = document.getElementById('content');
    var elem = within.getElementsByTagName('div');
    for(var i = 0; i < elem.length; i++) {
		if (elem[i].id.indexOf('hiddenBox') > -1) {
			if (elem[i].className == 'hiddenBox' && elem[i].id == 'hiddenBox'+boxId) {
		        elem[i].className = "showBox";
			} else {
				elem[i].className = "hiddenBox";
			}
		}
    }
}

function onLoadCaller() {
	//call all scripts that should load with the page here
	topLocationControl();
	setAllDotNetLinks();
	getThirdMenu();
	checkStartCookie();
	cleanGoogleCustomSearch();
}
if (window.addEventListener) {
	window.addEventListener("load", onLoadCaller, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", onLoadCaller);
} else {
	window.onload=onLoadCaller;
}
