<script>
var userSecurityCheck = new Function('return window');
var configurationSuccess = true;
top.componentXselected = false;
top.componentYselected = false;
top.configurationReady = false;
top.simulateFailure = false;

function configurationHelper(percentComplete)
{
	if(!percentComplete)
	{
		percentComplete = 0;
		top.showProgress();
	}
	if(percentComplete == 100)
	{
		setTimeout("top.showProgress(false); top.next();", 1000);
		return;
	}
	else
	{
		top.updateProgress(percentComplete++);
		setTimeout("top.configurationHelper("  + percentComplete + ")", 50);
	}
}

function checkConfigurationSuccess()
{
	if(!configurationSuccess)
	{
		top.setNavigationState('menu_configuration', 'error');
	}
	
}

/* String trim function, copied from Dojo Lib. */
String.prototype.trim = function(){
    var str = this.replace(/^\s+/, '');
    for(var i = str.length - 1; i >= 0; i--){
        if(/\S/.test(str.charAt(i))){
            str = str.substring(0, i + 1);
            break;
        }
    }
    return str;
};

var navFuncs = {
    tasksEnter: function() {},
    tasksNext: function() {},
    clusteripEnter: function() {},
    clusteripNext: function() {},
    serviceipEnter: function() {},
    serviceipNext: function() {},
    usbEnter: function() {},
    usbNext: function() {},
    usbPrevious: function() {},
    summaryEnter: function() {},
    finishAction: function() {}
},
sataskFiles = { command: "satask.txt", result: "satask_result.html"},
CMDResultPath = ['launchpad', 'command', 'result'].join(top.PATHSEPARATOR),
flashDriveFile = CMDResultPath + top.PATHSEPARATOR + 'flashdirve.txt',
appmarkPath = CMDResultPath + top.PATHSEPARATOR + 'appmark.txt',
flashDriveFileName = 'flashdrivepath.txt';

/* Simplify top.runProgram for Init Tool. */
function runCommand(cmd, callback, cbCtx, delay) {
    /* Fix space problem in Linux. */
    if(cmd[0].indexOf("deletefile.sh") != -1){
        cmd[1] = cmd[1].replace(/ /g, "|");
    }
    try{
        /* Fix failed asynchronous call in IE. Callback function is called directly, it was expected to run after command returns. */
        if(top.BROWSER == "IExplore" && delay == null) delay = 500;

        runProgram(null, cmd, BACKGROUND, HIDDEN, null, null, function(re){
            if(callback == null) return;

            if(delay == null) {
                callback.apply(cbCtx);
            } else {
                setTimeout( function(){ callback.apply(cbCtx); }, delay);
            }
        });
    } catch(e) {}
}

/* Get user's Flash Drive. */
function getFlashDirve() {
    try{
        var flashPath = top.readTextFile(top.STARTINGDIR + top.flashDriveFileName).trim();
    } catch(e) {}

    if(flashPath == null || flashPath == ""){
        top.InitToolPathOnUSB = top.flashDrive = top.STARTINGDIR;
    } else {
        top.flashDrive = (flashPath.charAt(flashPath.length - 1) == top.PATHSEPARATOR) ? flashPath : flashPath + top.PATHSEPARATOR;
        top.InitToolPathOnUSB = top.flashDrive + "InitTool" + top.PATHSEPARATOR;
    }
}

function openWindow(url) {
    window.open(url, "_blank", "width=800, height=600, toolbar = 1")
}

getFlashDirve();
</script>
