﻿var OpenedWin;
var LangWin;
var HelpWin;
var GuideWin;
var startPath="";


//  Qkids Old

var openedWindow = new Array();
var CurrChapter = 0 //the CurrChapter.

var availableLanguages = Array({name:"English",abbr:"English"},{name:"Spanish",abbr:"Spanish"},{name:"Greek",abbr:"Greek"},{name:"Korean",abbr:"Korean"},{name:"Russian",abbr:"Russian"},{name:"Turkish",abbr:"Turkish"},{name:"Vietnamese",abbr:"Vietnamese"},{name:"Mongolian",abbr:"Mongolian"},{name:"Portuguese",abbr:"Portuguese"},{name:"Arabic",abbr:"Arabic"},{name:"Japanese",abbr:"Japanese"});
//var availableLanguages = Array({name:"English",abbr:"English"},{name:"Spanish",abbr:"Spanish"},{name:"Mandarin",abbr:"ChineseMandarin"},{name:"Greek",abbr:"Greek"},{name:"Chinese",abbr:"Chinese"},{name:"Hungarian",abbr:"Hungarian"},{name:"Mongolian",abbr:"Mongolian"});
var selectedLanguageObj;

var selectedLanguage = ''; 

function CalculateAbsolutePlace()
{
    //  Calculate place of System Check DIV
    var left = (document.body.clientWidth / 2) - 360;
    var top =  (document.body.clientHeight / 2) - 232;
    if (top<0)top=0;
    if (left<0)left=0;
    syscheck.style.left=left + 180;    
    syscheck.style.top=top;
}


//  Function from QEnglish
 //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()
{
    if(selectedLanguage=="")
    {
       selectedLanguage="English";
    }
    openedWindow.pushIt(window.open("/Browse/Components/Help/"+selectedLanguage+"/default_"+ selectedLanguage + ".htm","forParents","channelmode=no,directories=no,fullscreen=no,height=507,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no,width=670"));    
}

//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');
    
    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);
   
   ///
   if(menu.style.visibility == "hidden")
   {
       menu.firstChild.style.visibility = "visible";
       menu.style.visibility = "visible"; 
       
       spn = document.getElementById(spn);
       if(spn != null)
       {
         spn.style.display = "inline";
       }
   }
   else
   {
       menu.firstChild.style.visibility = "hidden";
       menu.style.visibility = "hidden"; 
   }
   ///
   
}

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); 
    var LangSpan = spnLang;
   
    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 + 45;
    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();

}

function MouseOver(Obj)
{    
    Obj.src = Obj.src.toLowerCase().replace("_normal","_over");    
}

function MouseOut(Obj)
{
    Obj.src = Obj.src.toLowerCase().replace("_over","_normal");    
}

function DivMouseOver(Obj)
{    
    Obj.className = Obj.className.replace("_normal","_over");    
}

function DivMouseOut(Obj)
{
    Obj.className = Obj.className.replace("_over","_normal");    
}


//  QKids old function

Array.prototype.pushIt = function (element) 
{
    var found = false;
    for(var c=0;c<this.length;c++)
        if(element == this[c]) { found = true; this[c].focus(); }
    
    if (!found) this.push(element);
}

function cleanExit()
{
	try{
	        openedWindow.pushIt(scoWin.close());
	}catch(elogoff){}	

}

function launchSCO(scoFilename)
{
    openedWindow.pushIt(scoWin=window.open(scoFilename,"scoWin","channelmode=no,directories=no,fullscreen=no,height=530,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,width=737,left=135,top=100"));
}

function openPDF(pdfDoc)
{
  
    if(selectedLanguage=="")
    {
       selectedLanguage="English";
    }
    if(selectedLanguage=="Greek")
    {
        openedWindow.pushIt(window.open("Components/ParentsGuide/default_" + selectedLanguage + ".htm","forParents","channelmode=no,directories=no,fullscreen=no,height=807,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no,width=1195"));
    }
    else
    {
     openedWindow.pushIt(window.open("Components/ParentsGuide/default_" + selectedLanguage + ".htm","forParents","channelmode=no,directories=no,fullscreen=no,height=507,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no,width=670"));
    }
}

