function updateComparisonBasket( locationId )
{

   // Get added locations from cookie
   var comparisonBasket = GetCookie( window, "ComparisonBasket" );

   // Get location and compare hyperlinks
   var locationLink = document.getElementById( "Location" + locationId );
   var comparisonLink = document.getElementById( 'LocationCompareNow' + locationId );

   // Guard empty
   if (comparisonBasket == null)
      comparisonBasket = "";

   //	Check if location in basket
   if ( comparisonBasket.match( locationId ) )
   {
      // Remove location from basket
      comparisonBasket = removeFromList( comparisonBasket, locationId );

      // Update hyperlink
      if ( locationLink != null )
      {
         removeClass( locationLink, "Selected" );
         locationLink.textContent = "vergelijk";
      }

      // Hide 'compare now' link
      removeClass( comparisonLink, "Selected" );
   }
   else
   {
      // Add location to basket
      comparisonBasket = addToList( comparisonBasket, locationId );

      // Update hyperlink
      if ( locationLink != null )
      {
         addClass( locationLink, "Selected" );
         //locationLink.textContent = "verwijder";
      }

      // Display 'compare now' link
      addClass( comparisonLink, "Selected" );
   }

   // Limit selected locations
   comparisonBasketSelected = LimitList( comparisonBasket, 3 );

   // Store new baskets in cookie
   SetCookie( window, "ComparisonBasket", comparisonBasket );
   SetCookie( window, "ComparisonBasketSelected", comparisonBasketSelected );
   
   UpdateComparisonNumberInMenu( );
}

function UpdateComparisonNumberInMenu( ) 
{
	// Get added locations from cookie
	var comparisonBasket = GetCookie( window, "ComparisonBasket" );

	// Guard empty
	if ( comparisonBasket == null )
		comparisonBasket = "";

	var VergelijkAantalContainer = document.getElementById('VergelijkAantal');
	if (VergelijkAantalContainer == null)
		return;
	var comparisonLocations = comparisonBasket.split( "," );
	var numberOfLocations = 0;
	for ( var i = 0; i < comparisonLocations.length; i++ ) {
		if ( !IsEmpty( TrimFast( comparisonLocations[i] ) ) )
			numberOfLocations++;
	}
	if ( numberOfLocations > 0 )
		VergelijkAantalContainer.innerHTML = '(' + numberOfLocations + ')';
	else
		VergelijkAantalContainer.innerHTML = '';
}

function UpdateSelectionNumberInMenu() {

	var mijnSelectieAantalContainer = $('#SelectieAantal');
	if (mijnSelectieAantalContainer.length == 0 )
		return;

	if (numberSelected > 0)
		mijnSelectieAantalContainer.html( '(' + numberSelected + ')' );
	else
		mijnSelectieAantalContainer.html( '' );
}

function selectLocation( locationId )
{
   // Get selected locations from cookie
   var comparisonBasketSelected = GetCookie( window, "ComparisonBasketSelected" );
   var comparisonBasket = GetCookie( window, "ComparisonBasket" );

   // Guard empty
   if ( comparisonBasketSelected == null )
      comparisonBasketSelected = "";

   // Build a list with the three latest items.
   if ( comparisonBasket.indexOf( locationId ) > -1 )
   {
		comparisonBasketSelected = addToList( comparisonBasketSelected, locationId );

		// Limit selected locations
		comparisonBasketSelected = LimitList( comparisonBasketSelected, 3 );

		// Store selected locations in cookie
		SetCookie( window, "ComparisonBasketSelected", comparisonBasketSelected );
	}
	
   // Reload document
   document.location.reload( );
}

function deselectLocation( locationId )
{
   // Get selected locations from cookie
   var comparisonBasketSelected = GetCookie( window, "ComparisonBasketSelected" );

   // Guard empty
   if ( comparisonBasketSelected != null )
   {
      // Remove location from selection
      comparisonBasketSelected = removeFromList( comparisonBasketSelected, locationId );

      // Store selected locations in cookie
      SetCookie( window, "ComparisonBasketSelected", comparisonBasketSelected );
   }

   // Reload document
   document.location.reload( );   
}



// Add, has, remove class

function addClass( element, className )
{
   if ( element != null )
   {
      if ( !this.hasClass( element, className ) )
         element.className += " " + className;
   }
}

function hasClass( element, className )
{
   if ( element != null )
   {
      return element.className.match( new RegExp( '(\\s|^)' + className + '(\\s|$)' ) );
   }
}

function removeClass( element, className )
{
   if ( element != null && hasClass( element, className ) )
   {
      var reg = new RegExp( '(\\s|^)' + className + '(\\s|$)' );
      element.className = element.className.replace( reg, ' ' );
   }
}



// Add, remove, limit list

function addToList( list, value )
{
   returnList = value + "," + list;

   return TrimChar( returnList, "," );
}

function removeFromList( list, value )
{
   var returnList = "," + list + ",";
   returnList = returnList.replace( "," + value + ",", "," );

   return TrimChar( returnList, "," );
}

function LimitList(list, count) {
	var returnList = "";
	var array = list.split(",");
	for (i = 0; i < Math.min(array.length, count); i++)
		returnList += array[i] + ",";

	return TrimChar(returnList, ",");
}

var provincieSelected
function SelectProvincie() {
	
}

$(function() {
	$('input[type=checkbox]').checkBox();
});

// Show update notification for shortlist update
var slideUpTimer = null;
function ShowUpdateNotification( message )
{
	var htmlElementText = '<div id="ShortlistUpdateMessage" class="Cufon" style="display: none; font-size: 2em; z-index: 99999; text-align: center; position: absolute; top: 0; left: 0; right: 0; background: #FFF; color: #000">';
	htmlElementText += '<div class="PaddingTopHalf PaddingBottomHalf">';
	htmlElementText += message;
	htmlElementText += '</div>';
	htmlElementText += '</div>';
	$('#ShortlistUpdateMessage').remove();
	if ( slideUpTimer != null )
		clearTimeout(slideUpTimer);

	$( 'body' ).prepend( htmlElementText );
	$( document ).scroll( function()
	{
		$( '#ShortlistUpdateMessage' )
			.css( 'top', $( document ).scrollTop() )
	})
	$( '#ShortlistUpdateMessage' )
		.css( 'top', $( document ).scrollTop() )
		.slideDown( 300 );
	slideUpTimer = setTimeout( function()
	{
		$( '#ShortlistUpdateMessage' ).slideUp( 300 );
	}, 2500 );
}