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;
//alert(document.forms[formNum].name);
//alert(formNum);
//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=330,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=300 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 style=\"width:80%;\" 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) {}
}


function NumForm(NameForm) {
	for (var n=0; n < document.forms.length; n++) {		
		if (NameForm == document.forms[n].name) {return n;}
	}
}

function putCookieBron() {
	var $$ = jQuery.noConflict();

	$$.cookie("departCity", $$("select[name='departCity'] option:selected").val(),{ expires: 30 }); //alert(s);
	$$.cookie("returnCity", $$("select[name='returnCity'] option:selected").val(),{ expires: 30 });
	$$.cookie("direction", $$("input:radio[name='direction']:checked").val(),{ expires: 30 });
	//alert($$("input:radio[name='direction']:checked").val());
	$$.cookie("depDay", $$("select[name='depDay'] option:selected").val(),{ expires: 30 });
	$$.cookie("depMonth", $$("select[name='depMonth'] option:selected").val(),{ expires: 30 });
	$$.cookie("retDay", $$("select[name='retDay'] option:selected").val(),{ expires: 30 });
	$$.cookie("retMonth", $$("select[name='retMonth'] option:selected").val(),{ expires: 30 });
	$$.cookie("ADT", $$("select[name='ADT'] option:selected").val(),{ expires: 30 });
	$$.cookie("CHD", $$("select[name='CHD'] option:selected").val(),{ expires: 30 });
	$$.cookie("IFS", $$("select[name='IFS'] option:selected").val(),{ expires: 30 });
	$$.cookie("INF", $$("select[name='INF'] option:selected").val(),{ expires: 30 });	
	$$.cookie("departCity1", $$("select[name='departCity1'] option:selected").val(),{ expires: 30 });
	$$.cookie("destCity1", $$("select[name='destCity1'] option:selected").val(),{ expires: 30 });
	$$.cookie("depDay1", $$("select[name='depDay1'] option:selected").val(),{ expires: 30 });
	$$.cookie("depMonth1", $$("select[name='depMonth1'] option:selected").val(),{ expires: 30 });
}


function getCookieBron() {
	var $$ = jQuery.noConflict();

	if ( $$.cookie('departCity') != null ) $$("select[name='departCity']").val($$.cookie('departCity'));
	if ( $$.cookie('returnCity') != null ) $$("select[name='returnCity']").val($$.cookie('returnCity'));
	//if ( $$.cookie('direction') != null ) $$("input:radio[name='direction'] value='onewaytravel'").attr("checked", "checked");
	//$$("input[name='direction']").val($$.cookie('direction'));//.attr("checked", "checked");
		//$$("input[name='direction']").attr("checked", "checked");
	if ( $$.cookie('direction') != null ) {		
		$$("input[name='direction']").each(function(){
			if ( $$(this).val() == $$.cookie('direction') ) $$(this).attr("checked", "checked");
			//else $$(this).attr("checked", "");
		});
	}

	$$("input[name='direction'] value='onewaytravel'").attr("checked", "checked");
	if ( $$.cookie('depDay') != null ) $$("select[name='depDay']").val($$.cookie('depDay'));
	if ( $$.cookie('depMonth') != null ) $$("select[name='depMonth']").val($$.cookie('depMonth'));
	if ( $$.cookie('retDay') != null ) $$("select[name='retDay']").val($$.cookie('retDay'));
	if ( $$.cookie('retMonth') != null ) $$("select[name='retMonth']").val($$.cookie('retMonth'));
	if ( $$.cookie('ADT') != null ) $$("select[name='ADT']").val($$.cookie('ADT'));
	if ( $$.cookie('CHD') != null ) $$("select[name='CHD']").val($$.cookie('CHD'));
	if ( $$.cookie('IFS') != null ) $$("select[name='IFS']").val($$.cookie('IFS'));
	if ( $$.cookie('INF') != null ) $$("select[name='INF']").val($$.cookie('INF'));
	
	if ( $$.cookie('departCity1') != null ) $$("select[name='departCity1']").val($$.cookie('departCity1'));
	if ( $$.cookie('destCity1') != null ) $$("select[name='destCity1']").val($$.cookie('destCity1'));
	if ( $$.cookie('depDay1') != null ) $$("select[name='depDay1']").val($$.cookie('depDay1'));
	if ( $$.cookie('depMonth1') != null ) $$("select[name='depMonth1']").val($$.cookie('depMonth1'));

}


