	//	<!-- $$Revision: 2 $ -->	
	// 
	//	Title		: submitfunctions.js
	//	Author	:	DM
	//	Date		: 4 May 2005
	//	Version : 1.3.0.0
	//	These functions control the way a web page calls back to the server. The call can be either a standard 
	//	HTTP PostBack or a more precise call using the XMLHTTP ActiveX object can be used.  The main function
	//  to use in web pages is the _SendReceiveData() function.  This will determine whether or not a postback 
	//  is required, and will either do a postback or a call via XMLHTTP to the Aspire Executive web service housed
	//  within the Authenticator. 
	//
	//	The following will cause a PostBack automatically.
	//	1.	The 'element' param is null
	//	2.	The 'refreshsnapins' params is null
	//	3.  The form action is not the same as the current URL
	//  4.  Inability to create the XMLDOM or XMLHTTP activeX controls.  
	
	// Web Service Configuration Constants (Start)

	// This namespace must match the namespace declared in the .NET <WebService()> _  attribute.	
	var mcWebServiceNamespace			= 'www.ridgian-group.co.uk';

	// This must match the name of the method called on the web service.
	var mcWebServiceMethod				= 'Execute';

	// This must match the name of the parameter of the web service.
	var mcWebServiceMethodParam		= 'Xml';

	// This globally ENABLES/DISABLES WEB SERVICE CALLS and forces a PostBack.
	var mcWebServiceEnabled = false;

	// Web Service Configuration Constants (End)

	// General Functions (Start)

	// Local Constants (Start)
	
	var mcEncodedXMLStart			= '&lt;';
	var mcEncodedXMLEnd				= '&gt;';
	var mcEncodedAmpersand		= '&amp;';
	
	var mcXmlStartElement			= '<';
	var mcXmlEndElement				= '>';	
	var mcAmpersand						= '&';

	var mcASNone							= 'none';
	var mcASInLine						= 'inline';

	// Local Constants (End)

	// Regular Expression Constants (Start)

	var mcREXmlStartElement = '(<)';
	var mcREXmlEndElement		= '(>)';
	var mcREAmpersand				= '(&)';
	var mcREGlobal					= "g";
	var mcREEncodedXMLStart	= '(&lt;)';
	var mcREEncodedXMLEnd		= '(&gt;)';
	var mcREEncodedAmpersand = '(&amp;)';
	
	// Regular Expression Constants (End)

	// Javascript OBJECTS to help with web service calls.

	//	*****************************************************************
	//	Object			: Call
	//	
	//	Description :	Object container for the web service call
	// ******************************************************************
	function Call(xmlhttp,outputdiv,errordiv,progressbarID,statusmessages)
	{
		this.xmlhttp = xmlhttp;
		this.outputdiv = outputdiv;
		this.errordiv = errordiv;
		this.progressbarid = progressbarID;
		this.statusmessages = statusmessages;
	}

	//	*****************************************************************
	//	Object			: RequestHeader
	//	
	//	Description :	Object container for the XML HTTP request header.
	// ******************************************************************
	function RequestHeader(sKey,sValue)
	{
		this.key = sKey;
		this.value = sValue;
	}

	//	*****************************************************************
	//	Object			: Namespace
	//	
	//	Description :	Object container for the SOAP Namespace references.
	// ******************************************************************
	function Namespace(sPrefix,sURL)
	{
		this.prefix = sPrefix;
		this.url = sURL;
	}

	//	*****************************************************************
	//	Object			: StatusMessage
	//	
	//	Description :	Object container for the messages to display at the
	//								various enumerations of the onreadystatechanged
	//								event generated by the xmlhttp object.
	// ******************************************************************
	function StatusMessage(readystate,message)
	{
		this.readystate = readystate;
		this.message = message;
	}

	// WEB SERVICE FUNCTIONS 

	function EnableWebService(enable)
	{

		mcWebServiceEnabled = enable;	

	}

	// This is a wrapper function for callbacks to the server. It wraps the _SendReceiveData
	// function and should be used in future to comply with coding standards
	function DoPostBack(form,element,sendsnapin,task,refreshsnapins,async,formaction)
	{
	
		_SendReceiveData(form,element,sendsnapin,task,refreshsnapins,async,formaction);
		
	}

	//	*****************************************************************
	//	Object			: _SendReceiveData
	//	
	//	Description :	This is the key method for communicating with Aspire
	//								Executive.
	// ******************************************************************
	function _SendReceiveData(form,element,sendsnapin,task,refreshsnapins,async,formaction)
	{

		var WebServiceWSDL;

		// Check the existance of the Aspire Executive Control Fields.
		if (_AspireExecutiveControlFieldsPresent() == false)
		{
			return;
		}

		// If the form is undefined or the form name is not defined, then show an alert and exit the function.
		if (form == null)
		{
			alert('The HTML <form> which is to submit the request is either "null" or has not been specified in _SendReceiveData().');
			return;
		}
		
		// If there is no task set, then set the task value to an empty string.			
		if (task == null)
		{
			task = '';
		}
		else
		{
			// If there IS a task, then check that the snap-in which is initiating the task is specified.		
			if (sendsnapin == null || sendsnapin == '')
			{
				sendsnapin = '';
				task = '';
				alert('A task has been specified, but the value of the "sendsnapin" parameter of _SendReceiveData() is null or an empty string.');
				return;			
			}		
		
		}
		
		// Set the hidden fields to the required values.  These are needed whether or not a Web Service Call is required.
		document.getElementById('hdnAspireRequestSnapIn').value = sendsnapin;
		document.getElementById('hdnAspireTask').value = task;
		document.getElementById('hdnAspireResponseSnapIns').value = refreshsnapins;

		if (formaction != null)
		{
			form.action = formaction;
		}

		// If a file upload is required, we will always to a postback.
		if (form.encoding == 'multipart/form-data')
		{
			form.submit();
		}

		// If there is no element supplied, then the _IsWebServiceCall() function cannot determine whether or
		// not a web service call is required or available.
		if (element != null)
		{

			if (mcWebServiceEnabled == true && _IsWebServiceCall(element,form) == true) 
			{
				//
				if (refreshsnapins != null && refreshsnapins != '')
				{	
					if (async == null)
					{
						async = true;
					}
				
					WebServiceWSDL = document.location.href.replace(document.location.protocol + '//','').replace("aspx","asmx");
					_CallWebService(form,_PrependProtocol(WebServiceWSDL),async,null,null,null,true);
					
				}	
				else
				{
					form.submit();
				}
				
			}	
			else
			{
				// Do a straight forward postback.
				form.submit();
			}	
		}	
		else
		{
			// Do a straight forward postback.
			form.submit();			
		}
		
	}

	//	*****************************************************************
	//	Object			: _AspireExecutiveControlFieldsPresent
	//	
	//	Description :	This simply identifies if the key Aspire Executive
	//                fields are present. If not, it throws alerts.
	// ******************************************************************
	function _AspireExecutiveControlFieldsPresent()
	{
	
		var hdnRequestSnapIn;
		var hdnResponseSnapIns;
		var hdnTask;

		hdnRequestSnapIn = document.getElementById('hdnAspireRequestSnapIn');
		if (hdnRequestSnapIn != null)
		{
			hdnRequestSnapIn.value = '';
		}
		else
		{
			alert('The hidden field "hdnAspireRequestSnapIn" is required by Aspire Executive, but is not in the page.');
			return false;
		}

		hdnResponseSnapIns = document.getElementById('hdnAspireResponseSnapIns');
		if (hdnResponseSnapIns != null)
		{
			hdnResponseSnapIns.value = '';
		}		
		else
		{
			alert('The hidden field "hdnAspireResponseSnapIns" is required by Aspire Executive, but is not in the page.');
			return false;
		}
		
		hdnTask = document.getElementById('hdnAspireTask');
		if (hdnTask != null)
		{
			hdnTask.value = '';
		}	
		else
		{
			alert('The hidden field "hdnAspireTask" is required by Aspire Executive, but is not in the page.');
			return false;
		}
	
		return true;
	
	}

	function _PrependProtocol(webServiceUrl)
	{
	
		var sWebServiceURL;
	
		if (document.protocol.toLowerCase() == 'hypertext transfer protocol with privacy')
		{
		
			sWebServiceURL = 'https://' + webServiceUrl;
		
		}
		else
		{
		
			sWebServiceURL = 'http://' + webServiceUrl;
		
		}
	
		return sWebServiceURL;
	
	}

	//	*****************************************************************
	//	Function		: callWebService
	//	
	//	Description :	Method call.
	// ******************************************************************
	function _CallWebService(submittedForm,wsdl,async,ouputdivid,errordivid,progressbarid,status)
	{

		var xmlhttp;
		var call;
		
		// Declare Constants (Start)
		var sXmlHttp							= 'Microsoft.XMLHTTP';
		var sPost									= 'POST';
				
		// Declare Constants (End)

		// Declare Variables (Start)
		
		var sRequestVariables;
		
		var aRequestHeader		= new Array();
		var aNamespace				= new Array();
		var aStatusMessage		= new Array();

		var sSOAPRequest;
		var sSOAPRequestHeader;
		var sSOAPRequestBody;
		
		//Clear any previous exceptions
		_ClearException()
		
		// Load the HTTP Request Headers
		aRequestHeader		= new Array();	
		aRequestHeader[0] = new RequestHeader("SOAPAction",mcWebServiceNamespace + '/' +  mcWebServiceMethod);
		aRequestHeader[1] = new RequestHeader("Content-Type","text/xml; charset='UTF-8'");
		
		/*
		
			You can add in additional request headers at this point.
			e.g
			
			aRequestHeader[2] = new RequestHeader("AUTH_USER","ridgiandm2\smithf");
		
		*/
		
		aNamespace		= new Array();	
		aNamespace[0] = new Namespace('soap','http://schemas.xmlsoap.org/soap/envelope/');
		aNamespace[1] = new Namespace('rg',_PrependProtocol(mcWebServiceNamespace));
		
		/*
		
			You can add in additional namespaces at this point.
			e.g
			
			aNamespace[2] = new Namespace('XSD','http://http://www.w3.org/2001/XMLSchema');
		
		*/

		aStatusMessage		= new Array();	
		aStatusMessage[0] = new StatusMessage(1,'Loading, please wait ...');
		aStatusMessage[1] = new StatusMessage(4,'Done.');
		
		/*
		
			You can add in additional namespaces at this point. But the first argument
			of the StatusMessage constructor must match with one of the recognised values 
			of the XmlHttp.readyState object 
			
			(0) UNINITIALIZED The object has been created, but not initialized (open method has not been called). 
			(1) LOADING The object has been created, but the send method has not been called. 
			(2) LOADED The send method has been called and the status and headers are available, but the response is not yet available. 
			(3) INTERACTIVE Some data has been received. You can call responseBody and responseText to get the current partial results. 
			(4) COMPLETED All the data has been received, and the complete data is available in responseBody and responseText. 
		
		*/
		
		//	By default we make calls asynchronously, so if the async argument is
		//	null, we set it to true.
		if (async == null)
		{
			async = true;
		}
		
		// Create the Microsoft.XMLHTTP component
		try
		{
			xmlhttp = new ActiveXObject(sXmlHttp);
		}
		catch (ex)
		{
			_DisplayException('Fault: Client',ex.description);
		}
		//	If we don't have a component we cannot go any futher so
		//	simply exit.
		if (xmlhttp == null)
		{
			return;
		}

		// Open the connection to the web service.		
		xmlhttp.open(sPost,wsdl,async);

		// Set the HTTP request headers.
		for (var i=0;i<aRequestHeader.length;i++)
		{
			xmlhttp.setRequestHeader(aRequestHeader[i].key,aRequestHeader[i].value);
		}

		// Create a call object which will get passed through to the callback
		// function if the call to the web service is asynchronous.
		call = new Call(xmlhttp,ouputdivid,errordivid,progressbarid,aStatusMessage);
		
		//Set up the callback function for asynchronous calls.
		if (async == true)
		{
			xmlhttp.onreadystatechange = function() {OnReadyStateChangedHandler(call);};
		}		
		
		// Get the header and body 
		sRequestVariables = _SerializeRequest(submittedForm);
		
		//	Create the SOAP Message passing in the namespaces to include, and the header and body data.
		sSOAPRequest = _CreateSOAPmessage(aNamespace,null,sRequestVariables);
		xmlhttp.send(sSOAPRequest);
		
		//	If this is a synchronous call, then get the result.
		if (async == false)
		{	
			_ProcessResponse(call);
		}		
		
	}	

	//	*****************************************************************
	//	Object			: serializeFormVariables
	//	
	//	Description :	All the <input> tags of type text/hidden/password/
	//								checkbox/radio.
	// ******************************************************************
	
	// TODO: IMPORTANT Need to add in the caller determination code for the 'select' and 'textarea'tags
	
	function _SerializeRequest(submittedForm)
	{
		
		var Input;
		var Parent;
		var Inputs;
		var Select;
		var Selects;
		var TextAreas;
		var	TextAreas;
		
		var XmlNode;
		var XmlAttribute;
		var XmlRoot;
		var XmlForm;
		var XmlQueryString;
		var XmlServerVariables;
		var iCount;
		
		var bAppendNode;
		var bIsElementOfForm
		var XmlHandler;
	
		var RegEx;
		
		var sQueryString;
		var arrQueryString;
		var arrQueryStringElement;
		
		iCount = 0;
		bAppendNode = true;

		XmlHandler = new ActiveXObject("MSXML.DOMDocument")

		//XmlHandler = document.getElementById('XmlHandler');

		//	We are just saving the form variables, all other stuff we can get out of either
		//	the HttpContext.Request object, or from the raw http request itself. So we 
		//	initialise the XML DOM with the <form> tag.
		if (XmlHandler != null)
		{
			XmlHandler.loadXML('<?xml version="1.0" encoding="UTF-8"?><dictionary/>');
		}
		else
		{
			return '';
		}	
		// Bufferthe root element.
		XmlRoot = XmlHandler.documentElement;

		XmlForm = XmlHandler.createElement('item');
		XmlRoot.appendChild(XmlForm)		

		// Create the 'dictionary' attribute which is used by the 
		// ridgian.portal.collator to identify which elements are the source
		// of dictionaries.
		XmlAttribute = XmlHandler.createAttribute('key');
		XmlAttribute.value = 'form';
		XmlForm.setAttributeNode(XmlAttribute);
		
		// Buffer the collection of HTML <input> tags which appear on the page.
		Inputs = document.getElementsByTagName('input');
				
		for (var i=0;i<Inputs.length;i++)
		{
			
			// Buffer this tag;
			Input = Inputs[i];
			
			// Determine if the parent form of the caller is the parent form
			// of this <input> tag. If it is then add it to the Xml stream.
			if (Input.form.name  == submittedForm.name)
			{
				bIsElementOfForm = true;
			}
			else
			{
				bIsElementOfForm = false;
			}

			if (bIsElementOfForm == true) 
			{
				// If there is no 'name' attribute, then we are not interested.
				if (Input.name != null && Input.name != '')
				{
					
					if (Input.type == 'text' || Input.type == 'password' || Input.type == 'hidden' || Input.type == 'checkbox' ||  Input.type == 'radio')												
					{
								
						// If we have a radio button (all with the same name attribute) or a checkbox then
						// need first to check if we have already got an <item> node in the Xml DOM with this name
						XmlNode = XmlHandler.selectSingleNode('//item[@key="' + Input.name + '"]');
						if (XmlNode == null)
						{
							// We have not, so we create one.
							XmlNode = XmlHandler.createElement('item');
							bAppendNode = true;
						}
						else
						{
							// We have so we do nothing, including NOT appending the node to the Xml DOM as this will 
							// create a duplicate node.
							bAppendNode = false;
						}		
								
						switch (Input.type)
						{
							case 'text' :
							case 'password' :
							case 'hidden' :				
										
								// ... add on the value separated by a comma.
								XmlNode.text = XmlNode.text == '' ? Input.value : XmlNode.text + ',' + Input.value;	
								break;						
								
							case 'checkbox' :
								
								// For checkboxes we need to allow for the situation where we have multiple checkboxes with
								// the same name and distinct values, where we want to send back a string of comma separated 
								// values, as well as for the uniquely named checkbox with no value attribute where we want 
								// to send back the 'on' (checked) value or '' (not checked).
								if (Input.checked == true)
								{
									// If there is a value attribute ...
									if (Input.value != 'on')
									{ 
										// ... add on the value separated by a comma.
										XmlNode.text = XmlNode.text == '' ? Input.value : XmlNode.text + ',' + Input.value;	
									}
									else
									{
										// ... otherwise we set the <item> node string to 'on'
										XmlNode.text = Input.value;	
									}	
								}
								break;
								
							case 'radio'		:	

								// This is a radio button, so we only need the checked value 
								if (Input.checked == true)
								{
									XmlNode.text = Input.value;	
								}							
								break;					
						}
						
						// Get the name of the current item and set it as an attribute to the <item> node just created.
						XmlAttribute = XmlHandler.createAttribute('key');
						XmlAttribute.value = Input.name;
						XmlNode.setAttributeNode(XmlAttribute);					
						
						//If the flag allows, then add in the <item> into the XML DOM
						if (bAppendNode == true)
						{			
							XmlForm.appendChild(XmlNode);
						}
						
						// Increment the overall count of the number of <item> elements in the <form> element
						iCount++;

					}					
				}
			}
		}

		// Buffer the collection of HTML <select> tags which appear on the page.
		Selects = document.getElementsByTagName('select');
				
		for (var i=0;i<Selects.length;i++)
		{

			Select = Selects[i];

			// Determine if the parent form of the caller is the parent form
			// of this <select> tag. If it is then add it to the Xml stream.
			if (Select.form.name  == submittedForm.name)
			{
				bIsElementOfForm = true;
			}
			else
			{
				bIsElementOfForm = false;
			}
				
			if (bIsElementOfForm == true)
			{	
				if (Select.name != null && Select.name != '')
				{
				
					// Create the <item> node with the value of the HTML <select> control
					XmlNode = XmlHandler.createElement('item');
					XmlNode.text = Selects[i].value; 
					
					// Append it to the DOM.
					XmlForm.appendChild(XmlNode);
					
					// Now create the 'name' attribute and assign it the name of the 
					// HTML <select> control.
					XmlAttribute = XmlHandler.createAttribute('key');
					XmlAttribute.value = Selects[i].name;
					XmlNode.setAttributeNode(XmlAttribute);
					
					// Increment the overall count of the number of <item> elements in the <form> element
					iCount++;
				}
			}
		}

		// Buffer the collection of HTML <textarea> tags which appear on the page.
		TextAreas = document.getElementsByTagName('textarea');
		
		for (var i=0;i<TextAreas.length;i++)
		{

			TextArea = TextAreas[i];

			// Determine if the parent form of the caller is the parent form
			// of this <textarea> tag. If it is then add it to the Xml stream.
			if (TextArea.form.name  == submittedForm.name)
			{
				bIsElementOfForm = true;
			}
			else
			{
				bIsElementOfForm = false;
			}

			if (bIsElementOfForm == true)
			{	
				if (TextArea.name != null && TextArea.name != '')
				{		

					// Create the <item> node with the innerText of the HTML <textarea> control
					XmlNode = XmlHandler.createElement('item');
					XmlNode.text = TextAreas[i].innerText; 

					// Append it to the DOM.
					XmlForm.appendChild(XmlNode);
					
					// Now create the 'name' attribute and assign it the name of the 
					// HTML <textarea> control.
					XmlAttribute = XmlHandler.createAttribute('key');
					XmlAttribute.value = TextAreas[i].name;
					XmlNode.setAttributeNode(XmlAttribute);

					// Increment the overall count of the number of <item> elements in the <form> element
					iCount++;
				}
			}		
		}
	
		// Finally append the count attribute to the 
		XmlAttribute = XmlHandler.createAttribute('count');
		XmlAttribute.value = iCount;
		XmlForm.setAttributeNode(XmlAttribute);

		// Now create the 'query-string' sub dictionary. To do this, we use Regular expressions to break up 
		// the query string of the 

		//RegEx = new RegExp('[\\w\\W]+(?=\\?)','g'); 
		sQueryString = new String();
		arrQueryString = new Array();
		
		if (document.URL != null)
		{
		
			// IE 5.0 Fix (Start)
			sQueryString = document.URL.substring(0,document.URL.indexOf("?") + 1);
			sQueryString = document.URL.replace(sQueryString,'');
		
			//sQueryString = document.URLUnencoded.replace(RegEx,'');
			//var RegEx = new RegExp('\\?','g');
			//sQueryString = sQueryString.replace(RegEx,'');
			
			//IE 5.0 (End)
			var RegEx = new RegExp('&','g');
			arrQueryString = sQueryString.split(RegEx);
			
		}

		XmlQueryString = XmlHandler.createElement('item');
		XmlRoot.appendChild(XmlQueryString)		

		XmlAttribute = XmlHandler.createAttribute('key');
		XmlAttribute.value = 'query-string';
		XmlQueryString.setAttributeNode(XmlAttribute);
			
		for (i=0;i<arrQueryString.length;i++)
		{
				arrQueryStringElement = new Array();
				RegEx = new RegExp('=','g');
				arrQueryStringElement = arrQueryString[i].toString().split(RegEx);
				
				XmlNode = XmlHandler.createElement('item');
				XmlNode.text = arrQueryStringElement[1].toString();
				
				XmlAttribute = XmlHandler.createAttribute('key');
				XmlAttribute.value = arrQueryStringElement[0].toString();
				XmlNode.setAttributeNode(XmlAttribute);
							
				XmlQueryString.appendChild(XmlNode)
				
		}
		
		// Because we cannot send the server-varaibles in the Xml string, we put a place holder
		// to facilitate easy substitution in the server components.
		
		XmlServerVariables = XmlHandler.createElement('item');
		XmlRoot.appendChild(XmlServerVariables)		

		XmlAttribute = XmlHandler.createAttribute('key');
		XmlAttribute.value = 'server-variables';
		XmlServerVariables.setAttributeNode(XmlAttribute);
		
		// Return the complete XML document along with processing instructions.
		return XmlHandler.xml;
	
	}

	//	*****************************************************************
	//	Function		: _FetchParentForm
	//	
	//	Description :	Carries out a search up the HTML hierarchy to locate
	//								the parent <form> tag of the argument element.
	// ******************************************************************
	function _FetchParentForm(element)
	{

		var parentForm;

		//Determine the parent form for the calling element.
		if (element.form != null)
		{
			// here the calling element is an type of <input>, <select> or <textarea>
			// tag. These tags have a property of .form to tell us what <form> tag it
			// is a sub-element of.
			parentForm = element.form
		}	
		else
		{

			//Some other element has instigated this call e.g an anchor tag. In this case
			// we need to recurse UP the HTML DOM to find the parent element that has a
			// tagName of 'form'.
			while (element.parentElement != null)
			{
				if (element.tagName.toLowerCase() == 'form')
				{
					parentForm = element;
					break;
				}
				else
				{
					element = element.parentElement;				
				}
			}
		}
		
		return parentForm;

	}

	//	*****************************************************************
	//	Function		: _IsWebServiceCall
	//	
	//	Description :	Determines wether or not to make a web service
	//								call dependent upon if the page & query string of the 
	//								current Url and the page & query string of the form
	//                of the element being selected.
	// ******************************************************************
	function _IsWebServiceCall(element,form)
	{
	
		var sThisUrl;
		var submittedForm;
		var sFormUrl;
		var FormUrlRegEx;
	
		var bIsWebServiceCall;

		var XmlHandler;
		
		// Declare Variables (End)
		var XmlHandler = new ActiveXObject("MSXML.DOMDocument")
		
		if (XmlHandler == null)
		{
			bIsWebServiceCall = false;
		}
		else
		{
			sThisUrl = new String(document.URL);
					
			sThisUrl = sThisUrl.replace("https://","");
			sThisUrl = sThisUrl.replace("http://","");
			sThisUrl = sThisUrl.replace(document.domain + "/","");

			if (form == null)
			{
				// Find the form which is being submitted
				submittedForm = _FetchParentForm(element);
			}
			else
			{
				submittedForm = form;
			}
			
			sFormUrl = new String(submittedForm.action.toLowerCase());
			
			if (sFormUrl == '')
			{
				sFormUrl = sThisUrl;
				bIsWebServiceCall = true;
			}
			else
			{
				
				sFormUrl = sFormUrl.replace("https://","");
				sFormUrl = sFormUrl.replace("http://","");
				sFormUrl = sFormUrl.replace(document.domain + "/","");
						
				sFormUrl = sFormUrl.replace("?","\\?");
						
				FormUrlRegEx = new RegExp(sFormUrl);
						
				sFormUrl = new String(sThisUrl.match(FormUrlRegEx));
						
				if ((sFormUrl != 'null') && (sFormUrl.length != 0 ))
				{
					bIsWebServiceCall = true;
				}	
				else
				{
					bIsWebServiceCall = false;
				}	
			}	
		}
		
		return bIsWebServiceCall;
	
	}
		
	//	*****************************************************************
	//	Function		: _CreateSOAPmessage
	//	
	//	Description :	Create the complete SOAP message to send to the
	//								web service.
	// ******************************************************************
	function _CreateSOAPmessage(namespaces,header,body)
	{
	
		var buffer;

		buffer = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope ";

		for (var i=0;i<namespaces.length;i++)
		{
			buffer = buffer + 'xmlns:' + namespaces[i].prefix + '="' + namespaces[i].url + '" ';
		}		
		buffer = buffer + '>';
		
		buffer = buffer + '<soap:Header>';
		buffer = buffer + _CreateCustomSOAPHeader(header);
		buffer = buffer + '</soap:Header>';		

		buffer = buffer +	'<soap:Body>';
		buffer = buffer + _CreateCustomSOAPBody(body);
		buffer = buffer +	'</soap:Body>';
	
		buffer = buffer + '</soap:Envelope>';
		
		return buffer;
	
	} 

	//	*****************************************************************
	//	Function		: _CreateCustomSOAPHeader
	//	
	//	Description :	Create a custom SOAP header section to send to the
	//								web service.
	// ******************************************************************	
	function _CreateCustomSOAPHeader(header,type)
	{
	
		var buffer;
		
		buffer = '';
		
		switch (type)
		{
			case 'security':
				
				buffer = buffer + '<wsse:Security soap:mustUnderstand=\"0\" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/07/secext\">';
				buffer = buffer + '<wsse:UsernameToken xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\">'; 
				buffer = buffer + '<wsse:Username>mcmahond</wsse:Username>';
				buffer = buffer + '<wsse:Password>welcome</wsse:Password>'; 
				buffer = buffer + '</wsse:UsernameToken>'; 
				buffer = buffer + '</wsse:Security>'; 
				break;
				
			case 'routing' : 
			
				buffer = buffer + '<wsrp:path soap:mustUnderstand=\"0\" xmlns:wsrp=\"http://schemas.xmlsoap.org/rp\">'; 
				buffer = buffer + '<wsrp:action>http://www.ridgian-group.co.uk/executive/Execute</wsrp:action>';
				buffer = buffer + '<wsrp:to>http://localhost/executive/index.aspx</wsrp:to>'; 
				buffer = buffer + '<wsrp:id>';
			  buffer = buffer + '84b9f5d0-33fb-4a81-b02b-5b760641c1d6'; 
		    buffer = buffer + '</wsrp:id>'; 
				buffer = buffer + '</wsrp:path>';			
			
				break;	
		
		}

		return buffer;
		
	}

	//	*****************************************************************
	//	Function		: _CreateCustomSOAPBody
	//	
	//	Description :	Create a custom SOAP body section to send to the
	//								web service.
	// ******************************************************************	
	function _CreateCustomSOAPBody(body)
	{
	
		var buffer;
		
		buffer = '<rg:' + mcWebServiceMethod + '><rg:' + mcWebServiceMethodParam + '>' + _EncodeXMLToString(body) + '</rg:' + mcWebServiceMethodParam + '></rg:' + mcWebServiceMethod + '>';
		//buffer = '<rg:' + mcWebServiceMethod + '><rg:' + mcWebServiceMethodParam + '>Hello</rg:' + mcWebServiceMethodParam + '></rg:' + mcWebServiceMethod + '>';
		
		return buffer;
		
	}

	//	*****************************************************************
	//	Function		: OnReadyStateChangedHandler
	//	
	//	Description :	Callback function when the onreadystatechanged
	//								event of the xmlhttp object changes.  A readyState
	//								value of 4 indicates that the web service call
	//								is complete. The argument passed through is an
	//								instance of the Call object defined above.
	// ******************************************************************	
	function OnReadyStateChangedHandler(call)
	{

		//	Check to see if we have an instance of a Call object.	
		if (call == null ) return;


		//	Check to see if we have status messages to display in the 
		//  browser status bar.
		
		if (call.statusmessages != null)
		{
			//  Check the .readystate property of each call.stateusmessage
			//	object and if they match display that status message in the 
			//  status bar of the browser.
			for (var i=0;i<call.statusmessages.length;i++)
			{
				
				if (call.statusmessages[i].readystate == call.xmlhttp.readyState)
				{
					window.status =	call.statusmessages[i].message
				}
				
			}	
		}

		// Check to see if we have a reference to a progressbar
		if (call.progressbarid != null)
		{
			switch (call.xmlhttp.readyState)
			{
				case 1 :
					// If the xmlhttp object is loading data start the
					// progressbar running.
					runprogressbar(call.progressbarid,false);
					break;
				case 4 :	
					// Once we have received the reply from the web service
					// halt the progressbar
					stopprogressbar(call.progressbarid);
					break;
			}	
		}
		
		// Decode the response from the web service.
		_ProcessResponse(call);
		
		return;
		
	}

	//	*****************************************************************
	//	Function		: _ProcessResponse
	//	
	//	Description :	We can only successfully process the response from 
	//								the web service, when the readyState of the xmlhttp
	//								object is 4.
	// ******************************************************************	
	function _ProcessResponse(call)
	{
	
		var XmlFromWebService;
		var bValidReponse;
		var sSOAPPrefix;
	  var ExceptionXml;
	  var ResponseXml;
	  
	  var sFaultCode;				// String containing the fault code
	  var sFaultString;			// String containing the description of the exception
	  var sFaultDetail;			// Further exception details
	  
	  // Assume we do not have a valid response
		bValidReponse = false;
	
		// We only do anything here, if the readyState from the call to 
		// the web service is equal to 4
		if (call.xmlhttp.readyState == 4) 
		{
		
			// Check we have an instance of xmlhttp
			if (call.xmlhttp != null)
			{
			
				// Check we have an instance of xmlhttp.ResponseXML (an XML Document
				// object).
				if (call.xmlhttp.responseXML != null)
				{
					
					// Check the documentElement of the XML document is valid.
					if (call.xmlhttp.responseXML.documentElement != null)
					{
						// If so we have a valid SOAP response (even if there is an
						// exception at the server)
					
						bValidReponse = true;
						XmlFromWebService = call.xmlhttp.responseXML.documentElement; 
					
					}
				
				} 
			
			}
		
			// If we do not have a valid SOAP response then something serious is
			// wrong and we can do nothing.
			if (bValidReponse == false)
			{
			
				if (call.errordiv != null)
				{
					_DisplayException(call.errordiv,'Fault: Server','Unknown Server Exception');	
					return;
				}	
			
			}
		
			// If we have a valid SOAP message, get the primary prefix for the 
			// SOAP elements which is dictated by the prefix of the documentElement.
			if (XmlFromWebService.prefix != null)
			{
				sSOAPPrefix = XmlFromWebService.prefix + ':';
			}	
			
			// Try to examine the Fault element of a SOAP message
			ExceptionXml = XmlFromWebService.selectSingleNode('//' + sSOAPPrefix + 'Fault');
			
			// If there is a Fault element, then we need to dig deeper and extract the 
			// Fault (Exception) details.
			if (ExceptionXml != null)
			{
				sFaultCode = ExceptionXml.selectSingleNode('faultcode'); 
				sFaultString = ExceptionXml.selectSingleNode('faultstring');
				// Display the exception details
				if (call.errordiv != null)
				{								
					_DisplayException(call.errordiv, sFaultCode.xml,sFaultString.xml);
				}
				else
				{
					alert(ExceptionXml.xml);				
				}	
			}
			else
			{
				// If no Fault element exists, then we must have had a successful
				// call to the web service, and so, we extract the results.
				ResponseXml = XmlFromWebService.selectSingleNode('//' + mcWebServiceMethod + 'Result');
				_DisplayResult(ResponseXml.text);
			}			
		}	
	}
	
	//	*****************************************************************
	//	Function		: _DisplayResult
	//	
	//	Description :	This function populates <div> tags which have the 
	//								the custom attribute 'container' with the contents
	//								of the <rg:response> Xml tag which has a matching
	//								'id' attribute.
	// ******************************************************************	
	function _DisplayResult(content)
	{
	
		var XmlNode;											// An Xml Node.
		var XmlAttribute;									// An XML Attribute (specifically an id attribute)
		var XmlNodes;											// Collection of XML Nodes
		var HtmlElements;									// Collection of HTML Elements
		var id;														// The id of the nsap-in response from the web service.				
		var iNumberOfSnapIns;							// This is to count the number of snapins to replace 
		var iSnapInsReplaced;							// This is the count of number of snap-ins replaced.
		var XmlHandler;
		
		// The returned content from the web service will be XML. There is a !DOCTYPE declaration
		// at the start of the stream along with an !ENTITY declaration for the HTML &nbsp;
		// entity reference.  Because the !DOCTYPE is looking for a DTD which does not exist so it
		// can validate the XML we want to avoid this, therefore we switch off validation on
		// parsing.
		XmlHandler = new ActiveXObject("MSXML.DOMDocument")
		
		if (XmlHandler != null)
		{
			XmlHandler.validateOnParse = false;
		
			// Load the DOM with the XML.
			XmlHandler.loadXML(content);		
			
			// Check to see how many response sections exist in the document. This will
			// give us the number of snap-ins to replace.
			iNumberOfSnapIns = XmlHandler.selectNodes("/response/snapins/div").length;
			
			// Zero the count of snap-ins which have been replaced.
			iSnapInsReplaced = 0
			
			// Check to see if we have any snap-ins
			if (iNumberOfSnapIns != null && iNumberOfSnapIns > 0)
			{		
				// Now find the <div> tags on the page. 
				HtmlElements = document.getElementsByTagName('div')
				for (var i=0;i<HtmlElements.length;i++)
				{

					// Get it's id
					id = HtmlElements[i].id;
					
					if (id != null) 
					
					{
					
						// Now find the response nodes in the XML stream.
						XmlNode = XmlHandler.selectSingleNode("/response/snapins/div[@id='" + id + "']");
				
						if (XmlNode != null) 
						{
							HtmlElements[i].innerHTML = XmlNode.text; 
						}	
					}
				}
			}
			else
			{
				
				XmlNode = XmlHandler.selectSingleNode("//message");
				if (XmlNode != null)
				{
					alert(XmlNode.text);
				}
				else
				{
					alert(content);
				}	
			}
		}
		else
		{
			alert(content);
		}
	}


	//	*****************************************************************
	//	Function		: _StringFormat
	//	
	//	Description :	This function simulates the string.format function
	//								in C, Java and .NET. The placeholders '{0}' etc are
	//								replaced in the string 'input'
	// ******************************************************************	
	function _StringFormat(input,arg0,arg1,arg2,arg3)
	{
	
		var string = new String(input);

		// First we check to see if the first argument arg0 is actually
		// an object, if so, it should be an Array Object. We stick a 
		// try .. catch block around the test to see if it is an array. 
		// If it is not and some exception is riased, the original 
		// string is returned 	
		if (arg0 != null)
		{
			if (typeof arg0 == 'object')
			{
				try
				{
					for (var i=0;i<arg0.length;i++)
					{
							
						var regEx = new RegExp('\\{[' + i + ']{1}\\}',	mcREGlobal);
						string = string.replace(regEx,arg0[i]);					
											
					}		
				}	
				catch (ex)
				{
					// Do Nothing	
				}
	
				return string;	//Return the original string.

			}
			
			// See if arg0 is a string, if so, replace {0} in the 
			// string buffer with the contents of arg0.	
			if (typeof arg0 == 'string')
			{
				var regEx = new RegExp('\\{[0]{1}\\}',	mcREGlobal);
				string = string.replace(regEx,arg0);
			}
			
		}
		
		// See if arg1 is a string, if so, replace {1} in the 
		// string buffer with the contents of arg1.	
		if (arg1 != null)
		{
			if (typeof arg1 == 'string')
			{
				var regEx = new RegExp('\\{[1]{1}\\}',	mcREGlobal);
				string = string.replace(regEx,arg1);
			}
		}

		// See if arg2 is a string, if so, replace {2} in the 
		// string buffer with the contents of arg2.	
		if (arg2 != null)
		{
			if (typeof arg2 == 'string')
			{
				var regEx = new RegExp('\\{[2]{1}\\}',	mcREGlobal);
				string = string.replace(regEx,arg2);
			}		
		}	

		// See if arg3 is a string, if so, replace {3} in the 
		// string buffer with the contents of arg3.	
		if (arg3 != null)
		{
			if (typeof arg3 == 'string')
			{
				var regEx = new RegExp('\\{[3]{1}\\}',	mcREGlobal);
				string = string.replace(regEx,arg3);
			}	
		}
	
		return string;
	
	}

	//	*****************************************************************
	//	Function		: _EncodeXMLToString
	//	
	//	Description :	In order to send XML as a string in the header or
	//								in the body, we need to encode the '<' and the '>'
	//								and the '&' of any XML tag.
	// ******************************************************************	
	function _EncodeXMLToString(xml)
	{
	
		var buffer;				// Buffer holding the encoded string
		
		buffer = new String(xml);
		
		// Replace an '&' with the entity '&amp;'
		regularexpression = new RegExp('&',mcREGlobal);
		buffer = buffer.replace(regularexpression,'&amp;');
		
		// Replace the '<' of any XML element with the entity '&lt;'
		var regularexpression = new RegExp('(<)',mcREGlobal);
		buffer = buffer.replace(regularexpression,'&lt;');

		return buffer;
	
	}

	//	*****************************************************************
	//	Function		: _EncodeStringToXML
	//	
	//	Description :	Does the opposite of _EncodeXMLToString, that is it
	//								replaces '&lt;' with '<' ina string etc.
	// ******************************************************************	
	function _EncodeStringToXML(string)
	{
	
		var buffer;				// Buffer holding the encoded string
		
		buffer = new String(string);
		
		// Replace the '&lt;' with '<' 
		var regularexpression = new RegExp('(&lt;)',mcREGlobal);
		buffer = buffer.replace(regularexpression,'<');
		
		// Replace an '&amp;' with '&'
		regularexpression = new RegExp('(&amp;)',mcREGlobal);
		buffer = buffer.replace(regularexpression,'&');
	
		return buffer;
	
	}

	// General Functions (End)

	// Exception Display (Start)
	
	var mExceptionDiv;
	var mcExceptionBlockID		= 'exception-block';
	var mcExceptionCodeID			= 'exception-code';
	var mcExceptionMessageID	= 'exception-message';

	//	*****************************************************************
	//	Function		: _DisplayException
	//	
	//	Description :	Shows an exception in a specified <div>, on the page
	//								If the <div> is not present it tries to use a default
	//								<div>. Failing that an alert is triggered.
	// ******************************************************************	
	function _DisplayException(div,code,message)
	{

		// Check to see if the div exists.
		if (div == null)
		{
			// If not try to find the default <div>
			mExceptionDiv = document.getElementById(mcExceptionBlockID);
		}
		else
		{
			mExceptionDiv = div;
		}

		// We have a valid <div> tag.
		if (mExceptionDiv !=null)
		{
			// Show the exception block.
			if (mExceptionDiv.style != null)
			{
				mExceptionDiv.style.display = mcASInLine;
			}	
			
			// Find the child <div> to show the exception code.
			mExceptionDiv = document.getElementById(mcExceptionCodeID);
			if (mExceptionDiv != null)
			{
				mExceptionDiv.innerHTML = code;	
			}
			
			// Find the child <div> to show the exception message.
			mExceptionDiv = document.getElementById(mcExceptionMessageID);
			if (mExceptionDiv != null)
			{
				mExceptionDiv.innerHTML = message;	
			}
			
		}
		else
		{	
			alert('Exception Code: ' + code + '\r\n' + 'Exception Message:' + message);			
		}	
						
	}

	//	*****************************************************************
	//	Function		: _ClearException
	//	
	//	Description :	Clears any exception <div> block, and hides it.
	// ******************************************************************	
	function _ClearException(div)
	{
	
		// Check to see if the <div> block exists
		if (div == null)
		{
			// If not, use the default <div>
			mExceptionDiv = document.getElementById(mcExceptionBlockID);
		}
		else
		{
			mExceptionDiv = div;
		}

		// If we have a <div> tag ...
		if (mExceptionDiv !=null)
		{
			// Hide the <div>
			mExceptionDiv.style.display = mcASNone;
			
			// Find the code <div> and set it's contents to an empty string
			mExceptionDiv = document.getElementById(mcExceptionCodeID);
			if (mExceptionDiv != null)
			{
				mExceptionDiv.innerHTML = '';	
			}
			
			// Find the message <div> and set it's contents to an empty string
			div = document.getElementById(mcExceptionMessageID);
			if (div != null)
			{
				mExceptionDiv.innerHTML = '';	
			}
		}
	}
	
	// Exception Display (End)


