function GetRuleNames()
{
	var styleSheet				= null;
	var Rules					= new Array();
	var styleCount				= 0;
	var stylesLength			= 0;
	for (var ssIndex = 0; ssIndex<document.styleSheets.length; ssIndex++)
	{
		styleSheet				= document.styleSheets[ssIndex];
		if(styleSheet.rules)
		{
			stylesLength		= styleSheet.rules.length;
		}
		else if(styleSheet.cssRules)
		{
			stylesLength		= styleSheet.cssRules.length;
		}
		for (var rIndex = 0; rIndex < stylesLength; rIndex++)
		{
			if(styleSheet.rules)
			{
				rule = styleSheet.rules[rIndex];
			}
			else if(styleSheet.cssRules)
			{
				rule = styleSheet.cssRules[rIndex];
			}
			Rules[styleCount]	= rule.selectorText;
			alert(rule.selectorText);
			styleCount++;
		}
	}
	return Rules;
}

function GetRule(ruleName)
{
	var styleSheet		= null;
	var Rules			= new Array();
	var styleCount		= 0;
	var stylesLength	= 0;
	for (var ssIndex=0; ssIndex<document.styleSheets.length; ssIndex++)
	{
		styleSheet		= document.styleSheets[ssIndex];
		if(styleSheet.rules)
		{
			stylesLength = styleSheet.rules.length;
		}
		else if(styleSheet.cssRules)
		{
			stylesLength = styleSheet.cssRules.length;
		}
		for (var rIndex = 0; rIndex<stylesLength; rIndex++)
		{
			if(styleSheet.rules)
			{
				rule	= styleSheet.rules[rIndex];
			}
			else if(styleSheet.cssRules)
			{
				rule	= styleSheet.cssRules[rIndex];
			}
			if ((rule.selectorText == "." + ruleName) ||
				(rule.selectorText == ruleName))
			{
				Rules[styleCount]	= rule;
				styleCount++;
			}								
		}
	}
	return Rules;
}

function ChangeFontSize(amt)
{
	var rule;
	if(GetRule(".mainPageStyle")[0])
	{
		rule = GetRule(".mainPageStyle")[0];
	}
	else if(GetRule(".mainPageStyle")[0])
	{
		rule = GetRule(".mainPageStyle")[0];
	}
	var fontSize = parseInt(rule.style.fontSize,10) + amt;
	if (fontSize < 9)
	{
		fontSize = 9;
		alert("Dave Rose says No!");
	}
	rule.style.fontSize = fontSize + "px";
	SortAds();
	return rule.style.fontSize;
}

function SetFontSize(amt)
{
	var rule;
	var rule2;
	var rule3;
	var rule4;
	var rule5;
	if(GetRule(".mainPageStyle")[0])
	{
		rule = GetRule(".mainPageStyle")[0];
	}
	else if(GetRule(".mainPageStyle")[0])
	{
		rule = GetRule(".mainPageStyle")[0];
	}

	if(GetRule("span.majorSection")[0])
	{
		rule2 = GetRule("span.majorSection")[0];
	}
	else if(GetRule("SPAN.majorSection")[0])
	{
		rule2 = GetRule("SPAN.majorSection")[0];
	}
	
	if(GetRule("span.mainSection")[0])
	{
		rule3 = GetRule("span.mainSection")[0];
	}
	else if(GetRule("SPAN.mainSection")[0])
	{
		rule3 = GetRule("SPAN.mainSection")[0];
	}
	
	if(GetRule("span.subSection")[0])
	{
		rule4 = GetRule("span.subSection")[0];
	}
	else if(GetRule("SPAN.subSection")[0])
	{
		rule4 = GetRule("SPAN.subSection")[0];
	}
	
	if(GetRule("span.figureDesc")[0])
	{
		rule5 = GetRule("span.figureDesc")[0];
	}
	else if(GetRule("SPAN.figureDesc")[0])
	{
		rule5 = GetRule("SPAN.figureDesc")[0];
	}
	
	if(GetRule("span.tableDesc")[0])
	{
		rule6 = GetRule("span.tableDesc")[0];
	}
	else if(GetRule("SPAN.tableDesc")[0])
	{
		rule6 = GetRule("SPAN.tableDesc")[0];
	}
	
	var fontSize = amt;
	if (fontSize < 1)
	{
		fontSize = 1;
	}
	rule.style.fontSize		= (fontSize)		+ "px";
	rule2.style.fontSize	= (fontSize)		+ "px";
	rule3.style.fontSize	= (fontSize - 2)	+ "px";
	rule4.style.fontSize	= (fontSize - 2)	+" px";
	rule5.style.fontSize	= (fontSize - 2)	+ "px";
	rule6.style.fontSize	= (fontSize - 2)	+ "px";
	return rule.style.fontSize;
}

