	//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 for colouring the fields with errors
function hasErrors(fieldID, err){
	if(err){
		document.getElementById(fieldID).style.backgroundColor = '#f9d1d1';
	}else{
		document.getElementById(fieldID).style.backgroundColor = 'white';
	}
}


function notify(){
   	
   var fb = $("#uMessage").val();
   var fn = $("#uName").val();
   var em = $("#uEmail").val();
   
   var pars = 'fullname='+fn+'&message='+fb+'&email='+em;
	
	$.ajax({
	type: "POST",
	url: "ajax.contact.php",
	data: pars,
	success: function(msg){
		$("#notification").removeClass('hide');
		$("#notification").html(msg);
		$('#dialog').jqmHide();
		fadeOutAlert('#notification')
	}
	});
   return false;
}



function listnotify(){
   	
   var fn = $("#fName").val();
   var ln = $("#lName").val();
   var em = $("#mEmail").val();
   var zp = $("#mZip").val();
   var gn = $("#mGender").val();
   
   if(isEmpty($("#mAge").val())){ var ag = 'NULL'; }else{ var ag = $("#mAge").val(); }
   
   var pars = 'fname='+fn+'&lname='+ln+'&email='+em+'&zip='+zp+'&gender='+gn+'&age='+ag;
	
	$.ajax({
	type: "POST",
	url: "ajax.mlist.php",
	data: pars,
	success: function(msg){
		$("#notification").removeClass('hide');
		$("#notification").html(msg);
		$('#mlistdialog').jqmHide();
		fadeOutAlert('#notification')
	}
	});
   return false;
}
  

  		

function validateForm(){
	var this_form = document.contactform;
	var errors=0;
		
		if(isEmpty(this_form.uMessage.value)){
		$('#uMessage').addClass('err');
		errors++;
		}else{
		$('#uMessage').removeClass('err');
		}
		
		if(isEmpty(this_form.uName.value)){
		$('#uName').addClass('err');
		errors++;
		}else{
		$('#uName').removeClass('err');
		}

		if(isEmpty(this_form.uEmail.value)){
		$('#uEmail').addClass('err');
		errors++;
		}else{
		$('#uEmail').removeClass('err');
		}
		
		if(errors > 0){ return false; }
		
		return notify();
	
}

function validateListForm(){
	var this_form = document.mailinglist;
	var errors=0;
		
		if(isEmpty(this_form.fName.value)){
		$('#fName').addClass('err');
		errors++;
		}else{
		$('#fName').removeClass('err');
		}
		
		if(isEmpty(this_form.lName.value)){
		$('#lName').addClass('err');
		errors++;
		}else{
		$('#lName').removeClass('err');
		}

		if(isEmpty(this_form.mEmail.value)){
		$('#mEmail').addClass('err');
		errors++;
		}else{
		$('#mEmail').removeClass('err');
		}
		
		if(isEmpty(this_form.mZip.value)){
		$('#mZip').addClass('err');
		errors++;
		}else{
		$('#mZip').removeClass('err');
		}
		
		if(errors > 0){ return false; }
		
		return listnotify();
	
}
