
/***************** FMD WEB FRAMEWORK - COMMUNICATION FUNCTIONS *********************/
/* Version: 3.0                                                                    */
/* Copyright (c) 2005 Flying Machine Development, Inc All Rights Reserved          */
/* Contact: info@flyingmachine.com                                                 */
/***********************************************************************************/

/********************************** WSComm object **********************************/

  function WSComm()
  {
    var self=new Object();
    self.url="";
    self.callBack="";
    self.async=true;
    self.xml="";
    self.post=WSComm_post;
    self.get=WSComm_get;
    self.onLoadHandler=WSComm_onLoadHandler;
    
    if (window.XMLHttpRequest)
    {
      self.xmlHttpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
      self.xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }
    return self;
  }

  function WSComm_post()
  {
    var postData = "xml=" + escape(this.xml)
    if(this.callBack) 
    {
      var callBack=this.callBack;
      var xmlHttpRequest=this.xmlHttpRequest;
      var onLoadHandler=this.onLoadHandler;
      this.xmlHttpRequest.onreadystatechange = function(){onLoadHandler(xmlHttpRequest, callBack)};
    }
    this.xmlHttpRequest.open("POST", this.url, this.async);
    this.xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    this.xmlHttpRequest.send(postData)

  }
    
  function WSComm_get()
  {
    var qryString = ""
    if(this.xml.length > 0) 
    {
      qryString = "?xml=" + this.xml
    }
    if(this.callBack) 
    {
      var callBack=this.callBack;
      var xmlHttpRequest=this.xmlHttpRequest;
      var onLoadHandler=this.onLoadHandler;
      this.xmlHttpRequest.onreadystatechange = function() {onLoadHandler(xmlHttpRequest, callBack)};
    }
    this.xmlHttpRequest.open("GET", this.url + qryString, this.async);
    this.xmlHttpRequest.send("")
  }

  function WSComm_onLoadHandler(xmlHttpRequest, callBack)
  {
    if (xmlHttpRequest.readyState == 4)
    {
      if (xmlHttpRequest.status == 200)
      {
        callBack(xmlHttpRequest.responseXML);
      }
      else
      {
        alert("Web Service Error: " + xmlHttpRequest.statusText + " (" + xmlHttpRequest.status + ")");
      }
    }
  }


