//ESKY APP PUBLIC
/**
 * The first two numbers in the century to be used when decoding a two digit year. Since a two digit year is ambiguous (and date.setYear
 * only works with numbers < 99 and so doesn't allow you to set years after 2000) we need to use this to disambiguate the two digit year codes.
 *
 * @name format
 * @type String
 * @cat Plugins/Methods/Date
 * @author Kelvin Luck
 */
Date.fullYearStart = '20';

(function() {

	/**
	 * Adds a given method under the given name
	 * to the Date prototype if it doesn't
	 * currently exist.
	 *
	 * @private
	 */
	function add(name, method) {
		if( !Date.prototype[name] ) {
			Date.prototype[name] = method;
		}
	};

	/**
	 * Checks if the year is a leap year.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.isLeapYear();
	 * @result true
	 *
	 * @name isLeapYear
	 * @type Boolean
	 * @cat Plugins/Methods/Date
	 */
	add("isLeapYear", function() {
		var y = this.getFullYear();
		return (y%4==0 && y%100!=0) || y%400==0;
	});

	/**
	 * Checks if the day is a weekend day (Sat or Sun).
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.isWeekend();
	 * @result false
	 *
	 * @name isWeekend
	 * @type Boolean
	 * @cat Plugins/Methods/Date
	 */
	add("isWeekend", function() {
		return this.getDay()==0 || this.getDay()==6;
	});

	/**
	 * Check if the day is a day of the week (Mon-Fri)
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.isWeekDay();
	 * @result false
	 *
	 * @name isWeekDay
	 * @type Boolean
	 * @cat Plugins/Methods/Date
	 */
	add("isWeekDay", function() {
		return !this.isWeekend();
	});

	/**
	 * Gets the number of days in the month.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDaysInMonth();
	 * @result 31
	 *
	 * @name getDaysInMonth
	 * @type Number
	 * @cat Plugins/Methods/Date
	 */
	add("getDaysInMonth", function() {
		return [31,(this.isLeapYear() ? 29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()];
	});

	/**
	 * Gets the name of the day.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDayName();
	 * @result 'Saturday'
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDayName(true);
	 * @result 'Sat'
	 *
	 * @param abbreviated Boolean When set to true the name will be abbreviated.
	 * @name getDayName
	 * @type String
	 * @cat Plugins/Methods/Date
	 */
	add("getDayName", function(abbreviated) {
		return abbreviated ? Date.abbrDayNames[this.getDay()] : Date.dayNames[this.getDay()];
	});

	/**
	 * Gets the name of the month.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getMonthName();
	 * @result 'Janurary'
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getMonthName(true);
	 * @result 'Jan'
	 *
	 * @param abbreviated Boolean When set to true the name will be abbreviated.
	 * @name getDayName
	 * @type String
	 * @cat Plugins/Methods/Date
	 */
	add("getMonthName", function(abbreviated) {
		return abbreviated ? Date.abbrMonthNames[this.getMonth()] : Date.monthNames[this.getMonth()];
	});

	/**
	 * Get the number of the day of the year.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDayOfYear();
	 * @result 11
	 *
	 * @name getDayOfYear
	 * @type Number
	 * @cat Plugins/Methods/Date
	 */
	add("getDayOfYear", function() {
		var tmpdtm = new Date("1/1/" + this.getFullYear());
		return Math.floor((this.getTime() - tmpdtm.getTime()) / 86400000);
	});

	/**
	 * Get the number of the week of the year.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getWeekOfYear();
	 * @result 2
	 *
	 * @name getWeekOfYear
	 * @type Number
	 * @cat Plugins/Methods/Date
	 */
	add("getWeekOfYear", function() {
		return Math.ceil(this.getDayOfYear() / 7);
	});

	/**
	 * Set the day of the year.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.setDayOfYear(1);
	 * dtm.toString();
	 * @result 'Tue Jan 01 2008 00:00:00'
	 *
	 * @name setDayOfYear
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("setDayOfYear", function(day) {
		this.setMonth(0);
		this.setDate(day);
		return this;
	});

	/**
	 * Add a number of years to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addYears(1);
	 * dtm.toString();
	 * @result 'Mon Jan 12 2009 00:00:00'
	 *
	 * @name addYears
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addYears", function(num) {
		this.setFullYear(this.getFullYear() + num);
		return this;
	});

	/**
	 * Add a number of months to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addMonths(1);
	 * dtm.toString();
	 * @result 'Tue Feb 12 2008 00:00:00'
	 *
	 * @name addMonths
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addMonths", function(num) {
		var tmpdtm = this.getDate();

		this.setMonth(this.getMonth() + num);

		if (tmpdtm > this.getDate())
			this.addDays(-this.getDate());

		return this;
	});

	/**
	 * Add a number of days to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addDays(1);
	 * dtm.toString();
	 * @result 'Sun Jan 13 2008 00:00:00'
	 *
	 * @name addDays
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addDays", function(num) {
		this.setDate(this.getDate() + num);
		return this;
	});

	/**
	 * Add a number of hours to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addHours(24);
	 * dtm.toString();
	 * @result 'Sun Jan 13 2008 00:00:00'
	 *
	 * @name addHours
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addHours", function(num) {
		this.setHours(this.getHours() + num);
		return this;
	});

	/**
	 * Add a number of minutes to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addMinutes(60);
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 01:00:00'
	 *
	 * @name addMinutes
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addMinutes", function(num) {
		this.setMinutes(this.getMinutes() + num);
		return this;
	});

	/**
	 * Add a number of seconds to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addSeconds(60);
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 00:01:00'
	 *
	 * @name addSeconds
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addSeconds", function(num) {
		this.setSeconds(this.getSeconds() + num);
		return this;
	});

	/**
	 * Sets the time component of this Date to zero for cleaner, easier comparison of dates where time is not relevant.
	 *
	 * @example var dtm = new Date();
	 * dtm.zeroTime();
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 00:01:00'
	 *
	 * @name zeroTime
	 * @type Date
	 * @cat Plugins/Methods/Date
	 * @author Kelvin Luck
	 */
	add("zeroTime", function() {
		this.setMilliseconds(0);
		this.setSeconds(0);
		this.setMinutes(0);
		this.setHours(0);
		return this;
	});

	/**
	 * Returns a string representation of the date object according to Date.format.
	 * (Date.toString may be used in other places so I purposefully didn't overwrite it)
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.asString();
	 * @result '12/01/2008' // (where Date.format == 'dd/mm/rrrr'
	 *
	 * @name asString
	 * @type Date
	 * @cat Plugins/Methods/Date
	 * @author Kelvin Luck
	 */
	add("asString", function() {
		var r = Date.format;
		return r
			.replace(/(yyyy|rrrr)/i, this.getFullYear())
			.replace(/(yy|rr)/i, (this.getFullYear()+'').substring(2))
			.replace(/mmm/i, this.getMonthName(true))
			.replace(/mm/i, _zeroPad(this.getMonth()+1))
			.replace(/dd/i, _zeroPad(this.getDate()));
	});

	/**
	 * Returns a new date object created from the passed String according to Date.format or false if the attempt to do this results in an invalid date object
	 * (We can't simple use Date.parse as it's not aware of locale and I chose not to overwrite it incase it's functionality is being relied on elsewhere)
	 *
	 * @example var dtm = Date.fromString("12/01/2008");
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 00:00:00' // (where Date.format == 'dd/mm/rrrr'
	 *
	 * @name fromString
	 * @type Date
	 * @cat Plugins/Methods/Date
	 * @author Kelvin Luck
	 */
	Date.fromString = function(s)
	{
		if(!s) return new Date();

		var f = Date.format;
		var d = new Date('01/01/1977');
		var iY = f.indexOf('rrrr');
		if (iY > -1) {
			d.setFullYear(Number(s.substr(iY, 4)));
		} else {
			// TODO - this doesn't work very well - are there any rules for what is meant by a two digit year?
			d.setFullYear(Number(Date.fullYearStart + s.substr(f.indexOf('rr'), 2)));
		}
		var iM = f.indexOf('mmm');
		if (iM > -1) {
			var mStr = s.substr(iM, 3);
			for (var i=0; i<Date.abbrMonthNames.length; i++) {
				if (Date.abbrMonthNames[i] == mStr) break;
			}
			d.setMonth(i);
		} else {
			d.setMonth(Number(s.substr(f.indexOf('mm'), 2)) - 1);
		}
		d.setDate(Number(s.substr(f.indexOf('dd'), 2)));
		if (isNaN(d.getTime())) {
			return false;
		}
		return d;
	};

	// utility method
	var _zeroPad = function(num) {
		var s = '0'+num;
		return s.substring(s.length-2);
		//return ('0'+num).substring(-2); // doesn't work on IE :(
	};

})();
function getDateFormat(date) {
	var dd = date.getDate();
	var mm = date.getMonth() + 1; // styczen jest 0
	var yyyy = date.getFullYear();

	if(dd<10) { dd = '0' + dd; }
	if(mm<10) { mm = '0' + mm; }

	return yyyy + '-' + mm + '-' + dd;
}
Date.format = 'rrrr-mm-dd';

/**
 * Function for creating a cookie
 * @param {Object} name
 * @param {Object} value
 * @param {Object} days
 */
function createCookie(name,value,time) {
	if (time) {
		var date = new Date();
		date.setTime(date.getTime() + time);
		var expires = "; expires=" + date.toGMTString();
	}
	else {
		var expires = "";
	}
	document.cookie = "esky_"+name+"="+escape(value)+expires+"; path=/";
}
/**
 * Function for reading a cookie.
 * @param {Object} name
 */
function readCookie(name) {
	var nameEQ = "esky_" + name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') {
			c = c.substring(1, c.length);
		}
		if (c.indexOf(nameEQ) === 0) {
			return unescape(c.substring(nameEQ.length, c.length));
		}
	}
	return null;
}
function eraseCookie(name) {
	createCookie("esky_"+name,"",-1);
}

