nxVars.commonCookieName='nxcommon';
nxVars.defaultExperienceType=2; // default user experience type for A/B/T
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
    
    // logged in user info
    userProfile:{
        firstName:"",  // user first name 
        lastName:"",  // user last name
        nameStr:''  // output string for logout 
    },  
    showCAName:true
};

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"
        }
    });
    
// 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.aisleToken=isValidText(Object.hasProperty(spCookies,'cookieValue','nolCustomAisleToken'))?Object.hasProperty(spCookies,'cookieValue','nolCustomAisleToken').strip():null;
    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");

	nxVars.isEPPP=(nxVars.aisleToken=="eEwnRLV7Wr38IqnRYJHIPG8SSvI");
	
	tmp=Object.hasProperty(spCookies,'cookieValue','EXP_COOKIE');
	nxVars.experienceType=nxVars.isCA?1:(isValidText(tmp)?parseInt(tmp):nxVars.defaultExperienceType);
	
	tmp=Object.hasProperty(spCookies,'cookieValue','hasCart');
	nxVars.accOnlyCartCookie=(nxVars.experienceType==2&&tmp=='true');

}

// 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='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

}
//******************************
// 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;
    }
}





// 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=""; 
    var 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 tab bar
    out+=sprint_renderFullNav(hTab,linkTarget);
    return out;
}


function sprint_renderFullNav(hTab,targ){
    
    var out='<div class="sprint"><div class="content"><div class="header" id="masthead">';
    out+='<div id="navUtility"><ul>';
    var showAll=$if(hTab,'!=','&&','-5','-3','-1');
    var showTabs=$if(hTab,'!=','&&','-5','-4','-3','-2','-1');
    if(showAll){
        // generate top nav links
        out+=sprint_generateNavLinkList('primary',targ);
        // generate search box
        if(showTabs){
            out+='<li>'+sprint_getSearchBox()+'</li>';
        }
    }
    out+='</ul></div>';
    // start tabs
    // URL base defined in nav_def.js
    var logoSrc= '<img src="'+nxVars.hVars.headImgBase+'logo_sprint_nav.gif" id="logo" alt="Sprint" />';
    // -5 means unlink the logo
    if(hTab!=-5){
        logoSrc = '<a href="'+nxVars.hLinks.home+'?INTNAV=LEG:HE:Logo" target="'+targ+'">'+logoSrc+'</a>';
    }
    
    out+=logoSrc+_NL;
    out+='<div id="navWrapper"><div id="navInnerWrapper"><ul id="navGlobal">'+_NL;
    if(showTabs){
        var allowedTabs=[];
        nxVars.tabs.forEach(function(val,key){
            // check if the tab is allowed for the audience and for the aisle (if applicable)
            if(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+'"':'';    
                allowedTabs[nxVars.tabs[key].order]=key;
            }
        });
        allowedTabs.normalize();
        var tabOutput=[];
            for(var x=0; x<allowedTabs.length; x++){
            var prop={
                first:false,
                last:false,
                selected:false
                
            };
            if(x==0){
                prop.first=true;
            }
            if(x==allowedTabs.length-1){
                prop.last=true;
            }
            if(hTab==allowedTabs[x] || hTab==nxVars.tabs[allowedTabs[x]].selectNumber){
                prop.selected=true;
            }
            tabOutput[nxVars.tabs[allowedTabs[x]].order]=sprint_renderSingleTab(nxVars.tabs[allowedTabs[x]],targ,prop);
        };
        out+=tabOutput.join(_NL+_NL);
    }
    else{
        out+='<li class="topLevel first"><span class="empty">&nbsp;</span></li>';
    }
    if((nxVars.isCA)&&(nxVars.hVars.showCAName)&&(location.pathname!='/NASApp/onlinestore/Action/DisplayAisleLanding')){
        nxVars.CAName=(nxVars.CAName!=false)?decodeURIComponent(nxVars.CAName):'Sprint';
        out+='<li id="customAisle">'+nxVars.CAName+' Private Store</li>';
    }
    out+='</ul></div></div></div></div></div>'+_NL;
    return out;
}


