// Common site scripts for 006  //
// Created as part of Travel 2 migration//
// Webmaster Services 9/24/2008 //
// Scripts originally found in Navigation Bar, disclaimer and Cusotom Menus in Content Manager //

/*FORMATTING SCRIPTS ADDED BY WEBMASTERSERVICES ON 5/20/2008*/
function adjustStyle(styleName, newStyle) 
{
	if (document.styleSheets[0].addRule) 
	{
		// IE way
		document.styleSheets[0].addRule(styleName, newStyle);
	} else if (document.styleSheets[0].insertRule) 
	{
		// Mozilla/Standard way
		var x = document.styleSheets[0];
		x.insertRule(styleName + " {" + newStyle + "}", x.cssRules.length);
	}
}
function doStyleAdjust(bShow)
{
	if(document.all)
	{
		if(bShow == undefined) bShow = true;
		var displaystyle = bShow ? "display:inline;" : "display:none;"; 
		adjustStyle('.servicesconfig', displaystyle );
		adjustStyle('.leftconfig', displaystyle);
	}
}

//doStyleAdjust(false);
//window.setTimeout(doStyleAdjust, 500);

////NON-NAVIGATION RELATED SCRIPTS TO BE INCLUDED ON EACH PAGE OF SITE
//returns the first table node it encounters backwards in the DOM from the element passed
function getParentTag(el, tagname)
{
	if(!tagname) tagname = "TABLE";
	
	var parent = el.parentNode;
	while(parent)
	{
		if(parent.tagName == tagname) return parent;
		parent = parent.parentNode;
	}
	return null;
}

function getTagByClassName(classname, tagname)
{
	if(tagname == undefined) tagname = "TD";
	var tags = document.getElementsByTagName(tagname);
	for(var i=0;i<tags.length;i++)
	{
		if(tags[i].className.toLowerCase() == classname.toLowerCase())

		{
			return tags[i];
		}	
	}
	return null;

}

//special formatting for the center aligned design, 
//adjusts for the different national office page design styles

//global table size vars
var widthfullpage = 988; 
var widthcenter = 770; 

function setTableAlignments()
{
	//set width / alignment of content table
	var td, parentEl;
	var bSizeFooter = false;

	try
	{
		td = getTagByClassName("servicesconfig");
		td.style.backgroundColor = "#FFFFFF";
		parentEl = getParentTag(td);
		parentEl.width = widthfullpage;
		parentEl.align = "center";
		parentEl.style.borderLeft = "1px solid #000000";
		parentEl.style.borderRight = "1px solid #000000";
		td.vAlign = "top";
	}
	catch(e){}
	
	try
	{
		td = getTagByClassName("leftconfig");
		td.style.backgroundColor = "#FFFFFF";
	}
	catch(e){}
	
	if(document.all)
	{
		try
		{
			var evilBrTag = footertable.previousSibling;
			var evilBrTag2 = fonttag.childNodes[1];
			if(evilBrTag.tagName == "BR") evilBrTag.style.display = "none";
			try{if(evilBrTag2.tagName == "BR") evilBrTag2.style.display = "none";} catch(e) {}
		}
		catch(e){}
	}
	
	//show center section, previously hidden in IE
	doStyleAdjust(true);
}

//travel 2 override functions for positioning lrp div
function showLrp() 
{
	var bodyContainer = window.document.body;
	showAjaxSpinner(bodyContainer, 'lrpOverlay', 'lrp');
	document.getElementById("lrp").style.top = "275px";
	document.getElementById("lrp").style.left = "275px";
	document.getElementById("lrpOverlay").style.height = screen.height + "px";
	show('lrp');
}
//006 Test for T2 page
function isT2Page()
{
	return document.getElementById("document") != null;	
}
//006 Remove border from "outer" div and set properties for "login" div
//these settings can't be adjusted in the T2 stylesheet because they are 
//written in the club stylesheet and get overwritten in T2
var trys = 0;
function adjustT2Styles()
{
	if(isT2Page())
	{
		try 
		{
			document.getElementById("outer").style.border = "none"; 

			document.getElementById("login").style.width = "990px";
			document.getElementById("login").style.borderBottom = "1px solid black";

			document.getElementById("footer").style.width = "990px";
			document.getElementById("footer").style.padding = "0px";
			//adjust the header sections
			//commenting out this code as the club should adjust these styles in their stylesheet
			//var heading = getTagByClassName("heading1", "h1");
			//var parent = getParentTag(heading, "DIV");
			//parent.style.height = "auto";
			//document.getElementById("header").style.height = "auto";
		}	
		catch(e)
		{
			if(trys < 50)
			{
				window.setTimeout(adjustT2Styles, 250);
				trys++;
			}
		}
	}
}

window.setTimeout(adjustT2Styles, 250);
