
//Загружает цены
	function loading_prise_table(new_order_type){
		if(new_order_type != undefined) order_type = new_order_type;
		update_order_type_manu();
		document.getElementById('bild_order_button').style.display = order_type=='pass' ? 'none' : 'inline';
		if(order_type != 'recommend' && order_type != 'all' && order_type != 'easy' && order_type != 'info' && order_type != 'pass'){
			return 0;
		}
		if(order_type!='pass' && !bild_order()){
			document.getElementById('second_order_form_table').style.display = 'none';
			return 0;
		}else{
			document.getElementById('second_order_form_table').style.display = 'inline';
		}
		if(document.getElementById('extra_charge_caption')){
			document.getElementById('extra_charge_caption').innerHTML = order_type == 'pass' ? 'Ваша комисия:' : 'Наценка:';
		}
		if(document.getElementById('post_order_extra_charge')){
			document.getElementById('post_order_extra_charge').innerHTML = '';
		}
		document.getElementById('Ok').className = 'submit';
		//Расчёт и отображение обычной или упрощённой формы
		if(order_type == 'recommend' || order_type == 'all' || order_type == 'easy' || order_type == 'info'){
			document.getElementById('table_price_td').innerHTML = '<b>Идёт обработка запроса...';
			order_arr = document.getElementById('order').value;
			//print_r(order_arr.can_changed_price);
			bild_info_table(order_arr);
			JsHttpRequest.query(
				'http://'+document.location.host+'/classes/order/priceToJSClass.php5',
				order_arr,
				function(result, text){
					if(text!=''){
						alert(text);
					}
					/*if(result && text=='' && result.show_in_region){
						if(order_arr.start_address && result.show_in_region[0]){
							order_arr.start_address.show_in_region = result.show_in_region[0];
						}
						if(order_arr.interrim_address){
							for(var k in order_arr.interrim_address){
								if(result.show_in_region[k+1]){
									order_arr.interrim_address[k] = result.show_in_region[k+1];
								}
							}
						}
						if(order_arr.finish_address && result.show_in_region[result.show_in_region.length-1]){
							order_arr.finish_address.show_in_region = result.show_in_region[result.show_in_region.length-1];
						}
						bild_info_table(order_arr, result.show_in_region);
					}*/
					//alert([result.constructor, Object, result.constructor == Object]);
					//alert(result.calculate_time);
					//print_r(order_arr);
					if(result && text=='' && !result.error){
						loading_price = result;
						if(result.show_in_region){
							//
							bild_info_table(order_arr, result.show_in_region);
						}
						update_loading_price();
						if(order_type == 'info'){
							bild_prise_table();
						}else if(order_type == 'easy'){
							if(easy_order_taxi){
								bild_taxi_easy_prise();
							}else{
								bild_easy_prise();
							}
						}else if(order_type == 'recommend' || order_type == 'all'){
							bild_prise_table();
						}else{
							alert('Неверный тип заказа!');
							return 0;
						}
					}else{
						//Ошибка при загрузке
						HTML = '<b>Извините, но маршрут указан неверно и расчёт стоимости невозможен.</b><br>';
						if(result && result.error){
							HTML += '<br><br>'+result.error;
						}
						if(text!=''){
							HTML += '<br><br>'+text;
						}
						document.getElementById('table_price_td').innerHTML = HTML;
					}
				},
				true
			);
			document.getElementById('Ok').onclick = send_form;
		//Отображение формы без расчёта
		}else if(order_type == 'pass'){
			document.getElementById('table_info_td').innerHTML = '';
			var HTML = '<table cellpadding="0" cellspacing="1" bgcolor="#7DBC1E">';
			HTML+= '<tr bgcolor="#D8EBBB"><td style="padding: 5px 15px 5px 15px">Пассажир поедет по цене: <input type="text" name="pass_orders_price" id="pass_order_prise" style="width:36; height:15px; text-align:center;" value="'+(old_order_info&&old_order_info.price ? old_order_info.price : '')+'"> р.</td></tr>';
			HTML+= '</table>';
			HTML+= '<input type="hidden" name="price" value="pass">';
			document.getElementById('table_info_td').innerHTML = HTML;
			document.getElementById('table_price_td').innerHTML = '';
			if(document.getElementById('post_order_extra_charge')){
				document.getElementById('post_order_extra_charge').innerHTML = '&nbsp;Предлагать заказ <input type="text" name="pass_orders_timer" id="pass_orders_timer" style="width:36; text-align:center;" value="15" onchange="update_pass_orders_timer()"> минут <select name="pass_orders_timer_type" id="pass_orders_timer_type" style="width:120px;" onchange="update_pass_orders_timer()"><option value="from_order">после оформления<option value="to_delivery" selected>до подачи</select>';
			}
			document.getElementById('Ok').onclick = send_pass_form;
		}
	}
	
//Подсвечивает нужные пункты меню
	function update_order_type_manu(){
		if(document.getElementById('manu_order_type_recommend')){
			document.getElementById('manu_order_type_recommend').className = order_type=='recommend' ? 'manu_order_type_this' : 'manu_order_type';
		}
		if(document.getElementById('manu_order_type_all')){
			document.getElementById('manu_order_type_all').className = order_type=='all' ? 'manu_order_type_this' : 'manu_order_type';
		}
		if(document.getElementById('manu_order_type_easy')){
			document.getElementById('manu_order_type_easy').className = order_type=='easy' ? 'manu_order_type_this' : 'manu_order_type';
		}
		if(document.getElementById('manu_order_type_info')){
			document.getElementById('manu_order_type_info').className = order_type=='info' ? 'manu_order_type_this' : 'manu_order_type';
		}
		if(document.getElementById('manu_order_type_pass')){
			document.getElementById('manu_order_type_pass').className = order_type=='pass' ? 'manu_order_type_this' : 'manu_order_type';
		}
	}
//
	function update_pass_orders_timer(){
		var timer = document.getElementById('pass_orders_timer');
		var timer_type = document.getElementById('pass_orders_timer_type');
		if(timer_type && timer){
			timer.value = Math.max(timer.value, (timer_type.value == "from_order" ? 8 : 12));
		}
	}
	
//Обновляет тип оплаты (нал/безнал)
	function change_account_pay_type(){
		var check = document.getElementById('account_pay') && document.getElementById('account_pay').checked ? 1 : 0;
		if(check && document.getElementById('is_fast_charge') && document.getElementById('is_fast_charge').checked){
			document.getElementById('is_fast_charge').checked = 0;
		}
		//alert(check);
		if(document.getElementById('extra_charge_td')){
			document.getElementById('extra_charge_td').style.visibility = check ? 'hidden' : 'visible';
		}
		loading_prise_table();
	}
	
//Отправить заказ без явного расчёта
	function send_pass_form(){
		if(order_type != 'pass'){
			alert('Неверный тип заказа!');
			return 0;
		}
		if(!bild_order()){
			return 0;
		}
		document.getElementById('Ok').className = 'submit_push';
		order_arr = document.getElementById('order').value;
		JsHttpRequest.query(
			'http://'+document.location.host+'/classes/order/priceToJSClass.php5',
			order_arr,
			function(result, text){
				document.getElementById('Ok').className = 'submit';
				if(text!=''){
					alert(text);
				}
				if(result && text=='' && !result.error){
					if(result.price){
						for (var k in result.price){
							if((result.price[k].price || result.price[k].tariffs_info_id) && !result.price[k].error){
								send_form();
								return 1;
							}
						}
					}
					alert('Ни одно такси не принимает заказы!');
					return 0;
				}else{
					//Ошибка при загрузке
					HTML = '<b>Извините, но маршрут указан неверно.</b><br>';
					if(result && result.error){
						HTML += '<br><br>'+result.error;
					}
					if(text!=''){
						HTML += '<br><br>'+text;
					}
					document.getElementById('table_price_td').innerHTML = HTML;
				}
			},
			true
		);
	}
	
