/********************************************************************************
	This script is copyrighted by Orange Street Softare
		www.orangestreetsoftware.com
	
	It requires: 
		util.js

	The following <td> styles msut be defined:
		topmenu
********************************************************************************/

// ================================== GLOBAL VARIABLES ====================================================
// gloabl variable containg object with all menu setup information, 
// needs to be global within this script for event handlers (sorry)
var the_top_bar_container;

// these constants are indexes into the image_urls array in the container
var CI_TOP_BG_IMAGE = 0;

// ================================== UTITLITY FUNCTIONS ==================================================

// --------------------------------------------------------------------------------------------------------
// single point of call for all document writes (usefull for debuging etc.)
function top_bar_write ( s_text )
{

/*	debung stuff to show all tags as text
	s_text = s_text.replace ( /</g, "&lt;");
	s_text = s_text.replace ( />/g, "&gt;");
	document.writeln ( s_text + "<br>" );
*/
	if (the_top_bar_container.allow_render_caching)
	{
		if (!the_top_bar_container.is_cached)
			the_top_bar_container.render_cache = the_top_bar_container.render_cache + s_text;
	}
	else
		doc_write ( s_text );
}

// --------------------------------------------------------------------------------------------------------
// this is used to flush ot the cached top_bar_writes, 
// should be called afeter all other rendering code has finished, but before setup code
function top_bar_flush ()
{
	if (the_top_bar_container.allow_render_caching)
	{
		doc_write ( the_top_bar_container.render_cache );
		the_top_bar_container.is_cached = true;
	}
}

// ===================================== RENDERING FUNCTIONS ==============================================

// --------------------------------------------------------------------------------------------------------
// use this to draw the top bar, this will need to be called for each content page refresh
function render_top_bar ( the_container )
{
	// storing the menu setup object global to ease accessing metrics and urls
	//    er, sorry.
	the_top_bar_container = the_container;

	// make the rest of the menu bar	
	make_top_bar ();

	// flush the cached document writes if caching used
	top_bar_flush ();
}

// --------------------------------------------------------------------------------------------------------
// render out menu part of top bar
function make_top_bar ()
{
var n_item_index;

	// open div / layer
	if ( document.layers )
		top_bar_write ( '<layer name="topmenubg" pageY=0 pageX=0 height=69 width=780 z-index=1 visibility="show">' );
	else
		top_bar_write ( '<div id="topmenubg" style="position: absolute; top: 0px; left: 0px; height: 69px; width: 780px; z-index: 1; visibility: visible;">' );

	top_bar_write ( '<table cellspacing="0" cellpadding="0"><tr><td>' );
	
	// display the image
	top_bar_write ( '<img src="' + the_top_bar_container.image_urls + '" width=780 height=69>' );

	// finish table
	top_bar_write ( '</td></tr></table>' );
	
	// close div / layer
	if ( document.layers )
		top_bar_write ( '</layer>' );
	else
		top_bar_write ( '</div>' );


	// open div / layer
	if ( document.layers )
		top_bar_write ( '<layer name="topmenu" pageY=105 pageX=550 height=25 width=780 z-index=1 visibility="show">' );
	else
		top_bar_write ( '<div id="topmenu" style="position: absolute; top: 51px; left: 150px; height: 25px; width: 780px; z-index: 1; visibility: visible;">' );
		
	// make a table to display the image
	top_bar_write ( '<table border="0" cellspacing="0" cellpadding="0">' );
	//top_bar_write ( '<form name="rightbarform">' );
	top_bar_write ( '<tr><td style="color: white;">' );
	
	top_bar_write ( '<a href="http://www.goldenhandshake.co.za/money/default.asp" class="topmenuG" onclick=window.location.reload;><b>HOME</b></a>' );
	top_bar_write ( '&nbsp;<b>|</b>&nbsp;' );

	// loop thru the items in the top bar and make appropriate item tags
	for ( n_item_index = 0 ; n_item_index < the_top_bar_container.item_count ; n_item_index++ )
	{
		// dump out the hyperlinked item
		top_bar_write ( '<a href="javascript: the_top_bar_container.item_click (' + n_item_index.toString() + ');" class="topmenuG">' + the_top_bar_container.item_names[n_item_index] + '</a>' );
		top_bar_write ( '&nbsp;<b>|</b>&nbsp;' );
	}

	top_bar_write ( '</td><td class="whitebold">Go to another site:&nbsp;</td><td>' );
	top_bar_write ( '<select name="subsite" size="1" style="font-size: 7.5pt;" onchange="change(this.options[subsite.selectedIndex].value);">' );
	top_bar_write ( '<option value="-1" selected>Select Section:</option>' );
	
	// loop thru the items in the right bar and make appropriate item tags
	//for ( n_item_index = 0 ; n_item_index < the_top_bar_container.sub_site_count ; n_item_index++ )
	//{
		// dump out the hyperlinked item
		top_bar_write ( '<option value="http://www.goldenhandshake.co.za">GoldenHandShake</option>' );
		top_bar_write ( '<option value="http://www.financialsavvy.co.za">FinancialSavy</option>' );
		top_bar_write ( '<option value="http://www.secondlife.co.za">SecondLife</option>' );
		top_bar_write ( '<option value="http://www.domestichelp.co.za">DomesticHelp</option>' );
		top_bar_write ( '<option value="http://www.womensbiz.co.za">WomensBiz</option>' );
	//}

	// finish table
	top_bar_write ( '</select></form>' );
	top_bar_write ( '</td></tr></table>' );

	// close div / layer
	if ( document.layers )
		top_bar_write ( '</layer>' );
	else
		top_bar_write ( '</div>' );
}

// --------------------------------------------------------------------------------------------------------
function change(url_popup){
var url_popup_full;
//alert();
url_popup_full='"'+url_popup+'"';
window.open(url_popup);

}