﻿var xmlHttp;
var currentInstructor;

function getInstructor(id)
{ 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
      alert ("Your browser does not support AJAX!");
      return;
    } 
    var url="GetInstructor.aspx";
    url=url+"?instructorID="+id;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function stateChanged() 
{ 
    if (xmlHttp.readyState==4)
    { 
        document.getElementById("DivInstructor").innerHTML = xmlHttp.responseText;
        document.getElementById("DivShadow").innerHTML = xmlHttp.responseText;
    }
    else
    {
        document.getElementById("DivInstructor").innerHTML = "Loading instructor...<br /><br />";
        document.getElementById("DivShadow").innerHTML = "Loading instructor...<br /><br />";
    }
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
      {
          // Firefox, Opera 8.0+, Safari
          xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
          // Internet Explorer
          try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
          catch (e)
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
      }
    return xmlHttp;
}

function showInstructor(instructorID, top, left) {
    var EmergencyDiv = document.getElementById('EmergencyMessage');
    var offsetEmergencyDiv = 0;
    var offsetEmergencyDiv2 = 0;
    if (EmergencyDiv) {
        offsetEmergencyDiv = EmergencyDiv.offsetHeight;
    }
    //alert(navigator.userAgent);
    if(navigator.userAgent.indexOf('Firefox') > -1)offsetEmergencyDiv2 = 30;
    if (currentInstructor == null){ currentInstructor = instructorID; }
    getInstructor(instructorID);
    var instructorDiv = document.getElementById('DivInstructor');
    var shadowDiv = document.getElementById('DivShadow');
    //alert(offsetEmergencyDiv2);
    top = (top + offsetEmergencyDiv) - offsetEmergencyDiv2;
    instructorDiv.style.top = top + 'px';
    instructorDiv.style.left = left + 'px';
    shadowDiv.style.top = (top + 10) + 'px';
    shadowDiv.style.left = (left + 10) + 'px';
    if(instructorDiv.style.display == 'block' && currentInstructor != instructorID){
        instructorDiv.style.display = 'block';
        shadowDiv.style.display = 'block';
        currentInstructor = instructorID;
        return;
    }
    if(instructorDiv.style.display == 'none'){
        instructorDiv.style.display = 'block';
        shadowDiv.style.display = 'block'
    } else {
        instructorDiv.style.display = 'none';
        shadowDiv.style.display = 'none';
    }
    currentInstructor = instructorID;
}

function closeInstructor(){
    document.getElementById('DivInstructor').style.display = 'none';
    document.getElementById('DivShadow').style.display = 'none';
}