// Created by: 	Michael Nilsson, Bysted
// Date: 		15-06-2006

// *********************************************************************
// Function to change elements background image
// *********************************************************************

function ChangeMainMenuHover(myElementId) {

	var myElementId = myElementId.id ;
	
	// Change item background image
	document.getElementById(myElementId).className = 'MainMenu' + myElementId + 'Hover' ;
	
}

function ChangeMainMenuActive(myElementId) {

	var myElementId = myElementId.id ;
	
	// Change item background image
	document.getElementById(myElementId).className = 'MainMenu' + myElementId ;
	
}

// *********************************************************************
// Function enables us to click a table cell
// *********************************************************************

function GoToUrl(myUrl, newWindow) {

  if (newWindow == true){
	window.open(myUrl);
  }
  else{
	document.location.href = myUrl ;
  }  
}

// *********************************************************************
// Function enables us to change images in the frontpage tabbox
// *********************************************************************

function tabboxClick(myId) {

	var myElementId = myId.id ;
	
	if (myElementId === 'tabbox1') {
	// Set tabs
	document.getElementById('tabbox1').className = 'TabboxTab1Hover' ;
	document.getElementById('tabbox2').className = 'TabboxTab2Active' ;
	// Display / hide content
	document.getElementById('tabbox1Content').style.display = 'block' ;
	document.getElementById('tabbox2Content').style.display = 'none' ;
	}
	
	if (myElementId === 'tabbox2') {
	// Set tabs
	document.getElementById('tabbox1').className = 'TabboxTab1Active' ;
	document.getElementById('tabbox2').className = 'TabboxTab2Hover' ;
	// Display / hide content
	document.getElementById('tabbox1Content').style.display = 'none' ;
	document.getElementById('tabbox2Content').style.display = 'block' ;
	}

}

// *********************************************************************
// Function Increase / Decrease text size
// *********************************************************************

function TextEnlarge(myElement, enlargeText, decreaseText) {
	if (document.body.style.fontSize == '13px') {
		// Change general body font size
		document.body.style.fontSize = '11px' ;
		
		// Change enlarge / decrease label
		myElement.innerHTML = enlargeText ;
		myElement.title = enlargeText ;
		
		return;

		// Do not change the top menu elements
		document.getElementById('UnChangeable1').style.fontSize = '11px' ;
		document.getElementById('UnChangeable2').style.fontSize = '11px' ;
		document.getElementById('UnChangeable3').style.fontSize = '11px' ;
		
	} else {
		// Change general body font size
		document.body.style.fontSize = '13px' ;

		// Change enlarge / decrease label
		myElement.innerHTML = decreaseText ;
		myElement.title = decreaseText ;

		return;

		// Do not change the top menu elements
		document.getElementById('UnChangeable1').style.fontSize = '11px' ;
		document.getElementById('UnChangeable2').style.fontSize = '11px' ;
		document.getElementById('UnChangeable3').style.fontSize = '11px' ;
	}

	myElement.blur() ;
}

// *********************************************************************
// Function replaces select to ul / li (sloppy code)
// *********************************************************************
var SelectTimeout=null;
var SelectTimeoutElement=null;
// <![CDATA[
function selectReplacement(obj) {
  obj.className += ' replaced';
  var ul = document.createElement('ul');
  ul.className = 'selectReplacement';
  var opts = obj.options;
  for (var i=0; i<opts.length; i++) {
	var selectedOpt;
	if (opts[i].selected) {
	  selectedOpt = i;
	  break;
	} else {
	  selectedOpt = 0;
	}
  }
  for (var i=0; i<opts.length; i++) {
	var li = document.createElement('li');
	var txt = document.createTextNode(opts[i].text);
	li.appendChild(txt);
	li.selIndex = opts[i].index;
	li.selectID = obj.id;
	li.value = obj.value;
	li.onclick = function() {
	  selectMe(this);
	}
	if (i == selectedOpt) {
	  li.className = 'selected';
	  li.onclick = function() {
		this.parentNode.className += ' selectOpen';
		this.onclick = function() {
		  selectMe(this);
		}
	  }
	}
	if (window.attachEvent) {
	  li.onmouseover = function() {
		this.className += ' hover';
		if ( SelectTimeout ) {
			clearTimeout(SelectTimeout);
			SelectTimeout=null;
		}
	  }
	  li.onmouseout = function() {
		this.className = 
		  this.className.replace(new RegExp(" hover\\b"), '');
		  SelectTimeout=setTimeout("selectHide();", 100);
		  SelectTimeoutElement=this;
	  }
	}
	ul.appendChild(li);
  }
  obj.parentNode.insertBefore(ul,obj);
}