//	**********************************************************************************
//	Object			: progressbar
//	
//	Description :	object containing the information needed to control a javascript
//								progress bar.  
// ***********************************************************************************
function progressbar(id,index,value,maxvalue,timer)
{
	this.id = id;																// The id of the <table> tag which is the progressbar container.
	this.index = index == null ? 0 : index;			// The associated array index (0 if only one progress bar on the page).
	this.value = value;													// Current position of this progress bar
	this.maxvalue = maxvalue;										// Maximum value of the progressbar
	this.timer = timer;													// ID of the function set by the setTimeout function.
}

// Variable Declarations (Start)

//	maAS : Member Array Aspire
//	mcAS : Member Constant Aspire
//	miAS : Member Integer Aspire
//	mstAS: Member Style Aspire
var maASProgressValue			= new Array();				//stores the counters for any progress bars 
var maASProgressMaxValue	= new Array();				//stores the end count for any progress bars
var maASProgressTimer			= new Array();				//stores the references to the functions which are run by setTimeout
var maASProgressBar				= new Array();

var mcASProgressMaxValue	= 10;									// set to number of progress <span>'s.
var miProgressBarIndex		=	0;

var mcASProgressColor			= '#003399';					// set to progress bar color
var mcASProgressInterval	= 250;								// set to time between updates (milli-seconds)

