	//age check
	function twoDigits(dig){
		var str = dig.toString();
		var digit = (str.length == 2) ? str : '0'+str;
		return digit;
	}
	
	
	function realMonth(mm){
		var realmonth = (mm < 12) ? mm + 1 : mm = 1;
		return realmonth;
	}
			
	// returns true if the string is a US phone number formatted as...
	// (000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
	function isPhoneNumber(str){
		var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
		return re.test(str);
	}
	
	// returns true if the string is a date formatted as...
	// MM/DD/YYYY
	function isDate(str){
		var re = /\d{2}\/\d{2}\/\d{4}/
		return re.test(str);
	}
	
	// returns true if the string only contains characters A-Z, a-z or 0-9 or . or #
	function isAddress(str){
		var re = /[^a-zA-Z0-9\#\.]/g
		if (re.test(str)) return true;
		return false;
	}
	
	// returns true if the string is 5 digits
	function isZip(str){
		var re = /\d{5,}/;
		if(re.test(str)) return true;
		return false;
	}
	
	// returns true if the string only contains characters A-Z or a-z
	function noSpaces(str){
		var re = /[' ']/g
		if (re.test(str)) return false;
		return true;
	}
	
	// returns true if the string only contains characters A-Z or a-z
	function isAlpha(str){
		var re = /[^a-zA-Z-\s]/g
		if (re.test(str)) return false;
		return true;
	}
	
	// returns true if the string only contains characters A-Z or a-z or 0-9
	function isAlphaNumeric(str){
		var re = /[^a-zA-Z0-9]/g
		if (re.test(str)) return false;
		return true;
	}
	
	// returns true if the string only contains characters 0-9
	function isNumeric(str){
		var re = /[^0-9]/g
		if (re.test(str)) return false;
		return true;
	}

	function isEmpty(str){
		if(str == null || str.length == 0){
			return true;
		}else{
			return false;
		}
	}
	
	function isEmail(str){
	if(str == '') return false;
	var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
	return re.test(str);
	}
	
function stripWhitespace(str, replacement){
	if (replacement == null) replacement = '';
	var result = str;
	var re = /\s/g
	if(str.search(re) != -1){
		result = str.replace(re, replacement);
	}
	return result;
}

//function to remove error class on focus
function tryAgain(id){
	$(id).removeClass('errors');
}

//function to check for errors on keyup
function testValue(id){
	var tv = $(id).val();
	var tvv = id+'_validation';
	switch (id){
		
		case '#email_addr':
			if(isEmpty(tv) || !isEmail(tv)){
			hasErrors('#email_addr', true);
			}else{
			hasErrors('#email_addr', false);
			}
		break;
		
		case '#child_full_name':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#child_age':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#child_dob':
			if(isEmpty(tv) || hasDefaultValue(id) || !isDate(tv)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#child_gender':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#child_lesson_day':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#child_lesson_time':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#child_lessons':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#child_float':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#child_swim_5':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#parent_full_name':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#parent_address':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#parent_city':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#parent_zipcode':
			if(isEmpty(tv) || hasDefaultValue(id)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#parent_phone_number':
			if(isEmpty(tv) || hasDefaultValue(id) || !isPhoneNumber(tv)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
		case '#parent_email':
			if(isEmpty(tv) || hasDefaultValue(id) || !isEmail(tv)){
			hasErrors(tvv, true);
			}else{
			hasErrors(tvv, false);
			}
		break;
	}
	
}

//function to check if a field title is the same as its value
function hasDefaultValue(id){
	var dv = $(id).attr('title');
	var av = $(id).val();
	
	if(dv == av){ return true; }
	return false;
}

//function for coloring the fields with errors
function hasErrors(fieldID, err){
	if(err){
		$(fieldID).removeClass('pass');
		$(fieldID).addClass('errors');
	}else{
		$(fieldID).removeClass('errors');
		$(fieldID).addClass('pass');
	}
}

//function for coloring text with errors
function hasErrorsText(fieldID, err){
	if(err){
		$(fieldID).addClass('errortext');
	}else{
		$(fieldID).removeClass('errortext');
	}
}

function validateForm(){

	var err_count = 0;

	var c_fn = $("#child_full_name").val();
	var c_age = $("#child_age").val();
	var c_dob = $("#child_dob").val();
	var c_gen = $("#child_gender").val();
	var c_ldy = $("#child_lesson_day").val();
	var c_ltm = $("#child_lesson_time").val();
	var c_les = $("#child_lessons").val();
	var c_flo = $("#child_float").val();
	var c_swm = $("#child_swim_5").val();
	var p_fn = $("#parent_full_name").val();
	var p_add = $("#parent_address").val();
	var p_cty = $("#parent_city").val();
	var p_zip = $("#parent_zipcode").val();
	var p_phn = $("#parent_phone_number").val();
	var p_eml = $("#parent_email").val();
	
	if(isEmpty(c_fn) || hasDefaultValue('#child_full_name')){
		err_count++;
		hasErrors('#child_full_name_validation', true);
	}else{
		hasErrors('#child_full_name_validation', false);
	}
	if(isEmpty(c_age) || hasDefaultValue('#child_age')){
		err_count++;
		hasErrors('#child_age_validation', true);
	}else{
		hasErrors('#child_age_validation', false);
	}
	if(isEmpty(c_dob) || hasDefaultValue('#child_dob') || !isDate(c_dob)){
		err_count++;
		hasErrors('#child_dob_validation', true);
	}else{
		hasErrors('#child_dob_validation', false);
	}
	if(isEmpty(c_gen) || hasDefaultValue('#child_gender')){
		err_count++;
		hasErrors('#child_gender_validation', true);
	}else{
		hasErrors('#child_gender_validation', false);
	}
	if(isEmpty(c_ldy) || hasDefaultValue('#child_lesson_day')){
		err_count++;
		hasErrors('#child_lesson_day_validation', true);
	}else{
		hasErrors('#child_lesson_day_validation', false);
	}
	if(isEmpty(c_ltm) || hasDefaultValue('#child_lesson_time')){
		err_count++;
		hasErrors('#child_lesson_time_validation', true);
	}else{
		hasErrors('#child_lesson_time_validation', false);
	}
	if(isEmpty(c_les) || hasDefaultValue('#child_lessons')){
		err_count++;
		hasErrors('#child_lessons_validation', true);
	}else{
		hasErrors('#child_lessons_validation', false);
	}
	if(isEmpty(c_flo) || hasDefaultValue('#child_float')){
		err_count++;
		hasErrors('#child_float_validation', true);
	}else{
		hasErrors('#child_float_validation', false);
	}
	if(isEmpty(c_swm) || hasDefaultValue('#child_swim_5')){
		err_count++;
		hasErrors('#child_swim_5_validation', true);
	}else{
		hasErrors('#child_swim_5_validation', false);
	}
	if(isEmpty(p_fn) || hasDefaultValue('#parent_full_name')){
		err_count++;
		hasErrors('#parent_full_name_validation', true);
	}else{
		hasErrors('#parent_full_name_validation', false);
	}
	if(isEmpty(p_add) || hasDefaultValue('#parent_address')){
		err_count++;
		hasErrors('#parent_address_validation', true);
	}else{
		hasErrors('#parent_address_validation', false);
	}
	if(isEmpty(p_cty) || hasDefaultValue('#parent_city')){
		err_count++;
		hasErrors('#parent_city_validation', true);
	}else{
		hasErrors('#parent_city_validation', false);
	}
	if(isEmpty(p_zip) || hasDefaultValue('#parent_zipcode')){
		err_count++;
		hasErrors('#parent_zipcode_validation', true);
	}else{
		hasErrors('#parent_zipcode_validation', false);
	}
	if(isEmpty(p_phn) || hasDefaultValue('#parent_phone_number') || !isPhoneNumber(p_phn)){
		err_count++;
		hasErrors('#parent_phone_number_validation', true);
	}else{
		hasErrors('#parent_phone_number_validation', false);
	}
	if(isEmpty(p_eml) || hasDefaultValue('#parent_email') || !isEmail(p_eml)){
		err_count++;
		hasErrors('#parent_email_validation', true);
	}else{
		hasErrors('#parent_email_validation', false);
	}
	
	
	if(err_count == 0){
		return true;
	}
	showErrorBox();
	return false;
}

function showErrorBox(){
	$("#errorBox").html('<h2>Hmmmm...</h2><p>It looks like you&#39;ve missed something. Check the form again for items with <img src="im/exclamation.png" alt="error" /> next to it.</p>');
	$("#errorBox").show();
}

function validateSignup(){
	var err_count = 0;

	var em = $("#email_addr").val();
	
	if(isEmpty(em) || !isEmail(em)){
		err_count++;
		hasErrors('#email_addr', true);
	}
	
	if(err_count == 0){
		return true;
	}

	return false;
}
