
function createxmlhttp()
{
    xmlhttpobj = false;
    try{//Create an object, have to try one by one because there is no standart for browers made by different companies.
        xmlhttpobj = new XMLHttpRequest();
    }catch(e){
        try{
            xmlhttpobj=new ActiveXObject("MSXML2.XMLHTTP");
        }catch(e2){
            try{
                xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP");
            }catch(e3){
                xmlhttpobj = false;
            }
        }
    }

    return xmlhttpobj; 
}



function refreshCommentRating(commentID, newvalue, rating) {


	var xmlhttpobj = createxmlhttp();

	if (xmlhttpobj)
	{
		xmlhttpobj.open("get", "addcommentrating.asp?commentID="+commentID+"&newvalue="+newvalue+"&rating="+rating+"&number="+Math.random(),true); 
		xmlhttpobj.send(null);
							
		xmlhttpobj.onreadystatechange=function()
		{  			
			if (xmlhttpobj.readyState==4)
			{
			if (xmlhttpobj.status==200)
				{
					var html = xmlhttpobj.responseText;
					document.getElementById('commentrating'+commentID).innerHTML=html;
				}
				else
				{
					document.getElementById('commentrating'+commentID).innerHTML="No data to display.";
				}
			}
			else
			{
				document.getElementById('commentrating'+commentID).innerHTML="Processing. Please wait ...";//server is processing
			}
		}
	}

}


function ajax()
 {
	 var url = "microblogdisplay.asp";
	 target = "microblog";
    // native XMLHttpRequest object
   document.getElementById(target).innerHTML = 'refreshing...';
   if (window.XMLHttpRequest) {
       req = new XMLHttpRequest();
       req.onreadystatechange = function() {ajaxDone(target);};
       req.open("GET", url, true);
       req.send(null);
   // IE/Windows ActiveX version
   } else if (window.ActiveXObject) {
       req = new ActiveXObject("Microsoft.XMLHTTP");
       if (req) {
           req.onreadystatechange = function() {ajaxDone(target);};
           req.open("GET", url, true);
           req.send();
       }
   }
		   setTimeout("ajax()", 50000);
}

function ajaxDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200 || req.status == 304) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="ajax error:\n" +
req.statusText;
}
}
}

