//set showSearch to true to show the search textbox and button
var showSearch = false;

//call this here so it will hide the search textbox and button before the pages begin to load, if necessary
ShowHideSearch();

///
// called to load the homepage components
///
function OnLoad()
{

	var callingPage = " " + window.location;

	SizeTopAndBottomBorder();
	if (callingPage.indexOf("default.htm") > -1 || 				//it's called from www.forscom.army.mil/band/default.htm or
		callingPage.lastIndexOf("/") == callingPage.length - 1)	//it's called www.forscom.army.mil/band/
	{
		OnCalendarBaseLoad();
		OnSlideshowLoad();
	}
	else if (callingPage.indexOf("Calendar.htm") > -1)
	{
//		setTimeout("OnLoadCalendarOfEvents()", 0);
		OnLoadCalendarOfEvents();
	}
	else if (callingPage.indexOf("LargeImage.htm") > -1)
	{
		OnLoadLargeImage();
	}
	else if (callingPage.indexOf("PhotoGalleryTemplate.htm") > -1)
	{
		//calling page will be the path to PhotoGalleryTemplate?gallery=<galleryname>
		LoadGallery(callingPage);
	}
	else if (callingPage.indexOf("PhotoGalleryScroller.htm") > -1)
	{
		var path = GetRootDirectory() + "PhotoGallery/PhotoGallery.js";
		LoadBandScript(path);
		OnSlideshowLoad();
	}
	else if (callingPage.indexOf("Search.htm") > -1)
	{
		OnSearchLoad(callingPage);
	}
}


///
// dynamically loads the script at runtime
///
function LoadBandScript(fullPath)
{
	try
	{
		var oXML = getXMLHttpObj();
		oXML.open('GET', fullPath, false);
		oXML.send('');
		eval(oXML.responseText);
	}
	catch (e)
	{ 
		DhtmlLoadScript(fullPath);
	}
}

///
// fires when any form to which the MainTemplate is attached resizes
///
function OnResize()
{
	SizeTopAndBottomBorder();
}

///
// have to do this so top and bottom borders size correctly
///
function SizeTopAndBottomBorder()
{
	if (GetElement("topBorderTable") && GetElement("contentTable"))
	{
		GetElement("topBorderTable").width = GetElement("contentTable").clientWidth;
	}
	if (GetElement("searchTable") && GetElement("contentTable"))
	{
		GetElement("searchTable").width = GetElement("contentTable").clientWidth;
	}	
	if (GetElement("bottomBorderTable") && GetElement("contentTable"))
	{
		GetElement("bottomBorderTable").width = GetElement("contentTable").clientWidth;
	}
	if (GetElement("leftBorderCell") && GetElement("contentTable"))
	{
		GetElement("leftBorderCell").height = GetElement("contentTable").clientHeight;
	}
	if (GetElement("rightBorderCell") && GetElement("contentTable"))
	{
		GetElement("rightBorderCell").height = GetElement("contentTable").clientHeight;
	}	
}

//<!---------------------------------------------------------------------!>
//<!----------------Load Stuff in Content Area---------------------------!>
//<!---------------------------------------------------------------------!>
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

