var debugging = false;

$.fn.delay = function(time, name) {
    return this.queue((name || 'fx'), function() {
        var self = this;
        setTimeout(function() { $.dequeue(self); } , time);
    });
};

function loadSlideShow(groupID) {
	$('a.slideshow-' + groupID).colorbox({
		slideshow: true,
		transition: 'elastic'
	});
}

$(document).ready(function() {

	$(".check-in input").datepicker({
		showOn: 'both',
		buttonImage: '/templates/eco/images/date_picker_btn.gif',
		buttonImageOnly: true,
		numberOfMonths: 2,
		showAnim: 'fadeIn',
		dateFormat: 'yy-mm-dd',
		minDate: new Date(),
		maxDate: DateAdd(new Date(), 365),
		onSelect: function(dateText, inst) { checkInChanged(dateText, inst);}
	});
	$(".check-out input").datepicker({
		showOn: 'both',
		buttonImage: '/templates/eco/images/date_picker_btn.gif',
		buttonImageOnly: true,
		numberOfMonths: 2,
		showAnim: 'fadeIn',
		dateFormat: 'yy-mm-dd',
		minDate: new Date(),
		maxDate: DateAdd(new Date(), 365),
		onSelect: function(dateText, inst) { checkOutChanged(dateText, inst); }
	});

	$('#breadcrums a:last').each(function() {
		$(this).attr('href', window.location.pathname).addClass('set-page-name');
	});
    
	loadBanners();
	loadItems();
	$(".customhotelsearch").colorbox({speed: 700, width: 680, height: 550, iframe: true, opacity: 0.6 });
});

function checkInChanged(dateText, inst) {
	var checkInDate = $('#qs_datepicker_from').datepicker('getDate');
	var checkOutDate = $('#qs_datepicker_to').datepicker('getDate');

	if (checkInDate >= checkOutDate) {
		var newCheckOutDate = new Date(inst.currentYear, inst.currentMonth, inst.currentDay);
		newCheckOutDate.setDate(newCheckOutDate.getDate() + 1);
		$('#qs_datepicker_to').datepicker('setDate', newCheckOutDate)
	}
}

function checkOutChanged(dateText, inst) {
	var checkInDate = $('#qs_datepicker_from').datepicker('getDate');
	var checkOutDate = $('#qs_datepicker_to').datepicker('getDate');

	if (checkInDate >= checkOutDate) {
		var newCheckInDate = new Date(inst.currentYear, inst.currentMonth, inst.currentDay);
		newCheckInDate.setDate(newCheckInDate.getDate() - 1);
		$('#qs_datepicker_from').datepicker('setDate', newCheckInDate)
	}
}

function checkInHotelChanged(dateText, inst) {
	var checkInDate = $('#cp_datepicker_from').datepicker('getDate');
	var checkOutDate = $('#cp_datepicker_to').datepicker('getDate');

	if (checkInDate >= checkOutDate) {
		var newCheckOutDate = new Date(inst.currentYear, inst.currentMonth, inst.currentDay);
		newCheckOutDate.setDate(newCheckOutDate.getDate() + 1);
		$('#cp_datepicker_to').datepicker('setDate', newCheckOutDate)
	}
}

function checkOutHotelChanged(dateText, inst) {
	var checkInDate = $('#cp_datepicker_from').datepicker('getDate');
	var checkOutDate = $('#cp_datepicker_to').datepicker('getDate');

	if (checkInDate >= checkOutDate) {
		var newCheckInDate = new Date(inst.currentYear, inst.currentMonth, inst.currentDay);
		newCheckInDate.setDate(newCheckInDate.getDate() - 1);
		$('#cp_datepicker_from').datepicker('setDate', newCheckInDate)
	}
}

$(document).ready(function() {
	if (window.location.hash != null && window.location.hash.length > 0) {
		debugging = true;
	}
});

