/**********************************************************************************************************
 * BASE OF ALL URLS
 **********************************************************************************************************/

var strBaseUrl = "http://www.tjx.com/";

/**********************************************************************************************************
 * GLOBAL STYLESHEETS
 **********************************************************************************************************/

var aryStyleSheets = new Array();
/** aryStyleSheets.push("css/styles_topnav.css");
aryStyleSheets.push("css/styles_main.css");
aryStyleSheets.push("css/styles_footer.css"); **/

/**********************************************************************************************************
 * GLOBAL JAVASCRIPT FILES
 **********************************************************************************************************/

var aryJavascriptFiles = new Array();

aryJavascriptFiles.push("js/prototype.js");
aryJavascriptFiles.push("js/effects.js");
aryJavascriptFiles.push("js/accordion.js");
aryJavascriptFiles.push("js/util.js");
aryJavascriptFiles.push("js/swfobject.js");

/**********************************************************************************************************
 * IE6 SPECIFIC JAVASCRIPT FILES
 **********************************************************************************************************/

var aryLessThankIE7JsFiles = new Array();
aryLessThankIE7JsFiles.push("js/ie7.js");
/*aryLessThankIE7JsFiles.push("js/pngfix.js");*/


/**********************************************************************************************************
 * MAIN NAVIGATION
 **********************************************************************************************************/
var aryTopNavItems = new Array();

var arySubLinks1 = new Array();
arySubLinks1.push(new objLink("about_history.asp", "Our History"));
var objTopLink1 = new objLink("about.asp", "About Us");
aryTopNavItems.push(new objTopNavItem(objTopLink1, arySubLinks1, "About Us"));

var arySubLinks2 = new Array();
arySubLinks2.push("In the U.S.");
arySubLinks2.push(new objLink("businesses_tjmaxx.asp", "T.J. Maxx"));
arySubLinks2.push(new objLink("businesses_marshalls.asp", "Marshalls"));
arySubLinks2.push(new objLink("businesses_homegoods.asp", "HomeGoods"));
arySubLinks2.push(new objLink("businesses_ajwright.asp", "A.J Wright"));
arySubLinks2.push("In Canada");
arySubLinks2.push(new objLink("businesses_winners.asp", "Winners"));
arySubLinks2.push(new objLink("businesses_homesense_canada.asp", "HomeSense"));
arySubLinks2.push(new objLink("businesses_stylesense_canada.asp", "STYLESENSE"));
arySubLinks2.push("In Europe");
arySubLinks2.push(new objLink("businesses_tkmaxx.asp", "T.K. Maxx"));
arySubLinks2.push(new objLink("businesses_homesense_europe.asp", "HomeSense"));
var objTopLink2 = new objLink("businesses.asp", "Our Businesses");
aryTopNavItems.push(new objTopNavItem(objTopLink2, arySubLinks2, "Our Businesses"));

var arySubLinks3 = new Array();
arySubLinks3.push("Company Information");
arySubLinks3.push(new objLink("investor_introduction.asp", "TJX &quot;101&quot;"));
arySubLinks3.push(new objLink("about_history.asp", "Our History"));
arySubLinks3.push(new objLink("investor_presentations.asp","Company Presentations"));
arySubLinks3.push(new objLink("http://www.businesswire.com/portal/site/tjx/", "Press Releases"));
arySubLinks3.push(new objLink("investor_annualreports.asp", "Annual Reports"));
arySubLinks3.push(new objLink("http://ir.10kwizard.com/files.php?source=487", "SEC Filings"));
arySubLinks3.push(new objLink("investor_reconciliation.asp","Reconciliation of Financials"));
/*arySubLinks3.push(new objLink("investor_histcomp.asp", "Historical Comparable Sales"));*/
arySubLinks3.push("Investor Services");

arySubLinks3.push(new objLink("investor_calendar.asp", "Reporting Calendar"));
arySubLinks3.push(new objLink("investor_analystcoverage.asp", "Analyst Coverage"));
arySubLinks3.push(new objLink("investor_stocksplit.asp", "Stock Split History"));
arySubLinks3.push(new objLink("investor_holderszerocoupon.asp", "Investor Notices"));
arySubLinks3.push(new objLink("investor_contacts.asp","Investor Contacts"));
var objTopLink3 = new objLink("investor.asp", "Investor Information");
aryTopNavItems.push(new objTopNavItem(objTopLink3, arySubLinks3, "Investor Information"));

