﻿function windowFrame(windowName,frameWidth,frameHeight,url) {
  fw=window.open(url,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,left=0,top=0,width=" + frameWidth + ",height=" + frameHeight);     
  fw.focus();
}

function windowReferenceCAWorksheets(windowName,frameWidth,frameHeight,url){
 var b_name="";
 
  b_name=browser_name();

  if(b_name=="msie" )
  {
   fw=window.open(url,windowName,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,left=0,top=0,width=" + frameWidth + ",height=" + frameHeight);     
 
   fw.moveTo((screen.Width-780)/2,(screen.Height-500)/2 );
   }
   else
   {
    fw=window.open(url,windowName,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,left=200,top=200,width=" + frameWidth + ",height=" + frameHeight); 
   }
   
   fw.focus();
}

function windowReferenceQW(windowName,frameWidth,frameHeight,url){
 var b_name="";
 
  b_name=browser_name();

  if(b_name=="msie" )
  {
   fw=window.open(url,windowName,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,left=0,top=0,width=" + frameWidth + ",height=" + frameHeight);     
 
   fw.moveTo((screen.Width-780)/2,(screen.Height-500)/2 );
   }
   else
   {
    fw=window.open(url,windowName,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,left=200,top=200,width=" + frameWidth + ",height=" + frameHeight); 
   }
   
   fw.focus();
}

function windowFrameWithBrowserControls(windowName,frameWidth,frameHeight,url) {
  fw=window.open(url,windowName,"status=0,toolbar=0,menubar=1,scrollbars=1,resizable=1,location=0,directories=0,left=0,top=0,width=" + frameWidth + ",height=" + frameHeight);     
  fw.focus();
}

function windowReference(windowName,url) {
 var b_name="";
 
  b_name=browser_name();

  if(b_name=="msie" )
  {
   fw=window.open(url,windowName,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,left=0,top=0,width=780,height=500");     
 
   fw.moveTo((screen.Width-780)/2,(screen.Height-500)/2 );
   }
   else
   {
    fw=window.open(url,windowName,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,left=200,top=200,width=780,height=500"); 
   }
   
   fw.focus();
}

function windowReferenceWithSize(windowName,w,h,url) {
 var b_name="";
  b_name=browser_name();

  if(b_name=="msie" )
  {
   fw=window.open(url,windowName,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,left=0,top=0,width=" + w + ",height=" + h);
 
   fw.moveTo((screen.Width-w)/2,(screen.Height-h)/2 );
   }
   else
   {
    fw=window.open(url,windowName,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,left=200,top=200,width=" + w + ",height=" + h); 
   }
   
   fw.focus();
}

function windowNonResizable(windowName,frameWidth,frameHeight,url, centered){
var b_name="";
  b_name=browser_name();
   if(b_name=="msie" )
  {
  fw=window.open(url,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,left=0,top=0,width=" + frameWidth + ",height=" + frameHeight);     
  if(centered==true){
    fw.moveTo((screen.Width-frameWidth)/2,(screen.Height-frameHeight)/2 );
  }
  }
   else
   {
  fw=window.open(url,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,left=200,top=200,width=" + frameWidth + ",height=" + frameHeight); 
   }
  fw.focus();
}

function windowReferenceEdGuide(windowName,frameWidth,frameHeight,url, centered){
var b_name="";
  b_name=browser_name();
   if(b_name=="msie" )
  {
  fw=window.open(url,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,left=0,top=0,width=" + frameWidth + ",height=" + frameHeight);     
  if(centered==true){
    fw.moveTo((screen.Width-frameWidth)/2,(screen.Height-frameHeight)/2 );
  }
  }
   else
   {
  fw=window.open(url,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=no,left=200,top=200,width=" + frameWidth + ",height=" + frameHeight); 
   }
  fw.focus();
}

function setcookie(args)
{
	var aryArgs = args.split("|");
	var Audio = aryArgs[0];
	var Volume = aryArgs[1];
	document.cookie='audio=' + Audio;
	document.cookie='volume=' + Volume;
}

function getCookie(name) {
  var result = null;
  var myCookie = " " + document.cookie + ";";
  var searchName = "courseStatus=";
  var startOfCookie = myCookie.indexOf(searchName);
  var endOfCookie;
  if (startOfCookie != -1) {
    startOfCookie += searchName.length;
    endOfCookie = myCookie.indexOf(";",startOfCookie);
    result = unescape(myCookie.substring(startOfCookie,endOfCookie));
  }
  return result;
}

function browser_name() { 
    var browserName = ""; 

    var ua = navigator.userAgent.toLowerCase(); 
    if ( ua.indexOf( "safari" ) != -1 ) { 
        browserName = "safari"; 
    } 
    if ( ua.indexOf( "msie" ) != -1 ) { 
        browserName = "msie"; 
    }
    return browserName; 
};

function toggleBlock(blockID) {
	if (document.getElementById) {
		var subNodes = document.getElementById(blockID);
		subNodes.style.display = (subNodes.style.display == 'block') ? 'none' : 'block';
	}
}

function toggleResourceTocBlock(parentNode, blockID) {
	if (document.getElementById) {
		var subNodes = document.getElementById(blockID);
		if (subNodes.style.display == 'block') { //it is by default none but set in css class
		    subNodes.style.display = "none";
		  
		    parentNode.style.color = "#003399";
		} else {
		    subNodes.style.display = "block";
		    parentNode.style.color = "#003399";
		}
	}
}

function toggleTableContentBlock(aID) {
	if (document.getElementById) {
		var tableNode = document.getElementById('tableContentBlock' + aID);
		if (tableNode.style.display=="none") {
		    tableNode.style.display = "block";
		    document.getElementById('showTableContentBlock' + aID).style.display = "none";
		    document.getElementById('hideTableContentBlock' + aID).style.display = "block";
		 } else {
		    tableNode.style.display = "none";
		    document.getElementById('showTableContentBlock' + aID).style.display = "block";
		    document.getElementById('hideTableContentBlock' + aID).style.display = "none";
		 }
	}
}

function PopupGlossaryTerm(glossaryID) {
var b_name="";
  b_name=browser_name();

  if(b_name=="msie" )
  {
  fw=window.open("../glossaryPopup/" + glossaryID, 'Glossary',"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,left=0,top=0,width=550,height=485");     
  fw.moveTo((screen.Width-550)/2,(screen.Height-485)/2 );
  }
  else
  {
  fw=window.open("../glossaryPopup/" + glossaryID, 'Glossary',"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,left=200,top=200,width=550,height=485");
  }
  fw.focus();
}

function PopupGlossarySource() {
var b_name="";
  b_name=browser_name();

  if(b_name=="msie" )
  {
  fw=window.open("../glossarySourcePopup", 'Glossary',"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,left=0,top=0,width=650,height=550");     
  fw.moveTo((screen.Width-650)/2,(screen.Height-550)/2 );
   }
  else
  { fw=window.open("../glossarySourcePopup", 'Glossary',"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,left=200,top=200,width=650,height=550"); 
  }    
  fw.focus();
  
}

function showBoxes(divName){
   var i=1;
   var nodeId, tocNode;
   
   if (divName=='tocnodesime')
   {
    for (i=2;i<=75;i++)
     {
        tocNode  = document.getElementById('tocnodesime_c0' + i);
        if (tocNode!=null) tocNode.style.display='block';
     }
   } else if (divName=='partBlock100'){
    for (i=0;i<7;i++)
     {
      document.getElementById(divName+i).style.display='block';
     }
   }
document.getElementById('expandall').style.color='gray';
document.getElementById('hideall').style.color='#003399';
}
function hideBoxes(divName){
   var i=1;
   var nodeId, tocNode;
   
   if (divName=='tocnodesime')
   {
    for (i=2;i<=75;i++)
     {
        tocNode  = document.getElementById('tocnodesime_c0' + i);
        if (tocNode!=null) tocNode.style.display='none';
     }
   } else if (divName=='partBlock100'){
   for (i=0;i<7;i++)
{
document.getElementById(divName+i).style.display='none';
}
   }
document.getElementById('hideall').style.color='gray';
document.getElementById('expandall').style.color='#003399';
}

function preloadImage(){
    var myimages = new Array();
    for (var x=0; x<preloadImage.arguments.length; x++){
    myimages[x] = new Image();
    myimages[x].src = preloadImage.arguments[x];
    }
}

function reloadParentWindow() {
 var parentURL = top.opener.location.href;
 if (parentURL.indexOf("&refresh=1") > 0) {
    parentURL = parentURL.replace("&refresh=1", "&refresh=2");
 }else if (parentURL.indexOf("&refresh=2") > 0) {
   parentURL = parentURL.replace("&refresh=2", "&refresh=2");
 }else if (parentURL.indexOf("?") > 0) {
    parentURL = parentURL + "&refresh=1"; 
 }else {
    parentURL = parentURL + "?&refresh=1"; 
 }
 top.opener.location.href = parentURL;
}

function selectMyJamaItems(idPrefix, check) {
     var items = document.getElementsByTagName("input");
     for (var i=0; i<items.length; i++) {
         if (items[i].type == "checkbox" && items[i].id.indexOf(idPrefix)==0) {
             items[i].checked = check;
         }
     }
}

function EnterKeyPressed(e) {
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        
        return (keycode==13)?true:false;
}