var globalNavItems = new Array();
globalNavItems[0] = { name: "Home", server: "webapps", href: "therecentral/there_central.xml" };
globalNavItems[1] = { name: "People", server: "webapps", href: "profiles/people-search.xml" };
globalNavItems[2] = { name: "Places", server: "webapps", href: "places/places.xml" };
globalNavItems[3] = { name: "Activities", server: "webapps", href: "activities/activities.xml" };
globalNavItems[4] = { name: "Shop",  server: "webapps", href: "catalog/product?category=1000000001" };
globalNavItems[5] = { name: "Auctions", server: "webapps", href: "items/home" };
globalNavItems[6] = { name: "Groups", server: "webapps", href: "clubs/clubs" };
globalNavItems[7] = { name: "Forums", server: "forums", href: "" };
globalNavItems[8] = { name: "Help", server: "webapps", href: "scripts/help.py/helpPortal" };
globalNavItems[9] = { name: "Get&nbsp;There", server: "www", href: "download" };
globalNavItems[10] = { name: "Buy T$", server: "webapps", href: "banker/banker" };
//OMIT XSL
//This is a debug facility for every ThereCentral page.
//All you have to do is type omitXsl=1, just like that, into the window while it has focus, and you'll see a magic
//view of the XML as you would see when you refresh the page while *actually* omitting the XSL. (&omitXsl=1)
//With this method, you can have XML view *OR* XSL view, your choice. (includes XML close button)

//TODO:
//* support processing instructions and comments (outside of document element)
/*
function setupOmitXsl()
{
  //Load the ActiveX XML parsers.  Fail gracefully if errored.
  try
  {
    var source = new ActiveXObject("Msxml2.DOMDocument");
    var stylesheet = new ActiveXObject("Msxml2.DOMDocument");
  }
  catch(e)
  { return; } //No more soup for you!!!

  //Make a DIV.
  document.write("<div onresize='om_handleResize()' id='om_showXML' class='st' style='padding: 16px; z-index: 200; display: none; position: absolute; background-color: #ffffff; top: 0px; left: 0px; width: expression(document.body.clientWidth)'></div>");

  //Make it dynamic.
  document.all.om_showXML.onclick = om_cl;

  //Set no async so the XML parsers will block until loading completion.
  source.async = stylesheet.async = false;

  //Load the XML and XSL.  Fail gracefully if errored.
  try
  {
    source.loadXML(pageRootXML.xml);
    stylesheet.load("/common/defaultss.xsl");
  }
  catch(e) { return; } //No more soup for you!!!

  //Transform and output to DIV.
  document.all.om_showXML.innerHTML = source.transformNode(stylesheet);

  //Put in the close button.
  var om_closeBtnHTML = "<span style='padding: 3px; border: 2px solid black; cursor: hand; float: right; font-family: Arial; font-size: 14pt; font-weight: bold' onclick='om_closeXMLDisplay()'>Close XML Display</span>";
  document.all.om_showXML.innerHTML = om_closeBtnHTML + document.all.om_showXML.innerHTML;

  //Enable the key command trigger.
  document.attachEvent("onkeypress", om_hookKeypress);
}
*/

