top_indent				= 10;
header_height				= 270;
timer_id					= 0;
flight_from_global			= '';
flight_to_global			= '';
avia_company_global		= '';
ticket_type_global			= '';






function debug( debug_string )
{
	document.getElementById('debug_log').innerHTML += debug_string + '<br />';
}


function highlight( target_row , company )
{
	target_row.style.cursor = 'POINTER';
	var children = target_row.childNodes;
	var color = 'nothing';
	
	if ( company == 'aeroflot' ) color = '#c2c2c2'
	else if ( company == 'thai' ) color = '#c3a6cd'
	else if ( company == 'klm' ) color = '#e5f5ff'
	else if ( company == 'lufthansa' ) color = '#ffe29e'
	else if ( company == 's7' ) color = '#e0ffb4'
	else if ( company == 'austrian' ) color = '#94cbef'
	else if ( company == 'transaero' ) color = '#e0e7f1'
	else if ( company == 'germanwings' ) color = '#e1e1e1'
	else if ( company == 'estonianair' ) color = '#3d66a0'
	else if ( company == 'swissair' ) color = '#cccccc'
	else if ( company == 'isic' ) color = '#fff55d'
	else if ( company == 'brussels' ) color = '#ebf3ff'
	else if ( company == 'sas' ) color = '#4f9dc8'
	else if ( company == 'airfrance' ) color = '#e4ecf1'
	else if ( company == 'britishairways' ) color = '#eaecf5'
	else if ( company == 'bluewings' ) color = '#d2deef'
	else if ( company == 'clickair' ) color = '#f1f9fb'
	else if ( company == 'singapore' ) color = '#a2a8b1'
	else if ( company == 'niki' ) color = '#a6b5d6'
	else if ( company == 'alitalia' ) color = '#c8c8c8'
	else if ( company == 'malev' ) color = '#58b73c'
	else if ( company == 'finnair' ) color = '#e2eff7'
	else if ( company == 'flylal' ) color = '#dae5f8'
	else if ( company == 'qatar' ) color = '#e0abc7'
	else if ( company == 'delta' ) color = '#839db4'
	else if ( company == 'japan' ) color = '#d1d1d1'
	else if ( company == 'emirates' ) color = '#e5e5e5'
	else if ( company == 'iberia' ) color = '#f5f5f5'
	else if ( company == 'etihad' ) color = '#000000'
	else if ( company == 'airmauritius' ) color = '#d4e584'
	else if ( company == 'american' ) color = '#d6e2f0'
	else if ( company == 'thai' ) color = '#c0acd3'
	else if ( company == 'korean' ) color = '#8eb998'
	else if ( company == 'pulkovo' ) color = '#f4f4f4'
	else if ( company == 'airbaltic' ) color = '#eeeeee'
	else if ( company == 'qantas' ) color = '#f7f7f7'
	else if ( company == 'turkish' ) color = '#e8e5d2'
	else if ( company == 'airchina' ) color = '#eeeef0'
	
	for ( var i = 0 ; i < children.length ; i++ )
	{
		if ( children[i].nodeName == 'TD' )
			children[i].style.backgroundColor = color;
	}
}


function unhighlight( target_row )
{
	var children = target_row.childNodes;
	for ( var i = 0 ; i < children.length ; i++ )
	{
		if ( children[i].nodeName == 'TD' )
			children[i].style.backgroundColor = 'transparent';
	}
}


function fill_order_form()
{
	document.getElementById('flight_from').value = flight_from_global;
	document.getElementById('flight_to').value = flight_to_global;
	//document.getElementById('adult_tickets').selectedIndex = 1;
	//document.getElementById('adult_tickets').options[1].selected = true;
	document.getElementById('comments').value = 'Íåîáõîäèì áèëåò ïî ';
	if ( action_type_global != '' ) 
	{
		document.getElementById('comments').value += action_type_global;
	}
	else
	{
		document.getElementById('comments').value += 'ñïåöèàëüíîé àêöèè';
	}
	document.getElementById('comments').value += ' êîìïàíèè ' + avia_company_global + '.\n';
	//show_tooltip();	
}


