	// Bookings
	$(document).ready(function() {
		$('a#show_new_clients').click( function() { 
			$('div#clients').css({display: 'none'});
			$('div#new_client').css({display: 'none'});
			$('div#new_client').css({display: 'block'});
		});
	});

	$(document).ready(function() {
		$('a#show_existing_clients').click( function() { 
			$('div#clients').css({display: 'none'});
			$('div#new_client').css({display: 'none'});
			$('div#clients').css({display: 'block'});
		});
	});
	// Reservations
	$(document).ready(function() {
		$('a#show_new_clients').click( function() { 
			$('div#clients').css({display: 'none'});
			$('div#new_client').css({display: 'none'});
			$('div#new_client').css({display: 'block'});
		});
	});

	$(document).ready(function() {
		$('a#show_existing_clients').click( function() { 
			$('div#clients').css({display: 'none'});
			$('div#new_client').css({display: 'none'});
			$('div#clients').css({display: 'block'});
		});
	});
	
	$(document).ready(function() {
		$('a#close_clients').click( function() { 
			$('div#clients').css({display: 'none'});
			$('div#new_client').css({display: 'none'});
		});
	});
	
	$(document).ready(function() {
		// TRIP PRIVATE CHECKBOX
		$('input#trip_private').click( function() { 
			if($('input#trip_private').attr('checked') == true){
				$('table.trip_public').css({display: 'none'});
			} else {
				$('table.trip_public').css({display: 'block'});
			}
		});
	});

	$(document).ready(function() {
		$('#client_name').click( function() { 
			alert('hallo');
		});
		$('#client_name').autocomplete('ajax.php?area=client&action=search',{
																																delay:1,
																																minChars:2,
																																matchSubset:1,
																																matchContains:1,
																																cacheLength:10,
																																onItemSelect:selectItem,
																																onFindValue:findValue,
																																formatItem:formatItem,
																																autoFill:true
																															}
		);
	});

	
function findValue(li) {
	if( li == null ) return alert('No match!');
	if( !!li.extra ) var sValue = li.extra[0];
	else var sValue = li.selectValue;
	$('input#client_id').attr('value', sValue);	
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0];
}

function lookupAjax(){
	var oSuggest = $('input#client_name').autocompleter;
	oSuggest.findValue();
	return false;
}

	
	
	
	function showModalDialog(id){
		id_tag = "a#show_client_"+id;
		client_id_tag = "#client_id_"+id;
		// simplemodal
		$(document).ready(function () {
			$(id_tag).click(function (e) {
				e.preventDefault();
				$(client_id_tag).modal();
			});
		});
	}
	
	function viewClientData(client_id, trip_id){
		$("tr.listClient").css("background-color","white");
		$("#list_client_" + client_id).css("background-color","yellow");
		$("div#clientBookingData").css({display: 'none'});
		$("div#clientBookingData").empty();
		$(document).ready(function () {
			var url = '';
			url = "ajax.php?area=booking&action=view_client_data&client_id=" + client_id + "&trip_id=" + trip_id;
			$.post(url, 
						{},
						function(data){
							$("div#clientBookingData").css({display: 'none'});
							$("div#clientBookingData").empty();
							$("div#clientBookingData").replaceWith(data);
							$("div#clientBookingData").css({display: 'none'});
							$("div#clientBookingData").css({display: 'block'});
						}
					);
		});
	}
	
	function viewClientCommunication(trip_id){
		$("tr.listClient").css("background-color","white");
		$(document).ready(function () {
			//$("div#clientBookingData").css({display: 'none'});
			$("div#clientBookingData").empty();
			var url = '';
			url = "ajax.php?area=booking&action=view_client_communication&trip_id=" + trip_id;
			$.post(url, 
						{},
						function(data){
							$("div#clientBookingData").empty();
							$("div#clientBookingData").replaceWith(data);							
							$("div#clientBookingData").css({display: 'block'});
						}
					);
		});
	}
	
	function viewBookingFinancials(trip_id){
		//$("tr.listClient").css("background-color","white");
		$(document).ready(function () {
			$("div#clientBookingData").empty();
			var url = '';
			url = "ajax.php?area=booking&action=view_financials&trip_id=" + trip_id;
			$.post(url, 
						{},
						function(data){
							$("div#clientBookingData").empty();
							$("div#clientBookingData").replaceWith(data);							
							$("div#clientBookingData").css({display: 'block'});
						}
					);
		});
	}
	
	
	function showSpecialRequest(id){
		id_tag = "a#show_client_special_request_"+id;
		client_id_tag = "#client_special_request_"+id;
		// simplemodal
		$(document).ready(function () {
			$(id_tag).click(function (e) {
				e.preventDefault();
				$(client_id_tag).modal();
			});
		});
	}
	
	function showTripDialog(id){
		id_tag = "#show_trip_"+id;
		client_id_tag = "#viewTrip_"+id;
		//alert(id_tag);
		// simplemodal
		//$(document).ready(function () {
			//$(id_tag).click(function (e) {
				//alert(client_id_tag );
				//e.preventDefault();
				$(client_id_tag).modal();
			//});
		//});
	}
	
	function saveCommunication(id){
		own_travel_arrangements = $("#own_travel_arrangements_" + id).attr("checked") ? 1 : 0 ;
		travel_bookings_requested = $("#travel_bookings_requested_" + id).attr("checked") ? 1 : 0;
		travel_bookings_confirmed = $("#travel_bookings_confirmed_" + id).attr("checked") ? 1 : 0;
		payment_outstanding = $("#payment_outstanding_" + id).attr("checked") ? 1 : 0;
		payment_received = $("#payment_received_" + id).attr("checked") ? 1 : 0;
		doc_sent = $("#doc_sent_" + id).attr("checked") ? 1 : 0;
		sent_date = $("#sent_date_" + id).val();
		doc_delivered = $("#doc_delivered_" + id).attr("checked") ? 1 : 0;
		delivery_date = $("#delivery_date_" + id).val();
		$(document).ready(function () {
			url = "";
			$.post("ajax.php?area=booking&action=save_communication", { 
												id: id,
												own_travel_arrangements: own_travel_arrangements, 
												travel_bookings_requested: travel_bookings_requested ,
												travel_bookings_confirmed: travel_bookings_confirmed,
												payment_outstanding: payment_outstanding,
												payment_received: payment_received,
												doc_sent: doc_sent,
												sent_date: sent_date,
												doc_delivered: doc_delivered,
												delivery_date: delivery_date
												},function(data){}
					);
		});
		
	}

