
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/helpPortal" };
globalNavItems[9] = { name: "Get&nbsp;There", server: "www", href: "start_membership.html" };


/*
globalNavItems["Home"] = { server: "webapps", href: "therecentral/there_central.xml" };
globalNavItems["People"] = { server: "webapps", href: "profiles/people-search.xml" };
globalNavItems["Places"] = { server: "webapps", href: "places/places.xml" };
globalNavItems["Activities"] = { server: "webapps", href: "activities/activities.xml" };
globalNavItems["Shop"] = { server: "webapps", href: "catalog/product?category=1000000001" };
globalNavItems["Auctions"] = { server: "webapps", href: "items/home" };
globalNavItems["Groups"] = { server: "webapps", href: "clubs/clubs" };
globalNavItems["Forums"] = { server: "forums", href: "" };
globalNavItems["Help"] = { server: "webapps", href: "help/helphome.xml" };
globalNavItems["Get&nbsp;There"] = { server: "www", href: "start_membership.html" };
*/
//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 writeGlobalNavLinks()
{
        var home = document.getElementById( "globalNav_Home" );
        var people = document.getElementById( "globalNav_People" );
        var places = document.getElementById( "globalNav_Places" );
        var activities = document.getElementById( "globalNav_Activities" );
        var shop = document.getElementById( "globalNav_Shop" );
        var auctions = document.getElementById( "globalNav_Auctions" );
        var groups = document.getElementById( "globalNav_Groups" );
        var forums = document.getElementById( "globalNav_Forums" );
        var help = document.getElementById( "globalNav_Help" );
        var hostname;

        if (home)
        {
           hostname = getCluster( globalNavItems["Home"].server );
           home.href = hostname + globalNavItems["Home"].href;
        }

        if (people)
        {
           hostname = getCluster( globalNavItems["People"].server );
           people.href = hostname + globalNavItems["People"].href;
        }

        if (places)
        {
           hostname = getCluster( globalNavItems["Places"].server );
           places.href = hostname + globalNavItems["Places"].href;
        }

        if (activities)
        {
           hostname = getCluster( globalNavItems["Activities"].server );
           activities.href = hostname + globalNavItems["Activities"].href;
        }

        if (shop)
        {
           hostname = getCluster( globalNavItems["Shop"].server );
           shop.href = hostname + globalNavItems["Shop"].href;
        }

        if (auctions)
        {
           hostname = getCluster( globalNavItems["Auctions"].server );
           auctions.href = hostname + globalNavItems["Auctions"].href;
        }

        if (groups)
        {
           hostname = getCluster( globalNavItems["Groups"].server );
           groups.href = hostname + globalNavItems["Groups"].href;
        }

        if (forums)
        {
           hostname = getCluster( globalNavItems["Forums"].server );
           forums.href = hostname + globalNavItems["Forums"].href;
        }

        if (help)
        {
           hostname = getCluster( globalNavItems["Help"].server );
           help.href = hostname + globalNavItems["Help"].href;
        }
}

