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].validator;
        var theMessage = currentValue[i].message;
        var theName = currentValue[i].name;
        var result = "";

        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 (!result)
			errorCount += theMessage + "\n\n";
	}

	if (errorCount != "")
	{
		alert(errorMessage + errorCount);
        return false;
	}

return true;
}



