function closeSlideHolder(){

	jQuery("#galleryControls").slideUp(500);
	jQuery("#galleryHolder").slideUp(500, function(){
		jQuery("#galleryControls").remove();
		jQuery("#galleryHolder").remove();
	});

}

function slideImage(pic) {	
	if (jQuery("#galleryHolder").length > 0 ) {
		jQuery("#galleryHolder img").fadeOut(500, function(){
			jQuery("#galleryHolder").html("<img style='display:none;' id='" + pic + "' src='images/residential-homes/main/" + pic +".jpg' alt='Care South'/>");
			jQuery("#galleryHolder img").fadeIn(500);
		});
	}	
}

function getNextPicture(dir){

	//NEED TO KNOW WHAT THE NEXT PICTURE IS?
	var cur = jQuery("#galleryHolder img").attr("id");
	var newImg = (parseInt(cur)+1);
	if (jQuery("#t"+newImg).length > 0) {
		jQuery("#galleryHolder img").fadeOut(500, function(){
			jQuery("#galleryHolder").html("<img style='display:none;' id='" + newImg + "' src='images/residential-homes/main/" + newImg +".jpg' alt='Purbeck Shooting School'/>");
			jQuery("#galleryHolder img").fadeIn(500);
		});
	} else {
		jQuery("#galleryHolder img").fadeOut(500, function(){
			jQuery("#galleryHolder").html("<img style='display:none;' id='1' src='images/residential-homes/main/1.jpg' alt='<?=$data['name']?>'/>");
			jQuery("#galleryHolder img").fadeIn(500);
		});
	}

}

function getPreviousPicture(dir,maxImg){
	
	//NEED TO KNOW WHAT THE NEXT PICTURE IS?
	maxImg = parseInt(maxImg);
	var cur = jQuery("#galleryHolder img").attr("id");
	var newImg = (parseInt(cur)-1);
	if (jQuery("#t"+newImg).length > 0) {
		jQuery("#galleryHolder img").fadeOut(500, function(){
			jQuery("#galleryHolder").html("<img style='display:none;' id='" + newImg + "' src='images/residential-homes/main/" + newImg +".jpg' alt='Purbeck Shooting School'/>");
			jQuery("#galleryHolder img").fadeIn(500);
		});
	} else {
		jQuery("#galleryHolder img").fadeOut(500, function(){
			jQuery("#galleryHolder").html("<img style='display:none;' id='" + maxImg + "' src='images/residential-homes/main/" + maxImg + ".jpg' alt='Purbeck Shooting School'/>");
			jQuery("#galleryHolder img").fadeIn(500);
		});
	}

}

function validateForm(y, ShowPopup)
{
	function isValidEmail(emailAddress) 
	{
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	}
	
	function checkTelephone()
	{
		if ($('#home_number').val() == "" && $('#mobile_number').val() == "")
		{
			alert ("You must provide at least one contact number");
			return 1;	
		}		
	}
	
	var x = 0;
	var Errors = new Array();
	
	$(".requiredField").each(function()
	{
		if (($(this).val() == "" || this.value == "-1") )
		{			
			$(this).addClass("validationError");
			Errors.push($(this).attr("id") + " is required");
			x = 1;
		}
		else if ($(this).attr("id") == "email")
		{
			if (!isValidEmail($(this).val()))
			{
				x = 1;	
				$(this).addClass("validationError");
			}
			else
			{
				$(this).removeClass("validationError");	
			}
		}
		else
		{
			$(this).removeClass("validationError");
		}
	});
	
	x = checkTelephone();
	
	if(x === 1)
	{
		
		errors = "";
		for (var arr in Errors)
		{
			errors += "<p>" + arr + "</p>";
		}
		//$.prompt('Please enter all required fields marked with an *');
		if (ShowPopup)
		{
			$.prompt ("<h3>Error</h3><p>The following fields are required: </p>" + errors);
		}
		return false;
	}
	x = "document." + y + ".submit()";
	eval(x);
}
