/******************************************************************************
* javascript.js                                                               *
*******************************************************************************
* Invotech Solutions CMS		                                              *
* =========================================================================== *
* Software Version:           IS CMS 1.1                                      *
* Software by:                Invotech Solutions (http://www.invotech.se)	  *
* Copyright 2004-2008 by:     Invotech Solutions AB (http://www.invotech.se)  *
* Support:  				  kontakt@invotech.se	                          *
*******************************************************************************
* Detta program är reglerat av licensavtal av Invotech Solutions		      *
*                                                                             *
* Se "license.txt" för deltaljer om Invotech Solutions AB licensavtal.	      *
*																			  *
******************************************************************************/
//window.onerror=function(){return true;};
var OLloaded = 0; // set overlib loaded status to false
//if(self != top && self.name.indexOf('ajaxframe') == -1)
//	top.location=self.location;

/*$ = function() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}*/
function toggleGPSlist()
{
	document.getElementById('sidebar_gpslist').style.display = (document.getElementById('sidebar_gpslist').style.display=='block')? 'none' : 'block';
	//setEqualHeight();
}
$(document).ready(function(){
	if(typeof DD_belatedPNG != 'undefined') // only set in IE6
		DD_belatedPNG.fix('#footer,#footer_content,#footer_bottom_left,#footer_topleft,#footer_topcenter,#footer_topright,#footer_bottom,.footersep,#logo,.menuitem_left,.menuitem_middle,.menuitem_right,.search_left,.search_middle,.search_right,.content_square,.sidebar_square,.border_top_content,.border_top_sidebar,.border_bottom_content,.border_bottom_sidebar,.border_topleft,.border_topright,.border_bottomleft,.border_bottomright,.sticker_0,.sticker_1,.sticker_2,.sticker_3');
	$('.sidenavlist').css('display','block');
	$('#imgBg').bind("contextmenu",function(e){
		return false;
	});
	/*var active_menuobj;
	$("#firstpane p.menu_head").click(function(){
		$(this).children("a").css('color','#000');
		$(this).children("span").css({backgroundImage:"url(/template_sheets/owes/images/navarrow4x7_down.gif)"});
		$(this).css({backgroundImage:"url(/template_sheets/owes/images/vmenubg.png)"}).next("div.menu_body").slideDown("fast",function(){setEqualHeight();}).siblings("div.menu_body").slideUp("fast",function(){setEqualHeight();});
		$(this).siblings().children("a.navlnk").css('color','#8e8e8e');
		$(this).siblings().children("span").css({backgroundImage:"url(/template_sheets/owes/images/navarrow4x7.gif)"});
		active_menuobj=this;
	});
	$("#firstpane p.menu_head").hover(function(){$(this).children("a").css('color','#000');}, function(){if(active_menuobj!=this)$(this).children("a").css('color','#8e8e8e');});
	*/
	if ($.browser.msie)
	{
		$("#breadcrumblinks a").FontEffect({
			shadow:true,
			shadowOpacity:0.2,
			shadowOffsetTop:1,
			shadowOffsetLeft:1,
			shadowColor:"#000"
		})
		
	}
	
	/*$(function() {
		$('#menuContainer').droppy({speed: 250});
	});*/
	
	/*$(function() {
		$('#sidebar, #content').equalHeight();
	});*/
	
	winOnload();
	
});
function setEqualHeight()
{$('#maincontent').css('min-height','');
	var maxHeight = Math.max($('#maincontent').outerHeight(), ($('#sidebar').outerHeight()-30)); // content top/bottom borders are 15+15px
	var minHeight = maxHeight - ($('#maincontent').outerHeight() - $('#maincontent').height());
	var property = jQuery.browser.msie && jQuery.browser.version < 7 ? 'height' : 'min-height';
	
		$('#maincontent').css(property,minHeight);
}
function doSearch(obj)
{
	if(document.getElementById('search_all').value!='' && document.getElementById('search_all').value!='Sök produkt...')document.getElementById('frmSearch0').submit();
}
getElementsByClass = function(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

toggleTabs = function(obj,obj2)
{
	// set tabs
	var visibletabs = getElementsByClass('tab_active');
	if(visibletabs[0] == obj)
		return;
	visibletabs[0].className = 'tab_inactive';
	obj.className = 'tab_active';
	// set content
	/*var visiblecontent = getElementsByClass('content_visible');
	visiblecontent[0].className = 'content_hidden';
	obj2.className = 'content_visible';*/
	obj2.style.position = 'relative';
	if(_tweenRunning)
	{
		cancelTween();
		sizeTo(_savedObj,_savedWidth,_savedHeight);
	}
	_tweenRunning = false;
	_turned = false;
	_savedObj = null; // for resetting previous object, if animation is interupted
	_savedWidth = obj2.offsetWidth-contentBorderAndPadding_x;
	_savedHeight = obj2.offsetHeight-contentBorderAndPadding_y;
	//tweenLayer(hiddencontent[0].id,easeOutExpo,[hiddencontent[0].offsetWidth-contentBorderAndPadding_x,1], [hiddencontent[0].offsetWidth-contentBorderAndPadding_x, contentMaxHeight], 27);
	tweenLayer(obj2.id, easeOutExpo, [_savedWidth, _savedHeight], [1,1], 20);
	//hiddencontent[0].className = 'content_visible'; // use contentObj[0] as element for ajax content updates..
	
}

//window.onload=function(){vobj=$('tab1');toggleTabs(vobj,vobj.parentNode);};
var contentMaxHeight = 200;
var contentBorderAndPadding_x = 0;
var contentBorderAndPadding_y = 0;
var _tweenRunning = false;
var _savedObj = null;
var _timer = null;
var _turnedtimer = null;
var _tweenTime = 0;
var _turned = false;
var _savedWidth = 0;
var _savedHeight = 0;
tweenLayer = function(obj, method, start, end, time){ // time-based animation, with multiple easing methods
// method: a function that takes 4 arguments: time, start, change, and duration
// start: array of starting width, height dimensions [w, h]
// end: array of ending width, height dimensions [w, h]
// time: number of 'frames' it takes to get to the end position

	if(!_tweenRunning){
		cancelTween(); // reset dis niga
		var s = '['+start.toString()+']';
		var e = '['+end.toString()+']';
		_timer = setInterval('tweenLayer(\''+obj+'\','+method+','+s+','+e+','+time+')', 5);
		_tweenRunning = true;
		_savedObj = obj;
	}
	else
		_tweenTime++;
	if(_tweenTime > time){
		cancelTween();
		if(!_turned){
			var s = '[1,1]';
			var e = '['+_savedWidth.toString()+','+_savedHeight.toString()+']';
			var m = easeInExpo;
			_turnedtimer = setTimeout('tweenLayer(\''+obj+'\', '+m+', '+s+','+e+', '+time+')',5);
			_turned = true;	
		}
	}else{
		var w = method(_tweenTime, start[0], end[0]-start[0], time);
		var h = method(_tweenTime, start[1], end[1]-start[1], time);
		var o = (_tweenTime*(100/time))/100;
		
		//setOpacity(obj,o);
		sizeTo(obj,w,h);
	}
}
cancelTween = function(){ // cancel the tweenLayer method
	clearInterval(_timer);
	_tweenRunning = false;
	_timer = null;
	_turnedtimer = null;
	_tweenTime = 0;
}
sizeTo = function(obj,w,h){ // set the size of the element
	$(obj).style.width = w+'px';
	$(obj).style.height = h+'px';
}
setOpacity = function(obj,o){ // set opacity of the element
	//if(o > 0.98){o = 1;alert('dd');}
	$(obj).style.opacity = o;
	//$(obj).style.filter = "alpha(opacity:"+(o*100)+")";
	$(obj).style.KHTMLOpacity = o;
	$(obj).style.MozOpacity = o;
}

// tween algorithm methods
linearTween = function(t, b, c, d){
	return parseInt(c*t/d + b);
}

easeInQuad = function(t, b, c, d){
	t /= d;
	return parseInt(c*t*t + b);
}
easeOutQuad = function(t, b, c, d){
	t /= d;
	return parseInt(-c * t*(t-2) + b);
}
easeInOutQuad = function(t, b, c, d){
	t /= d/2;
	if (t < 1) return parseInt(c/2*t*t + b);
	t--;
	return parseInt(-c/2 * (t*(t-2) - 1) + b);
}
easeInExpo = function(t, b, c, d){
	return parseInt(c * Math.pow( 2, 10 * (t/d - 1) ) + b);
}
easeOutExpo = function(t, b, c, d){
	return parseInt(c * ( -Math.pow( 2, -10 * t/d ) + 1 ) + b);
}

function openhelp(){
	var height = 400;
	var width = 550;
	var x = (screen.Height/2) - (height/2);
	var y = (screen.Width/2) - (width/2);
	var url="modules/search/help.php";
	newwindow = window.open(url,"","width="+width+",height="+height+",top="+x+",left="+y+",scrollbars=yes,resizable=no");
}

function translatePage(language)
{
    if (language != null)
	{
        var link = "http://www.google.com/translate?u=" + document.location + "&hl=sv&ie=UTF8&sl=en&tl=" + language ;
        window.open(link);
    }
}

function getOffsetX(oNode)
{
	var iOffsetLeft = 0;

	while(oNode.offsetParent)
	{
		iOffsetLeft += oNode.offsetLeft;
		oNode = oNode.offsetParent;
	}

	iOffsetLeft += document.body.offsetLeft;

	return iOffsetLeft;
}

function getOffsetY(oNode)
{
	var iOffsetTop = 0;

	while(oNode.offsetParent)
	{
		//alert(oNode.type);
		iOffsetTop += oNode.offsetTop;
		oNode = oNode.offsetParent;
	}

	iOffsetTop += document.body.offsetTop;
	
	return iOffsetTop;
}

function mouseX(evt)
{
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX;// + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	else return null;
}
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY;// + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	else return null;
}
	
