function loadnext(divout,divin){
    $("." + divout).hide();
    $("." + divin).fadeIn("fast");
}
	
var publicHolidays = [
	"26/1/2010", "1/1/2010", "2/4/2010", "3/4/2010", "5/4/2010", "26/4/2010", "3/5/2010", "14/6/2010", "2/8/2010", "27/12/2010", "28/12/2010", "23/7/2010", "25/4/2010", "3/1/2011", "26/1/2011", "22/4/2011", "23/4/2011", "25/4/2011", "2/5/2011", "13/6/2011", "1/8/2011", "26/12/2011", "27/12/2011", "22/7/2011"
	];

function convertEuropeanAmerican(europeanDate)
{
	var bits = europeanDate.split("/");
	return bits[1] + "/" + bits[0] +"/"+ bits[2];
}

function getDateFromCalendar()
{
	return $("#datepicker").datepicker( 'getDate' );
}
	
$(document).ready(function(){
	//Start DatePicker
	$("#datepicker").datepicker({
		minDate: 0, maxDate: '+2Y'
	});


	$("#venueSelector").change(changeVenue);
	changeVenue();
	
	
	

	$('#licence_note').hide();
	$('#thelot_note').hide();
	$('#everything_note').hide();
	$('#buffet_station_note').hide();
	$('#bar_cocktail_note').hide();
	$('#small_items_note').hide();
	$('#nothing_note').hide();
	$('#form_note').hide();
	
	
  	$('a#note_icon_show').click(
		function() {
 			$('#licence_note').show('slow');
 			return false;
		}
	);
	

/* Hide */
	

  	$('a#note_icon_hide').click(function() {
 		$('#licence_note').hide('fast');
 		return false;
  	});
  	
  	
	$('a#thelot_icon_hide').click(function() {
 		$('#thelot_note').hide('fast');
 		return false;
  	});
  	
  	$('a#everything_icon_hide').click(function() {
 		$('#everything_note').hide('fast');
 		return false;
  	});	
  	
  	
  	$('a#buffet_station_icon_hide').click(function() {
 		$('#buffet_station_note').hide('fast');
 		return false;
  	});
  	
  	$('a#bar_cocktail_icon_hide').click(function() {
 		$('#bar_cocktail_note').hide('fast');
 		return false;
  	});
  	
  	$('a#small_items_icon_hide').click(function() {
 		$('#small_items_note').hide('fast');
 		return false;
  	});
  	
  	$('a#nothing_icon_hide').click(function() {
 		$('#nothing_note').hide('fast');
 		return false;
  	});
  	
  	$('a#form_icon_hide').click(function() {
 		$('#form_note').hide('fast');
 		return false;
  	});
  	
  	
 /* Show */  	
  	
 $('.jqModal').click(function() {
 		$('.ui-datepicker').show('fast');
 		return false;
  	});
 
 /* Toggles */
 
  	$('a#note_icon_toggle').click(function() {
 		$('#licence_note').toggle(400);
 		return false;
  	});
  	
  	
  	$('a#thelot_icon_toggle').click(function() {
 		$('#thelot_note').toggle(400);
 		return false;
  	});
  	
  	$('a#everything_icon_toggle').click(function() {
 		$('#everything_note').toggle(400);
 		return false;
  	});  

  	$('a#buffet_station_icon_toggle').click(function() {
 		$('#buffet_station_note').toggle(400);
 		return false;
  	});
  	
  	$('a#bar_cocktail_icon_toggle').click(function() {
 		$('#bar_cocktail_note').toggle(400);
 		return false;
  	});  
  	
  	$('a#small_items_icon_toggle').click(function() {
 		$('#small_items_note').toggle(400);
 		return false;
  	});  
  	
  	$('a#nothing_icon_toggle').click(function() {
 		$('#nothing_note').toggle(400);
 		return false;
  	});
  	
  	$('a#form_icon_toggle').click(function() {
 		$('#form_note').toggle(400);
 		return false;
  	});   	   		
  	
  	
});


$("a, input").each(function() {
  $(this).attr("hideFocus", "true").css("outline", "none");
});

//Step 2

