var Pattern = new Object();

Pattern.word = /[\w\d]+/;
Pattern.number = /^[,\d\s]+$/;
Pattern.email = /^[-.\w\d]{1,20}[@][-.\w\d]{1,30}$/;

function isThere(stuff)
{
	if (stuff == "")
		return false;

return true;
}

function isChar(word)
{
	if (Pattern.word.test(word))
		return true;

return false;
}

function isNum(number)
{
	if (Pattern.number.test(number))
		return true;

return false;
}

function isEmail(email)
{
	if (Pattern.email.test(email))
		return true;

return false;
}


function validateForm(form)
{
	errorCount = "";
	errorMessage = "An error has occured in the following fields: \n\n";

	var currentValue = form.elements;

	for (i=0; i<currentValue.length; i++)
	{
		var theValue = currentValue[i].value;
        var theValidator = currentValue[i].getAttribute('validator');
		var required = currentValue[i].getAttribute('required');
        var theMessage = currentValue[i].getAttribute('message');
        var theName = currentValue[i].getAttribute('name');
        var result = '';
		
		
		if (!required && !theValue){
			continue;
		}
		
        if (!theValidator){
			continue;
		} else if (theValidator == "exist") {
			result = isThere(theValue);
		} else if (theValidator == "word" || theValidator == "string") {
			result = isChar(theValue);
		} else if (theValidator == "number") {
			result = isNum(theValue);
		} else if (theValidator == "email"){
			result = isEmail(theValue);
		}
		
		
		if (required && theValue == '') {
			theMessage = theName + ' is a required field, but does not have a value.';
			result = false;
		}
		
		if (!result){
			errorCount += theMessage + "\n\n";
		}
	}

	if (errorCount != "")
	{
		alert(errorMessage + errorCount);
        return false;
	}
return true;
}



