function createRequestObject() {

   var req;

   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
     alert("Your Browser Does Not Support This Script - Please Upgrade Your Browser ASAP");
   }

   return req;

}

// Make the XMLHttpRequest object
var http = createRequestObject();

function subscribe(username) {
   http.open('get','include/subscribe.php?name=' + username);
   http.onreadystatechange = handleResponse;
   http.send(null);
}

function block(username) {
   http.open('get','include/block.php?name=' + username);
   http.onreadystatechange = handleBlock;
   http.send(null);
}

function handleResponse() {
   if(http.readyState == 4){

      // Text returned FROM the PHP script
      var response = http.responseText;
      if(response) {
	//	 response = response.replace(/<.*?>/g, '');
	//	 response = response.replace(/\+/g, '<br>');
         // UPDATE ajax content
		 var re = new Array();
		 re	= response.split("|");

         if (response.search("unsubscribed") != -1) {
			document.getElementById("sub_ico").src = "images/icons/subscribe.png";
		 } else if (response.search("subscribed") != -1){
			document.getElementById("sub_ico").src = "images/icons/unsubscribe.png";
		 }
		
		 document.getElementById("sub_txt").innerHTML = "<small>" + re[0] + "</small>";
		 if(re.length>1) document.getElementById("subscriptions").innerHTML = re[1];
      }
   }

}

function handleBlock() {
   if(http.readyState == 4){

      // Text returned FROM the PHP script
      var response = http.responseText;
      if(response) {
	//	 response = response.replace(/<.*?>/g, '');
	//	 response = response.replace(/\+/g, '<br>');
         // UPDATE ajax content
	//	 var re = new Array();
	//	 re	= response.split("|");

         if (response.search("Blocked") != -1) {
			document.getElementById("block").innerHTML = "<img src=\"images/icons/unblock.gif\"> unblock";
		 } else {
			document.getElementById("block").innerHTML = "<img src=\"images/icons/block.gif\"> block";
		 }
		

      }
   }

}