var allowed = new Array('.jpg', '.png', '.gif', '.JPG', '.PNG', '.GIF');
var message = '';

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

function validatePostTopic(form)
{
	message = '';
	var errors = new Array;
	if(form.userfile.value == '')
	{
		errors[0] = 'You must upload an image to post a new topic.';
	}
	if(!allowed.in_array(form.userfile.value.substr(form.userfile.value.length - 4)) && form.userfile.value != '')
	{
		errors[1] = 'Disallowed file type.';
	}
	if(errors.length > 0)
	{
		for(var i = 0;i < errors.length;i++)
		{
			if(errors[i])
			message += errors[i] + "\n";
		}
		alert(message);
		return false;
	}
	return true;
}

function validatePostReply(form)
{
	message = '';
	var replyErrors = new Array;
	if(!allowed.in_array(form.userfile.value.substr(form.userfile.value.length - 4)) && form.userfile.value != '')
	{
		replyErrors[0] = 'Disallowed file type.';
	}
	if(form.userfile.value == '' && form.comment.value == '')
	{
		replyErrors[1] = 'To reply you must either upload an image or post a comment.';
	}
	if(replyErrors.length > 0)
	{
		for(var i = 0;i < replyErrors.length;i++)
		{
			if(replyErrors[i])
			message += replyErrors[i] + "\n";
		}
		alert(message);
		return false;
	}
	return true;	
}