			function showVolume () 
			{
				var viz = document.getElementById ("volume").style.display;
				if (viz == "block")
					document.getElementById ("volume").style.display="none";
				if (viz == "none") 
				{
					document.getElementById ("volume").style.display="block";
					document.getElementById ("volume_box").checked = "checked";
				}
			}
			function changeTypeVolume ()
			{
				if (document.getElementById ("volume_box").checked)
				{
					document.getElementById("errorVolume1").innerHTML = "";
					document.getElementById("errorVolume2").innerHTML = "";				
					document.getElementById ("volume_img").src = "resources/box.gif";
					document.getElementById ("volume_input_box").style.display = "block";
					document.getElementById ("volume_input_cyl").style.display = "none";
					document.getElementById ("volume_input_tub").style.display = "none";
				}
				if (document.getElementById ("volume_cyl").checked)
				{
					document.getElementById("errorVolume1").innerHTML = "";
					document.getElementById("errorVolume2").innerHTML = "";				
					document.getElementById ("volume_img").src = "resources/cyl.gif";
					document.getElementById ("volume_input_cyl").style.display = "block";
					document.getElementById ("volume_input_box").style.display = "none";
					document.getElementById ("volume_input_tub").style.display = "none";
				}
				if (document.getElementById ("volume_tub").checked)
				{
					document.getElementById ("volume_img").src = "resources/tub.gif";
					document.getElementById ("volume_input_tub").style.display = "block";
					document.getElementById ("volume_input_box").style.display = "none";
					document.getElementById ("volume_input_cyl").style.display = "none";
				}
				document.getElementById ("volume_l").value='';
				document.getElementById ("volume_h").value='';
				document.getElementById ("volume_w").value='';
				document.getElementById ("volume_d").value='';
				document.getElementById ("volume_cl").value='';
				document.getElementById ("volume_ht").value='';
				document.getElementById ("volume_a").value='';
				document.getElementById ("volume_b").value='';
				document.getElementById ("volume_c").value='';
				document.getElementById("volume_result").innerHTML='0.00'
			}
			function calcVolume () { 
				if (document.getElementById ("volume_box").checked) 
				{
					var lenght = document.getElementById ("volume_l").value;
					lenght=lenght.replace(',', '.');
					lenght=lenght-0;
					var width = document.getElementById ("volume_w").value;
					width=width.replace(',', '.');
					width=width-0;
					var height = document.getElementById ("volume_h").value;
					height=height.replace(',', '.');
					height=height-0;
					var v_result = lenght*height*width/6000;
					var v_result1 = Math.floor(v_result);
					var v_result2 = v_result-v_result1; 
					if (v_result2 > 0 && v_result2 <= 0.5) 
						v_result2 = 0.5;
					else if (v_result2 > 0.5 && v_result2 <= 1) 
						v_result2 = 1;
					else 
						v_result2 = 0;
					v_result = v_result1 + v_result2;
				}
				if (document.getElementById ("volume_cyl").checked) 
				{
					var lenght = document.getElementById ("volume_cl").value;
					lenght=lenght.replace(',', '.');
					lenght=lenght-0;
					var diametr = document.getElementById ("volume_d").value;
					diametr=diametr.replace(',', '.');
					diametr=diametr-0;
					var v_result = 3.14*diametr*diametr*lenght/24000;
					var v_result1 = Math.floor(v_result);
					var v_result2 = v_result-v_result1;
					if (v_result2 > 0 && v_result2 <= 0.5)
						v_result2 = 0.5;
					else if (v_result2 > 0.5 && v_result2 <= 1)
						v_result2 = 1;
					else 
						v_result2 = 0;
					v_result = v_result1 + v_result2;
				}
				if(document.getElementById("volume_tub").checked)
				{
					var a = document.getElementById ("volume_a").value;
					a=a.replace(',', '.');
					a=a.replace(/[^0-9\.]/g, "");
					a=a-0;
					var b = document.getElementById ("volume_b").value;
					b=b.replace(',', '.');
					b=b.replace(/[^0-9\.]/g, "");
					b=b-0;		
					var c = document.getElementById ("volume_c").value;
					c=c.replace(',', '.');
					c=c.replace(/[^0-9\.]/g, "");
					c=c-0;
					var height = document.getElementById ("volume_ht").value;
					height=height.replace(',', '.');
					height=height.replace(/[^0-9\.]/g, "");
					height=height-0;
					if(a>0&&b>0&&c>0)
					{
						if((b+c-a)<=0||(a+c-b)<=0||(a+b-c)<=0)
						{
							document.getElementById("errorVolume1").innerHTML = "Ошибка:";
							document.getElementById("errorVolume2").innerHTML = "Одна из сторон треугольника больше или равна, сумме двух других!";
						}
						else
						{
							document.getElementById("errorVolume1").innerHTML = "";
							document.getElementById("errorVolume2").innerHTML = "";
							var s_tr = 1/4*Math.sqrt((a+b+c)*(b+c-a)*(a+c-b)*(a+b-c));
							var v_result = height*s_tr/6000;
							var v_result1 = Math.floor(v_result);
							var v_result2 = v_result-v_result1;
							if (v_result2 > 0 && v_result2 <= 0.5)
								v_result2 = 0.5;
							else if (v_result2 > 0.5 && v_result2 <= 1)
								v_result2 = 1;
							else 
								v_result2 = 0;
							v_result = v_result1 + v_result2;
						}
					}
				}				
				document.getElementById("volume_result").innerHTML = (v_result).toFixed(1);
			}


			// Подстановка города, переход по полям
			function liFormat (row)
			{
				var result = row[0] + "<span class=\"result_add\">" + row[1] + row[2] + "</span>";
				return result;
			}

			function resFormat (row)
			{
				var result = row[0] + row[1] + row[2];
				return result;
			}
			
			$(document).ready(function()
			{	
				$(".CSend, .CRec").autocomplete("inc/getCity.php", {
					max: 100,
					scroll: true,
					formatItem: liFormat,
					formatResult: resFormat,
					autoFill: false,
					width: 180
				});
				
				$(".CSend").result(function (event, data, formatted)
				{
					var id1 = "#" + $(this).attr('id');
					var id2 = "#String" + $(this).attr('id');
					var id3 = "#Rec" + $(this).attr('id').substring(4,$(this).attr('id').length); // определяем номер строки в которой находится элемент, вырезая цифру из id и далее формируем id следующего по ходу tab'a элемента
					$(id2).val(data[0]+data[1]+data[2]);
					$(id3).focus(); // перемещаем фокус на следующий элемент
				});
				
				$(".CRec").result(function (event, data, formatted)
				{
					var id1 = "#" + $(this).attr('id');
					var id2 = "#String" + $(this).attr('id');
					var id3 = "#Service" + $(this).attr('id').substring(3,$(this).attr('id').length); // определяем номер строки в которой находится элемент, вырезая цифру из id и далее формируем id следующего по ходу tab'a элемента
					$(id2).val(data[0]+data[1]+data[2]);
					$(id3).focus(); // перемещаем фокус на следующий элемент
				});
				
				// Если происходит смена значения, то в скрытое поле со строкой города получателя записывается то, что введено в поле ввода.
				// Это событие отрабатывает и в случае, если пользователь пользуется ф-цией автозаполнения, но оно отрабатывает раньше, чем result. Соотв result после все перезаписывает.
				$(".CSend, .CRec").change(function ()
				{
					var id1 = "#" + $(this).attr('id');
					var id2 = "#String" + $(this).attr('id');
					$(id2).val($(id1).attr("value"));
				}).change();
						
				$(".CService").change(function () 
				{
					var str;
					var id1 = "#" + $(this).attr('id');
					var id2 = "#Client" + $(this).attr('id');
					$(id1 + " option:selected").each(function () 
					{
						str = $(this).text();
					});
					$(id2).val(str);
				})
				.change();
				
				$(".CWeight").change(function () 
				{
					var id1 = "#" + $(this).attr('id');
					var id2 = "#Client" + $(this).attr('id');
					var str = $(id1).val();
					$(id2).val(str);
				})		
				.change();
			
				$(".COG, .CKGO").change(function () 
				{
					var id1 = "#" + $(this).attr('id');
					var id2 = "#Client" + $(this).attr('id');
					var str = $(id1 + ":checked").val();
					if (str != "on")
						str = "";
					$(id2).val(str);
				})
				.change();
			
				$('#og_h, #kgo_h').tooltip({
				});

			});
