function makeArray(n) {
this.length = n;
return this;
}
//
// global declarations and initialization
//
function init () {
theDate         = new Date();
today           = new Date();
currMonth       = today.getMonth();
msPerDay        = 24*60*60*1000;
cookieString    = "dispMonth="+currMonth+";";
document.cookie = cookieString;
startOfString   = document.cookie.indexOf("dispMonth");
countbegin      = document.cookie.indexOf("=",startOfString) + 1;
countend        = document.cookie.indexOf(";",countbegin);
if (countend == -1) {
countend = document.cookie.length;
}
dispMonth     = eval ("document.cookie.substring(countbegin,countend)");
firstOfMonth  = new Date(today.getYear(),dispMonth,1);
monthName = new Array("","Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь");
}
//
// entry point
//


function openCalendar (monthFldName, dateFldname,monthFldName1, dateFldname1,formNumber) {
init();
formNum  = formNumber;
//NQF: begin
//added to accept LHS variable of this type : arr(x)
for (var j=0; j< document.forms[formNum].length; j++) {

if(document.forms[formNum].elements[j].name != null && document.forms[formNum].elements[j].name != undefined)
{
    if ( document.forms[formNum].elements[j].name.toLowerCase() == monthFldName.toLowerCase()) 
    {
    monthFld = "elements["+j+"]";
    dispMonth=document.forms[formNum].elements[j].selectedIndex;
    }


if ( document.forms[formNum].elements[j].name.toLowerCase() == dateFldname.toLowerCase() ) {
dateFld = "elements["+j+"]";
}

if(monthFldName1!=''){
if ( document.forms[formNum].elements[j].name.toLowerCase() == monthFldName1.toLowerCase()) {
monthFld1 = "elements["+j+"]";
} }else{
monthFld1 = '';

}

if(dateFldname1!=''){
if ( document.forms[formNum].elements[j].name.toLowerCase() == dateFldname1.toLowerCase() ) {
dateFld1 ="elements["+j+"]";
} }else{
dateFld1 ='';
}
}

}
//NQF: end
windowOptions  = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=yes,width=275,height=290";
calendarWindow = this.open("","calendarWindow",windowOptions);
calendarWindow.callingForm = this;
redraw(-1);
}
//
// repaint the calendar
//
function redraw(increment) {
calendarWindow.callingForm = this;
//Y2K Browser compatibility issues. getYear() function works for IE.. but had to be
//altered to appear correctly for Netscape. 
if (navigator.appName =='Netscape' || navigator.appName.indexOf("Opera")>=0) {
newYear = today.getYear();
newYear = 1900 + newYear;
}
else {  newYear = today.getYear();
}
var tmpDate = new Date();
tmpDate.setMonth(dispMonth);
if ( tmpDate.getTime() < today.getTime() )
newYear++;
firstOfMonth = new Date(newYear,dispMonth,1);
//End Y2K Browser fix. 
calendarWindow.document.open();
calTitle = "<TITLE>.res [ календарь ]<\/TITLE>";


calendarWindow.document.write(calTitle);
drawCalendar(firstOfMonth);
calendarWindow.document.write(htmlBuffer);
calendarWindow.document.close();
calendarWindow.callingForm = this;
//calendarWindow.focus();
if (increment == 1) {
	calendarWindow.document.forms[0].monthUp.focus();
}else {
	calendarWindow.document.forms[0].monthDn.focus();
}

}
//
// fill the calling forms date and month
//
function fillDate(filler) {
var m = monthNum-1;
var d = filler-1;
eval("document.forms[" + formNum + "]." + monthFld + ".selectedIndex=" + m);
eval("document.forms[" + formNum + "]." + dateFld  + ".selectedIndex=" + d);

if(monthFld1!='')
eval("document.forms[" + formNum + "]." + monthFld1 + ".selectedIndex=" + m);

/*if(dateFld1!='')
eval("document.forms[" + formNum + "]." + dateFld1  + ".selectedIndex=" + d);*/

calendarWindow.close();
}
//
// set the month
//
function changeMonth (increment) {
nextMonth = dispMonth;
if (increment == 1) {
nextMonth++;
} else {
nextMonth--;  
}
if (nextMonth == 12)
   nextMonth = 0;
if (nextMonth == -1)
   nextMonth = 11;
dispMonth = nextMonth;
document.cookie="dispMonth="+nextMonth;
redraw(increment);

}
//
// generate the calendar document
//
function drawCalendar (theDate) {
monthNum = theDate.getMonth() + 1;
htmlBuffer  = "<HTML><BODY BGCOLOR=#ffffff><FORM>";

htmlBuffer += "<CENTER><table border=0 cellpadding=0 cellspacing=0 bgcolor=#ffffff><tr><td><TABLE BORDER=0 cellpadding=3 cellspacing=1><TH COLSPAN=7 bgcolor=#d1dff9><table width=100% border=0 cellpadding=4 cellspacing=0><tr><td><INPUT TYPE=BUTTON NAME=monthDn VALUE=\"<<\" onClick=callingForm.changeMonth(-1)>";
htmlBuffer += "<TH width=100% align=center> "+monthName[monthNum];
// getYear returns the year in year - 1900
// this causes ugly display
var tempYear = theDate.getYear()
if ( tempYear <= 1900 ) {
tempYear += 1900;
}
htmlBuffer += " " + tempYear;
htmlBuffer += "<TH align=right><INPUT TYPE=BUTTON NAME=monthUp VALUE=\">>\" onClick=callingForm.changeMonth(1)></table><TR>";
htmlBuffer += "<TH bgcolor=#445acf><FONT COLOR=#ffffff>Вс</FONT><TH bgcolor=#445acf><FONT COLOR=#ffffff>Пн</FONT><TH bgcolor=#445acf><FONT COLOR=#ffffff>Вт</FONT><TH bgcolor=#445acf><FONT COLOR=#ffffff>Ср</FONT><TH bgcolor=#445acf><FONT COLOR=#ffffff>Чт</FONT><TH bgcolor=#445acf><FONT COLOR=#ffffff>Пт</FONT><TH bgcolor=#445acf><FONT COLOR=#ffffff>Сб</FONT><TR>";
drawBody(theDate);
htmlBuffer += "<\/TABLE></td></tr></table><\/BODY><\/HTML>";
}
//
// generate the calendar body
//
function drawBody (theDate) {
//a fix for DST problem
theDate.setHours(11);
theDate.setMinutes(30);
thisMonth = theDate.getMonth();
thisDate  = theDate.getDate();
firstSunday(theDate);
for (w=0; w<6; w++) {
for (d=0; d<7; d++) {
date = theDate.getDate();
htmlBuffer   += "<TD ALIGN=CENTER bgcolor=#f1f1f1>";
// skip previous month
if (theDate.getMonth() != thisMonth) {
htmlBuffer += "<BR>";
} else {
htmlBuffer += "<INPUT TYPE=BUTTON NAME="+date+" VALUE=";
if ( date < 10 ) {
htmlBuffer += "0";
}
htmlBuffer += date+" onClick=callingForm.fillDate(" + date + ")>";
}
// increment the date
newTime = theDate.getTime() + msPerDay;
theDate.setTime(newTime);

}
htmlBuffer += "<TR>";
}
htmlBuffer += "<\/FORM>";
}
//
// reset the startdate to get the
// previous sunday before the current date
// so that the drawing can begin from a sunday
//
function firstSunday (fromDate) {
while (fromDate.getDay() != 0) {
newTime = fromDate.getTime() - msPerDay;
fromDate.setTime(newTime);
}
}