function sprint_renderSingleTab(obj,targ,prop){
    obj.mice='';
    if(bis.ie){
        obj.mice='onmouseenter="sprintLegacyNav.doIEMouseEnter(this)" onmouseleave="sprintLegacyNav.doIEMouseLeave(this)"';
    }
    else{
        obj.mice='onmouseover="sprintLegacyNav.doMouseOver(this)" onmouseout="sprintLegacyNav.doMouseOut(this)"';
    }
    obj.cls="topLevel";
    obj.corner='';
    if(prop.first){
        obj.cls+=' first';
        obj.corner='<span id="bottomLeftCornerSelected"></span>';
    }
    if(prop.last){
        obj.cls+=' last';
    }
    if(prop.selected){
        obj.cls+=' selected';
    }
    var tabtpl='<li id="<=domId=>" class="<=cls=>" <=mice=>><a href="<=url=>" target="<=target=>" <=popup=>> <=display=> <=corner=></a><=genSubNav=></li>';
    if(prop.subNav){
        obj.subNav=prop.subNav;
    }   
    obj.genSubNav='';
    
    var snav=sprint_generateNavLinkList(obj.subNav,targ);
    if(snav!=''){
        obj.genSubNav='<ul class="subNav">'+_NL+snav+'</ul>';
    }
    return tabtpl.template(obj);
    
}

// sub nav bar functions
function renderSubNavBar(navID, targ){
    if(navID){
        if(navID=='purchase'){
            var nd=$css('#'+nxVars.tabs['shop'].domId+' ul.subNav')[0];
            if(nd){
                nxVars.subNavItems["shop"].forEach(function(v,k){
                    switch(k){
                        case 'cov': var nd=$(v.domId);
                                        if(nd){
                                            nd.addClass('first'); 
                                        }
                                        break;
                        case 'cart': break;
                        default: var nd=$(v.domId);
                                    if(nd){
                                        nd.toggleOff(); 
                                    }
                                    break;
                    
                    }
                
                })
                //nd.setHTML(sprint_generateNavLinkList('purchase',targ));
            }
            
        }
        else{
            nxVars.subNavItems.forEach(function(v,k){
                v.forEach(function(val,key){
                    if(navID===key){
                        var nd=$(val.domId);
                        if(nd){
                            nd.$t('a').addClass('selected');
                        }
                    }
                });
            });
        }
    }
    sprintLegacyNav.setup();
    return '';
}


// generates the HTML for a sub-nav group (includes utility links and footer)
function sprint_generateNavLinkList(links,targ){
    if(!nxVars.subNavItems[links]){
        return '';
    }
    var linkTemplate='<li class="<=cls=>" <=iid=>><a href="<=url=>" class="<=lnkCls=>" target="<=linkTarget=>" <=pop=> <=doAccOnlyClick=>><=text=></a></li>'+_NL;
    var noLinkTemplate='<li class="<=cls=>" <=iid=>><=text=></li>'+_NL;
    var sObj=new Object();
    var showFirst=true;
    var barStr = '';
    var sItems=[];
    var iItems=[];
    
    // count how many valid links there are in the subset
    nxVars.subNavItems[links].forEach(function(val,key){
        if(key=='labelId'||(nxVars.isEPPP&&(key=="upg"))){return}
        if(sprint_check20Status(val)&&sprint_checkLinkAisleStatus(val)&&sprint_checkIndividualAvailable(val)){
            iItems[val.order]=key;
        }
    });     
    iItems.normalize();
    // for each link in set 
    iItems.forEach(function(v,k){
        var val=nxVars.subNavItems[links][v];
        var key=v;
        //remove upgrades from eppp aisle
        // check audience, aisle, hybrid filter status
        if(sprint_check20Status(val)&&sprint_checkLinkAisleStatus(val)&&sprint_checkIndividualAvailable(val)){
            sObj.text=val.label;
            val=sprint_getRealHeaderLink(val);    
			sObj.doAccOnlyClick=val.doAccOnlyClick;			
            sObj.url=val['url'];
            sObj.iid="";
            // set the ID of the item if it has one
            if(val['domId']){
                sObj.iid='id="'+val['domId']+'"';           
            }
            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':'';
            sObj.cls="";
            // if first item in list, remove the pipe to the left (add class "first")
            if(k==0){
                sObj.cls='first';
            }
            else if(k==iItems.length-1){
            // if last item in the list, set the class to "last"
                sObj.cls="last";
            }
            //sObj.pop='';  
            sItems[val.order]=(sObj.url!=null)?linkTemplate.template(sObj):noLinkTemplate.template(sObj);
        }
    });
    barStr+=sItems.join(' ');
//  barStr += ''    
    return barStr;
}

