﻿function addToBooklet(id, lcid) {
	var Booklet = $.cookie('Booklet');
	
	if (verifyBookletContent(id)) {
		deleteFromBooklet(id);
		
		if (document.images['BookletButton'])	
		  document.images['BookletButton'].src = '/media/' + lcid + '_323.gif';
	} else {
	    var content = Booklet ? Booklet + ';' + id : id;
	    
    	$.cookie('Booklet', content, { path: '/', expires: getDate() })
        $('#BookletButton').attr('src', '/media/' + lcid + '_326.gif');
	}
  
    reCount();
}
function RemoveFromList(id) {
	if (verifyBookletContent(id)) deleteFromBooklet(id);
}

function BookletCount() {
	var Booklet = $.cookie('Booklet');
	if (Booklet) return Booklet.split(';').length;
	
	return 0;
}

function reCount() {
    var bookletCount = String(BookletCount());
    
    $('#bookletCountDiv').html(bookletCount);
    $('#bookletCountDiv1').html(bookletCount);
    $('#bookletCount').html(bookletCount);
}

function deleteFromBooklet(id, query) {
	var Booklet = $.cookie('Booklet');
	var NewList = '';

	if (Booklet) {
		var CurrentList = Booklet.split(';');
		
		for (i = 0; i < CurrentList.length; i++){
			if (CurrentList[i] != id) {
				NewList += NewList == '' ? '' : ';';
				NewList += CurrentList[i];
			}
		}
	}
	
    $.cookie('Booklet', null, { path: '/' })
	$.cookie('Booklet', NewList, { path: '/', expires: getDate() })
}

function verifyBookletContent(id) {
	var Booklet = $.cookie('Booklet');
	if (Booklet) {
		var CurrentList = Booklet.split(';');
		for (i = 0; i < CurrentList.length; i++) if (CurrentList[i] == id) return true;
	}
	
	return false;
}

function getDate() {
    var date = new Date();
    date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
    
    return date;
}