nxVars.commonCookieName='nxcommon';
nxVars.CAInterstitialPage='/en/custom_aisles/ca_leaving.html';

nxVars.hVars={
	langItems:new Array(),  // Holds the language based Items
	hTabId:0,	// tab ID
	sNavId:-1, // sub-nav ID
	secureServer:((location.protocol == "https:")?true:false),  // checks for secure page
	headerLogoutStr:'/sso/Logout.jsp', // link text for logout
	// audience landing pages
	
	// logged in user info
	userProfile:{
		firstName:"",  // user first name 
		lastName:"",  // user last name
		nameStr:''  // output string for logout 
	},	
	// Manage properties
	manage:{
		userType:"h",  // user type "n"=nextel "h"=hybrid
		hybridUrl:'',  //	Manage tab url (for hybrid)
		hybridBase:'', // server name (no path) for hybrid users
		userAccountCookieName:'NXTL_SELECTED_ACCT',
		subscriberAccountCookieName:'NXTL_SELECTED_SUBSCRIBER',
		baseCookieName:'managebase',
		selectedAccount:'',
		selectedSubscriber:'',
		subNavFilter:'',
		subNavFilterCookieName:'manageSL',
		overviewPath:"/wps/myportal" //hybrid manage overview path toggle
	},
	showCAName:true
};
// set the base path for non-header specific assets to either he headerBaseUrl or the secure root
nxVars.hVars.assetBase = ((nxVars.hVars.secureServer)?nxVars.secureRoot:nxVars.headerAssetServer);
nxVars.hVars.headImgBase=nxVars.hVars.assetBase+nxVars.headImgPath;

nxVars.CAType=false;  // custom aisle type, false by default, "corp","govt",or "affiliate" if custom aisle

// store label, homepage, omniture value for each audience
nxVars.hVars.audInfo=new Hash({
		"INDIVIDUAL":{
				title:"Personal",
				url:nxVars.sprintServerUrl+"/index.shtml",
				audType:"INDIVIDUAL"
		},
		"PUBLIC_SECTOR":{
				title:"Public Sector",
				url:nxVars.sprintServerUrl+"/index.shtml",
				audType:"PUBLIC_SECTOR"
		},
		"ENTERPRISE":{
				title:"Enterprise",
				url:nxVars.sprintServerUrl+"/index.shtml",
				audType:"ENTERPRISE"
		},
		"GENERAL_BUSINESS":{
				title:"Small Business",
				url:nxVars.sprintServerUrl+"/index.shtml",
				audType:"GENERAL_BUSINESS"
		},
		"HISPANIC":{
				title:"en espa&ntilde;ol",
				url:nxVars.sprintServerUrl+"/index.shtml?language=ES",
				audType:"INDIVIDUAL"
		}
		
	});
	
// returns the omniture audience for the each audience type	
nxVars.getAud=function(name){
			var aud="INDIVIDUAL";
			if(nxVars.hVars.audInfo.hasKey(name)){
				aud=nxVars.hVars.audInfo[name].audType;
			}
			return aud			
		}
// returns the label for each audience type (not used anymore since label is not displayed in sub-nav)
nxVars.getAudText=function(name){
			var aud=nxVars.hVars.audInfo["INDIVIDUAL"].title;
			if(nxVars.hVars.audInfo.hasKey(name)){
				aud=nxVars.hVars.audInfo[name].title;				
			}
			return aud			
		}		
		
// store common links
nxVars.hLinks={
	home:'',
	shop:'',
	support:'',
	mySprint:''
}

//******************************
// END variable declarations
//******************************

//******************************
// Popup for NPI users
//*******************************
function sprint_doNPI(){
	nxVars.isNPI=Object.hasProperty(spCookies,'cookieValue','nxpartner','partner');
	if(nxVars.isNPI=="yes"){
		nxPopup('npiPopUp',nxVars.headerAssetServer+'/en/legal/npi_manage_popup.shtml');
		deleteNxCookie("nxpartner");
	}
}
//******************************
// END Popup for NPI users
//******************************

function sprint_getCookieVars(){
	var tmp=null;
	// is custom aisle
	nxVars.isCA=isValidText(Object.hasProperty(spCookies,'cookieValue','nolCustomAisleToken'));
	// custom aisle company name
	nxVars.CAName=Object.hasProperty(spCookies,'cookieValue','customAisleFileCookie','aisleCorpName');
	// is global suppressed (ariba) flag
	nxVars.gSup=isValidText(Object.hasProperty(spCookies,'cookieValue','GlobalSuppressedAisle'));
	// language preference (read from cookie, default to EN if not in cookie)
	tmp=Object.hasProperty(spCookies,'cookieValue',nxVars.commonCookieName,'language');
	nxVars.lang=(isValidText(tmp)?tmp.toLowerCase():'en');
	// user zipcode
	tmp=Object.hasProperty(spCookies,'cookieValue',nxVars.commonCookieName,'zipcode');
	nxVars.zipCode=(isValidText(tmp)?tmp:'');
	// user city
	tmp=Object.hasProperty(spCookies,'cookieValue',nxVars.commonCookieName,'city');
	nxVars.uCity=(isValidText(tmp)?tmp:'');
	// user state
	tmp=Object.hasProperty(spCookies,'cookieValue',nxVars.commonCookieName,'state');
	nxVars.uState=(isValidText(tmp)?tmp:'');
	// user region
	tmp=Object.hasProperty(spCookies,'cookieValue',nxVars.commonCookieName,'location');
	nxVars.uRegion=(isValidText(tmp)?tmp:'').replace(/\+/gim,'');
	 // user audience (read from cookie, default to individual if not there)
	tmp=Object.hasProperty(spCookies,'cookieValue',nxVars.commonCookieName,'audience');
	nxVars.aud=((isValidText(tmp)&&nxVars.hVars.audInfo.hasKey(tmp))?tmp:"INDIVIDUAL");

	tmp=Object.hasProperty(spCookies,'cookieValue','nolCustomAisleToken');
	nxVars.isEPPP=(tmp=="eEwnRLV7Wr38IqnRYJHIPG8SSvI");
}