function writeGlobalNav( selected, disableTherecentralLinks, d )
{
  //navStr  = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
  var t = document.createElement( 'table' );
  t.cellspacing = "0";
  t.cellpadding = "0";
  t.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>";
  var tr1 = document.createElement( 'tr' );

  var td1 = document.createElement( 'td' );
  td1.colspan = 99;
  td1.setAttribute( 'style', 'background-color:#929292' );

  var i1 = document.createElement( 'img' );
  i1.src = "/newcommon/media/clear.gif";
  i1.width = 0;
  i1.height = 0;
  i1.border = 0;
  //td1.appendChild( i1 );

  tr1.appendChild( td1 );

  t.appendChild( tr1 );

  //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>";
  var tr2 = document.createElement( "tr" );

  var td2 = document.createElement( "td" );
  td2.setAttribute( 'style', 'padding-left:0px;padding-right:10px;border-right:1px solid #666666' );
  td2.className = 'globalNav';

  var i2 = document.createElement( "img" );
  i2.src = "/newcommon/media/clear.gif";
  i2.width = 0;
  i2.height = 0;
  i2.border = 0;

  //td2.appendChild( i2 );

  tr2.appendChild( td2 );

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

    var td2a = document.createElement( "td" );
    td2a.verticalAlign = "top";
    var a2 = document.createElement( "a" );

    if( selected == globalNavItems[i].name && !disableTherecentralLinks ) {
      td2a.style.backgroundImage = "url( /newcommon/media/nav_selected.gif )";
      a2.href = hostName + globalNavItems[i].href;
      a2.className = "globalNavSel";
      a2.appendChild(document.createTextNode(globalNavItems[i].name));
      //navStr += "<td style=\"background-image:url( /newcommon/media/nav_selected.gif )\"><a href=\"" + hostName + globalNavItems[i].href + "\" class=\"globalNavSel\">" + globalNavItems[i].name + "</a></td>";
    } else if( selected != globalNavItems[i].name && !disableTherecentralLinks ) {
      td2a.setAttribute( "style", "background-image:url( '/newcommon/media/nav_bg.gif' )" );
      a2.href = hostName + globalNavItems[i].href;
      a2.className = "globalNav";
      a2.innerHTML = globalNavItems[i].name;
      //navStr += "<td style=\"background-image:url( /newcommon/media/nav_bg.gif )\"><a href=\"" + hostName + globalNavItems[i].href + "\" class=\"globalNav\">" + globalNavItems[i].name + "</a></td>";
    } else if( selected == globalNavItems[i].name && disableTherecentralLinks ) {
      td2a.setAttribute( "style", "background-image:url( /newcommon/media/nav_bg.gif )" );
      a2.href = hostName + globalNavItems[i].href;
      a2.className = "globalNavSel";
      a2.innerHTML = globalNavItems[i].name;
      //navStr += "<td style=\"background-image:url( /newcommon/media/nav_bg.gif )\"><a href=\"" + hostName + globalNavItems[i].href + "\" class=\"globalNavSel\">" + globalNavItems[i].name + "</a></td>";
    } else if( disableTherecentralLinks ) {
      td2a.setAttribute( "style", "background-image:url( /newcommon/media/nav_bg.gif )" );
      a2.className = "globalNavDisabled";
      a2.innerHTML = globalNavItems[i].name;
      //navStr += "<td style=\"background-image:url( /newcommon/media/nav_bg.gif )\"><a class=\"globalNavDisabled\">" + globalNavItems[i].name + "</a></td>";
    }

    td2a.appendChild( a2 );
    tr2.appendChild( td2a );
  }

  //navStr += "<td class=\"globalNav\" style=\"float:left;border-left:1px solid #CCFFFF;border-right:0px;padding-left:0px;width:184px\"></td></tr>";
  var td2b = document.createElement( "td" );
  td2b.setAttribute( "style", "float:left;border-left:1px solid #CCFFFF;border-right:0px;padding-left:0px;width:184px" );
  td2b.className = 'globalNav';

  tr2.appendChild( td2b );

  t.appendChild( tr2 );


  //navStr += "<tr><td colspan=\"99\" style=\"background-color:#929292\"><img src=\"/newcommon/media/clear.gif\" width=\"0\" height=\"0\" border=\"0\"/></td></tr>";
  var tr3 = document.createElement( "tr" );

  var td3 = document.createElement( "td" );
  td3.colspan = 99;
  td3.setAttribute( "style", "background-color:#929292" );

  var i3 = document.createElement( "img" );
  i3.src = "/newcommon/media/clear.gif";
  i3.width = 0;
  i3.height = 0;
  i3.border = 0;
  //td3.appendChild( i3 );

  tr3.appendChild( td3 );

  t.appendChild( tr3 );

  //navStr += "<tr><td colspan=\"99\" style=\"background-color:#A1B4B8\"><img src=\"/newcommon/media/clear.gif\" width=\"0\" height=\"0\" border=\"0\"/></td></tr>";
  var tr4 = document.createElement( "tr" );

  var td4 = document.createElement( "td" );
  td4.colspan = 99;
  td4.setAttribute( "style", "background-color:#A1B4B8" );

  var i4 = document.createElement( "img" );
  i4.src = "/newcommon/media/clear.gif";
  i4.width = 0;
  i4.height = 0;
  i4.border = 0;
  //td4.appendChild( i4 );

  tr4.appendChild( td4 );

  t.appendChild( tr4 );

  // navStr += "<tr><td colspan=\"99\" style=\"background-color:#C8DFE4\"><img src=\"/newcommon/media/clear.gif\" width=\"0\" height=\"0\" border=\"0\"/></td></tr>";
  var tr5 = document.createElement( "tr" );

  var td5 = document.createElement( "td" );
  td5.colspan = 99;
  td5.setAttribute( "style", "background-color:#C8DFE4" );

  var i5 = document.createElement( "img" );
  i5.src = "/newcommon/media/clear.gif";
  i5.width = 0;
  i5.height = 0;
  i5.border = 0;
  //td5.appendChild( i5 );

  tr5.appendChild( td5 );

  t.appendChild( tr5 );

  //d.appendChild( t );

document.getElementById(d).appendChild(t);


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

  //document.write( navStr );

  //if(!(typeof(om_cl) == "undefined")) setupOmitXsl();

}
//

function isLocalhost()
{
  return ( document.domain.indexOf( "localhost" ) != -1 ||
           document.domain.indexOf( "127.0.0.1" ) != -1 ) ? true : false;
}

function returnLocalhost()
{
  if( document.domain.indexOf( "localhost" ) != -1 )
  {
    return "http://localhost.thereinc.com/";
  }
  else if( document.domain.indexOf( "127.0.0.1" ) != -1 )
  {
    return "http://127.0.0.1/";
  }
}