function sprint_check20Status(val){
	return (nxVars.experienceType==2)?val.hasKey('show20')?val.show20:true:true;
}

function sprint_checkIndividualAvailable(val){
	return !(false===val.individual && !nxVars.isCA);
}

// 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;
}

// 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 out='<div class="clearer"></div><div class="sprint"><div class="content"><div class="footerBase">';
    // sitemap
    out+='<ul id="footerActions">'+_NL;
    if(!nxVars.isCA){
        out+='<li><a href="'+nxVars.sprintServerUrl+nxVars.siteMapLinkURL+'?INTNAV=SJS:FT:Sitemap" id="siteMapLink">'+nxVars.siteMapLabel+'</a></li>'+_NL;
    }
    out+='</ul>';
    
    // footer links
    out+='<ul id="navFooter">';
    if(!nxVars.isCA){
        out+='<li>'+nxVars.orderByPhoneLabel+' 1-866-866-7509</li>';
    }
    if($if(fOpt,'!=','&&','-1',-1)){
        out+=sprint_generateNavLinkList("footer",targ);
    }
    out+='</ul><p>&copy; '+(new Date).getFullYear()+' Sprint. '+nxVars.copyrightText+'</p>';
    // 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)){
            out+='<p class="customAisleFooter">'+fn+'</p>';
        }
    }
    