//Обновляет загруженные цены и накидывает к ним наценку
	function update_loading_price(){
		if(!loading_price || !loading_price.price) return false;
		if(
			document.getElementById('extra_charge') && 
			(!document.getElementById('account_pay') || !document.getElementById('account_pay').checked)
		){
			extra_charge = document.getElementById('extra_charge').value;
			extra_charge_type = extra_charge.search(/%/i);
			if(extra_charge_type!=-1){
				extra_charge = extra_charge.substr(0, extra_charge_type) * 1;
				extra_charge = 1 + extra_charge / 100;
				extra_charge_type = true
			}else{
				extra_charge_type = false
			}
		}else{
			extra_charge = 0;
			extra_charge_type = false;
		}
		var is_prise_alert = 0;
		var price1 = 0;
		var price2 = 0;
		for (var k in loading_price.price){
			one = loading_price.price[k];
			//Обработка растояния и времени в пути
			if(one.length && one.length*1!=0 && one.time && one.time*1!=0){
				one.length = one.length*1!=0 ? Math.round(one.length*10 + 0.45)/10 : '';
				one.time = one.time*1!=0 ? Math.round(one.time*1 + 0.45) : '';
				range_length = one.length;
				range_time = one.time;
			}
			//Смена формата
			if(one.price && typeof(one.price) == "object"){
				one.nominal_price = one.price.time_in_cash ? Math.round(one.price.time_in_cash / 10  + 0.45)*10 : 0;
				one.price = one.nominal_price;
			}
			//Учитывание числа автомобилей
			auto_count = Math.round(Math.max(1 * document.getElementById('order_auto_count').value, 1));
			if(auto_count>1){
				one.price*= auto_count;
			}
			//Своя цена
			if(one.taxi && one.taxi.id && one.price && is_taxi_engines_order && taxi_engines_id == one.taxi.id){
				taxi_engines_price = one.price;
			//Добавление наценки
			}else if(one.taxi && one.taxi.id && one.price && !one.error){
				price1 = extra_charge_type ? one.price * extra_charge : one.price + extra_charge*1;
				price2 = one.price + extra_charge_max;
				if(price1 > price2){
					if(!is_prise_alert){
						alert("Для Вас максимально допустимая наценка "+ extra_charge_max +' рублей');
					}
					is_prise_alert = 1;
					one.price = price2;
				}else{
					one.price = price1;
				}
				one.price = Math.round(one.price / 10  + 0.45)*10;
			}
			//Ограниченная наценка
			if(one.taxi.max_back_extra_charge && extra_charge && (one.price - one.nominal_price > one.taxi.max_back_extra_charge*one.price/100)){
				one.error = 'Ограничена наценка';
			}
		}
		//
	}
	