var startDate = null;
var endDate = null;
var insurance_xhr = null;
var Insurances = {
		Calculate: function(){

			$qsf = $('#travel-insurances-qsf');

			if($qsf.valid() && $("#travel-insurances-qsf:visible").length) {

				if (insurance_xhr) insurance_xhr.abort();
				insurance_xhr = $.ajax({
					url: $('.qsf-insurance #recalculate').attr('href'),
					method: "post",
					data: $('.qsf-insurance').serialize(),
					dataType: "json",
					beforeSend: function(){
						if(($('#travel-insurances-qsf').valid() && $('#Value-Flight').data('focused')) || ($('[name=InsuranceType]:checked').val() == 'full')) {
							$('#InsurancePrice').removeClass('error').addClass('calculating').html('<p><img src="common/images/travel/ajax-loader-small.gif">Trwa wycena ubezpieczenia</p>');
						}
					},
					success: function(data){
						if(($('#travel-insurances-qsf').valid() && $('#Value-Flight').data('focused')) || ($('[name=InsuranceType]:checked').val() == 'full')) {
							if (data != null) {
								if (typeof data.requestStatus != "undefined" && data.requestStatus == true) {

									html = '<p>' + TXT_Insurance_value  + '<b>' + data.price[14].Amount + '&nbsp;<span>' + data.price[14].Currency + '</span></b></p>';
									html_class = '';
								} else {
									html = '<b>Nie można wycenić usługi.</b>Sprawdź poprawność wypełnionych pól.';
									html_class = 'error';
								}
							} else {
								html = '<b>Nie można wycenić usługi.</b>Sprawdź poprawność wypełnionych pól.';
								html_class = 'error';
							}
							$('#InsurancePrice').removeClass('calculating').addClass(html_class).html(html);
						}
						$('#travel-insurances-qsf').valid();
					}
				});
			}
		},
		Datepicker : {
			minDate: '+1d',
			maxDate: '+365d',
			beforeShow: function() {
                startDate = $('#StartDate').datepicker('getDate');
                endDate = $('#EndDate').datepicker('getDate');

				if (this.name == 'StartDate') {
					if ($('[name=InsuranceType]:checked').val()=='ticket'){
						return { minDate: '-2d', maxDate: '0d' };
					} else {
						return { minDate: '+1d', maxDate: '+365d' };
					}
				} else if (this.name == 'EndDate') {
					var _previous_date = $('#StartDate').datepicker('getDate');

					if ($('[name=InsuranceType]:checked').val() != 'ticket') {
						return (_previous_date instanceof Date) ? {
							minDate: new Date(Date.parse(_previous_date) + 1 * 24 * 60 * 60 * 1000) //Add 1 days to checkin date
						} : {};
					} else {
						var today = new Date();
						today.setDate(today.getDate() + 1);

						return { minDate: today };
					}
				} else {
					return {};
				}
			},
            beforeShowDay: function(date) {
                // Highlight dates range
                if (startDate != null && endDate != null && $('[name=InsuranceType]:checked').val()!='ticket') {
                    if (date >= startDate && date <= endDate) {
                        return [true, 'highlight-date'];
                    }
                }

                return [true, ''];
            },
			onSelect: function(dateText, inst){
				if (this.name == 'StartDate') {
					var thisDate = $(this).datepicker('getDate');
					var nextDate = $('#EndDate').datepicker('getDate');

					if ((thisDate instanceof Date && thisDate >= nextDate) || !nextDate instanceof Date) {
						thisDate.setMilliseconds(thisDate.getMilliseconds() + 7 * 24 * 60 * 60 * 1000);
						$('#EndDate').datepicker('setDate', thisDate);
					}
				}

				$(this).trigger('change');
			}
		}
	};