//Omniture 2.0 code
    if(location.href.toLowerCase().indexOf('nasapp/onlinestore') < 0){
        if(location.href.toLowerCase().indexOf('/en/promotions/') >= 0 || location.href.toLowerCase().indexOf('/en/services/') >= 0 || 
                    location.href.toLowerCase().indexOf('/en/solutions/') >= 0 || location.href.toLowerCase().indexOf('/en/support/') >= 0 || 
                        location.href.toLowerCase().indexOf('/en/software_downloads/') >= 0 || location.href.toLowerCase().indexOf('/en/accessories/') >= 0 || 
                            location.href.toLowerCase().indexOf('/en/shop/') >= 0  || location.href.toLowerCase().indexOf('/en/about/') >= 0 ||
                                location.href.toLowerCase().indexOf('/en/contact_us/') >= 0 || location.href.toLowerCase().indexOf('/en/coverage/') >= 0 ||
                                    location.href.toLowerCase().indexOf('/en/decorations/') >= 0 || location.href.toLowerCase().indexOf('/en/gps/') >= 0 ||
                                        location.href.toLowerCase().indexOf('/en/landings/') >= 0 || location.href.toLowerCase().indexOf('/en/legal/') >= 0 ||
                                            location.href.toLowerCase().indexOf('/en/misc/') >= 0 || location.href.toLowerCase().indexOf('/en/my_sprint/') >= 0 ||
                                                location.href.toLowerCase().indexOf('/en/mynextel/') >= 0 || location.href.toLowerCase().indexOf('/en/stores/') >= 0 ||
                                                    location.href.toLowerCase().indexOf('/en/wlnp/') >= 0 || location.href.toLowerCase().indexOf('/personal/wireless/order_status') >= 0){
            out+= '<script type="text/javascript" >'+_NL;
            out+= 'Analytics = new Object;Analytics.MetricData = {};'+_NL;
            out+= 'Analytics.MetricData.appId = "eComStore";'+_NL;
            out+= 'Analytics.currentEnvironmentTest = "test";'+_NL;
            var cenv='test';
            var csrc='';
            if(location.hostname.toLowerCase()!="shop2.sprint.com"){
                out+= 'Analytics.currentEnvironmentTest = "dev";'+_NL;
                cenv='dev';
            }
            if(location.hostname.toLowerCase()=="shop2.sprint.com"){
                out+= 'Analytics.currentEnvironmentTest = "prod";'+_NL;
                cenv='prod';
            }
            switch(cenv){
                case "dev": out+= 'Analytics.MetricData.currentHost = "ee.test.sprint.com";'+_NL;
                            out+= 'Analytics.MetricData.environment ="dev";'+_NL;
                            csrc='ee.test.sprint.com';
                            break;
                case "test":    out+= 'Analytics.MetricData.currentHost = "nolbf.sprint.com";'+_NL;
                                out+= 'Analytics.MetricData.environment ="test";'+_NL;
                                csrc='nolbf.sprint.com';
                                break;
                case "prod":    out+= 'Analytics.MetricData.currentHost = "shop2.sprint.com";'+_NL;
                                out+= 'Analytics.MetricData.environment ="prod";'+_NL;
                                csrc='shop2.sprint.com';
                                break;
            }
            out+= 'Analytics.MetricData.action=location.href;'+_NL;
            out+= '</script>'+_NL;
            out+='<script type="text/javascript" src="//'+csrc+'/assets/scripts/analytics/analyticsFramework.js"></script>'+_NL;
                            
        }
    }
    //*****************end Omniture2.0
    else if(nxVars.doOmniture){
        out+='<div id="omnitureDiv"></div><scr'+'ipt type="text/javascript" src="'+nxVars.hVars.assetBase+nxVars.omnitureSrc+'"></scr'+'ipt>'
    }
    //*****************end Omniture2.0
    sprintLegacyNav.setup();
    out+='</div></div></div>';
    return out;
}

