function formValidation(form, submitFunction)
{
	for(var x = 0; x <= form.length - 1; x++)
	{
		if((form[x].type == 'text') || (form[x].type == 'textarea') || (form[x].type == 'password') || (form[x].type == 'file') || (form[x].type == 'hidden'))
		{
			var validationfunction = form[x].attributes['validationfunction'].value;
			var associatelabel = form[x].attributes['associatelabel'].value;
			var errormessage = form[x].attributes['errormessage'].value
			
			if((associatelabel != '') && (associatelabel != undefined))
				document.getElementById(associatelabel).innerHTML = '';
				
			if((validationfunction != '') && (validationfunction != undefined))
			{
				var validationFunction = eval(validationfunction);
				
				if((errormessage != '') && (errormessage != undefined))
				{
					if(!validationFunction(form[x].value))
					{
						if((associatelabel != '') && (associatelabel != undefined))
							document.getElementById(associatelabel).innerHTML = errormessage;
						else
							alert(errormessage);
						
						try
						{
							form[x].focus();
						}
						catch(ex) {}
						
						return;
					}
				}
			}
		}
	}
	
	if(submitFunction != null)
		eval(submitFunction);
	else
	{
		form.submit();
	}
}

function hasValue(value)
{
	if(value)
		return true;
	else
		return false;
}

function isEmail(value)
{
	if(!value.match(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.[a-z]{2,4}$/i))
		return false;
	else
		return true;
}

function isInt(value)
{
	if(!hasValue(value))
		return false;
	else if(isNaN(value))
		return false;
	else
		return true;
}

function confirmBox(message)
{
	if(confirm(message))
		return true;
	else
		return false;
}

function maxChars(obj, i)
{
	var value = obj.value;
	var length = obj.value.length;
	
	if(length >= i)
		obj.value = value.substring(0, i);
}
