var commentDiv = '';

function submitFormNew(form, div) {
	
	commentDiv = div;

    var checkLogin=isLoggedIn();
    
    if (commentDiv == 'solution_box0') {
    	if (document.forms[form].elements["comments"].value=='Please type your comment here...') {
			alert ('You did not enter a comment, please enter a comment and resubmit');
			return;
		}

		if (document.forms[form].elements["comments"].value=='') {
			alert ('You did not enter a comment, please enter a comment and resubmit');
			return;
		}
    } else {
    	if (document.forms[form].elements["reply"].value=='Please type your comment here...') {
			alert ('You did not enter a reply, please enter a reply and resubmit');
			return;
		}

		if (document.forms[form].elements["reply"].value=='') {
			alert ('You did not enter a reply, please enter a reply and resubmit');
			return;
		}
    }

	if (checkLogin !=0) {

	} else {
		alert ('You are not logged in...Please login above');
		return;
	}

    ColdFusion.Ajax.submitForm(form, '/CommentPostPage.cfm?Action=Comment', callback, errorHandler);
    //window.location.reload(true);
}
 
function errorHandler(code, msg) {
    //alert("Error!!! " + code + ": " + msg);
}

function callback(text) {
	if (commentDiv == 'solution_box0') {
    	$('html, body').animate({
			scrollTop: $("#AjaxSolutions").offset().top
		}, 2000);
		
		if (parseInt($("#commentsNumberForm").val()) == 0) {
			document.getElementById("noComments").innerHTML = '<div id="commentsNumber" style="display:inline">1</div> Comments';
		}
										                    	
		document.getElementById("commentsNumber").innerHTML = parseInt($("#commentsNumberForm").val()) + 1;
		document.getElementById("commentsNumberForm").value = parseInt($("#commentsNumberForm").val()) + 1;
		document.getElementById('comments').value='Please type your comment here...';
	} else {
		//alert(commentDiv);
		$('html, body').animate({
			scrollTop: $("#" + commentDiv).offset().top
		}, 2000);
		document.getElementById('reply').value='Please type your comment here...';
	}
	
	document.getElementById(commentDiv).innerHTML=text+document.getElementById(commentDiv).innerHTML;
}