function DatePreCheck(startPath) {
    var clientNowDate = new Date();
    var serverNowDate = new Date(serverPageLoadDate.getTime() + (clientNowDate - clientPageLoadDate));  
    var checkInDate = $('#qs_datepicker_from').datepicker('getDate');
   	var checkOutDate = $('#qs_datepicker_to').datepicker('getDate');    
    var re = ('^[0-9]{4}-(((0[13578]|(10|12))-(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-(0[1-9]|[1-2][0-9]|30)))$');

    if (!checkInDate.toString().match(re) || !checkOutDate.toString().match(re)) {
    	var tempCheckInDate = new Date(checkInDate.getFullYear(), checkInDate.getMonth(), checkInDate.getDate(), 14, 00, 00,00); 
    	var minDate = GetMinDate();
    	var today = new Date();
    	var releaseCheck = CountBusinessHours(serverNowDate, tempCheckInDate);

    	if ($('#qs_datepicker_from').val() == $('#qs_datepicker_to').val()) {
    		alert(ol_QuickSearch_DatesAreEqual);
    	} else if (checkInDate > checkOutDate) {
    		alert(ol_QuickSearch_CheckOutAfterCheckIn);
    	} else if (parseMyDate(checkInDate) < parseMyDate(today)) {
    		alert(ol_QuickSearch_DateInPast);
    	} else if (releaseCheck <= 7) {
    		alert(ol_QuickSearch_DateBeforeReleaseDay);	
        } else {
            if (!debugging) {
				quickSearch.search(startPath);
			}
    	}
	} else {
        alert(ol_QuickSearch_DatesAreInvalid);
    }
}

function PreDateCheckOnPriceQuote(ownerInfo, hotelID, path) {
    var clientNowDate = new Date();
    var serverNowDate = new Date(serverPageLoadDate.getTime() + (clientNowDate - clientPageLoadDate));


	var checkInDate = $('#cp_datepicker_from').datepicker('getDate');
	var checkOutDate = $('#cp_datepicker_to').datepicker('getDate');
    var re = ('^[0-9]{4}-(((0[13578]|(10|12))-(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-(0[1-9]|[1-2][0-9]|30)))$');

    if (!checkInDate.toString().match(re) || !checkOutDate.toString().match(re)) {
    	var tempCheckInDate = new Date(checkInDate.getFullYear(), checkInDate.getMonth(), checkInDate.getDate(), 14, 00, 00,00);
    	var minDate = GetMinDate();
    	var today = new Date();
    	var releaseCheck = CountBusinessHours(serverNowDate, tempCheckInDate);

    	if ($('#cp_datepicker_from').val() == $('#cp_datepicker_to').val()) {
    		alert(ol_QuickSearch_DatesAreEqual);
    	} else if (checkInDate > checkOutDate) {
    		alert(ol_QuickSearch_CheckOutAfterCheckIn);
    	} else if (parseMyDate(checkInDate) < parseMyDate(today)) {
    		alert(ol_QuickSearch_DateInPast);
    	} else if (releaseCheck <= 7) {
    		alert(ol_QuickSearch_DateBeforeReleaseDay);
        } else {
			if (!debugging) {
				GetHotelPriceQuote(ownerInfo, hotelID, path);
			}
        }
	} else {
        alert(ol_QuickSearch_DatesAreInvalid);
    }
}

function parseMyDate(s) {
    return new Date(s.getFullYear(), s.getMonth(), s.getDate(), 0, 0, 0, 0);
}

function GetMinDate() {
	var now = new Date();
	var offset = 0;

	switch (now.getDay()) {
		case 5: offset = 4;break;
		case 6: offset = 3;break;
	}

	now.setDate(now.getDate() + parseInt(offset));
	return now;
}

function DateAdd(date, daysToAdd) {
	var returnDate = date;
	returnDate.setDate(returnDate.getDate() + daysToAdd);
	return returnDate;
}

function CountBusinessHoursOld(d1, d2) {
	var h1from = 9, m1from = 0, h1to = 12, m1to = 30, h2from = 14, m2from = 30, h2to = 18, m2to = 30;
	var minPerDay = h1to * 60 - h1from * 60 + m1to - m1from + h2to * 60 - h2from * 60 + m2to - m2from;

	var xd1 = new Date(d1), xd2 = new Date(d2);
	xd1.setDate(xd1.getDate() + 1);
	xd2.setDate(xd2.getDate() - 1);

	var c = CountBusinessDays(xd1, xd2) * minPerDay;
	var h = 0, m = 0;

	if (IsBusinessDay(d1)) {
		h = d1.getHours();
		m = d1.getMinutes();
		c = c + GetIntersectionMinutes(h1from, m1from, h1to, m1to, h, m, 24, 0);
		c = c + GetIntersectionMinutes(h2from, m2from, h2to, m2to, h, m, 24, 0);
	};

	if (IsBusinessDay(d2)) {
		h = d2.getHours();
		m = d2.getMinutes();
		c = c + GetIntersectionMinutes(h1from, m1from, h1to, m1to, 0, 0, h, m);
		c = c + GetIntersectionMinutes(h2from, m2from, h2to, m2to, 0, 0, h, m);
	};

	return c/60;
}

