/***************************************************************************************************
  System:        Michiel van Nieuwkerk Javascript Tools
  Subsystem:     -
  Class:         WebserviceHandler.js
  File:          WebserviceHandler.js
  Title:         Javascript that handles webservicetags.
  Copyright:    (C) 2006 - 2007 Michiel van Nieuwkerk (http://www.mjvannieuwkerk.com/)
                 This library is distributed in the hope that it will be useful,
                 but WITHOUT ANY WARRANTY; without even the implied warranty of
                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
                 You may use this code for ANY PURPOSE, COMMERCIAL or PRIVATE,
                 without any further permission from the author. You may remove
                 parts from the original code for performance reasons or what
                 so ever, however it is APPRECIATED by the author if at least
                 this HEADER is KEPT.
                 You may NOT re-distribute this code in any way except through its
                 use. That means, you can include it in your product, or your web
                 site, or any other form where the code is actually being used. You
                 may NOT put the plain javascript up on your site for download or
                 include it in your own javascript libraries for download. Instead,
                 please just point to my URL to ensure the most up-to-date versions
                 of the files. Thanks.
   Use:          oWebserviceHandler = new InitWebserviceHandler('{excludeid1},{excludeid2}');
   History:
   2006-05-30    mjn First implementation
   2006-06-09    mjn Added Mozilla compatibility
   2006-06-18    mjn Added Javascript return type
   2006-06-20    mjn Added parameter validation
   2006-06-20    mjn Introduced new parameter 'afterresponse' this is where
                     you can do some javascript after a response is gotten.
   2006-07-31    mjn Added some documentation in manual.html
   2006-08-02    mjn Fixed a small bug. The parameter norecords can use the GetValue functionality,
                     but then it could return undefined when the evaluated function was not having
                     a return value (alert() for example), now it is returning '' in that case.
   2006-08-09    mjn Fixed a small bug. When the excluded items were empty, something went wrong.
   2006-08-31    mjn Fixed a minor bug. An empty parameter or parametername will now be ignored.
   2006-09-20    mjn Added GetForm function. Similar to GetValue, but this can create a
                     parameterstring from fields of a given form.
   2006-10-08    mjn Made GetValue & GetForm caseinsensitive.
   2006-10-08    mjn Added new parameter 'errormessage', so when an error occures
                     a custom error can be shown. Mainly occures when a invalid url
                     is given or access is restriced to the requested url.
   2006-10-12    mjn Added new resulttype 'customxmlresult'. Now you can
                     use your own functions to process a given XML result.
   2006-10-12    mjn Updated the manual.
   2006-10-25    mjn Bugfix in GetForm. Disabled field where posted.
   2006-11-03    mjn Updated the manual.
   2006-11-08    mjn Added possiblity for extra headers.
   2006-11-09    mjn Tested secure pages and headers and updated the manual.
   2007-01-05    mjn Fixed a bug for {GetForm:myform}. It wasn't Firefox compatible enough.
   2007-05-28    mjn Removed the requestheaders Content-length & Connection from the
                     MakePOSTRequest function. Problems occured when using some IE versions.
   2007-09-19    mjn Added exclude all functionality.
   2007-09-23    mjn Added a XHTML compliant version which uses javascript.
   Releases:     - 2006-06-18 Labeled version 1.0.0 (WebserviceHandler_v100.zip)
                 - 2006-06-20 Labeled version 1.0.1 (WebserviceHandler_v101.zip)
                 - 2006-07-31 Labeled version 1.0.2 (WebserviceHandler_v102.zip)
                 - 2006-08-02 Labeled version 1.0.3 (WebserviceHandler_v103.zip)
                 - 2006-08-09 Labeled version 1.0.4 (WebserviceHandler_v104.zip)
                 - 2006-08-31 Labeled version 1.0.5 (WebserviceHandler_v105.zip)
                 - 2006-09-20 Labeled version 1.0.6 (WebserviceHandler_v106.zip)
                 - 2006-10-08 Labeled version 1.0.7 (WebserviceHandler_v107.zip)
                 - 2006-10-12 Labeled version 1.0.8 (WebserviceHandler_v108.zip)
                 - 2006-10-25 Labeled version 1.0.9 (WebserviceHandler_v109.zip)
                 - 2006-11-09 Labeled version 1.1.0 (WebserviceHandler_v110.zip)
                 - 2007-01-05 Labeled version 1.1.1 (WebserviceHandler_v111.zip)
                 - 2007-05-28 Labeled version 1.1.2 (WebserviceHandler_v112.zip)
                 - 2007-09-23 Labeled version 1.1.3 (WebserviceHandler_v113.zip)
   Todo:         - Not much for the moment!
   Tips:         - If you get the error (uncaught exception: Permission denied to call method
                   XMLHttpRequest.open) in Mozilla Firefox it's caused by cross-domain scripting
                   with XMLHttpRequest. Check out this site to understand this problem:
                   http://www.captain.at/howto-ajax-permission-denied-xmlhttprequest.php.
                 - Mozilla will not work when you call your page from the filesystem. It must be
                   called from a webserver like: http://www.mydomain.com/WebserviceHandler.html.
***************************************************************************************************/
//**************************************************************************************************
// Title      : Globals
//
// Description: Global objects
//**************************************************************************************************
var g_oWebserviceHandlerTags = new Array();
//**************************************************************************************************
// Title      : InitWebserviceHandler
//
// Description: Initialize the ComboSelect
//**************************************************************************************************
function InitWebserviceHandler(v_sExcluded)
{
    var oWebserviceHandler = new WebserviceHandler();
    oWebserviceHandler.GetTags();
    oWebserviceHandler.HandleAllTags(v_sExcluded);
    return oWebserviceHandler;
}
//**************************************************************************************************
// Title      : WebserviceHandler
//
// Description: WebserviceHandler
//**************************************************************************************************
function WebserviceHandler()
{
    var c_sXmlResult = '1';
    var c_sHtmlResult = '2';
    var c_sTextResult = '3';
    var c_sJavascriptResult = '4';
    var c_sCustomXMLResult = '?';
    var m_oWH_ar = new Array;
    //**********************************************************************************************
    // Title      : GetTags
    //
    // Description: Get all 'WebserviceHandler' elements.
    //**********************************************************************************************
    function GetTags()
    {
        // Get all the tags
        m_oWH_ar = document.getElementsByTagName('WebserviceHandler');
    }
    this.GetTags = GetTags;
    //**********************************************************************************************
    // Title      : HandleAllTags
    //
    // Description: Handle all 'WebserviceHandler' elements.
    //**********************************************************************************************
    function HandleAllTags(v_sExcluded)
    {
        var c_sExcludeAll = '*';
        var lWHs;
        var lWHTags;
        var lExcluded;
        var sExcluded_ar = new Array;
        var bIsExcluded;
        if (v_sExcluded == undefined)
        {
            v_sExcluded = '';
        }
        sExcluded_ar = v_sExcluded.split(',');
        bIsExcluded = false;
        if (v_sExcluded != c_sExcludeAll)
        {
            // Handle the tags
            for (lWHs = 0; lWHs < m_oWH_ar.length; lWHs++)
            {
                bIsExcluded = false;
                for (lExcluded = 0; lExcluded < sExcluded_ar.length; lExcluded++)
                {
                    if (
                        m_oWH_ar[lWHs].attributes.getNamedItem('id').value ==
                        sReplace(sExcluded_ar[lExcluded], ' ', '')
                    )
                    {
                        bIsExcluded = true;
                    }
                }
                if (!bIsExcluded)
                {
                    HandleTag(m_oWH_ar[lWHs]);
                }
            }
            // Handle the XHTML compliant version
            for (lWHTags = 0; lWHTags < g_oWebserviceHandlerTags.length; lWHTags++)
            {
                bIsExcluded = false;
                for (lExcluded = 0; lExcluded < sExcluded_ar.length; lExcluded++)
                {
                    if (
                        g_oWebserviceHandlerTags[lWHTags].attributes.getNamedItem('id').value ==
                        sReplace(sExcluded_ar[lExcluded], ' ', '')
                    )
                    {
                        bIsExcluded = true;
                    }
                }
                if (!bIsExcluded)
                {
                    HandleTag(g_oWebserviceHandlerTags[lWHTags]);
                }
            }
        }
    }
    this.HandleAllTags = HandleAllTags;
    //**********************************************************************************************
    // Title      : HandleTag
    //
    // Description: Handle a 'WebserviceHandler' element.
    //**********************************************************************************************
    function HandleTag(v_oWH)
    {
        var c_sGetValue = '{GetValue:';
        var c_sGetForm = '{GetForm:';
        var m_oHttpRequest = false;
        var m_sHandlerUrl = '';
        var m_sResultType = '';
        var m_sHeader = '';
        var m_sFormat = '';
        var m_sFooter = '';
        var m_sNoRecords = '';
        var m_sResultFields = '';
        var m_sResultId = '';
        var m_sAfterResponse = '';
        var m_sParameters = '';
        var m_sErrorMessage = '';
        var m_sCustomXMLResultFunction = '';
        var m_sExtraHeaders = '';
        var m_oResultId;
        if (!bCheckParameters())
        {
            alert(
                '<WebserviceHandler\n' +
                '    id=\"{WebserviceHandler id}\"\n' +
                '    handlerurl=\"{some url you want to post information to and get information from}\"\n' +
                '    resulttype=\"{1 (XmlResult), 2 (HtmlResult), 3 (TextResult), 4 (javascriptresult) or ? (customxmlresult)}\"\n' +
                '    resultid=\"{a valid object}\"\n' +
                '><\/WebserviceHandler>\n' +
                '\n' +
                '(Press Ctrl + C to copy this)'
            );
            return false;
        }
        m_oResultId.innerHTML = sGetValue(m_sWaitHtml);
        MakePOSTRequest(
            m_sHandlerUrl,
            sPreparePostFields(m_sParameters)
        );
        //******************************************************************************************
        // Title      : MakePOSTRequest
        //
        // Description: MakePOSTRequest.
        //******************************************************************************************
        function MakePOSTRequest(v_sUrl, v_sParameters)
        {
            var c_sEHSeparator = ':=\'';
            var lEHs;
            var sEHs_ar;
            m_oHttpRequest = false;
            if (window.XMLHttpRequest) // Mozilla, Safari,...
            {
                // The following code should resolve the following error in Mozilla Firefox.
                // Error: uncaught exception: Permission denied to call method XMLHttpRequest.open
                try
                {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
                }
                catch (oException)
                {
                    // Permission UniversalBrowserRead denied or not necessary.
                    // Just have a go and see;
                }
                m_oHttpRequest = new XMLHttpRequest();
                if (m_oHttpRequest.overrideMimeType)
                {
                    m_oHttpRequest.overrideMimeType('text/xml');
                }
            }
            else
            {
                if (window.ActiveXObject) // IE
                {
                    try
                    {
                        m_oHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');
                    }
                    catch (oException)
                    {
                        try
                        {
                            m_oHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
                        }
                        catch (oException)
                        {
                        }
                    }
                }
                if (!m_oHttpRequest)
                {
                    alert('Cannot create XMLHTTP instance');
                    return false;
                }
            }
            m_oHttpRequest.onreadystatechange = AlertContents;
            m_oHttpRequest.open('POST', v_sUrl, true);
            m_oHttpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            // Set extra headers
            if (m_sExtraHeaders.length > 0)
            {
                sEHs_ar = m_sExtraHeaders.split('\';');
                for (lEHs = 0; lEHs < sEHs_ar.length; lEHs++)
                {
                    if (sReplace(sEHs_ar[lEHs], ' ', '').length > 0)
                    {
                        if (sEHs_ar[lEHs].indexOf(c_sEHSeparator) > -1)
                        {
                            sSubEH_ar = sEHs_ar[lEHs].split(c_sEHSeparator);
                            if (sReplace(sSubEH_ar[0], ' ', '').length > 0)
                            {
                                if (
                                    sSubEH_ar[0].toLowerCase() != 'content-type' &&
                                    sSubEH_ar[0].toLowerCase() != 'content-length' &&
                                    sSubEH_ar[0].toLowerCase() != 'connection'
                                )
                                {
                                    if (sSubEH_ar[1].lastIndexOf('\'') == sSubEH_ar[1].length - 1)
                                    {
                                        sSubEH_ar[1] = sSubEH_ar[1].substring(0, sSubEH_ar[1].length - 1);
                                    }
                                    m_oHttpRequest.setRequestHeader(
                                        sSubEH_ar[0],
                                        sGetValue(sSubEH_ar[1])
                                    );
                                }
                            }
                            else
                            {
                                // Do nothing, extraheadername appeared to be empty
                            }
                        }
                        else
                        {
                            // Do nothing
                        }
                    }
                    else
                    {
                        // Do nothing, extraheader appeared to be empty
                    }
                }
            }
            if (v_sParameters.length > 0)
            {
                m_oHttpRequest.send(v_sParameters);
            }
            else
            {
                m_oHttpRequest.send(null);
            }
        }
        //******************************************************************************************
        // Title      : AlertContents
        //
        // Description: AlertContents.
        //******************************************************************************************
        function AlertContents()
        {
            if (m_oHttpRequest.readyState == 4)
            {
                if (m_oHttpRequest.status == 200)
                {
                    switch (m_sResultType)
                    {
                        case c_sXmlResult: // 1
                            m_oResultId.innerHTML = ProcessXmlResult(m_oHttpRequest.responseXML);
                            break;
                        case c_sHtmlResult: // 2
                            m_oResultId.innerHTML = m_oHttpRequest.responseText;
                            break;
                        case c_sTextResult: // 3
                            m_oResultId.innerText = m_oHttpRequest.responseText;
                            break;
                        case c_sJavascriptResult: // 4
                            ProcessJavascriptResult(m_oHttpRequest.responseText);
                            m_oResultId.innerHTML = '';
                            break;
                        case c_sCustomXMLResult: // ?
                            m_oResultId.innerHTML = '';
                            eval(m_sCustomXMLResultFunction)(m_oHttpRequest.responseXML);
                            break;
                        default: // 2
                            m_oResultId.innerHTML = m_oHttpRequest.responseText;
                    }
                }
                else
                {
                    if (m_sErrorMessage.length > 0)
                    {
                        m_oResultId.innerHTML = sGetValue(m_sErrorMessage);
                    }
                    else
                    {
                        alert(
                            'There was a problem with the request.' +
                            '(HTTP/1.1: Status Code: ' + m_oHttpRequest.status + ')\n' +
                            'Check out \'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\' ' +
                            'for more info on this status code.');
                        m_oResultId.innerHTML = '';
                    }
                }
                eval(m_sAfterResponse);
            }
        }
        //******************************************************************************************
        // Title      : ProcessXmlResult
        //
        // Description: ProcessXmlResult.
        //******************************************************************************************
        function ProcessXmlResult(v_oXmlDoc)
        {
            var sString = '';
            var sFormatedString = '';
            var sRF_ar = new Array();
            var lResultFields;
            var oRows_ar = new Array();
            var lRows;
            var lTemp;
            sRF_ar = m_sResultFields.split(',');
            oRows_ar = v_oXmlDoc.getElementsByTagName('Row');
            if (oRows_ar.length > 0)
            {
                sString += m_sHeader;
                for (lRows = 0; lRows < oRows_ar.length; lRows++)
                {
                    sFormatedString = m_sFormat;
                    for (lResultFields = 0; lResultFields < sRF_ar.length; lResultFields++)
                    {
                        for (lTemp = 0; lTemp < oRows_ar[lRows].childNodes.length; lTemp++)
                        {
                            if (sRF_ar[lResultFields] == oRows_ar[lRows].childNodes[lTemp].nodeName)
                            {
                                sFormatedString =
                                    sReplace(
                                        sFormatedString,
                                        '%' + sRF_ar[lResultFields] + '%',
                                        oRows_ar[lRows].childNodes[lTemp].firstChild.data
                                    );
                            }
                        }
                        // If a field is not available it will still be in the format.
                        // Here it will be replaced by an empty string
                        sFormatedString =
                            sReplace(sFormatedString, '%' + sRF_ar[lResultFields] + '%', '');
                    }
                    sString += sFormatedString;
                }
                sString += m_sFooter;
                sString =
                    sReplace(sString, '%total%', v_oXmlDoc.getElementsByTagName('Row').length);
            }
            else
            {
                sString = sGetValue(m_sNoRecords);
            }
            return sString;
        }
        //******************************************************************************************
        // Title      : ProcessJavascriptResult
        //
        // Description: ProcessJavascriptResult.
        //******************************************************************************************
        function ProcessJavascriptResult(v_sJavascript)
        {
            var sJsLine_ar = new Array();
            var lRows;
            sJsLine_ar = v_sJavascript.split(';');
            for (lRows = 0; lRows < sJsLine_ar.length; lRows++)
            {
                eval(sJsLine_ar[lRows]);
            }
        }
        //******************************************************************************************
        // Title      : sPreparePostFields
        //
        // Description: Prepare the fields for the post
        //******************************************************************************************
        function sPreparePostFields(v_sString)
        {
            var c_sParameterSeparator = ':=';
            var s_ar = new Array;
            var sSub_ar = new Array;
            var lDelimitedString = 0;
            var sReturnString = '';
            if (v_sString.length > 0)
            {
                s_ar = v_sString.split(';');
                for (lDelimitedString = 0; lDelimitedString < s_ar.length; lDelimitedString++)
                {
                    if (sReplace(s_ar[lDelimitedString], ' ', '').length > 0)
                    {
                        if (s_ar[lDelimitedString].indexOf(c_sParameterSeparator) > -1)
                        {
                            sSub_ar = s_ar[lDelimitedString].split(c_sParameterSeparator);
                            if (sReplace(sSub_ar[0], ' ', '').length > 0)
                            {
                                sReturnString +=
                                    '&' + sSub_ar[0] + '=' + encodeURIComponent(sGetValue(sSub_ar[1]));
                            }
                            else
                            {
                                // Do nothing, formfieldname appeared to be empty
                            }
                        }
                        else
                        {
                            sReturnString += sGetForm(s_ar[lDelimitedString]);
                        }
                    }
                    else
                    {
                        // Do nothing, formfield appeared to be empty
                    }
                }
            }
            else
            {
                sReturnString = '';
            }
            return sReturnString;
        }
        //******************************************************************************************
        // Title      : sGetValue
        //
        // Description: Get Value of a given field
        //******************************************************************************************
        function sGetValue(v_sString)
        {
            var sValue;
            sValue = '';
            if (v_sString.substring(0, c_sGetValue.length).toLowerCase() == c_sGetValue.toLowerCase())
            {
                try
                {
                    sValue = eval(v_sString.substring(c_sGetValue.length, v_sString.indexOf('}')));
                    // Need to check if the returned value is undefined,
                    // then an empty string must be returned else undefined
                    // will be the returned value and that is not what should happen.
                    if (sValue == undefined)
                    {
                        sValue = '';
                    }
                    else
                    {
                        // Do nothing
                    }
                }
                catch (oException)
                {
                    sValue = '';
                }
            }
            else
            {
                sValue = v_sString;
            }
            return sValue;
        }
        //******************************************************************************************
        // Title      : sGetForm
        //
        // Description: Get Values from a form
        //******************************************************************************************
        function sGetForm(v_sString)
        {
            var sValue;
            var oForm;
            var lFormElements;
            var lFormCounter;
            var bFormFound;
            sValue = ''
            bFormFound = false;
            if (v_sString.substring(0, c_sGetForm.length).toLowerCase() == c_sGetForm.toLowerCase())
            {
                try
                {
                    for (lFormCounter = 0; lFormCounter < document.forms.length; lFormCounter++)
                    {
                        if (
                            document.forms[lFormCounter].id ==
                            v_sString.substring(c_sGetForm.length, v_sString.indexOf('}')) ||
                            document.forms[lFormCounter].name ==
                            v_sString.substring(c_sGetForm.length, v_sString.indexOf('}'))
                        )
                        {
                            oForm = document.forms[lFormCounter];
                            break;
                        }
                    }
                    for (lFormElements = 0;lFormElements<oForm.elements.length;lFormElements++)
                    {
                        if (oForm.elements[lFormElements].name.length > 0)
                        {
                            if (!oForm.elements[lFormElements].disabled)
                            {
                                sValue +=
                                    '&' + oForm.elements[lFormElements].name + '=' +
                                    encodeURIComponent(oForm.elements[lFormElements].value);
                            }
                            else
                            {
                                // Do nothing, field is disabled
                            }
                        }
                        else
                        {
                            // Do nothing
                        }
                    }
                }
                catch (oException)
                {
                    sValue = '';
                }
            }
            else
            {
                // Default to an empty string, geven value appears to be a invalid parameter
                sValue = '';
            }
            return sValue;
        }
        //******************************************************************************************
        // Title      : bCheckParameters
        //
        // Description: Check the parameters
        //******************************************************************************************
        function bCheckParameters()
        {
            if (v_oWH.attributes.getNamedItem('handlerurl'))
            {
                m_sHandlerUrl = v_oWH.attributes.getNamedItem('handlerurl').value;
                if (m_sHandlerUrl.length == 0)
                {
                    alert(
                        'The parameter \'handlerurl\' must be some url you want' +
                        'to post information to and get information from!'
                    );
                    return false;
                }
                else
                {
                    // Do nothing: parameter 'handlerurl' OK!
                }
            }
            else
            {
                alert('The parameter \'handlerurl\' is compulsory!');
                return false;
            }
            if (v_oWH.attributes.getNamedItem('resulttype'))
            {
                m_sResultType = v_oWH.attributes.getNamedItem('resulttype').value;
                if (
                    m_sResultType != c_sXmlResult &&
                    m_sResultType != c_sHtmlResult &&
                    m_sResultType != c_sTextResult &&
                    m_sResultType != c_sJavascriptResult &&
                    m_sResultType != c_sCustomXMLResult
                )
                {
                    alert(
                        'The parameter \'resulttype\' must be either ' +
                        '\n' + c_sXmlResult + ' (XmlResult), ' +
                        '\n' + c_sHtmlResult + ' (HtmlResult), ' +
                        '\n' + c_sTextResult + ' (TextResult), ' +
                        '\n' + c_sJavascriptResult + ' (JavascriptResult) or ' +
                        '\n' + c_sCustomXMLResult + ' (CustomXMLResult)'
                    );
                    return false;
                }
                else
                {
                    if (m_sResultType == c_sCustomXMLResult)
                    {
                        if (v_oWH.attributes.getNamedItem('customxmlresultfunction'))
                        {
                            m_sCustomXMLResultFunction =
                                v_oWH.attributes.getNamedItem('customxmlresultfunction').value;
                        }
                        else
                        {
                            m_sCustomXMLResultFunction = '';
                        }
                        if (m_sCustomXMLResultFunction.length == 0)
                        {
                            alert(
                                'When the chosen \'resulttype\' is \'' + c_sCustomXMLResult +
                                '\' the parameter \'customxmlresultfunction\' is compulsory!'
                            );
                            return false;
                        }
                    }
                    // Do nothing: parameter 'resulttype' OK!
                }
            }
            else
            {
                alert('The parameter \'resulttype\' is compulsory!');
                return false;
            }
            if (v_oWH.attributes.getNamedItem('header'))
            {
                m_sHeader = v_oWH.attributes.getNamedItem('header').value;
            }
            else
            {
                m_sHeader = '';
            }
            if (v_oWH.attributes.getNamedItem('format'))
            {
                m_sFormat = v_oWH.attributes.getNamedItem('format').value;
            }
            else
            {
                m_sFormat = '';
            }
            if (v_oWH.attributes.getNamedItem('footer'))
            {
                m_sFooter = v_oWH.attributes.getNamedItem('footer').value;
            }
            else
            {
                m_sFooter = '';
            }
            if (v_oWH.attributes.getNamedItem('norecords'))
            {
                m_sNoRecords = v_oWH.attributes.getNamedItem('norecords').value;
            }
            else
            {
                m_sNoRecords = '';
            }
            if (v_oWH.attributes.getNamedItem('waithtml'))
            {
                m_sWaitHtml = v_oWH.attributes.getNamedItem('waithtml').value;
            }
            else
            {
                m_sWaitHtml = '';
            }
            if (v_oWH.attributes.getNamedItem('resultfields'))
            {
                m_sResultFields = v_oWH.attributes.getNamedItem('resultfields').value;
            }
            else
            {
                m_sResultFields = '';
            }
            if (v_oWH.attributes.getNamedItem('resultid'))
            {
                m_sResultId = v_oWH.attributes.getNamedItem('resultid').value;
                if (m_sResultId.length == 0)
                {
                    alert('The parameter \'resultid\' must be an object!');
                    return false;
                }
                else
                {
                    m_oResultId = document.getElementById(m_sResultId);
                    if (!m_oResultId)
                    {
                        alert(
                            'The parameter \'resultid\' must be a valid object ' +
                            'and \'' + m_sResultId + '\' is not!'
                        );
                        return false;
                    }
                    else
                    {
                        // Do nothing: parameter 'resultid' OK!
                    }
                }
            }
            else
            {
                alert('The parameter \'resultid\' is compulsory!');
                return false;
            }
            if (v_oWH.attributes.getNamedItem('afterresponse'))
            {
                m_sAfterResponse = v_oWH.attributes.getNamedItem('afterresponse').value;
            }
            else
            {
                m_sAfterResponse = '';
            }
            if (v_oWH.attributes.getNamedItem('parameters'))
            {
                m_sParameters = v_oWH.attributes.getNamedItem('parameters').value;
            }
            else
            {
                m_sParameters = '';
            }
            if (v_oWH.attributes.getNamedItem('errormessage'))
            {
                m_sErrorMessage = v_oWH.attributes.getNamedItem('errormessage').value;
            }
            else
            {
                m_sErrorMessage = '';
            }
            if (v_oWH.attributes.getNamedItem('extraheaders'))
            {
                m_sExtraHeaders = v_oWH.attributes.getNamedItem('extraheaders').value;
            }
            else
            {
                m_sExtraHeaders = '';
            }
            return true;
        }
    }
    this.HandleTag = HandleTag;
    //******************************************************************************************
    // Title      : sReplace
    //
    // Description: Replace values in a given string (by Maarten Peeters)
    //******************************************************************************************
    function sReplace(v_sString, v_sFind, v_sReplacement)
    {
        var sString = v_sString;
        var l = sString.indexOf(v_sFind);
        while(l > -1)
        {
            sString = sString.replace(v_sFind, v_sReplacement);
            l = sString.indexOf(v_sFind, l + v_sReplacement.length);
        }
        return sString;
    }
}
//**************************************************************************************************
// Title      : WebserviceHandlerTag
//
// Description: Object to create a XHTML compliant version of the original tag.
//**************************************************************************************************
function WebserviceHandlerTag()
{
    this.id = function (v_sId)
    {
        return v_sId;
    }
    this.handlerurl = function (v_sHandlerUrl)
    {
        return v_sHandlerUrl;
    }
    this.resulttype = function (v_sResultType)
    {
        return v_sResultType;
    }
    this.header = function (v_sHeader)
    {
        return v_sHeader;
    }
    this.format = function (v_sFormat)
    {
        return v_sFormat;
    }
    this.footer = function (v_sFooter)
    {
        return v_sFooter;
    }
    this.norecords = function (v_sNoRecords)
    {
        return v_sNoRecords;
    }
    this.waithtml = function (v_sWaitHtml)
    {
        return v_sWaitHtml;
    }
    this.resultfields = function (v_sResultFields)
    {
        return v_sResultFields;
    }
    this.resultid = function (v_sResultId)
    {
        return v_sResultId;
    }
    this.afterresponse = function (v_sAfterResponse)
    {
        return v_sAfterResponse;
    }
    this.parameters = function (v_sParameters)
    {
        return v_sParameters;
    }
    this.errormessage = function (v_sErrorMessage)
    {
        return v_sErrorMessage;
    }
    this.customxmlresultfunction = function (v_sCustomXmlResultFunction)
    {
        return v_sCustomXmlResultFunction;
    }
    // Enable the attributes object
    this.attributes = new Attributes(this);
    g_oWebserviceHandlerTags[g_oWebserviceHandlerTags.length] = this;
}
//**************************************************************************************************
// Title      : Attributes
//
// Description: Creates a attributes object of the WebserviceHandlerTag
//**************************************************************************************************
function Attributes(v_oWH)
{
    this.getNamedItem = function (v_sParameter)
    {
        // Enable the GetNamedItem('parameter') object
        return new GetNamedItem(v_oWH, v_sParameter);
    }
}
//**************************************************************************************************
// Title      : GetNamedItem
//
// Description: Creates a GetNamedItem on the attributes object of the WebserviceHandlerTag
//**************************************************************************************************
function GetNamedItem(v_oWH, v_sParameter)
{
    var c_sTypeOfFunction = 'function';
    var sParameterValue = '';
    switch (v_sParameter)
    {
        case 'id':
            sParameterValue = v_oWH.id;
            break;
        case 'handlerurl':
            sParameterValue = v_oWH.handlerurl;
            break;
        case 'resulttype':
            sParameterValue = v_oWH.resulttype;
            break;
        case 'header':
            sParameterValue = v_oWH.header;
            break;
        case 'format':
            sParameterValue = v_oWH.format;
            break;
        case 'footer':
            sParameterValue = v_oWH.footer;
            break;
        case 'norecords':
            sParameterValue = v_oWH.norecords;
            break;
        case 'waithtml':
            sParameterValue = v_oWH.waithtml;
            break;
        case 'resultfields':
            sParameterValue = v_oWH.resultfields;
            break;
        case 'resultid':
            sParameterValue = v_oWH.resultid;
            break;
        case 'afterresponse':
            sParameterValue = v_oWH.afterresponse;
            break;
        case 'parameters':
            sParameterValue = v_oWH.parameters;
            break;
        case 'errormessage':
            sParameterValue = v_oWH.errormessage;
            break;
        case 'customxmlresultfunction':
            sParameterValue = v_oWH.customxmlresultfunction;
            break;
        default:
            sParameterValue = '';
            break;
    }
    // Enable the GetNamedItem('parameter').value and set defaults for function-type values
    if (typeof(sParameterValue) == c_sTypeOfFunction)
    {
        if (
            v_sParameter == 'id' ||
            v_sParameter == 'handlerurl' ||
            v_sParameter == 'resulttype' ||
            v_sParameter == 'resultid' ||
            v_sParameter == 'parameters'
        )
        {
            this.value = '';
        }
        else
        {
            this.value = null;
        }
    }
    else
    {
        this.value = sParameterValue;
    }
}
// End of file