var mcASProgressBar				= "progressbar";
var mcASProgressBarUpdate = 'progressbarupdate';
var mcASTransparent				= 'transparent';
var mstASSpace						= 'progressbar-space';
var mstASElement					= 'progressbar-element';

//	**********************************************************************************
//	Object			: runprogressbar
//	
//	Description :	Start running the progress bar with id = 'id'.
// ***********************************************************************************		
function runprogressbar(id,onceonly)
{

	var progress;		//Container variable for the progress bar.

	// If the element does not actually exist on the page (wrong id)
	// just exit.
	if (document.getElementById(id) == null) {return};

	// The onceonly argument if true means that the progress bar will
	// count up once and then stop.  If this argument is false, the 
	// progress bar will count to the maxvalue then reset and continue 
	// counting.  It can then be halted by a call to stopprogressbar(id).
	if (onceonly == null)
	{
		onceonly = true;
	}

	// Try to find an reference to the progress bar with id = 'id'
	// in the Array object maASProgressBar.  
	for (var i=0;i<maASProgressBar.length;i++)
	{
		if (maASProgressBar[i].id == id)
		{
			progress = maASProgressBar[i];
		}
	}
		
	// If progress is null, then no progressbar with the id = 'id'
	// exists in the array, so add it in, then increment the 
	// counter so that the next progressbar will occupy the next position 
	// in the array.
	if (progress == null)
	{
		maASProgressBar[miProgressBarIndex] = new progressbar(id,miProgressBarIndex,mcASProgressMaxValue,mcASProgressMaxValue, null);
		progress = maASProgressBar[miProgressBarIndex];
		miProgressBarIndex ++; 
	}

	// Show the progressbar
	document.getElementById(id).style.display=mcASInLine;

	// Reset the progressbar
	progressbarclear(progress);
	
	// Start the progressbar running.
	progressbarupdate(progress.id,onceonly);
	
	return;
	
}

