/// *** GLOBAL PARAMETER VAR
///     Clear out before any new method calls
gcParameters = ""  // parameters in XML format

function addParameter(lcName, lvValue, lcXMLType) {

switch (lcXMLType) {
   case "string":
      lcValue = lvValue;
      break;
   case "integer":
      lcValue = lvValue.toString();
      lcXMLType = "i4";
      break;
   case "boolean":
      if (lvValue)
         lcValue = "1";
      else
         lcValue = "0";
      break;
   default:
      lcXMLType = "string";
      lcValue = lvValue;
}

gcParameters = gcParameters + "<" + lcName + " xsi:type=\"" + lcXMLType + "\">" + lcValue + "</" + lcName + ">\r\n"
}

function CallMethod(lcMethod, lcUrl) {


var lcSOAPPackage = '<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"\r\n' + 
' SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"\r\n' +
' xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">\r\n' +
'<SOAP:Body>\r\n' +
"<" + lcMethod + ">\r\n" + 
gcParameters + 
"</" + lcMethod + ">\r\n" + 
"</SOAP:Body>\r\n" +
"</SOAP:Envelope>\r\n";

var loHTTP = new ActiveXObject("Microsoft.XMLHTTP");
loHTTP.Open("POST",lcUrl,false);

loHTTP.setRequestHeader("SOAPAction", lcUrl + "#" + lcMethod);
loHTTP.setRequestHeader("Content-Type","text/xml");

loHTTP.Send(lcSOAPPackage);

var oDOM = loHTTP.responseXML;

if (loHTTP.ResponseXML.xml == "") {
    alert(loHTTP.responseText);
    return false;
}

/// fake it for now by reading SOAP: values
loValue = oDOM.selectSingleNode("/SOAP:Envelope/SOAP:Body/" + lcMethod + "Response/" + lcMethod + "Result");

if (typeof(loValue) != "object"  || loValue == null) {
   alert("return value not found\r\n" + oDOM.xml)
   return false
}

lcValue = loValue.text;
lcType =  loValue.attributes.getNamedItem("xsi:type").text;

switch (lcType) {
  case "i4":
     return new Number(lcValue).valueOf();
  case "float":
     return new Number(lcValue).valueOf();
  case "boolean":
     if (lcValue == "1")
        return true;
     else
        return false;
  case "date":
     return new Date(lcValue).valueOf();
  case "datetime":
     return new Date(lcValue).valueOf();
  case "record":
	return loValue.xml  // return the entire XML string
  case "object":
	return loValue.xml  // return the entire XML string
 
}

return lcValue;
}