jQuery.fn.InsuranceSearchForm = function(settings){
	var f 		= $(this);
	var Dates 	= $('#StartDate,#EndDate',f);
	var Config 	= (typeof settings === 'object') ? settings : Insurances;

	$('#Value-Flight').data('focused', false);

	Dates.datepicker(Config.Datepicker);

	$("#InsuredCount").change(function(){
		if ($("[name=InsuranceType]:checked",f).val() == "ticket") {
			if ($(this).val() > 1) {
				$('#InsuranceValue',f).text(TXT_Insurance_ticketsValue);
			} else {
				$('#InsuranceValue',f).text(TXT_Insurance_ticketValue);
			}
		}
	});

	$('[name=InsuranceType]',f).click(function(){
		$('#InsuranceInfo-ticket',f).hide();

		var insuranceType = $(this).val();
		var insuranceLink = '?ptype={ptype}&stype={stype}&sellType=standalone';
		var insuranceLinkValues = {
			'ptype': {
				'full': 1,
				'ticket': 2
			},
			'stype': {
				'full': 'full',
				'ticket': 'ticket'
			}
		};

		Dates.each(function(){
			$(this).siblings('div:first').text('');
		});

		$('.insurance-documents a').each(function(){
			var url = String($(this).attr('href')).replace(/\?.+$/, '') +
			String(insuranceLink).replace('{ptype}', insuranceLinkValues['ptype'][insuranceType]).replace('{stype}', insuranceLinkValues['stype'][insuranceType]);
			$(this).attr('href', url);
		});

		$('[name=InsuranceType]').closest('label').removeClass('bold');

		$(this).closest('label').addClass('bold');

		switch(insuranceType){
			default:
			case 'full':
				$('#InsuranceValue',f).text(TXT_Insurance_currency);
				$('#EndDate-label').remove();
				$('#StartDate-label').remove();
				$('label[for=InsuredCountLabel]').text('Osób do ubezpieczenia');
				$('#Value-Flight').hide();
				var today = new Date();
				if($('#StartDate').datepicker('getDate') < today) {
					$('#StartDate').datepicker('setDate', today);

				}
				$("#label-datepicker-dates").text(TXT_Insurance_datesRange);
				break;
			case 'ticket':
				if ($("#InsuredCount").val() > 1) {
					$('#InsuranceValue',f).text(TXT_Insurance_ticketsValue);
				} else {
					$('#InsuranceValue',f).text(TXT_Insurance_ticketValue);
				}

				$('#InsuranceInfo-ticket',f).show();
				$('label[for=InsuredCountLabel]').text('Ile biletów?');
				$('#Value-Flight').show();
				$("#label-datepicker-dates").html("<span>" + TXT_Insurance_ticketsBuyDate + "</span><span>" + TXT_Insurance_departureDate + "</span>");
				break;
		}
		$("#StartDate").change();

	}).filter(':checked'); // Initialize;

	$('input, select',f).change(Insurances.Calculate);

	$('#InsuranceType-ticket').unbind('change').change(function(){
		if($('#Value-Flight').data('focused') && $('#travel-insurances-qsf').valid()){
			Insurances.Calculate();
		} else {
			$('#InsurancePrice').html('');
			return true;
		}
	});

	$('#Value-Flight').unbind('change').keyup(function(){
		setTimeout(Insurances.Calculate, 800);
	});

	$('#Value-Flight').focus(function(){
		$(this).data('focused', true);
	});

    // Prevent user from entering date or some other characters manually
    $('#travel-insurances-qsf #StartDate').keypress(function() {
        return false;
    });
    $('#travel-insurances-qsf #EndDate').keypress(function() {
        return false;
    });

    $("#travel-insurances-qsf").submit(function (e) {
    	$('#Value-Flight').focus();
    	$('#travel-insurances-qsf').valid();
		if ($("#InsurancePrice").hasClass("error") || $("#InsurancePrice").hasClass("calculating") || !$("#InsurancePrice").html()) {
			e.preventDefault();
		}
	});
};

