//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);
	}
	
	//returns true if follows the -###.### format
	function isFloat(str){
		var re = /[0-9\-\.]/g
		if (re.test(str)) return true;
		return false;
	}
	
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 clearError(id){
	$('#'+id).removeClass('error');
}

// Specific Forms

function validateContact(){
	
	var this_form = document.contactform;
	var err=0;
	
	if(isEmpty(this_form.contactname.value)){
	$('#contactname').addClass('error');
	err++;
	//return false
	}else{
	$('#contactname').removeClass('error');
	}
	
	if(isEmpty(this_form.contactemail.value) || !isEmail(this_form.contactemail.value)){
	$('#contactemail').addClass('error');
	err++;
	//return false
	}else{
	$('#contactemail').removeClass('error');
	}
	
	if(isEmpty(this_form.contactmessage.value)){
	$('#contactmessage').addClass('error');
	err++;
	//return false
	}else{
	$('#contactmessage').removeClass('error');
	}
	
	if (err > 0){
		return false;
	} else {
		this_form.submit();
	}
	
}

function validateUserGame(){
	
	var this_form = document.usergame;
	var err=0;
	
	if(isEmpty(this_form.gamename.value)){
	$('#gamename').addClass('error');
	err++;
	//return false
	}
	
	if(isEmpty(this_form.gamedesc.value)){
	$('#gamedesc').addClass('error');
	err++;
	//return false
	}
	
	if (err > 0){
		return false;
	} else {
		this_form.submit();
	}
	
}


function validateUserVideo(){
	var this_form = document.uservideo;
	var err=0;
	
	if(isEmpty(this_form.videoname.value)){
	$('#videoname').addClass('error');
	err++;
	//return false
	}
	
	if(isEmpty(this_form.videodesc.value)){
	$('#videodesc').addClass('error');
	err++;
	//return false
	}
	
	if(isEmpty(this_form.videourl.value)){
	$('#videourl').addClass('error');
	err++;
	//return false
	}
	
	if (err > 0){
		return false;
	} else {
		this_form.submit();
	}
	
}


function validateUserSpot(){
	
	var this_form = document.userspot;
	var err=0;
	
	if(isEmpty(this_form.spottitle.value)){
	$('#spottitle').addClass('error');
	err++;
	//return false
	}
	
	//user can add latitude and longitude OR address and city
	if(isEmpty(this_form.spotlat.value) || isEmpty(this_form.spotlong.value) ){
		//user didnt supply the lat/long, so verify the address
		if(isEmpty(this_form.spotaddress.value)){
		$('#spotaddress').addClass('error');
		err++;
		//return false
		}
		if(isEmpty(this_form.spotcity.value)){
		$('#spotcity').addClass('error');
		err++;
		//return false
		}
	}else{
		//validate the format of the lat/long
		if(!isFloat(this_form.spotlat.value)){
		$('#spotlat').addClass('error');
		err++;
		//return false
		}
		
		if(!isFloat(this_form.spotlong.value)){
		$('#spotlong').addClass('error');
		err++;
		//return false
		}
		
	}
	/* removed to allow international addresses
	if(isEmpty(this_form.spotstate.value)){
	$('#spotstate').addClass('error');
	err++;
	//return false
	}
	if(isEmpty(this_form.spotzipcode.value)){
	$('#spotzipcode').addClass('error');
	err++;
	//return false
	}
	*/
	if (err > 0){
		return false;
	} else {
		this_form.submit();
	}
	
}

function validateUserSpotComment(){
	
	var this_form = document.userspotcomment;
	var err=0;
	
	if(isEmpty(this_form.spotcomment.value)){
	$('#spotcomment').addClass('error');
	err++;
	//return false
	}
	
	if (err > 0){
		return false;
	} else {
		this_form.submit();
	}
	
}