	var windowFocused   = 20000; //if window got focuses, this is the interval for refreshing (20 seconds)
	var windowBlurred   = 60000; //if window lost it focus, decrease the refresh interval to save bandwidth (60 seconds)
	var pingInterval = windowFocused; 
	var isWorking = false;
	
	if((smiletagURL == "http://WWW.EXAMPLE.COM/smiletag/") || (smiletagURL == null)){
		var smiletagURL = "smiletag/";
	}
	
	var url = smiletagURL + "backend.php"; // The url to check the new message status
	
	//clear the message from the text area
	function clearMessage(){
		document.smiletagform.message.value=document.smiletagform.message_box.value;
	    document.smiletagform.message_box.value="";
    }
	
	//reload the iframe
	function reloadMessage(){
		var smiletagFrame = window.frames['iframetag'];
		smiletagFrame.location = smiletagURL + "view.php";
	}
	
	//check for new message
    function checkMessage(){
		if(!isWorking && (http != null)) {
			http.open("GET", url, true);
			http.onreadystatechange = handleHttpResponse;
			isWorking = true;
			http.send(null);
		}
		setTimeout('checkMessage()',pingInterval);
	}
	
	//check for new message, without calling the next settimeout
	//this function called when window got focus, so everytime user display the window
	//they will get the latest message
	function checkMessageForced(){
		if(!isWorking && (http != null)) {
			http.open("GET", url, true);
			http.onreadystatechange = handleHttpResponse;
			isWorking = true;
			http.send(null);
		}
	}
	
	
	function handleHttpResponse() {
	  if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1) {
		   var responseText = http.responseText; 
	   	   if(responseText == '1'){
				reloadMessage();
		   }     
		   isWorking = false;
		}
	  }
	}
	
	function getHTTPObject() {
	  var xmlhttp;
	  /*@cc_on
	  @if (@_jscript_version >= 5)
		try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		  try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			xmlhttp = false;
		  }
		}
	  @else
	  xmlhttp = false;
	  @end @*/
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
		  xmlhttp = new XMLHttpRequest();
		  xmlhttp.overrideMimeType("text/xml"); 
		} catch (e) {
		  xmlhttp = false;
		}
	  }
	  return xmlhttp;
	}
	
	var http = getHTTPObject(); // create the HTTP Object
	
	setTimeout('checkMessage()',pingInterval);
	
	window.onfocus=function(){
    	checkMessageForced();
    	pingInterval = windowFocused;
    }
	
    window.onblur=function(){
    	pingInterval = windowBlurred;
    } 
/* Impostazioni finestra popup smile */
	function popUpSmilies(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=250,height=300,left = 501,top = 332');");
	}

	function popUpArchive(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=245,height=400,left = 501,top = 332');");
	}