function renderinQFooter(fOpt, targ){
    var inQlnk='';
    if(!nxVars.isCA || nxVars.aisleToken=='EMa48RRo2om5iBIOxNKTUeUG9I8'){
        inQlnk='<div id="inQDiv"><scr'+'ipt type="text/javascript" src="http'+((nxVars.hVars.secureServer)?'s':'')+'://sprint.inq.com/chatskins/launch/inqChatLaunch154.js"></scr'+'ipt>'+_NL;
        inQlnk+='<scr'+'ipt type="text/javascript" src="'+nxVars.hVars.assetBase+'/assets/scripts/inq/inq_omniture.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){
	val.doAccOnlyClick='';
    if(nxVars.experienceType==2){
		if(val.url2){
			val.url=val.url2;
		}
		if(nxVars.accOnlyCartCookie==true && false !== val.show20Warning){
			val.doAccOnlyClick='onclick="return sprint_do20AccessoryOnlyClick(this)"';
		}
	}
	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;
}


var sprint20WarningDialog=null;
function sprint_close20WarningDialog(){
	sprint20WarningDialog.remove();
};
 
function sprint_do20AccessoryOnlyClick(e){
	var href=e.href;
	sprint20WarningDialog=new widgets.dialog({id:'sprint20WarningModal',className:'optModal',backingClass:'modalBacker',css:'position:absolute; z-index:1000; width:450px;',autoClose:true},true,false);
	var shell='<div class="modalContent">'+_NL;
	shell+='	<div class="inner">'+_NL;
	shell+='		<div class="aRight"><a href="javascript:void sprint_close20WarningDialog();" class="actionBox">Close X</a>'+_Clearer+'</div>'+_NL;
	shell+='		<div id="betaModalContent" style="padding:20px; width:400px; position:relative;">'+_NL;
	shell+='			<p>By leaving this page, you will lose any accessories in your cart.  Are you sure you wish to leave?</p>'+_NL;
	shell+='			<div style="padding:10px; text-align:center;"><a href="'+href+'" style="float:left; margin-right:10px;"><img src="/assets/images/common/buttons/bt_yl_yes_v1_en.gif" alt="yes" /></a><a href="javascript:void sprint_close20WarningDialog()" style="float:left; margin-right:10px;"><img src="/assets/images/common/buttons/bt_yl_no_v1_en.gif" alt="no" /></a></div>'+_NL;
	shell+=_Clearer+_NL;
	shell+='		</div>'+_NL;
	shell+='	</div>'+_NL;
	shell+='</div>';
	
	sprint20WarningDialog.setContent(shell);
	$(sprint20WarningDialog.backer.id).setOpacity(70);
	sprint20WarningDialog.center();
	sprint20WarningDialog.show();
	return false;
}

    
//  returns the appropriate set of sub-nav and footer links based on audience, custom aisle, and custom aisle suppression flag
//
function sprint_getNavLinkList(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.experienceType==1){
		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.sprint.com":"http://coveragetest.test.sprint.com");
    var page=((!pop) && (!nxVars.isCA)?"/IMPACT.jsp":"/IMPACTnobrand.jsp");
    var retProt=(nxVars.thirdParty?'':"http://");
    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",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);
        }
    }
	url.addParam('INTNAV','LEG:HE:Cov');
    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=nxVars.searchUrl+"/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.isCA){
        iSearch="/NASApp/onlinestore/Action/DisplaySearchResults?question_box=";
        iUserSite="aisles";
    }
    var msg='';
    
    // Added the below lines to use the new Search look and feel to display on the masthead
    msg+='<form id="frmSearch" name="frmSearch" action="'+iSearch+'" method="get" name="question_form">'+_NL;
    msg+='<fieldset><button id="btnSearchGo" type="submit" value="Go">Go</button><label for="txtSearch">Search</label>';
    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+='<input id="txtSearch" name="question_box" type="text" maxlength="52"  name="shellSearchField"/>'+_NL;
    msg+='</form>'+_NL;
    return msg;
}



