var http = createRequestObject();
var base_url = "http://www.woim.net/";
var divid = '';

function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}

function trim(a) {
	return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
}

function comment_song_handleResponse() {
	try {
		if((http.readyState == 4)&&(http.status == 200)){
			//document.getElementById("comment_field").style.display = "none";
			var response = http.responseText;
			if (response != "") {
				document.getElementById("btnAlbumCommentSend").disabled = false;
				old_value = document.getElementById("comment_area").innerHTML;
				document.getElementById("comment_area").innerHTML = response + old_value;
			}
			document.getElementById("comment_status").style.display = "none";
			document.getElementById("comment_content").value = "";
		}
  	}
	catch(e){}
	finally{}
}

function comment_song() {
	ok = false;
	
	content = encodeURIComponent(document.getElementById("comment_content").value);
	id = encodeURIComponent(document.getElementById("comment_id").value);

	if (trim(content) == "") {
		alert("Bạn chưa nhập nội dung cảm nhận. (No Comment on textbox)");
	}
	else {
		try{
			document.getElementById("btnAlbumCommentSend").disabled = true;
			
			document.getElementById("comment_status").style.display = "block";
			http.open('POST', base_url + 'comment/song');
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = comment_song_handleResponse;
			http.send('comment_act=song&comment_content='+content+'&id='+id);

		}
		catch(e){}
		finally{}
	}
	return ok;
}