// set variables for user logged in status
function sprint_setUserLoginStatus(){
	// user is logged in
	var tmp=Object.hasProperty(spCookies,'cookieValue','SMSESSION');
	nxVars.isLoggedIn=(tmp&&tmp!="LOGGEDOFF");
	// check store P2K login hack
	if(!nxVars.isLoggedIn){
		tmp=Object.hasProperty(spCookies,'cookieValue','LoggedIntoP2k');
		nxVars.isLoggedIn=(tmp&&tmp!="false");
	}
	//******************************
	// get Profile info for logout from cookie
	//******************************
	tmp=Object.hasProperty(spCookies,'cookieValue','nxprofile','fname');
	nxVars.hVars.userProfile.firstName=(tmp?tmp.replace(/\+/gim,' '):'');
	tmp=Object.hasProperty(spCookies,'cookieValue','nxprofile','lname');
	nxVars.hVars.userProfile.lastName=(tmp?tmp.replace(/\+/gim,' '):'');
	nxVars.hVars.userProfile.nameStr=nxVars.hVars.userProfile.firstName+' '+nxVars.hVars.userProfile.lastName;
}

// sets the common cookie.  
// parameters:
// 		cName: the piece of the cookie you want to set (e.g. zipcode)
// 		cVal: the value to set it to
function sprint_setCommonCookie(cName,cVal){
	if(nxVars.thirdParty){
		return
	}
	// ensure that the cookie has the basic properties (language, zip, audience, location)
	if(!Object.hasProperty(spCookies,'cookieValue',nxVars.commonCookieName)){
		spCookies.cookieValue[nxVars.commonCookieName]=new Hash({language:nxVars.lang.toUpperCase(),
			zipcode:nxVars.zipCode,
			audience:nxVars.aud,
			location:nxVars.uRegion
		});
	}
	var dte=new Date();
	// Cookie lasts 1 year
	dte.setFullYear(dte.getFullYear()+1);
	spCookies.setCookieItem([nxVars.commonCookieName,cName],cVal,dte.toGMTString());
}

//******************************
// Handle Audience based on URL
//******************************
function sprint_setUpAudience(){
	//******************************
	// parse audience from url query string
	//******************************
	var tmp=location.href.getParam("audience");
	// if audience in query, set cookie
	if(tmp){
		nxVars.aud = nxVars.getAud(tmp);		
		sprint_setCommonCookie('audience',nxVars.aud);
	}
}

function sprint_setUpLanguage(){
	var lang=nxVars.lang;
	// MyNextel, Ecare, Custom Aisles always set to english
	var myNextelPageArr = ['/wps/myportal/','/NASApp/cs/',
							'/wps/portal/','/NASApp/consent',
							'/NASApp/bulkreg','/NASApp/addrbook','/NASApp/caretools',
							'/NASApp/waputils','/NASApp/mvadmin','/NASApp/wes-web'];
	var mn=myNextelPageArr.some(function(val){
		return location.href.contains(val)
	});
	if(mn||nxVars.isCA||!nxVars.langCapable){
		lang="en";		
	}
	else{
		// check language parameter in URL
		var par=location.href.getParam("language");
		var pth=location.pathname;
		// check for EN in URL folders
		if(pth.contains("/en/")){
			lang = "en";
		}
		// check for ES in URL folders
		if(pth.contains("/es/")){
			lang = "es";					
		}
		// parameter in URL always wins 
		if($if(par,'==','||',"EN","ES")){
			lang=par.toLowerCase();
		}
	}
	// check for 3rd party explicitly setting language
	if(nxVars.thirdPartyLang != null){
		switch(nxVars.thirdPartyLang){
			case 'es': lang = 'es';
						break;
			default: lang = 'en';
		}
	}
	// if language is not the same as the cookie, set the cookie
	if(lang.toUpperCase()!=nxVars.lang.toUpperCase()){
		sprint_setCommonCookie('language',lang.toUpperCase());
	}
	
	// set global value
	nxVars.lang=lang;
// End Comment Spanish Decom

}