var sprintLegacyNav={
        doIEMouseEnter:function(el){
            sprintLegacyNav.unsetPermNode(el);
            if(bis.v<7){
                $(el).addClass('over');
            }               
        },
        doIEMouseLeave:function(el){
            sprintLegacyNav.resetPermNode(el);
            if(bis.v<7){
                $(el).removeClass('over');
            }
        },
        doMouseOver:function(el){
            sprintLegacyNav.unsetPermNode(el);
        },
        doMouseOut:function(el){
            sprintLegacyNav.resetPermNode(el);
        },
        unsetPermNode:function(el){
            if(sprintLegacyNav.permNode===null){
                sprintLegacyNav.getPermNode(el);
            }
            if(sprintLegacyNav.permNode!==''){
                $(sprintLegacyNav.permNode).removeClass('selected');
            }
        },
        resetPermNode:function(el){
            if(sprintLegacyNav.permNode===null){
                sprintLegacyNav.getPermNode(el);                
            }
            if(sprintLegacyNav.permNode!==''){
                $(sprintLegacyNav.permNode).addClass('selected');
            }
        },
        getPermNode:function(el){
            
            var p=el.parentNode;
            var ch=p.childNodes;
            var ln=ch.length;
            for(var x=0; x<ln; x++){
                if(ch[x].nodeType===1){
                    if(ch[x].className.match(/(^|\s)(selected)(\s|$)/)!=null){
                        sprintLegacyNav.permNode=$(ch[x]);
                        return;
                    }
                }
            }
            sprintLegacyNav.permNode='';
        },
        positionSubs:function(){
            var nav=$('navGlobal');
            if(nav){
                var ch=nav.childNodes;
                var mWid=0;
                for(var x=0; x<ch.length; x++){
                    if(ch[x].nodeType===1){ 
                        if(document.defaultView){
                            var d=document.defaultView.getComputedStyle(ch[x],null);
                            mWid+=Math.round(parseFloat(d.getPropertyValue('width')));
                        }
                        else{
                            mWid+=ch[x]["offsetWidth"];
                        }
                    }
                }
                
                for(var x=0; x<ch.length; x++){
                    if(ch[x].nodeType===1){
                        var wid=ch[x]["offsetWidth"];
                        var left=ch[x]["offsetLeft"];
                        var sNav=$(ch[x].getElementsByTagName('ul')[0]);
                        if(sNav){
                            var sWid=sNav["offsetWidth"];
                            if(bis.ie && bis.v<7){
                                var nds=sNav.getElementsByTagName('li');
                                sWid=0;
                                for(var y=0; y<nds.length; y++){
                                    sWid+=parseInt(nds[y]['offsetWidth']);
                                }
                                sNav.style.width=sWid+'px';

                            }
                            if(sWid>mWid||left==0||sWid>(left+wid)){
                                sNav.style.left=0;
                            }       
                            if((mWid-(wid+left)<left && sWid<mWid)){
                                sNav.style.left=(mWid-sWid)+'px';
                            }
                            
                            
                        }                       
                    }
                }
            }
        },
        setup:function(){
            if(!sprintLegacyNav.isSetUp){
                if(/WebKit/i.test(navigator.userAgent)){
                    document.addEventListener('DOMContentLoaded',sprintLegacyNav.positionSubs,false);
                    window.addEventListener('load',sprintLegacyNav.positionSubs,false);
                }
                else{
                    sprintLegacyNav.positionSubs();
                }   
                sprintLegacyNav.isSetUp=true;
			
            }
        },
        permNode:null,
        isSetUp:false
    };

// DEPRECATED, utility bar no longer exists
function renderUtilityBar(){return ""};
// backwards compatibility
var nx_setUserLoginStatus=sprint_setUserLoginStatus;

// calculates the base url for other assets (images/scripts etc) by grabbing the base server of this file as it is included on the page.
function sprint_getAssetServer(){
    var scr=document.getElementsByTagName('script');
    var ts="";
    var match='/assets/scripts/nx_header.js';
    for(var x=0; x<scr.length; x++){
        if(scr[x].src && scr[x].src.indexOf(match)>-1){
            ts=scr[x].src.replace(match,'');
        }
    }
    nxVars.headerAssetServer=ts;
    // removed for release B
    // nxVars.definitionFiles.path= nxVars.headerAssetServer+nxVars.definitionFiles.path;
    
    // set the base path for non-header specific assets to the headerBaseUrl
    nxVars.hVars.assetBase = nxVars.headerAssetServer;
    nxVars.hVars.headImgBase=nxVars.hVars.assetBase+nxVars.headImgPath;
};


/* run all of the set-up functions */
function sprint_headerSetUp(){
    sprint_doNPI();
    sprint_setupTabItems();
    sprint_setupSubNavItems();
    sprint_setupNavExtras();
    sprint_getAssetServer();
    sprint_getCookieVars();
    sprint_setUpAudience();
    sprint_setUpLanguage();
    sprint_setUserLoginStatus();
    //sprint_setUpManageAccount();
    sprint_setHeaderLinks();
    if(nxVars.isCA){
        sprint_setUpCustomAisles();
    }
    Events.inQ('DOMLoad',sprintLegacyNav.setup);
    
}

sprint_headerSetUp();