function writeGlobalNav( selected, disableTherecentralLinks )
{
  navStr  = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
  navStr += "<tr><td colspan=\"99\" style=\"background-color:#929292\"><img src=\"/common/media/clear.gif\" width=\"0\" height=\"0\" border=\"0\"/></td></tr>";
  navStr += "<tr><td class=\"globalNav\" style=\"padding-left:0px;padding-right:10px;border-right:1px solid #666666\"><img src=\"/common/media/clear.gif\" width=\"0\" height=\"0\" border=\"0\"/></td>";

  for( var i = 0; i < globalNavItems.length; i++ ) {
    hostName = getCluster( globalNavItems[i].server );

    if( selected == globalNavItems[i].name && !disableTherecentralLinks ) {
      navStr += "<td style=\"background-image:url( /common/media/nav_selected.gif )\"><a href=\"" + hostName + globalNavItems[i].href + "\" class=\"globalNavSel\">" + globalNavItems[i].name + "</a></td>";
    } else if( selected != globalNavItems[i].name && !disableTherecentralLinks ) {
            if (globalNavItems[i].name=="Buy T$"){
            navStr += "<td style=\"background-image:url( /common/media/nav_bg.gif )\"><a href=\"" + hostName + globalNavItems[i].href + "\" class=\"globalNav\" style='color=#ff4c33;'>" + globalNavItems[i].name + "</a></td>";
                }
            else {
              navStr += "<td style=\"background-image:url( /common/media/nav_bg.gif )\"><a href=\"" + hostName + globalNavItems[i].href + "\" class=\"globalNav\">" + globalNavItems[i].name + "</a></td>";
               }
    } else if( selected == globalNavItems[i].name && disableTherecentralLinks ) {
      navStr += "<td style=\"background-image:url( /common/media/nav_bg.gif )\"><a href=\"" + hostName + globalNavItems[i].href + "\" class=\"globalNavSel\">" + globalNavItems[i].name + "</a></td>";
    } else if( disableTherecentralLinks ) {
      navStr += "<td style=\"background-image:url( /common/media/nav_bg.gif )\"><a class=\"globalNavDisabled\">" + globalNavItems[i].name + "</a></td>";
    }

  }
  navStr += "</tr>";
  navStr += "</table>";

  document.write( navStr );

  //if(!(typeof(om_cl) == "undefined")) setupOmitXsl();
}
//
function getCluster( server )
{
  var currentDomain = document.domain;

  if( currentDomain.indexOf( "localhost" ) != -1 )
  {
    return "http://localhost.thereinc.com/";
  }
  else if( currentDomain.indexOf( "127.0.0.1" ) != -1 )
  {
    return "http://127.0.0.1/";
  }
  else if( currentDomain == "www.there.com" )
  {
    currentDomain = "www.prod.there.com";
  }
  currentDomain = currentDomain.split( "." );
  currentDomain[0] = server;
  currentDomain = currentDomain.join( "." );
  return "http://" + currentDomain + "/";
}

function createTextLink( tmpHref, tmpStr, tmpTarget, tmpClass )
{
  linkStr = '<a href=\"' + tmpHref + '\" target=\"' + tmpTarget + '\" class=\"' + tmpClass + '\">' + tmpStr + '</a>';
  document.write( linkStr );
}

function createImageLink( tmpHref, tmpImage, tmpTarget )
{
  linkStr = '<a href=\"' + tmpHref + '\" target=\"' + tmpTarget + '\"><img src=\"' + tmpImage + '\" border=\"0\"/></a>';
  document.write( linkStr );
}

//
function isCookieEnabled()
{
  if( document.all ) {
    return navigator.cookieEnabled;
  }
}

//
function getCookie( name )
{
  if( isCookieEnabled() ) {
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length +1;
    if(( start == -1 ) && ( name != document.cookie.substring( 0, name.length ))) {
      return null;
    }
    var end = document.cookie.indexOf( ";", len );
    if( end == -1 ) {
      end = document.cookie.length;
    }
    cookieValue = unescape( document.cookie.substring( len, end ))
    if( cookieValue ) {
      return cookieValue;
    }
  }
  return null;
}

//
function setCookie( name, value, expires )
{
  cookieStr = name
  document.cookie = name + "=" + escape( value ) + (( expires ) ? ";expires=" + expires : "" );
}

//
function getAvatarName()
{
  if( getCookie( 'tv' ) == 1 ) {
    return getCookie( 'av' );
  } else {
    return null;
  }
}

//
function getInWorldStatus()
{
  if( getCookie( 'tv' ) == 1 ) {
    if( getCookie( 'it' ) == getCookie( 'doid' )) {
      return true;
    } else {
      return false;
    }
  }
}

// set cookies here!
function setCookie( name, value, expires )
{
  cookieStr = name
  document.cookie = name + "=" + escape( value ) + (( expires ) ? ";expires=" + expires : "" );
}

