var current_sub_menu;
function onNew( arg_item, arg_extra )
{
	var url = arg_item + ".php?action=new";
	if ( arg_extra )
		url += "&" + arg_extra;
	window.location.href = url;
}

function confirm_logout()
{
        input_box=confirm("Are you sure you wish to log out?");
        if(input_box==true)
        {
                window.location="?method=logout";
        }
}

function on_switch_accounts()
{
	var list = document.getElementById( 'account_list' );
	var input = document.getElementById ( 'switch_accounts' );
	var frm = document.getElementById ( 'formSwitchAccounts' );
	if ( list && input && frm )
	{
		var value = list.options[ list.options.selectedIndex ].value;
		input.value = value;
		frm.submit();
	}
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

var bSubMenuActive = false;
function setSubMenuActive( bActive )
{
	bSubMenuActive = bActive;
	if( !bActive )
	{
		var milliseconds = 100;
		setTimeout( "OnSubMenuMouseOut()", milliseconds );
	}
}

function OnSubMenuMouseOut()
{
	if( !bSubMenuActive )
	{
		current_sub = hideSubMenus();
		if ( current_sub_menu == null )
			current_sub_menu = current_sub;
		if ( current_sub_menu )
			current_sub_menu.style.display = 'inline';
	}
}

function displaySubMenu( type )
{
	var current_sub;
	current_sub = hideSubMenus();
	if ( current_sub_menu == null )
		current_sub_menu = current_sub;
	var div_id = "sub_menu_" + type;
	var selected = document.getElementById( div_id );
	if( selected != null )
		selected.style.display = 'inline';
}

function hideSubMenus()
{
	var div_id;
        var selected;
	var last_selected_menu;
        var types = new Array();
        types[ 0 ] = 'listings';
        types[ 1 ] = 'vm';
        types[ 2 ] = 'rec';
        types[ 3 ] = 'acc';
	types[ 4 ] = 'works';
	types[ 5 ] = 'learn';
	types[ 6 ] = 'support';
	types[ 7 ] = 'aff';
	types[ 8 ] = 'marketing';
        for( var i in types )
        {
                div_id = 'sub_menu_' + types[ i ];
                selected = document.getElementById( div_id );
                if( selected != null )
		{
			if ( selected.style.display == 'inline' )
			    last_selected_menu = selected;
         		selected.style.display = 'none';
		}
        }
	return last_selected_menu;
}

function onIndexHover( idx )
{
	var div;
	var div_id;
	var img = document.getElementById( 'home_arrow' );
	var img_src;
	var img_1 = document.getElementById( 'home_image_1' );
	var img_2 = document.getElementById( 'home_image_2' );
	var img_3 = document.getElementById( 'home_image_3' );
	for( var i = 1; i <= 3; i++ )
	{
		div_id = "div_home_content_" + i;
		div = document.getElementById( div_id );
		if( div != null )
			div.style.display = 'none';
	}
	switch( idx )
	{
		case 1:
			div = document.getElementById( 'div_home_content_1' );
			img_src = 'images/home_arrow_left.gif';
			img_1.src = 'images/homepage1.gif';
			img_2.src = 'images/homepage2_out.gif';
			img_3.src = 'images/homepage3_out.gif';
			break;
		case 2:
			div = document.getElementById( 'div_home_content_2' );
			img_src = 'images/home_arrow_mid.gif';;
                        img_1.src = 'images/homepage1_out.gif';
                        img_2.src = 'images/homepage2.gif';
                        img_3.src = 'images/homepage3_out.gif';
			break;
		case 3:
			div = document.getElementById( 'div_home_content_3' );
			img_src = 'images/home_arrow_right.gif';;
                        img_1.src = 'images/homepage1_out.gif';
                        img_2.src = 'images/homepage2_out.gif';
                        img_3.src = 'images/homepage3.gif';
			break;
		default:
			div = null;
			img_src = null;
	}
	if( div != null )
		div.style.display = 'inline';
	if( img_src != null && img != null )
		img.src = img_src;
}

function OnRegAccountTypeChange( arg_key )
{
	var radio;
	if( arg_key != null )
	{
		radio = document.getElementById( 'reg_acct_type_' + arg_key );
		if( radio )
		{
			radio.click();
		}
		return;
	}
}

function OnClickRegAcctType( acct_type )
{
	var tdSingle = document.getElementById( "tdAcctTypeSingle" );
	var tdTeam = document.getElementById( "tdAcctTypeTeam" );
	var tdBroker = document.getElementById( "tdAcctTypeBroker" );
	var divSingle = document.getElementById( "divAcctTypeSingle" );
	var divTeam = document.getElementById( "divAcctTypeTeam" );
	var divBroker = document.getElementById( "divAcctTypeBroker" );

	switch( acct_type )
	{
		case 'single':
			tdSingle.style.fontWeight = "bold";
			tdTeam.style.fontWeight = "normal";
			tdBroker.style.fontWeight = "normal";
			divSingle.style.display = "block";
			divTeam.style.display = "none";
			divBroker.style.display = "none";
			break;
		case 'team':
			tdSingle.style.fontWeight = "normal";
                        tdTeam.style.fontWeight = "bold";
                        tdBroker.style.fontWeight = "normal";
                        divSingle.style.display = "none";
                        divTeam.style.display = "block";
                        divBroker.style.display = "none";
                        break;
		case 'broker':
			tdSingle.style.fontWeight = "normal";
                        tdTeam.style.fontWeight = "normal";
                        tdBroker.style.fontWeight = "bold";
                        divSingle.style.display = "none";
                        divTeam.style.display = "none";
                        divBroker.style.display = "block";
                        break;
	}
}
