/*
 * Name: Advanced Comment System
 * Version: 1.01
 * Created by: WebDevProject.com
 * User: Graphix
*/

function AddComment(id, id_type) {

var comment = document.getElementById('comment_txt').value;
 
if (comment.length > 3) {
 
 var ajax = false;

 // Create the object:

 // Choose the objecttype, depending on what is supported:
 if (window.XMLHttpRequest) {

    // IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
    ajax = new XMLHttpRequest();

 } else if (window.ActiveXObject) { // Old IE-browsers

    // Make the type Msxml2.XMLHTTP, if possible:
    try {
        ajax = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) { // Else use the other type:
        try {
            ajax = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e2) { }
    }

 }

 // Retrieving the data from the page

 if (ajax) {

   var url = "/comment.php?act=add&id=" + encodeURIComponent(id) + "&id_type=" + encodeURIComponent(id_type) + "&comment=" + encodeURIComponent(comment);

   ajax.open('GET', url);

   // Sends request
   ajax.send(null);
   var t = 0;
   // Function that handles response
   ajax.onreadystatechange=function(){
    // If everything is OK:
     if ( (ajax.readyState == 4) && (ajax.status == 200) ) {
          // Returns the value to the document
		  if (ajax.responseText == 'Succes') {
		    location.reload(true);
		  } else {
			alert("An error has occured, our apologies for the inconvenience. If this error persists, please contact us.");
		  }
	 }
    }


 } else { // AJAX is not useable
     alert('It is not possible to connect, please update your browser.');
 }
 
} else {
	alert('Your comment needs to be atleast 4 characters long!');
}
 
}
