var xmlHttp;

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
    
function createQueryString(rating, postID) {
    var queryString = "r=" + rating + "&p=" + postID;
    return queryString;
}

function submitVote(rating, postID) {
    createXMLHttpRequest();
    
    var url = "post_ratings_ajax.php?timeStamp=" + new Date().getTime();
    var queryString = createQueryString(rating, postID);
    
    xmlHttp.open("POST", url, true);
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
    xmlHttp.send(queryString);
}
    
function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            parseResults();
        }
    }
}

function parseResults() {
	respObj = eval("("+xmlHttp.responseText+")");
    	var responseDiv = document.getElementById("resp" + respObj.postid);
    	responseDiv.innerHTML = respObj.response;
}

function showHide(id){ 
if (document.getElementById){ 
	obj = document.getElementById(id); 
	if (obj.style.display == "none"){ 
		obj.style.display = ""; 
	} else { 
		obj.style.display = "none"; 
	} 
} 
} 