function cleanExit()
{
	try
	{
	    openedWindow.pushIt(scoWin.close());	    
	}
	catch(elogoff){}	
	window.location.href = "logoff.aspx";
}

//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', '/kids/Browse/logoff.aspx?TMID=' + TMID.getTime(), false); 
//           xmlHttp.send();
//           //alert(xmlHttp.responsetext);
//        }        
//        cleanExit();
//    }
//}

//function doLangvForCurrentLangv()
//{	   
//    var LMSGetDataPagePath =  "../WebServer/LMS/Scorm/Server/LMSGetData.aspx?Initialize=true";
//    var returLangvUser = "";
//    var ObjXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
//    var ObjDataModel = new ActiveXObject("Microsoft.XMLDOM");
//    ObjXMLHTTP.open("GET", LMSGetDataPagePath, false);

//    try
//    {
//        ObjXMLHTTP.send();
//    }
//    catch (e)
//    {
//     //alert("Error send XMLHTTP object: " + e.description)
//    }
//    
//    if (ObjXMLHTTP.readyState == 4)
//    {
//        if (ObjXMLHTTP.status == 200)
//        {
//            var xmlData = ObjXMLHTTP.responseText;
//        
//            try
//            {
//              ObjDataModel.loadXML(xmlData)
//            }
//            catch(e)
//            {
//               //alert("Error load XML file");
//            }
//            returLangvUser = ObjDataModel.selectSingleNode("datamodel/cmi/student_preference/language").text;
//        }
//    }    
//    return returLangvUser;
//}

function createLanguagesTable()
{

    var languagestable = document.getElementById("languagestable");
    for(var c=0;c<availableLanguages.length;c++){
        var newRow = languagestable.insertRow();
        var newCell = newRow.insertCell();
        newCell.innerHTML = "<IMG SRC='Images/CheckMark.gif' width=17 height=15 />";
        //newCell.style.background = "#B93700";
        newCell.style.visibility = "hidden";
        availableLanguages[c].imgCell = newCell;
        newCell = newRow.insertCell();
        newCell.innerHTML = "<a class='languagelink' href='#'>"+availableLanguages[c].name+"</a>";
        newRow.setAttribute("lid",c);
        newRow.onclick = selectLanguage;
    }
    
     for(var ii=0;ii<availableLanguages.length;ii++)
    {
        if(availableLanguages[ii].name==strUserLanguage)
        {
           availableLanguages[ii].imgCell.style.visibility = "";
           selectedLanguageObj = availableLanguages[ii];
           selectedLanguage = strUserLanguage;
        }
        else
        {
           availableLanguages[ii].imgCell.style.visibility = "hidden";           
        }
    }
}

function selectLanguage()
{ 
    selectedLanguageObj.imgCell.style.visibility = "hidden";
    selectedLanguageObj = availableLanguages[this.getAttribute("lid")];
    selectedLanguageObj.imgCell.style.visibility = "";   
    selectedLanguage = selectedLanguageObj.abbr;
    DivLang.style.visibility = "hidden";    
    DivLang.firstChild.style.visibility = "hidden";
    //languagestable.style.visibility = "hidden";
    
    
    try {
        	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      	} 
   catch(e) {
        	try {
          		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        	     } 
        	     catch(e) 
        	     {
          		    xmlHttp = false;
        	       }
		}
	if(xmlHttp)
	    {
	    xmlHttp.onready	
	    xmlHttp.open("GET", "SetLanguage.aspx?selectedLanguage=" + selectedLanguage, true);
		xmlHttp.send();
		}
    
    
}

function OpenSysCheck()
{
    //window.open("Components/SysChk/SystemCheck.html","systemreq","location=no,status=no,titlebar=no,height=200");
    //openedWindow.pushIt(window.open("Components/SysReq/default.htm","systemreq","location=no,status=no,titlebar=no,width=495,height=250"));
    var SCtime= new Date();
    //alert(SCtime.getTime());
    syscheckFrame.location.href="/Browse/Components/SysReq/default.aspx?TMID=" + SCtime.getTime() ;
    syscheck.style.display="block";
}