function openlogin(lnkobj,onload,loggedin)
{
	alignedlayer_open(lnkobj,document.getElementById('divLoginFrame'));
	if(!onload)
		ajax_call('http://'+document.domain+'/index.php?action=showloginform&loggedin='+loggedin,'divLogin','','loginfocus();alignedlayer_open();');
	else
		loginfocus();
}
function loginfocus(once)
{
	if(!once) // yea IE is slow
		setTimeout('loginfocus(1);',500);
	if(document.getElementById('login_name') && !document.getElementById('login_name').disabled)
		document.getElementById('login_name').focus();
}
function closelogin()
{
	alignedlayer_close();
}
function open_lostpw()
{
	ajax_call('http://'+document.domain+'/index.php?action=lostpw&showform=1','divLogin','','alignedlayer_open();');	
}

var linklayerobj = null;
function alignedlayer_open(linkobj,layerobj) // makes layer visible, puts it beside clicked link and makes sure it doesn't fall offscreen
{
	if(!layerobj)layerobj=document.getElementById('divLoginFrame');
	if(!linkobj)linkobj=document.getElementById('imgLogin');
	var parentwidth = (document.documentElement.offsetWidth ? document.documentElement.offsetWidth : document.body.offsetWidth);
	var parentheight = (document.documentElement.offsetHeight ? document.documentElement.offsetHeight : document.body.offsetHeight);
	x = getOffsetX(linkobj);
	y = getOffsetY(linkobj);
	var left = ((x+layerobj.offsetWidth) > parentwidth) ? (x - layerobj.offsetWidth) : x;
	var top = ((y+layerobj.offsetHeight) > parentheight) ? (y - layerobj.offsetHeight) : (y + linkobj.offsetHeight);
	layerobj.style.visibility = 'visible';
	layerobj.style.top = top+'px';
	layerobj.style.left = left+'px';
	linklayerobj = layerobj; // set global var used to hide layer later
}
function alignedlayer_show(otop,oleft)
{
	linklayerobj.style.visibility = 'visible';
	linklayerobj.style.top = otop+'px';
	linklayerobj.style.left = oleft+'px';
}
function alignedlayer_close() // closes layer referenced by alignedlayer_open
{
	if(linklayerobj){
		linklayerobj.style.visibility = 'hidden';
		linklayerobj = null;
	}
}

/* IE5.5-6 PNG FIX */
var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7.0);
/*if (itsAllGood && navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
	window.attachEvent("onload", fixPNG);
}*/

function fixPNG() {
	//for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
	if (itsAllGood)
	{
		var imgs = document.getElementsByTagName('IMG');
		for(var i=0;i<imgs.length;i++)
		{
			var img = imgs[i];
			if (img.src.match(/\.png$/i) != null)
			{
				fnFixPng(img);
				img.attachEvent("onpropertychange", fnPropertyChanged);
			}
			img.style.visibility = "visible";
		}

		var nl = document.getElementsByTagName("INPUT");
		for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
			if (e.className && e.className.match(/\bimage\b/i) != null) {
				if (e.src.match(/\.png$/i) != null) {
					fnFixPng(e);
					e.attachEvent("onpropertychange", fnPropertyChanged);
				}
				e.style.visibility = "visible";
			}
		}
	}
}

function fnPropertyChanged() {
	if (window.event.propertyName == "src") {
		var el = window.event.srcElement;
		if (!el.src.match(/transparentPixel\.gif$/i)) {
			el.filters.item(0).src = el.src;
			el.src = "images/transparentPixel.gif";
		}
	}
}

function dbg(o) {
	var s = "";
	var i = 0;
	for (var p in o) {
		s += p + ": " + o[p] + "\n";
		if (++i % 10 == 0) {
			alert(s);
			s = "";
		}
	}
	alert(s);
}

function fnFixPng(img) {
	
	if(img.className.match(/language/i) != null)return;
	var src = img.src;
	img.style.width = img.width + "px";
	img.style.height = img.height + "px";
	img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
	img.src = "images/transparentPixel.gif";
}

/* END IE5.5-6 PNG FIX */

