    var SessionUrl;
	var SessionHost;
	var xmlHttp;

	var AliasArray = new Array();

	function FillAliasArray(StrBuff)
	{
		var i=0;
		var Position=0;
		
		if (StrBuff.slice(0,8)=='&lt;?xml')  // This is a DocumentListXML
		{
			while(StrBuff != "")
			{
				Position = StrBuff.indexOf('Alias');
				if (Position == -1)
				{
					StrBuff = "";
				}
				else
				{
					StrBuff = StrBuff.slice(Position+7,StrBuff.length);
					
					AliasArray[i] = StrBuff.slice(0,StrBuff.indexOf('"'));
					StrBuff = StrBuff.slice(Position+1,StrBuff.length);
					i++
				}				
			}

		}
		else // We assume this is an ImageList since its not a DocumentListXML
		{
			while(StrBuff != "")
			{
				Position = StrBuff.indexOf(',');
				if (Position == -1)
				{
					AliasArray[i] = StrBuff;
					StrBuff = "";
				}
				else
				{
					AliasArray[i] = StrBuff.slice(0,Position);
					StrBuff = StrBuff.slice(Position+1,StrBuff.length);
					i++
				}
			}
		}
	}
	
//*************************************************************************************
/* 					DirectSmile Online Functions 					*/
//*************************************************************************************
	
    var SessionUrl;
	var SessionHost;
	var xmlHttp;
	var SessionRunAsync;
	
	function SetConstants(Url,Host,RunAsync)
	{
	  SessionUrl = Url;
	  SessionHost = Host;
	  SessionRunAsync = RunAsync;
	}
	
/*		 Functions handeling AUTHENTICATIONS			*/

    function Authenticate(UserName, PWD)
    {  
      var FunctionCall = "Authenticate"; 
	  var MyEnvelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
        + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
        + ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        + '<soap:Body><'+FunctionCall+' xmlns="http://www.directsmile.de/GenService/LB">'
        + '<UserName>' + UserName + '</UserName>'
        + '<Password>' + PWD + '</Password>'
        + '<Language></Language>'
		+ '</'+FunctionCall+'></soap:Body>'
        + '</soap:Envelope>';

      var headers = [
          {name:"SOAPAction", value:'"http://www.directsmile.de/GenService/LB/'+FunctionCall+'"'},
          {name:"Host", value:SessionHost},
          {name:"Content-Type", value:'text/xml; charset=utf-8'},
          {name:"Content-Length", value:MyEnvelope.length.toString()}
      ]
      ajaxCall('POST', SessionUrl, headers, MyEnvelope, OnSoapResponse, SessionRunAsync);
	  if (SessionRunAsync == false)
	  {
		return GetResult(FunctionCall+"Result");
	  }
	  else
	  {
		return "";
	  }
	}   

    function GetAuthenticationCode(UserName, PWD)
    {  
      var FunctionCall = "GetAuthenticationCode";
	  var MyEnvelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
        + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
        + ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        + '<soap:Body><'+FunctionCall+' xmlns="http://www.directsmile.de/GenService/LB">'
        + '<Username>' + UserName + '</Username>'
        + '<Password>' + PWD + '</Password>'
		+ '</'+FunctionCall+'></soap:Body>'
        + '</soap:Envelope>';

      var headers = [
          {name:"SOAPAction", value:'"http://www.directsmile.de/GenService/LB/'+FunctionCall+'"'},
          {name:"Host", value:SessionHost},
          {name:"Content-Type", value:'text/xml; charset=utf-8'},
          {name:"Content-Length", value:MyEnvelope.length.toString()}
      ]
      ajaxCall('POST', SessionUrl, headers, MyEnvelope, OnSoapResponse, SessionRunAsync);
	  if (SessionRunAsync == false)
	  {
		return GetResult(FunctionCall+"Result");
	  }
	  else
	  {
		return "";
	  }
    }   

