var elm_height=0;
var rst_height=0;
var frmvals="";

$(document).ready(function(){
	elm_height=$('#hotel .info').height();
	rst_height=$('#rest .info').height();
	
	$(window).bind("load",function(){
		$('#image').cycle();					   
	});
	
	$('#bad_form').submit(function(){
		$('#bafreturn').text("Processing...");
		if(CheckEmail($('#email2').val()))
		{
			inpemailaddr=$('#email2').val();
			$.post("media/php/baf.php",{emailaddr: inpemailaddr},function(data){
				$('#bafreturn').text(data);	
				$('#email2').val("");
			});
		}
		else
		{
			$('#bafreturn').text("Please enter a valid email address.");
		}
		return false;
	});
	
	
	$('#availablityenq').submit(function(){
		$('#returnresult').text("Processing...");
		ArrayFormVals();
		if(CheckVals() && CheckEmail(frmvals[1]))
		{
			$.post("media/php/roomenq.php",{f1: frmvals[0], f2: frmvals[1], f3: frmvals[2], f4: frmvals[3], f5: frmvals[4]},function(data){
				$('#returnresult').text(data);
				$('.aenqtb').val("");
				$('.textarea').val("");
			});
		}
		else
		{
			$('#returnresult').text("Please ensure all fields have been filled in correctly.");
		}
		return false;
	});
	
	$('#hotel .info').css("top","-"+elm_height+"px");
	$('#rest .info').css("top","-"+rst_height+"px");
	$('.infocontain').height(elm_height+"px");
	$('.frontbox .second').fadeOut();
	$('#hotel_link').mouseover(function() {
		$('#hotel .info').animate({top: "0px"},{queue: false});
		$('#hotel .second').fadeIn();
	});
	$('#hotel_link').mouseout(function() {
		$('#hotel .info').animate({top: "-"+elm_height+"px"});
		$('#hotel .second').fadeOut();
	});
	$('#restaurant_link').mouseover(function() {
		$('#rest .info').animate({top: "0px"},{queue: false});
		$('#rest .second').fadeIn();
	});
	$('#restaurant_link').mouseout(function() {
		$('#rest .info').animate({top: "-"+rst_height+"px"},{queue: false});
		$('#rest .second').fadeOut();
	});
});


//Javascript Functions
function ArrayFormVals()
{
	//clear array
	frmvals=new Array();
	
	$('.aenqtb').each(function(){
		frmvals.push($(this).val());				   
	});
	
	$('.textarea').each(function(){
		frmvals.push($(this).val());						 
	});
}
function CheckVals()
{
	j=0;
	for(i=0;i<=frmvals.length-1;i++)
	{
		if(frmvals[i]!="")
		{
			j++;	
		}
	}	
	if(j==frmvals.length)
	{
		return true;	
	}
	else
	{
		return false;
	}
}

function CheckEmail(inputemail) {
	AtPos = inputemail.indexOf("@");
	StopPos = inputemail.lastIndexOf(".");
	if (AtPos == -1 || StopPos == -1)
	{
		return false;
	}
	else
	{
		return true;	
	}
}