// this function determines whether the event is the equivalent of the microsoft
// mouseleave or mouseenter events.
function isMouseLeaveOrEnter(e, handler)
{		
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget :
	e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}

function doCalenderMouseOver(e, elem)
{
	if (isMouseLeaveOrEnter(e, elem))
	{
		addClassToElement(elem, 'hover');
	}
}

function doCalenderMouseOut(e, elem)
{
	if (isMouseLeaveOrEnter(e, elem))
	{
		removeClassFromElement(elem, 'hover');
	}
}

// Array Helpers
function isArray(obj)
{
	return obj.constructor.toString().indexOf('Array') != -1;
}

Array.prototype.contains = function (elem)
{
	for (var i=0; i < this.length; i++)
	{
		if (this[i] == elem) return true;
	}
	return false;
}

Array.prototype.getIndexOf = function (elem)
{
	for (var i=0; i < this.length; i++)
	{
		if (this[i] == elem) return i;
	}
	return -1;
}

Array.prototype.removeElement = function (elem)
{
	var out = [];
	for (var i=0; i < this.length; i++)
	{
		if (this[i] != elem) out.push(this[i]);
	}
	return out;
}

// Class manipulation functions
function addClassToElement(element, className)
{
	if (element.className)
	{
		var regex = new RegExp("\\b" + className + "\\b");
		if (!regex.test(element.className)) element.className += ' ' + className;
	}
	else element.className = className;
};

function removeClassFromElement(element, className)
{
	if (element.className)
	{
		var regex = new RegExp("\\b" + className + "\\b");
		element.className = element.className.replace(regex, '').replace(/^\s+|\s+$/g, '')
	}
};

// Stylesheet manipulation functions
function getRule(selectorText)
{
	var length = document.styleSheets.length;
	for (var i=0; i != length; i++)
	{
		var rule = getRuleFromStyleSheet(document.styleSheets[i], selectorText);
		if (rule) return rule;
	}
	return null;
};

function getRuleFromStyleSheet(styleSheet, selectorText)
{
	var length = styleSheet.rules ? styleSheet.rules.length : styleSheet.cssRules.length;
	for (var i=0; i != length; i++)
	{
		var rule = styleSheet.rules ? styleSheet.rules[i] : styleSheet.cssRules[i];
		if (rule.selectorText == selectorText) return {'rule' : rule, 'styleSheet' : styleSheet, 'ruleIndex' : i};
	}
	return null;
};

function addRuleToStyleSheet(styleSheet, rule)
{	
	if (styleSheet.insertRule) styleSheet.insertRule(rule, styleSheet.cssRules.length);
	else if (styleSheet.addRule) styleSheet.addRule(rule.substring(0, rule.indexOf("{")), rule.substring(rule.indexOf("{") + 1, rule.indexOf("}")));
};

function removeRule(selecterText)
{
	var rule = getRule(selecterText);
	if (rule) removeRuleFromStyleSheet(rule.styleSheet, rule.ruleIndex);
}

function removeRuleFromStyleSheet(styleSheet, ruleIndex)
{
	if (styleSheet.deleteRule) styleSheet.deleteRule(ruleIndex);
	else if (styleSheet.removeRule) styleSheet.removeRule(ruleIndex);
};

// The show and hide class helpers assume that the only css rule applied
// specifically to the class is the hide//show code
function showClass(className)
{
	var rule = getRule("." + className);
	if (rule) removeRuleFromStyleSheet(rule.styleSheet, rule.ruleIndex);
};

function hideClass(className)
{
	var rule = getRule("." + className);
	if (!rule) addRuleToStyleSheet(document.styleSheets[0], "." + className + "{ position: relative !important; left: -9999px !important; } ");
};