var arySubLinks4 = new Array();
arySubLinks4.push(new objLink("corporate_governance.asp", "Corporate Governance"));
arySubLinks4.push(new objLink("corporate_guidelines.asp", "Key Guidelines for Associates"));
arySubLinks4.push(new objLink("corporate_vendor.asp", "Vendor Social Compliance"));
arySubLinks4.push(new objLink("corporate_environmental.asp", "Environmental Responsibility"));
arySubLinks4.push(new objLink("corporate_leverage.asp", "Leveraging Differences"));
arySubLinks4.push(new objLink("corporate_community.asp", "Community Support"));
var objTopLink4 = new objLink("corporate.asp", "Corporate Responsibility");
aryTopNavItems.push(new objTopNavItem(objTopLink4, arySubLinks4, "Corporate Responsibility"));

var arySubLinks5 = new Array();

var arySubSubLinks1 = new Array();
arySubSubLinks1.push(new objLink("http://www.careers-tjx.com/tjx/jobboard/listjobs.aspx", "List Jobs"));
arySubSubLinks1.push(new objLink("http://www.careers-tjx.com/tjx/jobboard/canlogin.aspx?__RT=NewCandidateExt.aspx", "Update Profile"));
arySubLinks5.push(new objLink("careers_jobs.asp", "Employment Opportunities", arySubSubLinks1));

var arySubSubLinks2 = new Array();
arySubSubLinks2.push(new objLink("careers_merchandising_trainingprogram.asp", "Corporate Merchandising Training Program"));
arySubSubLinks2.push(new objLink("careers_college_internships.asp", "Internships"));
arySubSubLinks2.push(new objLink("careers_college_campusevents.asp", "Campus Events"));
arySubLinks5.push(new objLink("careers_college.asp", "College Recruitment", arySubSubLinks2));

arySubLinks5.push(new objLink("careers_military.asp", "Military Recruitment"));
arySubLinks5.push(new objLink("careers_benefits.asp", "Benefits and Amenities"));

var arySubSubLinks3 = new Array();
arySubSubLinks3.push(new objLink("businesses.asp", "Our Businesses"));
arySubSubLinks3.push(new objLink("careers_life_culture.asp", "Culture"));
arySubSubLinks3.push(new objLink("corporate_leverage.asp", "Leveraging Differences"));
arySubSubLinks3.push(new objLink("corporate_community.asp", "Community Support"));
arySubLinks5.push(new objLink("careers_life.asp", "Life at TJX", arySubSubLinks3));

var arySubSubLinks4 = new Array();
arySubSubLinks4.push(new objLink("careers_merchandising_trainingprogram.asp", "Corporate Merchandising Training Program"));
arySubSubLinks4.push(new objLink("careers_merchandising_faq.asp", "Frequently Asked Questions"));
arySubSubLinks4.push(new objLink("careers_merchandising_offpriceretailing.asp", "What is Off-Price Retailing?"));
arySubSubLinks4.push(new objLink("http://www.careers-tjx.com/tjx/jobboard/JobDetails.aspx?__ID=*F2CD1302510E0A75", "Apply Here"));
arySubLinks5.push(new objLink("careers_merchandising.asp", "Merchandising Careers", arySubSubLinks4));

arySubLinks5.push(new objLink("careers_merchandising_relocating.asp", "Relocating to Massachusetts"));
arySubLinks5.push(new objLink("careers_mediaroom.asp", "Media Room"));

var objTopLink5 = new objLink("careers.asp", "Careers");
aryTopNavItems.push(new objTopNavItem(objTopLink5, arySubLinks5, "Careers"));

var arySubLinks6 = new Array();
arySubLinks6.push(new objLink("contact_corpheadquarters.asp", "Corporate Headquarters"));
arySubLinks6.push(new objLink("contact_locator.asp", "Store Locator"));
var objTopLink6 = new objLink("contact.asp", "Contact us");
aryTopNavItems.push(new objTopNavItem(objTopLink6, arySubLinks6, "Contact us"));

/**********************************************************************************************************
 * FOOTER
 **********************************************************************************************************/