var sprintBetaDialog=null;
function sprint_closeBetaDialog(){
	sprintBetaDialog.remove();
};
function sprint_doBetaOpt(type){
	sprintBetaDialog=new widgets.dialog({id:'betaOptModal',className:'optModal',backingClass:'modalBacker',css:'position:absolute; z-index:1000;',autoClose:true},true,false);
	var shell='<div class="modalContent">'+_NL;
	shell+='	<div class="inner">'+_NL;
	shell+='		<div class="aRight"><a href="javascript:void sprint_closeBetaDialog();" class="actionBox">X</a>'+_Clearer+'</div>'+_NL;
	shell+='		<div id="betaModalContent">'+_NL;
	shell+='<=content=>'+_NL;
	shell+='		</div>'+_NL;
	shell+='	</div>'+_NL;
	shell+='</div>';
	var obj={};
	obj.content=sprintBetaContent[type];
	try{
		Analytics._numeric_.omni.trackOptInOutModal(type);
	}catch(e){}

	sprintBetaDialog.setContent(shell.template(obj));
	$(sprintBetaDialog.backer.id).setOpacity(70);
	sprintBetaDialog.center();
	sprintBetaDialog.show();
};

var betaVideoDialogModal=null;
function sprint_closeBetaVideoModal(){
	betaVideoDialogModal.remove();
}
function sprint_doBetaVideos(){
	betaVideoDialogModal=new widgets.dialog({id:'betaVideoDialogId',className:'optModal',backingClass:'modalBacker',css:'position:absolute; z-index:200; width:880px; background-color:#fff;',autoClose:true},true,false);
	var src=nxVars.storeServerUrl+'/assets/olsvideo/mediaPlayer.html?&selectedDeviceId=NEWSTORE1234&VideoName=Add%20device&VideoID=0';
	var shell='<div class="modalContent">'+_NL;
	shell+='	<div class="inner">'+_NL;
	shell+='		<div class="aRight"><a href="javascript:void sprint_closeBetaVideoModal();" class="actionBox">X</a>'+_Clearer+'</div>'+_NL;
	shell+='		<div id="betaModalContent">'+_NL;
	shell+='			<iframe name="FRAME1" src="'+src+'" width="860" height="650" frameborder="0" scrolling="no" ></iframe>';
	shell+='		</div>'+_NL;
	shell+='	</div>'+_NL;
	shell+='</div>';
	betaVideoDialogModal.setContent(shell);
	betaVideoDialogModal.center();
	if(betaVideoDialogModal.y < document.documentElement.scrollTop){
		betaVideoDialogModal.moveTo(betaVideoDialogModal.x,parseInt(document.documentElement.scrollTop+2));
	}
	betaVideoDialogModal.show();
};


function sprint_doBetaFeedback(){
	try{
		Analytics._numeric_.omni.trackBetaSurveys('RelC_CSATLink');
	}catch(e){}
};

function sprint_doBetaProblem(){
	try{
		Analytics._numeric_.omni.trackBetaSurveys('RelC_Problem');
	}catch(e){}
};

Events.inQ('DOMLoad',function(){
	// disabling in prod temporarily in case of accidental deployment
	//if(!nxVars.isProd){
	//
	if(!nxVars.isCA){
		if($('hBeta1')){
			if(nxVars.experienceType==1){
				$('hBeta1').toggleOn();
			}
			else{
				$('hBeta2','hBeta3','hBeta4').toggleOn();
			}
		}
	}
	// end prod disable
	//}
	//
});


var sprintBetaContent={};
// start opt-in content
sprintBetaContent.optin='<div class="clearfix sprint content">'+_NL;
sprintBetaContent.optin+='<h3>Want to try our new store?</h3>'+_NL;
sprintBetaContent.optin+='<div class="moduleDefault">'+_NL;
sprintBetaContent.optin+='<p>We\'ve updated our online store and are in the process of moving customers into it. You can shop in the new store today by clicking "Yes, I\'ll try the new store" below.</p>'+_NL;
sprintBetaContent.optin+='<p>You\'ll get the same online offers, free activation, free shipping and fast delivery that you\'ve come to expect from Sprint.com - plus a ton of new features to make your shopping easier.</p>'+_NL;

