//*************************************************************************
//***	DOM LIBRARY
//*************************************************************************

//*** GLOBAL VARIABEL
	var blnDOM = false;
	
//*** FUNCTIONS	
	//Advanced dthml check
	if (document.getElementById && document.createElement){
		blnDOM = true;
	}		
	
	//default image switch
	function fjsImgSwitch(id, imgsrc){
		if (blnDOM == true){		
			if (document.getElementById(item)){		
				//Switch image	
				document.getElementById(item).src = imgsrc;			
			}
		}
	}
	
	//Tool, strips away all path info
	function fjsGetFileName(varName) {
		var re = /^.*\/(\S*\.\S*)$/;
		var tmp = new String(varName);
		tmp = tmp.match(re)[1];
			
		return tmp;
	}
	
	//Swap classes for any item
	function fjsSwapClass(strId, class1, class2){
		if (blnDOM == true){			
			//Check if element exists
			if (document.getElementById(strId)){
				//Switch class
				if (document.getElementById(strId).className == class1){
					document.getElementById(strId).className = class2;
				}
				else if(document.getElementById(strId).className == class2){
					document.getElementById(strId).className = class1;
				}
			}
		}
	}
		
	//Change class for any item
	function fjsChangeClass(strId, class1){
		if (blnDOM == true){
			//Check if element exists
			if (document.getElementById(strId)){
				//Change class
				document.getElementById(strId).className = class1;
			}
		}
	}
	
	//Clear input boxes for default data 
	function fjsClearBox(e){			
		e.value = "";
		e.focus();			
	}	
	
	//When IE creates a new element it gives the new element about 84 attributes inherited from IE's default DTD. Oh what fun.
	//And when you try to change an attribute like "class", it actually creates a new attribute so you end up with 2 "class" attributes.
	//So, this function checks your node for a given attribute, if it exists then it changes the attribute value with the one given.
	//If the attribute doesnt exist, it creates a new one and sets its value.
	function fjsToolBox_setAttribute(oNode, strAttribute, strValue) 
	{
		if (oNode.getAttributeNode(strAttribute)) 
		{
			for (var i = 0; i < oNode.attributes.length; i++) {
				var attrName = oNode.attributes[i].name.toUpperCase();
				if (attrName == strAttribute.toUpperCase()) 
				{
					oNode.attributes[i].value = strValue;
				}
			}				
		}
		else {
			//create a new attribute 
			oNode.setAttribute(strAttribute, strValue);
		}
	}

	
	//retrieves content from text nodes
	function fjsToolBox_GetTextNodeContent(n) 
	{			
		var s = '';
		var children = n.childNodes;
		for(var i = 0; i < children.length; i++) 
		{
			var child = children[i];
			if (child.nodeType == 3 /*Node.TEXT_NODE*/) 
			{
				s += child.data;
			}
			else{ 
				s += getTextContent(child);
			}
		}
		return s;
	}
	
	function set3ColHeight(event)
	{
		var col1, col2, col3;
		if(document.getElementById("SiteMenu"))
			col1 = document.getElementById("SiteMenu");

		if(document.getElementById("PageContent"))
			col2 = document.getElementById("PageContent");

		if(document.getElementById("SiteRight"))
			col3 = document.getElementById("SiteRight");
			
		var mH = col1.offsetHeight;
		
		if(mH < col2.offsetHeight)
			mH = col2.offsetHeight;
			
		if(col3 != null && mH < col3.offsetHeight)
			mH = col3.offsetHeight;
			
		col1.style.height = mH + "px";
		col2.style.height = mH + "px";
		if (col3 != null) col3.style.height = mH + "px";
	}
	function setCookie(name, value, days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (days*24*60*60*1000));
			var expires = '; expires=' + date.toGMTString();
		}
		else
			expires = '';
			
		document.cookie = name + '=' + value + expires + '; path=/';
	}
	function getCookie(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 setActiveStyleSheet(title)
	{
		//alert('test');
		//alert(document.getElementById('CssSiteTextSize'))
		if (title == null) return;
		
		var tags = document.getElementsByTagName('link');
		for (var i = 0; i < tags.length; i++)
		{
			if (tags[i].getAttribute("rel") == 'alternate stylesheet')
			{
				tags[i].disabled = true;
				
				if (tags[i].title == title)
					tags[i].disabled = false;
			}
		}
		
		setCookie('ActiveStyleSheet', title, 300);
		//document.getElementById('SiteCssTextSize').href =  '/include/css/site_textsize2.css';
		//set3ColHeight();
		//window.getElementById('CssSiteTextSize').href = '/include/css/site_textsize2.css';
		//alert('test');
		//window.getElementById('CssSiteTextSize').href = '/include/css/site_textsize2.css';
	}

	function addEventHandler(element, eventName, handler)
	{
		if (element.addEventListener)
			element.addEventListener(eventName, handler, false);
		else if (element.attachEvent)
			element.attachEvent('on' + eventName, handler);
	}
	
	//addEventHandler(window, 'load', setActiveStyleSheet);
	addEventHandler(window, 'load', function(e) { setActiveStyleSheet(getCookie('ActiveStyleSheet')); });
	//addEventHandler(document, 'resize', set3ColHeight);
	//addEventHandler(window, 'load', set3ColHeight);
	
	/*
	if (window.attachEvent)
	{
		document.attachEvent('onload', set3ColHeight());
	}
	else if (window.attachEventHandler)
	{
		document.addEventListener('load', set3ColHeight, false);
	}*/
	