function fSubmitAeroflot(sFormName,utm_param_afl){
var dd;
var f; 
var ss;

	f = document.getElementById(sFormName);

	for(i=0; i<f.direction.length; i++)
	{
			if (f.direction[i].checked)
				{
					dd = f.direction[i].value;
				}
	}


	ss = "https://booking.aeroflot.ru/meridia?mode=booking&action=airRequest&page=requestAirMessage_air&"
									+"realRequestAir=realRequestAir&rem1=aeroflotmain&rem2=&rem3=&rem4=&rem5=&kiosk=0&posid=7B47&geoCountry=ru"
									+"&language="+f.lang_aeroflot.value+"&departCity="
									+f.departCity.value+"&returnCity="+f.returnCity.value
									+"&classService="+f.classService.value+"&direction="+dd+"&flightType="
									+f.flightType.value+"&depDay="+f.depDay.value
									+"&depMonth="+f.depMonth.value+"&depTime="+f.depTime.value
									+"&retDay="+f.retDay.value+"&retMonth="+f.retMonth.value
									+"&retTime="+f.retTime.value+"&ADT="+f.ADT.value
									+"&CHD="+f.CHD.value+"&IFS="+f.IFS.value+"&INF="
									+f.INF.value+"&actionType=nonFlex&YTH=0&ok=1&utm_source=d9_donavia&utm_medium=d9_donavia&utm_content=d9_donavia&utm_campaign=d9_donavia";

	flightScheduleWin=window.open("http://www.aeroflot-don.ru/aeroflot_bron.aspx?"+utm_param_afl+"&url="+encodeURIComponent(ss));
	flightScheduleWin.focus();
}


function fSubmitBron(sFormName,utm_param_afl,lang){

var f; 
var message_ru;
 message_ru = new Array('Не заполнено обязательное поле "Откуда"','Не заполнено обязательное поле "Куда"');
var message_en;
 message_en = new Array('The field "From" should be filled!','The field "To" should be filled!');
var message_aeroflot_ru;
 message_aeroflot_ru = "Подтвердите, что Вы ознакомились и согласны с Правилами онлайн бронирования и оплаты авиабилетов авиакомпании Аэрофлот!";	
var message_aeroflot_en;
 message_aeroflot_en = "Please, confirm if you have familiarized with and agree to the Air tickets booking and payment rules on the web-site of Aeroflot.";	
var $$ = jQuery.noConflict();


f = document.getElementById(sFormName);
//alert(f);

	if(f.departCity.value == "")
	{
		eval("alert(message_"+lang+"[0]);");
		return false;
	}
	if(f.returnCity.value == "")
	{
		eval("alert(message_"+lang+"[1]);");
		return false;
	}

//putCookieBron();


/*if (f.returnCity.value == "OMS" || f.departCity.value == "OMS" || 
	f.returnCity.value == "KZN" || f.departCity.value == "KZN" ||
	f.returnCity.value == "KGD" || f.departCity.value == "KGD" ||
	!( $$("select[name='depDay'] option:selected").val() < 30 && $$("select[name='depMonth'] option:selected").val() =="OCT" &&
	   $$("select[name='retDay'] option:selected").val() < 30 && $$("select[name='retMonth'] option:selected").val() =="OCT" ) 
																) {*/

/*		var _gaq = _gaq || []; 
		_gaq.push(['_setAccount', 'UA-4708623-1']); 
		_gaq.push(['_setDomainName', 'none']); 
		_gaq.push(['_setAllowLinker', true]); 
		//_gaq.push(['_setAllowHash', false]); 
		_gaq.push(['_link', 'http://booking.aeroflot.ru']);*/
		if (!f.checkrul.checked)
		{
			eval("alert(message_aeroflot_"+lang+")");
			HideShowElement('#show_afl_rules',1);
			f.checkrul.focus();
			return false;
		}
		fSubmitAeroflot(sFormName,utm_param_afl);					
		return false;
		
//	}

f.submit();

}

function ShowAeroflotRules(city1, city2) {
var str1;
var str2;
var $$ = jQuery.noConflict();

str1 = $$("select[name='"+city1+"'] option:selected").val();
str2 = $$("select[name='"+city2+"'] option:selected").val();
//alert(!( $$("select[name='depMonth'] option:selected").val() == "SEP" && $$("select[name='retMonth'] option:selected").val() == "SEP"));
//alert(str1+" "+str2);
/*if ((str1 != "" && str2 == "OMS") || 
	(str1 == "OMS" && str2 != "") ||
	(str1 != "" && str2 == "KZN") ||
	(str1 == "KZN" && str2 != "") ||
	(str1 != "" && str2 == "KGD") ||
	(str1 == "KGD" && str2 != "")  ||
	!( $$("select[name='depDay'] option:selected").val() < 30 && $$("select[name='depMonth'] option:selected").val() =="OCT" &&
	   $$("select[name='retDay'] option:selected").val() < 30 && $$("select[name='retMonth'] option:selected").val() =="OCT" )
	) {
		$$("#show_afl_rules").show(); 			
	} else {
		if ( $$("#show_afl_rules").is(':visible') ) $$("#show_afl_rules").hide();	 		 
	}*/

if (str1 != "" && str2 != "")  {
		$$("#show_afl_rules").show(); 			
	} else {
		if ( $$("#show_afl_rules").is(':visible') ) $$("#show_afl_rules").hide();	 		 
	}
}


