
/*#################################################################################
 * 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>";
	document.getElementById('captcha').src = 'images/progress.gif';
	timer = setTimeout("set_captcha();", 300);
}

function set_captcha()
{
	var rand = Math.floor(Math.random()*101)
	myimg=new Image()
	myimg.src = 'includes/function_captcha.php?id=' + rand;
	document.getElementById('captcha').src = myimg.src;
}

/*#################################################################################
 * 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);
}

/*#################################################################################
 * Comment form validation; Makes submit button on comment forms available
 #################################################################################*/
function validate()
{
	if (document.commentform.comment.value.length > 0)
	{
		document.commentform.addcomment.disabled = false;
	}
	else
	{
		document.commentform.addcomment.disabled = true;
	}
}

/*######################################################################################
 * Return an array with the mouse cursor's X and Y position; Parameter is self-defined
 #######################################################################################*/
function getXY(e)
{
	var mousePos = new Array();
	xPos = (window.Event) ? e.pageX : event.clientX;
	yPos = (window.Event) ? e.pageY : event.clientY;
	
	mousePos[0] = xPos;
	mousePos[1] = yPos;
	
	return mousePos;
}