//Отображает таблицу с ценами
	function bild_prise_table(){
		logFile = loading_price.logFile ? loading_price.logFile : '';
		arr = loading_price.price ? loading_price.price : [];
		//print_r('http://taxorg.org/logs/prise/'+loading_price.logFile);
		//print_r(arr);
		new_date = document.getElementById('order').value.date_js;
		var old_date;
		var i = 0;
		for (var k in arr){
			one = arr[k];
			if(
				!one.error && one.taxi && 
				(!is_taxi_engines_order || taxi_engines_id != one.taxi.id) && 
				(order_type != 'recommend' || one.taxi.is_recommend)
			){
				i++;
			}
		}
		HTML = 'Всего '+ i +' '+ rus_case(i, 'предложение') +'<br>';
		HTML+= '<input type="hidden" name="price" value="'+order_type+'">';
		HTML+= '<table cellpadding="0" cellspacing="1" bgcolor="#7DBC1E">';
		HTML+= '	<tr>';
		HTML+= '		<td class="prise_head" width="120px">Таксомотор</td>';
		//	HTML+= '		<td class="prise_head" colspan="2">Длина пути, км</td>';
		HTML+= '		<td class="prise_head" >Авто</td>';
		HTML+= '		<td class="prise_head" >Стоимость</td>';
		//	HTML+= '		<td class="prise_head" rowspan="2" width="60px">Рейтинг</td>';
		HTML+= '	</tr>';
		//	HTML+= '	<tr>';
		//	HTML+= '		<td class="prise_head" width="60px">город</td>';
		//	HTML+= '		<td class="prise_head" width="60px">пригород</td>';
		//	HTML+= '		<td class="prise_head" >по пути</td>';
		//	HTML+= '		<td class="prise_head" >по часам</td>';
		//	HTML+= '	</tr>';
		//	HTML+= '	<tr>';
		//	HTML+= '		<td class="prise_head" width="60px">нал</td>';
		//	HTML+= '		<td class="prise_head" width="60px">б/н</td>';
		//	HTML+= '		<td class="prise_head" width="60px">нал</td>';
		//	HTML+= '		<td class="prise_head" width="60px">б/н</td>';
		//	HTML+= '	</tr>';
		color = '';
		n = 0;
		//print_r(arr);
		//first = 1;
		
		var is_prise_alert = 0;
		var maxStairsPrise = 0;
		var maxRushPrice = 0;
		var repudiate_info = null;
		var max_group_prise = [];
		var group_prise_error = [];
		var max_all_group_prise = [];
		var min_prise = 9999999;
		var max_price = 0;
		
		for (var k in arr){
			one = arr[k];
			if(
				one.taxi && one.taxi.name && one.taxi.id && one.auto &&
				(one.price || one.error || one.tariffs_info_id) && 
				(!is_taxi_engines_order || taxi_engines_id != one.taxi.id) &&
				one.price && !one.is_disabled_rush
			){
				max_price = Math.max(max_price, one.nominal_price);
				min_prise = Math.min(min_prise, one.nominal_price);
				if(!easy_order_taxi){
					maxRushPrice = Math.max(maxRushPrice, one.price);
					max_group_prise[one.auto.group] = max_group_prise[one.auto.group] ? Math.max(max_group_prise[one.auto.group], one.nominal_price) : one.nominal_price;
				}else if(easy_order_taxi == one.taxi.id){
					if(parseInt(easy_order_taxi_shift, 10)){
						maxRushPrice = Math.max(maxRushPrice, easy_order_taxi_shift.search(/%/i)!=-1 ? one.price * (1 + parseInt(easy_order_taxi_shift, 10)/100) : one.price + parseInt(easy_order_taxi_shift, 10));
						maxRushPricemaxRushPrice = Math.round(maxRushPrice/10 + 0.45)*10;
					}else{
						maxRushPrice = Math.max(maxRushPrice, one.price);
					}
					max_group_prise[one.auto.group] = max_group_prise[one.auto.group] ? Math.max(max_group_prise[one.auto.group], one.nominal_price) : one.nominal_price;
				}
				if(!max_group_prise[one.auto.group]){
					max_group_prise[one.auto.group] = 0;
				}
				max_all_group_prise[one.auto.group] = max_all_group_prise[one.auto.group] ? Math.max(max_all_group_prise[one.auto.group], one.nominal_price) : one.nominal_price;
			}else if(one.error && easy_order_taxi == one.taxi.id){
				group_prise_error[one.auto.group] = one.error;
			}
		}
		//Наценка
		var min_group_extra_charge = [];
		var extra_charge = document.getElementById('extra_charge') ? document.getElementById('extra_charge').value : '';
		var extra_charge_type = extra_charge.search(/%/i);
		if(!(extra_charge = parseInt(extra_charge, 10))) extra_charge = 0;
		for (var k in max_group_prise){
			if(easy_order_taxi && easy_order_taxi_shift && max_group_prise[k]){
				max_group_prise[k] = easy_order_taxi_shift.search(/%/i)!=-1 ? max_group_prise[k] * (1 + parseInt(easy_order_taxi_shift, 10)/100) : max_group_prise[k] + parseInt(easy_order_taxi_shift, 10);
			}else if(easy_order_taxi && !max_group_prise[k] && !easy_order_taxi_strictly){
				max_group_prise[k] = max_all_group_prise[k];
			}
			if(!easy_order_taxi || (!max_group_prise[k] && !easy_order_taxi_strictly)){
				max_group_prise[k] = (max_price - min_prise) * easy_order_percent + min_prise;
			}
			if(max_group_prise[k]){
				if(extra_charge_type!=-1){
					min_group_extra_charge[k] = max_group_prise[k] * extra_charge / 100;
				}else{
					min_group_extra_charge[k] = extra_charge;
				}
				min_group_extra_charge[k] = Math.round(min_group_extra_charge[k]/10 + 0.45)*10;
				max_group_prise[k]+= min_group_extra_charge[k];
				max_group_prise[k] = Math.round(max_group_prise[k]/10 + 0.45)*10;
			}
		}
		for (var k in arr){
			one = arr[k];
			if(
				one.taxi && one.taxi.name && one.taxi.id && one.auto &&
				(one.price || one.error || one.tariffs_info_id) && 
				(order_type != 'recommend' || one.taxi.is_recommend) &&
				(!is_taxi_engines_order || taxi_engines_id != one.taxi.id)
			){
				color = color == "FFFFFF" ? "D8EBBB" : "FFFFFF";
				n++;
				HTML+= '	<tr bgcolor="#'+color+'">';
				if(one.taxi.is_recommend && order_type == 'all'){
					HTML+= '		<td class="prise" title="Рекомендованное такси"><b>*'+one.taxi.name+'</b></td>';
				}else{
					HTML+= '		<td class="prise">'+one.taxi.name+'</td>';
				}
				//HTML+= '		<td class="prise"><a class="more" href="?'+one.taxi.id+'">'+one.taxi.name+'</a></td>';
				HTML+= '		<td class="prise">'+(one.auto.group_name!=one.auto.name?one.auto.group_name+', ':'')+one.auto.name+'</td>';
				
				repudiate_info = null;
				if(one.taxi && one.taxi.id){
					for (var k2 in repudiate_taxi){
						if(one.taxi.id == k2) repudiate_info = repudiate_taxi[k2];
					}
					if(repudiate_info && repudiate_info.sleep && repudiate_info.time){
						old_date = SQL_date_to_js(repudiate_info.time);
						repudiate_info.sleeped = (new_date - old_date) < repudiate_info.sleep*60*1000;
					}
					//if(repudiate_info) print_r(repudiate_info);
				}
				//print_r(repudiate_info);
				if(one.error){
					HTML+= '<td class="prise">';
					if(repudiate_info && repudiate_info.caption){
						HTML+= '<font color=red _title="'+repudiate_info.time+'">'+repudiate_info.caption+'</font><br>';
					}
					HTML+= one.error;
					HTML+= '</td>';
				}else if(one.price){
					/*if(!one.is_disabled_stairs){
						maxStairsPrise = Math.max(maxStairsPrise, one.price);
					}*/
					//print_r(one);
					HTML+= '		<td class="prise">';
					if(repudiate_info && repudiate_info.caption){
						HTML+= '<font color=red _title="'+repudiate_info.time+'">'+repudiate_info.caption+'</font><br>';
					}
					if(!(repudiate_info && repudiate_info.sleeped) && !one.is_disabled_normal && order_type != 'info'){
						HTML+= '		<input type="checkbox" name="check_price[]" value="'+k+'_1" id="check_'+k+'_1" '+(user_group!='middlemans' || one.price<= maxRushPrice?'checked':'')+'>';
					}
					//HTML+= '		<input type="hidden" id="price_'+k+'_1" value="'+one.price+'">';
					if(one.can_change_time || one.can_change_length || one.can_change_price){
						HTML+= '~';
					}
					//
					if(order_type == 'info'){
						if(!max_group_prise[one.auto.group] && group_prise_error[one.auto.group]){
							HTML+= group_prise_error[one.auto.group];
						}else if(one.price<= max_group_prise[one.auto.group]){
							HTML+= max_group_prise[one.auto.group]+'('+one.nominal_price+'+'+(max_group_prise[one.auto.group] - one.nominal_price)+')';
						}else{
							HTML+= max_group_prise[one.auto.group] +'('+ (max_group_prise[one.auto.group] - min_group_extra_charge[one.auto.group]) +'+'+ min_group_extra_charge[one.auto.group] +') своя цена '+ one.nominal_price;
						}
					}else{
						HTML+= one.price;
					}
					if(prize_sum!=0 && one.price > prize_sum)
						HTML+= ' (с учётом скидки '+(one.price - prize_sum)+')';
					if(prize_sum!=0 && one.price <= prize_sum)
						HTML+= ' (с учётом скидки полностью оплачен)';
					if(one.tariffs_info_id)
						HTML+= ' (<a href="JavaScript:openTariffsWin('+ one.tariffs_info_id +');">тарифы</a>)';
					HTML+= '		</td>';
				}else if(one.tariffs_info_id){
					HTML+= '<td class="prise">';
					if(!(repudiate_info && repudiate_info.sleeped) && order_type != 'info'){
						HTML+= '		<input type="checkbox" name="check_price[]" value="'+k+'_1" id="check_'+k+'_1">';
					}
					if(repudiate_info && repudiate_info.caption){
						HTML+= '<font color=red _title="'+repudiate_info.time+'">'+repudiate_info.caption +'</font><br>';
					}
					HTML+= 'без расчёта цены';
					HTML+= ' (<a href="JavaScript:openTariffsWin('+ one.tariffs_info_id +');">тарифы</a>)';
					HTML+= '</td>';
				}
				//	HTML+= '		<td class="prise">'+(one.taxi.rating ? one.taxi.rating : '')+'</td>';
				HTML+= '	</tr>';
			}
		}
		if(maxRushPrice>0 && order_type != 'info'){
			if(user_group=='taxi_engines'){
				HTML = '<table cellpadding="0" cellspacing="1" bgcolor="#7DBC1E">'+
				'<tr bgcolor="#D8EBBB"><td style="padding: 5px 15px 5px 15px">Пассажир поедет по цене: <input type="text" name="order_max_price" id="order_max_prise" style="width:36; height:15px; text-align:center;" value="'+maxRushPrice+'" onchange="update_price_check()"> р.</td></tr>'+
				'</table><br>'+HTML;
			}else{
				color = color == "FFFFFF" ? "D8EBBB" : "FFFFFF";
				HTML+= '<tr bgcolor="#'+color+'" align="center"><td class="prise2" colspan="3">Максимальная цена <input type="text" name="order_max_price" id="order_max_prise" style="width:36; height:15px; text-align:center;" value="'+maxRushPrice+'" onchange="update_price_check()"> р.</td></tr>';
			}
		}
		if(range_length>0 && range_time>0){
			color = color == "FFFFFF" ? "D8EBBB" : "FFFFFF";
			HTML+= '<tr bgcolor="#'+color+'"><td class="prise3" colspan="3">Плановая протяжённость <a href="JavaScript: route_info();">маршрута</a> '+range_time+' минут '+range_length+' км.</td></tr>';
		}
		color = color == "FFFFFF" ? "D8EBBB" : "FFFFFF";
		HTML+= '<tr bgcolor="#'+color+'"><td class="prise3" colspan="3"><a href="/texts/to_taxi/">Здесь может быть цена Вашего такси.</a></td></tr>';
		if(logFile!='' && is_admin_price_info){
			color = color == "FFFFFF" ? "D8EBBB" : "FFFFFF";
			HTML+= '<tr bgcolor="#'+color+'"><td class="prise3" colspan="3"><a href="/logs/prise/'+logFile+'" target=_blank>расчёт</a></td></tr>';
		}
		HTML+= '</table>';
		if(order_type == 'info'){
			HTML+= '<input type="hidden" name="price" value="easy">';
			HTML+= '<input type="hidden" id="easy_order_min_prise" value="'+min_prise+'">';
			HTML+= '<input type="hidden" id="easy_order_max_prise" value="'+max_price+'">';
		}
		//alert([min_prise, max_price]);
		//order_type == 'info'
		if(taxi_engines_price){
			HTML+= '<b>(Цена Вашего такси '+taxi_engines_price+' руб.)</b><br>';
		}
		if(n == 0){
			if(order_type == 'recommend'){
				order_type = 'all';
				update_order_type_manu();
				return bild_prise_table();
			}
			HTML = '<b>Извините, но ни одно такси не может принять Ваш заказ.</b><br>';
		}
		document.getElementById('table_price_td').innerHTML = HTML;
		//alert(HTML);
	}
	
