// ccbn.js - This file should be included in most (if not all) of the CCBN gapinc.com redesign pages

// Initialize the level IDs
var level2ID = '0';
var level3ID = '0';
var level4ID = '0';
var level5ID = '0';

// Level 2 labels and URLs - These placeholder objects get loaded in the buildLeftNav() method
var level2Labels = new Array();
var level2URLs = new Array();

// Level 3 labels and URLs - These placeholder objects get loaded in the setLevel3LabelsAndURLs() method
var level3Labels = new Array();
var level3URLs = new Array();

// Level 4 labels and URLs - These placeholder objects get loaded in the setLevel4LabelsAndURLs() method
var level4Labels = new Array();
var level4URLs = new Array();

// Initialize the ubiquitous search variables
var isNS4 = (navigator.appName=="Netscape")?1:0;

var gqSearchFormUrl = "http://www.gapinc.com/wps/portal/gapinc/search";
var gqSearchFormVar;

// Build the bottom navigation
function buildBottomNav()
{
	document.writeln("<div class='navFooter'>");
	document.writeln("<a href=javascript:void(openPopupWindow('http://www.gapinc.com/public/includes/Shop_at_GapInc_Brands.shtml'))>Shop at Gap Inc. Brands</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='http://www.gapinc.com/public/About/abt_contact.shtml' target='_top'>Contact Us</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=javascript:void(openPopupWindow('http://www.gapinc.com/public/includes/Terms_of_Use.shtml'))>Terms of Use</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=javascript:void(openPopupWindow('http://www.gapinc.com//public/includes/Privacy_Policy.shtml'))>Privacy Policy</a>&nbsp;&nbsp;|&nbsp;&nbsp;&copy; 2010 Gap Inc.");
	document.writeln("</div>");
}

// Build the left navigation
function buildLeftNav(lev2ID,lev3ID,lev4ID,lev5ID)
{
	if (document.getElementById != null)
	{
		// Set the level 2 through 5 IDs if they are specified
		if (lev2ID != null) level2ID = lev2ID;
		if (lev3ID != null) level3ID = lev3ID;
		if (lev4ID != null) level4ID = lev4ID;
		if (lev5ID != null) level5ID = lev5ID;

		if (level2ID > '0')
		{
			// Set the level 2, 3 and 4 labels and URLs
			level2Labels = new Array('Financials','Real Estate','Stock Information','Governance','Corporate Compliance','Investor Contacts','FAQ');
			level2URLs = new Array('http://www.gapinc.com/public/Investors/inv_financials.shtml','http://www.gapinc.com/public/Investors/inv_re.shtml','http://www.gapinc.com/public/Investors/inv_stocks.htm','http://www.gapinc.com/public/Investors/inv_govern.shtml','http://www.gapinc.com/public/Investors/inv_compliance.shtml','http://www.gapinc.com/public/Investors/inv_contacts.shtml','http://www.gapinc.com/public/Investors/inv_faq.shtml');

			setLevel3LabelsAndURLs();
			setLevel4LabelsAndURLs();

			document.writeln("<table width='100%' border='0' cellspacing='0' cellpadding='0' class='navSide'>");

			// Build the level 2 left navigation items
			for (id2 = 0; id2 < level2Labels.length; id2++)
				buildLevel2Nav(id2);

			// Add 30 pixels of padding at the bottom of the left navigation
			document.writeln("<tr><td><img src='http://www.gapinc.com/public/images/technical_graphics/clear.gif' alt='' width='1' height='30' title=''/></td></tr>");
			document.writeln("</table>");
		}
	}
	else
	{
		alert("Sorry, the build left navigation feature works\nonly in javascript enabled browsers.");
	}
}

// Build the level 2 left navigation
function buildLevel2Nav(id2)
{
	// Need to add 1 to the ID and multiply it by 10 to match the IDs for the navigation items
	var currLev2ID = (id2 + 1) * 10;

	if (level2ID == currLev2ID)
	{
		if (level3Labels.length > '0')
			document.writeln("<tr class='nav1'><td class='opener'><div class='selected'><img src='http://www.gapinc.com/public/images/navigation_graphics/nav1Arrow.gif' alt='' border='0'/>" + buildNavItemText(level2Labels[id2],level2URLs[id2],'true',level3ID));
		else
			document.writeln("<tr class='nav1'><td><div class='selected'>" + buildNavItemText(level2Labels[id2],level2URLs[id2],'true',level3ID));

		document.writeln("</div></td></tr>");

		// Build the level 3 left navigation items
		for (id3 = 0; id3 < level3Labels.length; id3++)
			buildLevel3Nav(id3);
	}
	else
	{
		document.writeln("<tr class='nav1'><td><div>" + buildNavItemText(level2Labels[id2],level2URLs[id2],'false',level3ID));
		document.writeln("</div></td></tr>");
	}
}

