/////////////////////////////////////////////////////////////////////
//
// Assistant.js - implementation of global script used 
//                throughout the Assistants
//
// Copyright ? 2003 InstallShield Software Corporation
//

var NAVIGATIONBUTTON_HOME = 0;
var NAVIGATIONBUTTON_BACK = 1;
var NAVIGATIONBUTTON_NEXT = 2;

var stepIndex;
var steps;

function InitializeAssistant() {
    stepIndex = 0;
    steps = InitializeCallback();
    
    GoHome();
    
    return;
}

function GetStepIndex() {
    return stepIndex;
}

function GoHome() {
    stepIndex = 0;
    return GoTo(stepIndex);
}

function GoBack() {
    var newIndex = BackCallback();
    
    if (newIndex > -1) {
        return GoTo(newIndex);
    }
    
    if (stepIndex > 0) {
        stepIndex--;
        return GoTo(stepIndex);
    }
    
    return false;
}

function GoNext() {
    var newIndex = NextCallback();
    
    if (newIndex > -1) {
        return GoTo(newIndex);
    }
    
    if (stepIndex < (steps.length - 1)) {
        stepIndex++;
        return GoTo(stepIndex);
    }
    
    return false;
}

function GoTo(index) {
    if ((index >= 0) && (index < steps.length)) {
        stepIndex = index;
        
        var page = steps[stepIndex];
        window.frames["frameStep"].location.href = page;
        
        window.frames["frameHeader"].SetTitle("»¶Ó­ÖúÊÖ");
        window.frames["frameHeader"].SetIcon("images/Home32.gif", "»¶Ó­ÖúÊÖ");

        if (stepIndex == 0) {
            window.frames["frameNavigation"].EnableNavigationButton(NAVIGATIONBUTTON_HOME, false);
            window.frames["frameNavigation"].EnableNavigationButton(NAVIGATIONBUTTON_BACK, false);
        } else {
            window.frames["frameNavigation"].EnableNavigationButton(NAVIGATIONBUTTON_HOME, true);
            window.frames["frameNavigation"].EnableNavigationButton(NAVIGATIONBUTTON_BACK, true);
        }
        
        if (stepIndex == (steps.length - 1)) {
            window.frames["frameNavigation"].EnableNavigationButton(NAVIGATIONBUTTON_NEXT, false);
        } else {
            window.frames["frameNavigation"].EnableNavigationButton(NAVIGATIONBUTTON_NEXT, true);
        }
    }
    
    return false;
}

// These functions define the NavigationButton objec that is 
// used by the Navigation.htm page.

function NavigationButton(name, area, img) {
    this.Name = name;
    this.Area = area;
    this.Image = img;
    this.enabled = true;
    this.GetEnabled = _GetEnabled;
    this.SetEnabled = _SetEnabled;
    this.WarmUp = _WarmUp;
    this.CoolDown = _CoolDown;
    this.Navigate = _Navigate;
    
    //this.Area.attachEvent("onclick", this.Navigate);
    //this.Area.onclick = this.Navigate;
    
    return this;
}

function _GetEnabled() {
    return this.enabled;
}

function _SetEnabled(enable) {
    this.enabled = enable;
    
    var url = "images/";
    
    if (this.enabled) {
        url += (this.Name + ".gif");
    } else {
        url += (this.Name + "Disabled.gif");
    }
    
    this.Image.src = url;
    
    return;
}

function _WarmUp() {
    if (this.enabled) {
        var url = "images/";
        url += (this.Name + "Hover.gif");
        
        this.Image.src = url;
        this.Image.style.cursor = "hand";
    }
    
    return;
}

function _CoolDown() {
    var url = "images/";
    
    if (this.enabled) {
        url += (this.Name + ".gif");
    } else {
        url += (this.Name + "Disabled.gif");
    }
    
    this.Image.src = url;
    this.Image.style.cursor = "default";
    
    return;
}

function _Navigate() {
    if (this.enabled) {
        switch (this.Name) {
            case "Home":
                return GoHome();
            case "Back":
                return GoBack();
            case "Next":
                return GoNext();
            default:
                break;
        }
    }
    
    return false;
}

// Global functions start here.

function IsEditControl(element) {
    var ok = false;
    
    if (element.isTextEdit) {
        switch (element.tagName) {
            case "TEXTAREA":
                ok = true;
                break;
                
            case "INPUT":
                if ((element.type == "text") || (element.type == "password")) {
                    ok = true;
                }
                
                break;
                
            default:
                break;
        }
    }
    
    return ok;
}