function fSubmit1(sFormName, sAction){

	flightScheduleWin=window.open("https://cat.sabresonicweb.com/meridia?page="+document.forms[sFormName].page1.value+"&posid="+document.forms[sFormName].posid1.value+"&action="+document.forms[sFormName].action1.value+"&departCity="+document.forms[sFormName].departCity1.value+"&depDay="+document.forms[sFormName].depDay1.value+"&depMonth="+document.forms[sFormName].depMonth1.value+"&depTime="+document.forms[sFormName].depTime1.value+"&destCity="+document.forms[sFormName].destCity1.value+"&Airline="+document.forms[sFormName].Airline.value+"&language="+document.forms[sFormName].language.value,'flightScheduleWin',"toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=670,height=500,alwaysRaised=yes,dependent=yes");	
	
	flightScheduleWin.focus();
	// window.open("https://ww3.dotres.com/meridia?posid="+document.forms[sFormName].posid.value+"&action="+document.forms[sFormName].action.value+"&page="+document.forms[sFormName].page.value+"&language="+document.forms[sFormName].language.value+"&realRequestAir="+document.forms[sFormName].realRequestAir.value+"&departCity="+document.forms[sFormName].departCity.value+"&returnCity="+document.forms[sFormName].returnCity.value+"&classService="+document.forms[sFormName].classService.value+"&direction="+dd+"&flightType="+document.forms[sFormName].flightType.value+"&depDay="+document.forms[sFormName].depDay.value+"&depMonth="+document.forms[sFormName].depMonth.value+"&depTime="+document.forms[sFormName].depTime.value+"&retDay="+document.forms[sFormName].retDay.value+"&retMonth="+document.forms[sFormName].retMonth.value+"&retTime="+document.forms[sFormName].retTime.value+"&ADT="+document.forms[sFormName].ADT.value+"&CHD="+document.forms[sFormName].CHD.value+"&IFS="+document.forms[sFormName].IFS.value+"&INF="+document.forms[sFormName].INF.value+"&actionType="+ss); -->
//	document.forms[sFormName].submit(); 
}