// Scroll to the top of the page.
function goToTop()
{
	if (document.documentElement) document.documentElement.scrollTop = 0;
}
/*
var font_sizes = new Array( 90, 110, 160 ); 
	var current_font_size = 0;
 	if ( ( typeof( NN_reloadPage ) ).toLowerCase() != 'undefined' ) { NN_reloadPage( true ); }
	if ( ( typeof( opacity_init  ) ).toLowerCase() != 'undefined' ) { opacity_init(); }
	if ( ( typeof( set_min_width ) ).toLowerCase() != 'undefined' ) { set_min_width( 'pageWrapper' , 600 ); }
	if ( ( typeof( loadFontSize ) ).toLowerCase() != 'undefined' ) { event_attach( 'onload' , loadFontSize ); }
*/
function initPage1()
{
	var nav = document.getElementById("nav");
	if (nav)
	{
		var nodes = nav.getElementsByTagName("li");
		for (var i = 0; i < nodes.length; i++)
		{
			if (nodes[i].parentNode.id == "nav")
			{
				nodes[i].onmouseover = function () 
				{
					this.className += " hover";
					hideSelectBoxes(this.getElementsByTagName("ul").item(0));
				}
				nodes[i].onmouseout = function ()
				{
					this.className = this.className.replace("hover", "");
					showSelectBoxes(this.getElementsByTagName("ul").item(0));
				}
			}			
		}

		var nodes = nav.getElementsByTagName("a");
		for (var i = 0; i < nodes.length; i++)
		{
			if(nodes[i].parentNode.parentNode.parentNode.className == "bg")
			{
				nodes[i].onmouseover = function () 
				{
					this.parentNode.parentNode.parentNode.parentNode.parentNode.id = "tmp";
				}				
				nodes[i].onmouseout = function () 
				{
					this.parentNode.parentNode.parentNode.parentNode.parentNode.id = "";
				}				
			}
		}
				
	}
}
if (window.addEventListener)
	window.addEventListener("load", initPage1, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage1);

// tabs
function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;

					if (links[j].parentNode.className.indexOf("active") == -1)
					{
						var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));
						if (c) addClassToElement(c, 'hidden');//c.style.display = "block";
					}

					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							//reset all tabs
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
								this.tabs[i].parentNode.className = this.tabs[i].parentNode.className.replace("active", "");
							}
							this.parentNode.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", initTabs, false);
else if (window.attachEvent)
	window.attachEvent("onload", initTabs);
	
/* Cookie API  v1.0.1
 * documentation: http://www.dithered.com/javascript/cookies/index.html
 * license: http://creativecommons.org/licenses/by/1.0/
 * code (mostly) by Chris Nott (chris[at]dithered[dot]com)
 */
function setCookie( name, value, expires, path, domain, secure )
{
	 var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}
