function addJStoMenu()
{
    var menu = '';
    $$('#ulmenu li a').each(function(item) {
		var href = item.getAttribute('href').toString();
		href = href.substring(href.lastIndexOf('/') + 1,href.length);
        menu = menu + '<li><a href="javascript:show(\'' +
            href + '\')\">' + item.innerHTML  + "</a></li>\n";
    });
    $('ulmenu').update(menu);
    
    if (window.lang == 'en')
    {
      var text = 'General Conditions';
    } else {
      var text = 'Algemene Voorwaarden';
    }
    
    //$('conditions').update('<a href="javascript:show(\'' + text + '\')\">'
    //  + text + '</a>')
}

function addCalendar()
{
  var dp1 = new DatePicker();
  dp1.setShowNone(false);
  var el = dp1.create();
  $('divcalendar').appendChild( el );
  return dp1;
}

function submitForm()
{
  var valid = new Validation('form', {onSubmit:false});
  var result = valid.validate();
  if (result)
  {
    var datum= (dp1.getDate());
    
		if (datum.getDate()==24 && datum.getMonth()==11) {
			alert('Op de dag voor Kerst zijn wij gesloten.');	
		}	else if ((datum.getDate()==25 || datum.getDate()==26) && datum.getMonth()==11) {
			if ($('reservationtype').value == "Diner (18:00 - 21:30)") {
				var pars = $('form').serialize(); 
				pars = pars + '&date=' + datum;
				new Ajax.Request(
					"submit.php",
					{
					method: 'post',
					parameters: pars,
				onSuccess: function() {}
					});
				alert('Uw reservering is verzonden.');
			} else {
				alert("Met Kerst zijn wij alleen 's avonds open.");
			}
		} else {
			if (datum.getDay()>0)
			{
				var pars = $('form').serialize(); 
				pars = pars + '&date=' + datum;
				new Ajax.Request(
					"submit.php",
					{
					method: 'post',
					parameters: pars,
				onSuccess: function() {}
					});
				alert('Uw reservering is verzonden.');
			} else {
				alert('Op zondagen zijn wij gesloten.');
			}
		}
  }
  return false;
}


function show(page) {
    if (page !== window.shown) // als het zelfde doe niks
    {
      var old = $(window.shown);
      var element = $(page);
      var animationLength = 1;
      var fadeOutSpeed = 1;
  
      if(!window.first)
      {
			fadeIn(old, animationLength/fadeOutSpeed);
			setTimeout(function() {
				old.setStyle('display: none');
				fadeOut(element, animationLength);
            }, animationLength*1000/fadeOutSpeed); //milliseconden
			// Haal na de animatie van de verdwijnende layover de layover
			// oook echt weg. Anders kan er geen interactie plaatsvinden met
			// de content divs.
			setTimeout(function() {
				$('layover').setStyle('display: none;');
            }, animationLength*2000/fadeOutSpeed); //milliseconden
      } else {
          fadeOut(element, animationLength);
      }
  
      window.shown = page;
      window.first = false;
  }
}

function fadeIn(element, animationLength)
{
	$('layover').setStyle('display: block');  

	new Effect.Opacity('layover', 
       {duration:animationLength, from:0, to:1.0}); // seconden
}

function fadeOut(element, animationLength)
{
	element.setStyle('display: block;');

    new Effect.Opacity('layover',
       {duration:animationLength, from:1.0, to:0}); // seconden
}

function resTypeUpdate() {
    if ($('reservationtype').value == "Diner (18:00 - 21:30)") {
        $('lunchhour').hide();
        $('dinertime').show();
    } else {
        $('dinertime').hide();
        $('lunchhour').show();
    }
}

first = true;
show('Home');
new Validation('form');
Event.observe('reservationtype', 'change', resTypeUpdate);
$('lunchhour').hide();
$('dinertime').show();