//Обновляет отмеченные чекбоксы ниже введёной
	function update_price_check(){
		var max = document.getElementById('order_max_prise') ? document.getElementById('order_max_prise').value*1 : 0;
		var obj;
		for (var k in loading_price.price){
			if(obj = document.getElementById('check_'+k+'_1')){
				obj.checked = loading_price.price[k].price <= max;
			}
		}
	}
	
//Открывает окно с проложеным маршрутом
	function route_info(){
		window.open('/index.php5?modul=order&class=route','_blank','scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=30,left=30,width=800,height=600');
	}

//Отображает упрощённую форму с ценами
	function bild_easy_prise(){
		arr = loading_price;
		//logFile = arr.logFile ? arr.logFile : '';
		arr = arr.price ? arr.price : [];
		var maxPrise = 0;
		var minPrise = 9999999;
		var minNominalPrise = 9999999;
		var is_prise_alert = 0;
		
		//print_r(extra_charge);
		for (var k in arr){
			one = arr[k];
			if(one.price && !one.error && !one.is_disabled_easy && (!is_taxi_engines_order || taxi_engines_id != one.taxi.id)){
				minNominalPrise = Math.min(minNominalPrise, one.nominal_price);
				maxPrise = Math.max(maxPrise, one.nominal_price);
				minPrise = Math.min(minPrise, one.nominal_price);
				i++;
			}
		}
		//alert([minPrise, maxPrise, minNominalPrise]);
		price_temp = minPrise + (maxPrise - minPrise) * easy_order_percent;
		var extra_charge = document.getElementById('extra_charge') ? document.getElementById('extra_charge').value : '';
		var extra_charge_type = extra_charge.search(/%/i);
		extra_charge = parseInt(extra_charge, 10);
		if(extra_charge_type!=-1){
			price_temp*= (1 + extra_charge / 100);
			maxPrise*= (1 + extra_charge / 100);
			minPrise*= (1 + extra_charge / 100);
		}else{
			price_temp+= extra_charge;
			maxPrise+= extra_charge;
			minPrise+= extra_charge;
		}
		price_temp = Math.round(price_temp / 10 + 0.45)*10;
		maxPrise = Math.round(maxPrise / 10 + 0.45)*10;
		minPrise = Math.round(minPrise / 10 + 0.45)*10;
		
		price = price_temp;
		//price = 0;
		var i = 0; j = 0;
		for (var k in arr){
			one = arr[k];
			if(one.price && !one.error && !one.is_disabled_easy && price_temp >= one.price && one.taxi && (!is_taxi_engines_order || taxi_engines_id != one.taxi.id)){ 
				i++;
				//price = Math.max(price, one.price);
			}
			if(one.price && !one.error && !one.is_disabled_easy && one.taxi && (!is_taxi_engines_order || taxi_engines_id != one.taxi.id)) j++;
		}
		
		if(i>0){
			HTML = '<table cellpadding="0" cellspacing="1" bgcolor="#7DBC1E"><tr bgcolor="#D8EBBB"><td class="prise3" style="font:14px;">';
			HTML+= 'Заказ готовы принять '+ i +' из '+ j +' служб такси<br>';
			HTML+= '</td></tr><tr bgcolor="#FFFFFF"><td class="prise2" style="font:14px;">';
			HTML+= '<input type="hidden" name="price" value="easy">';
			HTML+= '<input type="hidden" id="easy_order_min_prise" value="'+minPrise+'">';
			HTML+= '<input type="hidden" name="easy_order_max_prise" id="easy_order_max_prise" value="'+price+'">цена маршрута: <b>'+price+'</b> рублей. ';
			//HTML+= '<!--a href="JavaScript:loading_prise_table(\'easy\');">info</a-->';
			HTML+= '</td></tr>';
			if(range_length>0 && range_time>0){
				HTML+= '<tr bgcolor="#D8EBBB"><td class="prise3" colspan="3">Плановая протяжённость <a href="JavaScript: route_info();">маршрута</a> '+range_time+' минут '+range_length+' км.</td></tr>';
			}
			HTML+= '</table>';
			
			if(taxi_engines_price){
				HTML+= '<b>(Цена Вашего такси '+taxi_engines_price+' руб.)</b><br>';
			}
			if(document.getElementById('post_order_extra_charge')){
				document.getElementById('post_order_extra_charge').innerHTML = '&nbsp;max '+(price - minNominalPrise)+' руб.';
			}
		}else{
			HTML = '<b>Извините, но ни одно такси не может принять Ваш заказ.</b><br>';
		}
		document.getElementById('table_price_td').innerHTML = HTML;
	}
	
