////////////////////////////////////////////////////////////////////////
//Main checking functions
////////////////////////////////////////////////////////////////////////
function checkNumber(string){
	var output = true;
	if(isNaN(string) || string.length < 1) output = false;
	return output;
}
function checkLength(string, minimum, maximum){
	var output = false;
	if(!isNaN(minimum) && !isNaN(maximum) && string != null){
		if(string.length >= minimum && string.length <= maximum) output = true;
	}
	return output;
}
function checkEmail(string){
	var output = true;
	var regExp = /[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+\.[a-zA-Z]{2,4}/;
	if(regExp.exec(string) == null) output = false;
	return output;
}
////////////////////////////////////////////////////////////////////////
//Complex types
////////////////////////////////////////////////////////////////////////
function checkCC(string){
	var output = false;
	if(checkNumber(string) && checkLength(string, 16, 18)) output = true;
	return output;
}
////////////////////////////////////////////////////////////////////////
//Form Checker
////////////////////////////////////////////////////////////////////////
function formCheck(){
	var output = true;
	var reasons = "The following errors occurred:";
	for(var i = 0; i < elements.length; i++){
		var insp = elements[i];
		if(insp[0].length > 0){
			switch(insp[1]){
				case "number" :
					if(!checkNumber(insp[0])){
						output = false;
						reasons += "\n -" + insp[2] + " needs to be a number";
					}
					break;
				case "string" :
					//Do nothing with strings
					break;
				case "credit card" :
					if(!checkCC(insp[0])){
						output = false;
						reasons += "\n -" + insp[2] + " is not a valid credit/debit card number";
					}
					break;
				case "email" :
					if(!checkEmail(insp[0])){
						output = false;
						reasons += "\n -" + insp[2] + " is not a valid email address";
					}
					break;
			}
		}
		else{
			output = false;
			reasons += "\n -" + insp[2] + " is empty";
		}
	}
	if(!output) alert(reasons);
	return output;
}