addEvent(window, 'load', 'initCheckoutLinks');
window.initCheckoutLinksHandler = initCheckoutLinks;
var checkout_separator = ':_:';
function initCheckoutLinks() {
	if (document.getElementById('add_chosen') && document.getElementById('del_chosen')) {
		var userCookie  = new cookieObject("checkout", 3, "/", "casting", "locations");
		if (userCookie.found) {
			var add = document.getElementById('add_chosen');
			var values = '';
			if (/(casting_link)/i.test(add.className)) {
				var values = userCookie.get('casting');
			} else if (/(location_link)/i.test(add.className)) {
				var values = userCookie.get('locations');
			}
			var id = add.getAttribute('rel');
			if (id) {
				var parts = values.split(checkout_separator);
				var del = document.getElementById('del_chosen');
				var found = false;
				for (var i=0; i<parts.length; i++) {
					if (parts[i]==id) {
						found = true;
					}
				}
				if (found) {
					del.style.display = 'block';
					add.style.display = 'none';
				} else {
					del.style.display = 'none';
					add.style.display = 'block';
				}
			}
		}
	}
}

function addCheckoutItem(name, value) {
	var userCookie  = new cookieObject("checkout", 3, "/", "casting", "locations");
	var res = '';
	if (userCookie.found) {
		var exist = userCookie.get(name);
		res = exist;
		var parts = exist.split(checkout_separator);
		var skip = false;
		for (var i=0; i<parts.length; i++) {
			if (parts[i]==value)
				skip = true;
		}
		if (!skip)
			res = res + checkout_separator + value;
	} else {
		userCookie.put('casting', '');
		userCookie.put('locations', '');
		res = value;
	}
	userCookie.put(name, res);
	userCookie.write();
	initCheckoutLinks();
}

function delCheckoutItem(name, value) {
	var userCookie  = new cookieObject("checkout", 3, "/", "casting", "locations");
	var res = '';
	if (userCookie.found) {
		var exist = userCookie.get(name);
		var parts = exist.split(checkout_separator);
		var skip = false;
		for (var i=0; i<parts.length; i++) {
			if (parts[i]!=value && parts[i]!= '')
				res = res + checkout_separator + parts[i];
		}
	}
	userCookie.put(name, res);
	userCookie.write();
	initCheckoutLinks();
}

function removeFromList(module, id) {
	delCheckoutItem(module, id);
	var div = document.getElementById('id-'+id);
	if (div) {
		var par = div.parentNode;
		par.removeChild(div);
	}
}

function emptyList() {
	var userCookie  = new cookieObject("checkout", 3, "/", "casting", "locations");
	userCookie.remove();
	return true;
}