function selectMe(obj) {
	var lis = obj.parentNode.getElementsByTagName('li');
	for (var i=0; i<lis.length; i++) {
		if (lis[i] != obj) {
			lis[i].className='';
			lis[i].onclick = function() {selectMe(this);}
		} else {
			obj.className='selected';
			setVal(obj.selectID, obj.selIndex);
			obj.parentNode.className = obj.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');
			obj.onclick = function() {
				obj.parentNode.className += ' selectOpen';
				this.onclick = function() { selectMe(this); }
			}
		}
	}
}
function selectHide() {
	if ( SelectTimeoutElement ) {
		SelectTimeoutElement.parentNode.className = SelectTimeoutElement.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');
		SelectTimeoutElement=null;
	}
} // selectHide

function setVal(objID, selIndex) {
  var obj = document.getElementById(objID);
  obj.selectedIndex = selIndex;
 
  if (obj.value.match("http") || obj.value.match("https") || obj.value.match("ftp")) {
	//location.href = obj.value
	window.open(obj.value);
  }

}
function setForm() {
  var s = document.getElementsByTagName('select');
  for (var i=0; i<s.length; i++) {
  // Id with globalRegionalSiteList only to be replaced
  if (s[i].id === 'globalRegionalSiteList' ) {
	selectReplacement(s[i]);
  }
  }
}
window.onload = function() {
  (document.all && !window.print) ? null : setForm();
}
// ]]>

// *********************************************************************
// Function for the tabbox element
// *********************************************************************

function TabBox(headeritemid, contentitemid, tabname) {

// Set tags in document variables

var elms = document.getElementsByTagName("*");
var tabelms = document.getElementsByTagName("*");

// Loop through all the tabs, set to default
// Highlight the selected tab

for( i=0; elms.length>i; i++ ) {
	if( elms[i].className.indexOf('TabsHeader') > -1 ) {
		try {
			elms[i].className='TabsHeader';
			
			// If is tab 1 use a special class
			if ( tabname === '1' ) {
				document.getElementById(headeritemid).className = 'TabsHeaderOverFirstTab' ;
			} else {
				document.getElementById(headeritemid).className = 'TabsHeaderOver' ;
			}
			
		} catch(e) {
			alert('Error block 1:\n'+e.message);
			return false;
		}
	}
}
	  

// Loop through all the tabs, set to display none
// Set display block at the selected tab

for ( i=0; tabelms.length>i; i++ ) {
	if(tabelms[i].className.indexOf('ShowHideTabs')>-1) {
		try {
			tabelms[i].style.display = 'none' ;
			document.getElementById(contentitemid).style.display = 'block' ;
	} catch(e) {
			alert('Error block 2:\n'+e.message) ;
		return false;
		}
	}
	}
}

// *********************************************************************
// Function to toogle the sitemap (onclick)
// *********************************************************************

function ExpandLevel(myElementId,myElementType) {

	var myElementId = myElementId.id ;
	var myElementType = myElementType ;
	
	try {
	
	// Open / close child
		if ( document.getElementById(myElementId + '_collection').style.display == 'none' ) {
		
			try {
				document.getElementById(myElementId + '_collection').style.display = 'block' ;
				
				// Level 1 node
				if (myElementType === 'Type1') {
					document.getElementById(myElementId).className = 'SitemapContainerType01Expanded' ;
				}
				
				// Level 2 node
				if (myElementType === 'Type2') {
					document.getElementById(myElementId).className = 'SitemapContainerType02Expanded' ;
				}
				
				// Level 3 node
				if (myElementType === 'Type3') {
					document.getElementById(myElementId).className = 'SitemapContainerType03Expanded' ;
				}
			
			} catch(e) {
				alert('Error:\n'+e.message) ;
			}
		
		} else {
		
			try {
				
				document.getElementById(myElementId + '_collection').style.display = 'none' ;
				
				// Level 1 node
				if (myElementType === 'Type1') {
					document.getElementById(myElementId).className = 'SitemapContainerType01' ;
				}
				
				// Level 2 node
				if (myElementType === 'Type2') {
					document.getElementById(myElementId).className = 'SitemapContainerType02' ;
				}
				
				// Level 3 node
				if (myElementType === 'Type3') {
					document.getElementById(myElementId).className = 'SitemapContainerType03' ;
				}
				
			} catch(e) {
				alert('Error:\n'+e.message) ;
			}
		
		}
	
	} catch(e) {
		alert('The link does not have a child to open');
	}
	
}

