
// ---------------------------------------------------------------------------
// Add to Travel Planner
// ---------------------------------------------------------------------------
function travel_planner_add(id, attraction, isset) {
	var rand = (Math.round((Math.random()*9999)));

	// update travel planner
	//var url = '/sites/oktourism/modules/travelplanner/travel-planner.ajax.php?id='+id+'&table='+attraction+'&'+rand;
	var travelPlannerUrl = '/m.Travelplanner_Sidebar/0/addItem/'+id+'/'+attraction+'/';
	var target = '#travel_planner_add_'+id;
	
	// Add item and update travel planner sidebar
	$.ajax({
		type: "GET",
		url: travelPlannerUrl,
		cache: false,
		success: function(html){
			//alert('Success!\n\n' + html);
			$("#travel_planner_sidebar").html(html);
			$(target).html('<p><strong class="updated">This item has been added to your travel planner.</strong></p>');
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Error: Unable to add item to cart!\n\n');
		}
	});
	
	if (isset != 'true') {
		if (document.cookie.length>0) {
			c_start=document.cookie.indexOf('travel_planner=');
			if (c_start!=-1) {
				c_start=c_start + 1;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				isset = unescape(document.cookie.substring(c_start,c_end));
			}
		}
	}
	if (isset != 'true') {
		// if this is the first addition to the travel planner
		// ask user if they want to login/register to save
		var confirm_text = 'You are adding to this item to a temporary travel planner. Any unsaved data will be lost when you close your web browser. You must login or register to save your travel planner.';
		alert(confirm_text);

		var exdate=new Date();
		exdate.setDate(exdate.getDate()+1);
		document.cookie='travel_planner=true'+
		((1==null) ? "" : ";expires="+exdate.toGMTString());

	}

	return false;
}


// ---------------------------------------------------------------------------
// Remove from Travel Planner
// ---------------------------------------------------------------------------
function travel_planner_remove(id) {
	// remove item from travel planner
	var travelPlannerUrl = '/m.Travelplanner_Sidebar/0/removeItem/'+id+'/';
	var target = '#travel_planner_'+id;
	
	// Add item and update travel planner sidebar
	$.ajax({
		type: "GET",
		url: travelPlannerUrl,
		cache: false,
		success: function(html){
			//alert('Success!\n\n' + html);
			$("#travel_planner_sidebar").html(html);
			$(target).hide(1000).remove();
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Error: Unable to add item to cart!\n\n');
		}
	});
}


// ---------------------------------------------------------------------------
// Name Travel Planner
// ---------------------------------------------------------------------------
function travel_planner_name() {
	var rand = (Math.round((Math.random()*9999)));

	var url = '/sites/oktourism/modules/travelplanner/travel-planner.ajax.php?action=name&'+rand;
	$('#travel_planner_name').load(url + pars);
}


// ---------------------------------------------------------------------------
// Save Travel Planner
// ---------------------------------------------------------------------------
function travel_planner_save() {

	// remove item from travel planner
	var name = $('#new_planner_name').val();
	var travelPlannerUrl = '/m.Travelplanner/0/savePlanner/'+name+'/';
	var target = '#travel_planner_list';
	
	// Add item and update travel planner sidebar
	$.ajax({
		type: "GET",
		url: travelPlannerUrl,
		cache: false,
		success: function(html){
			//alert('Success!\n\n' + html);
			$(target).html(html);
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Error: Unable to add item to cart!\n\n');
		}
	});
}


function literature_add(litId, userId, attraction) {
	// Submit AJAX request
	$.ajax({
		type: "GET",
		url: "/literature-request/m.Literature_Sidebar/62/addLiterature/"+litId+"/"+userId+"/"+attraction+"",
		cache: false,
		success: function(html){
			//alert('Success!\n\n' + html);
			$("#literature_sidebar").html(html);
			$('#literature_add_'+litId).html('<p><strong class="updated">Your literature request has been updated.</strong></p>');
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Error: Unable to add item to cart!\n\n');
		}
	});
}

/*
// ---------------------------------------------------------------------------
// Add to Literature Request
// ---------------------------------------------------------------------------
function literature_add(id, user, attraction) {
	var rand = (Math.round((Math.random()*9999)));

	// update literature request
	var url = '/sites/oktourism/modules/literature/literature.ajax.php?id='+id+'&attraction='+attraction+'&user='+user+'&'+rand;
	$('#literature_add_'+id).load(url);

	// update literature request sidebar
	var url = '/sites/oktourism/modules/literature/literature.ajax.php?action=sidebar'+'&'+rand;
	$('#literature_sidebar').load(url);
}



// ---------------------------------------------------------------------------
// Remove from Literature Request Cart
// ---------------------------------------------------------------------------
function literature_request_remove(id) {
	var rand = (Math.round((Math.random()*9999)));

	$.get('/sites/oktourism/modules/literature/literature.ajax.php?action=remove&id='+id+'&'+rand);
	Effect.Fade('literature_request_'+id, {duration: 0.5});
	setTimeout(function () { Element.remove('literature_request_'+id); }, 500);
}
*/

