var banners = ['spring_donation_button.gif', 
				'summer_donation_button.gif',
				'fall_donation_button.gif', 
				'holiday_donation_button.gif']


function startup()
{
	setGivingBanner();
	buildSubNavBar();
	
	var section = highlightSectionButton();
	highlightPageButton(section);


	if (document.URL.indexOf("/giftshop/printable.asp") != -1)
	{
		loadPrintProds();
	}	
	else if (document.URL.indexOf("/giftshop/") != -1)
	{
		loadprods();
		if (!navigator.cookieEnabled)
		{
			alert("Your browser is not allowing cookies.  Please set your browser to allow cookies or the shopping cart can not function properly."); 
		}
	}
}

var pageImageAlt = '';
function buildSubNavBar()
{
	var pageImage = document.getElementById('pageImage');
	if (pageImage != null)
	{
		pageImage.src = pageImageSrc;
		pageImage.alt = pageImageAlt;
	}
	var sectionHeader = document.getElementById('sectionHeader');
	if (sectionHeader != null)
		sectionHeader.src = sectionHeaderSrc;

	//Find Home add index page
	var sectionhome = document.getElementById('sectionhome');
	if (sectionhome != null && homeButton != null)
	{
		var anchor = document.createElement("A");
		anchor.className = 'navbutton';
		anchor.href = homeButton[0];
		anchor.innerHTML = homeButton[1];
		sectionhome.appendChild(anchor);
	}
	var subnavbar = document.getElementById('subnavbar');
	if (subnavbar != null)
	{
		//add remaining buttons
		if (buttons == null)
		{
			var subNavData = document.getElementById('subNavData').childNodes;
			for (var i=0; i < subNavData.length; i++)
			{
				var node = subNavData[i];
				if (node.nodeName == 'A')
				{
					var url = subNavData[i].href;
					var text = subNavData[i].innerHTML;
					subnavbar.appendChild(makeNavCell(url, text));
				}
			} 
		}
		else
		{
			for (var i=0; i < buttons.length; i++)
			{
				subnavbar.appendChild(makeNavCell(buttons[i][0],buttons[i][1]));
			}
		}
	}
	var textheader = document.getElementById('textheader');
	if (textheader != null)
		textheader.innerHTML = textHeaderText;

}

function makeNavCell(url, text)
{
	var cell = document.createElement('TD');
	cell.className = 'navbutton';
	cell.id = getPageName(url);
	cell.align = 'center';
	var anchor = document.createElement("A");
	anchor.className = 'navbutton';
	anchor.href = url;
	anchor.innerHTML = text;
	cell.appendChild(anchor);
	return cell;
}

function highlightSectionButton()
{
	var fileName = window.location.pathname;
	var start = fileName.lastIndexOf('/') + 1;
	var sectionName =  fileName.substring(1,start-1);
	var button = document.getElementById(sectionName);
	if (button == null)
	{
		var start = fileName.lastIndexOf('/') + 1;
		var end = fileName.lastIndexOf('.');
		var pageName = fileName.substring(start,end);
		button = document.getElementById(pageName);
	}
	if (button != null)
	{
		button.style.background = 'white';
		//document.getElementById('home').style.background = "#E2E0E1";
	}
	else
	{
		document.getElementById('home').style.background = 'white';
	}
	return sectionName;
}

function highlightPageButton(section)
{
	
	var fileName = window.location.pathname;
	var pageName = getPageName(fileName);
	if (pageName == 'index') pageName = section + '_home';
	var button = document.getElementById(pageName);
	
	if (button != null)
	{
		button.style.background = 'white';
		//if (pageName != section + 'home')
			//document.getElementById(section+'home').style.background = "#E2E0E1";
	}
	else
	{
		//document.getElementById(section+'home').style.background = 'white';
		var sectDiv = document.getElementById('sectionhome');
		if (sectDiv != null ) sectDiv.style.background = 'white';
	}

}

function getPageName(fileName)
{
	var start = fileName.lastIndexOf('/') + 1;
	var end = fileName.lastIndexOf('.');
	return fileName.substring(start,end);
}

function setGivingBanner()
{
	var month = (new Date()).getMonth();
	if (month < 5) month =0;
	else if (month < 8) month = 1;
	else if (month < 10) month = 2;
	else month = 3;
	
	var banner = document.getElementById("givingBanner");
	banner.src = '/images/banners/' + banners[month];
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function cookiecheck()
{
	cartcookie=getCookie('cookie_check');
	if (cartcookie == null || cartcookie !="yes")
	{
		setCookie('cookie_check','yes', 30);
		cartcookie=getCookie('cookie_check');
		if (cartcookie == null && cartcookie !="yes")
		{
			alert("Your browser is not allowing cookies.  Please set your browser to allow cookies or the shopping cart can not function properly."); 
		}
	}
}