// JScript File

window.setTimeoutEx = function(fRef, mDelay) {
//debugger
    if(typeof fRef == 'function')
    {
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function(){ fRef.apply(null, argu); });
        return window.setTimeout(f, mDelay);
    }
        return window.setTimeout(fRef,mDelay);
    }
    
    
window.setIntervalEx = function(fRef, mDelay) {
    if(typeof fRef == 'function')
    {
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function(){ fRef.apply(null, argu); });
        return  window.setInterval(f, mDelay);
    }
        return  window.setInterval(fRef,mDelay);
    }    
	
var m_curLesson = null;
var strCache = null;
var m_oStudyMode1=null;
var objCache = null;



function OnLessonDownloaded(result)
{
   //debugger
    m_curLesson = result;
   
   document.all("panel0").style.display="none";
   document.all("panel1").style.display="";
		       
   m_oStudyMode1 = new StudyMode1("panel1",m_curLesson);
   m_oStudyMode1.Init();
   
}

function DoJudge()
{
	 if(m_oStudyMode1!=null)
	 {
	 	m_oStudyMode1.DoJudge();
	 }
	
}

function saveCache()
{
//debugger
   strCache = document.all("panel1").innerHTML;
    
  //objCache = m_oStudyMode1.snap();
}

function GoNextQuestion()
{
//debugger
   StopSound();
   saveCache();
   LoadData();
    
}

function GoPreQuestion()
{    
     StopSound(); 
     document.all("panel1").innerHTML = strCache;
    
}

function StopSound()
{
//debugger

   wmp1.controls.stop();
   if (IsEnableVCOnline())
   {
         if (document.all("VCOnline1").IsRecording())
         {
              document.all("VCOnline1").RecordStop();
         }
   }
     
}

function PageMethodsState(callBackFunc)
{
 
   this.TimeId = null;
   
   this.CallBackFunc = callBackFunc;
   
   //public
   this.Check = function()
   {
        this.TimeId = window.setTimeoutEx(this.CheckBody,10,this);
            
   }
   
   //private 
   this.CheckBody = function(webData)
   {
     
     if ( typeof(PageMethods) == "undefined" )
     {
        window.clearTimeout(webData.TimeId);
        webData.TimeId = window.setTimeoutEx(webData.CheckBody,10);
        return;
     }  
     
     webData.CallBackFunc();
   }
  
     
}

function OnPageMethodReady()
{
    //debugger;
    //alert(document.all("panel0"));
    PageMethods.DownloadLesson(OnLessonDownloaded);
}

function LoadData()
{
    document.all("panel0").style.display="";
    document.all("panel1").style.display="none";
    
    pms.Check(OnPageMethodReady);
    

}
var pms =null;
document.body.onload = function()
{
    //debugger;
    
    pms = new PageMethodsState(OnPageMethodReady);  
   
    document.all("panel0").style.display="";
    LoadData();
   
} 


function IsEnableVCOnline ()
{
    try
    {
        var c = 0;
        c = document.all("VCOnline1").RefColor;
        if ( c == null || typeof(c) == 'undefined')
        {
            return false;
        }
        return true;
    }
    catch (e)
    {
        return false;
    }
}
    
    
function GetMediaFile(fileName)
{
    if (IsEnableVCOnline() ==  true)
    {
        return document.all("VCOnline1").GetLocalPathFileName(fileName);
    }
    return fileName;    
    
}

