   var http_request = false;
   function makePOSTRequest(url, parameters, listener) {
      showLoading(1);
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            http_request.overrideMimeType('text/xml');
            //http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = listener;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }


   function responseListener() {
      if (http_request.readyState == 4) {

         if (http_request.status == 200) {
            result = http_request.responseText;
            document.getElementById('response').innerHTML += "<li><b><u>Bot:</u></b> " + result + "</li>";            
         } else {
            alert('There was a problem with the request.');
         }
         showLoading(0);
		 document.getElementById('query').focus();
      }
   }

   function clientListener() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
		} else {
            alert('There was a problem with the request.');
         }
	  showLoading(0);
      }
   }

   function submitCommentListener() {
      if (http_request.readyState == 4) {

         if (http_request.status == 200) {
            result = http_request.responseText;
            document.getElementById('commentStatus').innerHTML = result;            
			document.getElementById('commentStatus').className = "ystatus";	  

			document.getElementById('submitButton').value = "Submit Comment";
			document.getElementById('submitButton').disabled = false;
			} else {
            alert('There was a problem with the request.');
         }
         showLoading(0);
      }
   }
   
   function submitBCommentListener() {
      if (http_request.readyState == 4) {

         if (http_request.status == 200) {
            result = http_request.responseText;
			if (result != "0")
			{
				document.getElementById('bcomment').value = "";	  
				document.getElementById('commentBStatus').innerHTML = "<center>Thanks for your comment!</center>";            
				document.getElementById('blogComments').innerHTML = result + document.getElementById('blogComments').innerHTML;
			}
			else
			{
				document.getElementById('commentBStatus').innerHTML = "<center>You should at least fill comment and name!</center>";            
			}
			document.getElementById('commentBStatus').className = "ystatus";	 			
			document.getElementById('submitBButton').value = "Submit Comment";
			document.getElementById('submitBButton').disabled = false;
			} else {
            alert('There was a problem with the request.');
         }
         showLoading(0);
      }
   }
   
   function getResponse(query, id) {
      var poststr = "query=" + encodeURI(query.value + "&userID=" + id);
      document.getElementById('response').innerHTML += "<li><b>You: </b> " + query.value + "</li>";            
	  query.value="";
	  
      makePOSTRequest('/portal/botapi', poststr, responseListener);
   }
   
   function submitComment(obj) {
	  obj.disabled = true;
	  obj.value = "Wait...";
      var poststr = "name=" + encodeURI(document.getElementById('name').value) + "&email=" + encodeURI(document.getElementById('email').value) + "&website=" + encodeURI(document.getElementById('website').value) + "&comment=" + encodeURI(document.getElementById('comment').value) + "&where=" + encodeURI("->");
	  document.getElementById('comment').value = "";	  
      makePOSTRequest('/portal/modules/comments/submitComment.php?lang=', poststr, submitCommentListener);
   }   

   
   function submitBComment(obj) {
	  obj.disabled = true;
	  obj.value = "Wait...";
      var poststr = "name=" + encodeURI(document.getElementById('bname').value) + "&email=" + encodeURI(document.getElementById('bemail').value) + "&website=" + encodeURI(document.getElementById('bwebsite').value) + "&comment=" + encodeURI(document.getElementById('bcomment').value) + "&blogID=" + encodeURI(document.getElementById('bID').value);
      makePOSTRequest('/portal/modules/blog/submitComment.php?lang=', poststr, submitBCommentListener);
   }    
   
   function client(id, action, arg1, arg2) {
	  if (typeof arg2 != "undefined")
		var poststr = "id=" + encodeURI(id) + "&action=" + encodeURI(action) + "&arg1=" + encodeURI(arg1) + "&arg2=" + encodeURI(arg2);
	  else if (typeof arg1 != "undefined")
		var poststr = "id=" + encodeURI(id) + "&action=" + encodeURI(action) + "&arg1=" + encodeURI(arg1);
	  else
		var poststr = "id=" + encodeURI(id) + "&action=" + encodeURI(action);
      makePOSTRequest('/portal/clientapi', poststr, clientListener);
   }
   
   function control(id, name) {
		document.getElementById('statusDiv').innerHTML = "Change status of "+ name;
		document.getElementById('sendDiv').innerHTML = "Send IM to "+ name;
		document.getElementById('controlDiv').className = "visible";
		document.getElementById('clientid').value = id;
   }
   