// *********************************************************************
// Function to toogle the sitemap (mouseover + mouseout)
// *********************************************************************

function SitemapOver(myElementId, myType) {
	var myElementId = myElementId.id ;
	var myType = myType ;

	if (myType == 'Type01') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType01Hover') {
			if (document.getElementById(myElementId).className != 'SitemapContainerType01Expanded') {
				document.getElementById(myElementId).className = 'SitemapContainerType01Hover' ;
			}
		}
	}
	
	if (myType == 'Type02') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType02Hover') {
			if (document.getElementById(myElementId).className != 'SitemapContainerType02Expanded') {
				document.getElementById(myElementId).className = 'SitemapContainerType02Hover' ;
			}
		}
	}
	
	if (myType == 'Type03') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType03Hover') {
			if (document.getElementById(myElementId).className != 'SitemapContainerType03Expanded') {
				document.getElementById(myElementId).className = 'SitemapContainerType03Hover' ;
			}
		}
	}
	
	if (myType == 'Type04') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType04Hover') {
			if (document.getElementById(myElementId).className != 'SitemapContainerType04Expanded') {
				document.getElementById(myElementId).className = 'SitemapContainerType04Hover' ;
			}
		}
	}
	
	if (myType == 'Type01None') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType01HoverNone') {
			document.getElementById(myElementId).className = 'SitemapContainerType01HoverNone' ;
		}
	}
	
	if (myType == 'Type02None') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType02HoverNone') {
			document.getElementById(myElementId).className = 'SitemapContainerType02HoverNone' ;
		}
	}
	
	if (myType == 'Type03None') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType03HoverNone') {
			document.getElementById(myElementId).className = 'SitemapContainerType03HoverNone' ;
		}
	}
}

function SitemapOut(myElementId, myType) {
	var myElementId = myElementId.id ;
	var myType = myType ;

	if (myType == 'Type01') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType01Expanded') {
			document.getElementById(myElementId).className = 'SitemapContainerType01' ;
		}
	}
	
	if (myType == 'Type02') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType02Expanded') {
			document.getElementById(myElementId).className = 'SitemapContainerType02' ;
		}
	}
	
	if (myType == 'Type03') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType03Expanded') {
			document.getElementById(myElementId).className = 'SitemapContainerType03' ;
		}
	}
	
	if (myType == 'Type04') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType04Expanded') {
			document.getElementById(myElementId).className = 'SitemapContainerType04' ;
		}
	}
	
	if (myType == 'Type01None') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType01None') {
			document.getElementById(myElementId).className = 'SitemapContainerType01None' ;
		}
	}
	
	if (myType == 'Type02None') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType02None') {
			document.getElementById(myElementId).className = 'SitemapContainerType02None' ;
		}
	}
	
	if (myType == 'Type03None') {
		if (document.getElementById(myElementId).className != 'SitemapContainerType03None') {
			document.getElementById(myElementId).className = 'SitemapContainerType03None' ;
		}
	}
}

// *********************************************************************
// Function to highlight text when mouseover in submit button lookalike
// *********************************************************************
function DynamicSubmitOver(myElementId) {
	document.getElementById(myElementId.id + '_1').className = 'SubmitHover02Hover' ;
}

function DynamicSubmitOut(myElementId) {
	document.getElementById(myElementId.id + '_1').className = 'SubmitHover02' ;
}
 
function CreateFlashTag(FlashPath, FlashStyle, FlashPath)   
{   
    document.write('<OBJECT id="objFlash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');   
    document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" ');   
    document.write('style="' + FlashStyle + '" viewastext>');   
    document.write('<PARAM NAME="movie" VALUE=http://"' + FlashPath + '" ref>');   
    document.write('<PARAM NAME="quality" VALUE="high">');   
    document.write('<PARAM NAME="Menu" VALUE="0">');   
    document.write('<PARAM NAME="Scale" VALUE="ExactFit">');   
    document.write('<PARAM NAME="BGColor" VALUE="#495A74">');   
    document.write('<IMG SRC="' + FlashPath + '" BORDER=0>');
    document.write('</object>'); 

   } 