var shiftkeyispressed = false;
function catchKeyDown(evt)
{

	var keyCode = evt.keyCode || evt.which;

	if ((keyCode == 18)) {
		shiftkeyispressed = true;
		return false;
	}
	return true;
}
function catchKeyUp(evt)
{
	var keyCode = evt.keyCode || evt.which;
	
	
	if ((keyCode == 18)) {
		shiftkeyispressed = false;
		return false;
	}
	return true;
}
function catchMouseDown(evt)
{

	var keyCode = evt.button || evt.which;
	
	if ((keyCode == 2)) {
		shiftkeyispressed = false;
		return false;
	}
    //else
    	//shiftkeyispressed = false;
        
	return true;
}
function catchMouseUp(evt)
{

	var keyCode = evt.button || evt.which;
	if ((keyCode == 2)) {
		shiftkeyispressed = true;
		return false;
	}
	else
		shiftkeyispressed = false;
	return false;
}
function addEvent(obj, evType, fn, useCapture)
{
// General function for adding an event listener
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	}
	else {
		alert("handler could not be attached");
	}
}
function addKeyEvent()
{




// Specific function for this situation
	
	   evtDown = (window.addEventListener) ? 'mouseup' : 'mouseup';
	   addEvent(document,evtDown,catchMouseUp,false);

		evtDown = (window.addEventListener) ? 'mousedown' : 'mousedown';
		addEvent(document,evtDown,catchMouseDown,false);
		
		
	//evtRes = (window.addEventListener) ? 'resize' : 'resize';
	//addEvent(window,evtRes,tstst,false);
	//evtDown = (document.addEventListener) ? 'keydown' : 'keydown';
	//addEvent(document,evtDown,catchKeyDown,false);
	//evtUp = (document.addEventListener) ? 'keyup' : 'keyup';
	//addEvent(document,evtUp,catchKeyUp,false);
}

function activateBtn(frm,txt,btn)
{
	// crude/stupid/etc
	if(typeof(frm) == 'object')
	{
		if(txt.value!='')
			btn.disabled=false;
		else
			btn.disabled=true;
	}
	else
	{
		/*if(typeof(document.forms['frmSearch0']) == 'object')
		{
			if(document.forms['frmSearch0'].txtSearch0.value!='')
				document.forms['frmSearch0'].btnSubmit0.disabled=false;
			else
				document.forms['frmSearch0'].btnSubmit0.disabled=true;
		}*/
		if(typeof(document.forms['frmSearch1']) == 'object')
		{
			if(document.forms['frmSearch1'].txtSearch1.value!='')
				document.forms['frmSearch1'].btnSubmit1.disabled=false;
			else
				document.forms['frmSearch1'].btnSubmit1.disabled=true;
		}
	}
}

function evenemang(id,key) {
var open_var = ("http://www.eventonline.se/anmalan.php?eid=" + id + "&key=" + key);
	SkrivUtWnd = window.open(open_var, "anmalan", "width=332,height=650,status=no,location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=no");
	SkrivUtWnd.focus();
	return;
}

function checkSIZE()
{

	if(document.getElementById)
	{	
		var eventscroll = document.getElementById('eventscroll');
		var myDiv = document.getElementById("myDiv");
	}
	else 
		if(document.all)
			{
				var eventscroll = document.getElementById('eventscroll');			
				var myDiv = document.all['myDiv'];
			}


	var temp = eventscroll.offsetHeight;
	if(temp > 400)
	{
		eventscroll.style.height = 400;
		eventscroll.style.overflow = 'auto';
	}
	
	var h = myDiv.offsetHeight + 43;
	var w = 763;
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	
	w = w+60;
	h = h+47;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
			w = w + 50;
			h = h + 18;
	 }
	}
	
	window.resizeTo(w,h); 
}

function DisableAllForms(xHow)
{
	for (var i = 0; i < document.forms.length; i++) {
        for (var j = 0; j < document.forms[i].elements.length; j++) {
            document.forms[i].elements[j].disabled = xHow;
        }
    }
}
function DisableEnableLinks(xHow)
{
	DisableAllForms(xHow);
	objLinks = document.links;
	for(i=0;i<objLinks.length;i++){
		if(objLinks[i].className == 'menuButton')
		{
			objLinks[i].disabled = xHow;
			//link with onclick
			if(objLinks[i].onclick && xHow){  
				objLinks[i].onclick = new Function("return false;");
			}
			//link without onclick
			else if(xHow){  
			  objLinks[i].onclick = function(){return false;}
			}
			//remove return false with link without onclick
			else if(!xHow && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1){            
			  objLinks[i].onclick = null;
			}
			//remove return false link with onclick
			else if(!xHow && objLinks[i].onclick.toString().indexOf("return false;") != -1){  
			  strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;","")
			  objLinks[i].onclick = new Function(strClick);
			}
		}
	}
}
String.prototype.getFuncBody = function(){ 
  var str=this.toString(); 
  str=str.replace(/[^{]+{/,"");
  str=str.substring(0,str.length-1);   
  str = str.replace(/\n/gi,"");
  if(!str.match(/\(.*\)/gi))str += ")";
  return str; 
} 
// START SEARCH HILIGHTER
/* New: Variable searchhi_string to keep track of words being searched. */
var searchhi_string = '';
var hlOn = new Array();
var classcount = 0;
/* http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */
function togglehighlightWord(node,word)
{
	if(node.hlOn)
		unhighlightWord(node,word);
	else
		highlightWord(node,word)
}

function highlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}

	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className.indexOf("searchword") == -1) {
				// word has not already been highlighted!
				
		//alert('hlword:'+hlOn[tempWordVal]);
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword_"+hlOn[tempWordVal];
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function unhighlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			unhighlightWord(node.childNodes[hi_cn],word);
		}
	}

	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className == "searchword") {
				prevSib = pn.previousSibling;
				nextSib = pn.nextSibling;
				nextSib.nodeValue = prevSib.nodeValue + node.nodeValue + nextSib.nodeValue;
				prevSib.nodeValue = '';
				node.nodeValue = '';
			}
		}
	}
}

function unhighlightWord2(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			unhighlightWord2(node.childNodes[hi_cn],word);
		}
	}

	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className.indexOf("searchword") != -1) {
				prevSib = pn.previousSibling;
				nextSib = pn.nextSibling;
				nextSib.nodeValue = prevSib.nodeValue + node.nodeValue + nextSib.nodeValue;
				prevSib.nodeValue = '';
				node.nodeValue = '';
			}
		}
	}
}

function unhighlight(node) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			unhighlight(node.childNodes[hi_cn]);
		}
	}

	// And do this node itself
	if (node.nodeType == 3) { // text node
		pn = node.parentNode;
		if(pn.className.indexOf("searchword") != -1) {
			prevSib = pn.previousSibling;
			nextSib = pn.nextSibling;
			nextSib.nodeValue = prevSib.nodeValue + node.nodeValue + nextSib.nodeValue;
			prevSib.nodeValue = '';
			node.nodeValue = '';
		}
	}
}