//******************************
// Manage Account Type settings
//******************************
function sprint_setUpManageAccount(){
	// read baseURL (prepended to links) from URL string
	var tmp=location.href.getParam('baseURL');
	// get baseURL from cookie
	var ck=Object.hasProperty(spCookies,'cookieValue',nxVars.hVars.manage.baseCookieName);
// if baseURL parameter or cookie, usertype = hybrid
	// if in URL parse parameter and set cookie
	if(tmp){
		var tmp2=decodeURIComponent(tmp);
		while(tmp2!=tmp){
			tmp=tmp2;
			tmp2=decodeURIComponent(tmp);
		}
		nxVars.hVars.manage.hybridUrl=tmp2;
		nxVars.hVars.manage.userType='h';
		setNxCookie(nxVars.hVars.manage.baseCookieName,tmp,'session');
	}
	// else read from cookie
	else if(ck){
		nxVars.hVars.manage.userType='h';
		nxVars.hVars.manage.hybridUrl=ck;
	} 
	else {
		nxVars.hVars.manage.hybridUrl=nxVars.uscBaseUrl;
	}
// parse pieces of URL
	if(isValidText(nxVars.hVars.manage.hybridUrl)){
		// parse the server name from the cookie/parameter
		var rg=/^(http(s)?\:\/\/)?([a-zA-Z\d\-\.]*(\:\d+)?){1}/i;
		var mt=nxVars.hVars.manage.hybridUrl.match(rg);
		if(mt!=null){
			nxVars.hVars.manage.hybridBase=mt[1]+mt[3];
			//set the path for hybrid accounts
			nxVars.hVars.hybridUrlPath=nxVars.hVars.manage.hybridBase+nxVars.manHybridBasePath;
		}
	}
	//setup hybrid sub-nav filter (filter=a base2 string of 6 numbers, 0 = hide sub-nav item, 1 = show, ex:011110 shows all links in sub-nav except 1st and last)
	
	// read from paramstring
	tmp=location.href.getParam('sl');
	ck=Object.hasProperty(spCookies,'cookieValue',nxVars.hVars.manage.subNavFilterCookieName);
	if(tmp){
		// if in paramstring, read from there and set cookie
		nxVars.hVars.manage.subNavFilter=tmp;
		setNxCookie(nxVars.hVars.manage.subNavFilterCookieName,tmp,'session');
	}
	// else read cookie value
	else if(ck){
		nxVars.hVars.manage.subNavFilter=ck
	}
	// setup manage selected account (appended to all hybrid sub-nav links so that it can be sent back to p2k server)
	// hybrid only
	tmp=location.href.getParam('selaccount');
	ck=Object.hasProperty(spCookies,'cookieValue',nxVars.hVars.manage.userAccountCookieName);
	// read from cookie first (in case server has changed the account but user hits back)
	if(ck){
		nxVars.hVars.manage.selectedAccount=ck;
	}
	// else read from paramstring
	else if(tmp){
		nxVars.hVars.manage.selectedAccount=tmp;
		setNxCookie(nxVars.hVars.manage.userAccountCookieName,tmp,'session');
	}
	// setup manage selected subscriber
	tmp=location.href.getParam('selsubscriber');
	ck=Object.hasProperty(spCookies,'cookieValue',nxVars.hVars.manage.subscriberAccountCookieName);
	if(ck){
		nxVars.hVars.manage.selectedSubscriber=ck;
	}
	else if(tmp){
		nxVars.hVars.manage.selectedSubscriber=tmp;
		setNxCookie(nxVars.hVars.manage.subscriberAccountCookieName,tmp,'session');
	}
	
}

//******************************
// link settings
//******************************

function sprint_setHeaderLinks(){
	// default the home link
	nxVars.hLinks.home=nxVars.sprintServerUrl+"/index.html";
	// if Aisle, change to aisle home (in cookie)
	if(nxVars.isCA){
		nxVars.hLinks.home=nxVars.headerAssetServer+nxVars.cookieVal["customAisleFileCookie"]["aisleLandingFilename"];
	}	
} // end sprint_setHeader_links



//******************************
// if custom aisle and on entry, support landing, promotions landing or audience landing page
// forward user to custom aisle equivelent.
// Added the token parameter to the all custom aisle pages
//******************************
function sprint_setUpCustomAisles(){
	var fwdUrl = false;
	var hm=nxVars.hLinks.home;
	var tpes=['affiliate','corp','govt'];
	tpes.forEach(function(val){
		if(hm.contains('/'+val+'/')){nxVars.CAType=val}
	});
	var pths=["/","/"+nxVars.lang+"/promotions/","/"+nxVars.lang+"/support/faq/"];
	var ck=[nxVars.hLinks.home,
		Object.hasProperty(spCookies,'cookieValue','customAisleFileCookie','aislePromoFilename'),
		Object.hasProperty(spCookies,'cookieValue','customAisleFileCookie','aisleFaqsFilename')];
	
	pths.forEach(function(val,key){
		if(((location.pathname==val)||(location.pathname==val+"index.shtml"))
		&&(ck[key]&&(location.pathname!=ck[key]))){
			location.replace(nxVars.headerAssetServer+ck[key]);
		}
	});
	if(location.pathname==nxVars.hLinks.home){
		nxVars.hVars.showCAName=false;
	}
}

