function replaceStyles()
{

	/* PANELS */
	
}

function replaceStylesDiv(elementSelector) {}

function changeAttendance()
{
}

function loadContent(elementSelector, sourceURL)
{
	$("#"+elementSelector).load(sourceURL, '', function()
	{
		replaceStylesDiv(elementSelector)
	});
}

function checkEmail(emailAddress)
{
	var str = emailAddress;
	if ((str.indexOf(".") > 0) && (str.indexOf("@") > 0) == true)
	{
		return true;
	} else {
		//window.alert('Please enter a valid email address');
		return false;
	}
}


$(document).ready(function()
{
	$.fn.delay = function(time, callback)
	{
		return this.animate({ opacity: '+=0' }, time, callback);
	}

	// apply some effects immediately
	
	equalHeight($('ul.gallery li'));
	
	// balance cols
	
	var paddingWithFooter = 81;
	var paddingWithoutFooter = 49;

	/* general balancing */

	$('#topOfPage').click(function(e)
	{
		e.preventDefault();
		$('html,body').stop(true).animate({scrollTop:0},500);
	});
	fadeMessages();
	fadePanels();
});

function fadeMessages()
{
	$('.message').wrap('<div class="messageHolder" />');
	$('.message').delay(3000).animate({opacity:0}, 500, function()
	{
		$('.messageHolder').slideUp();
	});
}

function checkLogInForm()
{
	var errors = '';
	if (checkEmail(document.logInForm.email.value)==false)
		errors += '- Email\n';
	if (document.logInForm.password.value.length == 0 || document.logInForm.password.value=='Password' || document.logInForm.password.value=='PASSWORD')
		errors += '- Password\n';
	if (errors != '')
	{
		errors = 'Please complete the following:\n\n'+errors;
		window.alert(errors);
		return false;
	} else {
		return true;
	}
}

function checkBigLogInForm()
{
	var errors = '';
	if (checkEmail(document.bigLogInForm.email.value)==false)
		errors += '- Email\n';
	if (document.bigLogInForm.password.value.length == 0 || document.bigLogInForm.password.value == 'Password' || document.bigLogInForm.password.value == 'PASSWORD')
		errors += '- Password\n';
	if (errors != '')
	{
		errors = 'Please complete the following:\n\n'+errors;
		window.alert(errors);
		return false;
	} else {
		return true;
	}
}

function checkImageUploadForm()
{
	var errors = '';
	if (document.getElementById('image-form').imageFile.value.length == 0)
		errors += '- Image (in JPEG format)\n';
	if (document.getElementById('image-form').imageFile.value.length == 0)
		errors += '- Caption\n';
	if (errors != '')
	{
		errors = 'Please complete the following:\n\n'+errors;
		window.alert(errors);
		return false;
	} else {
		/*var destination = document.imageForm.postDestination.value;
		//$(".new-image").css({opacity:0});
		//$(".image-form-holder").height($(".image-form-holder").height());
		$(".image-form").animate({opacity:1}, 500, function() {
			$.post(destination, $("#imageForm").serialize(), 	function(data) {
				$(".new-image").html(data);
				//$(".new-image").animate({opacity:1}, 500);
				//$("#add-image-button").animate({opacity:0}, 500);
				//$(".image-form-holder").animate({height: $(".new-image").height()}, 500);
				fadeMessages();
			});
		});*/
		return true;
	}
}

function checkPasswordReminder()
{
	errors = '';
	if (checkEmail(document.membersLogInForm.email.value)==false)
	{
		errors += '- Email Address\n';
	}
	if (errors == '')
	{
		return true;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		document.membersLogInForm.email.focus();
		return false;
	}
}

//

function checkRegisterForm()
{
	errors = '';
	if (document.registerForm.firstName.value.length == 0)
		errors += '- First Name\n';
	if (document.registerForm.lastName.value.length == 0)
		errors += '- Last Name\n';
	/*var sexcheck = '';
	for (i=0; i<document.registerForm.sex.length; i++) {
 		if (document.registerForm.sex[i].checked) {
			sexcheck = document.registerForm.sex[i].value;
		}
	}
	if (sexcheck == '')
		errors += '- Sex\n';
	*/
	if (document.registerForm.username.value.length == 0)
		errors += '- Username\n';
	if (checkEmail(document.registerForm.email.value)==false)
		errors += '- Email Address\n';
	if (document.registerForm.confirmEmail.value != document.registerForm.email.value)
	{
		errors += '- Email Addresses did not match\n';
		document.registerForm.checkEmail.value = '';	
	} else if (document.registerForm.confirmEmail.value.length == 0)
		errors += '- Confirmation Email Address\n';

	if (document.registerForm.password.value.length < 6)
		errors += '- Password\n';

	if (document.registerForm.confirmPassword.value.length < 6 || document.registerForm.confirmPassword.value != document.registerForm.password.value)
		errors += '- Confirm Password\n';

	if (errors == '')
	{
		return true;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	}
}

function checkProfileForm()
{
	errors = '';

	if (checkEmail(document.profileForm.email.value)==false)
		errors += '- Email address\n';

	if (document.profileForm.password.value.length > 0 && (document.profileForm.password.value.length < 6 || document.profileForm.password.value.length > 30))
		errors += '- Password must be between 6 and 30 characters';
	else if (document.profileForm.password.value.length > 0 && document.profileForm.password.value != document.profileForm.confirmPassword.value)
		errors += '- Passwords do not match\n';

	if (errors=='')
	{
		return true;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	}
}

function checkCommentForm()
{
	errors = '';
	
	if (document.commentForm.commentTitle.value.length == 0)
	{
		errors += '- Comment Title\n';
		document.commentForm.commentTitle.focus();
	}
	if (document.commentForm.commentText.value.length == 0)
	{
		errors += '- Comment Text\n';
	}

	if (errors == '')
	{
		var destination = document.commentForm.postDestination.value;
		$(".new-comment").css({opacity:0});	$(".comments-form-holder").height($(".comments-form-holder").height());
		$(".comments-form").animate({opacity:0}, 500, function() {
			$.post(destination, $("#commentForm").serialize(), 	function(data) {
				$(".new-comment").html(data);
				$(".new-comment").animate({opacity:1}, 500);
				$("#add-comment-button").animate({opacity:0}, 500);
				$(".comments-form-holder").animate(
					{height: $(".new-comment").height()}, 500);
				loadContent("comments-title", commentsTitleURI); 
				fadeMessages();
			});
		});
		return false;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	}
}

function fadePanels()
{}

function equalHeight(group)
{
	var tallest = 0;
	group.each(function()
	{
		var thisHeight = $(this).height();
		if(thisHeight > tallest)
		{
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function addShopItem(format, webroot)
{
	$('#basket .article.first').slideUp(function() {
		$('#basket .article.first').html(geturl(webroot+'add_to_order/'+format));
		$('#basket .article.first').slideDown();
	});
	$('#'+format+'Add').hide();
}

function changePostageRegion(region, webroot)
{
//	alert(region);
	$('#basket .article.first').slideUp(function() {
		$('#basket .article.first').html(geturl(webroot+'add_to_order/region/'+region));
		$('#basket .article.first').slideDown();
	});
}

function geturl(addr) {
	var r = $.ajax({
		type: 'GET',
		url: addr,
		async: false
	}).responseText;
	return r;
}

//------------------------------------------------------------------------------

