// Copyright 2003 by QuantMethods

// Manage a variable in the frameset window to record the current context
// for help and file operations.

parent.document.QMS_Context = null;

var QMS_HelpWindow   = null;
var QMS_ManualWindow = null;

function newModel() 
{
    parent.MainFrame.location.href = "Models.html";
}

function openModel() 
{
}

function saveModel()
{
}

function editModel() 
{
    var Context = parent.document.QMS_Context;

    if ( Context )
    {
        parent.MainFrame.location.href = Context + "/Problem.html";
    }
    else
    {
        newModel();
    }
}

function printModel() 
{
    if ( parent.MainFrame.print )
    {
        parent.MainFrame.focus();
        parent.MainFrame.print();
    }
    else
    {
        alert( "Your browser only supports printing from the File menu." );
    }
}

function openHelp() 
{
    var Context = "MainMenu";

    if ( openHelp.arguments.length == 1 )
    {
        Context = openHelp.arguments[ 0 ];
    }
    else if ( parent.document.QMS_Context )
    {
        Context = parent.document.QMS_Context;
    }

    if ( ( ! QMS_HelpWindow ) ||
         ( ! QMS_HelpWindow.open ) ||
         ( QMS_HelpWindow.closed ) )
    {
        var URL = "Help/";

        if ( Context != "MainMenu" )
        {
            URL += "?context=" + escape( Context );
        }

        QMS_HelpWindow = window.open( URL,
                                      "QMS_Help",
                                      "menubar=1,"     +
                                      "toolbar=1,"     +
                                      "location=0,"    +
                                      "directories=0," +
                                      "status=1,"      +
                                      "resizable=1,"   +
                                      "width=800,"     +
                                      "height=550" );
    }
    else
    {
        QMS_HelpWindow.HelpFrame.location.href = "Help/" + Context + ".html";
    }

    QMS_HelpWindow.focus();
}

function openManual() 
{
    if ( ( ! QMS_ManualWindow ) ||
         ( ! QMS_ManualWindow.open ) ||
         ( QMS_ManualWindow.closed ) )
    {
        QMS_ManualWindow = window.open( "Manual.html",
                                        "QMS_Manual",
                                        "menubar=1,"     +
                                        "toolbar=0,"     +
                                        "location=0,"    +
                                        "directories=0," +
                                        "status=0,"      +
                                        "resizable=1,"   +
                                        "width=800,"     +
                                        "height=550" );
    }

    QMS_ManualWindow.focus();
}

function registerUser() 
{
    parent.MainFrame.location.href = "Register.html";
}

function exitQMS() 
{
    top.location.href = "/";
}

function closeDocuments() 
{
    if ( ( QMS_HelpWindow ) &&
         ( QMS_HelpWindow.open ) &&
         ( ! QMS_HelpWindow.closed ) )
    {
        QMS_HelpWindow.close();
    }

    if ( ( QMS_ManualWindow ) &&
         ( QMS_ManualWindow.open ) &&
         ( ! QMS_ManualWindow.closed ) )
    {
        QMS_ManualWindow.close();
    }
}

function showModelNameInStatusBar( ModelName )
{
    window.status = ModelName;

    return true;
}

function clearModelNameInStatusBar()
{
    window.status = '';

    return true;
}

