    //----------------------------------------------------------------------

	function setNewContent(content)
	{
		$('inProgress').value=0;
		
        if($('pauseSpy').value==1)
           return;
	
		if(content.length < 20)
		{
			setTimeout('checkForNew()', 5000);
			return;
		}

		var firstPos = content.indexOf('<***>')+4;

		if(firstPos < 12)
		{
			setTimeout('checkForNew()', 5000);
            return;
		}
		
        var contentParts=content.split('<***>');
        var firstPart = contentParts[0];
		
		firstPos = firstPart.indexOf('lT:|')+4;
		
		var lengthInt = firstPart.indexOf('|:lT')-firstPos;

		var timestampLabel = firstPart.substr(firstPos,lengthInt);
		$('lastTimestamp').value = timestampLabel;

		var firstPos2 = firstPart.indexOf('lID:|')+5;
		var lengthInt2 = firstPart.indexOf('|:lID')-firstPos2;

		var lastID = parseInt(firstPart.substr(firstPos2,lengthInt2));
		
		$('articleID').value = lastID;
			
		
		var newText = firstPart.substr(0,firstPos-4);

        if(firstPart.indexOf('-dontset-') > 4)
		{
			setTimeout('checkForNew()', 5000);
            return;
		}

		if(content.indexOf('<***>') < 10)
			setTimeout('checkForNew()', 5000);
			
		else
		{
			var firstSepPos = content.indexOf('<***>')+5;
		    var textForRecursion = content.substr(firstSepPos,content.length);
			$('textRecursion').value = textForRecursion;
			setContentRecursivly();
		}
	}
	
	//----------------------------------------------------------------------
	
	function setContentRecursivly()
	{
		if($('pauseSpy').value==1)
		{
		   $('textRecursion').value=''; 
           return;
		}
		
		content = $('textRecursion').value;
		
		var contentParts=content.split('<***>');
		var firstPart = contentParts[0];
		
		for(var a=20;a>1;a--)
		{
                    if($('container_'+a))
			$('container_'+a).innerHTML = $('container_'+(a-1)).innerHTML;
		}

		$('container_1').innerHTML = firstPart;
		
		var secondPart = contentParts[1];
		
		if(secondPart)
		{
			var firstSepPos = content.indexOf('<***>')+5;
		    var textForRecursion = content.substr(firstSepPos,content.length);
			$('textRecursion').value = textForRecursion;
			setTimeout("setContentRecursivly()", 1000);
		}
		else
			setTimeout('checkForNew()', 2000);
	}

	//----------------------------------------------------------------------

    function checkForNew()
    {
         if($('pauseSpy').value==1)
            return;
		 
		 if($('inProgress').value==1)
		 	setTimeout('checkForNew()', 1000);
			
		$('inProgress').value=1;
    
		   var url = getSpyUrl();
		   var last_timestamp = $('lastTimestamp').value;
		   var langs = $('langs').value;
		   var lastID = $('articleID').value;

           advAJAX.get({
			   url: url,
			   parameters : {
				"last_timestamp" : last_timestamp,
				"langs" : langs,
				"lastID" : lastID
				},
				onSuccess : function(obj) { setNewContent(obj.responseText) }
			});
    }
    
    function togglePause()
    {
       if($('pauseSpy').value==0)
       {
          $('pauseSpy').value = 1;
          $('pauseButton').value = getSpyButtonLabel(1);
       }
       else
       {
          $('pauseSpy').value = 0;
          $('pauseButton').value = getSpyButtonLabel(0);
		  setTimeout('checkForNew()', 1000);
       }
    }

	//----------------------------------------------------------------------
