 





/*********************************************************************************
 Execute on page load
*********************************************************************************/
/*
see http://simon.incutio.com/archive/2004/05/26/addLoadEvent for details
Summary: This function allows for execution of muliple scripts/functions once the page loads (and replaces calls like body onload="..." and window.onload = LoadActiveImages;)
Useage: To call a function use the following syntax:
addLoadEvent(function() {
 	NameOfFuntionToLoad();
	})  
*/

var enEditorLength ="";
var frEditorLength ="";

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function clearText(inputCtrl,message) {
	if (inputCtrl.value == message) {
		inputCtrl.value = '';
	}
}

function displayChars(msg,textName,inputName,maxCount,message) {
	var inputCtrl = document.getElementById(inputName);
	var isMessage = (inputCtrl.value == message);
	var l = maxCount-(isMessage ? 0 : inputCtrl.value.length);
	var ctrl = document.getElementById(textName);
	ctrl.innerHTML=msg + ' ' + l + ' (' + maxCount +')';
	ctrl.style.color=(l<10 ? '#FF0000' : '#000000');
}

function FCKeditor_OnComplete( editorInstance )
{
    window.setTimeout(OnFckTimer, 250) ;
    editorInstance.Events.AttachEvent('OnSelectionChange', ClearCharsMsg) ;
}

function OnFckTimer() 
{
	UpdateCounter(FCKeditorAPI.GetInstance('creditsEn'));
	UpdateCounter(FCKeditorAPI.GetInstance('creditsFr'));
	UpdateCounter(FCKeditorAPI.GetInstance('introductionEn'));
	UpdateCounter(FCKeditorAPI.GetInstance('introductionFr'));
	UpdateCounter(FCKeditorAPI.GetInstance('referencesEn'));
	UpdateCounter(FCKeditorAPI.GetInstance('referencesFr'));
	UpdateCounter(FCKeditorAPI.GetInstance('fulltextEn'));
	UpdateCounter(FCKeditorAPI.GetInstance('fulltextFr'));
        window.setTimeout(OnFckTimer, 250);
}

function UpdateCounter(editorInstance) // for FCK Editor only
{
  if (editorInstance != null) {
    var ctrl = document.getElementById('charsCount'+editorInstance.Name);
    var aName =editorInstance.Name;  

    if (ctrl != null) {
        var s = editorInstance.GetXHTML(false);                     
	var l = 2500-s.length;
	ctrl.innerHTML='Please note that the character count includes HTML markup (e.g. paragraph tags), thus reducing the total amount of characters available.' + ' ' + 'Characters left:' + ' ' + l + ' (2500)';
	ctrl.style.color=(l<10 ? '#FF0000' : '#000000');
        if(aName !=null)
        {
           if (aName.lastIndexOf('En')!=-1)
           {
              enEditorLength =s;
           }
           if (aName.lastIndexOf('Fr')!=-1)
           {
              frEditorLength =s;
           }
        }
    }
  }
}

function getEnEditorLength()
{
   return enEditorLength;
}

function getFrEditorLength()
{
   return frEditorLength;
}

function ClearCharsMsg(editorInstance)
{
	if (editorInstance != null) 
        {
		var s =editorInstance.GetXHTML(false);
                if (s == '2500 Characters Maximum') {
                    editorInstance.SetHTML('');
                }
        }
}


/*********************************************************************************
 Global variables
*********************************************************************************/
//Default browsercheck
function browsercheck(){
    this.ver=navigator.appVersion
    this.agent=navigator.userAgent
    this.dom=document.getElementById?1:0;
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
    this.ie4=(document.all && !this.dom)?1:0;
    this.ie=this.ie4||this.ie5||this.ie6
    this.mac=this.agent.indexOf("Mac")>-1
    this.opera5=this.agent.indexOf("Opera 5")>-1
    this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
    this.ns4=(document.layers && !this.dom)?1:0;
    this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom)
    //this.bw=document.getElementById?1:0;
    return this
}
var bw=browsercheck();

