function EmailAndPhoneSniffer (form,fieldname) {
	var request_field = $(form).find("[name='"+fieldname+"']").val();

	if (request_field.match(/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i)) {
		DisplayError("Please do not enter your email address in the "+fieldname+" field");
		return false;
	}
	else if (request_field.match(/(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*/)) {
		DisplayError("Please do not enter your phone number in the "+fieldname+" field");
		return false;
	}
	
	return true;
}

function Validate (form) {
	var req_fields = $(form).find(".required");
	var valid = true;

	$(form).find("input,select,textarea").removeClass('left_blank');
	
	for (i=0; i<req_fields.length; i++) {
		var field_name = $(req_fields[i]).attr('name');
		
		if ($(req_fields[i]).val() == '') {
			$(req_fields[i]).addClass('left_blank');
			valid = false;
		}
	}

	if (valid == false) {
		if ($(form).find('[name=dialog]').length > 0) {
			DisplayDialogError("You left a required field blank");
		}
		else {
			DisplayError("You left a required field blank");
		}
	}
	
	return valid;
}

function ValidateAjax (formData, jqForm, options) {
	var form = jqForm[0];
	var req_fields = $(form).find(".required");
	var valid = true;

	for (i=0; i<req_fields.length; i++) {
		var field_name = $(req_fields[i]).attr('name');
		
		$(req_fields[i]).removeClass('left_blank');
		
		if ($(req_fields[i]).val() == '') {
			$(req_fields[i]).addClass('left_blank');
			valid = false;
		}
	}
	
	if (valid == false) {
		if ($(form).find('[name=dialog]').length > 0) {
			DisplayDialogError("You left a required field blank");
		}
		else {
			DisplayError("You left a required field blank");
		}
	}
	
	return valid;
}

function DisplayError (text) {
	$("#message").hide();
	if ($("#error").length == 0) $("#dialog").prepend('<div id="error"></div>');
	if (text) $("#error").html(text);
	$("#error").animate({ opacity: 1.0 }, 0).slideDown(200).animate({ opacity: 1.0 }, 5000);
	scroll(0,0);
}

function DisplayDialogError (text) {
	if ($("#dialog_error").length == 0) $("#dialog").prepend('<div id="dialog_error"></div>');
	if (text) $("#dialog_error").html(text);
	$("#dialog_error").animate({ opacity: 1.0 }, 0).slideDown(200).animate({ opacity: 1.0 }, 3000);
}

function DisplayMessage (text) {
	if (text) $("#error").html(text);
	$("#message").animate({ opacity: 1.0 }, 0).slideDown(200).animate({ opacity: 1.0 }, 1000);
	scroll(0,0);
}

function DisplayLogIn () {
	CreateDialog('Log-in',390);
	$("#dialog").load("/in/log_in.php", function() {
		ShowDialog();
	}).dialog("open");
}

function ViewMenu (id) {
	CreateDialog('Menu',525);
	$("#dialog").load("/in/menu.php", { id: id }, function() {
		ShowDialog();
	}).dialog("open");
}
function ViewEvent (id) {
	CreateDialog('Event',525);
	$("#dialog").load("/in/event.php", { id: id }, function() {
		ShowDialog();
	}).dialog("open");
}
function ViewBio (id) {
	CreateDialog('Bio',525);
	$("#dialog").load("/in/bio.php", { id: id }, function() {
		ShowDialog();
	}).dialog("open");
}
function ViewNews (id) {
	CreateDialog('News',525);
	$("#dialog").load("/in/news.php", { id: id }, function() {
		ShowDialog();
	}).dialog("open");
}
function ViewBackground (id) {
	CreateDialog('Background',525);
	$("#dialog").load("/in/background.php", { id: id }, function() {
		ShowDialog();
	}).dialog("open");
}

function CreateDialog (title, width) {
	ResetDialog();
	$("#dialog").dialog( { title: title, autoOpen: false, width: width, height: $(window).height()-200 } );
}
function ResetDialog () {
	if ($("#dialog").length == 0) $("body").append('<div id="dialog"><div class="spinner">Loading...</div></div>');
	$("#dialog").html('');
	$("#dialog").dialog('destroy');
}
function ShowDialog() {
	var content_height = $("#dialog div").height();
	var max_height = $(window).height() - 200;
	var height = (content_height > max_height) ? max_height : content_height+60;
	if (height < max_height) { 
		$("#dialog").dialog("option","height",height);
	}
}