/*		 Functions handeling SETS			*/

	function GetAvailableSetList(SessionID)
    {  
      var FunctionCall = "GetAvailableSetList";
	  var MyEnvelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
        + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
        + ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        + '<soap:Body><'+FunctionCall+' xmlns="http://www.directsmile.de/GenService/LB">'
        + '<SessionID>' + SessionID + '</SessionID>'
        + '</'+FunctionCall+'></soap:Body>'
        + '</soap:Envelope>';

      var headers = [
          {name:"SOAPAction", value:'"http://www.directsmile.de/GenService/LB/'+FunctionCall+'"'},
          {name:"Host", value:SessionHost},
          {name:"Content-Type", value:'text/xml; charset=utf-8'},
          {name:"Content-Length", value:MyEnvelope.length.toString()}
      ]
      ajaxCall('POST', SessionUrl, headers, MyEnvelope, OnSoapResponse, SessionRunAsync);
	  if (SessionRunAsync == false)
	  {
		return GetResult(FunctionCall+"Result");
	  }
	  else
	  {
		return "";
	  }
    }   

	function GetAvailableSetListAuth(AuthenticationCode)
    {  
      var FunctionCall = "GetAvailableSetListAuth";
	  var MyEnvelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
        + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
        + ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        + '<soap:Body><'+FunctionCall+' xmlns="http://www.directsmile.de/GenService/LB">'
        + '<AuthenticationCode>' + AuthenticationCode + '</AuthenticationCode>'
        + '</'+FunctionCall+'></soap:Body>'
        + '</soap:Envelope>';

      var headers = [
          {name:"SOAPAction", value:'"http://www.directsmile.de/GenService/LB/'+FunctionCall+'"'},
          {name:"Host", value:SessionHost},
          {name:"Content-Type", value:'text/xml; charset=utf-8'},
          {name:"Content-Length", value:MyEnvelope.length.toString()}
      ]
      ajaxCall('POST', SessionUrl, headers, MyEnvelope, OnSoapResponse, SessionRunAsync);
	  if (SessionRunAsync == false)
	  {
		return GetResult(FunctionCall+"Result");
	  }
	  else
	  {
		return "";
	  }
    }   

	function GetImageUrl(SessionID, SetAlias, TextToRender, PixelWidth, Filename, Quality, Key, WaterMarkType)
    {  
      var FunctionCall = "GetImageUrl";
	  var MyEnvelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
        + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
        + ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        + '<soap:Body><'+FunctionCall+' xmlns="http://www.directsmile.de/GenService/LB">'
        + '<SessionID>' + SessionID + '</SessionID>'
        + '<SetAlias>' + SetAlias + '</SetAlias>'
        + '<TextToRender>' + TextToRender + '</TextToRender>'
        + '<PixelWidth>' + PixelWidth + '</PixelWidth>'
        + '<Filename>' + Filename + '</Filename>'
        + '<Quality>' + Quality + '</Quality>'
        + '<Key>' + Key + '</Key>'
        + '<WaterMarkType>' + WaterMarkType + '</WaterMarkType>'
        + '</'+FunctionCall+'></soap:Body>'
        + '</soap:Envelope>';

      var headers = [
          {name:"SOAPAction", value:'"http://www.directsmile.de/GenService/LB/'+FunctionCall+'"'},
          {name:"Host", value:SessionHost},
          {name:"Content-Type", value:'text/xml; charset=utf-8'},
          {name:"Content-Length", value:MyEnvelope.length.toString()}
      ]
      ajaxCall('POST', SessionUrl, headers, MyEnvelope, OnSoapResponse, SessionRunAsync);
	  if (SessionRunAsync == false)
	  {
		return GetResult(FunctionCall+"Result");
	  }
	  else
	  {
		return "";
	  }
    }   

	function GetImageUrlAuth(AuthenticationCode, SetAlias, TextToRender, PixelWidth, Filename, Quality, WaterMarkType)
    {  
	  var FunctionCall = "GetImageUrlAuth";
	  var MyEnvelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
        + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
        + ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        + '<soap:Body><'+FunctionCall+' xmlns="http://www.directsmile.de/GenService/LB">'
        + '<AuthenticationCode>' + AuthenticationCode + '</AuthenticationCode>'
        + '<SetAlias>' + SetAlias + '</SetAlias>'
        + '<TextToRender>' + TextToRender + '</TextToRender>'
        + '<PixelWidth>' + PixelWidth + '</PixelWidth>'
        + '<Filename>' + Filename + '</Filename>'
        + '<Quality>' + Quality + '</Quality>'
        + '<WaterMarkType>' + WaterMarkType + '</WaterMarkType>'
        + '</'+FunctionCall+'></soap:Body>'
        + '</soap:Envelope>';

      var headers = [
          {name:"SOAPAction", value:'"http://www.directsmile.de/GenService/LB/'+FunctionCall+'"'},
          {name:"Host", value:SessionHost},
          {name:"Content-Type", value:'text/xml; charset=utf-8'},
          {name:"Content-Length", value:MyEnvelope.length.toString()}
      ]
      ajaxCall('POST', SessionUrl, headers, MyEnvelope, OnSoapResponse, SessionRunAsync);
	  if (SessionRunAsync == false)
	  {
		return GetResult(FunctionCall+"Result");
	  }
	  else
	  {
		return "";
	  }
    }   
	
	function GetImageUrlDSM(SessionID, SetAlias, TextToRender, PixelWidth, Filename, Quality, Key, WaterMarkType)
    {  
	  var FunctionCall = "GetImageUrlDSM";
	  var MyEnvelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
        + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
        + ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
        + '<soap:Body><'+FunctionCall+' xmlns="http://www.directsmile.de/GenService/LB">'
        + '<SessionID>' + SessionID + '</SessionID>'
        + '<SetAlias>' + SetAlias + '</SetAlias>'
        + '<TextToRender>' + TextToRender + '</TextToRender>'
        + '<PixelWidth>' + PixelWidth + '</PixelWidth>'
        + '<Filename>' + Filename + '</Filename>'
        + '<Quality>' + Quality + '</Quality>'
        + '<Key>' + Key + '</Key>'
        + '<WaterMarkType>' + WaterMarkType + '</WaterMarkType>'
        + '</'+FunctionCall+'></soap:Body>'
        + '</soap:Envelope>';

      var headers = [
          {name:"SOAPAction", value:'"http://www.directsmile.de/GenService/LB/'+FunctionCall+'"'},
          {name:"Host", value:SessionHost},
          {name:"Content-Type", value:'text/xml; charset=utf-8'},
          {name:"Content-Length", value:MyEnvelope.length.toString()}
      ]
      ajaxCall('POST', SessionUrl, headers, MyEnvelope, OnSoapResponse, SessionRunAsync);
	  if (SessionRunAsync == false)
	  {
		return GetResult(FunctionCall+"Result");
	  }
	  else
	  {
		return "";
	  }
    }  