// decalre search options and associated properties
var globalSearchOptions = new Array();
globalSearchOptions[0] = { category: "Activities",    action: getCluster('webapps') + "eventmgmt/fulltextsearch?Fulltext=" };
globalSearchOptions[1] = { category: "People",        action: getCluster('webapps') +  "listings/listings?Type=12&Filter=12&PageSize=20&Stylesheet=/profiles/people-search-results.xsl&Fulltext=" };
globalSearchOptions[2] = { category: "Groups",        action: getCluster('webapps') + "listings/listings?Type=7&PageSize=10&StylesheetSingle=/clubs/clubs_listing.xsl&Category=&MultiplePage=3&SinglePage=10&StylesheetMultiple=/clubs/clubs_listing_multiple.xsl&PatchName=LeaderDoid&PatchRestriction=Id&GroupCount=MembersGroupId&SortAscDate=Date&CategoryHier=All" };
globalSearchOptions[3] = { category: "Conversations", action: getCluster('webapps') + "eventmgmt/eventmgmt?op=search2&StyleSheet=activity_happening_now.xsl&EventTypeSearchString=20" };
globalSearchOptions[4] = { category: "Library",       action: getCluster('webapps') + "listings/listings?Type=17&Filter=17&PageSize=20&Stylesheet=/theredoc/search_results.xsl&PatchSkills=AuthorId:15&Fulltext=" };
globalSearchOptions[5] = { category: "Auctions",      action: getCluster('auctions') +  "items/fulltextsearch?Fulltext=" };
globalSearchOptions[6] = { category: "Places",        action: getCluster( 'webapps' ) + "zones/browse?Fulltext=" };
// now create the options list
function generateSearchOptions( selected )
{
  document.writeln( "<select id=\"globalSearchCatSelect\" class=\"input\">" );
  for( var i = 0; i < globalSearchOptions.length; i++ ) {
    optionStr = "<option name=\"" + globalSearchOptions[i].category + "\" action=\"" + globalSearchOptions[i].action + "\"";
    if( selected == globalSearchOptions[i].category ) {
      optionStr += "selected=\"true\"";
    }
    optionStr += ">" + globalSearchOptions[i].category + "</option>";
    document.writeln( optionStr );
  }
  document.writeln( "</select>" );
}
//
function submitSearch()
{
  var globalSearchCategory      = "";
  var globalSearchAction        = "";
  var globalSearchField         = "";

  var globalSearchCatSelectList = eval( document.getElementById( "globalSearchCatSelect" ));
  globalSearchIndex             = globalSearchCatSelectList.selectedIndex;
  globalSearchCategory          = globalSearchCatSelectList.options[globalSearchIndex].name;
  globalSearchAction            = globalSearchCatSelectList.options[globalSearchIndex].action;
  globalSearchField             = document.getElementById( "globalSearchField" ).value;

  // we need to enfore the 3 char minimum on people and Groups searches
  if(( globalSearchCategory == "People" || globalSearchCategory == "Groups" ) && globalSearchField.length < 3 ) {
    var errorStr = 'Your search request must contain 3 characters or more. Please try again.';
    alert( errorStr );
    return;
  }
  //if Groups is selected change some form element properties to return the proper xml to groups xsl
  if(globalSearchCategory == "Groups") {
    globalSearchAction += ("&Fulltext=" + escape( globalSearchField ));
    //set these args to "" so that listings will ignore them
    document.getElementById( "globalSearchField" ).value = "";
    globalSearchField = "";
  }
  // omit the value if one of these categories is selected
  // since they do not use keywords in a search
  if( globalSearchCategory == "Funzones" || globalSearchCategory == "Homes" || globalSearchCategory == "Clubhouses"
      || globalSearchCategory == "Neighborhoods" || globalSearchCategory == "Developments"  ) {
    globalSearchAction += ("&description=" + escape( globalSearchField ));
    //set these args to "" so that listings will ignore them
    document.getElementById( "globalSearchField" ).value = "";
    globalSearchField = "";
  }

  // make the request
  location.href = globalSearchAction + escape( globalSearchField );
}

var liveHelpEnabled;

function checkLiveHelp()
{
  var helpUrl = "http://live.there.com";
  var liveHelpWin = window.open( helpUrl );
}
