/*
 * $Header: /hti/htdocs/thinkleadership.dev.hti.bit10.net/js/common.js 8     11/10/05 17:53 Mattw $
 *
 * short: common JavaScript functions
 *
 * $Log: /hti/htdocs/thinkleadership.dev.hti.bit10.net/js/common.js $
 * 
 * 8     11/10/05 17:53 Mattw
 * Added another line of text to the Bit10_confirmation() confirm box.
 * 
 * 7     11/10/05 12:58 Craigm
 * Fixing the Cancel function
 * 
 * 6     10/10/05 16:44 Mattw
 * Changing text on "Bit10_confirmation()" confirm box.
 * 
 * 5     10/10/05 16:39 Mattw
 * Added "Bit10_confirmation()" function.
 * 
 * 4     10/10/05 14:42 Craigm
 * Changing the scripts now the poups have been removed
 * 
 * 3     29/05/02 14:31 Craigm
 * Fixed some change requests.
 * 
 * 2     15/10/01 13:56 Alex
 * Added new function B10_benchmarkwizardBack().
 *
 */
var _B10_wndChild;
var _B10_boolOldBrowser = parseInt(navigator.appversion) < 3;

// B10_spawnWindow() -- spawn a child browser window
function B10_spawnWindow(name, content, width, height, scrollbars) {
  _B10_wndChild = B10_spawnWindowAndReturn(name, content, width, height, scrollbars);
}

// B10_spawnWindowAndReturn() -- spawn a child browser window and return a reference to the new window
function B10_spawnWindowAndReturn(name, content, width, height, scrollbars) {
	var strAttribs = 'toolbar=no,width=' + width + ',height=' + height + ',directories=no,status=no,scrollbars=' + ((scrollbars)?'yes':'no') + ',resizeable=yes,menubar=no,location=no,screeny=50,screenx=50,alwaysRaised';
  var objWindow = window.open(content, name, strAttribs);
	if (!objWindow.opener) { objWindow.opener = window; }
	if (!_B10_boolOldBrowser)  { objWindow.focus();         }
  return objWindow;
}

// B10_spawnWindowAndWrite() -- spawn a child browser window and write the given contents to it
function B10_spawnWindowAndWrite(name, content, width, height, scrollbars) {
	var objWindow = B10_spawnWindowAndReturn(name, '', width, height, scrollbars);
	with (objWindow.document) {
	  open("text/html", "replace");
	  write(content)
	  close();
	}
}

  function submitContactUs() {
  
    frm = document.frmContactUs;
    frm.hdnValidForm.value = "FormIsValid";
    frm.submit();
  }


/*
 * The following are standard MarcoMedia functions
 */

// Open a new page in the current browser window
function MM_goToURL() { //v2.0
  for (var i=0; i< (MM_goToURL.arguments.length - 1); i+=2) //with arg pairs
    eval(MM_goToURL.arguments[i]+".location='"+MM_goToURL.arguments[i+1]+"'");
  document.MM_returnValue = false;
}

// Open a new window.
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_popupMsg(theMsg) { //v2.0
  alert(theMsg);
}


// ---------------------------------------------------------------------------
// Functions used for Question Wizard...
// ---------------------------------------------------------------------------

function B10_questionwizardBegin() {
  document.frmAssessment.submit();
}

function B10_questionwizardNext() {
  document.frmAssessment.hdnQuestion.value = parseInt(getURLParameter('quest')) + 1;
  document.frmAssessment.submit();
}

function B10_questionwizardBack() {
	var question = getURLParameter('quest');
  document.frmAssessment.hdnQuestion.value = parseInt(question) - 1;
  document.frmAssessment.submit();
}

function B10_wizardCancel(location) {
	document.location.href=location;
}

function B10_questionwizardContinue(iLocation) {
  location.replace(iLocation);
}