// Build the level 3 left navigation
function buildLevel3Nav(id3)
{
	// Need to add 1 to the ID and multiply it by 10 to match the IDs for the navigation items
	var currLev3ID = (id3 + 1) * 10;

	if (level3ID == currLev3ID)
	{
		if (level4Labels.length > '0')
			document.writeln("<tr class='nav2'><td class='opener'><div class='selected'><img src='http://www.gapinc.com/public/images/navigation_graphics/nav2Arrow.gif' alt='' border='0'/>" + buildNavItemText(level3Labels[id3],level3URLs[id3],'true',level4ID));
		else
			document.writeln("<tr class='nav2'><td><div class='selected'>" + buildNavItemText(level3Labels[id3],level3URLs[id3],'true',level4ID));

		document.writeln("</div></td></tr>");

		// Build the level 4 left navigation items
		for (id4 = 0; id4 < level4Labels.length; id4++)
			buildLevel4Nav(id4);
	}
	else
	{
		document.writeln("<tr class='nav2'><td><div>" + buildNavItemText(level3Labels[id3],level3URLs[id3],'false',level4ID));
		document.writeln("</div></td></tr>");
	}
}

// Build the level 4 left navigation
function buildLevel4Nav(id4)
{
	// Need to add 1 to the ID and multiply it by 10 to match the IDs for the navigation items
	var currLev4ID = (id4 + 1) * 10;

	if (level4ID == currLev4ID)
		document.writeln("<tr class='nav3'><td><div class='selected'><img src='http://www.gapinc.com/public/images/navigation_graphics/nav3BulletOn.gif' alt='' border='0'/>" + buildNavItemText(level4Labels[id4],level4URLs[id4],'true',level5ID));
	else
		document.writeln("<tr class='nav3'><td><div><img src='http://www.gapinc.com/public/images/navigation_graphics/nav3BulletOn.gif' alt='' border='0'/>" + buildNavItemText(level4Labels[id4],level4URLs[id4],'false',level5ID));

	document.writeln("</div></td></tr>");
}

// Build the text for a left navigation item
function buildNavItemText(itemText,itemURL,selected,subLevelID)
{
	var html = '';

	if (selected =='true' && subLevelID == '0')
	{
		// Don't hyperlink the item if it's selected and the sub level's item ID is "0"
		html += itemText;
	}
	else
	{
		// Hyperlink the item if it's not selected or the sub level's item ID is not "0"
		html += '<a href="' + itemURL + '" target="_top">' + itemText + '</a>';
	}

	return html
}

// Build the sub banner (contains the sliver images and the printer friendly functionality)
function buildSubBanner()
{
	document.writeln("<table width='740' class='subBanner' cellspacing='0' cellpadding='0' border='0'><tr>");

	// Write the HTML for the sliver images
	document.writeln("<td width='210' nowrap='nowrap'><img src='http://www.gapinc.com/public/images/5_Investors/5_sliver_fall.gif'/></td>");
	document.writeln("<td width='532' nowrap='nowrap'><img class='hdrImg' src='http://www.gapinc.com/public/images/5_Investors/5_img1_sliver.jpg'/><img class='hdrImg' src='http://www.gapinc.com/public/images/5_Investors/5_img2_sliver.jpg'/></td>");
	document.writeln("</tr><tr>");
	document.writeln("<td><img src='http://www.gapinc.com/public/images/technical_graphics/clear.gif' alt='' width='1' height='23' title=''></td>");

	// Write the HTML for the printer friendly functionality
	document.writeln("<td class='link'><a href='javascript:void(printFriendly())'><img src='http://www.gapinc.com/public/images/icons/iconPrinterFriendly.gif' alt='Printer-friendly version' border='0'/>Printer-friendly version</a></td>");
	document.writeln("</tr></table>");
}