function getAbsTop(el)
{
	var t = el.offsetTop;
	while((el = el.parentNode) && el != document)
	{
		t += el.offsetTop;
	}
	return t;
}

function getAbsLeft(el)
{
	var t = el.offsetLeft;
	while((el = el.parentNode) && el != document)
	{
		t += el.offsetLeft;
	}
	return t;
}

function getAbsHeight(el)
{
	var t = el.offsetHeight;
	return t;
}

var menu;
var ReadLater;
var maximizeButton;
var menuHidden			= 0;
var originalMenuHeight	= 0;
var menuTopBorder		= 10;
var theTop				= 120 + menuTopBorder;
var theLeft				= 0;
var old					= theTop;
var reallyOld			= 99;
var AddedWidth			= 860;
var menuWidth;
var theWidth;
var temp;
var pos;
var posH;

var section1height;
var section2height;
var section3height;
var section4height;
var section5height;
var section6height;
var section7height;
var section8height;
var section9height;
var section10height;
var section11height;
var section12height;
var section13height;
var section14height;
var section15height;

function returnPOS()
{
	if (window.innerHeight)
	{
		pos		= window.pageYOffset;
		posH	= window.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		pos		= document.documentElement.scrollTop;
		posH	= document.documentElement.scrollLeft;
	}
	else if (document.body)
	{
		pos		= document.body.scrollTop;
		posH	= document.body.scrollLeft;
	}
	if (pos < theTop)
	{
		pos		= theTop;
	}
	else
	{
		pos		+= menuTopBorder;
	}
	return pos;
}

window.onresize = init;

function init()
{
	menu			= new getObj('menu');
	maximizeButton	= new getObj('maximizeButton');
	ReadLater		= new getObj('readlaterstyle');

	if (window.innerWidth)
	{
		temp = window.innerWidth;
	}
	else if (document.documentElement.clientWidth)
	{
		temp = document.documentElement.clientWidth;
	}
	else
	{
		temp = document.body.clientWidth;
	}
	if (temp < 1065)
	{
		theLeft = 0;
	}
	else
	{
		theLeft = (temp - 1065) / 2;
	}

	movemenu();
}

