var homeUrl = "http://www1.avia.travel.ru/partner/travelru/";
var currDate = new Date();
var outDate = new Date(currDate.getFullYear(),currDate.getMonth(),currDate.getDate() + 1);
var inDate = new Date(outDate.getFullYear(),outDate.getMonth(),outDate.getDate() + 7);
/* begin of miscfunctions */
function trimLeft(str) {
var _len = str.length;
var _i;
var _result = new String(str);
if (_len < 1) {
return _result;
}
for (_i = 0; _i < _len; _i++) {
if ((str.charCodeAt(_i) > 32) || (str.charCodeAt(_i) < -1)) {
break;
}
}
if (_i < 1) {
return _result;
}
_result = _result.substring(_i,_len);
return _result;
}
function trimRight(str) {
var _len = str.length;
var _i;
var _result = new String(str);
if (_len < 1) {
return _result;
}
for (_i = 0; _i < _len; _i++) {
if ((str.charCodeAt(_len - _i - 1) > 32) || (str.charCodeAt(_i) < -1)) {
break;
}
}
if (_i < 1) {
return _result;
}
_result = _result.substring(0,_len - _i);
return _result;
}
function trim(str) {
var _result = trimLeft(str);
if (_result.length > 0) {
_result = trimRight(_result);
}
return _result;
}
function isBlank(str) {
return (trimLeft(str) == "");
}
function getDaysInMonth(month,year) {
if ((month < 1) || (month > 12)) {
return 0;
}
var _daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var _result = _daysInMonth[month - 1];
if ((month == 2) && isLeapYear(year)) {
_result++;
}
return _result;
}
function isInteger(n) {
return (!isNaN(n) && (Math.ceil(n) == Math.floor(n)));
}
function isNatural(n) {
return (isInteger(n) && (n >= 0));
}
function isLeapYear(year) {
if (year % 4 != 0) {
return false;
} else if (year % 400 == 0) {
return true;
} else if (year % 100 != 0) {
return true;
} else {
return false;
}
}
function isCorrectDate(year,month,day) {
if (!isNatural(year) || !isNatural(month) || !isNatural(day)) {
return false;
}
if ((year < 1) || (month < 1) || (month > 12) || (day < 1)) {
return false;
}
var _daysInMonth = getDaysInMonth(month,year);
if (day > _daysInMonth) {
return false;
}
return true;
}
function checkInOutDates(outYear,outMonth,outDay,inYear,inMonth,inDay) {
if (!isCorrectDate(outYear,outMonth,outDay)) {
return "Дата прямого вылета не правильная " + outDay + "-" + outMonth + "-" + outYear;
}
if (!isCorrectDate(inYear,inMonth,inDay)) {
return "Дата обратного вылета не правильная " + inDay + "-" + inMonth + "-" + inYear;
}
var msecPerDay = 24 * 60 * 60 * 1000;
var currDT = new Date();
currDT.setHours(0);
currDT.setMinutes(0);
currDT.setSeconds(0);
currDT.setMilliseconds(0);
var outDT = new Date(outYear,outMonth - 1,outDay);
var inDT = new Date(inYear,inMonth - 1,inDay);
if ((outDT.getTime() - currDT.getTime()) < msecPerDay) {
return "Нельзя выбирать прошедшие или текущую даты " + outDT.getDate() + "-" + (outDT.getMonth() + 1) + "-" + outDT.getYear();
}
if ((inDT.getTime() - outDT.getTime()) < msecPerDay) {
return "Дата обратного вылета должна быть позже даты прямого вылета";
}
if ((outDT.getTime() - currDT.getTime()) >= 331 * msecPerDay) {
return "Можно забронировать не более чем за 331 день до прямого вылета";
}
if ((inDT.getTime() - currDT.getTime()) >= 331 * msecPerDay) {
return "Можно забронировать не более чем за 331 день до обратного вылета";
}
return null;
}
/* end of miscfunctions */
function setBestPrices(value) {
var theForm = document.booking;
//theForm.bestPrices[1].checked = value;
//theForm.bestPrices[0].checked = !value;
}
function outDateChanged(theForm) {
setBestPrices(true);
var outDT = new Date(theForm.outYear.options[theForm.outYear.selectedIndex].value,
theForm.outMonth.options[theForm.outMonth.selectedIndex].value - 1,
theForm.outDay.options[theForm.outDay.selectedIndex].value);
var inDT = new Date(theForm.inYear.options[theForm.inYear.selectedIndex].value,
theForm.inMonth.options[theForm.inMonth.selectedIndex].value - 1,
theForm.inDay.options[theForm.inDay.selectedIndex].value);
var msecPerDay = 24 * 60 * 60 * 1000;
var currDT = new Date();
currDT.setHours(0);
currDT.setMinutes(0);
currDT.setSeconds(0);
currDT.setMilliseconds(0);
if ((outDT.getTime() - currDT.getTime()) < msecPerDay) {
return;
}
if ((inDT.getTime() - outDT.getTime()) >= 7 * msecPerDay) {
return;
}
inDT.setTime(outDT.getTime() + 7 * msecPerDay);
theForm.inYear.selectedIndex = inDT.getFullYear() - theForm.inYear.options[0].value;
theForm.inMonth.selectedIndex = inDT.getMonth();
theForm.inDay.selectedIndex = inDT.getDate() - 1;
}
function doSearch(theForm) {
var startPt = trim(theForm.startPoint.value).toLowerCase();
var endPt = trim(theForm.endPoint.value).toLowerCase();
if (startPt == "") {
alert("Введите пункт вылета");
theForm.startPoint.focus();
return false;
}
if (endPt == "") {
alert("Введите пункт прилёта");
theForm.endPoint.focus();
return false;
}
if (startPt == endPt) {
alert("Пункт вылета не должен совпадать с пунктом прилёта");
theForm.endPoint.focus();
return false;
}
if (theForm.bestPrices[1].checked) {
var datesCheckStr = checkInOutDates(
theForm.outYear.options[theForm.outYear.selectedIndex].value,
theForm.outMonth.options[theForm.outMonth.selectedIndex].value,
theForm.outDay.options[theForm.outDay.selectedIndex].value,
theForm.inYear.options[theForm.inYear.selectedIndex].value,
theForm.inMonth.options[theForm.inMonth.selectedIndex].value,
theForm.inDay.options[theForm.inDay.selectedIndex].value);
if (datesCheckStr != null) {
alert(datesCheckStr);
return false;
}
theForm.outDateStr.value =
theForm.outYear.options[theForm.outYear.selectedIndex].value + ""
+ theForm.outMonth.options[theForm.outMonth.selectedIndex].value + ""
+ theForm.outDay.options[theForm.outDay.selectedIndex].value;
theForm.inDateStr.value =
theForm.inYear.options[theForm.inYear.selectedIndex].value + ""
+ theForm.inMonth.options[theForm.inMonth.selectedIndex].value + ""
+ theForm.inDay.options[theForm.inDay.selectedIndex].value;
}
theForm.command.value = theForm.bestPrices[0].checked ? "searchTariff" : "searchFlight";
showSearchSplash();
return true;
}
