function add_extra(price, room_index, state) {
	var room_price = Math.ceil(byId('room_price_'+room_index).innerHTML);
	var extra_price = Math.ceil(byId('extra_price_'+room_index).innerHTML);
	extra_price = (state) ? extra_price + Math.ceil(price) : extra_price - Math.ceil(price);
	
	byId('show_extra_price_' + room_index).style.display='inline';
	byId('extra_price_'+room_index).innerHTML = extra_price;
	byId('total_price_'+room_index).innerHTML = extra_price + room_price;
}
function del_room(room_index, booking_type) {
	// tools/partner/del_price.php?id=room_index
	// после удаления всех номеров необходимо перекинуть Пользователя на страницу "Цены"
	document.getElementById('room_'+room_index).innerHTML='';
	document.getElementById('room_'+room_index).style.display='none';
	AjaxRequest.send('', '/tools/partner/delete_room_2.php', 'Идёт удаление...', true, {'room_index':room_index,'booking_type':booking_type});
}
function check_form() {
//	if (document.getElementById('type_payment').value == 3) {
//		alert('Укажите форму оплаты');
//		document.getElementById('type_payment').focus();
//		return false;
//	}
//	var customer = document.getElementById('booking').elements['customer'];
//	for(var i=0; i < customer.length; i++) {
//		if (customer[i].checked) {
//			AjaxRequest.send('booking', '/tools/partner/booking_2.php', 'Идёт бронирование...', true, {});
//			return false;
//		}
//	}
//	alert('Укажите главного туриста');
	AjaxRequest.send('booking', '/tools/partner/booking_2.php', 'Идёт бронирование...', true, {});
	var sbm = document.getElementById('submit_button');
	if(sbm) sbm.disabled = true;
	return false;
}
// Поддержка загрузки данных по тайм-ауту (1 секунда после
// последнего отпускания клавиши в текстовом поле).
var timeout = null;
var timeout_tourist = -1;
var timeout_room = -1;
function doLoadUp(tourist, room) {
	timeout_tourist = tourist;
	timeout_room = room;
	if (timeout) clearTimeout(timeout);
	timeout = setTimeout(doLoad, 1000);
}
function no_rooms() {
	document.location.href='/Prices/';	
}
// Вызывается по тайм-ауту или при щелчке на кнопке.
function doLoad() {
	document.getElementById('submit_button').disabled = true;
	AjaxRequest.send('booking', '/tools/partner/clients_2.php', 'Идёт загрузка', true, {'tourist_index':timeout_tourist, 'room_index':timeout_room});
}
// Загружает информацию о туристе из базы постоянных клиентов
function load_patron(patron_id, room_index, tourist_index) {
	document.getElementById('submit_button').disabled = true;
	AjaxRequest.send('booking', '/tools/partner/load_patron_2.php', 'Идёт загрузка', true, {'patron_id':patron_id, 'room_index':room_index, 'tourist_index':tourist_index});
}
function update_patron_data(room_index, tourist_index, id, sex, surname, name, birthday, passport, passport_valid_till, citizenship) {
	document.getElementById('id_'+room_index+'_'+tourist_index).value=id;
	document.getElementById('surname_'+room_index+'_'+tourist_index).value=surname;
	document.getElementById('name_'+room_index+'_'+tourist_index).value=name;
	document.getElementById('birthday_'+room_index+'_'+tourist_index).value=birthday;
	document.getElementById('passport_'+room_index+'_'+tourist_index).value=passport;
	document.getElementById('passport_valid_till_'+room_index+'_'+tourist_index).value=passport_valid_till;
	document.getElementById('citizenship_'+room_index+'_'+tourist_index).value=citizenship;
	document.getElementById('sex_'+room_index+'_'+tourist_index).selectedIndex = (sex == 'Mrs') ? 1 : 0;

	document.getElementById('surname_'+room_index+'_'+tourist_index).disabled=true;
	document.getElementById('name_'+room_index+'_'+tourist_index).disabled=true;
	
	document.getElementById('submit_button').disabled = false;
}
function load_city(room_index, tourist_index, region_id) {
	AjaxRequest.send('', '/tools/partner/load_city_2.php', 'Идёт загрузка', true, {'room_index':room_index, 'tourist_index':tourist_index, 'region_id':region_id});
}
function new_tourist(room_index, tourist_index) {
	document.getElementById('layer_patrons_'+room_index+'_'+tourist_index).innerHTML = '';
	document.getElementById('member_'+room_index+'_'+tourist_index).checked = false;
	
	document.getElementById('id_'+room_index+'_'+tourist_index).value=0;
	document.getElementById('surname_'+room_index+'_'+tourist_index).value='';
	document.getElementById('name_'+room_index+'_'+tourist_index).value='';
	document.getElementById('birthday_'+room_index+'_'+tourist_index).value='';
	document.getElementById('passport_'+room_index+'_'+tourist_index).value='';
	document.getElementById('sex_'+room_index+'_'+tourist_index).selectedIndex = 0;
	document.getElementById('layer_city_'+room_index+'_'+tourist_index).innerHTML = 'Выберите регион.';

	document.getElementById('surname_'+room_index+'_'+tourist_index).disabled=false;
	document.getElementById('name_'+room_index+'_'+tourist_index).disabled=false;
	
	var obj = document.getElementById('layer_vip_info_'+room_index+'_'+tourist_index).getElementsByTagName('input');
	for (var i in obj) obj[i].value = '';
	var obj = document.getElementById('layer_vip_info_'+room_index+'_'+tourist_index).getElementsByTagName('textarea');
	for (var i in obj) obj[i].value = '';
	var obj = document.getElementById('layer_vip_info_'+room_index+'_'+tourist_index).getElementsByTagName('select');
	for (var i in obj) obj[i].selectedIndex = 0;
	
	setTimeout('client_list_height('+room_index+', '+tourist_index+');', 500);
	
}
function change_agency(obj) {
	var color = obj.options[obj.selectedIndex].style.backgroundColor.toUpperCase();
	if (color == '#FF0000' || color == 'RGB(255, 0, 0)') {
		alert('Вы не можете выбрать этого агента.');
		obj.selectedIndex=0;
	} else if (color == '#FFFF00' || color == 'RGB(255, 255, 0)') {
		alert('Внимание! С данным агентом просрочено соглашение.');
		document.location.href='?id_agent_for='+obj.value;
	} else if (color == '#64C8FF' || color == 'RGB(100, 200, 255)') {
		alert('Возможно проблемный агент. Смотрите комментарий.');
		document.location.href='?id_agent_for='+obj.value;
	} else {
		document.location.href='?id_agent_for='+obj.value
	}
}
function add_infant(room_index) {
	var col = document.getElementById('booking').getElementsByTagName('div');
	var name = 'infant_'+room_index+'_';
	for (var i in col) {
		if (col[i].id && col[i].id.substr(0, name.length) == name && col[i].style.display != 'block') {
			col[i].style.display = 'block';
			return true;
		}
	}
}
function remove_infant(room_index, tourist_index) {
	document.getElementById('infant_'+room_index+'_'+tourist_index).style.display='none';
	document.getElementById('infant_surname_'+room_index+'_'+tourist_index).value = '';
}
function booking_complete(order_id) {
	document.location.href='/Online/OrderNew/Done/?order_id='+order_id;
}
function show_client_list(room_index, tourist_index) {
	var patrons = document.getElementById('patrons_'+room_index+'_'+tourist_index);
	patrons.style.display='block';
	setTimeout('client_list_height('+room_index+', '+tourist_index+');', 500);
	
	document.getElementById('submit_button').disabled = false;
}
function client_list_height(room_index, tourist_index) {
	var patrons = document.getElementById('patrons_'+room_index+'_'+tourist_index);
	var content = document.getElementById('layer_patrons_'+room_index+'_'+tourist_index);
	var height = (content.scrollHeight > 300) ? 300 : content.scrollHeight;
	patrons.style.height =  height + 'px';
}