/**
 * $Id: carwizard.js 715 2012-02-02 14:09:20Z koos $
 */
 
function showCarTab()
{
	$('#isVan').val('false'); 
	$('#car_container').show(); 
	$('#van_container').hide(); 
	$('.personenauto').addClass('selected'); 
	$('.bestelauto').removeClass('selected');
	
	return false;
}

function showVanTab()
{
	$('#isVan').val('true'); 
	$('#car_container').hide();
	$('#van_container').show();  
	$('.bestelauto').addClass('selected'); 
	$('.personenauto').removeClass('selected');
	
	return false;
}
 
/**
 * Refreshes the price info box on the left with new price info, based on the new prices vars and values
 * Called when form elements change that effect rent price (like begin and end date)
 * @param string serialized url friendly priceVars with keys and vars corresponding with the ones needed by the server side priceInfoAction method
 */
function updatePriceInfo(priceVars)
{
	//alert(priceVars);
	
	// zonder animatie
		/*
		$('#total_price').load('/carwizard/ajax-price-info/?' + priceVars);
		*/
	
	// met animatie met wit
		$('#total_price').fadeOut("fast");
		$('#total_price').load('/carwizard/ajax-price-info/?' + priceVars, function() 
			{ 
				$('#total_price').fadeIn("fast") 
			}
		);
	
	// met animatie zonder wit
		/*
		$('#total_price').css('z-index', 1);
		
		// dupliceer de oude en zet het duplicaat over de oude heen
		duplicate = $('#total_price').clone();
		duplicate.attr("id", "total_price_duplicate");
		duplicate.css("z-index", 2);
		
		// omdat ze absolute gepositioneerd zijn, komt het duplicaat bovenop te liggen
		$('#total_price').before(duplicate);
	
		//return;		
		
		// haal de nieuw prijs info op en zet dat in de verborgen total_price 
		$('#total_price').load('/carwizard/ajax-price-info/?' + priceVars, function() 
			{
				// als het laden klaar is : fade de duplicaat uit 
				// de duplicaat staat namelijk bovenop de nieuwe prijs, waardoor de oude met nieuwe gegevens zichtbaar wordt
				$('#total_price_duplicate').fadeOut("slow", function()
					{ 
						// als het uitfaden klaar is ruim de duplicate op 
						$('#total_price_duplicate').remove(); 
					}
				);
			}
		);
		*/
}

/**
 * Ververst de standaard openingstijden selectbox
 * @param string selectboxId the time field that needs to be changed
 * @param oject oDate dateobject
 */
function updateDefaultOpeningHours(selectboxId, oDate)
{
	// toont de juiste openingstijden
	iDay = oDate.getDay(); // 0 is sunday

	if ( iDay == 6)
	{
		//alert('hoi');
		// toon zaterdag tijden en verberg weekdays tijden
		$('#' + selectboxId + ' .weekdays').hide();
		$('#' + selectboxId + ' .weekdays').attr('disabled', 'disabled');
		$('#' + selectboxId + ' .weekdays').attr('disabled', 'disabled');
		$('#' + selectboxId + ' .saturday').show();
		$('#' + selectboxId + ' .saturday').removeAttr('disabled');
		
		// indien er geen selectie was, kiest de browser de eerste option (ook al is die disabeld) 
		// als dat zo is, kies dan de eerste wel enable option
		// de gekozen tijd nu disabled is of er is geen selectie, verschuif de gekozen tijd naar de eerstvolgende niet disablede tijd.
		if ($('#' + selectboxId + ' .saturday :selected').length == 0)
		{
			$('#' + selectboxId + ' .saturday').first().attr('selected', 'selected');
		}
	}
	else
	{
		// verberg zaterdag tijden en toon weekdays tijden
		$('#' + selectboxId + ' .saturday').hide();
		$('#' + selectboxId + ' .saturday').attr('disabled', 'disabled');
		$('#' + selectboxId + ' .weekdays').show();
		$('#' + selectboxId + ' .weekdays').removeAttr('disabled');
	}
	
}


