function setIframeSize(width,height){
	var iframe = document.getElementById('booking-iframe');
	iframe.style.width  = width+"px";
	iframe.style.height = height+"px";
}

function setCalendarDate(target, day, month, year) {
	//alert(target+": "+day+"."+month+"."+year);
	
	
	if(target=="h"){
		var monthInWeek = month;
		var dayInWeek = 1*(day)+7;
		var yearInWeek = year;
		if(dayInWeek>31) {
			dayInWeek -= 31;
			monthInWeek++;
		}
		if(monthInWeek>12) {
			monthInWeek -= 12;
			yearInWeek++;
		}
		
		if(dayInWeek.length<2) dayInWeek = "0"+dayInWeek;
		if(monthInWeek.length<2) monthInWeek = "0"+monthInWeek;
		
		updateForm('fastbooking_form','r_day',dayInWeek);
		updateForm('fastbooking_form','r_month',monthInWeek);
		updateForm('fastbooking_form','r_year',yearInWeek);
	}
	
	if(day.length<2) day = "0"+day;
	if(month.length<2) month = "0"+month;
	
	updateForm('fastbooking_form', target+'_day',day);
	updateForm('fastbooking_form', target+'_month',month);
	updateForm('fastbooking_form', target+'_year',year);
	
	tt_HideInit();
	
	// show form fields again in IE
	if (document.getElementById('WzClOsE').attachEvent){
		showHideDateFields(true);
	//	document.getElementById('WzClOsE').removeEvent("onclick");
	}
	
}

function showCalendar(target, title, language)
{
	
	Tip('<div id="calendar">loading calendar...</div>', TITLE, title, DELAY, 700, STICKY, true, CLICKCLOSE, false, CLOSEBTN, true, CLOSEBTNCOLORS, ['#a6d4ec', '#ffffff', '#fe0000', '#ffffff'], BGCOLOR, '', BORDERCOLOR, '#cae7f7', WIDTH, 160, FIX, [150, 00]);
	var calendar = new CalendarJS().init("calendar", target, language);
	
	// hide form fields in IE
	if (document.getElementById('WzClOsE').attachEvent){
		tt_tShow.Timer("showHideDateFields(false)", 700, true);
		document.getElementById('WzClOsE').attachEvent("onclick", showHideDateFields);
	}
	
	return false;
}

function showHideDateFields(show) {

	toggleField('h_month', show);
	toggleField('h_day', show);
	toggleField('h_year', show);
	toggleField('r_month', show);
	toggleField('r_day', show);
	toggleField('r_year', show);
}

function toggleField(name, visible) {
	var el = document.getElementsByName(name)[0];
	el.style.visibility = (visible==false)? "hidden" : "visible";
}

function disableField(name, disable) {
	var el = document.getElementsByName(name)[0];
	el.disabled = (disable==true)? true : false;
	el.style.backgroundColor = (disable==true)? "#dddddd" : "#ffffff";
	el.style.color = (disable==true)? "#dddddd" : "#000000";
}

function disableDestinationFields(disable) {
	disableField('r_month', disable);
	disableField('r_day', disable);
	disableField('r_year', disable);
	toggleField('r_calendar', !disable);
}

function linkToBookingMask(formname, options) {
	if (document[formname])	{
		var fObj = document[formname];
		fObj['mask'].value = "";
		
		if(typeof options == 'object') {
			for(var i in options) {
				setBookingField(formname, i, options[i]);
			}
		}
		fObj.submit();
	}
	return false;
}

function setBookingField(formname, fieldname, value) {
	var fObj = document[formname][fieldname];
	
	switch(fieldname) {
		case 'roundtrip':
			fObj[0].value = value;
			fObj[1].checked=false;
			fObj[2].checked=false;
			break;
		default:
			fObj.value = value;
	}
	
}

function transfer(index) {
    if (document.forms.length == 1) {
        airport = document.forms.Form.airport.value;
        direction = document.forms.Form.direction.value;
    } else {
        airport = document.forms[index - 1].airport.value;
        direction = document.forms[index - 1].direction.value;
    }
	
	
    if (direction == 5) {
       opener.document.getElementById('booking-t_from').value = airport;
	
    } else if (direction == 6) {
        opener.document.getElementById('booking-t_dest').value = airport;
    } 
	
    window.close();
    return true;
}

function linkToBookingMask(formname, options) {
	if (document[formname])	{
		var fObj = document[formname];
		fObj['mask'].value = "";
		
		if(typeof options == 'object') {
			for(var i in options) {
				setBookingField(formname, i, options[i]);
			}
		}
		fObj.submit();
	}
	return false;
}

function setBookingField(formname, fieldname, value) {
	var fObj = document[formname][fieldname];
	
	switch(fieldname) {
		case 'roundtrip':
			fObj[0].value = value;
			fObj[1].checked=false;
			fObj[2].checked=false;
			break;
		default:
			fObj.value = value;
	}
	
}
