﻿// JScript File

function GetXmlHttpObject(handler)
  { 
  var objXmlHttp=null
  if (navigator.userAgent.indexOf("MSIE")>=0)
  { 
    var strName="Msxml2.XMLHTTP"
      if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
      {
      strName="Microsoft.XMLHTTP"
      } 
      try
      { 
      objXmlHttp=new ActiveXObject(strName)
      objXmlHttp.onreadystatechange=handler 
      return objXmlHttp
      } 
      catch(e)
      { 
      alert("Error. Scripting for ActiveX might be disabled") 
      return 
      } 
  } 
  if (navigator.userAgent.indexOf("Mozilla")>=0)
  {
      objXmlHttp=new XMLHttpRequest()
      objXmlHttp.onload=handler
      objXmlHttp.onerror=handler 
      return objXmlHttp
  }
  if (window.XMLHttpRequest) {//opera
      objXmlHttp=new XMLHttpRequest()
      objXmlHttp.onreadystatechange = handler;
      return objXmlHttp
   }
  } 
  
function xmlhttpPost(strURL,strQueryString) {
 //debugger;
    var xmlHttpReq = false;
    var self = this;
    // IE
    if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    // Mozilla/Safari
    else if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest(); // Note, I am using IE7 and this line is being executed?
    }
 
        
        
    self.xmlHttpReq.open('GET', strURL, true);
    //self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
        //Code to execute when rewuest is done
            //Store the response of the requested URL
                        var text = self.xmlHttpReq.responseText;
                       // alert(text);
            //Parse the data
            parseXML(text);
        }
    }
        
    self.xmlHttpReq.send(strQueryString);
}
  
  
function parseXML(xml){
        //initialize the XML Document Object
        //and load the xml data
        try //Internet Explorer
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(xml);
        }
        catch(e)
        {
            try //Firefox, Mozilla, Opera, etc.
            {
                parser=new DOMParser();
                xmlDoc=parser.parseFromString(xml,"text/xml");
            }
            catch(e)
            {
                alert(e.message);
                return;
            }
        }
  
    //retrieve the DATA Elements
    var data = xmlDoc.getElementsByTagName("DATA");
    
    //Loop through the DATA elements
    for(var i = 0; i < data.length;i++){
     
        //Get the value of the EventTime attribute
        var eventTime = data[i].getAttribute("EventTime");
        
        //Retrieve the EVENT elements of this specific DATA element
        var events = data[i].getElementsByTagName("EVENT");
        //a Variable for the latsest PostTime EVENT
        var latestPost = 0;
        //Loop through the EVENT element to determine the latest one
        for(var e = 0; e < events.length;e++){
            //if the EVENT currently looped is later than the one saved in latestPost
            if(events[e].getAttribute("PostTime") > events[latestPost].getAttribute("PostTime")){
                //set the current EVENT element as the latest one
                latestPost = e;
            }
        }
        
 
      }
}

function createXHR() {
    var xmlhttp, XMLHttpFactories = [
        function() {
            return new XMLHttpRequest();
        }, function() {
            return new ActiveXObject("Msxml2.XMLHTTP");
        }, function() {
            return new ActiveXObject("Msxml3.XMLHTTP");
        }, function() {
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    ];
    for (var i = 0; i < XMLHttpFactories.length; i++) {
        try {
            xmlhttp = XMLHttpFactories[i]();
            this.createXHR = XMLHttpFactories[i];
            return xmlhttp;
        } catch (e) { }
    }
}