var aryFooterLinks = new Array();
aryFooterLinks.push("&copy; 2009 The TJX Companies, Inc. All rights reserved.");
aryFooterLinks.push(new objLink("legal.asp", "Terms of Use"));
aryFooterLinks.push(new objLink("privacy.asp", "Privacy"));
aryFooterLinks.push(new objLink("https://www.mytjx.com/mytjx/associates.html", "For Associates"));
aryFooterLinks.push(new objLink("https://www.mytjx.com/mytjx/supplier.html", "Not-for-Resale Suppliers"));


/*********************************************************************************************************
 * HTML Utility functions
 *********************************************************************************************************/

function renderTop(strCurrentSection, strCurrentPage)
{
  renderStyleSheets();
  renderScriptTags();
  
  if(navigator.userAgent.indexOf("MSIE 6") > -1)
    renderLessThanIE7Code();
    
  renderTopWrapperOpen();
  renderTopNav(strCurrentSection);
  document.write("<div id='interior_content' class='cover'>");
  
  renderSubNav(strCurrentSection, strCurrentPage);
  document.write("<div id='right_content'>");
}

function renderBottom(strCurrentSection, strCurrentPage)
{
  document.write("</div></div><div id='content_bottom'></div>");
  renderFooter()
  renderTopWrapperClose();
 
  if(navigator.userAgent.indexOf("MSIE 7") > -1)  
  {
    var topnav = $("topnav"); 
    topnav.update(topnav.innerHTML);
  }
}

function renderStyleSheets()
{
  
    for(var i=0; i < aryStyleSheets.length; i++)
      document.write(buildStyleSheetLinkTag(aryStyleSheets[i]));
}


function renderScriptTags()
{
    for(var i=0; i < aryJavascriptFiles.length; i++)
      document.write(buildScriptTag(aryJavascriptFiles[i]));
}


function renderLessThanIE7Code()
{
  var arySb = new Array();
  arySb.push("<style type='text/css'> body { behavior:url(/csshover.htc); }</style>");
  
  for(var i = 0; i < aryLessThankIE7JsFiles.length; i++)
      arySb.push(buildScriptTag(aryLessThankIE7JsFiles[i]));

  document.write(arySb.join(""));
}

function renderTopWrapperOpen()
{
  document.write("<div id='first_wrapper'><div id='second_wrapper'><div id='wrapper'>");
}

function renderTopWrapperClose()
{
    document.write("</div></div></div>");
}

function renderTopNav(strCurrentSection)
{
	var arySbHTML = new Array();
	arySbHTML.push("<div id='topnav'><a href='" + strBaseUrl + "default.asp'><img id='logo' src='" + strBaseUrl + "images/tjx_logo.png' width='171' height='56' /></a>");
	arySbHTML.push("<div id='mainNav'><ul>");

	for(var i = 0; i < aryTopNavItems.length; i++)
	{
		var objNavItem = aryTopNavItems[i];
    
		var strNavSectionIdActive = (strCurrentSection.toLowerCase() == objNavItem.CurrentSectionKey.toLowerCase() ? " id='navSectionActive'" : "");
		var strClassLast = (j  == aryTopNavItems.length - 1 ? " class='last'" : "");
    
		arySbHTML.push("<li" + strNavSectionIdActive + strClassLast + ">" + convertObjLinkToHTML(objNavItem.TopLink));
	
		if(objNavItem.SubLinks.length > 0)
		{
			if(navigator.userAgent.indexOf("MSIE 6") > -1)  
				arySbHTML.push("<iframe></iframe>");
			
			arySbHTML.push("<ul>");
		}
		
		var bIsFirstLink = true;

		for(var j = 0; j < objNavItem.SubLinks.length; j++)
		{
			var objSub = objNavItem.SubLinks[j];
			var strCssClass = "";
			var bIsString = typeof(objSub) == "string";

			var strInnerHTML = "";

			if(bIsString)
			{
				strCssClass = " class='gray'";
				strInnerHTML = objSub;
			}
			else 
			{
				if(bIsFirstLink)
				{
					strCssClass = " class='firstmenuitem'";
					bIsFirstLink = false;
				}

				strInnerHTML = convertObjLinkToHTML(objSub);
			}

			arySbHTML.push("<li" + strCssClass + ">" + strInnerHTML + "</li>");
		}

		if(objNavItem.SubLinks.length > 0)
		{
			arySbHTML.push("<li class='bottom'></li>");
			arySbHTML.push("</ul>");
		}

		arySbHTML.push("</li>");
	}

	arySbHTML.push("</ul></div></div>");
	document.write(arySbHTML.join(""));
}