function CountBusinessHours(d1, d2) {
	var h1from = 9, m1from = 0, h1to = 12, m1to = 30, h2from = 14, m2from = 30, h2to = 18, m2to = 30;
	var minPerDay = h1to * 60 - h1from * 60 + m1to - m1from + h2to * 60 - h2from * 60 + m2to - m2from;

	var xd1 = new Date(d1), xd2=new Date(d2);
	xd1.setDate(xd1.getDate() + 1);
	xd2.setDate(xd2.getDate() - 1);

	var c = CountBusinessDays(xd1, xd2) * minPerDay;
	var h=0, m=0;

	if (IsBusinessDay(d1)) {
		h = d1.getHours();
		m = d1.getMinutes();
		c = c + GetIntersectionMinutes(h1from, m1from, h1to, m1to, h, m, 24, 0);
		c = c + GetIntersectionMinutes(h2from, m2from, h2to, m2to, h, m, 24, 0);
	};

	if (IsBusinessDay(d2) && !IsSameDate(d1, d2)){
		h = d2.getHours();
		m = d2.getMinutes();
		c = c + GetIntersectionMinutes(h1from, m1from, h1to, m1to, 0, 0, h, m);
		c = c + GetIntersectionMinutes(h2from, m2from, h2to, m2to, 0, 0, h, m);
	};
	return c/60;
}

function IsSameDate(d1, d2) {
	if(d1.getFullYear() == d2.getFullYear() && d1.getMonth() == d2.getMonth() && d1.getDate() == d2.getDate()) {
		return true;
	}
	return false;
}

function GetIntersectionMinutes(h1from, m1from, h1to, m1to, h2from, m2from, h2to, m2to) {
	var t1from = h1from * 60 + m1from;
	var t1to = h1to * 60 + m1to;
	var t2from = h2from * 60 + m2from;
	var t2to = h2to * 60 + m2to;
	var tfrom = t1from > t2from ? t1from : t2from;
	var tto = t1to < t2to ? t1to : t2to;
	if (tto > tfrom) {
		return tto-tfrom;
	}
	return 0;
}

function CountBusinessDays(d1, d2) {
    var c = 0;
    var d = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate(),0, 0, 0, 0);
    var dmax=new Date(d2.getFullYear(), d2.getMonth(), d2.getDate(), 0, 0, 0, 0);
    while (d <= dmax) {
        if (d.getDay() != 6 && d.getDay() != 0 && IsBusinessDay(d))
			c++;

        d.setDate(d.getDate() + 1);
    }

    return c;
}

function IsBusinessDay(d) {
    var holidays1PT = ['1-1','4-25','5-1','6-10','8-15','10-5','11-1','12-1','12-8','12-25'];
    var holidays2PT = ['2010-2-16','2010-4-2','2010-4-4','2010-6-23','2011-3-8','2011-4-22','2011-4-24','2011-6-23','2012-2-21','2012-4-6','2012-4-8','2012-6-7']
    var x=d.getMonth()+1+'-'+d.getDate();
    if(ArrayContains(holidays1PT, x)) return false;
    x=d.getFullYear()+'-'+x;
    if(ArrayContains(holidays2PT, x)) return false;
    return true;
}

function ArrayContains(a, e) {
    for(i=0;i<a.length;i++){
        if(a[i]==e) return true;
    }
    return false;
}

var bannerIdx = 0;
var bannerCount = 0;
var timerCount = 0;

function loadItems() {
	$('.fp-items .item').hover(
		function () {
			$($(this).children('.content').get(0)).stop().animate({top:'-93px'}, 200, 'linear', function() {});
		},
		function () {
			$($(this).children('.content').get(0)).stop().animate({top:'0'}, 200, 'linear', function() {});
		}
	).click(function() {
		top.window.location.href =$(this).find('.content .more a').attr('href');
	});
}