function fSubmitD1(sForm, sAction)
{

	if(document.forms[sForm].departCity1.value == "")
	{
		alert("Не заполнено обязательное поле \"Откуда\"");
		return;
	}
	if(document.forms[sForm].destCity1.value == "")
	{
		alert("Не заполнено обязательное поле \"Куда\"");
		return;
	}

	fSubmit1(sForm,sAction);
}


function fSubmitDReis(sForm, sAction)
{

	if(document.forms[sForm].flight.value == "")
	{
		alert("Не заполнено обязательное поле \"Номер рейса\"");
		return;
	}

	fSubmitReis(sForm,sAction);
}

function fSubmitReis(sFormName, sAction){

	flightScheduleWin=window.open("https://cat.sabresonicweb.com/meridia?page="+document.forms[sFormName].page1.value+"&posid="
									+document.forms[sFormName].posid1.value+"&action="+document.forms[sFormName].action1.value
									+"&flight="+document.forms[sFormName].flight.value+"&depDay="+document.forms[sFormName].depDay1.value
									+"&depMonth="+document.forms[sFormName].depMonth1.value+"&Airline="+document.forms[sFormName].airline.value+"&language="+document.forms[sFormName].language.value,'flightInfoWin',"toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=670,height=500,alwaysRaised=yes,dependent=yes");	
	
	flightScheduleWin.focus();
}

//https://ww3.dotres.com/meridia?page=flightScheduleMessage_learn&posid=93E7&action=flightSchedule&departCity=ROV&depDay=18&depMonth=MAY&depTime=anytime&destCity=MOW&Airline=D9
//-->


// add functions to auto update the date selections to prevent a user
// from attempting to book flights out of sequence

// initialize the date

		
var now = new Date();
var depmonthnumber = now.getMonth();
var retmonthnumber = now.getMonth();
var monthday    = now.getDate();
var year        = now.getYear();
var defaultDepart = '2';
	
			var defaultReturn = '3';
	//vars for the configurable date advance set in SAT
//var defaultDepart;
//var defaultReturn;
	
// is this a leap year
function leapYear(theYear) { 
	if ( ((theYear % 4 == 0) && (theYear % 100 != 0)) || (theYear % 400 == 0) ) { 
		return true; 
	} else { 
		return false;
	} 
} 


