<?php
/*******************************************************************************
 *                    _ _ _ _
 *                   / _ _  /
 *            _ _   / /__/ /_ _   ____ _ _   _ _ _    __
 *           / _ ` /   _ _// _ ` / __// _ ` / _ \\ \ / /
 *          / _ _// /\ \  / _ _/ \_ \/ _ _// / \/ \ ` /
 *          \_ , /_/  \_\ \_ ,  /__ /\_ , /_/      \_/
 *
 *******************************************************************************
 *    Application:  eReserv
 *    Version:      6
 *    Author:       David Di Certo
 *    Website:      http://www.cogites.com
 *    Email:        contact@cogites.com
 *    Copyright:    2013 - David Di Certo
 *******************************************************************************
 *    == FR ==      La revente et la redistribution de l'application sont
 *                  strictement interdites.
 *
 *                  Vous êtes tenu d'avoir pris connaissance des
 *                  Conditions Générales de Vente disponibles sur Cogites.com
 *                  (y compris pour la version Free).
 *
 *    == EN ==      Resale and redistribution of the application are
 *                  Strictly prohibited.
 *
 *                  You are required to have read the Terms and Conditions
 *                  available on Cogites.com (including the Free version).
 *
 *******************************************************************************
*/
?>
		<?php if(!isset($no_visible_elements) || !$no_visible_elements)	{ ?>
			<!-- content ends -->
			</div><!--/#content.span10-->
		<?php } ?>
		</div><!--/fluid-row-->
		<?php if(!isset($no_visible_elements) || !$no_visible_elements)	{ ?>
			<hr>
		<?php } ?>

		<div id="dialog-confirm" title="<?php echo $tr->translate("msgDeleteTitle"); ?>" style="display: none;">
			<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 40px 0;"></span><?php echo $tr->translate("msgDeleteMessage"); ?></p>
		</div>

		<div id="dialog-detail" style='display:none'>
			<div id='exestylepopups' style='padding:10px; background:#fff;'>
				<center><h3 class="__mdbox-title"><?php echo $tr->translate("thDetails"); ?></h3></center>
			</div>
		</div>

		<footer>
			<p class="center">eReserv v<?php echo VERSION_NUMBER; ?> - copyright © <a href="http://cogites.com" target="_blank">Cogites.com</a></p>
		</footer>
	</div><!--/.fluid-container-->

	<!-- external javascript
	================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->

	<!-- jQuery -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery-2.1.1.min.js"></script>
	<!-- jQuery UI -->
	<!--<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery-ui-1.8.21.custom.min.js"></script>-->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery-ui-1.11.1.min.js"></script>
	<!-- BlockUI plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.blockUI.js"></script>

	<!-- transition / effect library -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-transition.js"></script>
	<!-- alert enhancer library -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-alert.js"></script>
	<!-- modal / dialog library -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-modal.js"></script>
	<!-- custom dropdown library -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-dropdown.js"></script>
	<!-- scrolspy library -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-scrollspy.js"></script>
	<!-- library for creating tabs -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-tab.js"></script>
	<!-- library for advanced tooltip -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-tooltip.js"></script>
	<!-- popover effect library -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-popover.js"></script>
	<!-- button enhancer library -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-button.js"></script>
	<!-- accordion library (optional, not used in demo) -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-collapse.js"></script>
	<!-- carousel slideshow library (optional, not used in demo) -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-carousel.js"></script>
	<!-- autocomplete library -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-typeahead.js"></script>
	<!-- tour library -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-tour.js"></script>
	<!-- library for cookie management -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.cookie.js"></script>
	<!-- data table plugin -->
	<script src='<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.dataTables.min.js'></script>

	<!-- In-Line Editing plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-editable.min.js"></script>

	<!-- chart libraries start -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/excanvas.js"></script>
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.flot.min.js"></script>
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.flot.pie.min.js"></script>
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.flot.stack.min.js"></script>
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.flot.resize.min.js"></script>
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.flot.time.min.js"></script>
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.flot.categories.min.js"></script>
	<!-- chart libraries end -->

	<!-- plugin for form wizard -->
	<!-- <script src="<?php // echo CONTEXT_ROOT_RESS;?>/styles/js/jquery/jquery.form/jquery.form.js"></script> -->
	<!-- plugin validate -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/validate/jquery.validate.min.js"></script>
	<?php if (isset($config['language_short']) && ($config['language_short'] != "en")) { ?>
		<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/validate/localization/messages_<?php echo $config['language_short']; ?>.js"></script>
	<?php } ?>
	<!-- <script src="<?php // echo CONTEXT_ROOT_RESS;?>/styles/js/jquery/jquery.form.wizard/jquery.form.wizard.js"></script> -->
	
	<!-- plugin for form wizard -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.smartWizard.js"></script> 
	
	<!-- select or dropdown enhancer -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/chosen.jquery.min.js"></script>
	<!-- checkbox, radio, and file input styler -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.uniform.min.js"></script>
	<!-- plugin for gallery image view -->