// write out the appropriate sub-nav and tab definition files on the page.
function sprint_getDefinitionFiles(){
	var tpl='<scr'+'ipt type="text/javascript" id="<=scriptId=>" src="<= src =>"></scr'+'ipt>'+_NL;
	var out='';
	var obj={};
	nxVars.hVars.navScriptIds=[];
	for(var x in nxVars.definitionFiles[nxVars.lang]){
		var v=nxVars.definitionFiles[nxVars.lang][x];
		if(x=='manage'){
			v=nxVars.definitionFiles[nxVars.lang][x][nxVars.hVars.manage.userType];
		}
		obj.scriptId=x+'_dev_file';
		nxVars.hVars.navScriptIds.push(x+'_dev_file');
		obj.src=nxVars.definitionFiles.path+v;
		if(nxVars.hVars.secureServer){
			obj.src=obj.src.replace("http://","https://");
		}
		out+=tpl.template(obj);
	}	
	dwl(out);
}






	

// Tab Bar Functions
// htab:  -5 to 3 or a0-a7, determines which tab to highlight 
//		-4 = hide tabs, show utility and empty tab bar
//		-3 = hide tabs and utility links, show empty tab bar
//		-2 = hide tabs and tab bar
//		-1 = hide tabs,tab bar, and utility links
//		0 = Show all, nothing highlighted
//		1=shop tab highlighted
//		2=support tab highlighted
//		3=mynextel tab highlighted
//		4=Digital Lounge tab highlighted
//
// targ:  gives a target for all links, see HTML <a> target properties 
//
function renderTabBar(hTab, targ){
	var out="";	
	linkTarget=((targ)?targ:((nxVars.gSup)?'_self':'_top'));
	// set tab ID
	nxVars.tabs.forEach(function(val,key){
		if(val.selectNumber==hTab){
			nxVars.hVars.hTabId=key;
		}
	});
	if(hTab!=null){
		nxVars.hVars.hTabId=hTab;		
	}
	// generate the logo bar
	out+=sprint_renderNavTop(nxVars.hVars.hTabId, linkTarget);
	// generate the tab bar
	out+=sprint_generateTabs(nxVars.hVars.hTabId,linkTarget);
	
	return out;
}


// generates the logo bar
function sprint_renderNavTop(hTab, targ){
	var out='<div id="navTop">'+_NL+'<div class="section">';
	out+='<p id="brand">'
	var img={};
	// URL base defined in nav_def.js
	img.base=nxVars.hVars.headImgBase;
	img.file='logo_header_'+nxVars.lang+'.gif';		
	img.alt=nxVars.hVars.langItems['brand_alt'];	
	var logoSrc = '<img src="<=base=><=file=>" id="headerLogo" alt="<=alt=>" />'.template(img);
	// -5 means unlink the logo
	if(hTab!=-5){
		logoSrc = '<a href="'+nxVars.hLinks.home+'" target="'+targ+'">'+logoSrc+'</a>';
	}
	out+=logoSrc;
	out+='</p>'+_NL;
	// -5, -3, -1 = no utility links (about etc)
	if($if(hTab,'!=','&&','-5','-3','-1')){
		out+='<div id="navI">'+_NL;
		out+=sprint_generateNavLinkList('primary',targ);
		out+='</div>'+_NL;			
		
	// Added the condition to hide/show Search box which was moved from the nav tab to the header VyshP @ 02/28/2008
	// As a part of homepage Redesign
		// see if "hTab" matches the tabs hash key for one of the tabs
		if(nxVars.isCA)
		{
			if(!nxVars.CASuppressSearch){
				out+=sprint_getSearchBox();
			}
		}		
		else if(nxVars.tabs.hasKey(hTab)){
			out+=(nxVars.tabs[hTab].allowSearch)?sprint_getSearchBox():'';
		}
		// else see if "hTab" matches on of the tabs "selectNumber" properties (for backwards compatibility)
		else if(isNumber(hTab)){
			nxVars.tabs.forEach(function(v){
				if(v.selectNumber==hTab){
					out+=(v.allowSearch)?sprint_getSearchBox():'';
				}
			});
		}
		
	}
	out+='<div class="clearer"></div>'+_NL+'</div>'+_NL+'</div>'+_NL;
	//out+='<div class="clearer"></div>'+_NL+'</div>'+_NL;
	return out
}