function getCluster( server )
{
  var currentDomain = document.domain;
  if( isLocalhost() == true )
    return returnLocalhost();
  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 ) {
    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()
{
  return getCookie( 'av' );
}

//
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: "/eventmgmt/fulltextsearch?Fulltext=" };
globalSearchOptions[1] = { category: "People", action: "/listings/listings?Type=12&Filter=12&PageSize=20&Stylesheet=/profiles/people-search-results.xsl&Fulltext=" };
globalSearchOptions[2] = { category: "Groups", action: "/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: "/eventmgmt/eventmgmt?op=search2&StyleSheet=activity_happening_now.xsl&EventTypeSearchString=20" };
globalSearchOptions[4] = { category: "Library", action: "/listings/listings?Type=17&Filter=17&PageSize=20&Stylesheet=/theredoc/search_results.xsl&PatchSkills=AuthorId:15&Fulltext=" };
globalSearchOptions[5] = { category: "Auctions", action: "/items/fulltextsearch?Fulltext=" };
globalSearchOptions[6] = { category: "Funzones", action: "/funzone/funzone?op=search&type=funzone" };
globalSearchOptions[7] = { category: "Homes", action: "/funzone/funzone?op=search&requiresAssociatedClub=0&type=house" };
globalSearchOptions[8] = { category: "Clubhouses", action: "/funzone/funzone?op=search&requiresAssociatedClub=1&type=house" };
globalSearchOptions[9] = { category: "Neighborhoods", action: "/funzone/funzone?op=search&requiresAssociatedClub=0&type=neighborhood" };
globalSearchOptions[10]= { category: "Developments", action: "/funzone/funzone?op=search&requiresAssociatedClub=0&type=development" };

// now create the options list
function generateSearchOptions( selected, l )
{
  // document.writeln( "<select id=\"globalSearchCatSelect\" class=\"input\">" );
  for( var i = 0; i < globalSearchOptions.length; i++ ) {

    theSelect = document.getElementById(l);
    theSelect.options[i] = new Option(globalSearchOptions[i].category, globalSearchOptions[i].action, false, false);
    /*
    var o = document.createElement( "option" );
    o.name = globalSearchOptions[i].category;
    o.action = globalSearchOptions[i].action;
    if( selected == globalSearchOptions[i].category ) {
      o.selected = "true";
    }
    o.value = globalSearchOptions[i].category;
    o.text = globalSearchOptions[i].category;
    l.appendChild( o );
    */
  }

}
//
 function submitSearch()
{
        // variable initialization
        var globalSearchCategory      = "";
        var globalSearchAction        = "";
        var globalSearchField         = "";

        //get the selected catagory by looping through all the available catagories.
        //check to see if its selected; if so assign it to the variable.

        var globalSearchCatSelectList = ( document.getElementById( "catSelect" ));
        var index = 0;
        while(true) {
               if (globalSearchCatSelectList.options[index].selected) {
                    globalSearchCategory = globalSearchCatSelectList.options[index].text;
                    globalSearchAction = globalSearchCatSelectList.options[index].value;
                    break ;
                }
               else
                    index++;
        }
        //get the search text
        globalSearchField = document.getElementById( "globalSearchField" ).value;
        // we need to enfore the 3 char minimum on people and clubs searches
        if( globalSearchCategory == "People" || globalSearchCategory == "Clubs" ) {
            if (globalSearchField.length < 3 ) {
                var errorStr = 'Your search request must contain 3 characters or more. Please try again.';
                alert( errorStr );
                return;
            }
        }

        // 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" ) {
        globalSearchField = "";
        }

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

var liveHelpEnabled;

function checkLiveHelp()
{
  if ( liveHelpEnabled == "1" ) {
    var helpUrl = "http://live.there.com";
  } else {
    var helpUrl = "http://www.fuzeqna.com/makenasupport/consumer/question.asp";
  }
  var liveHelpWin = window.open( helpUrl );
}

function writeAvatarName( d )
{
//avatarNameStr = '<span class="gry9">Logged in as <a class="mdBlu9Bld" href="/profiles/profiles?op=edit">' + getAvatarName() + '</a>&#xa0;|&#xa0;<a class="mdBlu9" href="/login/login?logout">Logout</a></span>';
     var s = document.createElement( "span" );
s.className = "gry9";
var t = document.createTextNode( "Logged in as " );
s.appendChild( t );
var a = document.createElement( "a" );
a.className = "mdBlu9Bld";
a.href = "/profiles/profiles?op=edit" + getAvatarName();
a.innerHTML = getAvatarName();
s.appendChild( a );
var t1 = document.createTextNode( "\xA0|\xA0" );
s.appendChild( t1 );
var a1 = document.createElement( "a" );
a1.className = "mdBlu9";
a1.href = "/login/login?logout";
a1.innerHTML = "Logout";
s.appendChild( a1 );
d.appendChild( s );
//document.write( avatarNameStr );
}