jQuery.validator.addMethod("float", function(value, element) {
	return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:(,|\.)\d+)?$/.test(value);
}, "Float");

jQuery.fn.extend({
	saveQuery: function(formId,days,number){
		var cookieId = (formId) ? formId : $(this).attr('id');
		var number = (number) ? number : 0;

		var cookie = readCookie(cookieId);

		if (cookie) {
			cookie=cookie.split(";");
		} else {
			cookie = new Array();
		}

		var queryString = cookieId;
		$('input[type="text"],input[type="hidden"].hidden,select,input[type="radio"]:checked,input[type="checkbox"]:checked',$(this))
		.not(':disabled,.dynamic')
		.each(function(){
			var val = $(this).val();
			if (typeof val != 'undefined' && val != '') {
				queryString += '|' + $(this).attr('type') + ':' + $(this).attr('name') + '=' + val;
			}
		});

		for (var i=0;i<number;i++) {
			if (typeof cookie[i] == "undefined") {
				cookie[i] = '';
			}
		}

		cookie[number] = queryString;

		if (typeof cookie[1] == "undefined") {
			cookie = cookie[0];
		} else {
			cookie = cookie.join(';');
		}

		createCookie(cookieId,cookie,days);
	},
	loadQuery: function(formId,field, number){
		var cookieId = (formId) ? formId : $(this).attr('id');
		var cookie = readCookie(cookieId);
		var number = (number) ? number : 0;
		if (cookie) {
			cookie = cookie.split(';');

			cookie = cookie[number];

			if (cookie) {

				var fields = cookie.split('|');
				for (i in fields) {
					var a = String(fields[i]).split(':');
					if(a[1]) var b = a[1].split('='); else continue;
					if(field && field!=b[0]) continue;
					switch(a[0]) {
						case 'radio':
						case 'checkbox':
							$('input[name="' + b[0] + '"][value="' + b[1] + '"]', $(this)).attr('checked','checked');
							break;
						case 'text':
						case 'hidden':
							$input = $('input[name="' + b[0] + '"]', $(this));
							if(b[1]!='' && b[1]!=$input.val() && $input.hasClass('virgin')){
								$input.removeClass('virgin');
							}
							//wartości przesyłane z DBRa są escapowane - więc trzeba unescapować (adamp)
							//(podwójnie gdyż pierwszy escape zmienia utf-owe krzaki na zapis typu: \u00xx
							//- natomiast drugi to escape znaków typowych np: \, spacja)
							var unescapedValue = unescape(unescape(b[1]));
							$input.val(unescapedValue);
							break;
						default:
							$('select[name="' + b[0] + '"]', $(this)).val(b[1]).change();
							break;
					}
				}
				return true;
			}

		}
		return false;
	}
});