<!--	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.colorbox.min.js"></script> -->
	<!-- rich text editor library -->
<!--	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.cleditor.min.js"></script> -->
	<!-- notification plugin -->
<!--	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.noty.js"></script> -->
	<!-- file manager library -->
	<!--<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/elfinder.min.js"></script> -->
	<!-- star rating plugin -->
	<!-- <script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.raty.min.js"></script> -->
	<!-- for iOS style toggle switch -->
<!--	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.iphone.toggle.js"></script>-->
	<!-- autogrowing textarea plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.autogrow-textarea.js"></script>
	<!-- multiple file upload plugin -->
<!--	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.uploadify-3.1.min.js"></script> -->
	<!-- history.js for cross-browser state change on ajax -->
<!--	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.history.js"></script> -->
	<!-- TinyMCE plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/tinymce/tinymce.min.js"></script>
	<!-- Redirect plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.redirect.min.js"></script>
	<!-- Gantt plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.fn.gantt.js"></script>
	<!-- Moment plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/moment.min.js"></script>
	<!-- TagsInput plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.tagsinput.min.js"></script>

	<!-- Wizard plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-wizard.min.js"></script>
	<!-- Bootpag plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.bootpag.min.js"></script>

	<!-- jQuery FullCalendar plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/fullcalendar/fullcalendar.min.js"></script>
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/fullcalendar/lang-all.js"></script>

	<!-- jQuery Table to JSON plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.tabletojson.min.js"></script>

	<!-- <script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-formhelpers-selectbox.js"></script> -->
	<!-- <script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-formhelpers-languages.codes.js"></script> -->
	<!-- <script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-formhelpers-languages.js"></script> -->

	<!-- Less plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/less.min.js"></script>

	<!-- DateTime Picker plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.datetimepicker.js"></script>

	<!-- Color Picker plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/colpick.js"></script>

	<!-- Colorbox plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/jquery.colorbox-min.js"></script>

	<!-- Colorbox plugin -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/bootstrap-maxlength.min.js"></script>

<?php if (isset($config['language_short'])) { ?>
	<!-- Datetime Picker Lang -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/lang/datepicker-<?php echo $config['language_short']; ?>.js"></script>
<?php } ?>
	<!-- application script for ERESERV -->
	<script src="<?php echo CONTEXT_ROOT_RESS;?>/styles/js/ereserv.js"></script>