///
// loads the specified url's content into the element with id equal to containerid
///
function LoadContentArea(url, containerid)
{
	var rootDir = GetRootDirectory();
	url = rootDir + url;
	
	var page_request = false;
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
	{	
		page_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{ // if IE
		try 
		{
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}
	else
	{
		return false;
	}
	
	
	page_request.onreadystatechange=function()
	{
		LoadPage(page_request, containerid);
	}
	
	if (bustcachevar) //if bust caching of external page
	{
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
	}
	page_request.open('GET', url+bustcacheparameter, true);
	page_request.send(null);
}

///
// loads the specified page_request
///
function LoadPage(page_request, containerid)
{
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	{	
		GetElement(containerid).innerHTML=page_request.responseText;
		GetElement(containerid).onresize();
	}
}

///
// determines from where call is coming and updates base directory 
///
function GetRootDirectory()
{
	var callingPage = " " + window.location;
	
	//strip off parameters
	var index = callingPage.indexOf("?");
	if (index > -1)
	{
		callingPage = callingPage.substr(0, index);
	}
	
	var parts = callingPage.split("/");
	var tmpDir = "./";
	var startCount = false;
	
	var siteName = "band";
	if (callingPage.indexOf("/newband") > -1)
	{
		siteName = "newband";
	}
	
	for(i = 0; i < parts.length; i++)
	{
		if (parts[i] == siteName)
		{
			startCount = true;
			tmpDir = "./";
		}	 
		
		if (startCount && parts[i] != "" && parts[i] != siteName && parts[i].indexOf(".htm") == -1)
		{
			tmpDir += "../";
		}
	}
	
	return tmpDir;
}

///
// gets the fully formatted path for the specified page
///
function GoToPage(page)
{
	location.href = GetRootDirectory() + page;
}

///
// creates the specified cookie
///
function CreateCookie(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=/";
}

///
// reads the specified
///
function ReadCookie(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;
}

///
// erases the cookie
///
function EraseCookie(name) 
{
	CreateCookie(name,"",-1);
}

///
// adds a leading zero to values less than 10 and returns new value
///
function AddLeadingZero(rawValue)
{
	var newValue;
	if (rawValue < 10)
	{
		newValue = "0" + rawValue;
	}
	else
	{
		newValue = rawValue;
	}
	return newValue;
}

///
// gets the month number for the given month
///
function GetMonth(monthName)
{
	var month = "undefined";
	if (monthName == "January")
	{
		month = "01";
	}
	else if (monthName == "February")
	{
		month = "02";
	}
	else if (monthName == "March")
	{
		month = "03";
	}
	else if (monthName == "April")
	{
		month = "04";
	}
	else if (monthName == "May")
	{
		month = "05";
	}
	else if (monthName == "June")
	{
		month = "06";
	}
	else if (monthName == "July")
	{
		month = "07";
	}
	else if (monthName == "August")
	{
		month = "08";
	}
	else if (monthName == "September")
	{
		month = "09";
	}
	else if (monthName == "October")
	{
		month = "10";
	}
	else if (monthName == "November")
	{
		month = "11";
	}
	else if (monthName == "December")
	{
		month = "12";
	}
	return month;
}

///
// gets the month name for the given month
///
function GetMonthName(monthNumeric)
{
	monthName = "undefined";
	switch (monthNumeric)
	{
		case 1:
			monthName = "January";
			break;
		case 2:
			monthName = "February";
			break;
		case 3:
			monthName = "March";
			break;
		case 4:
			monthName = "April";
			break;
		case 5:
			monthName = "May";
			break;
		case 6:
			monthName = "June";
			break;
		case 7:
			monthName = "July";
			break;
		case 8:
			monthName = "August";
			break;
		case 9:
			monthName = "September";
			break;
		case 10:
			monthName = "October";
			break;
		case 11:
			monthName = "November";
			break;
		case 12:
			monthName = "December";
			break;
	}
	return monthName;
}

// Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function  GetBrowser() 
{
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';	
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
	if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
	return navigator.userAgent.substr(0,agt.indexOf('\/'));}
	else return 'Netscape';} else if (agt.indexOf(' ') != -1)
	return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
}

///
// returns the indicated element
///
function GetElement(id)
{
	if (document.getElementById)
	{
		return document.getElementById(id);
	}	
	else if (document.all)
	{
		return document.all(id);
	}
    else if (document.layers) 
    {
      	return document.layers[element_id];
	}
	else
	{
		alert("unsupported browser");
	}
}

///
// returns the innerText value for the object, depending on browser
///
function GetInnerText(id)
{
	if (document.all)
	{
		return GetElement(id).innerText;
	}
	else
	{
		return GetElement(id).textContent;
	}
}

///
// sets the innerText value for the object, depending on browser
///
function SetInnerText(id, innerText)
{
	if (document.all)
	{
		GetElement(id).innerText = innerText;
	}
	else
	{
		GetElement(id).textContent = innerText;
	}
}