function loadBanners() {
	bannerCount = $('#banners .banner').length;
	bannerIdx = 0;
	
	if (bannerCount > 1) {
		showBanner(+1);
	} else {
		$('#banners div.banner:eq(0)').fadeIn(300);
	}
}

function showBanner(increase) {
	$('#banners div.banner:eq(' + bannerIdx + ')').fadeOut(300);
            
	bannerIdx = (bannerIdx + increase + bannerCount) % bannerCount;
          		                 
	$('#banners div.banner:eq(' + bannerIdx + ')').fadeIn(300, function() {   
		timerCount++;      
  		$.timer(10000, function() {
  			if(timerCount == 1) {
				showBanner(+1);
			}
			timerCount--;
		});            
	});
}

function SearchSwitcher(type) {
	quickSearch.hideAll();

	switch (type) {
		case 0:
			quickSearch.showItem('arr_dest_container');
			quickSearch.showItem('dates');
			quickSearch.ServiceCategoryID = 0;
			quickSearch.searchType = 'Standard';
			quickSearch.setUrls('Hotels|Passengers|Services|Payment|Receipt');
			break;
		case 2:
			quickSearch.showItem('arr_dest_container');
			quickSearch.showItem('dates');
			quickSearch.searchType = 'Standard';
			quickSearch.setUrls('Passengers|Services|Payment|Receipt');
			break;
		case 3:
			quickSearch.showItem('arr_dest_container');
			quickSearch.showItem('dates');
			quickSearch.searchType = 'Standard';
			quickSearch.setUrls('Passengers|Services|Payment|Receipt');
			break;
		case 4:
			quickSearch.showItem('arr_dest_container');
			quickSearch.showItem('dates');
			quickSearch.ServiceCategoryID = 0;
			quickSearch.searchType = 'Standard';
			quickSearch.setUrls('Cars|Passengers|Services|Payment|Receipt');
			break;
		case 5:
			quickSearch.showItem('arr_dest_container');
			quickSearch.showItem('srvcat_container');
			quickSearch.showItem('dates');
			quickSearch.ServiceCategoryID = 0;
			quickSearch.searchType = 'Standard';
			quickSearch.setUrls('Cars|Passengers|Services|Payment|Receipt');
			break;
		case 6:
			quickSearch.showItem('dep_dest_container');
			quickSearch.showItem('arr_dest_container');
			quickSearch.showItem('dep_flight_dates');
			quickSearch.showItem('arr_flight_dates');
			quickSearch.ServiceCategoryID = 0;
			quickSearch.setUrls('Flights|Passengers|Payment|Receipt');
			quickSearch.searchType = 'Departures';
			$('qs_departure_destination_id').addEvent('change', loadDates);
			$('qs_arriving_destination_id').addEvent('change', loadDates);
			break;
		case 7:
			quickSearch.showItem('dep_dest_container');
			quickSearch.showItem('arr_dest_container');
			quickSearch.showItem('dep_flight_dates');
			quickSearch.showItem('arr_flight_dates');
			quickSearch.ServiceCategoryID = 0;
			quickSearch.searchType = 'Departures';
			quickSearch.setUrls('Flights|Hotels|Cars|Passengers|Services|Payment|Receipt');
			$('qs_departure_destination_id').addEvent('change', loadDates);
			$('qs_arriving_destination_id').addEvent('change', loadDates);
			break;
		case 8:
		    quickSearch.showItem('pkg_cats');
		    quickSearch.showItem('pkg_items');
		    quickSearch.ServiceCategoryID = 0;
			quickSearch.searchType = 'Packages';
			quickSearch.setUrls('Package|Passengers|Payment|Receipt');
	}
}