// generates the tabs
function sprint_generateTabs(hTab,targ){
	var out="";
	// -2, -1 = no tab bar, return nothing
	if($if(hTab,'!=','&&','-1','-2')){
		// -3, -4,-5 = empty tab bar
		if($if(hTab,'!=','&&','-3','-4','-5')){
			var obj={};
			obj.section="";
			obj.language="lang-"+nxVars.lang;
			obj.search="";
	// for highlighting active tab:
			// see if "hTab" matches the tabs hash key for one of the tabs
			if(nxVars.tabs.hasKey(hTab)){
				obj.section=nxVars.tabs[hTab].styleclass;
				// Search box was moved from the tab to the header hence commented out below
				// obj.search=(nxVars.tabs[hTab].allowSearch)?sprint_getSearchBox():'';
			}
			// else see if "hTab" matches on of the tabs "selectNumber" properties (for backwards compatibility)
			else if(isNumber(hTab)){
				nxVars.tabs.forEach(function(v){
					if(v.selectNumber==hTab){
						obj.section=v.styleclass;
						// Search box was moved from the tab to the header hence commented out below
						//obj.search=(v.allowSearch)?sprint_getSearchBox():'';
					}
				});
			}
			var tabtpl='<div id="<=domId=>"><a href="<=url=>" target="<=target=>" <=popup=>><i><span><=altText=></span></i></a></div>';
			obj.tabs=[];
			// generate the html for each tab
			nxVars.tabs.forEach(function(val){
				// check if the tab is allowed for the audience and for the aisle (if applicable)
				if(sprint_checkLinkAudienceStatus(val)&&sprint_checkLinkAisleStatus(val)){
					val.popup="";
					val=sprint_getRealHeaderLink(val);	
					
					val['target']=((isValidText(val['target']))?val['target']:targ);
					val.popup=isValidText(val.popup)?'popup="'+val.popup+'"':'';	
					obj.tabs[val.order]=tabtpl.template(val);
				}
			});
			obj.tabStr=obj.tabs.join(_NL);
			var tpl='<div id="navTabs" class="<=section=>">'+_NL;
			tpl+='<div class="section <=language=>">'+_NL;
			tpl+='<div id="navII">'+_NL;
			tpl+='<div id="nowrapNavII">'+_NL;
			tpl+='<=tabStr=>'+_NL;
			tpl+='</div>'+_NL;
			tpl+='</div>'+_NL;
			tpl+='<=search=>';
			tpl+='</div>'+_NL;
			tpl+=_Clearer+_NL;
			tpl+='</div>'+_NL;
			out=tpl.template(obj);
		}
		// output empty tab bar
		else{
			out='<div id="navTabs"><img src="'+_SPACER+'" alt="" height="29" /></div>'+_NL;
		}			
	}
	return out
}

// sub nav bar functions
//
// navID: the unique Identifier for which sub-nav Item to highlight, see nxVars.hVars.subNavSet for IDs
//        0 = suppress all, render empty space
//		  shop = show shop sub-nav with nothing highlighted
//        support = show support sub-nav with nothing highlighted
// 		  nologout = show mynextel without logout info
//        showlogout = show logout info on non-mynextel pages
//
// targ:  gives a target for all links, see HTML <a> target properties 
//
function renderSubNavBar(navID, targ){
	var defStr='';
	nxVars.hVars.sNavId=(isDefined(navID)?navID:null);
	// if a sub-nav is defined:
	if(nxVars.hVars.sNavId){
		// get the links within the sub-nav group
		var links = sprint_getNavLinkList(nxVars.hVars.sNavId);
		if(links!=-1){
			defStr+=sprint_generateNavLinkList(links,targ);			
		}
		// if Aisle, show the aisle name below the sub-nav
		if((nxVars.isCA)&&(nxVars.hVars.showCAName)){
			nxVars.CAName=(nxVars.CAName!=false)?nxVars.CAName:'Sprint';
			defStr+='<h6>'+nxVars.CAName+' Private Store</h6>';
		}
	}	
	// if empty, add &nbsp; to make the browsers play nice
	if(defStr==''){defStr='&nbsp;'}	
	var out='<div id="navIII">'+_NL+defStr+'</div>'+_NL;
	return out;
}


// generates the HTML for a sub-nav group (includes utility links and footer)
function sprint_generateNavLinkList(links,targ){
	var linkTemplate='<li class="<=cls=>"><a href="<=url=>" class="<=lnkCls=>" target="<=linkTarget=>" <=pop=>><=text=></a></li>'+_NL;
	var noLinkTemplate='<li class="<=cls=>"><=text=></li>'+_NL;
	var sObj=new Object();
	var showFirst=true;
	var barStr = '<ul>';
	var sItems=[];
	// for each link in set
	nxVars.subNavItems[links].forEach(function(val,key){
		//remove upgrades from eppp aisle
		if(key=='labelId'||(nxVars.isEPPP&&(key=="upg"))){return}
		// check audience, aisle, hybrid filter status
		if(sprint_checkLinkAudienceStatus(val,key)&&sprint_checkLinkAisleStatus(val)&&sprint_checkLinkFilterStatus(val,nxVars.hVars.manage.subNavFilter)){
			sObj.text=val.label;
			val=sprint_getRealHeaderLink(val);			
			sObj.url=val['url'];			
			sObj.pop=isValidText(val.popup)?('popup="'+val.popup+'"'):'';
			// allow link definition to override "targ" parameter
			sObj.linkTarget=isValidText(val.target)?val.target:((targ)?targ:((nxVars.gSup)?'_self':'_top'));
			// if selected link, set class to "on"
			sObj.lnkCls=(key==nxVars.hVars.sNavId)?'on':'';
			// if first item in list, remove the pipe to the left (add class "first")
			sObj.cls=showFirst?'first':'';
			showFirst=false;
			//sObj.pop='';	
			sItems[val.order]=(sObj.url!=null)?linkTemplate.template(sObj):noLinkTemplate.template(sObj);
		}
	});
	barStr+=sItems.join(' ');
	barStr += '</ul>'	
	return barStr;
}

// Check if the link is allowed within the audience
function sprint_checkLinkAudienceStatus(val,key){
	// Aisle overrides the audience
	if(nxVars.isCA){return true}
	return !(val.hasKey(nxVars.aud.toLowerCase())&&(val[nxVars.aud.toLowerCase()]==false));
}

