
/*#################################################################################
 * Reset all CAPTCHA instances on the page. No parameters are necessary as each
 * page should have only one CAPTCHA.
 #################################################################################*/
function reset_captcha() {
	document.getElementById('captcha').innerHTML = "<img src=includes/function_captcha.php>";
}

/*#################################################################################
 * Activates loader box and ensures loader animation doesn't freeze in Internet
 * Explorer.
 #################################################################################*/
function form_submit() {
	var load = document.getElementById('loadbox');
	document.form.submit();
	document.getElementById('loader').innerHTML = '<DIV id="loadbox"><SPAN class="general">Please Wait...</SPAN><BR><img src="images/pbar5.gif"></DIV>';
}

/*#################################################################################
 * Runs an AJAX script in ajax_click.php to record clicks on external links
 * 
 * Parameters:
 *		id => Link ID as used in maj_links table
 #################################################################################*/
function linkout(id) {
	var req = null;
	
	// Browser compatible AJAX connection
	if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
		if (req.overrideMimeType) {
			req.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	};
	
	// Send link ID to ajax_click.php to record the action
	var queryString = "?id=" + id;
	req.open("GET", "includes/ajax_click.php" + queryString, true);
	req.send(null);
	return true;
}


/*#################################################################################
 * Runs an AJAX script in ajax_spam.php to report spam in the user comment boxes.
 * 
 * Parameters:
 *		media => Media type as used in maj_comments table
 *		id => The comment id
 *		url => A link to the page containing spam
 #################################################################################*/
function comspam(media, id, url) {
	var req = null;
	
	// Browser compatible AJAX connection
	if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
		if (req.overrideMimeType) {
			req.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	};
	
	// Run script to report spam
	var queryString = "?id=" + id + "&type=" + media + "&url=" + url;
	req.open("GET", "includes/ajax_spam.php" + queryString, true);
	req.send(null);
	
	// Change the link so that users can't report again
	var item = media + '_' + id;
	document.getElementById(item).innerHTML = "(<SPAN class=\"general\" style=\"font-size: 11px; color: red;\">Reported</SPAN>)";
}

/*#################################################################################
 * Enforces textareas to maintain specific character limits
 * 
 * Parameters:
 *		field => The textarea path "Example: this.form.field1 "
 *		maxlimit => Maximum characters allowed
 #################################################################################*/
function textCounter(field, maxlimit)
{
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0, maxlimit);
}

function validate()
{
	if (document.commentform.comment.value.length > 0)
	{
		document.commentform.addcomment.disabled = false;
	}
	else
	{
		document.commentform.addcomment.disabled = true;
	}
}