function googleSearchHighlight() {
	if (!document.createElement) return;
	ref = document.referrer;
        ref = ref.replace(/\/search\/web\//,'?search&q='); // Most WebCrawler searches
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
        qsa = qs.split('#');
        qs = qsa[0];
        qs = qs.replace(/(^|&)p=Q&ts=e&/,'&'); // Most Eurekster searches
        qs = qs.replace(/(^|&)query=/,'&q='); // Most Lycos searches
        qs = qs.replace(/(^|&)key=/,'&q='); // Most Walhello searches
        qs = qs.replace(/(^|&)keywords=/i,'&q='); // Most Overture searches
        qs = qs.replace(/(^|&)searchfor=/,'&q='); // Most Mysearch.com searches
        qs = qs.replace(/(^|&)qt=/,'&q='); // Most Acoona.com searches
        qs = qs.replace(/(^|&)s=/,'&q='); // Most Technirati GET searches
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'q' || qsip[0] == 'p' || qsip[0] == 'w') { // q= for Google, p= for Yahoo, w= for Eurekster
			// Trim leading and trailing spaces after unescaping
			qsip[1] = unescape(qsip[1]).replace(/^\s+|\s+$/g, "");
			if( qsip[1] == '' ) continue;
                        phrases = qsip[1].replace(/\+/g,' ').split(/\"/);
			for(p=0;p<phrases.length;p++) {
			        phrases[p] = unescape(phrases[p]).replace(/^\s+|\s+$/g, "");
				if( phrases[p] == '' ) continue;
				if( p % 2 == 0 ) words = phrases[p].replace(/([+,()]|%(29|28)|\W+(AND|OR)\W+)/g,' ').split(/\s+/);
				else { words=Array(1); words[0] = phrases[p]; }
	                	for (w=0;w<words.length;w++) {
					if( words[w] == '' ) continue;
					highlightWord(document.getElementsByTagName("body")[0],words[w]);
					if( p % 2 == 0 ) searchhi_string = searchhi_string + ' ' + words[w];
					else searchhi_string = searchhi_string + ' "' + words[w] + '"';
                		}
			}

	        }
	}
}

// Everything form this point on is modified to allow for highlighting
// of terms found in the REQUEST URI
function localSearchHighlight(searchStr,wcnt) {
	if (!document.createElement) return;
        if (searchStr == '') return;
	if (searchStr.indexOf('?') == -1) qs = searchStr.substr(0);
	else qs = searchStr.substr(1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'h') { // don't make this q or p or will get ghost highlights
			// Trim leading and trailing spaces after unescaping
			qsip[1] = unescape(qsip[1]).replace(/^\s+|\s+$/g, "");
			if( qsip[1] == '' ) continue;
                        phrases = qsip[1].replace(/\+/g,' ').split(/\"/);
			// Use this next line if you would like to force the script to always
			// search for phrases. See below as well!!!
			phrases = new Array(); phrases[0] = ''; phrases[1] = qsip[1].replace(/\+/g,' ');
			for(p=0;p<phrases.length;p++) {
			        phrases[p] = unescape(phrases[p]).replace(/^\s+|\s+$/g, "");
				if( phrases[p] == '' ) continue;
				if( p % 2 == 0 ) words = phrases[p].replace(/([+,()]|%(29|28)|\W+(AND|OR)\W+)/g,' ').split(/\s+/);
				else { words=Array(1); words[0] = phrases[p]; }
	                	for (w=0;w<words.length;w++) {
					if( words[w] == '' ) continue;
					//highlightWord(document.getElementsByTagName("body")[0],words[w]);
		if(hlOn[words[w].toLowerCase()]) {
			hlOn[words[w].toLowerCase()] = null;
			//classcount--;
			localSearchUnHighlight(searchStr);
		}
		else {
		//classcount++;			
		hlOn[words[w].toLowerCase()] = wcnt;
					highlightWord(document.getElementById("content"),words[w]);
					//highlightWord(document.getElementById("divSearchinfo"),words[w]);
					if( p % 2 == 0 ) searchhi_string = searchhi_string + ' ' + words[w];
					//else searchhi_string = searchhi_string + ' "' + words[w] + '"';
					// As before, use this next line if forcing phrase searching
					else searchhi_string = searchhi_string + ' ' + words[w];
		}
                		}
			}
	        }
	}
}

function localSearchUnHighlight(searchStr) {
	//hlOn[0] = null;
	
	if (!document.createElement) return;
        if (searchStr == '') return;
	if (searchStr.indexOf('?') == -1) qs = searchStr.substr(0);
	else qs = searchStr.substr(1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'h') { // don't make this q or p or will get ghost highlights
			// Trim leading and trailing spaces after unescaping
			qsip[1] = unescape(qsip[1]).replace(/^\s+|\s+$/g, "");
			if( qsip[1] == '' ) continue;
                        phrases = qsip[1].replace(/\+/g,' ').split(/\"/);
			// Use this next line if you would like to force the script to always
			// search for phrases. See below as well!!!
			phrases = new Array(); phrases[0] = ''; phrases[1] = qsip[1].replace(/\+/g,' ');
			for(p=0;p<phrases.length;p++) {
			        phrases[p] = unescape(phrases[p]).replace(/^\s+|\s+$/g, "");
				if( phrases[p] == '' ) continue;
				if( p % 2 == 0 ) words = phrases[p].replace(/([+,()]|%(29|28)|\W+(AND|OR)\W+)/g,' ').split(/\s+/);
				else { words=Array(1); words[0] = phrases[p]; }
	                	for (w=0;w<words.length;w++) {
					if( words[w] == '' ) continue;
					//highlightWord(document.getElementsByTagName("body")[0],words[w]);
					unhighlightWord2(document.getElementById("content"),words[w]);
					//highlightWord(document.getElementById("divSearchinfo"),words[w]);
					if( p % 2 == 0 ) searchhi_string = searchhi_string + ' ' + words[w];
					//else searchhi_string = searchhi_string + ' "' + words[w] + '"';
					// As before, use this next line if forcing phrase searching
					else searchhi_string = searchhi_string + ' ' + words[w];
                		}
			}
	        }
	}
}

function unHighlightAll()
{
	SmartHLUnload();
	unhighlight(document.getElementById("content"));
	//unhighlight(document.getElementById("divSearchinfo"));
	unhighlight(document.getElementsByTagName("body")[0]);
	document.getElementById('divSearchinfo').style.display = "none";
}

function SearchHighlight() {
	googleSearchHighlight();
	localSearchHighlight(location.search);

        // Trim any leading or trailing space
        // (this is an overkill way of getting rid of the leading
        //  space that always is present in searchhi_string)
        searchhi_string = searchhi_string.replace(/^\s+|\s+$/g, "");
	if(searchhi_string != '')
	{
        // In MSIE, sometimes the dynamic generation of the spans
        // for the highlighting takes the anchor out of focus.
        // Here, we put it back in focus.
        if( location.hash.length > 1 ) location.hash = location.hash;
		
		document.getElementById('divSearchinfo').style.display = "block";
		/*document.getElementById('divSearchinfo').style.position='relative';
		document.getElementById('divSearchinfo').style.left = (document.getElementById('divSearchinfo').offsetParent.offsetWidth - document.getElementById('divSearchinfo').offsetWidth) - 5 + 'px';
		document.getElementById('divSearchinfo').style.top = (document.getElementById('divSearchinfo').offsetTop - 10) + 'px';
		//document.getElementById('divSearchinfo').style.top = (document.getElementById('topspace').offsetTop + 30) + 'px';
		alert(document.getElementById('divSearchinfo').offsetParent.id);*/
	}
}

function toggleSearchbox()
{
	if(document.getElementById('divSearchinfo').style.display == "none")
		document.getElementById('divSearchinfo').style.display = "block";
	else
		document.getElementById('divSearchinfo').style.display = "none";
		return true;
}


