///////////////////////////////////////////////
// Copyright Questionmark Computing 2002 - 2006
// SBAPI.js version 4.3.0.0
// last modified 20.04.2006
//
// An API of functions for manipulating behaviour of Questionmark Secure player.
//
// Usage: include this file using:
//
//  <script language=JavaScript src=SBAPI.js></script>
//
// It is recommended that authors wrap calls to this API with:
//
//  if (bSB) {
// 
//  }

// Call this to establish whether the viewing browswer is SB
function SB_IsPresent()
{
   return ((window.external != null) && (window.external.SB_GetVersion != null));
}

var bSB = SB_IsPresent();

// Call this to establish the version of the viewing SB
function SB_GetVersion()
{
   if (bSB) {
      return window.external.SB_GetVersion();
   } else {
      return "";
   }
}

var bQS = (SB_GetVersion().indexOf("Perception Secure Browser") == -1);

/******************************************************
 Function: Register Page

 Tells SB that this is a Perecption page using the PSB functions
 Any pages in which this function is not called will be assumed to 
 be error pages and the PSB back button will be enabled if allowed
*******************************************************/

function SB_RegisterPage()
{
   if (bSB) {
      return window.external.SB_Register();
   }
}


/******************************************************
 Function: Pop Up Window

 Call this to display a pop-up window in a secure dialog within the viewing SB
 Params should be specified in the format: name=value, and are space-delimited.
 Spaces can be included within values by enclosing the value with matching 
 single or double quotes.

 Parameters are:

  href - specify the url to navigate to
  width - specify the width of the window - append a % to specify size relative to screen
  height - specify the height, as above
  top - specify the top of the window, as above
  left - specify the left of the window, as above

 e.g. SB_PopUp("href=www.questionmark.com width=33% height=33% top=50 left=50");
*******************************************************/

function SB_PopUp(params)
{
   if (bSB) {
      window.external.SB_PopUp(params);
   }
}


/******************************************************
 Property: Can Print
 Default:  false

 When true, user can print the current page.
*******************************************************/

function SB_SetCanPrint(state)
{
   if (bSB) {
      return window.external.SB_SetCanPrint(state);
   }
}

function SB_GetCanPrint()
{
   if (bSB) {
      return window.external.SB_GetCanPrint();
   }
}

/******************************************************
 Property: Can Refresh
 Default:  false

 When true, user can refresh the current page.
*******************************************************/

function SB_SetCanRefresh(state)
{
   if (bSB) {
      return window.external.SB_SetCanRefresh(state);
   }
}

function SB_GetCanRefresh()
{ 
   if (bSB) {
      return window.external.SB_GetCanRefresh();
   }
}

/******************************************************
 Property: CanGoBackOnError
 Default:  false

 When true, if any subsequent pages are not Perception pages
 (i.e. don't call SB_RegisterPage()), the back button is enabled.
*******************************************************/

function SB_SetCanGoBackOnError(state)
{
   if (bSB) {
      return window.external.SB_SetCanGoBackOnError(state);
   }
}

function SB_GetCanGoBackOnError()
{
   if (bSB) {
      return window.external.SB_GetCanGoBackOnError();
   }
}



/******************************************************
 Property: Toolbar Visibility
 Default:  false

 When true, toolbar is always visible.
 When false, toolbar shows itself when appropriate - i.e.
 when there are buttons other than close enabled 
*******************************************************/

function SB_SetToolbarVisibility(state)
{
   if (bSB) {
      return window.external.SB_SetToolbarVisibility(state);
   }
}

function SB_GetToolbarVisibility()
{
   if (bSB) {
      return window.external.SB_GetToolbarVisibility();
   }
}

/******************************************************
 Function: Exit QS

 Call this to exit Questionmark Secure

 Parameters are: None

 Return Value: None

 e.g. SB_EXitQS();
*******************************************************/

function SB_ExitQS()
{
   if (bSB) {
      if (bQS) { window.external.SB_ExitQS(); }
   }
   return void(0);
}

/******************************************************
 Property: Alt+F4 exit
 Default:  false

 When true, the users taking exams in QS can press ALt + F4 to exit qs any time.
 When false, the user cannot press Alt+F4 to exit QS
*******************************************************/

function SB_SetCanAltF4(state)
{
   if (bSB) {
      if (bQS) { return window.external.SB_SetCanAltF4(state); }
   }
}

function SB_GetCanAltF4()
{
   if (bSB) {
      if (bQS) { return window.external.SB_GetCanAltF4(); }
   }
}

/******************************************************
 Property: ExitOnError
 Default:  false

 When true, if any subsequent pages are not Perception pages
 (i.e. don't call SB_RegisterPage()), the Exit button is enabled.
*******************************************************/

function SB_SetCanExitOnError(state)
{
   if (bSB) {
      if (bQS) { return window.external.SB_SetCanExitOnError(state); }
   }
}

function SB_GetCanExitOnError()
{
   if (bSB) {
      if (bQS) { return window.external.SB_GetCanExitOnError(); }
   }
}

/******************************************************
 Property: Exit button
 Default:  false

 When true, the Exit button is enabled can close QS
 When false, the Exit button is disabled 
*******************************************************/

function SB_SetCanExit(state)
{
   if (bSB) {
      if (bQS) { return window.external.SB_SetCanExit(state); }
   }
}

function SB_GetCanExit()
{
   if (bSB) {
      if (bQS) { return window.external.SB_GetCanExit(); }
   }
}


/******************************************************
 NOTE - for compatability with PSB only, not supported in QS
 Property: Can Exit Without Password
 Default:  false

 When false, users require a password in order to exit the SB

 NOTE - for compatability with PSB only, not supported in QS
*******************************************************/

function SB_SetCanExitWithoutPassword(state)
{
   if (bSB) {
        if (!bQS) { 
            return window.external.SB_SetCanExitWithoutPassword(state); 
        } else {
            return false;
        }
   }
}

function SB_GetCanExitWithoutPassword()
{
    if (bSB) {
        if (!bQS) { 
            return window.external.SB_GetCanExitWithoutPassword(); 
        } else {
            return false;
        }
    }
}

/******************************************************
 NOTE - for compatability with PSB only, not supported in QS
 Property: Can Home
 Default:  false

 When true, user can click the home button to go to the
 home url.
 NOTE - for compatability with PSB only, not supported in QS
*******************************************************/

function SB_SetCanHome(state)
{
    if (bSB) {
        if (!bQS) {
            return window.external.SB_SetCanHome(state);
        } else {
            return false;
        }
   }
}

function SB_GetCanHome()
{
    if (bSB) {
        if (!bQS) {
            return window.external.SB_GetCanHome();
        } else {
            return false;
        }
   }
}

/******************************************************
Function: Set SCORM Results

Used to pass results back to the SCORM API when a secure
assessment is launched from an LMS using the SCORM protocol
*******************************************************/

function SB_SetSCORMResults(param)
{        
   if  (bSB)  {
		// check we're using version 4.2 or later
		if (parseFloat(SB_GetVersion().slice(-7,-4)) < 4.2) 	{
			return false;
		} else {
	        return window.external.SB_SetSCORMResults(param);
		}
    }  else {
        return false;
	}
}