//	**********************************************************************************
//	Object			: stopprogressbar
//	
//	Description :	Stop running the progress bar with id = 'id'.
// ***********************************************************************************		
function stopprogressbar(id)
{

	var progressbar; //Container variable for the progress bar.

	// If the element does not actually exist on the page (wrong id)
	// just exit.
	if (document.getElementById(id) == null) {return};
	
	for (var i=0;i<maASProgressBar.length;i++)
	{
		if (maASProgressBar[i].id == id)
		{
			progressbar = maASProgressBar[i];
		}
	}

	// If we successfully find the progressbar, then hide it, stop it and
	// clear it.
	if (progressbar != null)
	{
		document.getElementById(progressbar.id).style.display=mcASNone;
		progressbarstop(progressbar);
		progressbarclear(progressbar);
	}
	
	return;
	
}

//	**********************************************************************************
//	Object			: progressbarclear
//	
//	Description :	Given the reference to a progressbar object, clear the contents
//								and set the value to 0.
// ***********************************************************************************		
function progressbarclear(progressbar)
{
	for (var i = 1; i <= progressbar.maxvalue; i++) 
	{
		document.getElementById(progressbar.id + '.' + i).className = mstASSpace; 
	}
	progressbar.value = 0;
	
	return;
	
}

//	**********************************************************************************
//	Object			: progressbarupdate
//	
//	Description :	Update the appearance of the progress bar. We use the id
//								of the progressbar rather than a reference to the associated
//								object, because of the need to call this function recursively
//								via the window.setTimeout function which only accepts a string
//								value as it's first argument, if you want to pass in arguments
//								to the called function.
//	IMPORTANT		: DO NOT call this function from the page directly, and always
//								check prior to calling that there IS a progressbar with the
//								required id onthe page.	
// ***********************************************************************************	
function progressbarupdate(id,onceonly)
{

	var progressbar;

	// Find the reference to the progress bar.  
	for (var i=0;i<maASProgressBar.length;i++)
	{
		if (maASProgressBar[i].id == id)
		{
			progressbar = maASProgressBar[i];
		}
	}
	
	// Increment it's value.
	progressbar.value++;

	// Check to see if the maximum value has been reached.
	if (progressbar.value > progressbar.maxvalue)
	{
		if (onceonly == true)
		{
			// If this is a onceonly  progressbar, then we reset it's
			// value. Stop the timed calls, clear it's contents, and then
			// hide the progress bar on the page.
			progressbar.value = 0;
			progressbarstop(progressbar);
			progressbarclear(progressbar);
			document.getElementById(progressbar.id).style.display=mcASNone;
		}
		else
		{
			// We want to keep the progressbar cycling around, so rest the value,
			// clear the progressbar and then call the setTimeout function again.
			progressbar.value = 0;
			progressbarclear(progressbar);
			progressbar.timer = setTimeout(mcASProgressBarUpdate + '(\'' + progressbar.id + '\')',mcASProgressInterval);
		}	
	}
	else 
	{
		// Maximum value has not been reached, so show the element and call this function again via the setTimeout function.
		document.getElementById(progressbar.id + '.' + progressbar.value).className = mstASElement; 
		progressbar.timer = setTimeout(mcASProgressBarUpdate + '(\'' + progressbar.id + '\',' + onceonly + ')',mcASProgressInterval);
	}
	
	return;
	
}

