/**
 * @author Nektarios Gioldasis, TUC/MUSIC
 * @project Digital Library of ECE Deptartment of TUC
 * @version 1.0
 * 
 * Copyright 2008 Nektarios Gioldasis. All Rights Reserved.
 *  
 */
/*This script contains JavaScript Fuctions used in Ajax Interaction styles*/
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;

/****************************************************************************** 
* create the asynchronous requests objects 
*******************************************************************************/ 
function createRequest() {
   try {
      xmlHttp = new XMLHttpRequest();     
   } catch (trymicrosoft) {
      try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");      
      } catch (othermicrosoft) {
        try {
           xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");           
        } catch (failed) {
           xmlHttp = false;           
        }
    }
   }

   if (!xmlHttp)
      alert("Error initializing XMLHttpRequest!");  
}

/****************************************************************************** 
* show/update the body div of the container div
*******************************************************************************/ 
function showDataInBody(action, divID) {     
    createRequest();
   // Build the URL to connect to
   //var url = baseURL + action;  
   var currentDate = new Date();
    action+= "&REFRESH=" + new Date().getTime();
   // Open a connection to the server
   xmlHttp.open("GET", action, true); 
   // Setup a function for the server to run when it's done
   xmlHttp.onreadystatechange = function () {updateDataInBody(divID);};

   // Send the request
   xmlHttp.send(null);
   
   // Show the progress indicator
   //d.getElementById("body").innerHTML = "<img align='absmiddle' alt='progress' src=./images/progressIndicator.gif> loading...";
}

function updateDataInBody(divID) {   
  
   if (xmlHttp.readyState == 4) {   
      if (xmlHttp.status == 200) {        
         var response = xmlHttp.responseText;         
         document.getElementById(divID).innerHTML = response; 	        
      }	
      else if (xmlHttp.status == 404) {
         alert("Request URL does not exist");
      }
      else {
         alert("Error: status code is " + xmlHttp.status);
      }
   }
}

function showHideObj(action, objID){    
    var obj = document.getElementById(objID);        
    if (obj.style.visibility == "hidden"){
        //alert("SHOW");
        showDataInBody(action, objID);        
        obj.style.visibility = 'visible';
        obj.style.overflow = 'visible';
        obj.style.height = '100%';        
    }else if(obj.style.visibility == "visible"){
        obj.style.visibility = 'hidden';
        obj.style.overflow = 'hidden';
        obj.style.height = '0px';
        //alert("HIDE");
    }
}