//Отображает упрощённую форму с ценами ограниченными выбранным такси
	function bild_taxi_easy_prise(){
		arr = loading_price;
		//print_r('http://taxorg.org/logs/prise/'+loading_price.logFile);
		//print_r(arr.price);
		//return;
		//logFile = arr.logFile ? arr.logFile : '';
		arr = arr.price ? arr.price : [];
		var max_extra_charge = 0;
		var max_group_prise = [];
		var group_name = [];
		var group_count = [];
		var taxi_count = [];
		var group_prise_error = [];
		var count = 0;
		var count_all = 0;
		var min_prise = 9999999;
		var max_price = 0;
		
		//Максимальная цена по ценам такси
		for (var k in arr){
			one = arr[k];
			if(one.price && (!one.error || one.error=='Только по б\\н расчету') && one.taxi.id == easy_order_taxi){
				max_price = Math.max(max_price, one.nominal_price);
				min_prise = Math.min(min_prise, one.nominal_price);
				max_group_prise[one.auto.group] = max_group_prise[one.auto.group] ? Math.max(max_group_prise[one.auto.group], one.nominal_price) : one.nominal_price;
				/*if(parseInt(easy_order_taxi_shift, 10)){
					one.nominal_price = easy_order_taxi_shift.search(/%/i)!=-1 ? one.price * (1 + parseInt(easy_order_taxi_shift, 10)/100) : one.price + parseInt(easy_order_taxi_shift, 10);
					one.nominal_price = Math.round(one.nominal_price/10 + 0.45)*10;
				}*/
				i++;
			}else if(one.error && one.taxi.id == easy_order_taxi){
				group_prise_error[one.auto.group] = one.error;
			}
			group_name[one.auto.group] = one.auto.group_name;
			group_count[one.auto.group] = 0;
		}
		//Наценка
		var min_group_extra_charge = [];
		var extra_charge = document.getElementById('extra_charge') ? document.getElementById('extra_charge').value : '';
		var extra_charge_type = extra_charge.search(/%/i);
		extra_charge = parseInt(extra_charge, 10);
		for (var k in max_group_prise){
			if(easy_order_taxi_shift && max_group_prise[k]){
				max_group_prise[k] = easy_order_taxi_shift.search(/%/i)!=-1 ? max_group_prise[k] * (1 + parseInt(easy_order_taxi_shift, 10)/100) : max_group_prise[k] + parseInt(easy_order_taxi_shift, 10);
			}
			if(extra_charge_type!=-1){
				min_group_extra_charge[k] = max_group_prise[k] * extra_charge / 100;
			}else{
				min_group_extra_charge[k] = extra_charge;
			}
			min_group_extra_charge[k] = Math.round(min_group_extra_charge[k]/10 + 0.45)*10;
			max_group_prise[k]+= min_group_extra_charge[k];
			max_group_prise[k] = Math.round(max_group_prise[k]/10 + 0.45)*10;
		}
		//Если цены такси нет
		var error = '';
		for (var g in group_name){
			if(!max_group_prise[g]){
				if(!easy_order_taxi || !easy_order_taxi_strictly){
					for (var k in arr){
						one = arr[k];
						if(one.price && !one.error && !one.is_disabled_easy && !one.is_disabled_all && one.auto.group == g){
							max_group_prise[one.auto.group] = max_group_prise[one.auto.group] ? Math.max(max_group_prise[one.auto.group], one.price) : one.price;
							max_price = Math.max(max_price, one.price);
							min_prise = Math.min(min_prise, one.price);
							i++;
						}
					}
				}else{
					max_group_prise[g] = 0;
					if(group_prise_error[one.auto.group]){
						error = group_prise_error[one.auto.group];
					}
				}
			}
		}
		//Максимальная наценка
		for (var k in arr){
			one = arr[k];
			if(
				one.price && !one.error && !one.is_disabled_easy && !one.is_disabled_all && one.taxi && 
				(!is_taxi_engines_order || taxi_engines_id != one.taxi.id)
			){
				if(taxi_count[one.taxi.id]==undefined){
					taxi_count[one.taxi.id]=0;
					count_all++
				}
				//if(one.price <= max_group_prise[one.auto.group]){
				if(max_group_prise[one.auto.group]){
					if(taxi_count[one.taxi.id]==0){
						count++;
					}
					taxi_count[one.taxi.id]++;
					group_count[one.auto.group]++;
					max_extra_charge = Math.max(max_extra_charge, max_group_prise[one.auto.group] - one.nominal_price);
				}
			}
			//taxi_count
		}
		//print_r(group_name);
		//print_r(max_group_prise);
		//print_r(group_count);
		//
		if(count>0){
			HTML = '<table cellpadding="0" cellspacing="1" bgcolor="#7DBC1E"><tr bgcolor="#D8EBBB"><td class="prise3" style="font:14px;">';
			HTML+= 'Заказ готовы принять '+ count +' из '+ count_all +' служб такси<br>';
			HTML+= '</td></tr><tr bgcolor="#FFFFFF"><td class="prise2" style="font:14px;">';
			HTML+= '<input type="hidden" name="price" value="easy">';
			HTML+= '<input type="hidden" id="easy_order_min_prise" value="'+min_prise+'">';
			HTML+= '<input type="hidden" id="easy_order_max_prise" value="'+max_price+'">';
			for (var k in group_name){
				if(group_count[k]>0){
					HTML+= group_name[k]+': <b>'+max_group_prise[k]+'</b> рублей.<br>';
				}
			}
			//HTML+= '<!--a href="JavaScript:loading_prise_table(\'easy\');">info</a-->';
			HTML+= '</td></tr>';
			if(range_length>0 && range_time>0){
				HTML+= '<tr bgcolor="#D8EBBB"><td class="prise3" colspan="3">Плановая протяжённость маршрута '+range_time+' минут '+range_length+' км.</td></tr>';
			}
			HTML+= '</table>';
			
			if(taxi_engines_price){
				HTML+= '<b>(Цена Вашего такси '+taxi_engines_price+' руб.)</b><br>';
			}
			if(document.getElementById('post_order_extra_charge')){
				document.getElementById('post_order_extra_charge').innerHTML = '&nbsp;max '+max_extra_charge+' руб.';
			}
		}else if(error){
			HTML = '<b>'+error+'</b><br>';
		}else if(count_all>0){
			HTML = '<b>Извините, но ни одно такси не может принять Ваш заказ по заданной цене.</b><br>';
		}else{
			HTML = '<b>Извините, но ни одно такси не может принять Ваш заказ.</b><br>';
		}
		document.getElementById('table_price_td').innerHTML = HTML;
	}
	
//Открывает новое окно для отображения короткого текста
	function alert_window(HTML, width, height){
		width = width!=null ? 1*width : 250;
		height = width!=null ? 1*height : 150;
		//HTML = HTML.replace('"', '&quot;');
		HTML = HTML.replace('"', "''");
		window.open('JavaScript:document.write("'+HTML+'");window.setActive();','_blank','top=100,left=150,width='+width+',height='+height+',scrollbars=no,taskbar=no,resizeable=no,status=no,menubar=no');
	}
//Открывает новое окно для отображения текстов
	function openArticlesWin(id, width, height){
		width = width!=null ? 1*width : 250;
		height = width!=null ? 1*height : 150;
		window.open('/index.php5?module=articles&class=showArticles&articleId='+id+'&noMainIndex&noIndex', '_blank', 'scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=200,left=200,width='+width+',height='+height);
	}
//Открывает новое окно для отображения тарифов
	function openTariffsWin(id){
		window.open('/index.php5?module=clients&class=tariffsInfo&noMainIndex&noIndex&id='+id, '_blank', 'scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=200,left=200,width=520,height=200');
	}

