/**
  *
  * Confirm button
  *
  */
function confBut( ) {
	
		if ( confirm( 'Weet je het zeker?' ) ) {
				
				return true;
				
		}
		
		return false;
		
}

/**
  *
  * Create bookmark (IE & FF)
  *
  */
function createBookmark( ) {
		
		title	= 'NetChef.nl - Recepten, recepten, enneh... recepten!';
		url		= location.href;
		
		if ( window.sidebar ) {
				
				window.sidebar.addPanel( title, url, '' );
				
		} else if ( window.external ) {
				
				window.external.AddFavorite( url, title );
				
		} else {
				
				return false;
				
		}
		
}

/**
  *
  * First ask an question (confirm)
  *
  */

function doQuestion( question, url ) {
		
		if ( confirm( question ) ) {
				
				window.location = url;
				
		} else {
				
				return false;
				
		}
		
}

/**
  *
  * Toggle checkboxes
  *
  */
function toggleAll( elementName ) {
		
		var arrCheckbox = document.getElementsByName( elementName );
		
		for ( i = 0; i < arrCheckbox.length; i++ ) {
				
				var objCheckbox = document.getElementsByName( elementName ).item( i );
				
				if ( objCheckbox.checked ) {
						
						objCheckbox.checked = false;
						
				} else {
						
						objCheckbox.checked = true;
						
				}
				
		}
		
}


/**
  *
  * Print action
  *
  */
function doPrint( ) {
		
		window.open( 'boodschappenlijst/print', 'Print', 'width=800, height=500, scrollbars' );
		
}


/**
  *
  * Change searchbox
  *
  */
function changeBox( boxType ) {
		
		if ( boxType == 'simple' ) {
				
				document.getElementById( 'zoekenbox_smp' ).style.display = 'block';
				document.getElementById( 'zoekenbox_adv' ).style.display = 'none';
				
				document.getElementById( 'zoektab_spl' ).setAttribute( 'class', 'active zoekentab' );
				document.getElementById( 'zoektab_adv' ).setAttribute( 'class', 'inactive uitgebreidtab' );
				
		} else if ( boxType == 'advanced' ) {
				
				document.getElementById( 'zoekenbox_adv' ).style.display = 'block';
				document.getElementById( 'zoekenbox_smp' ).style.display = 'none';
				
				document.getElementById( 'zoektab_adv' ).setAttribute( 'class', 'active uitgebreidtab' );
				document.getElementById( 'zoektab_spl' ).setAttribute( 'class', 'inactive zoekentab' );
				
		} else {
				
				return false;
				
		}
		
}

/**
  *
  * Act on user actions
  *
  */
$( function( ) {
	
	$( 'ul.save > li' ).click( function( ev ) {
		
		var $item = $( this );
		var $target = $( ev.target );
		
		if ( $target.is( 'img.prullenbakje' ) ) {
			
			recycleImage( $item );
			
		}
		
		return false;
		
	} );
	
} );

/**
  *
  * Delete image from save list
  *
  */
function recycleImage( $item ) {
	
	var currCookie				= $.cookie( 'saveList' );
	var arrCookie				= currCookie.split( '-' );
	var newCookie				= null;
	
	for( i = 0; i < arrCookie.length; i++ ) {
		
		if ( arrCookie[ i ] != '' && arrCookie[ i ] != $item.attr( 'id' ) ) {
			
			newCookie			+= arrCookie[ i ] + '-';
			
		}
			
	}
	
	$.cookie( 'saveList', newCookie, { path: '/', expires: 10 } );
	$item.fadeOut( );
	
}