sprintBetaContent.optin+='<h5>Can I come back?</h5>'+_NL;
sprintBetaContent.optin+='<p>You can exit at any time by clicking "About our new store" at the top of any page. You\'ll see links to give us feedback, report a problem, and return to this version of the store. </p>'+_NL;
sprintBetaContent.optin+='<h5>What about my shopping cart?</h5>'+_NL;
sprintBetaContent.optin+='<p>Your shopping cart is specific to the version of the store you\'re visiting. If you have items in your shopping cart now, you\'ll have to start over in our new store. </p>'+_NL;
sprintBetaContent.optin+='<div class="betaButtons"><a onclick="doOptIn()" href="#" class="button1_converted"><img src="'+nxVars.headerAssetServer+'/assets/images/common/buttons/bt_yl_try_the_beta_store_v2.gif" alt="Try the Beta Store" /></a> <a onclick="sprint_closeBetaDialog()" href="#" class="button2_converted"><img src="'+nxVars.headerAssetServer+'/assets/images/common/buttons/bt_bk_no_thanks_v2.gif" alt="No thanks" /></a> </div>'+_NL;
sprintBetaContent.optin+='<div class="clearer"></div>'+_NL;
sprintBetaContent.optin+='</div>'+_NL;
sprintBetaContent.optin+='</div>'+_NL;

// start opt-out content
sprintBetaContent.optout='';
sprintBetaContent.optout='<div class="clearfix sprint content" style="width: 640px;">'+_NL;
sprintBetaContent.optout+='<h3>About our new store</h3>'+_NL;
sprintBetaContent.optout+='<div class="moduleDefault">'+_NL;
sprintBetaContent.optout+='<p>Our new store launch has begun! We hope you enjoy our new and improved features, including:</p>'+_NL;
sprintBetaContent.optout+='<p><strong>-- A robust phone filter</strong> - narrow down your choices by more than 40 features including price, style, operating system and more.</p>'+_NL;
sprintBetaContent.optout+='<p><strong>-- Side-by-side phone and plan comparisons.</strong> If you\'re a customer, sign in and see how new phones compare to the one you have, and whether they\'ll work with your existing plan.</p>'+_NL;
sprintBetaContent.optout+='<p><strong>-- Special features only for customers</strong> Sign in and see how easy it is to change your plan, add a phone or a new line, add or remove services, and more.</p>'+_NL;

sprintBetaContent.optout+='<h5>Tell us what you think</h5>'+_NL;
sprintBetaContent.optout+='<p>Experience a problem? Let us know by taking a short <a href="javascript:sprint_doBetaProblem();">feedback survey</a>.</p>'+_NL;
sprintBetaContent.optout+='<h5>If you miss the old store ...</h5>'+_NL;
sprintBetaContent.optout+='<p>For a limited time, you can go back. Click "Leave the new store" below to exit for this visit.</p>'+_NL;
sprintBetaContent.optout+='<div class="betaButtons"><a onclick="doOptOut()" href="#" class="button1_converted"><img src="'+nxVars.headerAssetServer+'/assets/images/common/buttons/bt_yl_leave_beta_store_v2.jpg" alt="Leave the beta store" /></a> <a onclick="sprint_closeBetaDialog()" href="#" class="button2_converted"><img src="'+nxVars.headerAssetServer+'/assets/images/common/buttons/bt_bl_keep_using_beta_store_v2.jpg" alt="Keep using the beta store" /></a> </div>'+_NL;
sprintBetaContent.optout+='</div>'+_NL;
sprintBetaContent.optout+='</div>'+_NL;

dwl('<script src="'+nxVars.hVars.assetBase+'/assets/scripts/store/beta.js"></script>');