//	**********************************************************************************
//	Object			: progressbarstop
//	
//	Description :	Cancel any call to the progressbarupdate function. 
// ***********************************************************************************		
function progressbarstop(progressbar)
{

	clearTimeout(progressbar.timer);

	return;

}	

// ************************************************************************************
// 
// Support functions
//
// ************************************************************************************

// ***************************************************************** '
// Name: LogException
//
// Description: Reports Javascript errors..
//
// ***************************************************************** '
function LogException(v_sPage, v_sFunction, v_lErrNo, v_lErrDesc)
{
var sMsg;
	
	// Build error message.
	sMsg = 'Javascript Error: \n Page: ' + 
			v_sPage + '\n Function: ' + 
			v_sFunction + '\n ErrNo: ' + 
			v_lErrNo + '\n Desc: ' + v_lErrDesc
	
	// Report error.
	alert(sMsg);
}

function element_showhide(elementid,toggleimgid,showimage,hideimage)
{
	
	var toggleimg;
	var imagesrc;
	var element;
	
	element = document.getElementById(elementid);
	
	if (element != null)
	{
		
		toggleimg = document.getElementById(toggleimgid); 
		imagesrc = new String(toggleimg.src);
		
		if (imagesrc.indexOf(showimage,0) < 0)
		{
			toggleimg.src = showimage;
			element.style.display = 'none';
		}
		else
		{
			toggleimg.src = hideimage;
			element.style.display = '';
		}   	
	}
}