//Отправляет форму заказа
	function send_form(){
		order_arr_1 = document.getElementById('order').value;
		if(!bild_order()){
			alert('Ошибка составления заказа.');
			loading_prise_table();
			return 0;
		}
		if(order_type == 'pass' && !order_arr_1){
			
		}
		order_arr_2 = document.getElementById('order').value;
		date_min = order_arr_1['date_js'];
		date_max = new Date(order_arr_1['date_js'].getFullYear(), order_arr_1['date_js'].getMonth(), order_arr_1['date_js'].getDate(), order_arr_1['date_js'].getHours(), order_arr_1['date_js'].getMinutes()+5);
		if(order_arr_2['date_js'] >= date_min && order_arr_2['date_js'] <= date_max){
			order_arr_1['date_js'] = order_arr_2['date_js'];
			order_arr_1['date'] = order_arr_2['date'];
			order_arr_1['time_hour'] = order_arr_2['time_hour'];
			order_arr_1['time_minut'] = order_arr_2['time_minut'];
		}else{
			alert('Прошло слишком много времени и надо обновить расчётные цены!');
			loading_prise_table();
			return 0;
		}
		order_arr_1.type = order_arr_2.type;
		order_arr_1.call_passenger_js = order_arr_2.call_passenger_js;
		order_arr_1.call_passenger = order_arr_2.call_passenger;
		//print_r(order_arr_1);
		//print_r(document.getElementById('order').value);
		//order_arr['date_js']
		if(!equal(order_arr_1, order_arr_2)){
			/*for (var k in order_arr_1)
				if(!equal(order_arr_1[k], order_arr_2[k])){
					print_r(k);
					print_r(order_arr_1[k]);
					print_r(order_arr_2[k]);
				}//*/
			//print_r(order_arr_1);
			//print_r(order_arr_2);
			alert('Были изменения в заказе и надо обновить расчётные цены!');
			loading_prise_table();
			return 0;
		}
		
		if(document.getElementById('order_name').value==""){
			alert('Вы не ввели имя!');
			return 0;
		}
		if(document.getElementById('order_phone').value==""){
			alert('Вы не ввели телефон!');
			return 0;
		}
		if(document.getElementById('order_text').value==""){
			alert('Вы не ввели коментарий!');
			return 0;
		}
		if(order_type == 'recommend' || order_type == 'all'/* || order_type == 'easy'*/){
			prise_list = document.getElementsByName('check_price[]');
			is_prise = prise_list['length']>0;
			if(!loading_price || !is_prise){
				alert('Стоимость заказа не расчитана!');
				return 0;
			}
		}
		if(order_type == 'pass' && (!document.getElementById('pass_order_prise') || document.getElementById('pass_order_prise').value*1<1)){
			alert('Цена не введина');
			return 0;
		}

		if((order_type == 'easy' || order_type == 'info') && document.getElementById('easy_order_min_prise') && document.getElementById('easy_order_max_prise') && (document.getElementById('easy_order_min_prise').value * 1 > document.getElementById('easy_order_max_prise').value * 1)){
			alert('Вы ввели цену ниже минимальной');
			return 0;
		}
		if(order_type == 'recommend' || order_type == 'all'){
			is_checked = 0;
			for (var i = 0; i<prise_list['length']; i++)
				if(prise_list[i].checked)
					is_checked = 1;
			if(!is_checked){
				alert('Вы не выбрали такси!');
				return 0;
			}
		}
		if(document.getElementById('account_pay') && document.getElementById('account_pay').checked){
			if(order_type == 'easy' || order_type == 'info'){
				prise = document.getElementById('easy_order_max_prise').value * 1;
			}else if(order_type == 'recommend'){
				//prise = document.getElementById('recommend_order_max_prise').value*1;
				prise = document.getElementById('order_max_prise').value*1;
			}else if(order_type == 'all'){
				prise = document.getElementById('order_max_prise').value*1;
				/*prise = 0;
				for (var i = 0; i<prise_list['length']; i++){
					if(prise_list[i].checked){
						if(prise_list[i].value == 'rush_order' || prise_list[i].value == 'stairs_order'){
							prise = document.getElementById(prise_list[i].value +'_max_prise').value * 1;
						}else{
							//prise = document.getElementById('price_'+prise_list[i].value).value * 1;
							prise = loading_price.price[prise_list[i].value].price * 1;
						}
					}
				}*/
			}else if(order_type == 'pass'){
				prise = document.getElementById('pass_order_prise').value*1;
			}else{
				alert('Неверный тип заказа!');
				return 0;
			}
			if(prise > user_money){
				alert('На вашем счёте не достаточно средств!');
				return 0;
			}
		}
	//	if(!document.getElementById('order_Ok').checked){
	//		alert('Вы не согласились с правилами перевозки!');
	//		return 0;
	//	}
		//print_r('1');
		//return 0;
		document.getElementById('order').submit();
	}

//Заполняет таблицу информации о заполненном заказе
	function bild_info_table(order_arr, show_in_region){
		if(!show_in_region) show_in_region = [];
		//alert('*');
		HTML = '<table width="600" cellpadding="0" cellspacing="0">';
		//Дата поездки (Когда едем)
		if(order_arr['date_js']){
			monse_arr = ['января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря'],
			date_t = order_arr['date_js'].getDate()+' '+ monse_arr[order_arr['date_js'].getMonth()] +' '+order_arr['date_js'].getFullYear();
			time_t = order_arr['date_js'].getHours()+':'+(order_arr['date_js'].getMinutes()<10?'0':'')+order_arr['date_js'].getMinutes();
			HTML += bild_step_info_table('Дата поездки', date_t+', <b>'+time_t+'</b>');
		}
		//Адрес отправления (Откуда едем)
		if(order_arr['start_address'])
			HTML += bild_step_info_table('Адрес отправления', get_addres_text(order_arr['start_address'], show_in_region[0]));
		//Через (Куда заедем по дороге)
		if(order_arr['interrim_address']){
			interrim_address_t = '';
			
			for (var k in order_arr['interrim_address']){
				interrim_address_t += (interrim_address_t == ''?'':'<br>')+get_addres_text(order_arr['interrim_address'][k], show_in_region[k+1]);
				i++;
			}
			if(interrim_address_t != '')
				HTML += bild_step_info_table('Через', interrim_address_t);
		}
		//Едем на (Куда едем)
		if(order_arr['finish_address'])
			HTML += bild_step_info_table('Едем на', get_addres_text(order_arr['finish_address'], show_in_region[show_in_region.length-1]));
		//Автомобиль (На чём едем)
		if(order_arr['auto_tip_name'] && order_arr['auto_models_name'] && order_arr['auto_models_name'].constructor == Array){
			auto_t = '';
			var i = 0;
			for (var k in order_arr['auto_models_name']){
				auto_t = order_arr['auto_models_name'][k] +(i == 0?'':(i == 1?' или ':', '))+ auto_t;
				i++;
			}
			HTML += bild_step_info_table('Автомобиль', order_arr['auto_tip_name']+': '+auto_t);
		}
		//Дополнительно потребуется (Дополнительные услуги)
		if(order_arr['auto_extra_name'] && order_arr['auto_extra_name'].length>0){
			HTML += bild_step_info_table('Дополнительно потребуется', order_arr['auto_extra_name']);
		}
		//
		
		HTML += '</table>';
		document.getElementById('table_info_td').innerHTML = HTML;
	}
	function get_addres_text(addres, show_in_region){
		
		var addres_str = '';
		if(addres['name_r']) 
			addres_str = addres_str + addres['name_r']+', ';
		if(show_in_region && show_in_region['caption'])
			addres_str = addres_str + show_in_region['caption']+', ';
		if(addres['name_a'])
			addres_str = addres_str + addres['name_a'];
		else if(addres['name_u'])
			addres_str = addres_str + addres['name_u'];
		else if(addres['name_p'])
			addres_str = addres_str + addres['name_p'];
		else
			addres_str = addres_str + '-';
		if(addres['time'] > 5) 
			addres_str = addres_str + ', '+addres['time']+' минут';
		return addres_str;
	}
	function bild_step_info_table(caption, val){
		var v = '';
		if(val.constructor == Array){
			for (var k in val){
				//v += (v == ''?'':'<br>') + k+':'+val[k];
				v += (v == ''?'':'<br>') + val[k];
			}
		}else{
			v = val;
		}
		return "<tr><td style='padding: 0px 5px 3px 0px'><nobr><b>"+caption+":</td> <td style='padding: 0px 5px 3px 5px' width='100%'>"+v+"</td></tr> <tr><td colspan=2 background='/images/design/psets.gif' height='1'></td></tr> <tr><td colspan=2 height=7></td></tr>";
	}

