﻿    /**********************************************************************************************/
    /* These functions are used to capture the video watch times of each visitor.                 */
    /**********************************************************************************************/
    function setDuration(duration1)
    {
        //This duration is passed to us by the flash movie so that we know the video length in seconds.
        var dur  = document.getElementById('hidDuration');
        dur.value = duration1;

    }   
       
    
    function VideoEnded(webisodeid, userid, language){
        //Called when the video ends.
        var duration = document.getElementById("hidDuration")
        var userid = document.getElementById("ctl00_body_content_hidUserId").value
        StopTheClock();
        elapsedTime = secs;
        var querystring = "duration="+duration.value+"&webisodeid="+webisodeid+"&language="+language+"&userid="+userid+"&complete=true&elapsedTime="+elapsedTime;
        var hidRecorded = document.getElementById('hidRecorded');
        if(hidRecorded.value != "true")
        {
            RecordElapsedTime(querystring);
            hidRecorded.value = "true";
        }
    }
    
    function RecordElapsedTime(output)
    {
        //Ajax call to record the how long each video was viewed.
        xmlhttp.open("POST","../AJAX/RecordVideo.aspx",false);
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
       
        xmlhttp.send(output);   
        
        strResponseText = xmlhttp.responseText;    
              
        if (strResponseText != "Recorded")
        {
            ErrorMessage = "Unable to record";
        }
    }
    
    
    
    function VideoInterrupted()
    {
       //the body tag's onunload event will call this. When user leaves this page or refreshes the page.
        var elapsedTime, webisodeid, language, userid, complete, duration
        StopTheClock();
        elapsedTime = secs; // The time that the person has watched
        webisodeid = document.getElementById('ctl00_body_content_hidWebisodeId').value;
        language = document.getElementById('ctl00_body_content_hidLang').value;
        userid = document.getElementById('ctl00_body_content_hidUserId').value;
        duration = document.getElementById('hidDuration').value; // The length of the video
        
        complete = "false";
        var dur1 = document.getElementById('hidDuration');
        var querystring = "elapsedTime="+elapsedTime+"&webisodeid="+webisodeid+"&language="+language+"&userid="+userid+"&complete="+complete+"&duration="+duration;
        var Recorded = document.getElementById('hidRecorded');
        
        
        if(Recorded.value != "true")
        {
            RecordElapsedTime(querystring);
            Recorded.value = "true";
        }
    }
    
   


    
    
    
    var secs
    var timerID = null
    var timerRunning = false
    var delay = 1000

    function InitializeTimer()
    {
        
        // Set the length of the timer, in seconds
        secs = 0
        StopTheClock()
        StartTimer()
    }
  
    function StopTheClock()
    {
      // if(timerRunning)
      //      clearTimeout(timerID)
      //  timerRunning = false
      
        timerRunning = false;
        //if(secs != 0)
        //    alert(secs);
        //clearTimeout(timerID);
    }


    
    function StartTimer()
    {
            self.status = secs;
            secs = secs + 1;
            timerRunning = true;
            timerID = self.setTimeout("StartTimer()", delay);
    }
    

    
   
  
