var x_icon = new Image();
x_icon.src = 'data_log/x.png';
var check_off = new Image();
check_off.src = 'data_log/tick.png';

/* Form Checks */
function RegisterCheck() {
	result = false;
	
	if (CheckFirstName()) {
		if (CheckLastName()) { 
			if (CheckEmail()) { 
				if (CheckEmailMatch()) {
					if (CheckZip()) {
						if (CheckCountry()) {
							result = true;
						}
					}
				}
			}
		}
	}

	return result;
}

/* Validation Helpers */
function isAlphaNum(field) {
	validChars = /^[0-9a-zA-Z]+$/;
	if (validChars.test(field.value)) {
		return true;
	} else {
		return false;
	}	
}

function isAlpha(field) {
	validChars = /^[a-zA-Z]+$/;
	if (validChars.test(field.value)) {
		return true;
	} else {
		return false;
	}	
}

function isEmail(field) { 
	if (field.value.match(/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/)) {
		return true;
	} else {
		return false;
	} 
}

/* Validation Notice Functions */

function CheckFirstName() {
	FirstName = document.getElementById('txt_FirstName');
	notice = document.getElementById('FnameMsg');
	
	if ((isAlpha(FirstName)) && (FirstName.value.length >= 1)) {
		notice.innerHTML = "<img src='" + check_off.src + "' border='0' alt='' title='' />";
		result = true;
	} else {
		setTimeout(function() {
			notice.innerHTML = "<img src='" + x_icon.src + "' border='0' alt='' title='' />";
		}, 1);
		result = false;
	}
	return result;
}

function CheckLastName() {
	LastName = document.getElementById('txt_LastName');
	notice = document.getElementById('LnameMsg');
	
	if ((isAlpha(LastName)) && (LastName.value.length >= 1)) {
		notice.innerHTML = "<img src='" + check_off.src + "' border='0' alt='' title='' />";
		result = true;
	} else {
		setTimeout(function() {
			notice.innerHTML = "<img src='" + x_icon.src + "' border='0' alt='' title='' />";
		}, 1);
		result = false;
	}
	return result;
}

function CheckEmail() {
	Email = document.getElementById('txt_Email');
	notice = document.getElementById('EmailMsg');
	
	if ((isEmail(Email)) && (Email.value.length >= 1)) {
		notice.innerHTML = "<img src='" + check_off.src + "' border='0' alt='' title='' />";
		result = true;
	} else {
		setTimeout(function() {
			notice.innerHTML = "<img src='" + x_icon.src + "' border='0' alt='' title='' />";
		}, 1);
		result = false;
	}
	return result;
}

function CheckEmailMatch() {
	Email = document.getElementById('txt_Email');
	Email2 = document.getElementById('txt_Email2');
	notice = document.getElementById('EmailMsg2');
	
	if ((Email.value == Email2.value) && (Email.value.length >= 5)) {
		notice.innerHTML = "<img src='" + check_off.src + "' border='0' alt='' title='' />";
		result = true;
	} else {
		setTimeout(function() {
			notice.innerHTML = "<img src='" + x_icon.src + "' border='0' alt='' title='' />";
		}, 1);
		result = false;
	}
	return result;
}

function CheckZip() {
	zip = document.getElementById('txt_ZipCode');
	notice = document.getElementById('ZipMsg');
	
	if (zip.value.length >= 5) {
		notice.innerHTML = "<img src='" + check_off.src + "' border='0' alt='' title='' />";
		result = true;
	} else {
		setTimeout(function() {
			notice.innerHTML = "<img src='" + x_icon.src + "' border='0' alt='' title='' />";
		}, 1);
		result = false;
	}
	return result;
}

function CheckCountry() {
	country = document.getElementById('sct_Country');
	notice = document.getElementById('CountryMsg');
	
	if (country.value != -1) {
		notice.innerHTML = "<img src='" + check_off.src + "' border='0' alt='' title='' />";
		result = true;
	} else {
		setTimeout(function() {
			notice.innerHTML = "<img src='" + x_icon.src + "' border='0' alt='' title='' />";
		}, 1);
		result = false;
	}
	return result;
}