// open pdf documents in new window
$("a[href*=.pdf]").click(function(){
	$(this).attr({"target":"_blank"});
	return false;
});

function attachInvoice(id){
	var class_text = "tr#invoice_" + id ;
	$("tr.invoice_list").css("color","white");
	$("tr.invoice_list").css("background-color","silver");
	$(class_text).css("color","black");
	$(class_text).css("background-color","#F0FF71");
	$('input#invoice_id').attr('value', id);	
}

/*
 * 
 * jQuery.send()
 *
 * Copyright (c) 2008 Jared Mellentine - jared(at)mellentine(dot)com | http://design.mellentine.com
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Date: 9/22/2008
 * 
 * Full option list here: http://docs.jquery.com/Ajax/jQuery.ajax#options
 * 
 * Most common options are callbacks:
 * - beforeSend (function): use to validate data before sending
 * - complete (function): will be called regardless of success or error
 * - success (function): called only on success
 * - error (function): called only on error
 * - ifModified (function): called only if the response has changed since last
 *   request (based on Last-Modified header)
 * 
 * Other common options:
 * - dataType (string): specifies data return type ('xml', 'json', etc)
 * - cache (boolean): can be used to bypass cache
 * 
 */

 
(function(jQuery) {
	jQuery.fn.send = function(options) {
		return this.each(function(){
		    var form = jQuery(this);
			jQuery(this).bind('submit', function() {
			    var data = form.serialize();
				var method = (this.getAttribute('method')) ? this.getAttribute('method') : 'get';
				var action = (this.getAttribute('action')) ? this.getAttribute('action') : window.location;
				var params = {
					type     	: method,
					url      		: action,
					data     	: data
				};
				jQuery.extend(params, options);
				jQuery.ajax(params);
				return false;
			});
		});
	};
})(jQuery);


/*  table onmouseover */
$(document).ready(function() { 
	$('table#communication tr' ) 
	.click(function() {
		alert('www');
		var thisClicked = $(this).text(); 
		$('table#communication tr' ) 
		.each(function(index) { 
			if (thisClicked == $(this).text()) { 
				$(this).parent().toggleClass('highlight'); 
			} else { 
				$(this).parent().removeClass('highlight'); 
			}; 
		}); 
	}); 
}) 