//Отложить
	/*function order_delay(){
		var time = window.prompt('Введите на сколько минут отложить','2');
		if(time!='' && time!=null && time*1>0){
			location.href='/index.php5?module=order&class=callBannerList&action=order_delay&delay_time='+(time*1);
		}
	}*/
	function order_delay(){
		document.getElementById('order_delay_form_root').style.visibility = 'visible';
	}
	function order_delay_send(){
		if(document.getElementById('order_delay_mod').value == 'relative'){
			var time = document.getElementById('order_delay_time').value *1;
		}else{
			var date = new Date();
			var time = Math.round((delay_time.date - date)/60000);
		}
		if(time < 1){
			alert('Время откладывания заказа меньше минуты');
			return;
		}
		/*if(time>60*24*7){
			alert('Время откладывания заказа больше недели');
			return;
		}*/
		var text = document.getElementById('order_delay_text').value;
		if(text==''){
			alert('Не ввели коментарий');
			return;
		}
		location.href='/index.php5?module=order&class=callBannerList&action=order_delay&delay_time='+time+'&delay_info='+text;
	}
	function order_delay_change_mod(){
		if(document.getElementById('order_delay_mod').value == 'relative'){
			document.getElementById('order_delay_time_root').innerHTML = '<input type="text" id="order_delay_time" value="2">';
		}else{
			var date = new Date();
			date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()+5);
			delay_time = new date_class('order_delay_time', date);
			delay_time.bild();
		}
	}
	function order_delay_close(){
		if(document.getElementById('order_delay_form_root')){
			document.getElementById('order_delay_form_root').style.visibility = 'hidden';
		}
	}
	
//Не заказали
	function order_break(){
		if(window.confirm('Не заказали?') && fast_order_id){
			location.href = '/index.php5?module=order&class=callBannerList&action=order_break&id='+fast_order_id;
		}
	}
	
//Не дозвониться
	function call_break(){
		if(window.confirm('Не дозвониться?') && fast_order_id){
			location.href = '/index.php5?module=order&class=callBannerList&action=call_break&id='+fast_order_id;
		}
	}
	
//---------------------------------------------------------------------------------------------------------------------------------------------------

//Проверяет на идентичность JS объекты
	function equal(arg1, arg2){
		if(arg1==null && arg2==null)
			return 1;
		if(arg1==null || arg2==null || arg1.constructor!=arg2.constructor)
			return 0;
		if(arg1.constructor == Object || arg1.constructor == Array){
			for (var k in arg1)
				if(!equal(arg1[k], arg2[k])){
					//alert(k+':'+arg1[k]+'='+arg2[k]);
					//print_r(arg1);
					//print_r(k);
					//print_r(arg1);
					//print_r(arg2);
					//print_r(arg1[k]);
					//print_r(arg2[k]);
					return 0;
				}
			return 1;
		}
		//if(arg1 != arg2) alert(arg1+'='+arg2);
		return arg1 == arg2;
	}
	
//Обрабатывает информацию о заказе
	function bild_order(){
		var order_arr = new Object();
		order_arr['auto_count'] = 1;
	//Форма опроса
		if(document.getElementById('surveys_ok') && !(1*document.getElementById('surveys_ok').value)){
			alert('Не заполнена форма опроса!');
			return 0;
		}
	//Откуда едем
		order_arr['start_address'] = get_address_to_arr('order_start_address');
		if(equal(order_arr['start_address'],[])){
			alert('Не заполнена точка отправления');
			return 0;
		}
	//Куда едем
		order_arr['finish_address'] = get_address_to_arr('order_finish_address');
		if(equal(order_arr['finish_address'],[])){ 
			alert('Не заполнена точка прибытия'); 
			return 0;
		}
	//Когда едем
		if( !document.getElementById('order_date_year')||
			!document.getElementById('order_date_month')||
			!document.getElementById('order_date_day')||
			!document.getElementById('order_time_hour')||
			!document.getElementById('order_time_hour')||
			!document.getElementById('order_time_minut')
		){
			alert('Не заполнено время подачи автомобиля');
			return 0;
		}
		order_date = new Date(
			document.getElementById('order_date_year').value*1,
			document.getElementById('order_date_month').value*1-1, 
			document.getElementById('order_date_day').value*1, 
			document.getElementById('order_time_hour').value*1,
			document.getElementById('order_time_minut').value*1
		);
		if(order_date=="NaN"){
			alert('Не заполнено время подачи автомобиля');
			return 0;
		}
		//d = new Date();
		//d = new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes() + minimal_order_delivery_time, d.getSeconds());
		//if(order_date < d) order_date = d;
		order_arr['date_js'] = order_date;
		order_arr['date'] = order_date.getDate()+'-'+(order_date.getMonth()>8?order_date.getMonth()+1:'0'+(order_date.getMonth()+1))+'-'+order_date.getFullYear();
		order_arr['time_hour'] = order_date.getHours();
		order_arr['time_minut'] = order_date.getMinutes();
		order_arr['wait'] = document.getElementById('order_wait') && document.getElementById('order_wait').value>0 ? document.getElementById('order_wait').value*1 : 0;
	//Куда заедем
		//print_r(interrim_address_arr);
		order_arr['interrim_address'] = interrim_address_arr!=null ? interrim_address_arr : [] ;
	//На чём едем
		/*order_arr['auto_tip'] = document.getElementById('order_auto_tip').value*1;
		order_arr['auto_tip_name'] = document.getElementById('order_auto_tip').options[document.getElementById('order_auto_tip').selectedIndex].innerHTML;
		order_arr['auto_models'] = [];
		order_arr['auto_models_name'] = [];
		var j=0;
		//_types
		//_types_name
		for(var i=1; document.getElementById('order_auto_model_'+i); i++){
			if(document.getElementById('order_auto_model_'+i).checked){
				order_arr['auto_models'][j] = document.getElementById('order_auto_model_'+i+'_code').value*1;
				order_arr['auto_models_name'][j] = document.getElementById('order_auto_model_'+i+'_name').value;
				j++;
			}
		}*/
		var j=0;
		var model = '';
		var model_nams = '';
		order_arr['auto'] = [];
		for(var i=1; document.getElementById('order_auto_model_'+i); i++){
			if(document.getElementById('order_auto_model_'+i).checked){
				group =  1*document.getElementById('order_auto_model_'+i+'_code').value;
				order_arr['auto'][group] = [];
				order_arr['auto'][group]['name'] = document.getElementById('order_auto_model_'+i+'_name').value;
				model_keys = document.getElementById('order_auto_model_'+i+'_types').value.split(",");
				model_names = document.getElementById('order_auto_model_'+i+'_types_name').value.split(",");
				models = [];
				for (var k in model_keys)
					if(model_names[k])
					models[model_keys[k]] = model_names[k];
				order_arr['auto'][group]['models'] = models;
				j=1;
			}
		}
		//print_r(order_arr['auto']);
		if(j==0){
			alert('Вы не выбрали ни одного типа автомобиля');
			return 0;
		}
	//Дополнительные услуги
		order_arr['auto_extra'] = [];
		order_arr['auto_extra_name'] = [];
		order_arr['auto_extra_explanation'] = [];
		order_arr['auto_extra_explanation_name'] = [];
		var j=0;
		for(var i=1; document.getElementById('order_additional_facilities_'+i); i++){
			temp = document.getElementById('order_additional_facilities_'+i);
			if(temp.checked){
				order_arr['auto_extra'][j] = document.getElementById('order_additional_facilities_'+i+'_id').value * 1;
				order_arr['auto_extra_name'][j] = temp.value;
				order_arr['auto_extra_explanation'][j] = document.getElementById('order_additional_facilities_'+i+'_explanation') ? document.getElementById('order_additional_facilities_'+i+'_explanation').value :'';
				order_arr['auto_extra_explanation_name'][j] = document.getElementById('order_additional_facilities_'+i+'_explanation_caption') ? document.getElementById('order_additional_facilities_'+i+'_explanation_caption').value :'';
				j++;
			}
		}
		order_arr['type'] = order_type;
		if(easy_order_taxi && (order_type == 'easy' || order_type == 'info')){
			order_arr['easy_order_taxi'] = easy_order_taxi;
			order_arr['easy_order_taxi_strictly'] = easy_order_taxi_strictly;
			order_arr['easy_order_taxi_shift'] = easy_order_taxi_shift;
		}
		//Задаёт может ли меняться цена
		order_arr['can_changed_price'] = can_changed_price;
		//Задаёт оплата со счёта или налом
		order_arr['account_pay'] = document.getElementById('account_pay') ? document.getElementById('account_pay').checked : 0;
	//Когда позвонить
		var date = new Date();
		$call_passenger_min = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()+5, date.getSeconds());
		$call_passenger_max = new Date(order_date.getFullYear(), order_date.getMonth(), order_date.getDate(), order_date.getHours(), order_date.getMinutes()-15, order_date.getSeconds());
		switch(document.getElementById('call_passenger_time_type') ? document.getElementById('call_passenger_time_type').value : ''){
			case 'after':
				order_arr['call_passenger_js'] = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()+document.getElementById('call_passenger_time_after').value*1, date.getSeconds());
				break;
			case 'in':
				order_arr['call_passenger_js'] = call_passenger_time_in.date;
				break;
			case 'before':
				order_arr['call_passenger_js'] = new Date(order_date.getFullYear(), order_date.getMonth(), order_date.getDate(), order_date.getHours(), order_date.getMinutes()-document.getElementById('call_passenger_time_before').value, order_date.getSeconds());
				break;
			default:
				order_arr['call_passenger_js'] = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()+5, date.getSeconds());
		}
		if(order_arr['call_passenger_js'] < $call_passenger_min){
			order_arr['call_passenger_js'] = $call_passenger_min;
			alert('Минимальное время отзвона через 5 минуты после создания заказа');
		}else if(order_arr['call_passenger_js'] > $call_passenger_max){
			order_arr['call_passenger_js'] = $call_passenger_max;
			alert('Максимальное время отзвона за 15 минут до подачи');
		}
		order_arr['call_passenger'] = js_date_to_format(order_arr['call_passenger_js'], '$Y-$m-$d $h:$i:$s');
		if(document.getElementById('call_passenger_time')){
			document.getElementById('call_passenger_time').value = order_arr['call_passenger'];
		}
		//
		document.getElementById('order').value=order_arr;
		return 1;
	}
	
