﻿function Toggle(itemID)
{
  var itemRef = document.getElementById(itemID);
	itemRef.style.display = (itemRef.style.display == "block") ? "none" : "block";
}

// skickar folk vidare med hjälp av Javascript (bör bara användas där man försöker gömma länkar för sökmotorer - typ "anmäl detta inlägg" - eller annat där det händer grejer automatiskt vid besök av adressen)
function RedirectUser(redirURL) 
{
    window.location = redirURL;
}

//anropar JS-biblioteket Thickbox
function openInlineDiv(url, height, width, modal, iframe, title) 
{
     //var windowHeight = getWindowHeight();
     ////alert("windowHeight:" + windowHeight);
     //if(windowHeight < height)
     //           height = windowHeight - 60;
    
    //test
    //height = 30;
    
     //var windowWidth = getWindowWidth();
     ////alert("windowWidth:" + windowWidth);
     //if(windowWidth < width)
     //           width = windowWidth - 60;
     ////alert("height:" + height + " - width:" + width);
                
     var separatorSign = "?";
     if(url.indexOf("?") > -1)
                separatorSign = "&";
     
     var addition = separatorSign + "KeepThis=true&" + (iframe ? "TB_iframe=true&" : "") + "height=" + height + "&width=" + width + (modal ? "&modal=true" : "");
     
     tb_show(title, url + addition, title);
     //alert(url + addition);
}


// Force CSS class on buttons
function SetCSS()
{
  var arrInputs = document.getElementsByTagName("input");
  for (i=0; i<arrInputs.length; i++)
  {
    if (arrInputs[i].type == "submit")
    {
      arrInputs[i].className = "button"
    }
  }
}

function InitButtonEvents()
{
	var arrInputButtons = document.getElementsByTagName("input");
	for (i=0; i<arrInputButtons.length; i++)
	{
		if (arrInputButtons[i].className == "button")
		{
			arrInputButtons[i].onmouseover = Over;
			arrInputButtons[i].onmouseout = Out;
		}
	}
	var arrButtons = document.getElementsByTagName("button");
	for (i=0; i<arrButtons.length; i++)
	{
		if (arrButtons[i].className == "button")
		{
			arrButtons[i].onmouseover = Over;
			arrButtons[i].onmouseout = Out;
		}
	}
	function GetTarget(e)
	{
		if (!e) return (window.event.srcElement);
		else return e.target;
	}
	function Over(e)
	{
		if (GetTarget(e).tagName == "INPUT" || GetTarget(e).tagName == "BUTTON")
			GetTarget(e).className = "buttonOver";
		if (GetTarget(e).parentElement.tagName == "BUTTON")
			GetTarget(e).parentElement.className = "buttonOver";
	}
	function Out(e)
	{
		if (GetTarget(e).tagName == "INPUT" || GetTarget(e).tagName == "BUTTON")
			GetTarget(e).className = "button";
		if (GetTarget(e).parentElement.tagName == "BUTTON")
			GetTarget(e).parentElement.className = "button";
	}
}

function Init()
{
	SetCSS();
	InitButtonEvents();
}
//onload = Init;