
var box_checked = false;
var time_checked = false;

var revReg = false;
var revDin = false;
var revBox = false;
var revPak = false;
var revBrk = false;



$(document).ready(function(){
	$("form#testForm").validate();
	
	if($('input[id^=box_t]:checked').size() != 0)
	{
		box_checked = true;
		time_checked = true;
	}
	 
});



$(function () {

	/*********************************************
				DISPLAY THE MORE INFO SECTIONS
	*********************************************/
	$("a#reveal-register").click(function(){ 
		if(revReg==false)	{
			$("#register.more-fo").slideDown('fast').show(); 
			revReg = true;
		}	else	{
			$("#register.more-fo").slideUp('fast').hide(); 
			revReg = false;
		}
		return false;
	});
	
	
	$("input#event-register").click(function(){ 
		if($(this).attr("checked")==true){
			
			if(revReg==false)	{
				$("#register.more-fo").slideDown('fast').show(); 
				revReg = true;
			}
		}
		
	});
	
	$("a#reveal-breakfast-sesh").click(function(){ 
		if(revBrk==false) {		
			$("#breakfast-sesh.more-fo").slideDown('fast').show(); 
			revBrk = true;
		}	else	{
			$("#breakfast-sesh.more-fo").slideUp('fast').hide(); 
			revBrk = false;
		}
		
		return false;
	});
	
	$("a#reveal-box").click(function(){ 
		if(revBox==false) {		
			$("#box.more-fo").slideDown('fast').show(); 
			revBox = true;
		}	else	{
			$("#box.more-fo").slideUp('fast').hide(); 
			revBox = false;
		}
		
		return false;
	});
	
	$("a#reveal-dinner").click(function(){ 
		if(revDin==false) {		
			$("#dinner.more-fo").slideDown('fast').show(); 
			revDin = true;
		}	else	{
			$("#dinner.more-fo").slideUp('fast').hide(); 
			revDin = false;
		}
		
		return false;
	});
	
	$("input#event-dinner").click(function(){ 
		if($(this).attr("checked")==true){
			
			if(revDin==false)	{
				$("#dinner.more-fo").slideDown('fast').show(); 
				revDin = true;
			}
		}
		
	});
	
	$("a#reveal-package").click(function(){ 
		if(revPak==false) {		
			$("#package.more-fo").slideDown('fast').show(); 
			revPak = true;
		}	else	{
			$("#package.more-fo").slideUp('fast').hide(); 
			revPak = false;
		}
		
		return false;
	});
	
	$("input#event-package").click(function(){ 
		if($(this).attr("checked")==true){
			
			if(revPak==false)	{
				$("#package.more-fo").slideDown('fast').show(); 
				revPak = true;
			}
		}
		
	});
	
		
	
	$("input#brekkie").click(function() {
		if($("#brekkie").attr("checked")==false){
			$("input#a").attr("disabled", true);
			$("input#b").attr("disabled", true);
			$("input[name=breakfast]").removeClass("required");
			$("input#a").attr("checked",false);
			$("input#b").attr("checked",false);
		}
		else {
			if(revBrk==false) {		
				$("#breakfast-sesh.more-fo").slideDown('fast').show(); 
				revBrk = true;
			}
			$("input#a").attr("disabled", false);
			$("input#b").attr("disabled", false);
			$("input[name=breakfast]").addClass("required");
		}
	});

	$("#event-box").click(function() {
		if($("#event-box").attr("checked")==false){
			$("input[name^='box_']").attr("disabled", true);
			$("input[name^='box_']").attr("checked", false).hide();
			$("input[id^='box_t_']").attr("disabled", true);
			$("input[id^='box_t_']").attr("checked", false).hide();
			box_checked = false;
			time_checked = false;
		}
		else {
			if(revBox==false) {		
				$("#box.more-fo").slideDown('fast').show(); 
				revBox = true;
			}
			$("input[name=box_number]").attr("disabled", false).show();
		}
	});

	$("input[name=box_number]").click(function() {
		var box = $(this).attr("id");
		box_checked = true;
		time_checked = false;
		$("input[id^='box_t_']").attr("disabled", true).hide();
		$("input[id^='box_t_']").attr("checked", false);
		$("td.for-sale input[class="+box+"]").attr("disabled", false).show();
	});
	

	$("input[id^=box_t_]").click(function() {
		if($(this).attr("checked")==true)
			time_checked = true;
		else
			time_checked = false;
	});
		
});


/*function to open up a pop up window for the floor plan*/

// JK Pop up image viewer script- By JavaScriptKit.com
// Visit JavaScript Kit (http://javascriptkit.com)
// for free JavaScript tutorials and scripts
// This notice must stay intact for use

var popbackground="white" //specify backcolor or background image for pop window
var windowtitle="Venturefest floor plan"  //pop window title

function detectexist(obj){
	return (typeof obj !="undefined")
}

function jkpopimage(imgpath, popwidth, popheight, textdescription){

function getpos(){
	leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0
	toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0

	if (window.opera)
	{
		leftpos-=screenLeft
		toppos-=screenTop
	}
}

	getpos()
	
	var winattributes='width='+popwidth+',height='+popheight+',resizable=yes,left='+leftpos+',top='+toppos
	var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"'

	if (typeof jkpopwin=="undefined" || jkpopwin.closed)
		jkpopwin=window.open("","",winattributes)
	else
	{
		//getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
		//jkpopwin.moveTo(leftpos, toppos)
		jkpopwin.resizeTo(popwidth, popheight+30)
	}

	jkpopwin.document.open()
	jkpopwin.document.write('<html><head><title>Venturefest floor plan</title></head><body '+bodyattribute+'><img src="'+imgpath+'" style="margin-bottom: 0.5em"><br />'+textdescription+'</body></html>')
	jkpopwin.document.close()
	jkpopwin.focus()
}



function confirmSubmit()
{
	if(!$("input[name=item_dinner]").attr("checked") &&
		!$("input[name=item_register]").attr("checked")&&
		!$("input[name=item_brekkie]").attr("checked")&&
		!$("input[name=item_box]").attr("checked")&&
		!$("input[name=item_package]").attr("checked"))
	{
		alert("You must select at least one option");
		return false;				
	}
	else
			$return = true;
	
	if($("input[name=item_box]").attr("checked"))
	{
		if(box_checked==false)
		{
			alert("Please select a box from the available boxes listed.");
			return false;
		}
		else if(time_checked==false)
		{
			alert("Please select the time you wish to book the box for, am or pm \nOr select both to book for the full day");
			return false
		}
		else
			$return = true;		
	}		
	
	if($("input[name=item_brekkie]").attr("checked"))
	{
		if(!$("input#a").attr("checked") && !$("input#b").attr("checked"))
		{
			alert("Please select the breakfast session you would like to attend");
			return false;
		}
		else
			$return = true;
	}
	
	if($("input[name=item_dinner]").attr("checked") &&
		!$("input[name=item_register]").attr("checked")&&
		!$("input[name=item_brekkie]").attr("checked")&&
		!$("input[name=item_box]").attr("checked")&&
		!$("input[name=item_package]").attr("checked"))
	{
		var agree=confirm("You have selected to attend only the Venturefest dinner, is that correct? \nClick OK to continue or Cancel to choose another option.");
		if(agree)
			$return = true;
		else
			return false;
	}
	
	
	return $return;	
}
