
function addDates(id) {
	$("#editdates_" + id).show('normal');
}

function editDates(id) {
	$("#editdates_" + id).show('normal');
}

function saveDates(id) {
	var frm = $('f_editdates_' + id);
	var startdate = '';
	var enddate = '';
	var sd = document.getElementById('startdate' + id + '_day').value;
	var sm = document.getElementById('startdate' + id + '_month').value;
	var sy = document.getElementById('startdate' + id + '_year').value;
	var ed = document.getElementById('enddate' + id + '_day').value;
	var em = document.getElementById('enddate' + id + '_month').value;
	var ey = document.getElementById('enddate' + id + '_year').value;
	
	if(sd != '' && sm != ''&& sy != ''){
		startdate = sy + '-' + sm + '-'+ sd;
	}
	
	if(ed != '' && em != '' && ey != ''){
		enddate = ey + '-' + em + '-'+ ed;
	}
	
   	$.get("/assets/TravelPlanner/ajax/adddates.cfm",{app:app,itemid:id,startdate:startdate,enddate:enddate},function(data,status){
        $("#dates_" + id).html(data);
  		
	    $("#dates_" + id).show('normal');
	    $("#dateControls_" + id).show('normal');
	    $("#editdates_" + id).hide('normal');
	    $("#adddates_" + id).hide('normal');
   	});
}

function cancelDates(id) {
	$("#editdates_" + id).hide('normal');
}


function addNote(id) {
	$("#editnote_" + id).show('normal');
	$("#ta_" + id).focus();
}

function editNote(id) {
	var notes = jQuery.trim($("#notetext_" + id).html());
	$("#ta_" + id).val(notes);
	$("#editnote_" + id).show('normal');
}

function saveNote(id,charLimit) {
	var notes = jQuery.trim($("#ta_" + id).val());
	if(notes != ''){
	   $.get("/assets/TravelPlanner/ajax/addnote.cfm",{app:app,notes:notes,itemid:id},function(data,status){
	      if(data.length > charLimit)
		  	note = data.substring(0,charLimit) + "...";
		  else 
		  	note = data;
		  $("#displaynote_" + id + " a").html(jQuery.trim(note));
		  $("#notetext_" + id).html(data);
	      $("#note_" + id).show('normal');
	      $("#addnote_" + id).hide('normal');
	      $("#editnote_" + id).hide('normal');
	   });
	}
	else {
	    $("#editnote_" + id).hide('normal');
	}
}

function deleteNote(id) {
   $.get("/assets/TravelPlanner/ajax/addnote.cfm",{app:app,notes:'',itemid:id},function(data,status){
      $("#ta_" + id).val('');
      $("#note_" + id).hide('normal');
      $("#addnote_" + id).show('normal');
      $("#editnote_" + id).hide('normal');
   });
}

function cancelNote(id) {
	$("#editnote_" + id).hide('normal');
}

function changeTab(tab) {
	if(tab == 'map'){
		$("#itineraryMapOuter").css('position','static');
		$("#itineraryMapOuter").css('visibility','visible');
		$("#itineraryMapOuter").show("normal");
		$("#itineraryListOuter").hide("normal");
		$("#itineraryMapTab").addClass("itineraryMapTabSelected");
		$("#itineraryMapTab").removeClass("itineraryMapTab");
		$("#itineraryListTab").addClass("itineraryListTab");
		$("#itineraryListTab").removeClass("itineraryListTabSelected");
		
	}
	else {
		$("#itineraryListOuter").show("normal");
		$("#itineraryMapOuter").hide("normal");
		$("#itineraryListTab").addClass("itineraryListTabSelected");
		$("#itineraryListTab").removeClass("itineraryListTab");
		$("#itineraryMapTab").addClass("itineraryMapTab");
		$("#itineraryMapTab").removeClass("itineraryMapTabSelected");	
	}
}

function showMapPopup(lat,lng) {
	$("#itineraryMapPopup").show().css("opacity", 0).fadeTo("slow", 0.5);
	return false;
}

function openMap(){
	$("#googlemap").show();
	$("#googlemapbody").show().css("opacity", 0).height($(document).height()).fadeTo("slow", 0.5, function(){
		var mapframe = $(document.createElement("iframe"));
			mapframe.attr("src", "http://www.google.co.nz").attr("width", "790").attr("height", "540").attr("frameborder", "0").attr("scrolling", "no").attr("marginheight", "0").attr("marginwidth", "0");
			$("#googlemap p").append(mapframe);
	});
	return false;
}

