var webservicebase = location.protocol + "//" + location.host + "/wsproxy/wsproxy.cfc?wsdl";
var domain = "";

// DEV
if (location.host == "localhost:90" 
 || location.host == "localhost:100" 
 || location.host == "localhost") 
{
	domain = "http://localhost:9080";
}

// UNIT
else if (location.host == "mdunit:88" 
	  || location.host == "mdunit:90" 
	  || location.host == "mdunit:100" 
	  || location.host == "mdunit")
{
	webservicebase = "http://cfusionx:88/wsproxy/wsproxy.cfc?wsdl";
	domain = "http://192.168.2.138:9082";  //(al5was03) IP used because wsproxy is outside the firewall.
}

// ITS
else if (location.host == "cfusionx:88" 
	  || location.host == "mdits"
	  || location.host == "mdits:100")
{
	domain = "http://192.168.2.137:9082";  //(al4was02) IP used because wsproxy is outside the firewall.
}
// ACC
else if (location.host == "76.12.47.147"
	  || location.host == "mdacc")
{
	domain = "https://hwt.mvphealthcare.com";
}
// PROD
else
{
	domain = "https://hwp.mvphealthcare.com";
}

var strSoapEnvelope = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
strSoapEnvelope += "<soapenv:Envelope ";
strSoapEnvelope += "xmlns:q0=\"http://web.sbi.mvphealthcare.com\"  ";
strSoapEnvelope += "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"  ";
strSoapEnvelope += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"  ";
strSoapEnvelope += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">  ";
strSoapEnvelope += "<soapenv:Body>";

function getProduct(memberId) {

	var payload = "<q0:getProduct>";
 	payload += "<domain>" + domain + "</domain>";
 	payload += "<memberId>" + memberId + "</memberId>";
	payload += "</q0:getProduct>";
	payload += "</soapenv:Body>";
	payload += "</soapenv:Envelope>";
	return sendEnvelope(payload, "getProduct");
}

function sendEnvelope(payload, methodName) {

	// send it to webservice synchronously
	var xmlHttpObj = getXMLHttpObject();
	xmlHttpObj.open("POST", webservicebase, false);
	xmlHttpObj.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
	xmlHttpObj.setRequestHeader("SOAPAction", webservicebase);
	xmlHttpObj.send(strSoapEnvelope + payload);

	// get it back...
	var xmlReturn = xmlHttpObj.responseXML;
	var response = xmlReturn.getElementsByTagName(methodName + "Return");
	var responseMessageText = response[0].firstChild;
	return responseMessageText.nodeValue;
}

function getXMLHttpObject() {
    // Firefox, Opera 8.0+, Safari
	try {
    	xmlHttp=new XMLHttpRequest();
	// Internet Explorer
	} catch (e) {
		try
	    {    
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		} catch (e) {    
			try
    	  		{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
				} catch (e) {
					return false;      
				}    
		}  
	}
	return xmlHttp;
}