HotelSelection = function() {
	this.init();
}
$.extend(HotelSelection.prototype, {
	init: function() {
		this.hotels = new Array();
		this.maxPrice = 0;
		this.minPrice = 0;
		this.minStars = 1;
		this.maxStars = 5;
	},
	add: function(id, maxPrice, minPrice, stars) {
	    this.hotels[this.hotels.length] = {
			id: id,
			max: maxPrice,
			min: minPrice,
			stars: stars,
			show: true
		};
	},
	showLoader: function() {
		jQuery('#hotel_loader').height(jQuery('.hotel-search-results').height()).fadeIn(100);
	},
	filter: function() {
	    this.showLoader();
		this.maxPrice = parseInt($('#price_to').val());
		this.minPrice = parseInt($('#price_from').val());
		this.maxStars = parseInt($('#stars_to').val());
		this.minStars = parseInt($('#stars_from').val());
		
		var filteredItemCounter = 0;

		jQuery.each(this.hotels, function() {
		    var hide = true;

			// STARS:
		    if (parseInt(this.stars) >= parseInt(hotels.minStars) && parseInt(this.stars) <= parseInt(hotels.maxStars)) {
				hide = false;
			}

			// PRICE:
			 if (parseInt(this.min) <= parseInt(hotels.maxPrice) && parseInt(this.max) >= parseInt(hotels.minPrice) ) {
       } else {
          hide = true;
       }
			
			if (hide) {
				jQuery('.hotel-id-' + this.id).addClass('hidden');
			} else {
				jQuery('.hotel-id-' + this.id).removeClass('hidden');
				filteredItemCounter++;
			}
		});
		
		this.setCounter(filteredItemCounter);
		$('#hotel_loader').delay(1000).height($('.hotel-search-results').height()).fadeOut(400);
	},
	setCounter: function(itemCount) {
	  if( parseInt(itemCount) != parseInt(this.hotels.length) ) {
	    $('#filterCounter').html (itemCount + ' hotels out of ' + this.hotels.length + ' shown.');
      if (parseInt(itemCount) == 0) {
        $('#allFilteredOut').removeClass('hidden')
      } else {
        $('#allFilteredOut').addClass('hidden')
      }
    } else {
      $('#filterCounter').html ();
      $('#allFilteredOut').addClass('hidden')
    }
  }
});

function validatePassengerForm() {
	var ret = true;

	$('input.el-req').each(function() {
		$('.field-row input.el-req').bind('keyup blur', inputValidator);

		if ($(this).val().length <= 1) {
			$(this).addClass('invalid');
			if ($('#' + this.id + ' + span').length == 0) {
				$('<span>' + $(this).attr('error') + '</span>').addClass('invalid').appendTo(this.parentNode);
			}

			if (ret) {
				ret = false;
			}
		}
	});
	
	return ret;
}

var inputValidator = function validateInput(ev) {
	$(this).removeClass('invalid');

	if ($(this).val().length <= 1) {
		$(this).addClass('invalid');
		if ($('#' + this.id + ' + span').length == 0) {
			$('<span>' + $(this).attr('error') + '</span>').addClass('invalid').appendTo(this.parentNode);
		}
	} else {
		$('#' + this.id + ' + span').remove();
	}
}

function SetPageName(name) {
	$('#page_name_or_prefix').html(name);
	$('a.set-page-name').html(name);
}

function LoadHotelPriceQuote(ownerInfo, hotelID, path) {
	$("#cp_datepicker_from").datepicker({
		showOn: 'both',
		buttonImage: '/templates/eco/images/date_picker_btn.gif',
		buttonImageOnly: true,
		numberOfMonths: 2,
		showAnim: 'fadeIn',
		dateFormat: 'yy-mm-dd',
		minDate: new Date(),
		maxDate: DateAdd(new Date(), 365),
		onSelect: function(dateText, inst) { checkInHotelChanged(dateText, inst);}
	});
	$("#cp_datepicker_to").datepicker({
		showOn: 'both',
		buttonImage: '/templates/eco/images/date_picker_btn.gif',
		buttonImageOnly: true,
		numberOfMonths: 2,
		showAnim: 'fadeIn',
		dateFormat: 'yy-mm-dd',
		minDate: new Date(),
		maxDate: DateAdd(new Date(), 365),
		onSelect: function(dateText, inst) { checkOutHotelChanged(dateText, inst); }
	});

	var c = $.cookieJar('ODIN-BOOKING-DATA', {
		path: '/',
		expires: 7,
		cookiePrefix: ''
	});

	if (!(c.get('owner_id') == undefined)) {
	    $("#cp_datepicker_from").val(c.get('departure_date'));
	    $("#cp_datepicker_to").val(c.get('arrival_date'));
		$('#cp_adult_count').val(c.get('adult_count'));
		$('#cp_child_count').val(c.get('child_count'));
		$('#cp_infant_count').val(c.get('infant_count'));

		GetHotelPriceQuote(ownerInfo, hotelID, path);
	}
}

var thumbCount = 0;
var thumbIndex = 0;

