CiComments = function() {	
}

CiComments.setFocus = function() {
	var fObj = document.getElementById("cicommentsForm");
	if (fObj) {
                var dObj = document.getElementById("comment_box");
	 	if (dObj) {
			dObj.style.display = "block";			
			fObj.user_name.focus();
		}
	}	
}

CiComments.validate = function() {
	var fObj = document.getElementById("cicommentsForm");
	if (fObj) {
		if (fObj.user_name.value == '') {
		 	alert( "Please enter your Name!" );
			fObj.user_name.focus();
			return false;
		} else if ( ( fObj.user_email.value == "" ) || ( fObj.user_email.value.search("@") == -1 ) || 
					( fObj.user_email.value.search("[.*]" ) == -1 ) ) {
			alert( "Please enter a valid e-mail address. (e.g. yourname@yourdomain.com)!" );
			fObj.user_email.focus();
			return false;
		} else if (fObj.comment.value == '') {
			alert( "Please enter your Comment first!" );
			fObj.comment.focus();
			return false;
		}
		return true;
	}
}

CiComments.submitComment = function() {
 	if (CiComments.validate()) {
 	 	var url = "index.php";
    	var params = "option=com_cicomments&format=raw&task=store";
	    var fObj = document.getElementById("cicommentsForm");
		if (fObj) {
			params += Ajax.serializeFormInputs(fObj.id);
			var contId = "comment_box";
            CiComments.toggleAdLink();
			Ajax.showLoading(contId);
			Ajax.doPost(url, Ajax.refreshWidget, true, contId, params, this, false);
		}
    }
}
CiComments.toggleAdLink = function() {
 	var dObj = document.getElementById("comment_add_link");
 	if (dObj) {
 	 	if (dObj.style) {
			if (dObj.style.display == "none") {
			 	dObj.style.display = "block";
			} else {
				dObj.style.display = "none";			
			}
		}       
    }
}
