function initHttpRequest() {
  var httpRequest;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    httpRequest = new XMLHttpRequest();
    if (httpRequest.overrideMimeType) {
      httpRequest.overrideMimeType('text/xml');
    }
  } 
  else if (window.ActiveXObject) { // IE
    try {
      httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
      try {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e) {
      }
    }
  }
  return httpRequest;
}

function execUrl(url, displayId) {
  var httpRequest = initHttpRequest();
  
  if (!httpRequest) {
    return false;
  }
  httpRequest.onreadystatechange = function() {  
	if (displayId != null) {
	  displayData(httpRequest, displayId);
    }
  };
  httpRequest.open('GET', url, true);
  httpRequest.send(null);
}

function ajaxObject(url, callbackFunction) {
  var that=this;      
  this.updating = false;

  this.update = function(passData,postMethod) { 
    if (that.updating==true) { return false; }
    that.updating=true;                       
    var AJAX = null;                          
    if (window.XMLHttpRequest) {      // Mozilla, Safari, ...        
      AJAX=new XMLHttpRequest();      
      if (AJAX.overrideMimeType) {
      	AJAX.overrideMimeType('text/xml');
    }        
    }else if (window.ActiveXObject) { // IE
    try {
      AJAX = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
      try {
        AJAX = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e) {
      }
    }
  }
  else {                                  
      AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }                                             
    if (AJAX==null) {                             
      return false;                               
    } else {
      AJAX.onreadystatechange = function() {  
        if (AJAX.readyState==4) {             
          that.updating=false;                
          that.callback(AJAX.responseText,AJAX.status,AJAX.responseXML);        
          delete AJAX;                                         
        }                                                      
      }                                                        
      var timestamp = new Date();                              
      if (postMethod=='POST') {
        var uri=urlCall+'&'+timestamp.getTime();
        AJAX.open("POST", uri, true);
        AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        AJAX.send(passData);
      } else {
        var uri=urlCall+'&'+passData+'&timestamp='+(timestamp*1); 
        AJAX.open("GET", uri, true);                     
        AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}  

function attachScript(responseText, responseStatus) {
   // This function is called by the ajaxObject when the server has finished
         // sending us the requested script.
   		if (responseStatus==200) {
            eval(responseText);
         }
}    
    

function displayData(httpRequest, displayId) {
  if (httpRequest.readyState == 4) {
    if (httpRequest.status == 200) {
    
      var dataDiv = document.getElementById(displayId);
      var dataTR = document.getElementById('TR_'+ displayId);
      
      var dataTD = document.getElementById('TD_'+ displayId);
      

       if (dataDiv != null) {
        dataDiv.innerHTML = httpRequest.responseText;
         if (dataTR != null){
          	dataTR.style.display = '';      
         	if(dataTD != null){
         		dataTD.style.height = 0;
         	}
		 }
		        dataDiv.style.display = 'block';
         		divHeight  = dataDiv.offsetHeight;
         
         		step = Math.round(divHeight/14);
         		slidedown(divHeight, displayId, step, 0);
      }
    }
  }
}


function slidedown(divHeight, displayId, step, i){

    dataDiv = document.getElementById('TD_'+displayId);
    
 i += step;
 if (i <= divHeight){
  newHeight = i +'px';
     dataDiv.style.height = newHeight;
  setTimeout(function() { slidedown(divHeight,displayId,step,i);}, 8, this);
  }
 else{
     dataDiv.style.height = divHeight + 10 +'px';
     }
 }
