// Module:	PAL_JavaScript.js 
// Create Date:	02-28-2010
// Purpose:	This file contains the JavaScript for the Palaestra Website

// Change Log:
//   Date	Description
// ============	======================================================


      var XMLHttpRequestObject = false;


// ----------------------------------------------------------------------------------
// This function controls the slideshow in the MyPalaestra banner.
// ----------------------------------------------------------------------------------
function loadpage(slideshow)
{ 
   index1 = 0;
   index2 = 7;
   index3 = 14;

   listofimages = new Array(21);
   listofimages[0] = new Image(203,137)
   listofimages[0].src = "images/DSC05831.jpg"
   listofimages[1] = new Image(203,137)
   listofimages[1].src = "images/DSC07556.jpg"
   listofimages[2] = new Image(203,137)
   listofimages[2].src = "images/DSC07560.jpg"
   listofimages[3] = new Image(203,137)
   listofimages[3].src = "images/DSC07607.jpg"
   listofimages[4] = new Image(203,137)
   listofimages[4].src = "images/DSC07604.jpg"
   listofimages[5] = new Image(203,137)
   listofimages[5].src = "images/DSC07625.jpg"
   listofimages[6] = new Image(203,137)
   listofimages[6].src = "images/DSC05136.jpg"


   listofimages[7] = new Image(203,137)
   listofimages[7].src = "images/funpicoutsidegirls.jpg"
   listofimages[8] = new Image(203,137)
   listofimages[8].src = "images/DSC07588.jpg"
   listofimages[9] = new Image(203,137)
   listofimages[9].src = "images/DSC07598.jpg"
   listofimages[10] = new Image(203,137)
   listofimages[10].src = "images/DSC07544.jpg"
   listofimages[11] = new Image(203,137)
   listofimages[11].src = "images/DSC07660.jpg"
   listofimages[12] = new Image(203,137)
   listofimages[12].src = "images/DSC07647.jpg"
   listofimages[13] = new Image(203,137)
   listofimages[13].src = "images/DSC05138.jpg"


   listofimages[14] = new Image(203,137)
   listofimages[14].src = "images/IMG_8726.jpg"
   listofimages[15] = new Image(203,137)
   listofimages[15].src = "images/DSC07573.jpg"
   listofimages[16] = new Image(203,137)
   listofimages[16].src = "images/DSC07574.jpg"
   listofimages[17] = new Image(203,137)
   listofimages[17].src = "images/DSC07619.jpg"
   listofimages[18] = new Image(203,137)
   listofimages[18].src = "images/DSC07630.jpg"
   listofimages[19] = new Image(203,137)
   listofimages[19].src = "images/DSC07627.jpg"
   listofimages[20] = new Image(203,137)
   listofimages[20].src = "images/DSC05270.jpg"

   if (slideshow == 'y')
   {
      thetimer = setTimeout("changeimage()", 5000);
   }
} 


// ----------------------------------------------------------------------------------
// This function will control the rate of change of the images.
// ----------------------------------------------------------------------------------
function changeimage()
{ 
   index1 = index1 + 1;
   index2 = index2 + 1;
   index3 = index3 + 1;
   if (index1 == "7") 
   { 
      index1 = 0; 
      index2 = 7; 
      index3 = 14; 
   } 
   imagesource1 = listofimages[index1].src;
   imagesource2 = listofimages[index2].src;
   imagesource3 = listofimages[index3].src;
   window.document.banner1.src = imagesource1;
   window.document.banner2.src = imagesource2;
   window.document.banner3.src = imagesource3;

   thetimer = setTimeout("changeimage()", 5000);
} 


// ----------------------------------------------------------------------------------
// This function retrieves the Teacher Bio information.
// ----------------------------------------------------------------------------------
function getStaffData(divID, group)
{
   var display = "<table width=100% border=0>";

   var selection = document.getElementById('choose').selectedIndex;
   var instructID = document.getElementById('choose').options[selection].value;

   var obj =  document.getElementById(divID);
   var dataSource = "staff_data.php?groupid=" + group + "&instructid=" + instructID;

   createXMLHttpRequest();
   XMLHttpRequestObject.onreadystatechange = function()
   {
      if (XMLHttpRequestObject.readyState == 4 &&
          XMLHttpRequestObject.status == 200) 
      {
         var c1;
         var instructor = null;

         var xmlDocument = XMLHttpRequestObject.responseXML;
         var instructor_data = xmlDocument.getElementsByTagName("instructor");

         if (instructor_data.length == 0)
         {
            display = display + "<tr><td>No BIO Found</td></tr>";
         } 
         else
         {
            instructor = instructor_data[0];
            name = instructor.getElementsByTagName("name")[0].firstChild.nodeValue;
            image = instructor.getElementsByTagName("image")[0].firstChild.nodeValue;
            bio = instructor.getElementsByTagName("bio")[0].firstChild.nodeValue;

            display = display + "<tr><td><b>" + name + "</b></td></tr>";
            display = display + "<tr><td>&nbsp;</td></tr>";                  
            if (image == 'Person1.gif')
            {
               display = display + "<tr><td>(no image found)</td></tr>";
            }
            else
            {
               display = display + "<tr><td><img src=\"images/instructors/" + image + "\" border=1></td></tr>";
            }   
            display = display + "<tr><td>&nbsp;</td></tr>";                  
            display = display + "<tr><td><b>" + bio + "</b></td></tr>";                      
         }
         display = display + "</table>";
 
         obj.innerHTML = display;
      } 
   }

   XMLHttpRequestObject.open("GET", dataSource, true);
   XMLHttpRequestObject.send(null);
}


// ----------------------------------------------------------------------------------
// Function to create an HTTP Request.
// ----------------------------------------------------------------------------------
function createXMLHttpRequest()
{
   if (window.XMLHttpRequest) 
   {
      XMLHttpRequestObject = new XMLHttpRequest();
   } 
   else if (window.ActiveXObject) 
   {
      XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
   }
}


// ----------------------------------------------------------------------------------
// Function to resubmit a page with new parameters. 
//   page_name parameter will be used if we just need to resubmit a standard URL.
//   page_url parameter will be used if we need special elements on the URL.
// ----------------------------------------------------------------------------------
function resubmitpage(page_name, page_url)
{
   document.myform.action=page_url;
   document.myform.submit();
}
