/*====================================================================
= User Interface Functins
====================================================================*/
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*====================================================================
= Locale functions
====================================================================*/
function selectLocale(sltObj, formObj, action) {
//sltObj.options[sltObj.selectedIndex].value;	
formObj.page.value = action;
formObj.submit();
}
/*======================================================================
= functions to be used in portal pages
=========================================================================*/
function searchCourseByCatalog(parentId, cvalue, isGuest, action) {
form = document.getElementById("catalogListFormId");
if(action!=null && action!=""){
form = document.getElementById("searchseccatForm");
form.page.value = action;
}
form.keyword.value = cvalue;
form.parentId.value=parentId;
//alert("parentId = "+parentId);	
if(validateUser(isGuest)){
form.submit();	
}
}
function categoryCheckBox(cbId){
form = document.getElementById("searchCourseFormId");
cbSites = form.cbSites;
cbCatalog = form.cbCatalog;
bool = false;
cbSites = new Array();
totalSize = -1;
count = 0;
index=0;
for(i=0; i<form.elements.length;i++){ 
if(form.elements[i].type=="checkbox"){ 
cbSites[index] = form.elements[i];
if(form.elements[i].checked==true){
if(index>0){
count++;
}
}
totalSize++;
index++;
}	
}	
if(cbId==cbSites[0].id){
cbSites[0].checked = true;
for(j=0;j<cbSites.length;j++){
if(j>0){	
cbSites[j].checked=false;
}
}
}else{
cbSites[0].checked=false;
if(count == totalSize){
for(j=0;j<cbSites.length;j++){
if(j>0){	
cbSites[j].checked=false;
}else{
cbSites[j].checked=true;
}
}
}
}	
}
function searchEncyclopediaByPage(value, isGuest)
{
form = document.getElementById("searchForm");	
form.pageNumber.value = value;	
if(validateUser(isGuest)){
form.submit();
}
}
function searchCourseByCategory(catId, isGuest) {
form = document.getElementById("courseCategoryFormId");
form.crsCategory.value = catId;	
if(validateUser(isGuest)){
form.submit();
//temporarily disabled
}
}
function validateUser(isGuest){	
if(ipAuth() && !ipPass()){	
promptUserAccess("ip");
return false;
}
if(requireLogin()){
if(isGuest==null || isGuest=="true"){
promptUserAccess("login");
return false;
}
}	
return true;
}
function showCourseByCatalog(value, action){
form = document.getElementById("searchcatForm");
form.page.value = action;	
form.pageNumber.value = "1";
form.crsCatalogId.value = value;
form.submit();
}
function showCourse(value, action, actionUrl) {
form = document.getElementById("searchcatForm");
form.page.value = action;
if(actionUrl!=null && actionUrl != ""){	
form.action = actionUrl;	
}	
form.pageNumber.value = "1";
form.crsCategory.value = value;
form.submit();
}
function showCategoryCourse(value, action,countCategory,categoryKeyword, actionUrl) {
form = document.getElementById("searchseccatForm");
form.page.value = action;
form.countCategory.value=countCategory;
form.categoryKeyword.value=categoryKeyword;
if(actionUrl!=null && actionUrl != ""){	
form.action = actionUrl;	
}	
form.pageNumber.value = "1";
form.catalogParentId.value = value;
form.submit();
}
function showCategoryCatalogCourse(value, action,isCatalog, sourceCount, actionUrl) {
form = document.getElementById("searchseccatForm");
form.page.value = action;
if(sourceCount!=null && sourceCount != "")
form.sourceCount.value=sourceCount;
//form.categoryKeyword.value=categoryKeyword;
if(actionUrl!=null && actionUrl != ""){	
form.action = actionUrl;	
}	
form.pageNumber.value = "1";
if(isCatalog!=null && isCatalog != "")
form.crsCatalogId.value=isCatalog;
if(value!="0"){
form.catalogParentId.value = value;
}
//form.crsCategory.value = cvalue;	
form.submit();
}
var newCourseWindow;
var childStatus;
var childWinType;
function launchCourse(isTraining, newWin, trnId, winH, winW){	
if(newWin!=null){
//alert(newWin);
if(newWin=="Y"||newWin=="F"){	
childWinType=newWin;	
if(winH==null || winH <= 0){
winH = 450;
}
if(winW==null || winW <= 0){
winW = 550;
}
if(isTraining==null || isTraining=='false'){
action = "launch_course_quick";
params = "courseId="+trnId;
}else{
action = "launch_course";
params = "trainId="+trnId;
}	
if(newCourseWindow!=null){
newCourseWindow.close();
childStatus="close";
}
if(isTraining=='scorm'){
form = document.getElementById("myResourceForm");
form.action = "LearnPlanServlet?page="+action+ "&" + params;
form.submit();
}else{
//var curDateTime = new Date();
//params += "&localTime="+curDateTime.getTime();
newCourseWindow = window.open("LearnPlanServlet?page="+action+ "&" + params, "mybookwindow", "scrollbars=yes,toolbars=yes,status=no,resizable=yes,width="+winW+",height="+winH);
//alert(newCourseWindow+" id "+trnId);
newCourseWindow.focus();
childStatus="open";
}	
}
}else{
//in case the course editors did not make this course launch in new window.
alert("This course could not be launched in the same window.")
}
}
function rssFeed(value1)
{
form = document.getElementById("rssFormId");
form.submit();
}
function getEncyclopedia(value, isGuest)
{	
if(validateUser(isGuest)){
form = document.getElementById("getEncyclopediaForm");	
form.page.value = "search_encyclopedia";	
form.alphabetId.value = value;	
//temporarily disabled
form.submit();
}
}
function setEditorValue(instanceName, text)
{ 
// Get the editor instance that we want to interact with.
var oEditor = FCKeditorAPI.GetInstance( instanceName ) ; 
// Set the editor contents.
oEditor.SetHTML( text ) ;
}
var IFrameObj; // our IFrame object
function callToServer(tvalue) {
if (!document.createElement) {return true};
var IFrameDoc;
var URL ='server.jsp';
//if(tvalue!=null&&tvalue!="") URL+='?trnId='+tvalue;//server.html';
if(tvalue!=null&&tvalue!="") URL=tvalue;//+childStatus;
childStatus='open';
//alert(URL);
if (!IFrameObj && document.createElement) {
// create the IFrame and assign a reference to the
// object to our global variable IFrameObj.
// this will only happen the first time 
// callToServer() is called
try {
var tempIFrame=document.createElement('iframe');
tempIFrame.setAttribute('id','RSIFrame');
//tempIFrame.setAttribute( 'onLoad','window.parent.iframeStartPingServer()');
//tempIFrame.setAttribute( 'onUnload' ,'window.parent.postFinalSessionTime()');
tempIFrame.style.border='0px';
tempIFrame.style.width='0px';
tempIFrame.style.height='0px';
IFrameObj = document.body.appendChild(tempIFrame);
if (document.frames) {
// this is for IE5 Mac, because it will only
// allow access to the document object
// of the IFrame if we access it through
// the document.frames array
IFrameObj = document.frames['RSIFrame'];
}
} catch(exception) {
// This is for IE5 PC, which does not allow dynamic creation
// and manipulation of an iframe object. Instead, we'll fake
// it up by creating our own objects.
iframeHTML='<iframe id="RSIFrame" ';//onLoad="window.parent.iframeStartPingServer()" onUnload="window.parent.postFinalSessionTime()" '; 
iframeHTML+='style="';
iframeHTML+='border:0px;';
iframeHTML+='width:0px;';
iframeHTML+='height:0px;';
iframeHTML+='"><\/iframe>';
document.body.innerHTML+=iframeHTML;
IFrameObj = new Object();
IFrameObj.document = new Object();
IFrameObj.document.location = new Object();
IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
IFrameObj.document.location.replace = function(location) {
this.iframe.src = location;
}
}
}
if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
// we have to give NS6 a fraction of a second
// to recognize the new IFrame
setTimeout('callToServer()',10);
return false;
}
if (IFrameObj.contentDocument) {
// For NS6
IFrameDoc = IFrameObj.contentDocument; 
} else if (IFrameObj.contentWindow) {
// For IE5.5 and IE6
IFrameDoc = IFrameObj.contentWindow.document;
} else if (IFrameObj.document) {
// For IE5
IFrameDoc = IFrameObj.document;
} else {
return true;
}
IFrameDoc.location.replace(URL);
return false;
}
function removeIframe(){
adSidebar = document.getElementById('RSIFrame');
if (adSidebar) {
adSidebar.parentNode.removeChild(adSidebar);
}
}
function handleResponse() {
alert('this function is called from server.html ok?')
}
/*======================================================================
= tree menu bar scripts
=========================================================================*/
var menuids=["treemenu1"] //Enter id(s) of UL menus
function buildsubmenus_horizontal(){	
for (var i=0; i<menuids.length; i++){	
menuId = document.getElementById(menuids[i]);
if(menuId!=null){	
var ultags=menuId.getElementsByTagName("ul")
for (var t=0; t<ultags.length; t++){	
if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
}
else{ //else if this is a sub level menu (ul)
ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
}
ultags[t].parentNode.onmouseover=function(){
this.getElementsByTagName("ul")[0].style.visibility="visible"
}
ultags[t].parentNode.onmouseout=function(){
this.getElementsByTagName("ul")[0].style.visibility="hidden"
}
}
}
}
}
if (window.addEventListener){
window.addEventListener("load", buildsubmenus_horizontal, false);
}
else if (window.attachEvent){
window.attachEvent("onload", buildsubmenus_horizontal)	
}
function gotoPage(id){
form = document.menuBarForm;
form.id.value = id;	
form.submit();
}
/*======================================================================
= end tree menu bar scripts
=========================================================================*/
/*=======================================================================
= Norvatis function
==========================================================================*/
function gotoSecuredPage(url, isGuest){
if(validateUser(isGuest)){
securedPage = window.open(url, 'newWindow', 'width=600,height=500,toolbar=no,status=yes,resizable=yes');
securedPage.focus();
}
}