/**
 * Disables all dates before given date
 * @param object oDate
 */
function setMinimumEndDate(oDate)
{
	minimumEndDate = oDate; 
	minimumEndDate.setDate(oDate.getDate() );
		
	$('#date_end').datepicker('option', 'minDate', minimumEndDate );
}

/**
 * @dependency array with holidays[date] = holidayname needs to exist!
 * @return array in the format http://jqueryui.com/demos/datepicker/#event-beforeShowDay
 */
function noSundaysOrHolidays(oDate) 
{
	if (oDate == undefined) 
	{
		return [true, '', ''];
	}

	// check for sundays
	if ( oDate.getDay() == 0)
	{	
		return new Array(
			false, // true/fase indicating whether or not this date is selectable
			'', // css classname defaults to 'ui-state-disabled',
			'' // an optional popup tooltip for this date. It is called for each day in the datepicker before it is displayed.			
		);
	}
	
	// check for holidays
	// format date to the holidays dates format
	date = $.datepicker.formatDate('yy-mm-dd', oDate);
	
	if ( holidays[date] != undefined)
	{
		return new Array(
			false, // true/fase indicating whether or not this date is selectable
			'', // css classname defaults to 'ui-state-disabled',
			holidays[date] // an optional popup tooltip for this date. It is called for each day in the datepicker before it is displayed.
		);
	}
	
	return new Array(true, '');
}

function verplichtVoorwaarden(){
	
	$('.confirm').click(function(e){
		
		if($('.voorwaarden').attr('checked')){
			//if checkbocks is checkt do defalt  
		}else{
			//else show user voorwaarden 
			e.preventDefault();
			
			//showLightBox();
			// light box have to be made multilang 
			$('.voorwaardenText').css({'color' : 'red'});
		}
	});
	
	$('.voorwaarden').click(function(){
		$('.voorwaardenText').css({'color' : '#000'});
		if($(this).attr('checked')){
			$('.voorwaarden').attr('checked','checked');
		}else{
			$('.voorwaarden').removeAttr('checked');
		}
	});
}

function showLightBox(){
	
	if($('.lightbox').length <= 0){
		lightbox = $("<div>");
		lightbox.css({
			"background": "#fff",
			"width" : "300px",
			"height" : "150px",
			"left" :  "50%",
			"top" : "50%",
			"margin-top": "-55px",
			"margin-left" : "-130px",
			"position" :  "absolute",
			"padding" : "10px",
			"-moz-border-radius" : "10px", /* Firefox */
			"-webkit-border-radius" : "10px", /* Safari, Chrome */
			"border-radius" : "10px", /* CSS3 */
			"z-index" : "100000"
		});
		
		lbbackground = $("<div>");
		lbbackground.css({
			"background": "#000",
			"width" : "100%",
			"height" : "100%",
			"position" :  "absolute",
			'opacity':'0.8',
			"z-index" : "99999"
		});
		
		lightbox.addClass('lightbox');
		lbbackground.addClass('lbbackground');
		lightbox.html('<h1>Beste Klant</h1><br/><br/>U moet akkoord gaan met de voorwaarden.<div style="text-align: center; cursor: pointer;">[ OK ]</div>');
		
		lbbackground.click(function(){
			lightbox.fadeOut('slow', function() {});
			lbbackground.fadeOut('slow', function() {});
		});
		
		lightbox.click(function(){
			lightbox.fadeOut('slow', function() {});
			lbbackground.fadeOut('slow', function() {});
		})
		
		$("body").prepend(lbbackground);
		$("body").prepend(lightbox);
	}else{
		$('.lightbox').fadeIn('slow', function() {});
		$('.lbbackground').fadeIn('slow', function() {});
	}
}

$(document).ready(function()
{
	// dit fixt het verticale scrollertje naast een autodetail
	$("#scrollup").click(function()
	{
		$("#carthumbcontainer").animate({ "top": 0}, 750);
	});

	$("#scrolldown").click(function()
	{
		$("#carthumbcontainer").animate({ "top": -255}, 750);
	});
	
	verplichtVoorwaarden();
	
});