function LoadHotelSlideShow() {    
	thumbCount = $('.thumb-list .list a').length;
	var current = 0;
        
	$('.thumb-list .list a').each(function() {
		if ($(this).hasClass('master')) {
			thumbIndex = current;
		}	
		current++;
	});

	$('.thumbs a.prev').click(function() {
		this.blur();
		if (thumbIndex > 0) {
			thumbIndex = thumbIndex - 1;
			MoveThumbs(false);
		} else {
			thumbIndex = thumbCount - 1;
			MoveThumbs(false);
		}
		return false;
	});
	
	$('.thumbs a.next').click(function() {
		this.blur();
		if (thumbIndex < (thumbCount - 1)) {
			thumbIndex = thumbIndex + 1;
			MoveThumbs(false);
		} else {
			thumbIndex = 0;
			MoveThumbs(false);
		}
		return false;
	});
	
	$('.thumb-list .list a').click(function() {
		this.blur();
		thumbIndex = parseInt($(this).attr('pos')) - 1;
		MoveThumbs(false);
		return false;
	});    
	
	$('.thumb-list .list a img').each(function( i, item){
		if( $(item).height() > 100 )
		{
			var top = ($(item).height() - 100) / 2;
			$(item).css("margin-top", -top);
		}
	});

	MoveThumbs(true);
}

function MoveThumbs(isFirst) {
	if (!isFirst) {}

	$('#thumb_list').animate({
		left: ((124 * thumbIndex * -1) + 165) + 'px'
	}, 200, 'swing', function() {
       	ShowHotelImage();
	});
}

function ShowHotelImage() {
	$('.img-frame .img img.selected').hide();
	$('.img-frame .img img').removeClass('selected');
	$('.loading-img').hide();
	$('.img-frame .img img:eq(' + thumbIndex + ')').addClass('selected').show();
}

function SendContactForm(path) {
	if ($("#SearchResultsForm").valid()) {
		$('.con-form .btn img').show();
		var qs = 'i_subject=Subject&i_to=net@ecoviagens.pt';

		$('.con-form input, .con-form select, .con-form textarea').each(function() {
			qs += '&' + $(this).attr('id') + '=' + $(this).val();
		});

		if ($('#signup:checked').length > 0) {
			qs += '&signup=yes';
		} else {
			qs += '&signup=no';
		}

		$.post('/Modules/Forms/Submit.aspx', qs, function(r) {
			top.window.location.href = path;
		});
	}
}

function SendEmploymentForm() {
	if ($("#SearchResultsForm").valid()) {
		$('.emp-form .btn img').show();
		var qs = 'i_subject=Subject&i_to=net@ecoviagens.pt';
	
		$('.emp-form input, .emp-form select, .emp-form textarea').each(function() {
			qs += '&' + $(this).attr('id') + '=' + $(this).val();
		});
	
		$.post('/Modules/Forms/Submit.aspx', qs, function(r) {
			top.window.location.href = '/EcoViagens/Recrutamento/Obrigado/';
		});
	}
}

function DoSimpleBooking(nextUrl,lang) {

	$('#btn_container_bank').removeClass('book-now');
	$('#btn_container_bank').addClass('more-link');
    
    var postURL = "/Modules/Odin/SimpleBooking_EN.aspx";
    
    if (lang == 'pt') {
        postURL = "/Modules/Odin/SimpleBooking.aspx";
    }                         
    
    var cb = $('.terms input')[0];
    if (!cb.checked) {
		alert(ol_PaymentTermsNotAgreed);
		return false;
	}
		
	if ($("#SearchResultsForm").valid()) {

		var qs = 'name=' + $('#customer_first_name').val() + '+' + $('#customer_last_name').val();
			qs += '&idnumber=' + $('#customer_phone_work').val();
			qs += '&address=' + $('#customer_address').val();
			qs += '&city=' + $('#customer_city').val();
			qs += '&zipcode=' + $('#customer_zipcode').val();
			qs += '&country=' + $('#customer_country').val();
			qs += '&email=' + $('#customer_email').val();
			qs += '&telephone=' + $('#customer_phone_home').val();
       		
        $.post(postURL, qs, function(r) {
			top.window.location.href = nextUrl + r + '/';
		});
 	}
 	
    $('#btn_container_bank').addClass('book-now');
    $('#btn_container_bank').removeClass('more-link');
}

var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};