function checkNumber()
{
	var valid = false;
	var numGuests = $("#numberGuests").val();
	if (numGuests!="" && parseInt(numGuests)==numGuests)
	{valid=true;}
	else
	{
		alert("Please insert a number of guests");
	}
	return valid;
}

//Step 3

function changeVenue()
{
	var optionElement = $("#venueSelector option:selected");
	var seats = optionElement.attr("seats");
	var imgSrc = optionElement.attr("imgSrc");
	var url = optionElement.attr("url");

	$("#venueImg").attr("src",imgSrc);
	$("#venueURL").attr("href",url);
	$("#venueSeats").text(seats);
}


//Step 5


function checkBeverages() 
{
	var valid = false;
	
	var tabValueSelf = $("#tabValue").val();
	
	if (tabValueSelf!="" &&  parseFloat(tabValueSelf) == tabValueSelf)
	{valid=true;}
	else
	{
		if ($("input[name='beverageOption']:checked").length == 0)
			alert("Please choose a Beverage Preference");
		else
			valid=true;
	}
	return valid;
}


function checkPackDown()
{
	var valid = false;
	
	if ($("input[name='packdown']:checked").length ==0)
		alert("Please choose a Setup and Pack Down Option");
	else
		valid=true;
	return valid;
}





//Step 7

function loadForm()
{
	var date = new Date($("#datepicker").datepicker( 'getDate' ));
	var numGuests = parseInt($("#numberGuests").val());
	
	var other = $("#otherVenue").val();
	var venue = other!=""?other:$("#venueSelector option:selected").text();
	
	var menuStyleValue =  parseFloat($("#menuSelector option:selected").val());
	var menuStyleText = $("#menuSelector option:selected").text();
	
	
	var tabValue = 0;
	
	
	
	var isSday = isSunday(date);
	var isPHoliday = isPublicHolliday(date);
	
	var tabValueElement = $("#tabValue");
	
	if (tabValueElement.val()!="")
	{
		tabValue = parseInt(tabValueElement.val());
	}
	else
	{
		tabValue =  parseFloat($("input[@name='notab']:checked").val()) * numGuests;
		tabValue = tabValue + ((isSday || isPHoliday)?0.3*tabValue:0);
	}
	
	
	
	var packDownValue =  parseFloat($("input[@name='packdown']:checked").val());
	var packDownText = $("input[@name='packdown']:checked").parent().next('div').text();
	var beverageText = $("input[@name='beverageOption']:checked").parent().next('div').text();


	
	
	
	$("#dateChoice").text(date.getDate() + "/" +  (date.getMonth()+1) + "/" + date.getFullYear() + " "
	 	+(isSday?"(Sunday + 30% surcharge)":"") + (isPHoliday?"(Public Holiday + 30% surcharge)":""));
		
	$("#guestChoice").text(numGuests);
	$("#venueChoice").text(venue);
	$("#menuChoice").text(menuStyleText);
	$("#beverageChoice").text(beverageText);
	$("#packdownChoice").text(packDownText);
	
	
	var total = numGuests * (menuStyleValue  + packDownValue);
	total = total + ((isSday || isPHoliday)?0.3*total:0);
	total = total + tabValue;
	
	$("#packageTotal").text("$"+total+" gst inclusive");
	
	$("#hdnDate").val(date.getDate() + "/" +  (date.getMonth()+1) + "/" + date.getFullYear() + " "
	 	+(isSday?"(Sunday + 30% surcharge)":"") + (isPHoliday?"(Public Holiday + 30% surcharge)":""));
	$("#hdnGuests").val(numGuests);
	$("#hdnVenue").val(venue);
	$("#hdnMenu").val(menuStyleText);
	$("#hdnBeverage").val(beverageText);
	$("#hdnPackDown").val(packDownText);
	$("#hdnTotal").val(total);
	
	
	
}

function isSunday(date)
{
	return date.getDay()==0;
}

function isPublicHolliday(date)
{
	
	for(var n=0;n<publicHolidays.length;n++)
	{
		var holiday = new Date(convertEuropeanAmerican(publicHolidays[n]));
		
		if (holiday.getDate() == date.getDate() && holiday.getMonth() == date.getMonth())
			return true;
	}
	return false;
}