	//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 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 for coloring the fields with errors
function hasErrors(fieldID, err){
	if(err){
		$(fieldID).addClass('errors');
	}else{
		$(fieldID).removeClass('errors');
	}
}

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

function validateForm(){
	var this_form = document.entry;
	var err_count = 0;
	
	var fn = $("#fname").val();
	var ln = $("#lname").val();
	var em = $("#email").val();
	var le = $("#learn").val();
	var leo = $("#learn_other").val();
	var of = $("#often").val();
	var ow = $("#ownership").val();
	var owo = $("#ownership_other").val();
	var pu = $("#purchase").val();
	var re = $("#recommend").val();
	var cfb = $("#confb").val();
	var ctw = $("#contw").val();
	var cms = $("#conms").val();
	var cbz = $("#conbz").val();
	
	if(isEmpty(fn)){
		err_count++;
		hasErrors('#fname', true);
	}
	
	if(isEmpty(ln)){
		err_count++;
		hasErrors('#lname', true);
	}
	
	if(isEmpty(em) || !isEmail(em)){
		err_count++;
		hasErrors('#email', true);
	}
	
	if(isEmpty(le)){
		err_count++;
		hasErrors('#learn', true);
	}
	
	if(le == 'other'){
		if(isEmpty(leo) || leo == 'Please explain'){
			err_count++;
			hasErrors('#learn_other', true);
		}
	}
	
	if(isEmpty(of)){
		err_count++;
		hasErrors('#often', true);
	}
	
	//if(isEmpty(ow)){
		//err_count++;
		//hasErrors('#ownership', true);
	//}
	
	if(ow == 'other'){
		if(isEmpty(owo) || owo == 'Please explain'){
			err_count++;
			hasErrors('#ownership_other', true);
		}
	}
	
	if(isEmpty(pu)){
		err_count++;
		hasErrors('#purchase', true);
	}
	
	if(isEmpty(re)){
		err_count++;
		hasErrors('#recommend', true);
	}
	
	if(isEmpty(cfb) && isEmpty(ctw) && isEmpty(cms) && isEmpty(cbz)){
		err_count++;
		hasErrors('.connfld', true);
	}
	
	if(err_count == 0){
		return true;
	}else{
		return false;
	}

}

function validateTell(){
	var this_form = document.tellafriend;
	var err_count = 0;
	
	var yn = $("#yname").val();
	var ye = $("#yemail").val();
	var fn = $("#faname").val();
	var fe = $("#faemail").val();
	
	if(isEmpty(yn)){
		err_count++;
		hasErrors('#yname', true);
	}
	
	if(isEmpty(ye) || !isEmail(ye)){
		err_count++;
		hasErrors('#yemail', true);
	}
	
	if(isEmpty(fn)){
		err_count++;
		hasErrors('#faname', true);
	}
	
	if(isEmpty(fe) || !isEmail(fe)){
		err_count++;
		hasErrors('#faemail', true);
	}
	
	
	if(err_count == 0){
		return true;
	}else{
		return false;
	}

}

