/* Release 5.1 */

if (typeof displayHeader != 'boolean') { displayHeader = true; }
if (typeof displayMenu != 'boolean') { displayMenu = true; }
if (typeof displaySearch != 'boolean') { displaySearch = true; }
if (typeof displayBonusBar != 'boolean') { displayBonusBar = true; }
if (typeof displayMergerLinks != 'boolean') { displayMergerLinks = displayMenu; } /* Temporarily defaulted to displayMenu to avoid code change in the DA app */

var defaultSearchBoxText = 'Search site'; 
//var defaultSearchBoxText = 'Search for . . .';

function checkForDefault() {
	var SearchValue = document.getElementById('swnquerytext').value;
	if (SearchValue == defaultSearchBoxText || SearchValue == '') return false;
	//HPSearch(this); Obsolete. Related to old web analytics (insight first)
	return true;
}

/* Self-Executing Function. This allows us to encapsulate the local variables for better minification */
(function() { 
	var assetPath = '//www.united.com/ual/asset/';
	var aMenuLinksLength = aMenuLinks.length;
	var HeaderContent = [];
	var tabIndex = 0;
	var tabName = '';
	var i = 0;
	var aMenuItem = '';
	
	/* New branding header 02/07/11 11:20AM SSM */
	HeaderContent.push('<div id="bhHeader">');
	if (displayMergerLinks) {
		HeaderContent.push('<div id="bhTop">');
		HeaderContent.push('<div id="bhTopLeft">');
		HeaderContent.push('<p><a href="' + continental_link + '">continental.com</a>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<span class="untxt">united.com</span></p>');
		HeaderContent.push('</div>');
		HeaderContent.push('<div id="bhTopRight">');
		HeaderContent.push('<p><a href="' + merger_link + '">About our new logo</a></p>');
		HeaderContent.push('</div>');
		HeaderContent.push('</div>');
		HeaderContent.push('<div id="bhMiddleArrow">');
		HeaderContent.push('<img src="' + assetPath + 'global-nav-pointer.gif" height="9" width="18" alt="Pointer" />');
		HeaderContent.push('</div>');
	}
	if (displayHeader) {
		HeaderContent.push('<div id="bhBottom">');
		HeaderContent.push('<div id="bhBottomLeft">');
		HeaderContent.push('<a href="' + homepage_link + '"><img class="newUnitedLogo" src="' + assetPath + logoImgName + '" height="30" width="173" alt="United" /></a>');
		HeaderContent.push('</div>');
		HeaderContent.push('<div id="bhBottomLeftSA">');
		HeaderContent.push('<a href="' + starAlliance_link + '"><img class="newSALogo" src="' + assetPath + staralliance_logo + '" height="14" width="160" alt="Star Alliance" /></a>');
		HeaderContent.push('</div>');
		HeaderContent.push('<div id="bhBottomRight">');
		HeaderContent.push('<p><span id="ualbrandedlinks"></span><a href="' + myProfile_link + '">' + myProfile_label + '</a>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a href="' + worldwide_link + '">' + worldwide_label + '</a>&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;<a href="' + customerSerice_link + '">' + customerSerice_label + '</a></p>');
		HeaderContent.push('</div>');
		HeaderContent.push('</div>');
	}
	HeaderContent.push('</div>');

	if (displayMenu) {
		HeaderContent.push('<div id="ualswnarea">');
		HeaderContent.push('	<form id="Homepagesearch" onsubmit="return checkForDefault();" action="//www.united.com/cgi-bin/texis/webinator/search/" name="Homepagesearch" method="get" style="margin: 0px;">');
		HeaderContent.push('		<div style="float:left; height:32px;width:10px; background-color:#FFF;"></div>');
		HeaderContent.push('		<ul class="jd_menu" style="float:left;">');
		
		/* Build the tabs */
		for (tabIndex=1; tabIndex<5; tabIndex++) {
			/* Extract the url for the tab image */
			tabName = "tab"+tabIndex;
			for (i=0; i<aMenuLinksLength; i++) {
				aMenuItem = aMenuLinks[i];
				if (aMenuItem[0] == tabName) {
					break;
				}
			}
			/* aMenuItem is the element in the array we are looking for to build the tab image */
			HeaderContent.push('			<li id="'+tabName+'" onClick="window.location.assign(\''+aMenuItem[2]+aMenuItem[3]+'\');"><a id="'+ tabName +'Button" class="navButton" href="'+aMenuItem[2]+aMenuItem[3]+'"></a>');
			HeaderContent.push('				<ul class="newSubMenu" style="width:'+ulWidth[tabIndex]+'px !important"></ul>');
			HeaderContent.push('			</li>');
		}
		
		HeaderContent.push('		</ul>');
		HeaderContent.push('		<div class="swnquerytextContainer">');
		
		if (displaySearch) {
			HeaderContent.push('		<input type="text" value="' + defaultSearchBoxText + '" name="query" id="swnquerytext">');
		}
		
		HeaderContent.push('		</div>');
		HeaderContent.push('		<div class="swnquerybuttonContainer">');
		
		if (displaySearch) {
			HeaderContent.push('		<input id="swnquerybutton" type="image" src="//www.united.com/ual/asset/swn_search_button.gif" value="submit" name="submit"><input type="hidden" value="siteprofile" name="pr">');
		}
		
		HeaderContent.push('		</div>');
		HeaderContent.push('	</form>');
		HeaderContent.push('</div>');
	}
	
	/* The bonus bar element must be present to accept JS in another file, but we'll hide it if necessary */
	if (displayBonusBar) display = 'block';
	else display = 'none';
	HeaderContent.push('		<div id="ualbonusbar" style="display: '+ display +';"></div>');
	
	document.write(HeaderContent.join(''));
})();

if (displaySearch) {
	var ualEvent = {
		add: function(obj, type, fn){
			if (obj.attachEvent) {
				obj['e' + type + fn] = fn;
				obj[type + fn] = function(){
					obj['e' + type + fn](window.event);
				};
				obj.attachEvent('on' + type, obj[type + fn]);
			}
			else 
				obj.addEventListener(type, fn, false);
		},
		remove: function(obj, type, fn){
			if (obj.detachEvent) {
				obj.detachEvent('on' + type, obj[type + fn]);
				obj[type + fn] = null;
			}
			else 
				obj.removeEventListener(type, fn, false);
		}
	};
	
	var SearchBoxObj = document.getElementById('swnquerytext');
	ualEvent.add(SearchBoxObj, 'focus', function(){
		if (SearchBoxObj.value == defaultSearchBoxText) {
			SearchBoxObj.value = '';
			SearchBoxObj.style.textAlign = 'left';
			SearchBoxObj.style.color = '#1B3D6B';
		}
	});
	
	ualEvent.add(SearchBoxObj, 'blur', function(){
		if (SearchBoxObj.value == '') {
			SearchBoxObj.value = defaultSearchBoxText;
			SearchBoxObj.style.textAlign = 'left';
			SearchBoxObj.style.color = '#666666';
		}
	});
	
	ualEvent.add(SearchBoxObj, 'keydown', function(e){
		if (window.quickUASearch) {
			quickUASearch(event);
		}
	});
	
	ualEvent.add(SearchBoxObj, 'keypress', function(e){
		if (window.quickUASearch) {
			quickUASearch(event);
		}
	});
}