function renderSubNav(strCurrentSection, strCurrentPage)
{
  
    var objSection = null;
    
    for(var i = 0; !objSection && i < aryTopNavItems.length; i++)
    {
        if(aryTopNavItems[i].CurrentSectionKey.toLowerCase() == strCurrentSection.toLowerCase())
          objSection = aryTopNavItems[i];
    }
    
    document.write("<div id='left_nav'>");

    if(objSection)
    {
      if(typeof(objSection.SubLinks[0]) == "string")
        renderOurBusinessesTypeSubNav(objSection, strCurrentSection, strCurrentPage);
     else
        renderAccordionSubNav(objSection, strCurrentSection, strCurrentPage);
    }
    else
      document.write("&nbsp;");
      
    document.write("</div>");
    
}

function renderOurBusinessesTypeSubNav(objSection, strCurrentSection, strCurrentPage)
{
  

  var arySb = new Array();
  arySb.push("<p class='ourbusinesses'{0}>".replace("{0}", ( objSection.CurrentSectionKey.toLowerCase() == strCurrentPage.toLowerCase() ? " class='active'" : ""  )));
  arySb.push(convertObjLinkToHTML(objSection.TopLink));
  arySb.push("</p>");
  
  arySb.push("<ul class='ourbusinesses'>")
  
  for(var i = 0; i < objSection.SubLinks.length; i++)
  {
    var strLiClass = "";
    var strLiInnerHTML = "";
    
    if(typeof(objSection.SubLinks[i]) == "string")
    {
      strLiClass = " class='gray'";
      strLiInnerHTML = objSection.SubLinks[i];
    }
    else
    {
      var bIsActive = objSection.SubLinks[i].Text.toLowerCase() == strCurrentPage.toLowerCase();
      var bIsLastLink = i == objSection.SubLinks.length - 1;
      
      if(bIsActive && bIsLastLink)
      {
        strLiClass = " class='active lastmenuitem'";
      }
      else if(bIsActive)
        strLiClass = " class='active'";
      else if(bIsLastLink)
        strLiClass = " class='lastmenuitem'";
      
      strLiInnerHTML = convertObjLinkToHTML(objSection.SubLinks[i]);
    }
    
      arySb.push("<li{0}>".replace("{0}", strLiClass))
      arySb.push(strLiInnerHTML);
      arySb.push("</li>");
      
  }
  
  arySb.push("</ul>")
  document.write(arySb.join(""));
}

function renderAccordionSubNav(objSection, strCurrentSection, strCurrentPage)
{
  var arySb = new Array();
  arySb.push("<p{0}>".replace("{0}", (objSection.CurrentSectionKey.toLowerCase() == strCurrentPage.toLowerCase() ? " class='active'" : ""  )));
  arySb.push(convertObjLinkToHTML(objSection.TopLink));
  arySb.push("</p>");
  arySb.push("<div id='vertical_container'>");
  
  var open_index;
  var current_menu_item_index;

  if(objSection.hasSubLinks())
  {

    for(var i=0; i < objSection.SubLinks.length; i++)
    {
        var lnk = objSection.SubLinks[i];

        var strClasses = "vertical_accordion_toggle";
        
        var aryChildHTML = new Array();
        
        if(!lnk.hasSubLinks())
        {
            strClasses += " noarrow";
            
            if(lnk.Text.toLowerCase() == strCurrentPage.toLowerCase())
            strClasses += " highlighted";
        }
        
        if(!(i < objSection.SubLinks.length - 1))
          strClasses += " lastmenuitem";

        arySb.push("<h3 class='{0}'>{1}</h3>".replace("{0}", strClasses).replace("{1}", convertObjLinkToHTML(lnk)));
        
        arySb.push("<div class='vertical_accordion_content vertical_accordion_content_closed'>")
        renderAccordionSubNavChildren(aryChildHTML, lnk);
        
        var strHTML = aryChildHTML.join("");
        
        if(strHTML != "")
          arySb.push(strHTML);
        else
          arySb.push("<ul></ul>");
          
        arySb.push("</div>");
    }
  }
  else
    arySb.push("&nbsp;");
  
  
  arySb.push("</div>");
  
  document.write(arySb.join(""));
}