function updateReturnDate(formName) {
// create new date objects just in case
	var d = new Date(); 
	var dYear = d.getFullYear(); 
	var dMonth = formName.depMonth.selectedIndex; 
	var dDay = formName.depDay.selectedIndex; 
	var today = new Date(); 
    // set the return day and month currently selected to variables
	var rDy = formName.retDay.selectedIndex; 
	var rMon =formName.retMonth.selectedIndex;
     // get the year
	var rYr = d.getFullYear(); 
	// for next year if the return month is numerically less than the 
	//current month then add 1 year
	
	if (formName.retMonth.selectedIndex < d.getMonth())
	{ 
		rYr = rYr+1; 
	} 
    // for next year same as above only for departure
	if (formName.depMonth.selectedIndex < d.getMonth())
	{ 
		dYear = dYear+1; 
	} 
	rDate = new Date(rYr, rMon, rDy); 
	dDate = new Date(dYear, dMonth, dDay+defaultDepart);
	var rYear = dYear; 
	var rMonth = '0'; 
	var rDay = '0'; 
	// 30 Days: April-3 June-5 September-8 November-10 
	// 31 Days: January-0, March-2, May-4, July-6, August-7, October-9, December-11 
	// 28 Days: February-1 
	// For Months with 31 days 
	
	if ( (dMonth == '0' || dMonth == '2' || dMonth == '4' || dMonth == '6' || dMonth == '7' || dMonth == '9' || dMonth == '11' )){ 
		if (dDay == '29') { 
			rDay = '0'; 
// If December, set month back to '0' for January
		if (dMonth == '11') { 
			rMonth = '0'; 
		} else { 
			rMonth = dMonth + 1; 
		} 
	} else if (dDay == '30') { 
	rDay = '1'; 
// If December, set month back to '0' for January
		if (dMonth == '11') { 
			rMonth = '0'; 
		} else { 
			rMonth = dMonth + 1; 
		} 
	} else { 
		rDay = dDay + 2; 
		rMonth = dMonth; 
	} 			
       // For Months with 30 days
			} else if ((dMonth == '3' || dMonth == '5' || dMonth == '8' || dMonth == '10' )) { 
             /* test for invalid dates */
				if (dDay == '30') { 
					dDay = '30'; eval (formName.depDay.selectedIndex = dDay); 
				} 
				if (dDay == '28' || dDay == '29') { 
					rDay = '0'; 
					rMonth = dMonth + 1; 
				} else if (dDay == '30') { 
					rDay = '1'; 
					rMonth = dMonth + 1; 
				} else { 
					rDay = dDay + 2; 
					rMonth = dMonth; 
				} 
				// For February, check for leapyear.

			} else if (dMonth == '1') { 
				if (dMonth > rMonth) { rYear += 1; } 
                  // Check to see if Feb 29, 30, or 31 is selected for NON-leapyear. 
			      // If so, set departure date to Feb 28. 
			

				if ((!leapYear(rYear) && dDay == '28') || dDay == '29' || dDay == '30') { 
					dDay = dDay; eval (formName.depDay.selectedIndex = dDay); 
				} 
				if ((leapYear(rYear) && dDay == '27') || (!leapYear(rYear) && dDay == '26') || dDay ==29 ) { 
					rDay = '0'; rMonth = dMonth + 1; 
				} else if ((leapYear(rYear) && dDay == '28') || (!leapYear(rYear) && dDay == '27') || dDay == '30' || (!leapYear(rYear) && dDay == '28')) { 
				rDay = '1'; 
				rMonth = dMonth + 1; 
				} else { 
					rDay = dDay + 2; 
					rMonth = dMonth; 
				} 
			} 
        //check to see if on different page
		if(formName.dateChanged != null && formName.dateChanged.value == 'true') return; 
		if(formName.retDay.changed == null && formName.changed == null){ 
			eval (formName.retDay.selectedIndex = rDay); 
		} 
		if( formName.retMonth.changed == null && formName.changed == null){ 
			eval (formName.retMonth.selectedIndex = rMonth); 
		} 
		return; 
} 


/*function fSubmit(sFormName, sAction){
	if (sAction!="" && document.forms[sFormName].elements["hidAction"]){
		document.forms[sFormName].elements["hidAction"].value = sAction;
	}
	document.forms[sFormName].submit(); 
}*/


