//*****************************************************************************
//                  Copyright (c) 2007, Lexmark International, Inc.           
//     THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY     
//        INFORMATION WHICH IS THE PROPERTY OF LEXMARK INTERNATIONAL, INC.     
//                                                                             
//   ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM  
//              LEXMARK INTERNATIONAL, INC., IS STRICTLY PROHIBITED.           
//*****************************************************************************
//
//  commonJS.js contains methods that provide access to the gateway. The 
// 	javascript of the displayed screen does not access the DLL directly.
//  Instead, it will go through the methods provided by the Common Javascript
//  file. The methods in this file will call upon the methods in the gateway.
//  These methods are the ones that will access the DLL.
//
//****************************************************************************

// Create an empty object
var commonJS = new Object();

//	GetGateway
//		A method that initializes the Gateway1 variable which will allow access
// 		to the gateway.
//
function GetGateway()
{
    commonJS.Gateway1 = window.external;
}

// Startup
//      A method that calls the gateway Startup method.
//  Params:
//      landingID       The ID of the initial screen to display.
//      friendlyName    The friendly name of the device. Optional.
//      portName    The port name of the device. Optional.
//  Return:
//      startupRetVal   The HalStartup return code. HAL_SUCCESS = 0, 
//                      HAL_FAIL = 1 and HAL_BUSY = 2.
//
commonJS.Startup = function (
    landingID,
    friendlyName,
    portName)
{
    var startupRetVal;

    GetGateway();

    // See if Gateway1 is valid
    if (commonJS.Gateway1 != null)
    {
        // Call the Gateway Startup method
        startupRetVal = commonJS.Gateway1.Startup(landingID);
    }

    return startupRetVal;
}

// Action
//      A method that calls the gateway Action method.
//  Params:
//      currentScreenId     The ID of the currently displayed screen.
//      actionId            The ID of the current action to perform.
//      currentScreenLogId  String ID to use when logging a conversation.
//      actionLogId         String ID to use when logging a conversation.
//      catsId              ID used in the CATS log for the current screen.
//  Return:
//      actionRetVal    The HalAction return code. HAL_SUCCESS = 0, 
//                      HAL_FAIL = 1 and HAL_BUSY = 2.
//
commonJS.Action = function (
    currentScreenId,
    actionId,
    currentScreenLogId, 
    actionLogId, 
    catsId)
{
    var actionRetVal;

    GetGateway();

    // See if Gateway1 is valid
    if (commonJS.Gateway1 != null)
    {
        // Call the Gateway Action method
        actionRetVal = commonJS.Gateway1.Action(currentScreenId, actionId);
    }

    return actionRetVal;
}


commonJS.ActionAsync = function (
    currentScreenId,
    actionId,
    currentScreenLogId, 
    actionLogId, 
    catsId)
{
    var actionRetVal;

    GetGateway();

    // See if Gateway1 is valid
    if (commonJS.Gateway1 != null)
    {
        // Call the Gateway Action method
        actionRetVal = commonJS.Gateway1.ActionAsync(currentScreenId, actionId);
    }

    return actionRetVal;
}

//
// Exit
//		A method that calls the gateway Exit method.
// 
commonJS.Exit = function()
{
    GetGateway();

    // See if Gateway1 is valid
    if (commonJS.Gateway1 != null)
    {
		commonJS.Gateway1.Exit();
    }
}

//
// GetDataPath
//      Retrieves the data path for the scripts.
// Return:
//      dataPath    Returns the data path for the scripts.
//
commonJS.GetDataPath = function()
{
    var dataPath;
    
    GetGateway();
    
    if(commonJS.Gateway1 != null)
    {
        dataPath = commonJS.Gateway1.GetDataPath();
    }
    
    return dataPath;
}

//
// ResetSession
//      Resets the session for the app. 
// Return: None
//
commonJS.ResetSession = function()
{
    GetGateway();
    if(commonJS.Gateway1 != null)
    {
        commonJS.Gateway1.ResetSession();
    }
}

//
// GetWaitState
//      Retrieve the stored wait state. 
// Return:
//      true    if the app is in a wait state -- app is busy
//      false   if the app isn't in a wait state -- app is ready
//
commonJS.GetWaitState = function()
{
    var isWaiting;
    
    GetGateway();
    if(commonJS.Gateway1 != null)
    {
        // Call the Gateway GetWaitState method
        isWaiting = commonJS.Gateway1.GetWaitState();
    }
    
    return isWaiting;
}

//
// EndWaitCursor
//      Ends the wait cursor. 
// Return: None
//
commonJS.EndWaitCursor = function()
{
    GetGateway();
    if(commonJS.Gateway1 != null)
    {
        // Call the Gateway EndWaitCursor method
        commonJS.Gateway1.EndWaitCursor();
    }
}

commonJS.ExpandDialog = function()
{
    GetGateway();
    if(commonJS.Gateway1 != null)
    {
        // Call the Gateway EndWaitCursor method
        commonJS.Gateway1.ExpandDialog();
    }
}


//
// GetLandingId
// 		Retrieve the stored landing identifier.
// 	Return:
// 		landingId	Returns the landing identifier
// 
commonJS.GetLandingId = function()
{
    var landingId;

    GetGateway();

    // See if Gateway1 is valid
    if (commonJS.Gateway1 != null)
    {
        // Call the Gateway GetLandingId method
        landingId = commonJS.Gateway1.GetLandingId();
    }

    return landingId;
}



//
// GetScriptName
// 		Retrieve the stored script name of the screen to be displayed. This
// 		is for OGRE testing only.
// 	Return:
// 		scriptName	Returns the script name.
// 
commonJS.GetScriptName = function()
{
    var scriptName;

    GetGateway();

    // See if Gateway1 is valid
    if (commonJS.Gateway1 != null)
    {
        // Call the Gateway GetScriptName method
        scriptName = commonJS.Gateway1.GetScriptName();
    }

    return scriptName;
}


commonJS.GetDiagnosisInfo = function(diagInfoType)
{
	 var diagInfo;

    GetGateway();

    // See if Gateway1 is valid
    if (commonJS.Gateway1 != null)
    {
        // Call the Gateway IsOgreEnabled method
        diagInfo = commonJS.Gateway1.GetDiagnosisInfo(diagInfoType);
    }

	return diagInfo;
}
