﻿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/Help.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?TMID=' + TMID.getTime(), false); 
       xmlHttp.send();
       //alert(xmlHttp.responsetext);
    }
    
    // set menu position of language,help links
    SetMenuPos('menu_1','spnLang');
    SetMenuPos('spnHelp2','spnHelp');
    SetMenuPos1('spnHelpNew','spnSupport1');
    SetMenuPos2('menu_2','spnCurLanguage','spnHelpNew');
   
    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(menu1,spn1)
{
//debugger;
  var menu=menu1;  // menu of open link
  var spn=spn1;    // span that the menu is in him
   menu= document.getElementById(menu);
   menu.firstChild.border="2px";
   menu.firstChild.borderColor="#b6b6e3";
   menu.firstChild.style.visibility = "visible";
   menu.style.visibility = "visible"; 
   
   spn = document.getElementById(spn);
   if(spn != null)
   {
     spn.style.display = "inline";
   }
}

function showMenuNew(menu1,spn1)
{
//debugger;
  var menu=menu1;  // menu of open link
  var spn=spn1;    // span that the menu is in him
   menu= document.getElementById(menu);
   //menu.firstChild.border="2px";
   //menu.firstChild.borderColor="#b6b6e3";
   menu.firstChild.style.visibility = "visible";
   menu.style.visibility = "visible"; 
   spn = document.getElementById(spn);
   if(spn != null)
   {
     spn.style.display = "inline";
   }
}

function hideMenu(menu1)
{
    var menu=menu1; // menu of open link
   menu= document.getElementById(menu);
   menu.style.visibility = "hidden";
   menu.firstChild.style.visibility = "hidden";
             
}
function menuOn(td)
{
   td.style.backgroundColor = "#c0e5ff";
  
}
function menuOut(td)
{
   td.style.backgroundColor = "";
   
}
 
 function SetMenuPos(menu,spn)
 {
    
    var spnLang=document.getElementById(spn); 
    if (spnLang)
    {
    var LangSpan = spnLang.parentElement;
    
    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 get_firstchild(n)
    {
        x=n.firstChild;
        while (x.nodeType!=1)
        {
            x=x.nextSibling;
        }
        return x;
    }

 
    function SetMenuPos1(menu,spn)
    {
        var spnLang = document.getElementById(spn);        
        if (spnLang)
        {            
            //var LangSpan = spnLang.parentElement;
            var LangSpan = spnLang.parentNode;
            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-11;
            //alert( document.getElementById("spnSupport1").clientLeft);
            //menu.style.left = curleft;
            menu.style.left = 185;
             //document.getElementById("spnSupport").offsetLeft+ 461;
            menu.style.visibility = "hidden";
            var FirstChildObj = get_firstchild(menu);
            FirstChildObj.border="0px";
            FirstChildObj.style.visibility = "hidden";
            //menu.firstChild.border="0px";
            //menu.firstChild.style.visibility = "hidden";
        } 
    }
 
    function SetMenuPos2(menu,spn,menu1)
    {
        var spnLang=document.getElementById(spn); 
        if (spnLang)
        {
            //var LangSpan = spnLang.parentElement;
            var LangSpan = spnLang.parentNode;
            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
                }
            }
            menu1= document.getElementById(menu1);
            //alert(curTop)
            menu.style.top = -3-menu1.clientHeight;
            //alert(curleft);
            //menu.style.left = curleft;
            menu.style.left = 57;
            menu.style.visibility = "hidden";
            var FirstChildObj = get_firstchild(menu);
            FirstChildObj.border="0px";
            FirstChildObj.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
    if(popUpWin)
        popUpWin.focus();

}
