function addcomment(){

	if (checkEmail(document.commentform.email.value) == true){
	if (checkForm(document.commentform) == true){
      var ajaxRequest;
      try { //Opera 8.0+, Firefox, Safari
         ajaxRequest = new XMLHttpRequest();
      }
      catch(e) {
         //Internet Explorer Browsers
         try {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch(e) {
            try {
               ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e) {
               // Something went wrong
               alert("Your browser broke!");
               return false;
            }
         }
      }
      //Create a function that will receive the data from the server
      ajaxRequest.onreadystatechange = function() {
         if ( ajaxRequest.readyState == 4 ) {
				//alert(ajaxRequest.responseText);	
            alert("Thank you for your comment. It will be reviewed before being posted.");
				//alert(document.commentform.hiddenID.value);
         }
      }
      var str = "addcomment.php?name=" + document.commentform.name.value +
      	"&email=" + document.commentform.email.value + 
			"&message=" + document.commentform.message.value + 
			"&id=" + document.commentform.hidden_id.value;
      ajaxRequest.open("GET", str ,true);
      ajaxRequest.send(null);
   //window.location.reload();
   document.commentform.reset();
	}
	}
}

function checkEmail(contact) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(contact) ){
      return (true);
   }
	   alert("Invalid E-mail Address! Please re-enter.")
	   return (false);
}

function checkForm(form) {
	if (form.name.value == "" || form.message.value == ""){
		alert("You are required to fill out all fields.");
		return(false);
	}
	else{
		return(true);
	}
}