function movemenu()
{
	pos = returnPOS();
	menuWidth = 220;
	if ((menu.obj != "NULL") && (maximizeButton.obj != "NULL"))
	{
		if (menuHidden == 0)
		{
			menu.style.left					= (theLeft - posH) + "px";
			maximizeButton.style.left		= "-1000px";
		}
		else
		{
			menu.style.left					= "-1000px";
			maximizeButton.style.left		= (theLeft - posH) + 7 + "px";
			menuWidth = 30;
		}
	}
	if (ReadLater.obj != "NULL")
	{
		ReadLater.style.left = (theLeft - posH) + AddedWidth + "px";
	}
	document.getElementById("contentTable").style.position	= "absolute";
	document.getElementById("contentTable").style.left		= theLeft + menuWidth + "px";
	document.getElementById("contentTable").style.width		= AddedWidth - menuWidth + "px";
	if (pos == old &&  reallyOld != pos)
	{
		if (menu.obj != "NULL")
		{
			if (typeof document.body.style.maxHeight == "undefined")
			{
				menu.style.top						= pos;
			}
			else
			{
				menu.obj.style.position				= "fixed";
				if(pos == theTop)
				{
					menu.style.top					= theTop;
				}
				else
				{
					menu.style.top					= menuTopBorder;
				}
			}
		}
		if (maximizeButton.obj != "NULL")
		{
			if (typeof document.body.style.maxHeight == "undefined")
			{
				maximizeButton.style.top			= pos;
			}
			else
			{
				maximizeButton.obj.style.position	= "fixed";
				if(pos == theTop)
				{
					maximizeButton.style.top		= theTop;
				}
				else
				{
					maximizeButton.style.top		= menuTopBorder;
				}
			}
		}
		if (ReadLater.obj != "NULL")
		{
			if (typeof document.body.style.maxHeight == "undefined")
			{
				ReadLater.style.top					= pos;
			}
			else
			{
				ReadLater.obj.style.position		= "fixed";
				if(pos == theTop)
				{
					ReadLater.style.top				= theTop;
				}
				else
				{
					ReadLater.style.top				= menuTopBorder;
				}
			}
		}
		var rule6;
		if(GetRule("div.Ads")[0])
		{
			rule6					= GetRule("div.Ads")[0];
		}
		else if(GetRule("DIV.Ads")[0])
		{
			rule6					= GetRule("DIV.Ads")[0];
		}
		rule6.style.left			= theLeft + AddedWidth + "px";

					// Menu Highlighting and collapsing
		if ((menuHidden == 0) && (menu.obj != "NULL"))
		{
			var count;

			var locations = new Array(15);
			for (count = 0; count < 15; count++)
			{
				locations[count]	= new getObj('section' + (count + 1) + 'location');
			}

			var menus = new Array(15);
			for (count = 0; count < 15; count++)
			{
				menus[count]		= new getObj('section' + (count + 1) + 'menu');
			}

			var menuparts = new Array(15);
			for (count = 0; count < 15; count++)
			{
				menuparts[count]	= new getObj('section' + (count + 1) + 'menuparts');
			}

			var heights = new Array(15);
			for (count = 0; count < 15; count++)
			{
				eval("heights[" + count + "] = section" + (count + 1) + "height");
			}

			var menu2				= new getObj('menu');
			var toplocation			= new getObj('toplocation');
			var topmenu				= new getObj('topmenu');

			var fontColorNormal		= '#ffffff';
			var fontColorHighlight	= '#424B73';
			var normalColor			= '#ae0031';
			var highlightColor		= '#000099';
			var highlightColorRGB	= 'rgb(0, 0, 153)';

			if(toplocation.obj != "NULL" && topmenu.obj != "NULL")
			{
				topmenu.style.backgroundColor				= normalColor;
				topmenu.style.color							= fontColorNormal;
				if (locations[0].obj != "NULL" &&
					menus[0].obj != "NULL")
				{
					if(pos + 130 >= getAbsTop(toplocation.obj) && pos + 130 <= getAbsTop(locations[0].obj))
					{
						if(topmenu.style.backgroundColor != highlightColor && topmenu.style.backgroundColor != highlightColorRGB)
						{
							topmenu.style.backgroundColor	= highlightColor;
							topmenu.style.color				= fontColorHighlight;
						}
					}
				}
				else if(pos + 130 >= getAbsTop(toplocation.obj))
				{
					if(topmenu.style.backgroundColor != highlightColor && topmenu.style.backgroundColor != highlightColorRGB)
					{
						topmenu.style.backgroundColor		= highlightColor;
						topmenu.style.color					= fontColorHighlight;
					}
				}
			}

			// MIDDLE MENU
			var count = 0;
			while(count < ((locations.length)-1))
			{
				if (locations[count].obj != "NULL" && menus[count].obj != "NULL")
				{
					menus[count].style.backgroundColor = normalColor;
					menus[count].style.fontColor = fontColorNormal;
					if (locations[count+1].obj != "NULL" && menus[count+1].obj != "NULL")
					{
						if (pos + 130 >= getAbsTop(locations[count].obj) &&
							pos + 130 <= getAbsTop(locations[count+1].obj))
						{
							if (menus[count].style.backgroundColor != highlightColor && menus[count].style.backgroundColor != highlightColorRGB)
							{
								menus[count].style.backgroundColor = highlightColor;
								menus[count].style.color = fontColorHighlight;
							}
							if (typeof document.body.style.maxHeight != "undefined")
							{
								if(heights[count] != "0")
								{
									menuparts[count].style.display = "block";
								}
							} 
						}
						else
						{
							if (typeof document.body.style.maxHeight != "undefined")
							{
								menuparts[count].style.display = "none";
							}
						}
					}
					else if (pos+130 >= getAbsTop(locations[count].obj))
					{
						if(menus[count].style.backgroundColor != highlightColor && menus[count].style.backgroundColor != highlightColorRGB)
						{
							menus[count].style.backgroundColor = highlightColor;
							menus[count].style.color = fontColorHighlight;
						}
						if (typeof document.body.style.maxHeight != "undefined")
						{
							if(heights[count] != "0")
							{
								menuparts[count].style.display = "block";
							}
						} 
					}
					else
					{
						if (typeof document.body.style.maxHeight != "undefined")
						{
							menuparts[count].style.display = "none";
						}
					}
				}
				count++;
			}
			// LAST SECTION
			if (locations[count].obj != "NULL" && menus[count].obj != "NULL")
			{
				menus[count].style.backgroundColor = normalColor;
				if (pos+130 >= getAbsTop(locations[count].obj))
				{
					if (menus[count].style.backgroundColor != highlightColor &&
						menus[count].style.backgroundColor != highlightColorRGB)
					{
						menus[count].style.backgroundColor = highlightColor;
					}
					if (typeof document.body.style.maxHeight != "undefined")
					{
						if(heights[count] != "0")
						{
							menuparts[count].style.display	= "block";
						}
					}
				}
				else
				{
					if (typeof document.body.style.maxHeight != "undefined")
					{
						menuparts[count].style.display		= "none";
					}
				}
			}
		}
	}

	reallyOld	= old;
	old			= pos;
	if (typeof document.body.style.maxHeight == "undefined")
	{
		temp	= setTimeout('movemenu()',250);
	}
	else
	{
		temp	= setTimeout('movemenu()',20);
	}
}

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		if(this.obj)
		{
			this.style = document.getElementById(name).style;
		}
		else
		{
			this.obj = "NULL";
		}
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		if(this.obj)
		{
			this.style = document.all[name].style;
		}
		else
		{
			this.obj = "NULL";
		}
	}
	else if (document.layers)
	{
		this.obj = getObjNN4(document,name);
		if(this.obj)
		{
			this.style = this.obj;
		}
		else
		{
			this.obj = "NULL";
		}
	}
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		{
			foundLayer = x[i];
		}
		else if (x[i].layers.length)
		{
			var tmp = getObjNN4(x[i],name);
		}
		if (tmp)
		{
			foundLayer = tmp;
		}
	}
	return foundLayer;
}