/* ONLOAD */
$(document).ready(function(){
	$('#travel-insurances-qsf').InsuranceSearchForm();
	if ($('#travel-insurances-qsf').length > 0) {
		$('#travel-insurances-qsf').validate({
			errorClass: "error",
			errorPlacement: function(error, element) {
			     return false;
			},
			rules: {
				'Value[Flight]': {
					required: function(element) {
						return (($('#InsuranceType-full:checked').length > 0) || !$(element).data('focused')) ? false : true;
			        },
			        float: {
                        depends: function(element) {
			        		return ($('#InsuranceType-full:checked').length > 0) ? false : true;
                        }
			        },
			        min: 0
				}
			},
			messages: {
				'Value[Flight]': {
					required: 'Prosimy o uzupełnienie pola <b>ile biletów</b>'
				}
			},
			success: function(label) {

			},
			highlight: function(element, errorClass) {
				$("label#InsuranceValue").addClass("insurances-error");
				$(element).addClass("error").removeClass("valid");
			},
			unhighlight: function(element, errorClass) {
				$("label#InsuranceValue").removeClass("insurances-error");
				$(element).removeClass("error").addClass("valid");
			}
		});

	}
	$('#InsuranceType-full').click();
	Insurances.Calculate();

	$('#StartDate').change(function(){
		var o = $('#EndDate');

		var today = new Date();
		today.setHours('0');
		today.setMinutes('0');
		today.setSeconds('0');
		today.setMilliseconds('0');

		var dateStart = new Date.fromString($(this).attr('value'));
		var dateEnd = new Date.fromString($('#EndDate').attr('value'));

		if ($("#Value-Flight:visible").length) {
			today.addDays(-2);
		}

		if(dateStart < today) {
			$('#StartDate').attr('value', getDateFormat(today));
			today.setDate(today.getDate() + 7);
			$('#EndDate').attr('value', getDateFormat(today));
			return false;
		}

		if ($("#Value-Flight:visible").length) {
			if (dateStart > today.addDays(+2)) {
				$('#StartDate').attr('value', getDateFormat(today));
				today.setDate(today.getDate() + 7);
				$('#EndDate').attr('value', getDateFormat(today));
				return false;
			}
		} else {
			if (dateStart > today.addYears(+1)) {
				$('#StartDate').attr('value', getDateFormat(today));
				today.setDate(today.getDate() + 7);
				$('#EndDate').attr('value', getDateFormat(today));
				return false;
			}
		}

		if(((dateStart >= dateEnd) && (!isNaN(dateStart)) || isNaN(dateEnd))) {
			dateStart.setDate(dateStart.getDate()+7);
			$('#EndDate').attr('value', getDateFormat(dateStart));
		}

		if (dateEnd > dateStart.addYears(+1)) {
			$('#EndDate').attr('value', getDateFormat(dateStart.addDays(-1)));
		}

		return false;
	});

	$('#EndDate').change(function(){
		$('#StartDate').trigger('change');
		return false;
	});




});