//window.name = "MainWin";

var PageImages = new Array();
var PageAltImages = new Array();
var nest = "";
var loaded = 0;


/*********************************************************************************
Images Preload
*********************************************************************************/

//Kevin suggests rewritting to use ~getElemntByType, or something along those lines
//Re-write for -on and -off??
function LoadActiveImages() {
	var num = document.images.length;
	for (var i = 0; i < num; i++) {
		var thisImage = document.images[i];
		var thisImageSrc = thisImage.src;
		var imageName = thisImageSrc.substring(0,thisImageSrc.lastIndexOf("_o"));
		//document.write(imageName + "<BR>");
		if (thisImageSrc.lastIndexOf("_off") != -1) {
			PageImages[i] = new Image(thisImage.width, thisImage.height);
      	    PageImages[i].src = imageName + "_on.gif";
		} else if (thisImage.src.lastIndexOf("_on") != -1) {
			PageAltImages[i] = new Image(thisImage.width, thisImage.height);
      	    PageAltImages[i].src = imageName + "_off.gif";
		}
    }
}

addLoadEvent(function() {
 	LoadActiveImages;
	})


/*********************************************************************************
Image Swap
*********************************************************************************/
function imageSwap(which, state) {
     	
	//which - required input of image name
	//state - required input of image rollover state (1 for on, 0 for off)
	//div1,div2,... - optional input layer hierarchy for Netscape 4.0 browsers
	var divNest=''
	var argLength = arguments.length
	
	//loop over the arguments, to check for any passed div id's, and set the nesting
	//used for NN4 only
	if (argLength>2) {
		for (var i = 2; i < argLength; i++)  
		divNest=divNest+'document.'+arguments[i]+'.';
	}
	
	//get the element obj reference
 bw.dom?thisImage=document.getElementById(which):bw.ie4?document.all[which]:thisImage=eval(divNest+"document[which]");
	
	//find the image src name
	var imageName = thisImage.src.substring(0,thisImage.src.lastIndexOf("_o"));
	//toggle the src name based on state
	state == 0?endString = "_off.gif":endString = "_on.gif";
	//alert(layerOver);
	//set the image src to the new src
	bw.dom?thisImage.setAttribute("src",imageName + endString):thisImage.src=imageName + endString;
}

/*********************************************************************************
Window Functions
*********************************************************************************/	

// suppress errors
// uncomment after debugging is complete
/*function stopError() {
	return true;
}
window.onerror = stopError;
*/

if (window.focus) {
	self.focus();
}

function popWindow(URL,name,widgets) {
	popwin = window.open(URL,name,widgets);
	popwin.focus();	
	popwin.opener = self;
	popwin.name = name;
	// wrap in an if statement; don't rename if window.name already exists
	//window.name = "MainWin";			
}

function closeWin(){
	window.close()
}

//  *** To Do: Add French translation
function printPage(lang) {
  if (window.print) {
    window.print() 
  } else if (lang == "FR") {
    alert("D&eacute;sol&eacute;, votre fureteur ne supporte pas cette fonction.\n[Fr reqd] Use the print option on your browser to print this page"); 
  } else  {
    alert("Sorry, your browser doesn't support this feature. \nUse the print option on your browser to print this page"); 
  } 
}


function back1Page() {
	if (window.history) {
	 window.history.go(-1);
  } else {
  	alert("Sorry, your browser doesn't support this feature. \nUse the back button on your browser to return to the previous page"); 
  }
/* [Fr req'd] Modify function to take language argument for error message?
D&eacute;sol&eacute;, votre fureteur ne supporte pas cette fonction.\nUtilisez plutÃ´t le bouton marche arriÃ¨re du fureteur pour reculer dans l'affichage 
*/
}

/**************************************************************************************
show and hide a div
**************************************************************************************/
function getStyleObject(strId) {
	//alert(strId);
	if (document.getElementById && document.getElementById(strId)) {
		return document.getElementById(strId).style;
	} else if (document.all && document.all(strId)) {
		return document.all(strId).style;
	} else {
		return false;
	}
}
	
