function comment(id) {
	document.getElementById("valid").innerHTML = '';
	document.getElementById("comment").innerHTML = '<br><input type="hidden" name="id" id="id" value="' + id + '">Name: <br /><input type="text" name="name" id="name" size="30"/><br>Email: <br><input type="text" name="email" id="email" size="30"/><br>Comment: <br /><textarea name="articlecomment" id="articlecomment" rows="7" cols="45"></textarea><br><button type="button" onClick="addComment()">Submit</button>';
}
function addComment(){
	var id = document.getElementById('id');
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var comment = document.getElementById('articlecomment');
	document.getElementById("comment").innerHTML = '<img src="images/loading.gif">';
	var valid = "";
	if(name.value == null || name.value == ""){
		valid = "You must enter a name<br>";
	}
	if(email.value == null || email.value == ""){
		if(valid == ""){
			valid = "You must enter an email address<br>";
		}
		else {
			valid = valid + "You must enter an email address<br>";
		}
	}
	if(comment.value == null || comment.value == ""){
		if(valid == "") {
		valid = "You must enter a comment<br>";
		}
		else {
			valid = valid + "You must enter a comment<br>";
		}
	}
	if(valid != ""){
		valid = '<br><span style="color: red;">' + valid + "</span><br>"
		document.getElementById("valid").innerHTML = valid;
	}
	else {
		var send = "id=" + id.value + "&name=" + name.value + "&email=" + email.value + "&comment=" + comment.value;
		$.ajax({
			type: "GET",
			url: "http://www.thecornellian.com/archives/addcomment.php",
			data: send,
			dataType: "text",
			success: function(msg){
				if(parseInt(msg)==1){
					document.getElementById("comment").innerHTML = '';
					document.getElementById("valid").innerHTML = '<br /><span style="color: green;">Your comment was added and is awaiting approval</span><br />';
				}
				else if(parseInt(msg)==2){
					document.getElementById("comment").innerHTML = '';
					document.getElementById("valid").innerHTML = '<br /><span style="color: red;">Please enter a valid email address</span><br>';
				}
				else{
					document.getElementById("comment").innerHTML = '';
					document.getElementById("valid").innerHTML = '<br /><span style="color: red;">There was an error submitting your comment. Please Try again later</span><br>';
				}
			}
		});
	}
}