function SmartHighlight()
{
	// This function is like SearchHighlight()
	// but it detects a page refresh and toggles highlighting
	// on each refresh. This gives a quick way to turn off
	// highlighting (and quickly turn it on after).

	var today = new Date();
	var now = today.getUTCSeconds();

	var cookie = document.cookie;
	var cookieArray = cookie.split('; ');

	// Get timestamp stored in cookie
	for (var loop=0; loop < cookieArray.length; loop++){
		var nameValue = cookieArray[loop].split("=");
		if (nameValue[0].toString() == 'SHTS'){
			var cookieTime = parseInt( nameValue[1] );
		}
		else if (nameValue[0].toString() == 'SHTSP'){
			var cookieName = nameValue[1];
		}
	}

	// If we got a cookie, the cookie is from this page,
	// and the cookie's time is very close to now, then
	// this must be a page refresh (or very similar)
	// so we don't want to highlight. (the 5 second threshold
	// may need to be adjusted for slower browsers/pages/etc.)
	if( cookieName &&
		cookieTime &&
		cookieName == escape(location.href) && 
		Math.abs(now - cookieTime) < 5 )
	{
		// Refresh detected, so don't highlight

		// Disable refresh detection for this run;
		// this is what allows us to toggle the highlighting
		// back *ON* on the next refresh
		searchhi_unl = 0;
	}
	else
	{
		// This is not a refresh, so highlight
		SearchHighlight();
	}

}

function SmartHLUnload()
{
	if( searchhi_unl > 0 )
	{
		// Turn refresh detection on so that if this
		// page gets quickly loaded, we know it's a refresh
		var today = new Date();
		var now = today.getUTCSeconds();
		document.cookie = 'SHTS=' + now + ';';
		document.cookie = 'SHTSP=' + escape(location.href) + ';';
	}
	else
	{
		// Refresh detection has been disabled
		document.cookie = 'SHTS=;';
		document.cookie = 'SHTSP=;';
	}
}

function NotRefreshHL() 
{
	// This is not a refresh. It's probably a submit
	// with the same search string, so disable refresh
	// detection on this go around.
	searchhi_unl = 0;
	return true;
}

// By default, turn refresh detection on
var searchhi_unl = 1;

// window.onload = SearchHighlight;
// window.onload = SmartHighlight;
// window.onunload = SmartHLUnload;

// END SEARCH HILIGHTER

var ajaxObjects = new Array();
function ajax_call(str,element,form,oncomplete)
{
	//if(str == ajax_laststring)
		//return false;
	ajax_laststring = str;
	//toggleloader(1);
	var ajaxqs = "";
	var ajaxIndex = ajaxObjects.length;	
	ajaxObjects[ajaxIndex] = new sack();
	var ajaxqs = "&ajaxaction=1&ajax=true";

	if(form)
	{
		var elem = document.forms[form].elements;
		for(var i = 0; i < elem.length; i++)
		{
			if(elem[i].type == 'checkbox' || elem[i].type == 'radio')
			{
				if(elem[i].checked)
						ajaxObjects[ajaxIndex].setVar(elem[i].name, elem[i].value); 
			}
			else
				ajaxObjects[ajaxIndex].setVar(elem[i].name, elem[i].value);
		}
	}
	if(element)
	{
		ajaxObjects[ajaxIndex].element = element;
		//document.getElementById(element).innerHTML = '<div align="center"><br /><strong>Vänta...</strong><br /><img src="http://'+document.domain+'/images/ajax-loader.gif" alt="" align="middle" style="margin:10px;" /></div>';
		document.getElementById(element).innerHTML = '<div align="center"><div style="width:155px;height:105px;background:url(/images/loading...gif) no-repeat;"><span id="spnLoader" style="font:11px Arial,sans-serif;font-weight:bold;color:#1a6384;"></span><br /><img src="/images/ajax-loader.gif" alt="" style="position:relative;top:3px;" /></div>';
	}

	ajaxObjects[ajaxIndex].onCompletion = function() { if(element)ajaxObjects[ajaxIndex].element.innerHTML = ajaxObjects[ajaxIndex].response;if(oncomplete=='evalreturn')eval(ajaxObjects[ajaxIndex].response);else if(oncomplete)eval(oncomplete); } ;	// Specify function that will be executed after file has been found
	
	ajaxObjects[ajaxIndex].requestFile = str + ajaxqs;	// Specifying which file to get
//alert(ajaxObjects[ajaxIndex].requestFile);
	//ajaxObjects[ajaxIndex].onLoaded = function() {toggleloader(0);}
	ajaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function
}
var loaderwait;
function toggleloader(on,str)
{
	if(navigator.userAgent.indexOf("Opera") != -1 || navigator.appVersion.indexOf("Safari") != -1)
		return;
	if(on) {
		//parent.document.getElementById('divLoader').style.display='block';
		document.getElementById('divLoaderFrame').style.visibility='visible';
		if(str)
			document.getElementById('spnLoader').innerHTML=str;
		/*if (document.documentElement && document.documentElement.scrollTop){
			var wintop = document.documentElement.scrollTop;
			var middle = document.documentElement.clientHeight/3;
		}
		else if (document.body){
			var wintop = document.body.scrollTop;
			var middle = document.body.clientHeight/3;
		}
		else if (window.innerHeight){
			var wintop = window.pageYOffset;
			var middle = window.innerHeight/3;
		}
		var elTop = getOffsetY(document.getElementById('maincontent'));
		var elLeft = getOffsetX(document.getElementById('maincontent'));
		var elWidth = document.getElementById('maincontent').offsetWidth;
		var elHeight = document.getElementById('maincontent').scrollHeight;
		var loaderHeight = document.getElementById('divLoadercontent').offsetHeight;
		var loaderWidth = document.getElementById('divLoadercontent').offsetWidth;
		var movetoLeft = elLeft + (elWidth/2) - (loaderWidth/2);
		var movetoTop = elTop + (elHeight/2) - (loaderHeight/2);
		if(movetoTop > 400)movetoTop=400;
		document.getElementById('divLoadercontent').style.marginLeft = movetoLeft+'px';
		document.getElementById('divLoadercontent').style.marginTop = movetoTop+'px';*/
		//document.getElementById('maincontent').style.filter = 'alpha(opacity:20)';
		//document.getElementById('maincontent').style.opacity = '.20';
		//return alignLayer('divLoaderFrame','',wintop+middle);
	}
	else {
		clearTimeout(loaderwait);
		//parent.document.getElementById('divLoader').style.display='none';
		document.getElementById('divLoaderFrame').style.visibility='hidden';
		//document.getElementById('divLoadercontent').style.margin = '300px auto';
		//document.getElementById('maincontent').style.filter = 'alpha(opacity:100)';
		//document.getElementById('maincontent').style.opacity = '1.00';
	}
}

function scrollToTop() // scroll to top but do not go sidewayazzz
{
	var leftPos = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
	window.scrollTo(leftPos,0);
}