function showDialog(url)
{

	window.open(url,null,'height=200,width=300,menubar=no,toolbar=no,location=no,resizable=yes');

}

// This function should be used in preference to select_OnChange to comply with 
// up to dat coding standards.
function OnSelectIndexChanged(select,prefix)
{
	select_OnChange(select,prefix);
}

// ************************************************************************************
//
//	Generic function which links a drop down <select> tag to a number of <div> tags.  Which eveer
//  value in the <select> tag is selected shows one of a set of <div> tags.	For this function to work, 
//	the id attribute of the <div> tags which need to be shown/hidden must be equal to the value of the 
//	'prefix' argument followed by the possible option values in the <select> tag. e.g	
//
//	<select onchange="select_OnChange(select,'source-settings-')" >
//		<option>database</option>
//		<option>clr</option>
//		<option>file</option>
//	</select>		
//	
//	<div id="source-settings-database">Database</div>
//	<div id="source-settings-clr">clr</div>
//	<div id="source-settings-file">file</div>
//
//  If 'database' is selected from the <select> tag, then the <div> with id attribute equal to "source-settings-database" will 
//  be shown, the rest will be hidden.
//
// ************************************************************************************
function select_OnChange(select,prefix)
{

	var option;		// An <option> tag within the <select> tag represented by the 'select' argument.
	var showdiv;  // The <div> tag to show
	var hidediv;  // The <div> tag to hide
	
	/* 
		Loop through the <option> tags within the <select> tags and set ALL of the styles to display:none 
		for the <div> tags on th epage that have an id attribute equal to the prefix contained in the 'prefix'
		argument.
	*/
	for (i=0;i<=select.options.length-1;i++)
	{
		var option = select.options[i];
		var hidediv = document.getElementById(prefix + option.innerHTML);
		if (hidediv != null)
		{
			hidediv.style.display = 'none';
		}	
	}
	
	// Show the <div> tag with an id equal to the prefix followed by the value of the <select> tag.
	showdiv = document.getElementById(prefix + select.value);
	if (showdiv != null)
	{	
		showdiv.style.display = 'inline';
	}	

}

function getdParams()
{
	
	var dparams;
	
	if (document.URL.indexOf("&dparam") > 0)
	{
		dparams = document.URL.substring(0,document.URL.indexOf("&dparam") + 1);
		dparams = document.URL.replace(dparams,'');
		dparams = '&' + dparams;
	}
	else
	{
		dparams = '';
	}	
	
	return dparams;
	
}

function ChangeRowClass(element,toClass,ignoreClass)
{
	var div = document.getElementById(element.id);
	if (div.className.toLowerCase() != ignoreClass)
	{
		div.className = toClass;
	}
}

function UseWebService(value)
{
	mcWebServiceEnabled = value;
}