function checkDate(sForm, sField){
	var dNow = new Date();
	
	//var dToday = new Date ((navigator.appName.indexOf("Netscape")>=0?dNow.getYear()+1900:dNow.getYear()),dNow.getMonth(),dNow.getDate());
	// compare not against Today but against (Today - 5 month)
	var dToday;
	if(dNow.getMonth() > 5)
		dToday = new Date ((navigator.appName.indexOf("Netscape")>=0?dNow.getYear()+1900:dNow.getYear()),dNow.getMonth()-1,dNow.getDate());
	else
		dToday = new Date ((navigator.appName.indexOf("Netscape")>=0?dNow.getYear()+1900:dNow.getYear())-1,dNow.getMonth()+7,dNow.getDate());


	lstDay = document.forms[sForm].elements[sField+'Day'];
	lDay = lstDay.selectedIndex + 1;
	lstMonth = document.forms[sForm].elements[sField+'Month'];
	lMonth = lstMonth.selectedIndex + 1;
	hidYear = 'year';
	var lYear = parseInt(navigator.appName.indexOf("Netscape")>=0?dNow.getYear()+1900:dNow.getYear());
	dDate = new Date(lYear,lMonth-1,lDay);
	if (dDate < dToday){
		dDate = new Date(lYear+1,lMonth-1,lDay);
	}

	lstDay.selectedIndex = dDate.getDate()-1;
	lstMonth.selectedIndex = dDate.getMonth();
	hidYear.value = (navigator.appName.indexOf("Netscape")>=0?dDate.getYear()+1900:dDate.getYear());
}


function fSubmit(sFormName, sAction){
	var ss;
	var dd;
	if (sAction!="" && document.forms[sFormName].elements["hidAction"]){
		document.forms[sFormName].elements["hidAction"].value = sAction;
	}

//	alert(document.forms[sFormName].actionType.length);
	if (document.forms[sFormName].actionTypeS.value!="" || document.forms[sFormName].actionTypeS.value!="undefined"){
		ss = document.forms[sFormName].actionTypeS.value;
	} else {
		for(i=0; i<document.forms[sFormName].actionType.length; i++)
		{
			if (document.forms[sFormName].actionType[i].checked)
				{
					ss = document.forms[sFormName].actionType[i].value;
				}
		}
	}
	for(i=0; i<document.forms[sFormName].direction.length; i++)
	{
			if (document.forms[sFormName].direction[i].checked)
				{
					dd = document.forms[sFormName].direction[i].value;
				}
	}
	 window.open("https://cat.sabresonicweb.com/meridia?posid="+document.forms[sFormName].posid.value+"&action="+document.forms[sFormName].action.value+"&page="+document.forms[sFormName].page.value+"&language="+document.forms[sFormName].language.value+"&realRequestAir="+document.forms[sFormName].realRequestAir.value+"&departCity="+document.forms[sFormName].departCity.value+"&returnCity="+document.forms[sFormName].returnCity.value+"&classService="+document.forms[sFormName].classService.value+"&direction="+dd+"&flightType="+document.forms[sFormName].flightType.value+"&depDay="+document.forms[sFormName].depDay.value+"&depMonth="+document.forms[sFormName].depMonth.value+"&depTime="+document.forms[sFormName].depTime.value+"&retDay="+document.forms[sFormName].retDay.value+"&retMonth="+document.forms[sFormName].retMonth.value+"&retTime="+document.forms[sFormName].retTime.value+"&ADT="+document.forms[sFormName].ADT.value+"&CHD="+document.forms[sFormName].CHD.value+"&IFS="+document.forms[sFormName].IFS.value+"&INF="+document.forms[sFormName].INF.value+"&actionType="+ss+"&utm_source="+document.forms[sFormName].utm_source.value+"&utm_medium="+document.forms[sFormName].utm_medium.value+"&utm_content="+document.forms[sFormName].utm_content.value+"&utm_campaign="+document.forms[sFormName].utm_campaign.value);
//	document.forms[sFormName].submit(); 
}