var ajax_laststring;
function ajax_action(str,completion,form,element,callstr,onComplete,frameTarget,ischild,nomsg)
{
	//if(str == ajax_laststring)
		//return false;
	ajax_laststring = str;
	var ajaxqs = "";
	if(!nomsg){
		if(str.indexOf('sendmail') > -1)
			toggleloader(1,'Skickar...');
		else
			loaderwait = setTimeout('toggleloader(1);',500);
	}
	var ajaxIndex = ajaxObjects.length;	
	ajaxObjects[ajaxIndex] = new sack();
	var et = (str.indexOf('?') > -1) ? '&' : '?';
	if(ischild)
		ajaxObjects[ajaxIndex].child = ischild;
	else
		var ajaxqs = et+"ajax=true&ajaxaction=1";
		
	if(element)
		ajaxObjects[ajaxIndex].element = element;
	
	//if(element)ajaxObjects[ajaxIndex].element = element;
	if(completion == 'actionshowmsg')
		ajaxObjects[ajaxIndex].onCompletion = function() { if(typeof checkscroll != 'undefined')checkscroll();if(!nomsg)toggleloader(0);window.iframe_actionmsg.location.replace('/icms_showactionmsg.php');window.myframe.location.replace('/icms_showmsg.php');if(element == "callback")if(document.getElementById(element).innerHTML == "true")window.location.replace(callstr); } ;	// Specify function that will be executed after file has been found
	else if(completion == 'showmsg')
		ajaxObjects[ajaxIndex].onCompletion = function() { if(typeof checkscroll != 'undefined')checkscroll();if(!nomsg)toggleloader(0);window.myframe.location.replace('/icms_showmsg.php');if(onComplete)parent.window[onComplete]();if(element == "callback")if(document.getElementById(element).innerHTML == "true")window.location.replace(callstr); };// Specify function 
	else if(completion == 'refresh')
		ajaxObjects[ajaxIndex].onCompletion = function() {if(typeof checkscroll != 'undefined')checkscroll();if(!nomsg)toggleloader(0);parent.window.location.reload();};
	else
		ajaxObjects[ajaxIndex].onCompletion = function() {if(typeof saveEditingItem != 'undefined')loadEditingItems();if(typeof checkscroll != 'undefined')checkscroll();if(!nomsg)toggleloader(0);};
	if(form)
	{
		var elem = document.forms[form].elements;
		for(var i = 0; i < elem.length; i++)
			ajaxObjects[ajaxIndex].setVar(elem[i].name, elem[i].value);
	}
	ajaxObjects[ajaxIndex].requestFile = str + ajaxqs;	// Specifying which file to get
//alert(ajaxObjects[ajaxIndex].requestFile);
	ajaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function
	//ajaxObjects[ajaxIndex].onLoaded = function() {if(!nomsg)toggleloader(0);}
	if(onComplete)
	{
		if(frameTarget == 'myframe')
		myframe.window[onComplete]();
		else
		if(frameTarget == 'iframe_actionmsg')
		iframe_actionmsg.window[onComplete]();
		else
			window[onComplete]();
	
	}
	return false;
}

function checkScrolltop() {
	if (document.documentElement && document.documentElement.scrollTop)
		var wintop = document.documentElement.scrollTop;
	else if (document.body)
		var wintop = document.body.scrollTop;
	else if (window.innerHeight)
		var wintop = window.pageYOffset;
	if(document.getElementById('xToolbar') && document.getElementById('xToolbar').style.display == 'block')
		wintop += parseInt(document.getElementById('xToolbar').offsetHeight);
	if(document.getElementById('adminToolbar'))
		wintop += parseInt(document.getElementById('adminToolbar').offsetHeight);

	var objA = document.getElementById('Layer1');
	var objB = document.getElementById('div_actionmsg');
	var visA = (objA && objA.style.visibility == 'visible') ? true : false;
	var visB = (objB && objB.style.visibility == 'visible') ? true : false;
	if(document.forms['login'])
		var tbl = 'tblLogin';
	else
		var tbl = 'tblMain';
	if(visA)
		alignLayer('myframe',tbl,wintop);
	if(visB)
		alignLayer('iframe_actionmsg',tbl,wintop);
}
function alignLayer(oDiv, oParent, dTop)
{
	//dbg(document.body.clientWidth);
	dTop = (!dTop)?0:dTop;
	var divtyp = (document.getElementById) ? "document.getElementById" : "MM_findObj2";
	var divobj = (document.getElementById) ? document.getElementById(oDiv) : MM_findObj2(oDiv);
	var parobj = (document.getElementById) ? document.getElementById(oParent) : MM_findObj2(oParent);
	if(divobj) {
		if((oParent) && (parobj))
		{
			var dw = parobj.offsetWidth;
			var dh = parobj.offsetHeight;
			var dl = parobj.offsetLeft;
			var dt = parobj.offsetTop;
		}
		else
		{
			if(document.documentElement && document.documentElement.clientWidth) {
				var dw = document.documentElement.clientWidth;
				var dh = document.documentElement.clientHeight;
			}
			else if (document.body) {
				var dw = document.body.clientWidth;
				var dh = document.body.clientHeight;
			}
			else {
				var dw = window.innerWidth;
				var dh = window.innerHeight;
			}
			var dl = 0;
			var dt = 0;
		}
		
		//var lw = divobj.style.width.replace("px","");
		//var lh = divobj.style.height.replace("px","");
		var lw = divobj.offsetWidth;
		var lh = divobj.offsetHeight;
		
		var x = (document.layers) ? ".left" : ".style.left";
		var y = (document.layers) ? ".top" : ".style.top";
		
		cpie = (navigator.appName.indexOf("Microsoft")!=-1)?4:0;
		if (document.body.scrollHeight > document.body.offsetHeight)
			pageHeight = document.body.scrollHeight;
		else
			pageHeight = document.body.offsetHeight-cpie;
		pageWidth = document.body.scrollWidth;
		var leftpos = Math.round((dw/2)-(lw/2))+'px';
		//pageHeight = document.getElementById('cellMaincontent').offsetHeight-5;
//		var pageHeight = document.body.offsetHeight ? parent.document.body.offsetHeight : parent.window.innerHeight;
//		var pageWidth = document.body.offsetWidth ? parent.document.body.offsetWidth : parent.window.innerWidth;

		//var objHeight = divobj.offsetHeight;
		//var objWidth = divobj.offsetWidth;
		//var leftpos = ((pageWidth - parent.document.getElementById(oDiv).offsetWidth) /2)+'px';
		//var leftpos = Math.round((pageWidth/2)-(lw/2))+'px';
		
		//dbg(document.getElementById('iframe_actionmsg').offsetWidth);
		var toppos = Math.round(dTop + 50)+'px';

		//alert(lh+' '+pageHeight+' '+lw+' '+pageWidth);
		if(oDiv == "iframe_actionmsg")
			var movediv = "div_actionmsg";
		else if(oDiv == "myframe")
			var movediv = "Layer1";
		else
			var movediv = oDiv;
		if((lh <= pageHeight) && (lw <= pageWidth))
		{			
		//	eval(divtyp+"('"+movediv+"')"+x+"='"+leftpos+"'");
			eval(divtyp+"('"+movediv+"')"+y+"='"+toppos+"'");
		}
		/*if(movediv == 'Layer1') {
			// have to resize loaderbg to fill screen if document is scrolled..
			
			document.getElementById('divLoader').style.height = pageHeight+'px';
			document.getElementById('iframe_Loader').style.height = pageHeight+'px';
			document.getElementById('divLoader').style.width = pageWidth+'px';
			document.getElementById('iframe_Loader').style.width = pageWidth+'px';
		}*/
	//	alert(dw);
		/*if(movediv == 'Layer1') {
			// have to resize loaderbg to fill screen if document is scrolled..
			
			document.getElementById('divLoader').style.height = pageHeight+'px';
			document.getElementById('iframe_Loader').style.height = pageHeight+'px';
			document.getElementById('divLoader').style.width = pageWidth+'px';
			document.getElementById('iframe_Loader').style.width = pageWidth+'px';
		}*/
		return true;
	}
}