// Check the aisle status of a sub-nav link
function sprint_checkLinkAisleStatus(val){
	var r=true;
	// check for regular aisle
	if(nxVars.isCA&&val.hasKey('showCA')&&(val['showCA']==false)){
		r=false;
	}
	// check for global suppressed aisles
	if(nxVars.gSup&&val.hasKey('showSuppressed')&&(val['showSuppressed']==false)){		
		r=false;
	}
	return r;
}
// check the Hybrid filter status of a link
function sprint_checkLinkFilterStatus(val,filter){
	return !(filter&&(val.filter)&&(filter.charAt(val.filter)=='0'))
}


// renders the footer
// fOpt:  -1 = suppress nav links, otherwise it ignores all inputs
//
// targ:  gives a target for all links, see HTML <a> target properties 
//

function renderFooter(fOpt, targ){
	var fObj=new Object();
	var tpl='<div class="section">'+_NL+'<=links=>'+_NL+'<p class="copy"><=copyright=></p>'+_NL+'<=disclaimer=>'+_NL+_Clearer+_NL+'<=omniture=></div>';
	fObj.omniture=(nxVars.doOmniture)?'<div id="omnitureDiv"></div><scr'+'ipt type="text/javascript" src="'+((isDefined(nxVars.omniturePrepend)&&nxVars.omniturePrepend)?nxVars.hVars.assetBase:"")+nxVars.omnitureSrc+'"></scr'+'ipt>':'';
	fObj.links=($if(fOpt,'!=','&&','-1',-1))?sprint_generateNavLinkList("footer",targ):'&nbsp;';
	fObj.copyright=nxVars.hVars.langItems['copyright'];
	fObj.disclaimer='';
	// add the aisle footnote if it is defined in the cookie
	if(nxVars.isCA){
		var fn=Object.hasProperty(spCookies,'cookieValue','customAisleFileCookie','aisleFootnote');
		if(fn&&isValidText(fn)){
			fObj.disclaimer='<p class="disclaimer">'+fn+'</p>';
		}
	}
	//Omniture 2.0 code
	if(location.href.toLowerCase().indexOf('nasapp/onlinestore') < 0){
		if(location.href.toLowerCase().indexOf('/promotions/') >= 0 || location.href.toLowerCase().indexOf('/services/') >= 0 || 
					location.href.toLowerCase().indexOf('/accessories/') >= 0 || location.href.toLowerCase().indexOf('/shop/') >= 0){
			fObj.omniture += '<script type="text/javascript" >'+
							'Analytics = new Object;Analytics.MetricData = {};Analytics.MetricData.appId = "eComStore";Analytics.currentEnvironmentTest = "test";'+
							'if(location.host.toLowerCase().indexOf("atlsdesd.nextel.com") >= 0){'+
							'Analytics.currentEnvironmentTest = "dev";}'+
							'if(location.host.toLowerCase().indexOf("nextelonline.nextel.com") >= 0 || location.host.toLowerCase().indexOf("www.nextel.com") >= 0){'+
							'Analytics.currentEnvironmentTest = "prod";}'+
							'switch(Analytics.currentEnvironmentTest){'+
							'case "dev": '+
							'Analytics.MetricData.currentHost = "144.226.249.20";Analytics.MetricData.environment ="dev";break;'+
							'case "test":'+
							'Analytics.MetricData.currentHost = "nolbf.sprint.com";Analytics.MetricData.environment ="test";break;'+
							'case "prod":'+
							'Analytics.MetricData.currentHost = "nextelonline.nextel.com";Analytics.MetricData.environment ="prod";break;'+
							'}Analytics.MetricData.action=location.href;'+
							'Analytics.library = document.createElement("script");Analytics.library.type = "text/javascript";'+
							'Analytics.library.src = "//"+Analytics.MetricData.currentHost+"/assets/scripts/analytics/analyticsFramework.js";'+
							'document.getElementsByTagName("head")[0].appendChild(Analytics.library);'+
							'</script>';
		}
	}
	//*****************end Omniture2.0
	ftlnk=tpl.template(fObj);
	return ftlnk;
}

function renderinQFooter(fOpt, targ){
	var inQlnk='';
	if(!nxVars.isCA){
		inQlnk='<div id="inQDiv"><scr'+'ipt type="text/javascript" src="/assets/scripts/inq/inq_omniture.js"></scr'+'ipt>'+_NL;
		inQlnk+='<scr'+'ipt type="text/javascript" charset="utf-8" src="https://sprint.inq.com/chatskins/launch/inqChatLaunch154.js"></scr'+'ipt></div>';
	}
	return ftLinks=inQlnk+_NL+renderFooter(fOpt, targ);
}

// converts the link to call the hispanic interstitial page
//
function getNxInterstitialLink(url){
	// manage landing has a special redirect
	if(url == nxVars.myUrl){
		url = nxVars.mySprintServerUrl+"/wps/myportal/mynextel/LandingPage";
	}	
	return nxVars.storeServerUrl+'/es/mynextel/index.shtml?loc='+encodeURIComponent(url)+'&ref='+encodeURIComponent(location.href);
}