function getCookie( name )
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf( "; " + prefix );
	if ( begin == -1 )
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else
	{
		begin += 2;
	}
	var end = document.cookie.indexOf( ";", begin );
	if ( end == -1 )
	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie( name, path, domain )
{
	var value = getCookie( name );
	if ( value != null )
	{
		document.cookie = name + "=" + 
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
	return value;
}

/* font size functions operate on the body element's
 * style and defines sizes in percentages. because
 * the default font size is set to 0 in the array,
 * the first value in the font_sizes array should
 * _ALWAYS_ be 100.
 *
 *	var font_sizes = new Array( 100, 110, 120 );
 *	var current_font_size = 0;
 *	event_attach( 'onload' , loadFontSize );
 */
function loadFontSize()
{
	current_font_size = parseInt( '0' + getCookie ( "font_size" ) );
	setFontSize ( current_font_size );
	fixLayout();
}
function setFontSize( size )
{
	if( size >= 0 && size < font_sizes.length )
	{
		current_font_size = size;
	}
	else if( ++current_font_size >= font_sizes.length )
	{
		current_font_size = 0;
	}
	if ( document.body )
	{
		document.body.style.fontSize = font_sizes[ current_font_size ] + '%';
		setCookie( "font_size" , current_font_size );
	}
}


function event_attach( event , func )
{

	if ( window.attachEvent )
	{
		window.attachEvent( event , func );
	}
	else
	{
		if ( ( typeof( func ) ).toLowerCase() != 'function' )
		{
			return;
		}
		if ( ( typeof( document.event_handlers ) ).toLowerCase() == 'undefined' )
		{
			document.event_handlers = new Array();
		}
		if ( ( typeof( document.event_handlers[ event ] ) ).toLowerCase() == 'undefined' )
		{
			document.event_handlers[ event ] = new Array();
		}
		if ( ( typeof( eval( 'window.' + event ) ) ).toLowerCase() != 'function' )
		{
			eval( 'window.' + event + ' = function () { if ( ( typeof( document.event_handlers[ \'' + event + '\' ] ) ).toLowerCase() != \'undefined\' ) { for ( i = document.event_handlers[ \'' + event + '\' ].length - 1 ; i >= 0  ; i-- ) { document.event_handlers[ \'' + event + '\' ][ i ](); } } } ' );
		}
		document.event_handlers[ event ][ document.event_handlers[ event ].length ] = func;
	}
}


function fixTextAlign()
{
	var nav = document.getElementById("nav");
	if (nav && window.addEventListener)
	{
		nav.innerHTML = nav.innerHTML + '';
	}
	initPage1();
}
function fixLayout()
{
	var c = document.getElementById("wraper");
	var d = document.getElementById("scale");
	if ( c&&d )
	{
		
		d.style.height = c.offsetHeight - 60 + "px";
	}
}
if (window.addEventListener){
		window.addEventListener("load", fixLayout, false);
}



if (window.addEventListener)
{
	window.addEventListener("load", initTab, false);
	window.addEventListener("load", initSearchMore, false);
}
else if (window.attachEvent && !window.opera)
{
	window.attachEvent("onload", initTab);
	window.attachEvent("onload", initSearchMore);
}

function hideSelectBoxes(object)
{
	if (!object || window.addEventListener) return;
	if (!object.sboxes)
		object.sboxes = [];
	var ol = getElementX(object);
	var ot = getElementY(object);
	var ow = object.offsetWidth;
	var oh = object.offsetHeight;
	var sboxes = document.all.tags("select");
	for (var i=0; i<sboxes.length; i++)
	{
		var node = sboxes[i].parentNode;
		while (node != object && node.tagName != "BODY")
			node = node.parentNode;
		var skip = (node == object);
		if (skip) continue;
		var t = getElementY(sboxes[i]);
		var l = getElementX(sboxes[i]);
		var w = sboxes[i].offsetWidth;
		var h = sboxes[i].offsetHeight;
		var ver = false;
		if (t > ot && t < (ot + oh))
			ver = true;
		else if ((t + h) > ot && (t + h) < (ot + oh))
			ver = true;
		var hor = false;
		if (l > ol && l < (ol + ow))
			hor = true;
		else if ((l + w) > ol && (l + w) < (ol + ow))
			hor = true;
		else if (l < ol && (l + w) > ol)
			hor = true;
		if (ver && hor && sboxes[i].style.visibility != "hidden")
			object.sboxes[object.sboxes.length] = sboxes[i];
	}
	for (var i=0; i<object.sboxes.length; i++)
		object.sboxes[i].style.visibility = "hidden";
}

function showSelectBoxes(object)
{
	if (!object || window.addEventListener) return;
	if (!object.sboxes) return;
	for (var i=0; i<object.sboxes.length; i++)
		object.sboxes[i].style.visibility = "";
	object.sboxes = [];
}

function getElementX(object) {return getElementC(object, true)}
function getElementY(object) {return getElementC(object, false)}

function getElementC(element, xAxis)
{
	var initialElement = element;
	var c = 0;

	while (element != null)
	{
		c += (xAxis) ? element.offsetLeft : element.offsetTop;
		if (element.style.position == "absolute")
			break;
		else
			element = element.offsetParent;
	}

	var elementWnd = document.window;
	if (!elementWnd) return c;

	if (!elementWnd.frameElement) return c;

	return c + getElementC(elementWnd.frameElement, xAxis);
}

function initSearchMore()
{
	var divs = document.getElementsByTagName("ul");
	if (divs)
	{
		for (var i = 0; i < divs.length; i++)
		{
			if (divs[i].className == "more-options")
			{
				var links = divs[i].getElementsByTagName("a");
				for (var j = 0; j < links.length; j++)
				{	
					if (links[j].parentNode.parentNode.tagName == "H3")
					{
						links[j].href = "javascript:;";
						links[j].onclick = function()
						{
							var p = this.parentNode.parentNode.parentNode;
							var _cbx = document.getElementById(p.id.replace("-tab",""));
							
							if (p.className.indexOf("active") != -1 )
							{
								p.className = p.className.replace("active", "");
								if(_cbx)
								{
									_cbx.checked = false;
								}
							}
							else
							{
								p.className += "active";
								if(_cbx)
								{
									_cbx.checked = true;
								}
							}
								
						}
					}
				}
			}
		}
	}
}

// popup
function detectSafari(){ 
if (navigator.appVersion.indexOf("Safari") != -1) 
   document.body.className += " safari"; 
} 

if (window.addEventListener) 
   window.addEventListener("load", detectSafari, false);

var sBar = null;

function doCalendar(button, month, year)
{
	
	function responseHandler(ajaxRequest)
	{			
		var responseXML = (ajaxRequest ? ajaxRequest.responseXML : null);
		if (!responseXML)
		{
			window.location.href = button.href; // we've hit an error, do fall back.
			return;
		}
		
		var html = getXMLEntries(ajaxRequest.responseXML, 'htmlCode').join("");
		var cal = document.getElementById("eventCalendar");
		cal.innerHTML = html;
	}
	
	ajaxSend('post', 'ajaxCalendar.jsp', 'month=' + month + '&year=' + year, responseHandler);
	return false;
}

function doFavourite(event, favButton, favType, favId)
{

	if (favButton)
	{
		var container = favButton.parentNode;
		while (container && container.nodeName != 'LI' && container.nodeName != 'TR') container = container.parentNode;
		if (!container)
		{
			// probably an advice page, look for div with class 'content'
			var container = favButton.parentNode;
			while (container && (container.nodeName != 'DIV' || container.className.indexOf('content') != 0)) container = container.parentNode;
		}
		if (!container) return true; // we've hit an error.  Enable fall back.
		favButton.onclick = doFavourite;
		favButton.container = container;
		favButton.favType = favType;
		favButton.favId = favId; 
	}
	else
	{
		favButton = this;
		favType = favButton.favType;
		favId = favButton.favId;
	}
	
	
	var container = favButton.container;
	var action = container.className && container.className.split(' ').contains("fav") ? 'remove' : 'add';
		
	var parameters = "favType=" + favType + "&favId=" + favId + "&action=" + action;
	
	// Because I'm adding the onclick function directly the this variable will point to the favButton
	// after the 1st time this script is run.  Before that we are grabbing the reference passed in
	// via the HTML onclick declaration.
	if (!favButton) favButton = this;
	
	function responseHandler(ajaxRequest)
	{			
		/*var debug = document.createElement("textarea");
		debug.value = ajaxRequest.responseText;
		document.body.appendChild(debug);*/
		
		var responseXML = (ajaxRequest ? ajaxRequest.responseXML : null);
		if (!responseXML)
		{
			window.location.href = favButton.href; // we've hit an error, do fall back.
			return;
		}
		
		var status = getXMLEntries(ajaxRequest.responseXML, 'status')[0];
		
		if (status != "Ok")
		{
			var userMessages = getXMLEntries(ajaxRequest.responseXML, 'userMessage');
			if (userMessages.length)
			{
				if (userMessages.join("") == "Sorry, you are not logged on.") window.location.href = "/register.jsp?source=fav";
				//alert(userMessages.join("\n\n"));
			}
			else
			{
				// Must be some sort of unexpected error, do fall back
				window.location.href = favButton.href;
			}
			
			return;			
		}
		
		if (action == 'add')
		{
			addClassToElement(container, 'fav');
			favButton.innerHTML = "REMOVE FROM FAVS";
		}
		else
		{
			removeClassFromElement(container, 'fav');		
			favButton.innerHTML = "ADD TO FAVS";
		}		
	}

	showFavNotification(action == 'add' ? "Adding to favourites" : "Removing from favourites");
	ajaxSend('post', '/addRemoveFavourites.jsp', parameters, responseHandler);
	favButton.blur();
	return false;
}

var favNotificationHTML = '<div id="favNotification"><div id="favNotificationStatusBar"><div><img src="/images/favNotificationStar.gif" /></div><div><img src="/images/favNotificationStar.gif" /></div><div><img src="/images/favNotificationStar.gif" /></div></div><span id="favNotificationText">Msg Goes Here</span></div>';
function showFavNotification(msg)
{
	var favNotification = document.getElementById("favNotification");
	if (favNotification)
	{
		 // clear the timers, we'll re-use the notification
		clearTimeout(favNotification.removeTimer);
		clearInterval(favNotification.starTimer);		
	}
	else
	{
		// add the notification
		var tmpDiv = document.createElement("div");
		tmpDiv.innerHTML = favNotificationHTML;
		var favNotification = tmpDiv.firstChild;
		document.body.appendChild(favNotification);
	}
	
	// Center the notification
	var wHeight = document.all && !window.opera ?  document.documentElement.clientHeight : window.innerHeight;	
	favNotification.style.top = (document.documentElement.scrollTop + wHeight/2 - favNotification.clientHeight/2) + 'px';
	favNotification.style.left = (document.documentElement.scrollLeft + document.documentElement.clientWidth/2 - favNotification.clientWidth/2) + 'px';

	// Set the notification text
	var favNotificationText = document.getElementById("favNotificationText");
	favNotificationText.innerHTML = msg;
	
	// Init stars cycle vars
	var favNotificationStatusBar = document.getElementById("favNotificationStatusBar");
	var stars = favNotificationStatusBar.getElementsByTagName("div");
	var maxIndex  = stars.length-1;
	var curPos = -1;

	function cycle()
	{
		if (++curPos > maxIndex) curPos = 0;
		var star = stars[curPos];
		if (star) star.className = star.className ? '' : 'flash';
	}

	// Start stars cycle
	favNotification.starTimer = setInterval(cycle, 100); // cycle every 100ms

	// Remove notification after 2 seconds
	favNotification.removeTimer = setTimeout(removeFavNotification, 2000); // remove after 2 seconds
}

function removeFavNotification()
{
	var favNotification = document.getElementById("favNotification");
	clearInterval(favNotification.starTimer);
	document.body.removeChild(favNotification);
}

function enlarge()
{
	var popup = document.getElementById('adding-favourites');	
	var bars = popup.getElementsByTagName("div");
	for (i = 0; i< bars.length; i++)
	{
		if (bars[i].className.indexOf("status-bar") != -1)
		{
			sBar = bars[i];
		}
	}
	if (sBar && !sBar.active) {
		initSBar();
	}
	
	
	var wHeight = window.innerHeight;	

	if (document.all && !window.opera) {
		wHeight = document.documentElement.clientHeight;
	}
	
	popup.style.display = 'block';
	popup.style.top = (document.documentElement.scrollTop + wHeight/2 - popup.clientHeight/2) + 'px';
	popup.style.left = (document.documentElement.scrollLeft + document.documentElement.clientWidth/2 - popup.clientWidth/2) + 'px';
	return false;
}

function hide()
{
	var popup = document.getElementById('adding-favourites');	
	popup.style.display = 'none';
	
	if (sBar)
	{
		deinitSBar();
	}
}

function initSBar()
{
	sBar.active = 1;
	sBar.images = sBar.getElementsByTagName("img");
	sBar.imagesLength = sBar.images.length - 1;
	//sBar.current = 0;
	sBar.track = 0;
	setTimeout("sBar_scroll(0)", 100);
	
	for (i = 0; i< sBar.images.length; i++)
	{
		
		if (sBar.images[i].src.substr(-8, 4) == "-off")
		{
			sBar.images[i].src = sBar.images[i].src.replace("-off", "");
		}
	}

}

function deinitSBar()
{
	sBar.active = 0;
}

function sBar_scroll(item)
{
	if (sBar.active)
	{
		if (sBar.track)
		{
			sBar.images[item].src = sBar.images[item].src.replace("-off", "");
		}
		else
		{
			//alert(sBar.images[item].src.substr(0, sBar.images[item].src.length - 4));
			var tmp = sBar.images[item].src.substr(0, sBar.images[item].src.length - 4) + "-off.gif";
			sBar.images[item].src = tmp;
		}
		if (item == sBar.imagesLength)
		{
			item = 0;
			if (sBar.track)
			{
				sBar.track = 0;
			}
			else
			{
				sBar.track = 1;
			}
		}
		else
		{
			item++;
		}
		
		setTimeout("sBar_scroll(" + item + ")", 100);
	}
}

// TabsCheckbox
function initTabsCheckbox()
{
	var _ids = ['graduate','experience','vacancies'];
	
	for(var _id in _ids)
	{
		var _cbx = document.getElementById(_ids[_id]);
		if(_cbx)
		{
			_cbx.onchange = function()
			{
				var _tab = document.getElementById(this.id + "-tab");
				if(_tab)
				{
					if(this.checked)
					{
						_tab.className = "active";
					}
					else
					{
						_tab.className = "";						
					}					
				}
			}
			_cbx.onclick = function()
			{
				var _tab = document.getElementById(this.id + "-tab");
				if(_tab)
				{
					if(this.checked)
					{
						_tab.className = "active";
					}
					else
					{
						_tab.className = "";						
					}					
				}
			}
		}
	}
}

var links = [];

function tabLinkClickFunction()
{
	if (this.isOpen)
	{
		removeClassFromElement(this, 'active')
		removeClassFromElement(this.tabButton, 'tab-buttonclose');
		addClassToElement(this.tabButton, 'tab-button');
		addClassToElement(this.tab, 'hidden');
		this.isOpen = false;		
	}
	else
	{
		addClassToElement(this, 'active')
		addClassToElement(this.tabButton, 'tab-buttonclose');
		removeClassFromElement(this.tabButton, 'tab-button');
		removeClassFromElement(this.tab, 'hidden');
		this.isOpen = true;
		
		// close other tabs
		var link = this.previousLink;
		while (link)
		{
			if (link.isOpen) link.onclick();
			link = link.previousLink;
		}
		
		link = this.nextLink;
		while (link)
		{
			if (link.isOpen) link.onclick();
			link = link.nextLink;
		}
		
		// move to the open tab.
		window.location.href = '#' + this.tabButton.id;
	}
	return false;
}

//var tabCookieId = "openTabs-" + window.location.href.replace(/.*?[^\/:]\//, '').replace(/\//g, '').replace(/\?.*/, '');
function initTab()
{		
	var tabHolder = document.getElementById("white-bg");
	if (!tabHolder) return; // no tabs to play with
	
	var openTab = window.location.href.indexOf("#") == -1 ? "" : window.location.href.substring(window.location.href.indexOf("#") + 1);	
	var links = tabHolder.getElementsByTagName("a");
	var length = links.length;
	var previousLink = null;
	var openTabId = null;
	for (var i=0; i < length; i++)
	{
		var link = links[i];
		var tabButton = link.parentNode.parentNode.parentNode;

		if ((link.className.indexOf('open') != -1 || link.className.indexOf('closed') != -1) && tabButton.className.indexOf("tab-button") != -1)
		{
			link.tab =  document.getElementById(link.href.substr(link.href.indexOf("#") + 1));
			if (link.tab)
			{
				link.isOpen = true;
				link.tabButton = tabButton;
				link.onclick = tabLinkClickFunction;
				
				// close tab if not specified as open.
				// It can be set as open either by giving the link the class 'active'
				// or by having the tabButton.id given in the url after the #
				if (tabButton.id == openTab)
				{
					// style the open tab
					addClassToElement(link, 'active')
					addClassToElement(tabButton, 'tab-buttonclose');
					if (!openTabId) openTabId = tabButton.id;				
				}
				else if (link.className.indexOf('active') != -1)
				{
					// add the matching style to the tabButton
					addClassToElement(tabButton, 'tab-buttonclose');
				}
				else link.onclick(); // close the tab
				
				// add reference to other links
				link.previousLink = previousLink;
				link.nextLink = null;
				if (previousLink) previousLink.nextLink = link;
				previousLink = link;
			}
		}
	}
	
	// if we have an open tab, move to it.
	if (openTabId)
	{
		window.location.href = '#' + openTabId;
	}
}

function oldInitTab()
{
	var _div = document.getElementById("white-bg");
	if(!_div) return;
	var _links = _div.getElementsByTagName("a");
	var j = 0;
	for (var i = 0; i < _links.length; i++)
	{
		_links[i]._parent = _links[i].parentNode.parentNode.parentNode;
		if (_links[i].className.indexOf('open') != -1 && _links[i]._parent.className.indexOf("tab-button") != -1)
		{

			links[j] = _links[i];
			links[j]._div = false;

			var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));
			if(c)
				links[j]._div = c;

			if(links[j].className.indexOf("active") != -1)
			{
				links[j]._div.style.display = "block";
			}
			else
			{
				links[j]._div.style.display = "none";				
			}

			links[j].onclick = function ()
			{
				if (this._div)
				{
					var _is_openned = false;
					if(this.className.indexOf("active") != -1)
					{
						_is_openned = true;
					}

					for (var i = 0; i < links.length; i++)
					{
						links[i]._div.style.display = "none";
						links[i].className = links[i].className.replace("active", "");
						links[i]._parent.className = "tab-button";
					}

					if(!_is_openned)
					{
						this.className += " active";
						this._parent.className = "tab-buttonclose";
						this._div.style.display = "block";
					}

				}
			}

			links[j]._href = links[j].href;
			links[j].href = 'javascript:;';
			
			j++;
			
		}
	}
}

if (window.addEventListener)
{
	window.addEventListener("load", initTabsCheckbox, false);
}
else if (window.attachEvent && !window.opera)
{
	window.attachEvent("onload", initTabsCheckbox);
}

function addScript(scriptURL, language)
{
	// Create the script tag
    var scriptObj = document.createElement("script");
    
    // Add script object attributes
    scriptObj.setAttribute("type", "text/javascript");
    if (language) scriptObj.setAttribute("language", language); 
    scriptObj.setAttribute("charset", "utf-8");
    if (scriptURL.indexOf("?") < 0) scriptObj.setAttribute("src", scriptURL);
    
    // Add the script
    document.getElementsByTagName("head").item(0).appendChild(scriptObj);
}