function toggleVisibility(me,vis)
{
	image = document.getElementById(me);
	if (vis == 1)
	{
		image.style.visibility = "visible";
	}
	else 
	{
		image.style.visibility = "hidden";
	}
}

function showKeywordPopup(keywordId)
{
	clearTimeout(timeout);
	image = document.getElementById(keywordId);
	image.style.visibility = "visible";
	if(tempX != 0)
	{
		image.style.left = tempX;
	}
	if(tempY != 0)
	{
		image.style.top = tempY;
	}
}

var timeout;
var maximized = 1;
function startTimeout(keywordId)
{
	timeout = setTimeout('hideKeywordPopup(' + keywordId + ')', 1000);
}

function hideKeywordPopup(keywordId)
{
	image = document.getElementById(keywordId);
	image.style.visibility = "hidden";
}

function minimizeMenu()
{
	if (menuHidden == 0)
	{
		menuHidden = 1;
	}
	else
	{
		menuHidden = 0;
	}

	temp = setTimeout('movemenu()',200);
}

function maximizeMenu()
{
	minimizeMenu();
}


function grayOut(vis, options) 
{  
	// Pass true to gray out screen, false to ungray  
	// options are optional.  This is a JSON object with the following (optional) properties  
	// opacity:0-100         
	// Lower number = less grayout higher = more of a blackout   
	// zindex: #             
	// HTML elements with a higher zindex appear on top of the gray out  
	// bgcolor: (#xxxxxx)    
	// Standard RGB Hex color code  
	// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});  
	// Because options is JSON opacity/zindex/bgcolor are all optional and can appear  
	// in any order.  Pass only the properties you need to set.  
	//alert('trying');
	var options = options || {};   
	var zindex = options.zindex || 50;  
	var opacity = options.opacity || 70;  
	var opaque = (opacity / 100);  
	var bgcolor = options.bgcolor || '#000000';  
	var dark=document.getElementById('darkenScreenObject');  
	if (!dark) 
	{    
		// The dark layer doesn't exist, it's never been created.  So we'll    
		// create it here and apply some basic styles.    
		// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917    
		var tbody = document.getElementsByTagName("body")[0];    
		var tnode = document.createElement('div');           
		// Create the layer.        
		tnode.style.position='absolute';                 
		// Position absolutely        
		tnode.style.top='0px';                           
		// In the top        
		tnode.style.left='0px';                          
		// Left corner of the page        
		tnode.style.overflow='hidden';                   
		// Try to avoid making scroll bars                    
		tnode.style.display='none';                      
		// Start out Hidden        
		tnode.id='darkenScreenObject';                   
		// Name it so we can find it later    
		tbody.appendChild(tnode);                            
		// Add it to the web page    
		dark=document.getElementById('darkenScreenObject');  
		// Get the object.  
	}
	if (vis) 
	{    
		// Calculate the page width and height     
		if((document.body) &&
			(document.body.scrollWidth || document.body.scrollHeight)) 
		{        
			var pageWidth = document.body.scrollWidth + 'px';        
			var pageHeight = document.body.scrollHeight + 'px';    
		} 
		else if( document.body.offsetWidth ) 
		{      
			var pageWidth = document.body.offsetWidth + 'px';      
			var pageHeight = document.body.offsetHeight + 'px';    
		} 
		else 
		{       
			var pageWidth = '100%';       
			var pageHeight = '100%';    
		}       
		// set the shader to cover the entire page and make it visible.    
		dark.style.opacity = opaque;                          
		dark.style.MozOpacity = opaque;                       
		dark.style.filter = 'alpha(opacity=' + opacity + ')';     
		dark.style.zIndex = zindex;            
		dark.style.backgroundColor = bgcolor;      
		dark.style.width = pageWidth;    
		dark.style.height = pageHeight;    
		dark.style.display = 'block';                           
	} 
	else 
	{     
		dark.style.display = 'none';
	}
}

