// JavaScript file to validate forms
// Provides global functions to validate forms at each step, will reply if 
// something is outside the constraint of the validation

function revealError(id, message)
{
	var newElement = document.createElement("p");
	var textElement = document.createTextNode(message);
	
	newElement.appendChild(textElement);
	newElement.className = "fineprint_red";
	id.appendChild(newElement);
}

function removeError(id)
{
	var nodeList = id.childNodes;

	id.removeChild(nodeList[1]);
}

function checkEmail(emailError, email)
{
	var reg = eval(/^(\w([-._\w]*\w)*@(\w[-_\w]*\w\.)+\w{2,9})$/);
	if(reg.exec(email)) {
		removeError(emailError);
	} else {
		revealError(emailError, "There is an error in your email address.");
	}
}

function checkText(idField, strng)
{
	var reg = eval(/[A-Za-z]/);
	if(reg.exec(strng)) {
		removeError(idField);
	} else {
		revealError(idField, "The text you have entered contains invalid characters, such as letters or numbers.");
	}
}

function checkCreditCard(ccType, ccnumber)
{
	
}