// Hides all DIVs in the same parent of the layerid-sent into function
// And then displays the layer
// Also, marks the clicked layerID, and unmarks all other layers in the same parent.
// By using the last paramaters classname
function fnDisplayLayerHideAllFriends(strDisplayDiv,strMark,strMarkWithClass){
	oMark = document.getElementById(strMark);
	oDisplayDiv = document.getElementById(strDisplayDiv);
	
	// Get parents
	oParentMark = oMark.parentNode;
	oParentDiv = oDisplayDiv.parentNode;
	// Loop all friends, set all to hidden (by adding the class "hiddendiv")
	for (var i=0; i < oParentDiv.childNodes.length; i++){
		if (oParentDiv.childNodes[i].nodeName == "DIV"){
			// Get the classes of this DIV
			strClassnames = oParentDiv.childNodes[i].className;
			// Remove any earlier state
			rExp = /visiblediv|hiddendiv/gi;
			strClassnames = strClassnames.replace(rExp, "");
			if (oDisplayDiv.id != oParentDiv.childNodes[i].id){
				// Add a hide-class
				strClassnames = strClassnames + ' hiddendiv';
				
			}else{
				// Add a display class
				strClassnames = strClassnames + ' visiblediv';
			}
			// Set the class
			oParentDiv.childNodes[i].className = strClassnames;
		}
	}
	
	// Loop all friends, set all to be unmarked (by removing the class)
	for (var i=0; i < oParentMark.childNodes.length; i++){
		if (oParentMark.childNodes[i].nodeName == "A"){
			// Get the classes of this Anchor
			strClassnames = oParentMark.childNodes[i].className;
			// Remove any earlier state
			rExp = new RegExp(strMarkWithClass, "gi")
			strClassnames = strClassnames.replace(rExp, "");
			if (oMark.id == oParentMark.childNodes[i].id){
				// Add a selected class
				strClassnames = strClassnames + ' ' + strMarkWithClass;
			}
			// Set the class
			oParentMark.childNodes[i].className = strClassnames;
		}
	}
	// Reset the layout
	oDiv = document.getElementById('frontpagemainwrapperid');
	oDiv.style.height = 'auto';
	oDiv.style.height = '100%';
	
	// Reset the selection, otherwise browser shows active link
	oMark.blur();
}
function textsize(size)
{
		var textDiv = document.getElementById('texttoggler')
		strClassnames = textDiv.className
		// Remove any of the classes if present
		rExp1 = /submain/gi;
		rExp2 = /textmedium/gi;
		rExp3 = /textlarge/gi;
		
		strClassnames = strClassnames.replace(rExp1, "")
		strClassnames = strClassnames.replace(rExp2, "")
		strClassnames = strClassnames.replace(rExp3, "")
		// Add the correct class
		textDiv.className = size
		updateCookie(size, 'ifmetall')
		
}
function checkTextStatus()
{
	textstorlek = GetUserCookie('ifmetall')
	textDiv = document.getElementById('texttoggler')
	textDiv.className = textstorlek
//alert(textstorlek)
}
	var win= null;
	function NewWindow(mypage,myname,w,h)
	{
		var doScroll = '1';
	
	 	var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
		var settings  ='height='+h+',';
	    settings +='width='+w+',';
    	settings +='top='+wint+',';
      	settings +='left='+winl+',';
	    settings +='scrollbars='+doScroll+',';
    	settings +='resizable=0';
//alert(settings)
		win=window.open(mypage,myname,settings);
		if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
function checkToolboxStatus()
{
	
	var toolLayer = new Array();
	toolLayer[0] = 'missions';
	toolLayer[1] = 'contract';
//	toolLayer[2] = 'education';
	toolLayer[2] = 'theclub';
	toolLayer[3] = 'department';
//	toolLayer[5] = 'ifmetall';
	toolLayer[4] = 'bookmark';
	toolbox = GetUserCookie('ifmportal')
	toolboxArray = toolbox.split(',')
	for(n = 0; n < toolboxArray.length;n++)
	{
		if (toolboxArray[n] != 0)
		{
			oElement = document.getElementById(toolLayer[n]);
			oElement.className = 'sel'
		}
	}
}
function docDelete(unid)
{
	oreturn =  document.getElementById('thisPageUrl')
	location.href="/ifmetall/home/reg.nsf/bookmark/" + unid + "?DeleteDocument"
//	location.href=oreturn.value
}
// Function switch disabled
function fnSwitchDisabled(strID,strDisableID){
	oDisable = document.getElementById(strDisableID)
	oEnable = document.getElementById(strID)
	
	oDisable.disabled = true;
	oDisable.value = '';
	oDisable.className = 'disabled';
	oEnable.disabled = false;
	oEnable.className = '';
}
function setBookmark()
{
	oElement1 = document.getElementById('bookmark')
	oElement2 = document.getElementById('bookmarkwrapper')
	oElement1.className = 'sel'
	oElement2.className = 'sel'
	urlElement = document.getElementById('thisPageUrl')
	bookmarkElement = document.getElementById('bookmarkurl')
	bookmarkElement.value = urlElement.value
	elementBookmarkName = document.getElementById('bookmarkname')
	elementRubrik = document.getElementById('rubrik')
	elementBookmarkName.value = elementRubrik.value
}
function saveBookmark()
{
	if (document.frmaddbookmark.bookmarkname.value == "")
	{
		alert("Du måste ange namn på bokmärket")
		return false;
	}
	if (document.frmaddbookmark.bookmarkurl.value == "")
	{
		alert("Bokmärket måste ha en url om du ska kunna spara")
		return false;
	}
	document.frmaddbookmark.submit()
}
function updateCookie(cvalue, name)
{
//         	name = 'ifmportal';
	date = new Date();
  	date.setTime(date.getTime() + (365*24*3600*1000)); 
            	document.cookie = name + '=' + escape(cvalue) + "; expires=" + date.toGMTString() +  "; path=/";  
}
function GetUserCookie(crumbName)
{
    colCookie = document.cookie.split("; ");
    
    for (a=0; a < colCookie.length; a++)
    {
        colCrumb = colCookie[a].split("=");                    
        if(colCrumb[0] == crumbName)
            return unescape(colCrumb[1]);
    }
    return "";
}
// Function to toggle the visibility of a single ID.
function fnToggleLayer(strLayer) {
	
	var toolLayer = new Array();
		toolLayer[0] = 'missions';
		toolLayer[1] = 'contract';
//		toolLayer[2] = 'education';
		toolLayer[2] = 'theclub';
		toolLayer[3] = 'department';
//		toolLayer[5] = 'ifmetall';
		toolLayer[4] = 'bookmark';
	if(strLayer != '') {
		oElement = document.getElementById(strLayer); // hämtar klickad layer
		// Find out if div is hidden or visible
		strClassnames = oElement.className; // kollar om den har klassen sel eller tomt
		rExp = /sel/gi;
		strResults = strClassnames.search(rExp)
		// Remove any of the classes if present
		rExp = /sel/gi;
		strClassnames = strClassnames.replace(rExp, "")
		
		// Add the correct class depending on the first search
		if(strResults === -1){
			strClassnames = 'sel';
		}
		
		oElement.className = strClassnames;
		var makeString = ""
		 
		for(n = 0; n < toolLayer.length;n++)
		{
			element =  document.getElementById(toolLayer[n]);
			isClass = element.className
			if (isClass)
			{
				strValue = '1'
			}
			else
			{
				strValue = '0'
			}
			if (makeString == "")
			{
				separator = "";
			}
			else
			{
				separator = ',';
			}
			makeString = makeString + separator+strValue
		}
		updateCookie(makeString, 'ifmportal')
	}
}
// Function to toggle the visibility of a single ID.
function fnToggleLayerHideSilbings(strLayer) {
	if(strLayer != '') {
		oElement = document.getElementById(strLayer);
		oElementParent = oElement.parentNode;
		// Loop all friends, set all to be unmarked (by removing the class)
		for (var i=0; i < oElementParent.childNodes.length; i++){
			if (oElementParent.childNodes[i].nodeName == "LI"){
				// Get the classes of this Anchor
				strClassnames = oElementParent.childNodes[i].className;
	
				// Remove any earlier state
				rExp = new RegExp("sel", "gi")
				strClassnames = strClassnames.replace(rExp, "");
	
				// Set the class
				oElementParent.childNodes[i].className = strClassnames;
			}
		}
		// Find out if div is hidden or visible
		strClassnames = oElement.className;
		rExp = /sel/gi;
		strResults = strClassnames.search(rExp)
		// Remove any of the classes if present
		rExp = /sel/gi;
		strClassnames = strClassnames.replace(rExp, "")
		// Add the correct class depending on the first search
		if(strResults === -1){
			strClassnames = 'sel';
		}
		oElement.className = strClassnames;
	}
}
// Function to activate hover for LIs on IE
startList = function() {
	if (document.all&&document.getElementById){
		navRoot = document.getElementById("navigation");
		
		if (navRoot != null){
			for (i=0; i<navRoot.childNodes.length; i++){
				node = navRoot.childNodes[i];
				if (node.nodeName == "LI"){
					node.onmouseover = function() {	this.className+= " sel"; }
					node.onmouseout = function() { this.className = this.className.replace(" sel", ""); }
				}
			}
		}
	}
}
// Start script onload
window.onload = startList;

