function postCommentRequest() {
	var oForm = document.getElementById('postComment');
	var message = oForm.elements['p-comment'].value;
	if (message.length > 1000) {
		message=message.substring(0, 1000)
	};
	// open socket connection
	XMLHttpObj.open('POST', "post_comment.asp", true);
	// set form http header
	XMLHttpObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	// get form values and send http request
	XMLHttpObj.send(getFormValues(oForm));
	XMLHttpObj.onreadystatechange = commentStatusChecker;
	document.getElementById("commentForm").innerHTML = 'Processing.';
	document.getElementById("commentForm").align = 'center';
	document.getElementById("commentForm").style.width = "100%";
	document.getElementById("commentText").style.display = "none";
}

// check status of email requester object
function commentStatusChecker() {
	var msg = 'Processing....';
	// if mail request is completed
	switch(XMLHttpObj.readyState) {
		case 1 : msg = 'Processing..';
		case 2 : msg = 'Processing...';
		case 3 : msg = 'Processing....';
		case 4 : {
			if (XMLHttpObj.status == 200) {
				msg = 'Comment was posted successfully!';
			}
			else{
				msg = 'Failed to post comment : ' + XMLHttpObj.statusText + XMLHttpObj.responseText;
			}
		}
	}
	document.getElementById("commentForm").innerHTML = msg;
}

// Vote for a painting
function voteRequest(picParam, voteParam) {
	var aParams = new Array();
	aParams.push(encodeURIComponent("pic") + "=" + encodeURIComponent(picParam));
	aParams.push(encodeURIComponent("vote") + "=" + encodeURIComponent(voteParam));
  var query = aParams.join("&");
  
	XMLHttpObj.open('POST', "vote.asp", true);
	XMLHttpObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	XMLHttpObj.send(query);
	XMLHttpObj.onreadystatechange = voteStatusChecker;

  return false;
}

function voteStatusChecker() {
  if (XMLHttpObj.readyState == 4) {
		if (XMLHttpObj.status == 200) {
      // Disable voting
    	var rat = document.getElementById("rating");
      var lists = rat.getElementsByTagName("LI");
      var count = lists.length;
      for (i = 1; i < count; i++) {
        lists[i].style.display = "none";
      }
      var stars = XMLHttpObj.responseText;
      lists[0].style.width = stars * 20;
  	}
  	else{
  		alert('Failed to post vote : ' + XMLHttpObj.statusText);
  	}
  }
}
