/*!
 * Car Rental Script v3.0
 * https://www.phpjabbers.com/car-rental-script/
 * 
 * Copyright 2019, PHPJabbers
 * 
 */
(function (window, undefined){
	"use strict";
	
	pjQ.$.ajaxSetup({
		xhrFields: {
			withCredentials: true
		}
	});
	var document = window.document,
		validate = (pjQ.$.fn.validate !== undefined),
		routes = [
			{pattern: /^#!\/Search$/, eventName: "loadSearch"},
			{pattern: /^#!\/Register$/, eventName: "loadRegister"},
	      	{pattern: /^#!\/Login$/, eventName: "loadLogin"},
	      	{pattern: /^#!\/ForgotPassword$/, eventName: "loadForgotPassword"},
			{pattern: /^#!\/Profile$/, eventName: "loadProfile"},
			{pattern: /^#!\/Orders\/page:(\d+)?$/, eventName: "loadOrders"},
			{pattern: /^#!\/Orders$/, eventName: "loadOrders"},
			{pattern: /^#!\/ViewOrder\/([A-Z]{2}\d{10})$/, eventName: "loadViewOrder"},
	      ];
	
	function log() {
		if (window.console && window.console.log) {
			for (var x in arguments) {
				if (arguments.hasOwnProperty(x)) {
					window.console.log(arguments[x]);
				}
			}
		}
	}
	
	function assert() {
		if (window && window.console && window.console.assert) {
			window.console.assert.apply(window.console, arguments);
		}
	}
	
	function hashBang(value) {
		if (value !== undefined && value.match(/^#!\//) !== null) {
			if (window.location.hash == value) {
				return false;
			}
			window.location.hash = value;
			return true;
		}
		
		return false;
	}
	
	function onHashChange() {
		var i, iCnt, m;
		for (i = 0, iCnt = routes.length; i < iCnt; i++) {
			m = window.location.hash.match(routes[i].pattern);
			if (m !== null) {
				pjQ.$(window).trigger(routes[i].eventName, m.slice(1));
				break;
			}
		}
		if (m === null) {
			pjQ.$(window).trigger("loadSearch");
		}
	}
	pjQ.$(window).on("hashchange", function (e) {
    	onHashChange.call(null);
    });
	
	function CR(options) {
		if (!(this instanceof CR)) {
			return new CR(options);
		}
		this.reset.call(this);
		this.init.call(this, options);
		
		return this;
	}
	
	CR.inObject = function (val, obj) {
		var key;
		for (key in obj) {
			if (obj.hasOwnProperty(key)) {
				if (obj[key] == val) {
					return true;
				}
			}
		}
		return false;
	};
	
	CR.size = function(obj) {
		var key,
			size = 0;
		for (key in obj) {
			if (obj.hasOwnProperty(key)) {
				size += 1;
			}
		}
		return size;
	};
	
	CR.prototype = {
		reset: function () {
			this.container = null;
			this.$container = null;
			this.current = 'loadSearch';
			this.step = 0;
			this.opts = {
				folder: ""
			};
			return this;
		},
		init: function (opts) {
			var self = this;
			this.opts = opts;
			this.container = document.getElementById("crContainer");
			this.$container = pjQ.$(this.container);

			//self.loadSearch(0);
			
			pjQ.$(self.container).on('click.cr', '#crBtnMap', function (e) {
				if (typeof window.initializeCR == "undefined") {
					window.initializeCR = function () {
						handleMap();
					};
					pjQ.$.getScript(['//maps.googleapis.com/maps/api/js?key=', self.opts.google_api_key, '&callback=initializeCR'].join(''));
				} else {
					handleMap();
				}
				
				function handleMap () {
					var map, center;
					pjQ.$("#pjCrMapModal").on("shown.bs.modal", function () {
					    google.maps.event.trigger(map, "resize");
					    if (center) {
					    	map.setCenter(center);
					    }
					}).modal('show');
					
					var canvasId = 'pjCrMapCanvas';
					
					pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionGetLocations", "&session_id=", self.opts.session_id].join("")).done(function (data) {
						map = new google.maps.Map(document.getElementById(canvasId), {
							zoom: 8,
							mapTypeId: google.maps.MapTypeId.ROADMAP
						});
						if (data && data.length) {
							var i, len, markers = [], _latLng, _marker, _info;
							for (i = 0, len = data.length; i < len; i++) {
								_latLng = new google.maps.LatLng(data[i].lat, data[i].lng);
								_marker = new google.maps.Marker({
									map: map,
									position: _latLng
								});
								var info_arr = [],
									location_thumb = '';
								if(data[i].thumb != null) {
									location_thumb = '<img src="'+data[i].thumb+'" /><br/>';
								}
								if(data[i].state != null)
								{
									info_arr.push(data[i].state);
								}
								if(data[i].city != null)
								{
									info_arr.push(data[i].city);
								}
								if(data[i].zip != null)
								{
									info_arr.push(data[i].zip);
								}
								if(data[i].address_1 != null)
								{
									info_arr.push(data[i].address_1);
								}
								if(data[i].email != null) {
									var $str = self.opts.location_email +  ': <a href="mailto:'+ data[i].email + '">' + data[i].email + '</a>';
									info_arr.push($str);
								}
								if(data[i].phone != null) {
									var $str = self.opts.location_phone +  ': ' + data[i].phone;
									info_arr.push($str);
								}
								_info = new google.maps.InfoWindow({
									content: ['<span style="font-weight: bold; text-transform: uppercase">', data[i].name, '</span><br /><br />',
									    location_thumb, 
										info_arr.join("<br />")
									].join("")
								});
								google.maps.event.addListener(_marker, "click", function (info, marker) {
									return function () {
										info.open(map, marker);
									};
								}(_info, _marker));
								if (i == len - 1) {
									map.setCenter(_latLng);
									center = _latLng;
								}
								markers.push(_marker);
							}
						}
					});
				}
				
				return false;
			}).on("click.cr", "#cr_same_location", function (e) {
				self.bindLocation();
			}).on("change.cr", "#cr_same_location", function (e) {
				self.bindLocation();
			}).on("change.cr", "#cr_pickup_id", function (e) {
				self.bindLocation();
				
				var pickup_id = pjQ.$('#cr_pickup_id').val(),
					params = "&session_id=" + self.opts.session_id + "&pickup_id=" + pickup_id;
				pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionGetDefaultPickupTime", params].join("")).done(function (resp) {
					pjQ.$('.pjCrTimePickerFromContainer').html(resp);
					
					pjQ.$('.pjCrTimePickerFromContainer').find('.pjCrTimePicker').datetimepicker({
						format: self.opts.time_format,
						ignoreReadonly: true,
						allowInputToggle: true
					});
				});
			}).on("click.cr", "#crBtnQuote", function (e) {
				self.disableButtons();
				pjQ.$.post([self.opts.folder, "index.php?controller=pjFront&action=pjActionCheckWTime", "&session_id=", self.opts.session_id].join(""), pjQ.$('#crFormSearch').serialize()).done(function (data) {
					if(data.status == 'OK')
					{
						self.loadCars.apply(self, [pjQ.$('#crFormSearch').serialize()]);
					}else{
						self.errorHandler(data.text);
						self.enableButtons(self);
					}
				}).fail(function () {
					self.enableButtons(self);
				});
				return false;
			}).on("click.cr", ".crBreadcrumbsEl", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				if(self.step != 5)
				{
					var rel = parseInt(pjQ.$(this).attr('rel'), 10);
					switch (rel) {
						case 1:
							self.loadSearch(1);
							break;
						case 2:
							self.loadCars();
							break;
						case 3:
							self.loadExtras();
							break;
						case 4:
							self.loadCheckout();
							break;
					}
				}else{
					if(rel == 1)
					{
						self.loadSearch(1);
					}
				}
				
				return false;
			}).on("click.cr", ".crLocaleEl", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				var locale_id = pjQ.$(this).attr('rel');
				self.setLocale(locale_id);
				return false;
			}).on("change.cr", "#crTransmission", function (e) {
				self.loadCars.apply(self, [null, self.type_id, pjQ.$(this).val(), self.col_name, self.direction]);
			}).on("change.cr", ".crTabsSelect", function (e) {
				var rel = pjQ.$('option:selected', this).attr('rel');
				self.loadCars.apply(self, [null, rel, self.transmission]);				
			}).on("change.cr", ".crSort", function (e) {
				var rel = pjQ.$('option:selected', this).attr('rel');
				self.loadCars.apply(self, [null, self.type_id, self.transmission, rel.split("|")[0], rel.split("|")[1]]);
			}).on("click.cr", ".crBtnContinue", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				self.type_id = pjQ.$(this).val();
				self.disableButtons();
				self.loadExtras();
				return false;
			}).on("click.cr", ".crChangeDates", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				self.loadSearch(1);
				return false;
			}).on("click.cr", "#crBtnWhen", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				self.loadSearch(1);
				return false;
			}).on("click.cr", "#crBtnCheckout", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				self.disableButtons();
				self.loadCheckout();
				return false;
			}).on("click.cr", "#crBtnConditions", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				pjQ.$('#pjCrTermsModal').modal('show');
				return false;
			}).on("click.cr", "#crBtnChoise", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				self.loadCars();
				return false;
			}).on("click.cr", ".crBtnAdd", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				self.addExtra.apply(self, [pjQ.$(this).val()]);
				return false;
			}).on("click.cr", ".crBtnRemove", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				self.removeExtra.apply(self, [pjQ.$(this).val()]);
				return false;
			}).on("change.cr", ".crSelectSmall", function (e) {
				var id = pjQ.$(this).attr('rel'),
					added = pjQ.$(this).attr('rev');
				if(added == 1)
				{
					self.addExtra.apply(self, [id]);
				}	
			}).on("click.cr", "#crBtnBack", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				self.loadExtras();
				return false;
			}).on("change.cr", "select[name='payment_method']", function (e) {
				switch (pjQ.$(this).val()) {
					case 'creditcard':
						pjQ.$('#crCCData').show();
						pjQ.$('#crBankData').hide();
						break;
					case 'bank':
						pjQ.$('#crCCData').hide();
						pjQ.$('#crBankData').show();
						break;
					default:
						pjQ.$('#crCCData').hide();
						pjQ.$('#crBankData').hide();
				}
			}).on("click.cr", "#pjCrCaptchaImage", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				var $captcha = pjQ.$(this);
				$captcha.attr("src", $captcha.attr("src").replace(/(&rand=)\d+/g, '\$1' + Math.ceil(Math.random() * 99999)));
				pjQ.$('#pjCrCaptchaField').val("").removeData("previousValue");
				return false;
			}).on("click.cr", ".pjCrBtnPannelTrigger", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				pjQ.$('.pjCrPanelLeft').toggleClass('hidden-xs');
				return false;
			}).on("click.cr", "#crBtnStartOver", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				self.loadSearch(0);
				return false;
			}).on("click.cr", ".pjCrSearch", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				if (!hashBang("#!/Search")) 
				{
					self.loadSearch.call(self, 0);
				}
				return false;
			}).on("click.cr", ".pjCrRegister", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				if (!hashBang("#!/Register")) 
				{
					self.loadRegister.call(self);
				}
				return false;
			}).on("click.cr", ".pjCrLogin", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				if (!hashBang("#!/Login")) 
				{
					self.loadLogin.call(self);
				}
				return false;
			}).on("click.cr", ".pjCrForgotPassword", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				if (!hashBang("#!/ForgotPassword")) 
				{
					self.loadForgotPassword.call(self);
				}
				return false;
			}).on("click.cr", ".pjCrLogout", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				
				var session_str = '';
				if(self.opts.session_id != '')
				{
					session_str += "&session_id=" + self.opts.session_id;
				}
				pjQ.$.post([self.opts.folder, "index.php?controller=pjFront&action=pjActionLogout", session_str].join("")).done(function (data) {
					if (!hashBang("#!/Search")) 
					{
						self.loadSearch.call(self, 0);
					}
				});
				return false;
			}).on("click.cr", ".pjCrProfile", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				if (!hashBang("#!/Profile")) 
				{
					self.loadProfile.call(self);
				}
				return false;
			}).on("click.cr", ".pjCrOrders", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				if (!hashBang("#!/Orders")) 
				{
					self.loadOrders.call(self);
				}
				return false;
			}).on("click.cr", ".pjCrPaging", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				var $type = pjQ.$(this).attr('data-type');
				if ($type == 'Orders') {
					hashBang("#!/Orders/page:" + pjQ.$(this).attr('data-page'));
				}
				return false;
			}).on('click.cr', '.pjCrApplyCode', function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				var voucher_code = pjQ.$('#pjCrVoucherCodeField').val();
				if(voucher_code != '')
				{
					pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionApplyCode"].join(""), {
						"session_id": self.opts.session_id,
						"locale": self.opts.locale,
						"voucher_code" : voucher_code
					}).done(function (data) {
						pjQ.$('#pjCrVoucherMessage').removeClass('alert-danger alert-info');
						if(data.status == "OK")
						{
							pjQ.$('#pjCrVoucherMessage').html(data.text).addClass('alert-info').show();
							pjQ.$('.pjCrApplyCode').hide();
							pjQ.$('.pjCrRemoveCode').show();
						}else{
							pjQ.$('#pjCrVoucherMessage').html(data.text).addClass('alert-danger').show();
						}
						setTimeout(function() {
							self.getSummary.call(self);
		    			}, 1000 );
					});
				}
			}).on('click.cr', '.pjCrRemoveCode', function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				var voucher_code = pjQ.$('#pjCrVoucherCodeField').val();
				if(voucher_code != '')
				{
					pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionRemoveCode"].join(""), {
						"session_id": self.opts.session_id,
						"locale": self.opts.locale,
						"voucher_code" : voucher_code
					}).done(function (data) {
						pjQ.$('#pjCrVoucherCodeField').val("");
						pjQ.$('#pjCrVoucherMessage').html("").hide();
						pjQ.$('.pjCrApplyCode').show();
						pjQ.$('.pjCrRemoveCode').hide();
						self.getSummary.call(self);
					});
				}
			}).on("change.cr", "input[name='c_email']", function(){
				var $this = pjQ.$(this);				
				if($this.val() != '')
				{
					pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionCheckClientAccount", "&session_id=", self.opts.session_id, "&email=", $this.val()].join("")).done(function (data) {
						if (data == 'true') {
							pjQ.$('#pjCrLoginModal').modal('show');
						}
					});					
				}
			});
			
			pjQ.$(document).on("click.cr", 'button[data-dismiss="modal"]', function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				var $modal = pjQ.$(this).closest('.modal');
				if ($modal !== undefined && $modal.length > 0) {
					$modal.modal('hide');
					pjQ.$('body').removeClass('modal-open');
				}
				return false;
			});
			
			pjQ.$(window).on("loadSearch", this.container, function (e) {
				self.loadSearch.call(self);
			}).on("loadCheckout", this.container, function (e) {
				self.loadCheckout.call(self);
			}).on("loadForgotPassword", this.container, function (e) {
				self.loadForgotPassword.call(self);
			}).on("loadProfile", this.container, function (e) {
				self.loadProfile.call(self);
			}).on("loadRegister", this.container, function (e) {
				self.loadRegister.call(self);
			}).on("loadLogin", this.container, function (e) {
				self.loadLogin.call(self);
			}).on("loadOrders", this.container, function (e) {
				switch (arguments.length) {
					case 1:
						self.page = 1;
						break;
					case 2:
						self.page = arguments[1];
					break;
				}
				self.loadOrders.call(self);
			}).on("loadViewOrder", this.container, function (e, booking_uuid) {
				self.booking_uuid = booking_uuid;
				self.loadViewOrder.call(self);
			});
			
			if (window.location.hash.length === 0) {
				if (self.opts.showCarsOnly == 1) {
					this.loadCarsOnly.call(this);
				} else {
					this.loadSearch.call(this, 0);
				}
			} else {
				onHashChange.call(null);
			}
			
			pjQ.$(document).on("click.cr", 'button[data-dismiss="modal"]', function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				var $modal = pjQ.$(this).closest('.modal');
				if ($modal !== undefined && $modal.length > 0) {
					$modal.modal('hide');
					pjQ.$('body').removeClass('modal-open');
				}
				return false;
			});
		},
		disableButtons: function(){
			var self = this;
			self.$container.find(".btn").each(function (i, el) {
				pjQ.$(el).addClass('disabled').attr('disabled','disabled');
			});
		},
		enableButtons: function(){
			var self = this;
			self.$container.find(".btn").each(function (i, el) {
				pjQ.$(el).removeClass('disabled').removeAttr("disabled");
			});
		},
		bindMenu: function () {
			var self = this;
			
			self.$container.find(".crBreadcrumbsEl").each(function (i, el) {
				pjQ.$(el).removeAttr("disabled");
				var breadcrumb_rel = parseInt(pjQ.$(el).attr('rel'), 10);
				if(breadcrumb_rel > self.step)
				{
					pjQ.$(el).css('cursor', 'default');
				}else{
					if(self.step == 5 && breadcrumb_rel != 1 && breadcrumb_rel != 5)
					{
						pjQ.$(el).css('cursor', 'default');
					}
				}
			});
		},
		bindGallery: function () {
			var self = this;
			pjQ.$('.pjCrProduct').each(function() {
				var $id = pjQ.$(this).attr('data-id');
				var $main = pjQ.$('.owl-carousel.main-'+$id);
			    var $thumbs = pjQ.$('.owl-carousel.thumbs-'+$id);

			      // init main
			      $main.owlCarousel({
			        items: 1,
			        dots: false,
			        nav: false,
			        loop: false,     // set true if you want infinite
			        margin: 8,
			        smartSpeed: 350,
			        lazyLoad: true,
			      });

			      // init thumbs
			      $thumbs.owlCarousel({
			        //items: 3,
			        dots: false,
			        nav: false,
			        margin: 8,
			        smartSpeed: 300,
			        center: false,
			        /*responsive: {
			          0:   { items: 4 },
			          640: { items: 5 },
			          900: { items: 6 }
			        }*/
			      });

			      // mark current thumb
			      function setThumb(index) {
			        $thumbs.find('.owl-item').removeClass('current')
			          .eq(index).addClass('current');

			        // ensure active thumb is visible
			        var thumbVisible = $thumbs.find('.owl-item').eq(index).hasClass('active');
			        if (!thumbVisible) $thumbs.trigger('to.owl.carousel', [index, 300, true]);
			      }
			      setThumb(0);

			      // sync: main -> thumbs
			      $main.on('changed.owl.carousel', function (e) {
			        if (!e.namespace || e.property.name !== 'position') return;
			        var index = e.item.index; // current slide index
			        setThumb(index);
			      });

			      // sync: thumbs -> main
			      $thumbs.on('click', '.owl-item', function () {
			        var i = pjQ.$(this).index();
			        $main.trigger('to.owl.carousel', [i, 300, true]);
			        setThumb(i);
			      });
			});
		},
		bindCarsGallery: function () {
			var self = this;
			pjQ.$('.car-gallery').owlCarousel({
			    items: 1,
			    loop: true,
			    margin: 0,
			    nav: true,
			    dots: false,
			    autoplay: false,
			    autoplayTimeout: 3500,
			    autoplayHoverPause: true,
			    navText: [
			      '<span class="glyphicon glyphicon-chevron-left"></span>',
			      '<span class="glyphicon glyphicon-chevron-right"></span>'
			    ]
			  });
		},
		bindLocation: function(){
			var self = this;
			if(pjQ.$('#cr_same_location').is(':checked'))
			{
				pjQ.$('#cr_return_id').val(pjQ.$('#cr_pickup_id').val());
				pjQ.$('#cr_return_id').attr('disabled', 'disabled');
			}else{
				pjQ.$('#cr_return_id').removeAttr('disabled');
			}
		},
		bindSearch: function () {
			var self = this;
			if(pjQ.$('#pjCrCalendarLocale').length > 0)
			{
				moment.updateLocale('en', {
					months : pjQ.$('#pjCrCalendarLocale').data('months').split("_"),
			        weekdaysMin : pjQ.$('#pjCrCalendarLocale').data('days').split("_"),
			        week: { dow: self.opts.startDay }
				});
			}
			pjQ.$('.pjCrTimePicker').datetimepicker({
				format: self.opts.time_format,
				ignoreReadonly: true,
				allowInputToggle: true
			});
			pjQ.$('.pjCrTimePickerFrom').on('dp.change', function (e) {
				pjQ.$('#cr_hour_from').val(e.date.hour());
				pjQ.$('#cr_minutes_from').val(e.date.minute());
			});
			pjQ.$('.pjCrTimePickerTo').on('dp.change', function (e) {
				pjQ.$('#cr_hour_to').val(e.date.hour());
				pjQ.$('#cr_minutes_to').val(e.date.minute());
			});
			
			if(pjQ.$('.pjCrDatePickerFrom').length > 0)
			{
				var currentDate = new Date();
				pjQ.$('.pjCrDatePickerFrom').datetimepicker({
					format: self.opts.momentDateFormat.toUpperCase(),
					locale: moment.locale('en'),
					allowInputToggle: true,
					minDate: new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()),
					ignoreReadonly: true
				});
				pjQ.$('.pjCrDatePickerFrom').on('dp.change', function (e) {
					var toDate = new Date(e.date);
					toDate.setDate(toDate.getDate() + 1);
					var momentDate = new moment(toDate);
					pjQ.$('.pjCrDatePickerTo').datetimepicker().children('input').val(momentDate.format(self.opts.momentDateFormat.toUpperCase()));
					pjQ.$('.pjCrDatePickerTo').data("DateTimePicker").minDate(e.date);
				});
			}
			if(pjQ.$('.pjCrDatePickerTo').length > 0)
			{
				var min_to = pjQ.$('.pjCrDatePickerTo').eq(0).attr('data-min');
				var fromDate = new Date(min_to);
				pjQ.$('.pjCrDatePickerTo').datetimepicker({
					format: self.opts.momentDateFormat.toUpperCase(),
					locale: moment.locale('en'),
					allowInputToggle: true,
					ignoreReadonly: true,
					useCurrent: false,
					minDate: new Date(fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate())
				});
			}
			
			if(pjQ.$('#cr_same_location').length > 0 && pjQ.$('#crReturnBox').length > 0)
			{
				self.bindLocation();
			}
			pjQ.$('.modal-dialog').css("z-index", "9999");
		},
		bindCheckout: function () {
			var self = this,
				btnConfirm = document.getElementById("crBtnConfirm"),
				$form = pjQ.$("#crCheckoutForm");	
			
			pjQ.$('.modal-dialog').css("z-index", "9999");
			
			var $reCaptcha = self.$container.find('#g-recaptcha');
			if ($reCaptcha.length > 0)
            {
                grecaptcha.render($reCaptcha.attr('id'), {
                    sitekey: $reCaptcha.data('sitekey'),
                    callback: function(response) {
                        var elem = pjQ.$("input[name='recaptcha']");
                        elem.val(response);
                        elem.valid();
                    }
                });
            }
			
			if(pjQ.$('#pjCrCalendarLocale').length > 0)
			{
				moment.updateLocale('en', {
					months : pjQ.$('#pjCrCalendarLocale').data('months').split("_"),
			        weekdaysMin : pjQ.$('#pjCrCalendarLocale').data('days').split("_"),
			        week: { dow: self.opts.startDay }
				});
				
				if(pjQ.$('.pjCrDateBirthday').length > 0)
				{
					pjQ.$('.pjCrDateBirthday').datetimepicker({
						format: self.opts.momentDateFormat.toUpperCase(),
						locale: moment.locale('en'),
						allowInputToggle: true,
						ignoreReadonly: true,
						useCurrent: false
					});
				}
			}
			
			$form.validate({
				rules: {
					"captcha": {
						remote: self.opts.folder + "index.php?controller=pjFront&action=pjActionCheckCaptcha&session_id=" + self.opts.session_id
					},
					"recaptcha": {
                        remote: self.opts.folder + "index.php?controller=pjFront&action=pjActionCheckReCaptcha&session_id=" + self.opts.session_id
                    },
				},
				ignore: ".ignore",
				onkeyup: false,
				onfocusout: function(element) {
			        var $el = pjQ.$(element);
			        $el.valid();
			    },
				errorElement: 'li',
				errorPlacement: function (error, element) {
					if(element.attr('name') == 'c_agree' || element.attr('name') == 'c_birthday')
					{
						error.appendTo(element.parent().next().find('ul'));
					}else if(element.attr('name') == 'captcha'){
						error.appendTo(element.parent().parent().next().find('ul'));
					}else if(element.attr('name') == 'recaptcha'){
						error.appendTo(element.next().find('ul'));
					}else{
						element.parent().addClass('has-error');
						error.appendTo(element.next().find('ul'));
					}
				},
				highlight: function(ele, errorClass, validClass) {
	            	var element = pjQ.$(ele);
	            	if(element.attr('name') == 'c_agree' || element.attr('name') == 'captcha')
					{
						element.parent().parent().parent().removeClass('has-success').addClass('has-error');
					}else if(element.attr('name') == 'c_birthday')
					{
						element.parent().parent().removeClass('has-success').addClass('has-error');
					}else{
						element.parent().removeClass('has-success').addClass('has-error');
					}
	            },
	            unhighlight: function(ele, errorClass, validClass) {
	            	var element = pjQ.$(ele);
	            	if(element.attr('name') == 'c_agree' || element.attr('name') == 'captcha')
					{
						element.parent().parent().parent().removeClass('has-error').addClass('has-success');
					}else if(element.attr('name') == 'c_birthday')
					{
						element.parent().parent().removeClass('has-error').addClass('has-success');
					}else{
						element.parent().removeClass('has-error').addClass('has-success');
					}
	            },
	            submitHandler: function(form){
	            	self.disableButtons();
	            	pjQ.$.post([self.opts.folder, "index.php?controller=pjFront&action=pjActionBookingSave", "&session_id=", self.opts.session_id].join(""), $form.serialize()).done(function (data) {
						switch (data.code) {
							case 100:
								self.errorHandler('\n' + self.opts.message_4);
								self.enableButtons();
								break;
							case 200:
								self.loadFinal(data);
								break;
							default:
								self.errorHandler('\n' + data.text);
								self.enableButtons();
								break;
						}
					});
					return false;
			    }
			});
			
		},
		bindFinal: function(data)
		{
			var self = this;
			var $alert = self.$container.find(".alert[data-payment]");
			if ($alert.length && $alert.data("payment") === "paypal_express") {
				$alert.remove();
			}
			var $payment_form = self.$container.find("form[name='pjOnlinePaymentForm']").first();
			if ($payment_form.length > 0) {
				$payment_form.trigger('submit');
			}
		},
		loadFinal: function(data)
		{
			var self = this;
			var params = "&session_id=" + self.opts.session_id + "&booking_id=" + data.booking_id;
			if(self.opts.pjLang > 0)
			{
				params += "&pjLang=" + self.opts.pjLang;
			}
			pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionLoadFinal", params].join("")).done(function (resp) {
				self.$container.html(resp);
				pjQ.$('.modal-dialog').css("z-index", "9999");
				self.bindFinal(data);
				self.step = 5;
				self.bindMenu();
			});
			self.current = "loadFinal";
		},
		loadSearch: function (index) {
			var self = this;
			var params = "&session_id=" + self.opts.session_id + "&index=" + index + "&tid=" + self.opts.tid;
			if(self.opts.pjLang > 0)
			{
				params += "&pjLang=" + self.opts.pjLang;
			}
			pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionLoadSearch", params].join("")).done(function (data) {
				self.$container.html(data);
				self.bindSearch();
				self.step = 1;
				self.bindMenu();
			});
			self.current = "loadSearch";
		},
		loadCars: function () {
			var self = this,
				post = typeof arguments[0] != "undefined" ? arguments[0] : null,
				qs = "";
			qs += "&session_id=" + self.opts.session_id + "&tid=" + self.opts.tid;
			if (typeof arguments[1] != "undefined") {
				self.type_id = arguments[1];
			} else {
				if (parseInt(self.opts.tid, 10) > 0) {
					self.type_id = self.opts.tid;
				} else {
					self.type_id = "all";
				}
			}
			qs += "&type_id=" + self.type_id;
			if (typeof arguments[2] != "undefined") {
				self.transmission = arguments[2];
			} else {
				self.transmission = "";
			}
			qs += "&transmission=" + self.transmission;
			if (typeof arguments[3] != "undefined") {
				self.col_name = arguments[3];
			} else {
				self.col_name = "total_price";
			}
			qs += "&col_name=" + self.col_name;
			if (typeof arguments[4] != "undefined") {
				self.direction = arguments[4];
			} else {
				self.direction = "asc";
			}
			qs += "&direction=" + self.direction;
			if(self.opts.pjLang > 0)
			{
				qs += "&pjLang=" + self.opts.pjLang;
			}
			pjQ.$.post([self.opts.folder, "index.php?controller=pjFront&action=pjActionLoadCars", qs].join(""), post).done(function (data) {
				self.$container.html(data);
				self.step = 2;
				self.bindMenu();
				self.bindGallery();
			});
			self.current = "loadCars";
		},
		loadCarsOnly: function () {
			var self = this,
				qs = "";
			qs += "&session_id=" + self.opts.session_id;
			qs += "&direction=" + self.direction;
			if(self.opts.pjLang > 0)
			{
				qs += "&pjLang=" + self.opts.pjLang;
			}
			pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionLoadCarsOnly", qs].join("")).done(function (data) {
				self.$container.html(data);
				self.step = 6;
				self.bindCarsGallery();
			});
			self.current = "loadCarsOnly";
		},
		loadExtras: function () {
			var self = this,
				qs = "&session_id=" + self.opts.session_id + "&type_id=" + self.type_id;
			if(self.opts.pjLang > 0)
			{
				qs += "&pjLang=" + self.opts.pjLang;
			}
			pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionLoadExtras", qs].join("")).done(function (data) {
				self.$container.html(data);
				pjQ.$('.modal-dialog').css("z-index", "9999");
				self.step = 3;
				self.bindMenu();
			});
			self.current = "loadExtras";
		},
		loadCheckout: function () {
			var self = this,
				qs = "&session_id=" + self.opts.session_id;
			if(self.opts.pjLang > 0)
			{
				qs += "&pjLang=" + self.opts.pjLang;
			}
			pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionLoadCheckout", qs].join("")).done(function (data) {
				self.$container.html(data);
				self.bindCheckout();
				self.step = 4;
				self.bindMenu();
				self.bindPopupLogin.call(self);
			});
			self.current = "loadCheckout";
		},
		addExtra: function (extra_id) {
			var self = this;
			self.disableButtons();
			
			pjQ.$.post([self.opts.folder, "index.php?controller=pjFront&action=pjActionAddExtra", "&session_id=", self.opts.session_id, "&extra_id=", extra_id].join(""), pjQ.$('#crFormExtras').serialize()).done(function (data) {
				self.loadExtras();
			});
			return self;
		},
		removeExtra: function (extra_id) {
			var self = this;
			self.disableButtons();
			pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionRemoveExtra", "&session_id=", self.opts.session_id, "&extra_id=", extra_id].join("")).done(function (data) {
				self.loadExtras();
			});
			return self;
		},
		setLocale: function (locale) {
			var self = this;
			pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionSetLocale", "&session_id=", self.opts.session_id, "&locale=", locale].join("")).done(function (data) {
				switch (self.current) {
					case 'loadSearch':
						self.loadSearch(1);
						break;
					case 'loadCars':
						self.loadCars();
						break;
					case 'loadExtras':
						self.loadExtras();
						break;
					case 'loadCheckout':
						self.loadCheckout();
						break;
					case 'loadFinal':
						self.loadSearch(1);
						break;
				}
				if (window.myCR) {
					window.myCR.opts = data;
				}
			});
		},
		errorHandler: function (message) {
			if(pjQ.$('.crError').length > 0)
			{
				pjQ.$('.crError').html(message.replace(/\n/g, "<br />")).show();
				setTimeout(function() {
					pjQ.$('.crError').fadeOut();
    			}, 5000 );
			}else{
				alert(message);
			}
		},
		loadRegister: function () {
			var self = this,
				index = this.opts.index,
				params ={};
			
			params.locale = self.opts.locale;
			params.hide = self.opts.hide;
			params.index = self.opts.index;
			if(self.opts.session_id != '')
			{
				params.session_id = self.opts.session_id;
			}
			
			pjQ.$.get([this.opts.folder, "index.php?controller=pjFront&action=pjActionRegister"].join(""), params).done(function (data) {
				self.$container.html(data);
				self.bindRegister.call(self);
			}).fail(function () {
				self.enableButtons.call(self);
			});
			self.current = "loadRegister";
		},
		bindRegister: function(){
			var self = this,
				index = this.opts.index,
				params = {};
			
			var $frmRegister = pjQ.$('#pjCrRegisterForm_' + self.opts.index);
			
			if($frmRegister.length > 0)
			{
				if(pjQ.$('#pjCrCalendarLocale').length > 0)
				{
					moment.updateLocale('en', {
						months : pjQ.$('#pjCrCalendarLocale').data('months').split("_"),
				        weekdaysMin : pjQ.$('#pjCrCalendarLocale').data('days').split("_"),
				        week: { dow: self.opts.startDay }
					});
					
					if(pjQ.$('.pjCrDateBirthday').length > 0)
					{
						pjQ.$('.pjCrDateBirthday').datetimepicker({
							format: self.opts.momentDateFormat.toUpperCase(),
							locale: moment.locale('en'),
							allowInputToggle: true,
							ignoreReadonly: true,
							useCurrent: false
						});
					}
				}
				
				if (validate) 
				{
					var login_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionRegister",
						check_email_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionCheckEmail";
					if(self.opts.session_id != '')
					{
						login_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionRegister&session_id=" + self.opts.session_id;
						check_email_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionCheckEmail&session_id=" + self.opts.session_id;
					}
					$frmRegister.validate({
						rules: {
							"customer_email": {
								remote: check_email_url
							}
						},
						onkeyup: false,
						errorElement: 'li',
						errorPlacement: function (error, element) {
							error.appendTo(element.next().find('ul'));
						},
			            highlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	element.parent().removeClass('has-success').addClass('has-error');
			            },
			            unhighlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	element.parent().removeClass('has-error').addClass('has-success');
			            },
						submitHandler: function (form) {
							self.disableButtons.call(self);
							var $form = pjQ.$(form);
							pjQ.$('.pjCrRegisterMsg').hide();
							pjQ.$.post(login_url, $frmRegister.serialize()).done(function (data) {
								if (data.status == "OK") {
									setTimeout(function(){
										if (!hashBang("#!/Login")) 
										{
											self.loadLogin.call(self);
										}
									}, 2000);
									pjQ.$('.pjCrRegisterMsg').find('.alert').addClass('alert-success').removeClass('alert-danger').html(data.text);
									pjQ.$('.pjCrRegisterMsg').show();
								} else {
									pjQ.$('.pjCrRegisterMsg').find('.alert').addClass('alert-danger').removeClass('alert-success').html(data.text);
									pjQ.$('.pjCrRegisterMsg').show();
									self.enableButtons.call(self);
								}
							}).fail(function () {
								self.enableButtons.call(self);
							});
							return false;
						}
					});
				}
			}
		},
		loadLogin: function () {
			var self = this,
				index = this.opts.index,
				params ={};
			
			params.locale = self.opts.locale;
			params.hide = self.opts.hide;
			params.index = self.opts.index;
			if(self.opts.session_id != '')
			{
				params.session_id = self.opts.session_id;
			}
			
			pjQ.$.get([this.opts.folder, "index.php?controller=pjFront&action=pjActionLogin"].join(""), params).done(function (data) {
				self.$container.html(data);
				self.bindLogin.call(self);
			}).fail(function () {
				self.enableButtons.call(self);
			});
			self.current = "loadLogin";
		},
		bindLogin: function(){
			var self = this,
				index = this.opts.index,
				params = {};
			
			var $frmLogin = pjQ.$('#pjCrLoginForm_' + self.opts.index);
			
			if($frmLogin.length > 0)
			{
				if (validate) 
				{
					var login_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionLogin";
					if(self.opts.session_id != '')
					{
						login_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionLogin&session_id=" + self.opts.session_id;
					}
					$frmLogin.validate({
						onkeyup: false,
						errorElement: 'li',
						errorPlacement: function (error, element) {
							error.appendTo(element.next().find('ul'));
						},
			            highlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	element.parent().removeClass('has-success').addClass('has-error');
			            },
			            unhighlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	element.parent().removeClass('has-error').addClass('has-success');
			            },
						submitHandler: function (form) {
							self.disableButtons.call(self);
							var $form = pjQ.$(form);
							pjQ.$.post(login_url, $frmLogin.serialize()).done(function (data) {
								if (data.status == "OK") {
									self.opts.userloggedIn = 1;
									if (!hashBang("#!/Search")) 
									{
										self.loadSearch.call(self);
									}
								} else {
									pjQ.$('.pjCrLoginMsg').find('.alert').addClass('alert-danger').removeClass('alert-success').html(data.text);
									pjQ.$('.pjCrLoginMsg').show();
									self.enableButtons.call(self);
								}
							}).fail(function () {
								self.enableButtons.call(self);
							});
							return false;
						}
					});
				}
			}
		},
		bindPopupLogin: function(){
			var self = this,
				index = this.opts.index,
				params = {};
			
			var $frmLogin = pjQ.$('#pjCrLoginForm');
			
			if($frmLogin.length > 0)
			{
				if (validate) 
				{
					var login_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionLogin";
					if(self.opts.session_id != '')
					{
						login_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionLogin&session_id=" + self.opts.session_id;
					}
					$frmLogin.validate({
						onkeyup: false,
						errorElement: 'li',
						errorPlacement: function (error, element) {
							error.appendTo(element.next().find('ul'));
						},
			            highlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	element.parent().removeClass('has-success').addClass('has-error');
			            },
			            unhighlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	element.parent().removeClass('has-error').addClass('has-success');
			            },
						submitHandler: function (form) {
							var $loginMessage = pjQ.$('#pjLoginMessage');
							$loginMessage.removeClass("alert-danger");
							$loginMessage.html('');
							$loginMessage.parent().parent().hide();
							
							self.disableButtons.call(self);
							var $form = pjQ.$(form);
							pjQ.$.post(login_url, $frmLogin.serialize()).done(function (data) {
								if (data.status == 'ERR') {
									$loginMessage.addClass("alert-danger");
									$loginMessage.html(data.text);
									$loginMessage.parent().parent().show();
									self.enableButtons.call(self);
								} else {
									pjQ.$('#pjCrLoginModal').modal('hide');
									pjQ.$('body').removeClass('modal-open');
									pjQ.$(window).trigger("loadCheckout");
								}
							}).fail(function () {
								self.enableButtons.call(self);
							});
							return false;
						}
					});
				}
			}
		},
		loadForgotPassword: function () {
			var self = this,
				index = this.opts.index,
				params ={};
			
			params.locale = self.opts.locale;
			params.hide = self.opts.hide;
			params.index = self.opts.index;
			if(self.opts.session_id != '')
			{
				params.session_id = self.opts.session_id;
			}
			pjQ.$.get([this.opts.folder, "index.php?controller=pjFront&action=pjActionForgotPassword"].join(""), params).done(function (data) {
				self.$container.html(data);
				self.bindForgotPassword.call(self);
				pjQ.$('body').removeClass('modal-open');
			}).fail(function () {
				self.enableButtons.call(self);
			});
			self.current = "loadForgotPassword";
		},
		bindForgotPassword: function(){
			var self = this,
				index = this.opts.index,
				params = {},
				$frmForgotPassword = pjQ.$('#pjCrForgotPasswordForm_' + self.opts.index);
			
			if($frmForgotPassword.length > 0)
			{
				if (validate) 
				{
					var forgot_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionForgotPassword";
					if(self.opts.session_id != '')
					{
						forgot_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionForgotPassword&session_id=" + self.opts.session_id;
					}
					$frmForgotPassword.validate({
						onkeyup: false,
						errorElement: 'li',
						errorPlacement: function (error, element) {
							error.appendTo(element.next().find('ul'));
						},
			            highlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	element.parent().removeClass('has-success').addClass('has-error');
			            },
			            unhighlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	element.parent().removeClass('has-error').addClass('has-success');
			            },
						submitHandler: function (form) {
							self.disableButtons.call(self);
							var $form = pjQ.$(form);
							pjQ.$('.pjCrForgotPassworsMsg').hide();
							pjQ.$.post(forgot_url, $frmForgotPassword.serialize()).done(function (data) {
								if (data.status == 'OK') {
									pjQ.$('.pjCrForgotPassworsMsg').find('.alert').addClass('alert-success').removeClass('alert-danger').html(data.text);
									$frmForgotPassword[0].reset();
								} else {
									pjQ.$('.pjCrForgotPassworsMsg').find('.alert').addClass('alert-danger').removeClass('alert-success').html(data.text);
								}
								pjQ.$('.pjCrForgotPassworsMsg').show();
								self.enableButtons.call(self);
							}).fail(function () {
								self.enableButtons.call(self);
							});
							return false;
						}
					});
				}
			}
		},
		loadProfile: function () {
			var self = this,
				index = this.opts.index,
				params ={};
			
			params.locale = self.opts.locale;
			params.hide = self.opts.hide;
			params.index = self.opts.index;
			if(self.opts.session_id != '')
			{
				params.session_id = self.opts.session_id;
			}
			pjQ.$.get([this.opts.folder, "index.php?controller=pjFront&action=pjActionProfile"].join(""), params).done(function (data) {
				if (data.status !='undefined' && data.status == 'NO_LOGIN') {
					if (!hashBang("#!/Login")) 
					{
						self.loadLogin.call(self);
					}
				}
				self.$container.html(data);
				self.bindProfile.call(self);
			}).fail(function () {
				self.enableButtons.call(self);
			});
			self.current = "loadProfile";
		},
		bindProfile: function(){
			var self = this,
				index = this.opts.index,
				params = {},
				$frmProfile = pjQ.$('#pjCrProfileForm_' + self.opts.index);
			
			if($frmProfile.length > 0)
			{
				if(pjQ.$('#pjCrCalendarLocale').length > 0)
				{
					moment.updateLocale('en', {
						months : pjQ.$('#pjCrCalendarLocale').data('months').split("_"),
				        weekdaysMin : pjQ.$('#pjCrCalendarLocale').data('days').split("_"),
				        week: { dow: self.opts.startDay }
					});
					
					if(pjQ.$('.pjCrDateBirthday').length > 0)
					{
						pjQ.$('.pjCrDateBirthday').datetimepicker({
							format: self.opts.momentDateFormat.toUpperCase(),
							locale: moment.locale('en'),
							allowInputToggle: true,
							ignoreReadonly: true,
							useCurrent: false
						});
					}
				}
				
				if (validate) 
				{
					var check_email_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionCheckEmail&id=" + $frmProfile.find('input[name="id"]').val();
					var profile_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionProfile";
					if(self.opts.session_id != '')
					{
						 check_email_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionCheckEmail&session_id=" + self.opts.session_id + "&id=" + $frmProfile.find('input[name="id"]').val();
						 profile_url = self.opts.folder + "index.php?controller=pjFront&action=pjActionProfile&session_id=" + self.opts.session_id;
					}
					$frmProfile.validate({
						rules: {
							"customer_email": {
								remote: check_email_url
							}
						},
						onkeyup: false,
						errorElement: 'li',
						errorPlacement: function (error, element) {
							if(element.attr('name') == 'captcha' || element.attr('name') == 'customer_birthday'){
								error.appendTo(element.parent().next().find('ul'));
							}else{
								error.appendTo(element.next().find('ul'));
							}
						},
			            highlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	if(element.attr('name') == 'captcha' || element.attr('name') == 'customer_birthday')
							{
								element.parent().parent().removeClass('has-success').addClass('has-error');
							}else{
								element.parent().removeClass('has-success').addClass('has-error');
							}
			            },
			            unhighlight: function(ele, errorClass, validClass) {
			            	var element = pjQ.$(ele);
			            	if(element.attr('name') == 'captcha' || element.attr('name') == 'customer_birthday')
							{
								element.parent().parent().removeClass('has-error').addClass('has-success');
							}else{
								element.parent().removeClass('has-error').addClass('has-success');
							}
			            },
						submitHandler: function (form) {
							self.disableButtons.call(self);
							var $form = pjQ.$(form);
							pjQ.$.post(profile_url, $frmProfile.serialize()).done(function (data) {
								if (data.status == 'OK') {
									pjQ.$('.pjCrProfileMsg').find('.alert').addClass('alert-success').removeClass('alert-danger').html(data.text);
									setTimeout(function(){ self.loadProfile.call(self); }, 3000);
								} else {
									pjQ.$('.pjCrProfileMsg').find('.alert').addClass('alert-danger').removeClass('alert-success').html(data.text);
								}
								pjQ.$('.pjCrProfileMsg').show();
								self.enableButtons.call(self);
							}).fail(function () {
								self.enableButtons.call(self);
							});
							return false;
						}
					});
				}
			}
		},
		loadOrders: function () {
			var self = this,
				index = this.opts.index,
				params ={};
			
			params.locale = self.opts.locale;
			params.hide = self.opts.hide;
			params.index = self.opts.index;
			if(self.opts.session_id != '')
			{
				params.session_id = self.opts.session_id;
			}
			params.page = self.page;
			pjQ.$.get([this.opts.folder, "index.php?controller=pjFront&action=pjActionOrders"].join(""), params).done(function (data) {
				if (data.status !='undefined') {
					if (data.status == 'NO_LOGIN') {
						if (!hashBang("#!/Login")) 
						{
							self.loadLogin.call(self);
						}
					}
				}
				self.$container.html(data);
			}).fail(function () {
				self.enableButtons.call(self);
			});
			self.current = "loadOrders";
		},
		loadViewOrder: function () {
			var self = this,
				index = this.opts.index,
				params ={};
			
			params.locale = self.opts.locale;
			params.hide = self.opts.hide;
			params.index = self.opts.index;
			if(self.opts.session_id != '')
			{
				params.session_id = self.opts.session_id;
			}
			params.uuid = self.booking_uuid;
			pjQ.$.get([this.opts.folder, "index.php?controller=pjFront&action=pjActionViewOrder"].join(""), params).done(function (data) {
				if (data.status !='undefined') {
					if (data.status == 'NO_LOGIN') {
						if (!hashBang("#!/Login")) 
						{
							self.loadLogin.call(self);
						}
					}
				}
				self.$container.html(data);
			}).fail(function () {
				self.enableButtons.call(self);
			});
			self.current = "loadViewOrder";
		},
		getSummary: function () {
			var self = this;
			if(pjQ.$('#pjCrBookingSummaryBox').length > 0)
			{
				pjQ.$.get([self.opts.folder, "index.php?controller=pjFront&action=pjActionGetSummary"].join(""), {
					"session_id": self.opts.session_id,
					"locale": self.opts.locale,
					"hide": self.opts.hide
				}).done(function (data) {
					pjQ.$('#pjCrBookingSummaryBox').html(data);
				});
			}
			return this;
		}
	};
	return (window.CR = CR);
})(window);