xlr.remote = 
{
    send : function (reqData,respAction) 
    {
	var http = new XMLHttpRequest();
	http.open("POST","/XelaraServices/XInterpreter",true);
	http.onreadystatechange = function() {
	    if(http.readyState == 4)
	    {
		if(http.status == 200)
		{
		    respAction.process(http.responseText);
		}
	    }
	};
//	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-Type", "text/plain;charset=utf8");
	http.send(reqData);
    },

    createResponse : function(xmlString) 
    {
	var xmlDom =  xlr.remote.parseXML(xmlString);
	var rv = {}
	var response = xmlDom.getElementsByTagName("response")[0];
	if(response) {
	    var atrb = response.attributes["ok"];
	    rv.isOK = top.xlr.core.parseBoolean(atrb ? atrb.nodeValue : false);
	    rv.value = top.xlr.xml.parseValue(response.firstChild.nodeValue);
	}
	return rv;
    },

    createRequest : function(command) 
    {
	var rv = "";
	var part = top.c.split(top.s);
	
	var x1 = xlr.swapCloud(part[0],part[4],part[1]);
	var x2 = xlr.swapCloud(part[3],part[2],part[1]);

	var head = xlr.xml.createAttributeString(
	    {docType:"de.wuplex.servlets.request", version:"01.00.00"});
	var month = xlr.xml.createAttributeString(
	  {userName:x1, password:x2, dir:"default"});
	rv+="<xelara"+head+"/>"+"\n";
	rv+="<request>"+"\n";
	rv+="	<xaccount"+month+"/>"+"\n";
	rv+="	<commands>"+"\n";
	rv+=xlr.remote.createCommand(command)+"\n";
	rv+="	</commands>"+"\n";
	rv+="</request>"+"\n";
	return rv;
    },

    createCommand : function(command) 
    {
	var rv = "";
	switch(command.name)
	{
	    //---------------------------------------------------------------------
	    case "inc":
		rv = "		<inc";
		rv+=xlr.xml.createAttributeString({fieldName:command.fieldName, step:command.step})+"/>";
	    break;
	    //---------------------------------------------------------------------
	    case "getValue":
		rv = "		<getValue";
		rv+=xlr.xml.createAttributeString({fieldName:command.fieldName})+"/>";
	    break;
	    //---------------------------------------------------------------------
	    case "sendMail":
		rv = "		<sendMail>"+"\n";
		rv+="			<to";
		rv+=xlr.xml.createAttributeString({address:command.toAddress})+"/>"+"\n";
		rv+="			<message>"+"\n";
		rv+="				<subject>"+"\n";
		rv+="					<!#"+"\n";
		rv+="						(!#"+command.message.subject+"#!)"+"\n";  
		rv+="					#!>"+"\n";
		rv+="				</subject>"+"\n";
		rv+="				<body>"+"\n";
		rv+="					<!#"+"\n";
		rv+="						(!#"+command.message.body+"#!)"+"\n";  
		rv+="					#!>"+"\n";
		rv+="				</body>"+"\n";
		rv+="			</message>"+"\n";
		rv+="		</sendMail>"+"\n";
	    break;
	    //---------------------------------------------------------------------
	}
	return rv;
    },

    parseXML : function(xmlString)
    {
	var xmlDoc;
	if (window.DOMParser)
	{
	    parser = new DOMParser();
	    xmlDoc = parser.parseFromString(xmlString,"text/xml");
	}
	else 
	{
	    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	    xmlDoc.async="false";
	    xmlDoc.loadXML(xmlString);
	}
 	return xmlDoc;
    }
};
/*
<xelara docType="de.wuplex.servlets.response" version="01.00.00"/>
<response ok="false">
    <exceptionList>
        <exception>
           <!#
              (!#NULL Request#!)
           #!>
        </exception>
    </exceptionList>
</response>
*/
