var bLoaded = 0;

var sHomepage = sCGIUrl + "ntcgi." + sExt + "?base=home";
var sOptions = sCGIUrl + "ntcgi." + sExt + "?base=home&action=prefs";

var sEval = sCGIUrl + "ntcgi." + sExt + '?base=eval';
var sHelp = "";

function CrossFrameError()
{
    return true;
}

function init()
{
    var sCookie;

    DynHeader = new DynLayer( "HeaderLayer" );
    DynProfilesTab = new DynLayer( "ProfilesTabLayer" );
    DynOptionsTab = new DynLayer( "OptionsTabLayer" );

    MM_preloadImages( 'images/ichback.gif', 'images/ichtop.gif', 'images/ichhelp.gif', 'images/ichadmin.gif' );

    self.defaultStatus='';
    bLoaded = 1;

    if ( bEval )
    {
        sCookie = GetCookie( 'SaneEval' );
        if ( !sCookie )
        {
            var iHeight, iWidth, iTop, iLeft;

            iHeight = 135;
            iWidth = 500;

            if ( is.kq )
            {
                iHeight += 3;
                iWidth -= 2;
            }

            iTop = parseInt( (screen.height - iHeight) / 2 );
            iLeft = parseInt( (screen.width - iWidth) / 2 );

            SetCookie( 'SaneEval', 1 );
            window.open( sEval, 'evalFrame', 'fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + iWidth + ',height=' + iHeight + ',top=' + iTop + ',left=' + iLeft );
        }
    }
}

function actionManager( cmd )
{
    switch ( cmd )
    {
        case "h_tab_profiles":
            ShowProfilesTab();
            Redirect( sHomepage );
            break;

        case "h_tab_options":
            ShowOptionsTab();
            Redirect( sOptions );
            break;

        case "h_icon_pageback":
            window.onerror = CrossFrameError;
            if ( parent.rptBody )
                parent.rptBody.history.go( -1 );
            window.onerror = null;
            break;

        case "h_icon_pagetop":
            window.onerror = CrossFrameError;
            if ( parent.rptBody )
            {
                if ( parent.rptBody.optBody )
                    parent.rptBody.optBody.scrollTo( 0, 0 );
                else
                    parent.rptBody.scrollTo( 0, 0 );
            }
            window.onerror = null;
            break;

        case "h_icon_help":
            DisplayHelp( self.sHelp );
            break;

        case "h_icon_admin":
            parent.location = sProgHTMLUrl + "admin/index.html";
            break;

        case "h_order_now":
            Redirect( sOrder );
            break;
    }
}

function ShowProfilesTab()
{
    if ( bLoaded )
    {
        DynProfilesTab.show();
        DynOptionsTab.hide();
        DynHeader.hide();
    }
}

function ShowOptionsTab()
{
    if ( bLoaded )
    {
        DynProfilesTab.hide();
        DynOptionsTab.show();
        DynHeader.hide();
    }
}

function ShowLoginState()
{
    if ( bLoaded )
    {
        DynProfilesTab.hide();
        DynOptionsTab.hide();
        DynHeader.show();
    }
}

function Redirect( sLocation )
{
    if ( sLocation && parent.rptBody )
        parent.rptBody.location = sLocation;
}

function DisplayHelp( sTopic )
{
    var sLocation = "";

    if ( sTopic )
        sLocation = sProgHTMLUrl + "help/" + sLang + "/index.html?" + sTopic;
    else
        sLocation = sProgHTMLUrl + "help/" + sLang + "/index.html";

    window.open( sLocation, "helpFrame", "scrollbars=1,resizable=1,width=570,height=430" );
}