//---------------------------------------------------------------------------------------------------------------------------------------------------

//Открывает новое окно для редактирование промежуточных адресов
	function openAddressWin(id,action){
		window.open('/index.php5?module=address&class=add&noMainIndex&noIndex&id='+id+'&action='+action,'_blank','scrollbars=yes,taskbar=no,resizeable=no,status=no,menubar=no,top=200,left=200,width=520,height=200');
	}
//Строит таблицу со списком промежуточных адресов
	function bild_interrim_address_list(arr){
		interrim_address_arr = clone(arr);
		var HTML = '<table cellpadding="0" cellspacing="0">'+"\r\n";
		var c1 = 0;
		var c2 = 0;
		for (var k in arr) c2++;
		for (var k in arr){
			c1++;
			HTML += '<tr>'+"\r\n";
			HTML += '<td style="padding: 3px 3px 4px 3px">'+"\r\n";
			if(c1!=1)
				HTML += '<a href="JavaScript:openAddressWin('+k+',\'up\');"><img width="7" height="9" src="/images/design/ar_up.gif" alt="Поднять"></a>'+"\r\n";
			HTML += '</td>'+"\r\n";
			HTML += '<td style="padding: 3px 3px 4px 3px">'+"\r\n";
			if(c1!=c2)
				HTML += '<a href="JavaScript:openAddressWin('+k+',\'down\');"><img width="7" height="9" src="/images/design/ar_down.gif" alt="Опустить"></a>'+"\r\n";
			HTML += '</td>'+"\r\n";
			address_temp = arr[k]['name_r']?arr[k]['name_r']+', ':'';
			if(arr[k]['name_u'])
				address_temp += arr[k]['name_u']+': ';
			else if(arr[k]['name_p'])
				address_temp += arr[k]['name_p']+': ';
			address_temp+= arr[k]['name_a']?arr[k]['name_a']:'';
			HTML += '<td style="padding: 3px 0px 0px 3px"><b>'+address_temp+'</td></tr>'+"\r\n";
			HTML += '<tr><td></td><td></td><td style="padding: 2px 10px 2px 15px">'+(arr[k]['time']&&arr[k]['time']>0?arr[k]['time']+' минут':'')+'</td></tr>'+"\r\n";
			//HTML += '</tr>'+"\r\n";
			HTML += '<tr><td></td><td></td><td>'+"\r\n";
			HTML += '<a href="JavaScript:openAddressWin('+k+',\'edit\');" class="more">Изменить</a>'+"\r\n";
			HTML += '<a href="JavaScript:openAddressWin('+k+',\'delit\');" class="more">Удалить</a>'+"\r\n";
			HTML += '</td></tr>'+"\r\n";
		}
		HTML += '</table>';
		//alert(HTML);
		document.getElementById('interrim_address_list').innerHTML = HTML;
	}
	
//---------------------------------------------------------------------------------------------------------------------------------------------------
	
	function call_passenger_time_open(){
		document.getElementById('order_call_back_time_form').style.visibility = 'visible';
	}

	function call_passenger_time_change_type(){
		var type = document.getElementById('call_passenger_time_type').value;
		var after_div = document.getElementById('call_passenger_time_after_root');
		var in_div = document.getElementById('call_passenger_time_in_root');
		var before_div = document.getElementById('call_passenger_time_before_root');
		
		after_div.style.display = type == 'after' ? 'inline' : 'none';
		in_div.style.display = type == 'in' ? 'inline' : 'none';
		before_div.style.display = type == 'before' ? 'inline' : 'none';
		
		if(type=='in' && in_div.innerHTML==''){
			var date = new Date();
			date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes()+7);
			call_passenger_time_in = new date_class('call_passenger_time_in', date);
			call_passenger_time_in.bild();
		}
	}
	
	function call_passenger_time_close(){
		bild_order();
		order_arr = document.getElementById('order').value;
		var start = new Date();
		var end = order_arr.date_js;
		var mod = document.getElementById('call_passenger_time_type').value;
		var time;
		if(mod == 'after'){
			time = Math.round((order_arr.call_passenger_js - start)/60000);
			document.getElementById('call_passenger_time_info').innerHTML = 'Позвонить мне через '+time+' '+rus_case(time, 'минута');
			document.getElementById('call_passenger_time_after').value = time;
		}else if(mod == 'before'){
			time = Math.round((end - order_arr.call_passenger_js)/60000);
			document.getElementById('call_passenger_time_info').innerHTML = 'Позвонить мне за '+time+' '+rus_case(time, 'минута');
			document.getElementById('call_passenger_time_before').value = time;
		}else{
			time = (start.getDate()!=order_arr.call_passenger_js.getDate()?js_date_to_format(order_arr.call_passenger_js, '$D $M'):'')+' в '+js_date_to_format(order_arr.call_passenger_js, '$H:$i');
			document.getElementById('call_passenger_time_info').innerHTML = 'Позвонить мне '+time;
			call_passenger_time_in.date = order_arr.call_passenger_js;
			call_passenger_time_in.year = order_arr.call_passenger_js.getFullYear();
			call_passenger_time_in.month = order_arr.call_passenger_js.getMonth();
			call_passenger_time_in.day = order_arr.call_passenger_js.getDate();
			call_passenger_time_in.hours = order_arr.call_passenger_js.getHours();
			call_passenger_time_in.minutes = order_arr.call_passenger_js.getMinutes();
			call_passenger_time_in.bild();
		}
		document.getElementById('order_call_back_time_form').style.visibility = 'hidden';
	}
	
