function showCommentForm(art_id) {
	art_form = document.getElementById('comment_' + art_id);
	
	art_form.style.display = 'block';
	document.forms['comment_form'].elements['comment_' + art_id].focus();
}

function deleteComment(comment_id, parent_object_id, parent_object) {
	if(!confirm('Are you sure?')) {
		return false;
	}
	
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	
	var url = "/comment/delete/" + comment_id;
	
	xmlhttp.open("POST", url ,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
//			commentsDiv = document.getElementById('comment_container_' + art_id);
//			commentsDiv.innerHTML = xmlhttp.responseText;			
			getComments(parent_object, parent_object_id);
		}
	}
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8'); 	
	xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");	
	xmlhttp.send('parent_object=' + parent_object + '&parent_id=' + parent_object_id);	
}

function submitComment(parent_object, parent_object_id) {
	var comment = document.forms['comment_form'].elements['comment_' + parent_object_id].value;
	if(comment == "") {
		alert("Enter a comment");
		return false;
	}
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	
	var url = "/comment/create/" + parent_object_id;

	xmlhttp.open("POST", url ,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.forms['comment_form'].elements['comment_' + parent_object_id].value = '';
			getComments(parent_object, parent_object_id);
		}
	}
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8'); 	
	xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");	
	xmlhttp.send('parent_object=' + parent_object + '&comment=' + encodeURIComponent(comment));
	
}

function getComments(parent_object, parent_object_id) {
	
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	
	var url = "/comment/index/" + parent_object_id;
	
	xmlhttp.open("POST", url ,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			commentsDiv = document.getElementById('comment_container_' + parent_object_id);
			commentsDiv.innerHTML = xmlhttp.responseText;
			showCommentForm(parent_object_id);
		}
	}
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");	
	xmlhttp.send('parent=' + parent_object)
}