function flight_selected( flight_from , flight_to , avia_company , ticket_type , action_type )
{
	panel = document.getElementById('order_ticket_panel').style;
	if ( panel.paddingTop == '' )
		panel.paddingTop = '0px';
	
	flight_from_global = flight_from;
	flight_to_global = flight_to;
	avia_company_global = avia_company;
	ticket_type_global = ticket_type;
	action_type_global = action_type;
	
	var target_position = 0;
	if ( window.scrollY > header_height )
		target_position = window.scrollY + top_indent;
	var current_position = header_height + parseInt(panel.paddingTop);
	var remain_all = target_position - current_position;
	if ( parseInt(panel.paddingTop) + remain_all < 0 )
		remain_all = 0 - parseInt(panel.paddingTop);
	make_step( remain_all );
}


function make_step( remain )
{
	var step =  ( remain - (remain % 3) ) / 3;
	if ( step == 0 )
	{
		if ( remain < 0 ) step = -1;
		if ( remain > 0 ) step = 1;
	}
	remain_new = remain - step;
	panel.paddingTop = parseInt(panel.paddingTop) + step + 'px';
	if ( remain_new != 0 )
	{
		timer_id = setTimeout("make_step( remain_new )", 50);
	}
	if ( remain_new == 0 )
	{
		timer_id = setTimeout("fill_order_form()", 300);
	}
}


function search_focus( search_bar )
{
	if ( search_bar.value == ' ÏÎÈÑÊ' )
		search_bar.value = '';
}


function search_blur( search_bar )
{
	if ( search_bar.value == '' )
		search_bar.value = ' ÏÎÈÑÊ';
}


function check_search()
{
	search_bar = document.getElementById('search_field');
	if ( search_bar.value == ' ÏÎÈÑÊ' )
	{
		return false;
	}
	else 
	{
		return true;
	}
}






var timer;
var head_top = "null";
var foot_top = "null";
var counter_step = -1;


function play()
{
	counter_step = -1;
}
function pause()
{
	counter_step = 0;
}


function scroll()
{
	try
	{
		var head_height = document.getElementById("scroll_head").offsetHeight;
		var foot_height = document.getElementById("scroll_foot").offsetHeight;
		if ( head_top == "null") head_top = 0;
		if ( foot_top == "null") foot_top = 0 + head_top;
		head_top += counter_step;
		foot_top += counter_step;
		if ( foot_top <= 0 )
		{
			head_top = foot_top + foot_height ;
		}
		if ( head_top <= 0 )
		{
			foot_top = head_top + head_height ;
		}
		document.getElementById("scroll_head").style.top = + head_top + "px";
		document.getElementById("scroll_foot").style.top = + foot_top + "px";
		setTimeout("scroll()", 100);
	}catch(error){}
}


function switch_visible(something)
{
	
	default_state = 'none';
	if ( document.getElementById(something).style.display == '' )
		document.getElementById(something).style.display = default_state;
	if ( document.getElementById(something).style.display == 'none' )
		document.getElementById(something).style.display = 'block';
	else
	if ( document.getElementById(something).style.display == 'block' )
		document.getElementById(something).style.display = 'none';
	
	/*
	default_state = 'hidden';
	if ( document.getElementById(something).style.visibility == '' )
		document.getElementById(something).style.visibility = default_state;
	if ( document.getElementById(something).style.visibility == 'hidden' )
		document.getElementById(something).style.visibility = 'visible';
	else
	if ( document.getElementById(something).style.visibility == 'visible' )
		document.getElementById(something).style.visibility = 'hidden';
	*/
}


function show_tooltip()
{
	document.getElementById('tooltip').style.visibility = 'visible';
}
