﻿function Validate_Form(frm) {

	// By default were always valid unless we find a time its not
	var valid = true;
	
	// Get our form fields to work with
	var name = document.getElementById('Name');
	var divName = document.getElementById('divName');
	var phone = document.getElementById('Phone');
	var divPhone = document.getElementById('divPhone');

	// Check if we have something for our phone
	// note: we go in reverse order so the last to get focus is the upper most item
	if (Setup_Field(phone, (phone.value.length > 0), divPhone) === false) {
		valid = false;
		phone.focus();
	}
	// Check if we have something for our name
	
	if (Setup_Field(name, (name.value.length > 0), divName) === false) {
		valid = false;
		name.focus();
	}
	
	// Return if were valid
	return valid;

}


// Easily allow us to update how a field should look
function Setup_Field(field, success, div) {

	var colorBG = 'white';
	var colorBorder = '#8b7d60';
	
	if (success == false) {
		colorBG = 'yellow';
		colorBorder = 'red';
		div.style.display = 'block';
	}else {
		div.style.display = 'none';
	}

	field.style.backgroundColor = colorBG;
	field.style.border = 'solid 1px '+colorBorder;
	
	// Return success incase we wanna do something with it
	return success;
	
}
