﻿function xmlEncode(text) {
    text.replace(/\&/g, '&' + 'amp;');
    text.replace(/</g, '&' + 'lt;');
    return text;
}

function getXMLHttpRequest()
{
       try
       {
               if(window.XMLHttpRequest)
               {
                       var req = new XMLHttpRequest();
                       // some versions of Moz do not support the readyState property and the onreadystate event so we patch it!
                       if(req.readyState == null)
                       {
                               req.readyState = 1;
                               req.addEventListener("load",
                               function()
                               {
                                       req.readyState = 4;
                                       if(typeof req.onreadystatechange == "function")
                                               req.onreadystatechange();
                               },
                               false);
                       }
                       return req;
               }
               if(window.ActiveXObject)
                       return new ActiveXObject(SOAPClient._getXmlHttpProgID());
       }
       catch (ex) {}
       return null;
}


function sendErrorLogToserver(errMsg) {
       try
       {
       xmlHttp = getXMLHttpRequest();

//       xmlHttp.open("POST", "http://ohmrolle.informatik.fh-nuernberg.de/LoggingWS/LogService.svc", true);
       xmlHttp.open("POST", "http://" + window.location.hostname +  "/LoggingWS/LogService.svc", true);
       
       xmlHttp.setRequestHeader("SOAPAction", "http://tempuri.org/ILogService/Log");
       xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

       xmlHttp.send("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><Log xmlns=\"http://tempuri.org/\"><text>JS Error</text><additionalInformation>"+xmlEncode(errMsg)+"</additionalInformation><level>critical</level></Log></s:Body></s:Envelope>");
       }
       catch(e)
       {
       }

/*
       xmlHttp.readyState
       xmlHttp.responseXML
*/
   }