//------ SK - glossary links enabling/disabling --------------------------------
function swapAttributes(el, old_attr, new_attr)
{
	old_value = el.getAttribute(old_attr);
	el.removeAttribute(old_attr);
	el.setAttribute(new_attr, old_value);
}

function swapAttributes2(el, old_attr, new_attr, b)
{
	old_value = el.getAttribute(old_attr);
	if (b) {
		el.setAttribute(old_attr, "");
	}
	else {
		el.removeAttribute(old_attr);
	}
	el.setAttribute(new_attr, old_value);
}

function toggleglossarylinks_(cookie_value)
{
	var toggle_element = document.getElementById("toggle-glossary-link");
	var glossary_links = document.getElementsByName("gloss-reflink");
	
	if (cookie_value == null || cookie_value == "enabled") {
		
		toggle_element.firstChild.data = "Disable Glossary Links";

		for (i = 0; i < glossary_links.length; ++i) {
			var el = glossary_links[i];
			swapAttributes(el, "href_", "href");
			swapAttributes2(el, "onclick_", "onclick", false);
		}
	}
	else {
		
		toggle_element.firstChild.data = "Enable Glossary Links";

		for (i = 0; i < glossary_links.length; ++i) {
			var el = glossary_links[i];
			swapAttributes(el, "href", "href_");
			swapAttributes2(el, "onclick", "onclick_", true);
		}
	}
}

function toggleglossarylinks()
{
	var toggle_element = document.getElementById("toggle-glossary-link");

	if (toggle_element.firstChild.data.match("Enable"))
		pmcCreateCookie("GlossaryLinks", "enabled", 7);
	else 
		pmcCreateCookie("GlossaryLinks", "disabled", 7);
	
	toggleglossarylinks_(pmcReadCookie("GlossaryLinks"));
}

//------------------------------------------------------------------------------
function adjustGlossaryLinks()
{
	if (document.getElementById("toggle-glossary-link")) {
		cookie_value = pmcReadCookie("GlossaryLinks");

		if (cookie_value == null)
			pmcCreateCookie("GlossaryLinks", "enabled", 7);
		else if (cookie_value == "disabled")
			toggleglossarylinks_(cookie_value);
	}
}

//------ AK - cookie support ---------------------------------------------------
function pmcCreateCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";

	document.cookie = name+"="+value+expires+"; path=/";
}

function pmcReadCookie(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 pmcEraseCookie(name)
{
	pmcCreateCookie(name,"",-1);
}

//------------------------------------------------------------------------------
//----- work around MSIE bug with location.hash --------------------------------
//------------------------------------------------------------------------------
	var count = 0;	
	var max_count = 1000;
	var delay = 10;

function getInternetExplorerVersion() 
{
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(navigator.userAgent) != null)
			return parseFloat(RegExp.$1);
	}

	return -1;
}
	var count = 0;	
	var max_count = 1000;
	var delay = 10;
//------------------------------------------------------------------------------
function restoreHash()
{
//alert(window.location.hash);
//alert(window.document.URL);

	if (window.location.hash == "undefined" || window.location.hash.length == 0) {
		var ver = getInternetExplorerVersion();
		if (ver >= 6.0) {
			setTimeout("restoreHashHandler();", delay);
		}
	}
}


//------------------------------------------------------------------------------
function restoreHashHandler()
{	
	if (window.location.hash == "undefined" || window.location.hash.length == 0) {
		var v = window.document.URL.split("#", 2);	
		if (v.length > 1) 
			document.location.hash = v[1];	
		else if (++count < max_count)				
			setTimeout("restoreHashHandler();", delay);
	}
}

//------------------------------------------------------------------------------