// Build the top navigation
function buildTopNav()
{
	document.writeln("<table width='758' class='navTop' cellspacing='0' cellpadding='0' border='0'>");
	document.writeln("<tr><td rowspan='2'><a href='http://www.gapinc.com/public/index.shtml' target='_top'><img border='0' alt='Gap Inc.' src='http://www.gapinc.com/public/images/00_x_global/x_nav_gapinc_fall.gif'/></a></td>");

	// Write the HTML for the global search functionality
	document.writeln("<td><form name='gqStaticSearchForm' action='' method='get' target='_top'>");
	document.writeln("<table width='548' border='0' cellspacing='0' cellpadding='0' class='globalSearch'><tr>");
	document.writeln("<td width='399'><img src='http://www.gapinc.com/public/images/technical_graphics/clear.gif' alt='' width='1' height='32' title=''/></td>");
	document.writeln("<td width='110'><input type='text' name='query' value='Search' class='txtSearch' onfocus='gqSetQueryFocus();' onKeypress='if(!isNS4){if ((event.keyCode > 32 && event.keyCode < 34) || (event.keyCode > 34 && event.keyCode < 39) || (event.keyCode > 39 && event.keyCode < 43) || (event.keyCode > 46 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 61) || (event.keyCode > 61 && event.keyCode < 63) || (event.keyCode > 90 && event.keyCode < 95) || (event.keyCode > 122 && event.keyCode < 124) || (event.keyCode > 124 && event.keyCode < 126)) event.returnValue = false;}else{if ((event.which > 32 && event.which < 34) || (event.which > 34 && event.which < 39) || (event.which > 39 && event.which < 43) || (event.which > 46 && event.which < 48) || (event.which > 57 && event.which < 61) || (event.which > 61 && event.which < 63) || (event.which > 90 && event.which < 95) || (event.which > 122 && event.which < 124) || (event.which > 124 && event.which < 126)) return false;}'/></td>");
	document.writeln("<td width='40'><input name='imageField' type='image' src='http://www.gapinc.com/public/images/buttons/btnGoTan.gif' class='border'/></td>");
	document.writeln("</tr></table></form>");
	document.writeln("<script language='javascript' type='text/javascript'>gqSetSearchForm(document.gqStaticSearchForm);</script>");
	document.writeln("</td></tr>");

	// Write the HTML for the top navigation
	document.writeln("<tr><td width='548' height='24'>");
	document.writeln("<table width='548' cellspacing='0' cellpadding='0' border='0'><tr>");
	document.writeln("<td><a href='http://www.gapinc.com/public/About/about.shtml' target='_top'><img border='0' src='http://www.gapinc.com/public/images/00_x_global/x_nav_about_fall_off.gif' alt='About Gap Inc.'/></a></td>");
	document.writeln("<td><img src='http://www.gapinc.com/public/images/00_x_global/x_nav_div_off_fall.gif'/></td>");
	document.writeln("<td><a href='http://www.gapinc.com/public/OurBrands/brands.shtml' target='_top'><img border='0' src='http://www.gapinc.com/public/images/00_x_global/x_nav_brands_fall_off.gif' alt='Our Brands'/></a></td>");
	document.writeln("<td><img src='http://www.gapinc.com/public/images/00_x_global/x_nav_div_off_fall.gif'/></td>");
	document.writeln("<td><a href='http://www.gapinc.com/public/Careers/careers.shtml' target='_top'><img border='0' src='http://www.gapinc.com/public/images/00_x_global/x_nav_careers_fall_off.gif' alt='Careers'/></a></td>");
	document.writeln("<td><img src='http://www.gapinc.com/public/images/00_x_global/x_nav_div_off_fall.gif'/></td>");
	document.writeln("<td><a href='http://www.gapinc.com/public/SocialResponsibility/socialres.shtml' target='_top'><img border='0' src='http://www.gapinc.com/public/images/00_x_global/x_nav_sr_fall_off.gif' alt='Social Responsibility'/></a></td>");
	document.writeln("<td><img src='http://www.gapinc.com/public/images/00_x_global/x_nav_div_on_all.gif'/></td>");
	document.writeln("<td><a href='http://www.gapinc.com/public/Investors/investors.shtml' target='_top'><img border='0' src='http://www.gapinc.com/public/images/00_x_global/x_nav_invest_fall_on.gif' alt='Investors'/></a></td>");
	document.writeln("<td><img src='http://www.gapinc.com/public/images/00_x_global/x_nav_div_on_all.gif'/></td>");
	document.writeln("<td><a href='http://www.gapinc.com/wps/portal/gapinc/media' target='_top'><img border='0' src='http://www.gapinc.com/public/images/00_x_global/x_nav_media_fall_off.gif' alt='Media'/></a></td>");
	document.writeln("</tr></table></td></tr></table>");
}

