/****************************************
*	Pure Luxury Form JS
*
*	Created by: Adam Foster
*	Date Created: 2008-05-07
*
*	Copyright 2008 Lightmaker Manchester
*
****************************************/

$(document).ready(function(){
	
	// destination drop down
	$('#chooseResort').hide();
	var currentDestination;
	var selectedElement = document.getElementById("qdestination");
	$("#qdestination").change(function() { 
	  currentDestination = selectedElement.selectedIndex-1;
	  //console.log(currentDestination);
	  if(currentDestination == null){
        $('#chooseResort').fadeOut("fast");
	  } else {
		$('#resortCheckBoxes p').remove();
		if(currentDestination >= 0){
			for (var i = 1; i < allData[currentDestination].length; i++) {
				injectBoxs(allData[currentDestination][i]);
			}
		}
	  	$('#chooseResort').fadeIn("fast");
		//fakeBoxes();
		if(currentDestination >= 0){$('#destination').attr("(value", allData[currentDestination][0]);}
	  }
	}); 
	
	function injectBoxs(resText){
		$('#resortCheckBoxes').append("<p class='checkboxColumn1'><label for='"+resText+"'>"+resText+"</label><input class='checkbox' id='"+resText+"' name='resort' type='checkbox' value='"+resText+"'/></p>");
	}
	
	// Fake Checkboxes		
	/*function fakeBoxes(){	
		$("input:checkbox").css({visibility: 'hidden'});
		$(".fakecheck").css({backgroundImage: 'url(_include/img/checkbox.gif)'});
		// check for what is/isn't already checked and match it on the fake ones
		$("input:checkbox").each( function() {
			(this.checked) ? $("#fake"+this.id).addClass('fakechecked') : $("#fake"+this.id).removeClass('fakechecked');
		});
		// function to 'check' the fake ones and their matching checkboxes
		$(".fakecheck").click(function(){
			($(this).hasClass('fakechecked')) ? $(this).removeClass('fakechecked') : $(this).addClass('fakechecked');
			$(this.hash).trigger("click");
			return false;
		});		
	};
	
	fakeBoxes();*/
		
	//resorts accordion 
//	$("#resorts .rowHeader").click(function() { 
//			$(this).children('span').toggleClass("activeAccordionItem");
//			$(this).next().slideToggle("fast")
//		}).next().hide();
		
	// validate forms 	
	$("#callbackForm").validate();
	$("#quoteForm").validate();
	$("#brochureForm").validate();
	
	// trigger select menu update on change not focus
	$("select").change(function() { 
	  $(this).valid(); 
	}); 

	// ancors as submit buttons
	/*
	$(function() {
	  $("#clicksubmit").click(function() {
		$("form").submit();
		return false;
	  });	
	});
	*/
});
