function updateTips( tipElement, tipText ) {
	tipElement
		.text( tipText )
		.addClass( "ui-state-highlight" );
	setTimeout(function() {
		tipElement.removeClass( "ui-state-highlight", 1500 );
	}, 500 );
}

function checkLength( str, name, min, max, tipElement ) {
	if ( str.val().length > max || str.val().length < min ) {
		str.addClass( "ui-state-error" );
		updateTips( tipElement, "Length of " + name + " must be between " +
			min + " and " + max + "." );
		return false;
	} else {
		return true;
	}
}

function checkLocationSet( loc, marker, tipElement ) {
	if (marker === undefined) {
		loc.addClass( "ui-state-error" );
		updateTips( tipElement, "No location set, enter a location and click 'Lookup'" );
		return false;
	} else {
		return true;
	}
}

function checkRegexp( str, regexp, errStr, tipElement ) {
	if ( !( regexp.test( str.val() ) ) ) {
		str.addClass( "ui-state-error" );
		updateTips( tipElement, errStr );
		return false;
	} else {
		return true;
	}
}

function checkMatches( str1, str2, errStr, tipElement ) {
	if (str1.val() != str2.val())
	{
		str1.addClass( "ui-state-error" );
		str2.addClass( "ui-state-error" );
		updateTips( tipElement, "Passwords do not match!" );
		return false;
	} else {
		str1.removeClass( "ui-state-error" );
		str2.removeClass( "ui-state-error" );
		tipElement.text( "All form fields are required to sign up." )
		return true;
	}
} 