// put in the aisle interstitial page for links that leave the nextel domain	
function sprint_getCAWarningPage(url){
	return (nxVars.storeServerUrl+nxVars.CAInterstitialPage).addParam('redirect',url);
}


// returns the correct link based on whether a link is supposed to be over-ridden by a custom aisle cookie
// or whether the language is ES and the link should use the interstitial page
function sprint_getRealHeaderLink(val){
	if(isFunction(val.url)){
		val=val.url(val);
	}
	if(nxVars.isCA){
		if(val['aisleCookie']){
			val['url']=nxVars.headerAssetServer+nxVars.cookieVal["customAisleFileCookie"][val['aisleCookie']].addParam("token",spCookies.cookieValue.nolCustomAisleToken);	
		}
		if(val['aisleWarning']){
			val['popup']='toolbar=no,menubar=no';
			val['target']='cawarn';
			val['url']=sprint_getCAWarningPage(val.url);
		}
	}
	else if(val['interstitial']){
		val['url']=getNxInterstitialLink(val['url']);
	}
	return val;
}
		
//  returns the appropriate set of sub-nav and footer links based on audience, custom aisle, and custom aisle suppression flag
//
function sprint_getNavLinkList(linkId){
	// Hybrid users have a set of 6 sub-nav links, legacy nextel users only have 3
	// Manage pages always call the Hybrid link definition, this function converts the link for non-hybrid users
	function remapManageLinks(lnk){	
		if(nxVars.hVars.manage.userType=='n'){
			switch(lnk){
				case 'manPap':
				case 'manBap':
				case 'manSap':
				case 'manMot': lnk='manAcc';

								break;
			}
		}
		return lnk
	}
	if(!isDefined(linkId)){
		if((nxVars.hVars.hTabId == "manage")&&(nxVars.isLoggedIn)){
			return "manLabel"
		}
		if((parseInt(linkId) == 0)||(linkId == "nologout")){
			return -1;
		}	
		switch(nxVars.hVars.hTabId){
			case "shop": 
			case "support": return nxVars.hVars.hTabId;
			default: return -1
		}		
	}
	
	linkId=remapManageLinks(linkId);
	// check if the called sub-nav id matches either a set id (nothing highlighted) or the ID
	// of an item in the set (item to be highlighted).  Returns the set-ID either way.
	var lId=nxVars.subNavItems.grep(function(val,key){
			if((key==linkId)||(val.labelId&&(val.labelId==linkId))){
				return true;
			}
			else{
				 var ky=val.grep(function(v,k){
					return (k==linkId)
				});
				return (ky?ky:false)
			}
	});
	// if no match, return -1 so that the receiving functions know
	lId=(lId?lId:-1)
	return lId;
}


// show the region bar (used in store pages)
function nxDisplayRegion(){
	var zipRedirectUrl='';
	if((nxVars.uCity != "") && (nxVars.uState != "")){
		var outTxt = '<div class="regionBar">';
		if((typeof(upgradePath)!='undefined') && (upgradePath!=null)){
			outTxt += '<span style="float:right;" class="subscriberNum">';
			outTxt += nxVars.hVars.langItems['region_intro']+' '+nxVars.uCity +', '+nxVars.uState;
			outTxt += '<a href="javascript:doUpgradeXHR(\''+zipCodeModalAction+'\', null)"> ';
			outTxt += nxVars.zipCode;
			outTxt += ' </a></span>';
			outTxt += '<br />';
			outTxt += '<span style="float:right;" class="subscriberNum">Upgrading phone: <a href="javascript:doUpgradeXHR(\''+changeSubscriberUrl+'\', null)\">'+ subscriberPhone + '</a></span>';
		} else {
			if((typeof(targetUrl)!='undefined') && (targetUrl!=null)){
				zipRedirectUrl='?'+targetUrl;
			}
			outTxt += nxVars.hVars.langItems['region_intro']+' '+nxVars.uCity +', '+nxVars.uState;
			outTxt += '<a href="'+nxVars.storeServerUrl+'/NASApp/onlinestore/'+nxVars.lang+'/Action/DefineRegionAction'+zipRedirectUrl+'">';
			outTxt += ' '+nxVars.zipCode;
			outTxt += '</a>';
		}
		outTxt += '</div>'+_Clearer;
		dwl(outTxt);
	}
}

// gets the coverage map link
function getCoverageLink(uZip,linkIn){
	var pop=nxVars.thirdParty;
	var covBase=(nxVars.isProd||nxVars.thirdParty?"http://coverage.sprintpcs.com":"http://tdas2144.test.sprint.com");
	var page=((!pop) && (!nxVars.isCA)?"/IMPACT.jsp":"/IMPACTnobrand.jsp");
	var retProt=(nxVars.thirdParty?'':"http://");
	var retBase=retProt+(nxVars.isProd?'nextelonline.nextel.com':(nxVars.thirdParty?'':location.host));
	if(nxVars.subNavItems["shop"]["pho"]["url"].indexOf('nextel.com')!=-1){retBase=''}
	var url=covBase+page;
	var zip=(isDefined(uZip)?uZip:(isDefined(location.href.getParam('mapzip'))?location.href.getParam('mapzip'):nxVars.zipCode));
	url=url.addParam("mapzip",zip).addParam('covType','sprint').addParam("returnUrl",retBase+nxVars.subNavItems["shop"]["pho"]["url"]).addParam("language",nxVars.lang.toUpperCase());
	// Aisles has its own coverage map page to avoid leaving the domain
	if(nxVars.isCA && !linkIn){
		url="/en/custom_aisles/coverage_maps.html";
		if(isDefined(uZip)){
			url=url.addParam("mapzip",uZip);
		}
	}
	return url;
}