function visibilityToggle(id,action)
{
	var testvis;
    if(document.layers)	   //NN4+
    {
	
		var el = document.layers[id];

		if(action == 'visible')
			el.visibility = "show";		
		else
			el.visibility = "hide";
			
		testvis = (document.layers[id].visibility == "show") ? true : false;
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(id);
			if(action == 'visible')				
			obj.style.visibility = "visible";			
			else
				obj.style.visibility = "hidden";
				
		testvis = (document.getElementById(id).style.visibility == "visible") ? true : false;
    }
    else if(document.all)	// IE 4
    {
		var el = document.all[id].style;
		
		if(action == 'visible')
			el.visibility = "visible";		
		else 
			el.visibility = "hidden";
	
		testvis = (document.all[id].style.visibility == "visible") ? true : false;
    }
	
	/*if(!testvis)
		setTimeout("hideSelects('visible');",100);
	else
		hideSelects('hidden');*/
	/*if(action == 'visible') {
		if(id == 'Layer1')
			document.getElementById('divLoader').style.display='block';
	}
	else {
		if(id == 'Layer1')
			document.getElementById('divLoader').style.display='none';
	}*/
	
	// clean any editor content
	if(action != 'visible') {
		if(id == 'div_actionmsg'){
			window.frames['iframe_actionmsg'].window.location.replace('about:blank');
		}
	}
	return true;
}

function opacity(id, opacStart, opacEnd, millisec) { 
	//speed for each frame 
	if(typeof document.getElementById(id) == 'undefined')
		return false;
	var speed = Math.round(millisec / 100); 
	var timer = 0; 

	//determine the direction for the blending, if start and end are the same nothing happens 
	if(opacStart > opacEnd) { 
		for(i = opacStart; i >= opacEnd; i--) { 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} else if(opacStart < opacEnd) { 
		for(i = opacStart; i <= opacEnd; i++) 
			{ 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} 
}
//change the opacity for different browsers 
function changeOpac(opacity, id) { 
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
	object.filter = "alpha(opacity=" + opacity + ")"; 
}

/* NAVIGATION AJAX */
var linktext = '';
var active_linkobj;
var navwait;
function ajax_nav_showloading(linkobjId)
{
	linkobj = document.getElementById(linkobjId);
	if(linkobj.className != 'tab_active'){
		var linkobjarr = linkobj.id.split('_');
		active_linkobj = document.getElementById('menuloading_'+linkobjarr[1]);
		active_linkobj.className='tab_loading_on';
	}
}
function ajax_nav(str,element,activeclassname,linkobj,formname,nomsg)
{
	if(str == ajax_laststring)
		return false;
	//toggleTabs(linkobj,$(element));
	ajax_laststring = str;
	if(!nomsg){
		//toggleloader(1);
		if(linkobj)
			navwait = setTimeout('ajax_nav_showloading(\''+linkobj.id+'\');',200);
		
	}
	ajax_doc_uri = 'http://'+document.domain+str;
	var ajaxIndex = ajaxObjects.length;	
	ajaxObjects[ajaxIndex] = new sack();
		
	if(element)
		ajaxObjects[ajaxIndex].element = element;
	else
		return confirm('No element set');
	if(formname)
	{
		var elem = document.forms[formname].elements;
		for(var i = 0; i < elem.length; i++)
			ajaxObjects[ajaxIndex].setVar(elem[i].name, elem[i].value);
	}
	ajaxObjects[ajaxIndex].requestFile = str + "&ajaxnav=1";	// Specifying which file to get
	//alert(ajaxObjects[ajaxIndex].requestFile);
	ajaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function
	ajaxObjects[ajaxIndex].onCompletion = function() {ajax_setMenuclasses(linkobj.id, activeclassname);/*if(!nomsg)toggleloader(0);*/}
}

function ajax_setMenuclasses(objId, classId)
{
	//clearTimeout(navwait);
	for(i=1;document.getElementById('navlink_'+i);i++)
	{
		if(objId && 'navlink_'+i == objId)
		{
			document.getElementById(objId).className = classId + '_active';
			
			//document.getElementById('navleft_'+i).className = 'nav_active_left';
			//document.getElementById('navright_'+i).className = 'nav_active_right';
			if(linktext != ''){
			//obj.innerHTML=linktext; // remove loader img from beside the link text
			linktext = '';
			}
			//if(active_linkobj)
				//active_linkobj.className = 'nav_inactive_right';
		}
		else
		{
			document.getElementById('navlink_'+i).className = classId + '_inactive';
			//document.getElementById('navleft_'+i).className = 'nav_inactive_left';
			//document.getElementById('navright_'+i).className = 'nav_inactive_right';
		}
		document.getElementById('menuloading_'+i).className = 'tab_loading_off';
	}
	return false;
}

document.getElementsByClassName = function(clsName)
{
	var retVal = new Array();
	var elements = document.getElementsByTagName("*");
	for(var i = 0;i < elements.length;i++)
	{
		if(elements[i].className.indexOf(" ") >= 0)
		{
			var classes = elements[i].className.split(" ");
			for(var j = 0;j < classes.length;j++){
				if(classes[j] == clsName)
					retVal.push(elements[i]);
			}
		}
		else if(elements[i].className == clsName)
			retVal.push(elements[i]);
	}
	return retVal;
}

var showtranslate = 0;
function toggleTranslate(callerObj)
{
	document.getElementById('divTranslate').style.visibility=(document.getElementById('divTranslate').style.visibility!='visible')?'visible':'hidden';
	document.onmouseup = (document.getElementById('divTranslate').style.visibility=='visible') ? function(){toggleTranslate(callerObj)} : null;
}
function showTranslate(callerObj)
{
	showtranslate=1;
	document.getElementById('divTranslate').style.visibility='visible';
	document.onmouseover = function(){setTimeout('hideTranslate();',2000);};
	document.onclick = hideTranslate;
}
function hideTranslate()
{
	if(!showtranslate){
	document.getElementById('divTranslate').style.visibility='hidden';
	document.onmouseover=null;
	}
}

var textsize1 = '0.7em';
var textsize2 = '0.8em';
var textsize3 = '1.0em';
var textsize_active;
function fontSize_set(sizeval,init)
{
	var tsize = (sizeval == 1) ? textsize1 : (sizeval == 3) ? textsize3 : textsize2;
	$('body').css('fontSize',tsize);
	if(!init)
		createCookie("icms_textsize", sizeval, 0);
	fontSize_setimage(sizeval);
	textsize_active = sizeval;
	return false;
}
function fontSize_init()
{
	var sizefromcookie = readCookie("icms_textsize");
	var tsize = sizefromcookie ? sizefromcookie : 2;
	fontSize_set(tsize,1);
	return false;
}
function fontSize_setimage(val)
{
	$('#imgTextsize_1').css('color', (val==1) ? '#004bf5' : '#333');
	$('#imgTextsize_2').css('color', (val==2) ? '#004bf5' : '#333');
	$('#imgTextsize_3').css('color', (val==3) ? '#004bf5' : '#333');
	$('#imgTextsize_1').css('font-weight', (val==1) ? 'bold' : 'normal');
	$('#imgTextsize_2').css('font-weight', (val==2) ? 'bold' : 'normal');
	$('#imgTextsize_3').css('font-weight', (val==3) ? 'bold' : 'normal');
}
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
 
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function printContent(titleStr)
{
	var printWin = window.open('http://'+document.domain+'/printpage.php?title='+titleStr+'','printWin','width=640,height=480,scrollbars=yes');
	printWin.print();
	return false;
}

/* SPLASH */
function icms_splash_show()
{
	if(document.getElementById('divAdminPopup').style.display == 'block')
		closeAdminpopup();
	var docEl = (document.documentElement) ? document.documentElement : document.body;
	document.getElementById('splashscreen_bg').style.display='block';
	if(parseInt(docEl.scrollHeight) > parseInt(docEl.offsetHeight))
		document.getElementById('splashscreen_bg').style.height = docEl.scrollHeight+'px';
	document.getElementById('splashscreen_bg').innerHTML = '<div class="splashscreen_wrapper"><div class="splashscreen_loader"></div></div>';
	var ajaxIndex = ajaxObjects.length;	
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].element = 'splashscreen_bg';
	ajaxObjects[ajaxIndex].onCompletion = function() {document.getElementById('splashscreen_bg').style.display='block';ajaxObjects[ajaxIndex].element.innerHTML = ajaxObjects[ajaxIndex].response;favs_sndReq();};
    ajaxObjects[ajaxIndex].requestFile = 'http://'+document.domain+'/inc/icms_splash.php?action=splashcontent&language_id='+language_id;
	ajaxObjects[ajaxIndex].runAJAX();
	
	return true;
}
function icms_splash_close(ajx)
{
	if(ajx)
	{
		document.getElementById('splashscreen_bg').style.display='none';
		document.getElementById('splashscreen_bg').innerHTML = '';
	}
	else
	{
		//document.getElementById('splashscreen_bg').innerHTML = '<div class="splashscreen_wrapper"><div class="splashscreen_loader">Stänger...</div></div>';
		var val = (document.getElementById('chkNosplash').checked) ? '1' : '0';			
		ajax_call('http://'+document.domain+'/inc/icms_splash.php?action=showsplash&val='+val+'','','','evalreturn');
	}
	return false;
}
function icms_splash_onresize()
{
	var docEl = (document.documentElement) ? document.documentElement : document.body;
	var sh = (parseInt(docEl.scrollHeight) > parseInt(docEl.offsetHeight)) ? docEl.scrollHeight : docEl.offsetHeight;
		document.getElementById('splashscreen_bg').style.height = sh+'px';
	return false;
}
function icms_splash_openlink(uri,la_id)
{
	icms_splash_close(1);
	openAdminwindow(uri,la_id);
}

// -------
function hideElement(elementId) {
	var element;
	if (document.all)
		element = document.all[elementId];
	else if (document.getElementById)
		element = document.getElementById(elementId);
	if (element && element.style)
		element.style.display = 'none';
}
function showElement(elementId) {
	var element;
	if (document.all)
		element = document.all[elementId];
	else if (document.getElementById)
		element = document.getElementById(elementId);
	if (element && element.style)
		element.style.display = '';
}
function showLinklist() {
	//hideElement('tblEditlinkKlar');
	hideElement('tblEdit');
	//showElement('tblEditlink');
	//showElement('tblLinks');
}
function showLinkedit() {
	//hideElement('tblEditlink');
	//hideElement('tblLinks');
	showElement('tblEdit');
	document.getElementById('addlink').focus();
	//showElement('tblEditlinkKlar');
}
// AJAX //
function favs_sndReq(action,text) 
{
	if(!action || typeof action != 'string')action='get';
	if(!text || typeof text != 'string')text='';
	var ajaxIndex = ajaxObjects.length;	
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].element = 'divLinklist';
	ajaxObjects[ajaxIndex].onCompletion = function() {ajaxObjects[ajaxIndex].element.innerHTML = ajaxObjects[ajaxIndex].response;document.getElementById('favlinksWrapper').style.height=(5+document.getElementById('favlinksHeading').offsetHeight+document.getElementById('divLinklist').offsetHeight)+'px';};
    ajaxObjects[ajaxIndex].requestFile = 'http://'+document.domain+'/inc/icms_splash_favlinks_output.php?action='+action+'&text='+text+'&language_id='+language_id;
	ajaxObjects[ajaxIndex].runAJAX();
}