function fSubmitStr(sFormName, sAction){
	var ss;
	var dd;
	if (sAction!="" && document.forms[sFormName].elements["hidAction"]){
		document.forms[sFormName].elements["hidAction"].value = sAction;
	}

//	alert(document.forms[sFormName].actionType.length);
	for(i=0; i<document.forms[sFormName].actionType.length; i++)
	{
			if (document.forms[sFormName].actionType[i].checked)
				{
					ss = document.forms[sFormName].actionType[i].value;
				}
	}

	for(i=0; i<document.forms[sFormName].direction.length; i++)
	{
			if (document.forms[sFormName].direction[i].checked)
				{
					dd = document.forms[sFormName].direction[i].value;
				}
	}
	 return "https://cat.sabresonicweb.com/meridia?posid="+document.forms[sFormName].posid.value+"&action="+document.forms[sFormName].action.value+"&page="+document.forms[sFormName].page.value+"&language="+document.forms[sFormName].language.value+"&realRequestAir="+document.forms[sFormName].realRequestAir.value+"&departCity="+document.forms[sFormName].departCity.value+"&returnCity="+document.forms[sFormName].returnCity.value+"&classService="+document.forms[sFormName].classService.value+"&direction="+dd+"&flightType="+document.forms[sFormName].flightType.value+"&depDay="+document.forms[sFormName].depDay.value+"&depMonth="+document.forms[sFormName].depMonth.value+"&depTime="+document.forms[sFormName].depTime.value+"&retDay="+document.forms[sFormName].retDay.value+"&retMonth="+document.forms[sFormName].retMonth.value+"&retTime="+document.forms[sFormName].retTime.value+"&ADT="+document.forms[sFormName].ADT.value+"&CHD="+document.forms[sFormName].CHD.value+"&IFS="+document.forms[sFormName].IFS.value+"&INF="+document.forms[sFormName].INF.value+"&actionType="+ss;
//	document.forms[sFormName].submit(); 
}


function fSubmitD(sForm, sAction)
{
	checkDate(sForm,'dep');
	checkDate(sForm,'ret');
/*
alert(document.forms[sForm].dep_year.value);
alert(document.forms[sForm].elements['dep_date'].value);
alert(document.forms[sForm].arr_year.value);
alert(document.forms[sForm].elements['arr_date'].value);
*/
	if(document.forms[sForm].departCity.value == "")
	{
		alert("Не заполнено обязательное поле \"Откуда\"");
		return;
	}
	if(document.forms[sForm].returnCity.value == "")
	{
		alert("Не заполнено обязательное поле \"Куда\"");
		return;
	}
/*
	var nowDate = new Date(2008, 1-1, 22);
	var depDate = new Date(2008, document.forms[sForm].dep_month.value-1, document.forms[sForm].dep_day.value)
	var arrDate = new Date(2008, document.forms[sForm].arr_month.value-1, document.forms[sForm].arr_day.value)

	if((depDate < nowDate) && (Math.abs((document.forms[sForm].dep_month.value % 10)-2) == 1))
	{
		document.forms[sForm].dep_year.value = 2008+1;
	}

	if((arrDate < nowDate) && (Math.abs((document.forms[sForm].arr_month.value % 10)-2) == 1))
	{
		document.forms[sForm].arr_year.value = 2008+1;
	}
*/  
	fSubmit(sForm,sAction);
	//return fSubmitStr(sForm,sAction);
}

function showCouponInputBox(form)  {
}


function childrenDropdownValueChanged() {
		if ($("Children").selectedIndex == 0) {
		$("childDOBTxt").style.display = "none";
//		$("spacerChildDescription").style.display = "none";
		} else {
		$("childDOBTxt").style.display = "block";
//		$("spacerChildDescription").style.display = "block";
		}
		for (i = 1; i <= 4; i++) {
			if (i <= $("Children").selectedIndex) {
				$("childDOB"+i).style.display = "block";
//				$("spacerChildDateBirth"+i).style.display = "block";
				} else {
				$("childDOB"+i).style.display = "none";
//				$("spacerChildDateBirth"+i).style.display = "none";
				}
				}
				$("childDOB").style.display = "block";
				}
function $(obj) {
				try {
				return document.getElementById(obj);
				} catch (e) {}
}
		