// makes a nav definition item into a coverage map link
function sprint_convertCoverageToNav(obj){
	// 3rd parties get coverage as a pop-up
	if(nxVars.thirdParty){
		obj.target='impactMap';
		obj.popup='height=600,width=700,top=0,left=0, scrollbars,resizable';
	}
	obj['url']=getCoverageLink();
	return obj
}

// some teamsite pages have links with coverage pop-up (mostly aisles)
function doCoveragePop(obj){
	obj.href=getCoverageLink();
	return true
}


// generate the search box
function sprint_getSearchBox(){
   // ISearch should not be displayed for CustomAisles. The below code will take care of not showing ISearch
	if(nxVars.isCA){return "";}	
	//var iSearch=(nxVars.isProd?"http://search.sprint.com/inquiraapp/ui.jsp":"http://search.dev.sprint.com/inquiraapp/ui.jsp");
	var iSearch="http://search.sprint.com/inquiraapp/ui.jsp";
	var iUserStatus="prospect";
	var iUserSite="onlinestore";
	var icharSetES="iso-8859-1";
	var iLang="en-US";
	var searchButton=nxVars.hVars.assetBase+"/assets/images/common/buttons/bt-iSearch_en.gif";
	if(nxVars.lang=='es'){
				iLang="es-ES";
				iUserSite="spanish";
				icharSetES="iso-8859-1";
				searchButton=nxVars.hVars.assetBase+"/assets/images/common/buttons/bt-iSearch_es.gif";
	}
	
	if(nxVars.isCA){
		iSearch="/NASApp/onlinestore/Action/DisplaySearchResults?question_box=";
		iUserSite="aisles";
	}else{
		if(nxVars.isProd){
			if(nxVars.lang=='es'){
				iSearch="http://search.sprint.com/inquiraapp_spanish/ui.jsp";				
			}
		//If the host is L&P Environment
		}else if(nxVars.isLnPTest) {
			if(nxVars.lang=='es'){
				iSearch="http://search.test.sprint.com/inquiraapp_spanish/ui.jsp";				
			}
		//Other then prod and l&p environments
		}else{
			if(nxVars.lang=='es'){
				iSearch="http://search.test.sprint.com/inquiraapp_spanish/ui.jsp";				
			}
		}
	}
	var msg='';
	
	// Added the below lines to use the new Search look and feel to display on the masthead
	msg+='<div class="clearer"></div><form id="shellSearch" action="'+iSearch+'" method="get" name="question_form">'+_NL;
	msg+='<div id="searchDiv">'+_NL;
	msg+='<input type="hidden" name="ui_mode" value="question" />'+_NL;
	msg+='<input type="hidden" name="charset" value="'+icharSetES+'" />'+_NL; 
	msg+='<input type="hidden" name="language" value="'+iLang+'" />'+_NL; 
	msg+='<input type="hidden" name="aisleToken" value="" />'+_NL; 
	msg+='<input type="hidden" name="user.status" value="'+(nxVars.isLoggedIn?'customer':'prospect')+'" />'+_NL; 
	msg+='<input type="hidden" name="user.site" value="'+iUserSite+'" />'+_NL; 
	msg+='<label id="shellSearchLabel" for="shellSearchField">Search</label>'+_NL;
	msg+='<input id="shellSearchField" name="question_box" type="text" maxlength="52" onclick="clearSearch(this)" value="'+nxVars.hVars.langItems['search_instr']+'" name="shellSearchField"/>'+_NL;
	msg+='<input id="shellSearchButton" type="image" alt="Search" src="'+searchButton+'" alt="'+nxVars.hVars.langItems['search_alt']+'"/>'+_NL;
	msg+='</div>'+_NL;
		
	if(nxVars.lang=='es'){
		msg+='<span>'+nxVars.hVars.langItems['lang_toggle']+'</span>'+_NL;
	}
	msg+='</form>\x0A';
	return msg
}

// function called to clear the search box on initial click	
function clearSearch(obj){
	if(obj.value==nxVars.hVars.langItems['search_instr']){
		obj.value='';
	}
}



// DEPRECATED, utility bar no longer exists
function renderUtilityBar(){return ""};
// backwards compatibility
var nx_setUserLoginStatus=sprint_setUserLoginStatus;

/* run all of the set-up functions */
function sprint_headerSetUp(){
	sprint_doNPI()
	sprint_getCookieVars();
	sprint_setUpAudience();
	sprint_setUpLanguage();
	sprint_setUserLoginStatus();
	sprint_setUpManageAccount();
	sprint_setHeaderLinks();
	if(nxVars.isCA){
		sprint_setUpCustomAisles();
	}
}

sprint_headerSetUp();
sprint_getDefinitionFiles();

