
function showHourGlass(cursorState) {
	if (cursorState == true) {
		document.body.style.cursor = 'wait';
	} else {
		document.body.style.cursor = '';
	}
}

// Taget fra CallWebService

// CallWebService library v. 1.0
// © TECTURA 2004
//
// Disclaimer:
// TECTURA can not be held responsible if this library causes failures, data
// leaks or in other ways functions in an unintended manner.
// Use of this library is at your own risk.
//
// Description:
// This JavaScript library lets you call web services directly from the client,
// without having to post back a form to the server.
// This will actually enable you to perform server side tasks triggered from
// the client, for instance zip code lookup, data validation and database access.
// Additionally the library contains two methods, HtmlEncode and IsArray.
// HtmlEncode takes a string and encodes it, so that it can be used in an XML
// document (used by CallWebService to create a valid SOAP message). IsArray
// returns a boolean indicating if the parameter passed is an array or not (used
// by CallWebService to check wether the method called is a single- or multi-
// parameter method.
//
// Requirements:
// MSXML 3 or above must be installed on the client. MSXML is installed as part
// of many Microsoft standard products and product suites, so this should not
// pose too much of an obstacle.
//
// Instructions:
// The main function in this library is the CallWebService function, which takes
// the following parameters:
// Url: A string containing the Url of the web service, f.x.
//		http://www.mydomain.com/webservice/service.asmx
// Namespace: A string containing the namespace configured in the web service, f.x.
//		http://www.mydomain.com/webservices/    or
//		http://tempuri.org/ (if no custom namespace is configured)
// FuncName: A string containing the name of the method name that should be called.
// ParamName: Either a string containing the name of the parameter to be passed to
//	 a single-parameter method, or an array of string containing the parameter 
//   names of all the parameters of a multi-parameter method.
// ParamValue: Either a string containing the value of the parameter to be passed 
//   to a single-parameter method, or an array of string containing the parameter 
//   values of all the parameters of a multi-parameter method.
// The function returns the return value of the method called.
//
// Examples:
// var result = CallWebService(
//					"http://www.mydomain.com/service1.asmx", 
//					"http://www.mydomain.com/webservices",
//					"MyMethod",
//					"MyParameter",
//					"value");
//
// var paramName = new Array(2);
// var paramValue = new Array(2);
// paramName[0] = "Param1";
// paramName[1] = "Param2";
// paramValue[0] = "Value1";
// paramValue[1] = "Value2";
// var result = CallWebService(
//					"http://www.mydomain.com/service1.asmx", 
//					"http://www.mydomain.com/webservices",
//					"MyMethod",
//					paramName,
//					paramValue);

function CallWebService(Url, Namespace, FuncName, ParamName, ParamValue) {
	var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
	xmlhttp.open("POST", Url + "?op=" + FuncName, false); 
	xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=ISO-8859-1");
	xmlhttp.setRequestHeader("SOAPAction", Namespace + FuncName);
	var soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
		"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
		"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
		"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
		"<soap:Body>" + 
			"<" + FuncName + " xmlns=\"" + Namespace + "\">";
	if (IsArray(ParamName) && IsArray(ParamValue) && (ParamName.length == ParamValue.length)) {
		var i = 0;
		for (i = 0; i < ParamName.length; i++)
			soap += "<" + ParamName[i] + ">" + HtmlEncode(ParamValue[i]) + "</" + ParamName[i] + ">";
	} else {
		soap += "<" + ParamName + ">" + HtmlEncode(ParamValue) + "</" + ParamName + ">";
	}
	soap += "</" + FuncName + ">" +
		"</soap:Body>" +
		"</soap:Envelope>";
	xmlhttp.send(soap);
	return xmlhttp.responseXML.text;
}

function HtmlEncode(s) {
	s = s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
	var result = "";
	var i = 0;
	for (i = 0; i < s.length; i++) {
		var c = s.charCodeAt(i);
		if ((c >= 32) && (c <= 122)) {
			result += s.substring(i,i+1);
		} else {
			result += "&#" + c + ";";
		}
	}
	return result;
}

function IsArray(obj)
{
	if (typeof(obj) != "object") 
		return false;

	var s = new String;
	s.value = obj.constructor.toString();
	if (s.value.indexOf("Array") == -1)
		return false;
	else
		return true;
}


