$(document).ready(function(){
	//Top Header Show/Hide function
	maxHeight = 60;
    minHeight = 0;
	minWidth= 0;
	maxWidth =563;
	
	$('#frm_contact').submit(function(){
		i=0;
		f_nme=$('.textbox_format2').eq(0).val();
		f_email=$('.textbox_format2').eq(1).val();
		f_comment=$('.textbox_format2').eq(2).val();
		
		if(isValidEmail(f_email)){i++;}
		if(f_nme!=""){i++;}
		if(f_comment!=""){i++;}
		
		if(i==3)
		{
			$.post("media/php/snd_coms.php",{s1: f_nme, s2: f_email, s3: f_comment},function(data){
				alert(data);				  
			});
		}
		else
		{
			alert("Please make sure all fields have been filled in.");	
		}		
		return false;								  
	});
	
	
    $("#toggle").click(function () {
		var cur_l = $('#content').css('left');
		//alert(cur_l);
		if(cur_l == "560px") {
			$("#content").animate({left: "0px"}, {queue:false});
		} else {
			if(cur_l == "0px") {
				$("#content").animate({left: "560px"}, {queue:false});	
			}
		}
		
	  
    });
	
	var togheight = $('#content').height();
	$('#toggle').height(togheight);

	//Cycle plugin
	$('#images') .cycle({  
		//fx:     'scrollLeft',
		easing: 'easeInOut',
		speed: 1000,
		delay:  -5000,
		timeout:  7000
	});
	
	//Cycle Thumb function
	$('#goto1').click(function() { 
		$('#images').cycle(0); 
		return false; 
	}); 
	 
	$('#goto2').click(function() {  
		$('#images').cycle(1);  
		return false;  
	}); 
	$('#goto3').click(function() { 
		$('#images').cycle(2); 
		return false; 
	}); 
	 
	$('#goto4').click(function() {  
		$('#images').cycle(3);  
		return false;  
	});
	
	$('#goto5').click(function() {  
		$('#images').cycle(4);  
		return false;  
	});
	
	$('#goto6').click(function() {  
		$('#images').cycle(5);  
		return false;  
	});
	
	
	$('#directions_form').submit(function(){
		if($('#postcode_box').val()!="")
		{
			return true;
		}
		alert("Please enter your postcode");
		return false;
	});
	
	
	$('#baf_form').submit(function(){
		$('#baf_info').text("Processing...");
		inpemail=$('#baf_email').val();
		
		if(isValidEmail(inpemail))
		{
			$.post("media/php/baf.php",{chkpost: "lafon", email_address: inpemail},function(data){
				$('#baf_info').text(data);		  
			});	
		}
		else
		{
			$('#baf_info').text("Please enter a valid email address.");
		}
		return false;							   
	});
	
	
	
	$('#accom_form').submit(function(){						 
		$('#frm_post').text("Processing...");
		
		inpDTEchkin=CheckDateTime($('#accom_chkin').val());
		inpDTEchkout=CheckDateTime($('#accom_chkout').val());
		
		chkin1=$('#accom_chkin').val();
		chkout1=$('#accom_chkout').val();
		inpPersons=$('#accom_per').val();
		cmail=$('#con_email').val();
		
		if(inpDTEchkin!="" && inpDTEchkout!="")
		{
			if(CheckPer(inpPersons))
			{
				if(!isValidEmail(cmail) || cmail=="")
				{
					$('#frm_post').text("Please enter a valid email address.");
					return false;
				}
				else
				{
					$.post("media/php/accom_snd.php",{chkin: chkin1, chkout: chkout1, persons: inpPersons, eml: cmail, chkpost: "lafon"},function(data){
						$('#frm_post').text(data);
					});
					return false;	
				}

			}
			else
			{
				$('#frm_post').text("Please enter the number of persons that will be staying with us.");
				return false;
			}
		}
		else
		{
			return false;	
		}
	});
});

function CheckPer(InputString)
{
	if(parseInt(InputString))
	{
		return true;	
	}
	else
	{
		return false;
	}
}

function CheckDateTime(inputDTE)
{
	if(inputDTE!="")
	{
		//yy-mm-dd
		var NewDate=new Date();
		
		//02-04-09 12:30
		str1=inputDTE.split(" ");
		str2=str1[0].split("-");
		str3=str1[1].split(":");
		
		if(parseInt(str2[0]+str2[1]+str2[2]) && parseInt(str3[0]+str3[1]))
		{
			return "yes";
		}
		else
		{
			$('#frm_post').text("Please enter a valid date and time (27-03-2009 16:30)");
			return "";
		}
	}
	else
	{
		return "";
	}
}

function isValidEmail(str) {

   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