function favs_handleResponse() 
{
    if(favs_http.readyState == 4)
    {
        var response = favs_http.responseText;
		
		var element;
		if (document.all)
			element = document.all['divLinklist'];
		else if (document.getElementById)
			element = document.getElementById('divLinklist');
		if (element && element.innerHTML)
			element.innerHTML = response;
    }
}
function GetAddLink()
{
	var text = document.getElementById('addlink').value;
	return (text);
}
function GetDeleteLink()
{
	var text = document.getElementById('deletelink').value;
	return (text);
}
/* /SPLASH */

function file_exists (url) {
    // Returns true if filename exists  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/file_exists    // +   original by: Enrique Gonzalez
    // +      input by: Jani Hartikainen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
    // %        note 1: Synchronous so may lock up browser, mainly here for study purposes.     // *     example 1: file_exists('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
    // *     returns 1: '123'
    
    var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (!req) {throw new Error('XMLHttpRequest not supported');}      
    // HEAD Results are usually shorter (faster) than GET
    req.open('HEAD', url, false);
    req.send(null);
    if (req.status == 200){        return true;
    }
    
    return false;
}

var ol_cgbackground="/admin/images/layout/showactionmsg_top2.gif";
var ol_fadetime=0;
var ol_fadein=0;
var ol_filter=1;
var ol_filteropacity=95;
var ol_filtershadow=2;
var ol_filtershadowcolor="#1c1c1c";
var ol_close="<img border='0' src='/admin/images/layout/closebutton2.gif' alt='' onMouseDown=\"this.src='/admin/images/layout/closebutton_down2.gif';\" onMouseUp=\"this.src='/admin/images/layout/closebutton2.gif';\" onMouseOver=\"this.src='/admin/images/layout/closebutton_over2.gif';\" onMouseOut=\"this.src='/admin/images/layout/closebutton2.gif';\" hspace='2' vspace='2' />";
var ol_bgcolor="#535353";
var ol_closetitle="Klicka för att stänga";
var icms_loaderimage_src = (itsAllGood) ? "loading...gif" : "loading...png";
var icms_loaderimage_alpha = (itsAllGood) ? 'filter:alpha(opacity=85);-moz-opacity:0.85;opacity:.85;' : '';