// Start ubiquitous search functions
function gqSetSearchForm(searchForm)
{
	gqSearchFormVar = searchForm;
	gqSearchFormVar.action = gqSearchFormUrl;
}

function gqSetQueryInit(qryParmValue)
{
	if (qryParmValue == '')
		qryParmValue = 'Search';

	gqSearchFormVar.query.value = qryParmValue;
}

function gqSetQueryFocus()
{
	if (gqSearchFormVar.query.value == 'Search')
		gqSearchFormVar.query.value = '';
}

function gqSubmit()
{
	// Massage the query data
	//alert("gqSearchForm.action is " + gqSearchFormVar.action);
	gqSearchFormVar.submit();
	return false;
}
// End ubiquitous search functions

// Open a popup window
function openPopupWindow(url)
{
	window.open(url,"popupWindow","width=620,height=500,directories=no,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
}

// Build the printer friendly popup window
function printFriendly()
{
	if (document.getElementById != null)
	{
		var html = '<html class="printerFriendly">\n<head>\n';
		var headTags = document.getElementsByTagName("head");
		html += headTags[0].innerHTML;
		html += '\n</head>\n<body><table class="border" cellspacing="0" cellpadding="0" width="100%" align="center" border="0"><tr><td class="closeWindow" width="500"><img height="34" alt="Gap Inc." src="http://www.gapinc.com/public/images/00_x_global/x_printerbar_fall.gif" width="500"/></td><td class="closeWindow" width="110"><a href="javascript:window.close()">close window</a></td></tr></table>';
		html += '<br/><table cellspacing="0" cellpadding="0" align="center" width="500"><tr><td>';

		var printPageElem = (document.getElementById("pf1").innerHTML) + (document.getElementById("pf2").innerHTML) + (document.getElementById("pf3").innerHTML) + (document.getElementById("pf4").innerHTML) + (document.getElementById("pf5").innerHTML);
		html += printPageElem;
		html += '</td></tr></table>';
		html += '</body>\n</html>';

		var printWin = window.open("GapInc.","pf1","height=450,width=630,directories=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=yes");
		printWin.document.open();
		printWin.document.write(html);
	}
	else
	{
		alert("Sorry, the printer friendly feature works\nonly in javascript enabled browsers.");
	}
}

// Set the level 3 labels and URLs for the appropriate level 2 item
function setLevel3LabelsAndURLs()
{
	switch(level2ID)
	{
		case '10':
			level3Labels = new Array('Annual Reports & Proxy','SEC Filings','Conference Calls & Webcasts','Reporting Calendar')
			level3URLs = new Array('http://www.gapinc.com/public/Investors/inv_fin_annual_reports_and_proxy.htm','http://www.gapinc.com/public/Investors/inv_fin_sec_filings.htm','http://www.gapinc.com/public/Investors/inv_fin_conf_calls_and_webcast.htm','http://www.gapinc.com/public/Investors/inv_fin_reportingcalendar.shtml')
			break
		case '30':
			level3Labels = new Array('Stock Chart','Stock Split History','Historical Price Lookup','Investment Calculator','Transfer Agent','Analyst Coverage')
			level3URLs = new Array('http://www.gapinc.com/public/Investors/inv_stock_chart.htm','http://www.gapinc.com/public/Investors/inv_stock_split_history.htm','http://www.gapinc.com/public/Investors/inv_stock_historical_price_lookup.htm','http://www.gapinc.com/public/Investors/inv_stock_calculator.htm','http://www.gapinc.com/public/Investors/inv_stock_transfer_agent.htm','http://www.gapinc.com/public/Investors/inv_stock_analyst_coverage.htm')
			break
		default:
			// Do nothing
	}
}

// Set the level 4 labels and URLs for the appropriate level 2 and level 3 item
function setLevel4LabelsAndURLs()
{
	switch(level2ID)
	{
		case '10':
			switch(level3ID)
			{
				case '10':
					level4Labels = new Array('Shareholders&#39; Meeting Results')
					level4URLs = new Array('http://www.gapinc.com/public/Investors/inv_fin_shareholders_meeting_results.htm')
					break
				case '30':
					level4Labels = new Array('Archived Events')
					level4URLs = new Array('http://www.gapinc.com/public/Investors/inv_fin_archived_events.htm')
					break
				default:
					// Do nothing
			}

			break
		case '30':
			if (level3ID == '50')
			{
				level4Labels = new Array('Direct Registration')
				level4URLs = new Array('http://www.gapinc.com/public/Investors/inv_stock_direct_registration.shtml')
			}

			break
		default:
			// Do nothing
	}
}
