﻿var OpenedWin;
var LangWin;
var HelpWin;
var GuideWin;
var startPath="";

 //This function Launches a lessons.
function LaunchSCO(ScoID,TreeID)
{
    var src
    src="ScoLauncher.aspx?TreeID=" + TreeID + "&scoID=" + ScoID + "&scoFilename=Content/SCOs/" + ScoID + "/" + ScoID +".htm";
    OpenedWin=window.open(src,'LessonWin','scrollbars=1, channelmode = 0, directories = 0,menubar = 0,resizable = 1,status = 0,titlebar = 0,toolbar = 0,width=790, height=528');
    window.OpenedWin.focus();
}
 //This function Launches a test.
function LaunchTest(ScoID,TreeID)
{
    var src
    src="TestLauncher.aspx?TreeID=" + TreeID + "&ScoID=" + ScoID + "&scoFoldername=Content/SCOs/" + ScoID + "&scoFileName=ex_" + ScoID +".xml";
    
    OpenedWin=window.open(src,'LessonWin','scrollbars=1, channelmode = 0, directories = 0,menubar = 0,resizable = 0,status = 0,titlebar = 0,toolbar = 0,width=790, height=523');

    window.OpenedWin.focus();
}
//This function Opens the Help Window.
function OpenHelp()
{
    var src
    src="Components/Help/HelpFrame.aspx";
    
    HelpWin=window.open(src,'HelpWin','scrollbars=1, channelmode = 0, directories = 0,menubar = 0,resizable = 0,status = no,titlebar = 0,toolbar = 0,width=800, height=600');

    window.HelpWin.focus();
}

//This function Opens the Learner's Guide.
function OpenGuide()
{
    var src
    src="Components/ScholarLearner/SLFrame.aspx";
    
    GuideWin=window.open(src,'GuideWin','scrollbars=1, channelmode = 0, directories = 0,menubar = 0,resizable = 0,status = 0,titlebar = 0,toolbar = 0,width=800, height=600');

    window.GuideWin.focus();
}

 //This Opens the Select Language window -Changed to menu (Miri)
/*function SelectLang(){
   
   
    var src
    src=startPath + "/Browse/LanguageSelection.aspx";
    
    LangWin=window.open(src,'LangWin','scrollbars=1, channelmode = 0, directories = 0,menubar = 0,resizable = 1,status = 0,titlebar = 0,toolbar = 0,width=200, height=150');

    window.LangWin.focus();
}*/

function Reconected(){
    try { 
        xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
        try {
            xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
        } catch(e) {
            xmlHttp = false;
        }
    }

    if(xmlHttp){
       var TMID = new Date
       xmlHttp.open('GET', startPath + '/Reconected.aspx?TMC=' + TMID.getTime(), false); 
       xmlHttp.send();
       //alert(xmlHttp.responsetext);
    }
    //SetMenuPos('menu_1','spnLang');
    self.setTimeout('Reconected()',40000)
} 
function closewindows(){

    if (OpenedWin != null){ 
        OpenedWin.close();
    }

    if (LangWin != null){ 
        LangWin.close();
    }

    if (HelpWin != null){ 
        HelpWin.close();
    }

    if (GuideWin != null){ 
        GuideWin.close();
    }

}
function AutoLogout(){

    if (event.clientY < 0) { //Only if the window is closed
    
        try { 
            xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e) {
            try {
                xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
            } catch(e) {
                xmlHttp = false;
            }
        }

        if(xmlHttp){
           var TMID = new Date
           xmlHttp.open('GET', startPath + '/Browse/logoff.aspx?TMID=' + TMID.getTime(), false); 
           xmlHttp.send();
           //alert(xmlHttp.responsetext);
        }
        
        closewindows();

    }
}
 
 function GetXMLData(xmlfile){
        //Input:    The XML file (including file path).
        //output:   The data from the XML file.
        //This function imports data from a XML file.
        //If the browser doesn't support this function - return false
        
            //var XMLdata //temporery data holder.
                        
            //Checks the users' browser
            if (window.ActiveXObject) //IE
            {
                XMLdata=new ActiveXObject("Microsoft.XMLDOM");
                XMLdata.async=false;
                XMLdata.load(xmlfile);              
                return XMLdata
            }
            else if (document.implementation && document.implementation.createDocument) //Mozilla, Firefox, Opera, etc.
            {
                XMLdata=document.implementation.createDocument("","",null);
                XMLdata.load(xmlfile);
                return XMLdata
            }
            else //Unsupported browser
            {
            	alert('Your browser cannot handle this script');
            	return false
            }
        
        }

function RotateBanners(xmlFile, i, bannerPlacement,bannerImage)
{
    var xmlObj = GetXMLData(xmlFile);
    var nodesArray = xmlObj.selectNodes('//Ad');
    var currNode;
    if (i > nodesArray.length)
    {
        i = 1;
    } 
    currNode = nodesArray[i-1];
    document.getElementById(bannerImage).src = currNode.getAttribute('ImageUrl');
    document.getElementById(bannerPlacement).href = currNode.getAttribute('NavigateUrl');
    
    i++;
    window.setTimeout("RotateBanners('"+xmlFile+"',"+i+",'"+bannerPlacement+"','"+bannerImage+"')", 6000);
}
function RotateBannersErrorPage(xmlFile, i, bannerPlacement,bannerImage)
{
    var xmlObj = GetXMLData(xmlFile);
    var nodesArray = xmlObj.selectNodes('//Ad');
    var currNode;
    if (i > nodesArray.length)
    {
        i = 1;
    } 
    currNode = nodesArray[i-1];
    document.getElementById(bannerImage).src = "Browse/" + currNode.getAttribute('ImageUrl');
    document.getElementById(bannerPlacement).href = currNode.getAttribute('NavigateUrl');
    
    i++;
    window.setTimeout("RotateBannersErrorPage('"+xmlFile+"',"+i+",'"+bannerPlacement+"','"+bannerImage+"')", 6000);
}
function showMenu(inner, outer)
{
   inner.firstChild.border="2px";
   inner.firstChild.borderColor="#b6b6e3";
   inner.firstChild.style.visibility = "visible";
   inner.style.visibility = "visible";
   
   //menu.firstChild.style.display = "block";
   //menu.style.display = "block";
   //menu.style.zIndex = 200;
    
   
   if(outer != null)
   {
     outer.style.display = "block";
   }
}

function hideMenu(menu)
{
   menu.style.visibility = "hidden";
   menu.firstChild.style.visibility = "hidden";
   //menu.style.display = "none";
   //menu.firstChild.style.display = "none";
             
}
function menuOn(td)
{
   td.style.backgroundColor = "#c0e5ff";
  
}
function menuOut(td)
{
   td.style.backgroundColor = "";
   
}
 
 function SetMenuPos(menu,spn)
 {
    var LangSpan=document.getElementById(spn); 
   
    var curleft =  0;
    var curTop= 0;
    var menu;
    menu= document.getElementById(menu);
   
  
	if (LangSpan.offsetParent) {
		curleft = LangSpan.offsetLeft
		curTop= LangSpan.offsetTop
		while (LangSpan = LangSpan.offsetParent) {
			curleft += LangSpan.offsetLeft
			curTop+= LangSpan.offsetTop
		}
	}
	 
   
    menu.style.top = curTop + 13;
    menu.style.left = curleft;
    menu.style.visibility = "hidden";
//    menu.firstChild.border="0px";
//    menu.firstChild.style.visibility = "hidden";
   
 
 }
 function OpenWindow(url,mode)
{
    var popUpWin = window.open(url,"",mode);
    
    //Get the focus
    popUpWin.focus();

}