<script>
function blockUI() {
	$.blockUI({ message: '<h3><img src="<?php echo CONTEXT_ROOT_RESS ;?>/styles/img/loading.gif" /> <?php echo $tr->translate("msgPleaseWait"); ?></h3>' });
}
function unblockUI() {
	$.unblockUI();
}
$(document).ready(function(){
	//datatable
	oTable = $('.datatable').dataTable({
		// "sScrollX": "auto",
		// "sScrollXInner": "100%",
		// "bScrollCollapse": true,
		// "aaSorting": [],
		"bStateSave": true,
		"iCookieDuration": 60 * 60 * 24, // 1 day
		"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
		"sPaginationType": "bootstrap",
		"oLanguage": {
		<?php if (isset($config['language_short'])) { ?>
			"sUrl": "<?php echo LANGUAGE_PATH_RESS; ?>/dataTables.<?php echo $config['language_short']; ?>.txt"
		<?php } ?>
		},
		"fnDrawCallback":function(){
			var wrapper = this.parent();
			var rowsPerPage = this.fnSettings()._iDisplayLength;
			var rowsToShow = this.fnSettings().fnRecordsDisplay();
			var minRowsPerPage = this.fnSettings().aLengthMenu[0][0];
			if ( rowsToShow <= rowsPerPage || rowsPerPage == -1 ) {
				$('.dataTables_info', wrapper).parent().parent().hide();
				$('.dataTables_length', wrapper).parent().hide();
				// $('.dataTables_filter', wrapper).parent().hide();
			}else{
				$('.dataTables_info', wrapper).parent().parent().show();
				$('.dataTables_length', wrapper).parent().show();
			}
		}
	});
	$('.datepicker_____').datepicker({
		<?php if (isset($config) && !empty($config)) { ?>
			dateFormat: '<?php echo $config['date_format_js']; ?>',
			minDate: '<?php echo date($config['date_format']); ?>'
		<?php } ?>
	});

	$('.datepicker').datetimepicker({
		scrollMonth: false,
		closeOnDateSelect: <?php echo ($config['reserv_hour_enabled'] ? "false" : "true"); ?>,
		lang:'fr',
		format: '<?php echo $config['date_format']; ?>',
		timepicker: <?php echo ($config['reserv_hour_enabled'] ? "true" : "false"); ?>,
		step: <?php echo ($config['reserv_hour_increment'] ? $config['reserv_hour_increment'] : 15); ?>,
		hours12: <?php echo ($config['reserv_hour_12HourFormat'] ? "true" : "false"); ?>,
		weeks: true,
		allowTimes: [<?php 
			function hoursRange( $lower = 0, $upper = 86400, $step = 3600, $format = '' ) {
				$times = array();
				if ( empty( $format ) ) {
					$format = 'g:i a';
				}
				foreach ( range( $lower, $upper, $step ) as $increment ) {
					$increment = gmdate( 'H:i', $increment );
					list( $hour, $minutes ) = explode( ':', $increment );
					$date = new DateTime( $hour . ':' . $minutes );
					$times[] = (string) $increment;
				}
				return "'".implode("','",$times)."'";
			}
			function hoursRange2( $lower = 0, $upper = 86400, $step = 3600, $format = '' ) {
				$times = array();
				$start=strtotime($lower);
				$end=strtotime($upper);

				while($start<=$end) {
					$start=ceil($start/300)*300;
					$times[] = date('H:i', $start);
					$start+= $step*60;
				}
				return "'".implode("','",$times)."'";
			}
			print_r(hoursRange2(($config['reserv_hour_mintime'] ? $config['reserv_hour_mintime'] : 0), ($config['reserv_hour_maxtime'] ? $config['reserv_hour_maxtime'] : 0), ($config['reserv_hour_increment'] ? $config['reserv_hour_increment'] : 15)));
			?>]
	});

	$('.timepicker').datetimepicker({
		lang:'fr',
		format: 'H:i',
		timepicker: true,
		datepicker: false,
		step: <?php echo $config['reserv_hour_increment']; ?>,
		hours12: <?php echo ($config['reserv_hour_12HourFormat'] ? "true" : "false"); ?>
	});

	
	//uniform - styler for checkbox, radio and file input
	$("input:checkbox, input:radio, input:file").not('[data-no-uniform="true"]').uniform({
		fileButtonHtml:"<?php echo $tr->translate("ChooseFile"); ?>",
		fileDefaultHtml:"<?php echo $tr->translate("NoFile"); ?>"
	});

	$("#dialog-confirm").dialog({
		autoOpen: false,
		resizable: false,
		height: 'auto',
		modal: true,
		closeOnEscape: true,
		draggable: false,
		buttons: {
			'<?php echo $tr->translate("Yes"); ?>': function(){
				$(this).dialog('close');
				deleteAction();
			},
			'<?php echo $tr->translate("No"); ?>': function(){
				$(this).dialog('close');
			}
		}
	});
	$(".ui-dialog-titlebar-close").addClass("hide");
<?php if (isset($session->connected) && $session->connected == true && class_exists('ReservationMgr')) { ?>
$(document).on('click', '.tracking-element', function(e){
	var balance = $(this).parent().parent().parent().find("td").eq(8).html().trim();
	$('#reservationid').val($(this).parent().parent().parent().attr('id'));
	$('#status').val($(this).attr('name'));

	if ($("#tracking-action").length){
		$("#tracking-action").remove();
	}

	if ($(this).hasClass("current") && (!$(this).hasClass("error"))){
		e.preventDefault();
		alert("<?php echo $tr->translate("msgTrackingNoBack"); ?>");
		return false;
	}else{
		switch($(this).attr("name")) {
			case '<?php echo ReservationMgr::RESERV_OPTION; ?>':
					e.preventDefault();
					if ((location.pathname.split('/').slice(-1)[0] == "") || (location.pathname.split('/').slice(-1)[0] == "index.php")) { // we are in the Dashboard, tables have different col nb
						var balance = $(this).parent().parent().parent().find("td").eq(7).html().trim();
					}else if ((location.pathname.split('/').slice(-1)[0] == "search.php") || (location.pathname.split('/').slice(-1)[0] == "reservation.php")){
						var balance = $(this).parent().parent().parent().find("td").eq(6).html().trim();
					}

					$(this).parent().after(
						'<div id="tracking-action"><br>'+
							'<div class="control-group">'+
								'<div class="progress progress-success">'+
									'<div class="bar" style="width: 100%"><?php echo $tr->translate("thTrackingSetOption"); ?></div>'+
								'</div>'+
							'</div>'+
							'<div class="control-group">'+
								'<label class="control-label" for="reserv_price"><?php echo $tr->translate("thPaymentAmount"); ?></label>'+
								'<div class="controls">'+
									'<div class="input-append"><input class="input-small" id="reserv_price" name="reserv_price" type="text" value="' + balance + '"><span class="add-on"><?php echo $config['currency_symbol']; ?></span>'+
									'</div>	'+
								'</div>'+
							'</div>'+
							'<div class="control-group">'+
								'<div class="controls">'+
									'<div>'+
									'<button id="tracking-action-success" name="tracking-action-success" class="btn btn-mini btn-success"><?php echo $tr->translate("btnTrackingValidate"); ?></button>'+
									'<button id="tracking-action-cancel" name="tracking-action-cancel" type="button" class="btn btn-mini btn-warning"><?php echo $tr->translate("btnTrackingCancel"); ?></button>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>');
				$('#action').val('NEXT_STEP');
				return false;
				break;
			case '<?php echo ReservationMgr::RESERV_LEASE_SENT; ?>':
				if ($(this).hasClass("error")){
					e.preventDefault();
					$(this).parent().after(
						'<div id="tracking-action"><br>'+
							'<div class="control-group">'+
								'<div class="progress progress-danger">'+
									'<div class="bar" style="width: 100%"><?php echo $tr->translate("thTrackingLeaseReSent"); ?></div>'+
								'</div>'+
							'</div>'+
							'<div class="control-group">'+
								'<div class="controls">'+
									'<div>'+
									'<button id="tracking-action-success" name="tracking-action-success" class="btn btn-mini btn-success"><?php echo $tr->translate("btnTrackingValidate"); ?></button>'+
									'<button id="tracking-action-cancel" name="tracking-action-cancel" type="button" class="btn btn-mini btn-warning"><?php echo $tr->translate("btnTrackingCancel"); ?></button>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>');
					$('#action').val('LEASE_RESENT');
				}else{
					e.preventDefault();
					var deposit = Math.round($(this).parent().parent().parent().find("td").eq(7).html().trim() * <?php echo $config['lease_deposit_percent']; ?>)/ 100;
					$(this).parent().after(
						'<div id="tracking-action"><br>'+
							'<div class="control-group">'+
								'<div class="progress progress-warning">'+
									'<div class="bar" style="width: 100%"><?php echo $tr->translate("thTrackingLeaseSent"); ?></div>'+
								'</div>'+
							'</div>'+
						'<div class="control-group">'+
							'<label class="control-label" for="deposit_montant"><?php echo $tr->translate("thDepositAmount"); ?></label>'+
							'<div class="controls">'+
								'<div class="input-append"><input class="input-small" id="deposit_montant" name="deposit_montant" type="text" value="'+ deposit + '"><span class="add-on"><?php echo $config['currency_symbol']; ?></span>'+
								'</div>	'+
							'</div>'+
						'</div>'+
							'<div class="control-group">'+
								'<div class="controls">'+
									'<div>'+
									'<button id="tracking-action-success" name="tracking-action-success" class="btn btn-mini btn-success"><?php echo $tr->translate("btnTrackingValidate"); ?></button>'+
									'<button id="tracking-action-cancel" name="tracking-action-cancel" type="button" class="btn btn-mini btn-warning"><?php echo $tr->translate("btnTrackingCancel"); ?></button>'+
									'<button type="button" name="tracking-action-leasepreview" id="tracking-action-leasepreview" class="btn btn-info btn-mini" data-rel="tooltip" title="<?php echo $tr->translate("tipReservLeasePreview"); ?>"><i class="icon-search"></i></button>'+
									'</div>'+
								'</div>'+
							'</div>'+
						'</div>');
					$('#action').val('NEXT_STEP');
				}
				return false;
				break;
			case '<?php echo ReservationMgr::RESERV_VALIDATE; ?>':
				e.preventDefault();
				var deposit = ($(this).parent().parent().parent().attr("data-deposit") ? $(this).parent().parent().parent().attr("data-deposit") : Math.round($(this).parent().parent().parent().find("td").eq(7).html().trim() * <?php echo $config['lease_deposit_percent']; ?>)/ 100);
				$(this).parent().after(
					'<div id="tracking-action"><br>'+
						'<div class="control-group">'+
							'<div class="progress progress-info">'+
								'<div class="bar" style="width: 100%"><?php echo $tr->translate("thTrackingPaiment"); ?></div>'+
							'</div>'+
							'<label class="control-label"><?php echo $tr->translate("msgTrackingPayment"); ?></label>'+
							'<div class="controls center">'+
								'<input type="checkbox" id="cbtracking" name="cbtracking" checked>'+
							'</div>'+
						'</div>'+
						'<div class="control-group">'+
							'<label class="control-label" for="payment_montant"><?php echo $tr->translate("thPaymentAmount"); ?></label>'+
							'<div class="controls">'+
								'<div class="input-append"><input class="input-small" id="payment_montant" name="payment_montant" type="text" value="'+ deposit + '"><span class="add-on"><?php echo $config['currency_symbol']; ?></span>'+
								'</div>	'+
							'</div>'+
						'</div>'+
						'<div class="control-group">'+
							'<label class="control-label" for="payment_method"><?php echo $tr->translate("thPaymentMethod"); ?></label>'+
							'<div class="controls">'+
								'<select class="input-small" id="payment_method" name="payment_method">'+
									<?php $arrPaymentName = $tr->translate("thPaymentMethodNames");
										foreach($arrPaymentName as $paymentName) { ?>
											'<option value="<?php echo $paymentName; ?>" ><?php echo $paymentName; ?></option>'+
									<?php } ?>
								'</select>'+
							'</div>'+
						'</div>'+
						'<div class="control-group">'+
							'<div class="controls">'+
								'<div>'+
								'<button id="tracking-action-success" name="tracking-action-success" class="btn btn-mini btn-success"><?php echo $tr->translate("btnTrackingValidate"); ?></button>'+
								'<button id="tracking-action-cancel" name="tracking-action-cancel" type="button" class="btn btn-mini btn-warning"><?php echo $tr->translate("btnTrackingCancel"); ?></button>'+
								'</div>'+
							'</div>'+
						'</div>'+
					'</div>');
				$('#action').val('NEXT_STEP');
				return false;
				break;
			case '<?php echo ReservationMgr::RESERV_CLOSED; ?>':
				e.preventDefault();
				$(this).parent().after(
					'<div id="tracking-action"><br>'+
						'<div class="control-group">'+
							'<div class="progress progress-success">'+
								'<div class="bar" style="width: 100%"><?php echo $tr->translate("thTrackingBalance"); ?></div>'+
							'</div>'+
							'<label class="control-label"><?php echo $tr->translate("msgTrackingBalance"); ?></label>'+
							'<div class="controls center">'+
								'<input type="checkbox" id="cbtracking" name="cbtracking" checked>'+
							'</div>'+
						'</div>'+
						'<div class="control-group">'+
							'<label class="control-label" for="payment_montant"><?php echo $tr->translate("thPaymentAmount"); ?></label>'+
							'<div class="controls">'+
								'<div class="input-append"><input class="input-small" id="payment_montant" name="payment_montant" type="text" value="'+ balance + '"><span class="add-on"><?php echo $config['currency_symbol']; ?></span>'+
								'</div>	'+
							'</div>'+
						'</div>'+
						'<div class="control-group">'+
							'<label class="control-label" for="payment_method"><?php echo $tr->translate("thPaymentMethod"); ?></label>'+
							'<div class="controls">'+
								'<select class="input-small" id="payment_method" name="payment_method">'+
									<?php $arrPaymentMethod = $tr->translate("thPaymentMethodNames");
										foreach($arrPaymentMethod as $paymantMethod) { ?>
											'<option value="<?php echo $paymantMethod; ?>" ><?php echo $paymantMethod; ?></option>'+
									<?php } ?>
								'</select>'+
							'</div>'+
						'</div>'+
						'<div class="control-group">'+
							'<div class="controls">'+
								'<div>'+
								'<button id="tracking-action-success" name="tracking-action-success" class="btn btn-mini btn-success"><?php echo $tr->translate("btnTrackingValidate"); ?></button>'+
								'<button id="tracking-action-cancel" name="tracking-action-cancel" type="button" class="btn btn-mini btn-warning"><?php echo $tr->translate("btnTrackingCancel"); ?></button>'+
								'</div>'+
							'</div>'+
						'</div>'+
					'</div>');
				$('#action').val('NEXT_STEP');
				return false;
				break;
		}
		// trackingForm.submit();
	}
});

<?php } ?>
	$(".tenant-popup").click(function(e){
	tid = $(this).attr("data-tenantid");
		$(this).colorbox({
			width: "550px",
			height: "350px",
			inline: true,
			href: "#exestylepopups",
			onOpen: function(){
				$.ajax({ url: 'ajaxFnc.php',
					 data: {
						func: 'getTenant',
						tenantid: tid
					},
					type: 'POST',
					success: function(output) {
						$('#cboxLoadedContent').append('<div style="top: 10px;position: absolute;"><a class="btn btn-mini btn-success btn-action" _id="' + tid + '" _page="tenantDetail.php" _action="Edit"><?php echo $tr->translate("Edit"); ?></a></div>');
						$('#cboxLoadedContent').append(output);
					},
					error:function(xhr, ajaxOptions, thrownError){
					}
				});
			},
			success: function(data) {
			}
		});
	});
	$(document).on('click', '#tracking-action-cancel', function(e){
		$("#tracking-action").remove();
	});
	$(document).on('click', '#tracking-action-success, .menu-action', function(e){
		blockUI();
	});
	$(document).on('click', '#tracking-action-leasepreview', function(e){
			$("#trackingForm").attr("action", "leasePreview.php");
			$("#reservationid").val($(this).parent().parent().parent().parent().parent().parent().find("td").eq(0).html());
			trackingForm.submit();
			$("#trackingForm").attr("action", "");
	});

	jQuery.extend( jQuery.fn.dataTableExt.oSort, {
		"custom-date-pre": function ( a ) {
			switch("<?php echo $config['date_format']; ?>"){
				case "d.m.Y":
					var ukDatea = a.split('.');
					return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
					break;
				case "d.m.Y H:i":
					var ukDatea = a.split(' ');
					var d = ukDatea[0].split('.');
					var t = ukDatea[1].split(':');
					return (d[2] + d[1] + d[0] + t[0] + t[1]) * 1;
					break;
				case "d/m/Y":
					var ukDatea = a.split('/');
					return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
					break;
				case "d-m-Y":
					var ukDatea = a.split('-');
					return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
					break;
				case "Y-m-d":
					var ukDatea = a.split('-');
					return (ukDatea[0] + ukDatea[1] + ukDatea[2]) * 1;
					break;
				default:
					return a;
			}
		},

		"custom-date-asc": function ( a, b ) {
			return ((a < b) ? -1 : ((a > b) ? 1 : 0));
		},

		"custom-date-desc": function ( a, b ) {
			return ((a < b) ? 1 : ((a > b) ? -1 : 0));
		},
		"custom-numeric-pre": function ( a ) {
			var x = a.match(/data-search="*(-?[0-9\.]+)/)[1];
			return parseFloat( x );
		},

		"custom-numeric-asc": function ( a, b ) {
			return ((a < b) ? -1 : ((a > b) ? 1 : 0));
		},

		"custom-numeric-desc": function ( a, b ) {
			return ((a < b) ? 1 : ((a > b) ? -1 : 0));
		}

	});
});
</script>
</body>
</html>