function Bit10_confirmation(URL) {
	var answer = confirm("Are you sure you want to navigate away from the current assessment?\n\n" + "All answers for this module will be lost!\n\n" + "Press OK to continue, or Cancel to stay on the current page.")
	if (answer){
		window.location.href = URL;
	}
}

// ---------------------------------------------------------------------------
// End of Question Wizard functions...
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
// Functions used for Registration Wizard...
// ---------------------------------------------------------------------------

function B10_registerwizardBegin() {
  location.href = "register.cfm?step=1"
}

function B10_registerwizardNext() {
  document.frmRegister.hdnStep.value = parseInt(getURLParameter('step')) + 1;
  document.frmRegister.submit();
}

function B10_registerwizardBack() {
  document.frmRegister.hdnStep.value = parseInt(getURLParameter('step')) - 1;
  location.href = "register.cfm?step=" + document.frmRegister.hdnStep.value;
}

function B10_registerwizardBackToStart() {
  document.frmRegister.hdnStep.value = 1;
  document.frmRegister.submit();
}

function B10_registerwizardContinue(iLocation) {
  location.replace(iLocation);
}

// ---------------------------------------------------------------------------
// End of Registration Wizard functions...
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
// Functions used for AMP Wizard...
// ---------------------------------------------------------------------------

function B10_ampwizardNext() {
  document.frmAMP.hdnStep.value = parseInt(getURLParameter('step')) + 1;
  document.frmAMP.submit();
}

function B10_ampwizardBack() {
  document.frmAMP.hdnStep.value = parseInt(getURLParameter('step')) - 1;
  location.href = "amp.cfm?step=" + document.frmAMP.hdnStep.value;
}

// ---------------------------------------------------------------------------
// End of AMP functions...
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
// Functions used for Extra Data Wizard...
// ---------------------------------------------------------------------------

function B10_extradatawizardBack() {
  location.href = "actionplan.cfm";
}

// ---------------------------------------------------------------------------
// End of Extra Data functions...
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
// Functions used for AMP Wizard...
// ---------------------------------------------------------------------------

function B10_benchmarkwizardNext() {
//  document.frmBenchmark.hdnStep.value = parseInt(getURLParameter('step')) + 1;
  document.frmBenchmark.submit();
}

function B10_benchmarkwizardBack() {
  location.href = "benchmark.cfm?snapshot=" + parseInt(getURLParameter('snapshot')) + "&mod=" + parseInt(getURLParameter('mod'));
}

// ---------------------------------------------------------------------------
// End of Benchmark functions...
// ---------------------------------------------------------------------------

// The following function is used to close the wizard window and load the login 
// screen into the main window, when the users session times out.
function B10_wizardLogin() {
  window.opener.location.href = "/audit/login.cfm";
  self.close();
}

function getURLParameter(strParameterName) {

  var intStartIndex, intEndIndex;  //starting and ending of substrings of the location string to examine

  // mark first url parameter
  intStartIndex = location.href.indexOf("?") + 1;
  
  // for all url parameters
  while(intStartIndex != 0) {
  
    // mark between ?/& and = to get name of url parameter
    intEndIndex = location.href.indexOf("=", intStartIndex);
    if(intEndIndex == -1) intEndIndex = location.href.length; 
    
    // compare name with passed parameter
    if(location.href.substring(intStartIndex, intEndIndex) == strParameterName) {

      // mark between = and & to get value of url parameter
      intStartIndex = intEndIndex + 1;
      intEndIndex = location.href.indexOf("&", intStartIndex);
      if(intEndIndex == -1) intEndIndex = location.href.length;
      
      // return value
      return (intStartIndex == intEndIndex) ? null : location.href.substring(intStartIndex,intEndIndex);
    }
    
    // move onto next url parameter
    intStartIndex = location.href.indexOf("&", intEndIndex) + 1;          
  }
    
  // no match so return null
  return null;
}

function MM_swapImgRestore() { //v2.0
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}

function MM_preloadImages() { //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

function MM_swapImage() { //v2.0
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  } }
  document.MM_swapImgData = swapArray; //used for restore
}
