
//*********************************************************
//*
//* Executed immediately on load (bind events)
//*
//*********************************************************

MainLoadStatus = new Array(false); //nothing is loaded yet

MainReady = false;






//*********************************************************
//*
//* Public API
//*
//*********************************************************

//---------------------------------------------------------
//---------------------------------------------------------
function RegisterLoadedFrame(index, frame)
{
    //is this a frame refresh after main load? if so, ignore
    if (null == MainLoadStatus) {
        return;
    }
    
    //check if everything is loaded
    if (MainLoadStatus[index]) {
        throw "Houston, we have a problem.";
    }
    MainLoadStatus[index] = true;
    for (var i = MainLoadStatus.length; i-- > 0; ) {
        if (!MainLoadStatus[i]) {
            return;
        }
    }
    
    //ok, this was the last frame; everything should now be ready
    
    MainLoadStatus = null;
    private_Initialize();
    if (MainReady) 
    {
		// go to admin screens
//		window.setTimeout("private_Redirect('frames/body.htm', true)", 50);
//      window.setTimeout("private_Redirect('frames/bodyMain.aspx', false)", 100);
    }
}



//---------------------------------------------------------
// Handle toolbar clicks. This will switch to the proper context
// and update any visual clues.
//---------------------------------------------------------
function ButtonClicked(name, updateLocation)
{
    var mainFrame = document.frames.bs_main;
    
    //switch all tabs to nonactive
    if ("help" != name) 
    {
    }
    var redirect = null;

    switch (name) {
                      
        case 'help':
            var width = 800;
            var height = 600;
            var left = (window.screen.availWidth - width) / 2;
            var top = (window.screen.availHeight - height) / 2;
            var options =
                "top=" + top +
                ",left=" + left +
                ",width=" + width +
                ",height=" + height +
				",channelmode=no" +
				",directories=no" +
				",fullscreen=no" +
				",location=no" +
				",menubar=no" +
				",resizable=yes" +
				",scrollbars=yes" +
				",status=yes" +
				",titlebar=yes" +
				",toolbar=no";
            //OpenWindow(window, "Help", "frames/bodyHelp.htm", options);
            Application.RegisterWindow( window.open("frames/bodyHelp.htm", "", options) );
            break;

        case 'home':
//		        window.setTimeout("private_Redirect('frames/bodyMain.aspx?page_guid=375C6F00-73C4-4075-8B51-9EE66F369855', false)", 100);
			break;

        default:
            alert("Unknown action \"" + name + "\"");
            break;
    }
    
    //If we should redirect and have a place to go, let's
    //temporarily switch to waiting page
    if (updateLocation && (null != redirect)) {
        window.setTimeout("private_Redirect('frames/body.htm', true)", 50);
        window.setTimeout("private_Redirect('" + redirect + "', false)", 100);
    }
}


//*********************************************************
//*
//* Private stuff
//*
//*********************************************************

//---------------------------------------------------------
//---------------------------------------------------------
function private_Redirect(url, updateHistory)
{
    window.open(url, "bs_main", null, !updateHistory);
}


//---------------------------------------------------------
//---------------------------------------------------------
function private_Initialize()
{
    //initialize top-levl application object
    window.Application = new LIApplication();
    Application.Debug.Initialize();
   
    MainReady = true;
    MainLoadStatus = null;
}

