// when the submit button is pressed this function is launched and will do a quick validation, then send to the server
function sendComment()
{
	// clear errors
	document.getElementById("errors").innerHTML = '';
	
	var com_name = document.addComm.name;
	var com_email = document.addComm.email;
	var com_comments = document.addComm.comments;
	// validate
	if(com_name.value == '' || com_comments.value == '' || com_email.value == '') {
			var err = new Array("Please fill in all fields");
			showErrors(err);
	} else {
		// we got some data lets send her on through boys 
		var postVars = 'action=api_postComment&name='+ajaxObj.getForm('addComment');
		//alert(postVars);
		//var postVars = 'action=api_postComment&name='+encodeURIComponent(com_name.value)+'&email='+encodeURIComponent(com_email.value)+'&comments='+encodeURIComponent(com_comments.value);
		ajaxObj.call(postVars, respComment);
	}
	
}

// after the ajax request for posting a comment this function will either show errors from the server or a success message
function respComment(resp) {
	
	if(resp) {
		if(resp.errors) { 
			showErrors(resp.errors); 
		} else {
			document.getElementById("errors").innerHTML = resp;
			document.addComm.name.disabled = true;
			document.addComm.email.disabled = true;
			document.addComm.comments.disabled = true;
			document.addComm.but.disabled = true;
			
		}
	} else {
			var err = new Array("An unknown error occurred");
			showErrors(err);
	}
}

function showErrors(errors)
{
	var errs = '';
	var err_display = document.getElementById("errors");
	var err_beg = '<p>Error:<BR/>';
	for(var i in errors) {
		errs =  errors[i]+"<BR>";
	}
	
	err_display.innerHTML = err_beg + errs +'</p>';
}