function ShowAeroflotScheduleRules(url_afl_str,utm_param_afl) {
var $$ = jQuery.noConflict();
var url_str;

if ( $$("#show_afl_schedule_rules").is(':hidden') ) 
	if (!document.getElementById('checkrul_sched').checked) $$("#show_afl_schedule_rules").show();

url_str = "http://www.aeroflot-don.ru/aeroflot_bron.aspx?"+utm_param_afl+"&url="+encodeURIComponent(url_afl_str)
if (document.getElementById('checkrul_sched').checked) BronAeroflotFromSchedule(url_str);
$$("input[name='checkrul_sched']").val(url_str);
}




function BronAeroflotFromSchedule(url_str) {
	bronScheduleWin=window.open(url_str);
	bronScheduleWin.focus();
}




function HideShowElement(elem,show) {
var $$ = jQuery.noConflict();

if (show)
{
	if ( $$(elem).is(':hidden') ) $$(elem).show();	
} else {
	if ( $$(elem).is(':visible') ) $$(elem).hide();	
}
return;
}


function AutoComplete(lang) {
var message_ru;
 message_ru = new Array('введите город или страну','Показать все города');
var message_en;
 message_en = new Array('enter city or country','Show all cities');

var $$ = jQuery.noConflict();
	(function( $$ ) {
		$$.widget( "ui.combobox", {
			_create: function() {
				var self = this,
					select = this.element.hide(),
					selected = select.children( ":selected" ),
					value = selected.val() ? selected.text() : "";
				var input = this.input = $$( "<input>" )
					.insertAfter( select )
					.val( value )
					.attr( "title", eval("message_"+lang+"[0]") )
					.focus(function(){    // получение фокуса текстовым полем							
					        $$(this).select();
					})
					.autocomplete({
						delay: 0,
						minLength: 0,
						source: function( request, response ) {
							var matcher = new RegExp( $$.ui.autocomplete.escapeRegex(request.term), "i" );
							response( select.children( "option" ).map(function() {
								var text = $$( this ).text();
								if ( this.value && ( !request.term || matcher.test(text) ) )
									return {
										label: text.replace(
											new RegExp(
												"(?![^&;]+;)(?!<[^<>]*)(" +
												$$.ui.autocomplete.escapeRegex(request.term) +
												")(?![^<>]*>)(?![^&;]+;)", "gi"
											), "<strong>$1</strong>" ),
										value: text,
										option: this
									};
							}) );							
						},
						select: function( event, ui ) {
							ui.item.option.selected = true;
							self._trigger( "selected", event, {
								item: ui.item.option
							});							
							//$$("select[name='departCity']").val();
							//alert(  (ui.item.value).substr((ui.item.value).indexOf('(')+1,3) );
							select.val((ui.item.value).substr((ui.item.value).indexOf('(')+1,3) );
							//alert($$("select[name='departCity']").val() + '' + $$("select[name='returnCity']").val());
							ShowAeroflotRules('departCity','returnCity');
							//alert(  input.data( "autocomplete" ).term);
							 //input.select();
							 input.focus();
						},						
						change: function( event, ui ) {
							if ( !ui.item ) {
								var matcher = new RegExp( "^" + $$.ui.autocomplete.escapeRegex( $$(this).val() ) + "$", "i" ),
									valid = false;
								select.children( "option" ).each(function() {
									if ( $$( this ).text().match( matcher ) ) {
										this.selected = valid = true;
										return false;
									}
								});
								if ( !valid ) {
									// remove invalid value, as it didn't match anything
									$$( this ).val( "" );
									select.val( "" );
									input.data( "autocomplete" ).term = "";
									return false;
								}
							}
						}
					})
					.addClass( "ui-widget ui-widget-content inp1" );

				input.data( "autocomplete" )._renderItem = function( ul, item ) {
					return $$( "<li></li>" )
						.data( "item.autocomplete", item )
						.append( "<a>" + item.label + "</a>" )
						.appendTo( ul );
				};

				this.button = $$( "<button type='button'>&nbsp;</button>" )
					.attr( "tabIndex", -1 )
					.attr( "title", eval("message_"+lang+"[1]") )
					.insertAfter( input )
					.button({
						icons: {
							primary: "ui-icon-triangle-1-s"
						},
						text: false
					})
					.removeClass( "ui-corner-all" )
					.addClass( "ui-corner-right ui-button-icon" )
					.click(function() {
						// close if already visible
						if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
							input.autocomplete( "close" );
							return;
						}

						// work around a bug (likely same cause as #5265)
						$$( this ).blur();

						// pass empty string as value to search for, displaying all results
						input.autocomplete( "search", "" );
						input.focus();
					});
			},

			destroy: function() {
				this.input.remove();
				this.button.remove();
				this.element.show();
				$$.Widget.prototype.destroy.call( this );
			}
		});
	})( jQuery );
}