function fnShow(aryDivId) {
	for (i=0; i < aryDivId.length; i++) {
		if (aryDivId[i] != undefined){
			document.getElementById(aryDivId[i]).style.display = "block"; 
		}
	}	
}

function fnHide(strDivId) {
	var objStyle = document.getElementById(strDivId);
	objStyle.style.display = "none"
}

function fnExpand(strBoxId,strDivId) {
	var checked = document.getElementById(strBoxId).checked;
	var objStyle = document.getElementById(strDivId);
	
	if(!checked){
		objStyle.style.display = "none"
	}else{
		objStyle.style.display = "block"; 
	}
	
}

function toggleImg(imgId, imgFileName, srcFolder) {
	// *** Note: srcFolder is optional. It can be included if the image to be swapped is not located in /images/ 
	// (i.e. /images/en)
	var argLength = arguments.length;
	var imgFolder = "/images/";	
	if (argLength > 2) {
		imgFolder = imgFolder + srcFolder + '/';
	}
	var strFileExtension = ".gif";
	//alert(imgFolder + imgFileName + strFileExtension);
	document.getElementById(imgId).src = imgFolder + imgFileName + strFileExtension;
}

//  *** To Do: Add French translation
function confirmDelete (lang,record) {
	if (record == "loc") {
		if (lang == "FR") {
			return confirm('Etes-vous certain de vouloir supprimer la collection et tous ses objets dâapprentissages? Cette action ne peut Ãªtre annulÃ©e.');	
		} else {
			return confirm('Are you sure you want to delete the Collection and all its Learning Objects? This action cannot be undone!');
		}
	} else if (record == "lo") {
		if (lang == "FR") {
			return confirm('Etes-vous certain de vouloir supprimer lâobjet et tous ses actifs numÃ©riques? Cette action ne peut Ãªtre annulÃ©e.');	
		} else {
			return confirm('Are you sure you want to delete the Learning Object and all its Digital Assets? This action cannot be undone!');
		}		
	} else {
		if (lang == "FR") {
			return confirm('Etes-vous certain de vouloir supprimer lâactif numÃ©rique? Cette action ne peut Ãªtre annulÃ©e.');	
		} else {
			return confirm('Are you sure you want to delete the Digital Asset and all the associated information? This action cannot be undone!');
		}			
	}		
}

/*not in use*/
function checkFileExt(file){
	var fileName = file;
	fileArr = new Array();
	fileArr = fileName.split(".");
	len = fileArr.length ;
	ext = fileArr[len];
	return ext;
}

function checkImage(){
	var fileEn = window.document.forms['0'].filenameEn.value;
	
	var extEn = checkFileExt(fileEn);
	
	alert(extEn);
	if(extEn != "gif" || extEn != "jpg" || extEn != "jpeg"){
		msg = "English Image file is not a gif or jpeg.";
	}
	
	/*var fileFr = window.document.forms['0'].filenameFr.value;
	var extFr = checkFileExt(fileFr);
	
	if(extFr != "gif" || extFr != "jpg" || extFr != "jpeg"){
		msg = "French Image file is not a gif or jpeg.";
	}*/
	
	if (!msg  == ""){
		alert(msg);
		return false;
	} else {
		return true;
	}
}

//  *** To Do: Add French translation
function bookmark (url, title, lang) {
	
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	} else {
		if (lang == 'EN') {
			alert("Sorry, your browser doesn't support this feature.");
		} else {
			alert("D&eacute;sol&eacute;, votre fureteur ne supporte pas cette fonction.");
		}
	}
	
}

function displayCharMax(myfield,msg)
{
  if (myfield.value.length==0) {
    myfield.value=msg;
   }
}

function clearCharMax(myfield,msg)
{
  if (myfield.value==msg) {
    myfield.value='';
  }
}