//*************************************************************************************
/*		 In case of Async Operation these Functions are called in redponse 				*/
//*************************************************************************************
	
	function onAuthCodeArrived(ResultValue)
	{
//		alert(ResultValue);
	}

	function onSetListArrived(ResultValue)
	{
//		alert(ResultValue);
	}

	function onImageUrlArrived(ResultValue)
	{
//		alert(ResultValue);
	}

//*************************************************************************************
/*					 Ajax Support Functions 					*/
//*************************************************************************************
	
    function ajaxCall(method, url, headers, Envelope, callback, RunAsync) 
    {
        
        if (xmlHttp = newXMLHTTPRequest()) 
        {
            xmlHttp.open(method, url, RunAsync);

            for( var i = 0; i<headers.length; i++)
            {
                try 
                {
                    xmlHttp.setRequestHeader(headers[i].name, headers[i].value);
                }
                catch (ex)
                {
                    alert(ex);
                }
            }
            xmlHttp.onreadystatechange = callback;
            xmlHttp.send(Envelope);
        }
        else
        {
            alert("AJAX not supported");
        }
    }

	function GetResult(ResultLookup)
	{
		try {
            if (xmlHttp.readyState == 4) 
			{
                if (xmlHttp.status == 200) 
				{
					return parseResult(ResultLookup);
                } else 
				{
                    alert('ERROR xmlHttp.status='+xmlHttp.status+':'+xmlHttp.statusText+' --> '+xmlHttp.responseText);
                }
            }
        }
        catch( e ) 
		{
            alert('Caught Exception: ' + e.description);
        }
	}

    function parseResult(wich) 
    {
        var Result;
		var strPos;
		
		Result = xmlHttp.responseText;

		strPos = Result.search(wich);
		if (strPos == -1) 
		{
		  return "";
		}  
		Result = Result.slice(strPos+wich.length+1);
		Result = Result.slice(0,Result.search('<'));
		return Result;
	}
    
	function OnSoapResponse() 
    {
       // 0 - uninitialized
       // 1 - loading
       // 2 - loaded
       // 3 - interactice
       // 4 - complete 
	   
		var ResultFrom = "";
		var ResultValue = "";

		switch (xmlHttp.readyState)
		{
			case 0:
				//alert("uninitialized");
				break;
			case 1:
				//alert("loading");
				break;
			case 2:
				//alert("loaded");
				break;
			case 3:
				//alert("interactive");
				break;
			case 4:
				ResultFrom = xmlHttp.responseText.slice(xmlHttp.responseText.search('www.directsmile.de/GenService/LB')+35,xmlHttp.responseText.length);
				ResultFrom = ResultFrom.slice(0,ResultFrom.search('>'));
				
				ResultValue = parseResult(ResultFrom);

				if (ResultFrom == 'GetAuthenticationCodeResult')
				{
					onAuthCodeArrived(ResultValue);
				}

				if (ResultFrom == 'GetAvailableSetListAuthResult')
				{
					onSetListArrived(ResultValue);
				}
				
				if (ResultFrom == 'GetImageUrlAuthResult')
				{
					onImageUrlArrived(ResultValue);
				}

				break;
			default:
				alert("unhandled return code from xmlHttp ->" + xmlHttp.readyState);
				break;
		}
    }

    function newXMLHTTPRequest()
    {
        // Mozilla, Opera, Safari and Internet Explorer 7
        if (typeof XMLHttpRequest != 'undefined') 
        {
            xmlHttp = new XMLHttpRequest();
        }
        if (!xmlHttp) 
        {
        // Internet Explorer 6 and later
            try 
            {
                xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
            } 
    
            catch(e) 
            {
                try 
                {
                    xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e) 
                {
                    xmlHttp  = null;
                }
            }
        }    
        return xmlHttp;
    }   

	function wait(msecs)
	{
		var start = new Date().getTime();
		var cur = start
		while(cur - start < msecs)
		{
			cur = new Date().getTime();
		}
	} 













