/**
 * ditp software
 * 
 * @version $Id$
 * @returns continue variable (true in case of no errors, false otherwise
 */
currentField = null;
messagPane = null;

function validateSmallContactForm() {
	messagePane = $("#message");
	
	setPendingField("prospectName");
	if (!isText(currentField.val())) {
		setErrorMessage("Voer aub uw naam in");
		return false;
	}
	
	setPendingField("prospectMail");
	if (!isEmail(currentField.val())) {
		setErrorMessage("Vul aub een geldig email adres in");
		return false;
	}
	
	setPendingField("prospectMessage");
	if (!isText(currentField.val())) {
		setErrorMessage("Voer aub uw bericht in");
		return false;
	}
	
	
	return true;
}

/* *******
 * "Private" methods
 * ******* 
 */
function setPendingField(id) {
	currentField = $("#"+id);
	currentField.css("border","1px solid #555");
}


function setErrorMessage(message) {
	currentField.css("border", "1px solid #c10000");
	
	messagePane.text(message);
	messagePane.addClass("error");
}


function isEmail(str){
	if(str == "") return false;
	var regex = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
	return regex.test(str);
}

function isText(str){
	if(str == "") return false;
	return true;
}

function isURL(str){
	var regex = /[a-zA-Z0-9\.\/:]+/
	return regex.test(str);
}

/**
 * @returns true if the number is formatted in the following ways:
 * 			(000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
 */
function isPhone(str){
	var regex = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
	return regex.test(str);
}

/**
 * @returns true if the string contains A-Z, a-z or 0-9 or . or # only
 */
function isAddress(str){
	var regex = /[^a-zA-Z0-9\#\.]/g
	if (regex.test(str)) return true;
	return false;
}

/** 
 * @returns true if the string is 5 digits
 */
function isZip(str){
	var regex = /\d{5,}/;
	if(regex.test(str)) return true;
	return false;
}

/**
 * @returns true if the string contains A-Z or a-z only
 */
function isAlpha(str){
	var regex = /[a-zA-Z]/g
	if (regex.test(str)) return true;
	return false;
}

// returns true if the string contains A-Z or a-z or 0-9 only
function isAlphaNumeric(str){
	var regex = /[^a-zA-Z0-9]/g
	if (regex.test(str)) return false;
	return true;
}