function renderAccordionSubNavChildren(aryHTML, lnk)
{

    if(lnk.hasSubLinks())
    {
      aryHTML.push("<ul>");
      
      for(var i=0; i < lnk.SubLinks.length; i++)
      {
        var lnkChild = lnk.SubLinks[i];
        aryHTML.push("<li>");
        aryHTML.push(convertObjLinkToHTML(lnkChild));
        renderAccordionSubNavChildren(aryHTML, lnkChild);
        aryHTML.push("</li>");
      }
      
      aryHTML.push("</ul>");
    }
}

function renderFooter()
{
  var arySb = new Array();
  arySb.push("<div id='footer'><ul>");
  
  for(var i=0; i < aryFooterLinks.length; i++)
  {
    if(typeof(aryFooterLinks[i]) != "string")
    {
      arySb.push("<li>");
      arySb.push(convertObjLinkToHTML(aryFooterLinks[i]));
    }
    else
    {
      arySb.push("<li id='copyright'>");
      arySb.push(aryFooterLinks[i]);
    }
      
    if(i > 0 && i < aryFooterLinks.length - 1)
      arySb.push("&nbsp;&nbsp;&nbsp;");
      
    arySb.push("</li>");
  }
  
  arySb.push("</ul></div>");
  document.write(arySb.join(""));
}


function buildScriptTag(strSrc)
{
    var strScript = "<script type='text/javascript' src='{0}'></script>";
    return strScript.replace("{0}", strBaseUrl + strSrc);
}

function buildStyleSheetLinkTag(strHref)
{
    var strHyperLink = "<link href='{0}' rel='stylesheet' type='text/css' />";
    return strHyperLink.replace("{0}", strBaseUrl + strHref);
}

function convertObjLinkToHTML(objLnk)
{
  if(objLnk && objLnk.Href && objLnk.Text)
    return strHyperLink.replace("{0}", objLnk.Href).replace("{1}",  objLnk.Text);
}


/**********************************************************************************************************
 * Objects
 **********************************************************************************************************/

function objLink(strHref, strText, arySubLinks)
{
	this.Href = (strHref.indexOf("http://") > -1 || strHref.indexOf("https://") > -1 ) ? strHref : strBaseUrl + strHref;
	this.Text = strText;
  this.SubLinks = arySubLinks;
}

objLink.prototype.hasSubLinks = 
function ()
{
  return (typeof(this.SubLinks) != "undefined" && this.SubLinks != null && this.SubLinks.length > 0);
}

function objTopNavItem(objTopLink, arySubLinks, strCurrentSectionKey)
{
	this.TopLink = objTopLink;
	this.SubLinks = arySubLinks;
  this.CurrentSectionKey = strCurrentSectionKey;
}

objTopNavItem.prototype.hasSubLinks = 
function ()
{
  return (typeof(this.SubLinks) != "undefined" && this.SubLinks != null && this.SubLinks.length > 0);
}


function objPopupLink(strHref, strText, strOptions)
{
  this.Href =  (strHref.indexOf("http://") > -1 || strHref.indexOf("https://") > -1 ) ? strHref : strBaseUrl + strHref;
	this.Text = strText;
  this.Options = strOptions;
}

objPopupLink.prototype.toHTML = 
function ()
{
  var strLinkFormat = "<a class='popup' href='{0}' options='{1}'>{2}</a>";
  
  if(typeof(this.Href != "undefined") && typeof(this.Text != "undefined") && this.Href != "" && this.Text != "")
  {
      var strOptions = "";
  
      if(typeof(this.Options) != "" && this.Options != "");
        strOptions = this.Options;
        
      return  strLinkFormat.replace("{0}", this.Href).replace("{1}", strOptions).replace("{2}", this.Text);
  }
  return "";
}

/**********************************************************************************************************
 * Global variables
 **********************************************************************************************************/
 
 var strHyperLink = "<a href='{0}'>{1}</a>";