function addLoadEvent(func) 
{
  	var oldonload = window.onload;
  	if (typeof window.onload != 'function') 
  	{
    	window.onload = func;
  	} 
  	else 
  	{
    	window.onload = function() 
    	{
      		if (oldonload) 
      		{
        		oldonload();
      		}
      		func();
    	}
  	}
}

function moveReadLater()
{
//	pos = returnPOS();
}

var warned = 0;
function submitToReadLater(urlVar,urlOther,verified)
{
	document.getElementById('ReadLater').src = urlVar;
	if(verified != '1' && warned == 0)
	{
		warned = 1;
		lightbox.prototype.popupDialog(urlOther);
	}
}

var currentUsersScrollTo = 0;
function saveLocation(urlOther,verified)
{
	var currentScroll = getScroll();
	document.getElementById('ReadLater').src = 'readlater.php?ScrollLocation=' + currentScroll + '&PubId=' + currentPublicationId;
	currentUsersScrollTo = getScroll();
	if(verified != '1' && warned == 0)
	{
		warned = 1;
		lightbox.prototype.popupDialog(urlOther);
	}
}

function gotoMySpot()
{
	window.scrollTo(0, currentUsersScrollTo);
}

function getScroll()
{
	if (self.pageYOffset) 
	{
		this.yPos = self.pageYOffset;
	} 
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		this.yPos = document.documentElement.scrollTop; 
	} 
	else if (document.body) 
	{
		this.yPos = document.body.scrollTop;
	}
	if(this.yPos == 0)
	{
		return 1;
	}
	else
	{
		return this.yPos;
	}
}
	
function setScroll(x, y)
{
	window.scrollTo(x, y); 
}

function createXMLHttp()
{
	if (typeof XMLHttpRequest != 'undefined')
	{
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp",
		"MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0",
		"MSXML2.XmlHttp.5.0"];
		for (var i = avers.length -1; i >= 0; i--) 
		{
			try 
			{
				httpObj = new ActiveXObject(avers[i]);
				return httpObj;
			} 
			catch(e) 
			{
			}
		}
	}
	throw new Error('XMLHttp (AJAX) not supported');
}

var ajaxObj = createXMLHttp(); 

function doSomething(url)
{
	ajaxObj.open("GET", url, true); 
	ajaxObj.onreadystatechange = function() {ajaxObj.processRequest();} 
	ajaxObj.send(null);
}

ajaxObj.processRequest = function() 
{
	if (this.readyState == 4) 
	{
		// got response reload the page
		window.location.reload();
	}
}
