	function show_panel()
	{

		if  (document.getElementById('footer_up').style.display=='none')
		{
			document.getElementById('footer_up').style.display='block';
		}
		else
		{
			document.getElementById('footer_up').style.display='none';
		}
		
	}
	
	
	function getsumma()
	{
		var w = document.getElementById('status_korz').value;
		if (w>0)
		{		
			var kol = document.getElementById('kolvo_tovars').value;		
			var summa = 0;

			for (i=1; i<=kol; i=i+1)
				{
						if (document.getElementById('kolich' + i + '_a').value>=0)
						{
							document.getElementById('tovar' + i + '_kolvo').value = document.getElementById('kolich' + i + '_a').value
						}
						else
						{
							document.getElementById(kolvo).value = 0;
						}

					cena = 'tovar' + i + '_cena';
					kolvo = 'tovar' + i + '_kolvo';
					status = 'tovar' + i + '_status';
					if (document.getElementById(status).value == 'y')
					{
						summa=summa + (document.getElementById(cena).value * document.getElementById(kolvo).value);

					}
				}
				summa = Math.ceil(summa*100)/100
			document.getElementById('itogo_cena').innerHTML=summa;
		}
	}

	function get_txt_onlink()
	{
		var w = document.getElementById('status_korz').value;
		if (w>0)
		{
			var kolt = document.getElementById('kolvo_tovars').value;
			if (kolt == 0)
			{
				document.getElementById('korz_d').innerHTML = 'Ваша корзина пуста';
			}
			if (kolt == 1)
			{
				document.getElementById('korz_d').innerHTML = 'В Вашей корзине 1 товар';
			}
			if (kolt > 1)
			{
				document.getElementById('korz_d').innerHTML = 'В Вашей корзине '+kolt+' товарa';
			}
			if (kolt > 4)
			{
				document.getElementById('korz_d').innerHTML = 'В Вашей корзине '+kolt+' товаров';
			}
		}
		else
		{
				document.getElementById('korz_d').innerHTML = 'Ваша корзина пуста';
		}
	}
	
	function korzina_show()
	{
		fade.addRule('fadeRule1',"#E3E4DC","#F04F53", "background-color", 100, 1);
		fade.addRule('fadeRule1_1',"#DCD6CA","#F04F53", "background-color", 100, 1);
		fade.addRule('fadeRule2',"#FFCC99","#f00", "border-color", 15, 1);
		fade.addRule('fadeRule3',"#ccc","#000", "color", 50, 1);	
		
		document.getElementById('korzina').style.display='block';
		
		make_korzina();

	}


		function make_korzina()
			{
				$("#korzina_spisok_full").ajaxStart(function(){
				
					$(this).html('Идёт синхронизация данных... Пожалуйста, подождите...');
					
					//$("#statusbox").hide('slow');
					//$(this).show('slow');
				 });
				/*
				$("#loading").ajaxStop(function(){
				  $(this).html($(this).attr('value'));
				  $(this).hide('slow');
				 });
				 */
				
				$.ajax({
				   type: "POST",
				   url: "/korz_show.php",
				   
				   success: function(msg){
						if (msg=='notovars')
						{
							msg='Товаров в корзине нет';
							$("#korzina_spisok_full").html(msg);
							document.getElementById('status_korz').value = '0';
							getsumma();
							get_txt_onlink();
						}
						else
						{
							$("#korzina_spisok_full").html(msg);
							document.getElementById('status_korz').value = '1';
							getsumma();
							get_txt_onlink();
						}
				   },
				   error: function() {
					 $("#korzina_spisok_full").html('Синхронизация прошла неудачно!');
				   }
				 });
			}
	



		function addtovar(theid)
			{
				var theid;
				//alert('Вот мы нажали на кнопку, чтобы добавить товар с ID = '+theid);
				$("#korzina_spisok_full").ajaxStart(function(){
				
					$(this).html('Идёт синхронизация данных... Пожалуйста, подождите...');
					
					//$("#statusbox").hide('slow');
					//$(this).show('slow');
				 });
				/*
				$("#loading").ajaxStop(function(){
				  $(this).html($(this).attr('value'));
				  $(this).hide('slow');
				 });
				 */
				
				$.ajax({
				   type: "POST",
				   url: "/korz_add.php?theid="+theid,
				   
				   success: function(msg){
					   //$("#korzina_spisok_full").html(msg);
					   document.getElementById('korzina').style.display='block';
					   //alert('Показываем корзину');
					   make_korzina_after_add(msg,theid)
				   },
				   error: function() {
					 $("#korzina_spisok_full").html('Синхронизация прошла неудачно!');
				   }
				 });
			}
		
		
		
		
		
		function savetovar()
			{
				var theids, thekolvos;



				var w = document.getElementById('status_korz').value;
				if (w>0)
				{		
					var kol = document.getElementById('kolvo_tovars').value;		

					for (i=1; i<=kol; i=i+1)
						{

							idd = 'tovar' + i + '_id';
							kolvo = 'tovar' + i + '_kolvo';
							status = 'tovar' + i + '_status';
							if (document.getElementById(status).value == 'y')
							{
								theids=theids+"|"+document.getElementById(idd).value;
								thekolvos=thekolvos+"|"+document.getElementById(kolvo).value;
							}
						}
				}


				
				//alert('ID = '+theids);
				//alert('KOLVO = '+thekolvos);
				
				$("#korzina_spisok_full").ajaxStart(function(){
				
					$(this).html('Идёт сохранение данных... Пожалуйста, подождите...');
					
					//$("#statusbox").hide('slow');
					//$(this).show('slow');
				 });
				/*
				$("#loading").ajaxStop(function(){
				  $(this).html($(this).attr('value'));
				  $(this).hide('slow');
				 });
				 */
				
				$.ajax({
				   type: "POST",
				   url: "/korz_save.php?theids="+theids+"&thekolvos="+thekolvos,
				   
				   success: function(msg){
					   //$("#korzina_spisok_full").html(msg);
					   alert('Данные успешно сохранены!');
						document.getElementById('status_korz').value = '0';
						getsumma();
						get_txt_onlink();
					   make_korzina();
					   korzina_unshow();
				   },
				   error: function() {
					 $("#korzina_spisok_full").html('Синхронизация прошла неудачно!');
				   }
				 });
			}
			
			
		function savetovar2()
			{
				var theids, thekolvos;

				var w = document.getElementById('status_korz').value;
				if (w>0)
				{		
					var kol = document.getElementById('kolvo_tovars').value;		

					for (i=1; i<=kol; i=i+1)
						{

							idd = 'tovar' + i + '_id';
							kolvo = 'tovar' + i + '_kolvo';
							status = 'tovar' + i + '_status';
							if (document.getElementById(status).value == 'y')
							{
								theids=theids+"|"+document.getElementById(idd).value;
								thekolvos=thekolvos+"|"+document.getElementById(kolvo).value;
							}
						}
				}


				
				//alert('ID = '+theids);
				//alert('KOLVO = '+thekolvos);
				
				//$("#korzina_spisok_full").ajaxStart(function(){
				
				//	$(this).html('Идёт сохранение данных... Пожалуйста, подождите...');
					
					//$("#statusbox").hide('slow');
					//$(this).show('slow');
				// });
				/*
				$("#loading").ajaxStop(function(){
				  $(this).html($(this).attr('value'));
				  $(this).hide('slow');
				 });
				 */
				
				$.ajax({
				   type: "POST",
				   url: "/korz_save.php?theids="+theids+"&thekolvos="+thekolvos,
				   
				   success: function(msg){

				   },
				   error: function() {
					 $("#korzina_spisok_full").html('Синхронизация прошла неудачно!');
				   }
				 });
			}
			
			
		function make_korzina_after_add(info, theid)
			{
				var info, theid;
				//alert('ОТВЕТ СКРИПТА: '+info);
				//alert(theid);
				$("#korzina_spisok_full").ajaxStart(function(){
				
					$(this).html('Идёт синхронизация данных... Пожалуйста, подождите...');
					
					//$("#statusbox").hide('slow');
					//$(this).show('slow');
				 });
				/*
				$("#loading").ajaxStop(function(){
				  $(this).html($(this).attr('value'));
				  $(this).hide('slow');
				 });
				 */
				
				$.ajax({
				   type: "POST",
				   url: "/korz_show.php",
				   
				   success: function(msg){
					   $("#korzina_spisok_full").html(msg);
						if (msg=='notovars')
						{
							msg='Товаров в корзине нет';
							$("#korzina_spisok_full").html(msg);
						}
						else
						{
								$("#korzina_spisok_full").html(msg);
								document.getElementById('status_korz').value = '1';
								getsumma();
								get_txt_onlink();
							
							if (info=='ok')
							{
								//Товар добавлен
								fadeundo_new(theid);
								
							}
							if (info=='isit')
							{
								//Товар уже естьв  корзине
								alert('Данный товар уже есть в Вашей корзине');
								fadeundo_new(theid);
							}
						}
					
				   },
				   error: function() {
					 $("#korzina_spisok_full").html('Синхронизация прошла неудачно!');
				   }
				 });
			}

			
	function korzina_unshow()
	{
		document.getElementById('korzina').style.display='none';
		get_txt_onlink();
	}
	
	function fadedo(num)
	{

		
		var num;
		var elem_img1='sk'+num+'_img1';
		var elem_img2='sk'+num+'_img2';
		var elem1a='k'+num+'_2a';
		var elem2a='k'+num+'_3a';
		var elem3a='k'+num+'_5a';
		var elem1na='k'+num+'_2na';
		var elem2na='k'+num+'_3na';
		var elem3na='k'+num+'_5na';		
		
		document.getElementById(elem_img1).style.display='none';
		document.getElementById(elem_img2).style.display='block';
		document.getElementById(elem1a).style.display='none';
		document.getElementById(elem1na).style.display='block';
		document.getElementById(elem2a).style.display='none';
		document.getElementById(elem2na).style.display='block';
		document.getElementById(elem3a).style.display='none';
		document.getElementById(elem3na).style.display='block';
		
		$("#elem_img1").hide('slow');
		
		status = 'tovar' + num + '_status';
		document.getElementById(status).value = 'n';
		
		getsumma();
	}
	

	
	function fadeundo(num)
	{
	
		var num;
		var elem_img1='sk'+num+'_img1';
		var elem_img2='sk'+num+'_img2';
		var elem1a='k'+num+'_2a';
		var elem2a='k'+num+'_3a';
		var elem3a='k'+num+'_5a';
		var elem1na='k'+num+'_2na';
		var elem2na='k'+num+'_3na';
		var elem3na='k'+num+'_5na';		
		
		document.getElementById(elem_img1).style.display='block';
		document.getElementById(elem_img2).style.display='none';
		document.getElementById(elem1a).style.display='block';
		document.getElementById(elem1na).style.display='none';
		document.getElementById(elem2a).style.display='block';
		document.getElementById(elem2na).style.display='none';
		document.getElementById(elem3a).style.display='block';
		document.getElementById(elem3na).style.display='none';
		
		status = 'tovar' + num + '_status';
		document.getElementById(status).value = 'y';
		
		getsumma();
	}	
	
	
	function fadeundo_new(num)
	{
	
		var num, numr;

		pole = 'tovarpoid_' + num;
		
		numr = document.getElementById(pole).value;
		num=numr;
		
		var elem1='sk_'+num;
		var elem2='sktd_'+num;
	
		fade(elem1, 'fadeRule1,fadeRule2,fadeRule3')
		fade(elem2, 'fadeRule1_1,fadeRule2,fadeRule3')
		
		setTimeout("fadeundo_new2("+num+")",1000)
		
		status = 'tovar' + num + '_status';
		document.getElementById(status).value = 'y';
		
		getsumma();
	}	
	
	function fadeundo_new2(num)
	{
	
		var num;
		var elem1='sk_'+num;
		var elem2='sktd_'+num;
	
		fade.back(elem1, 'fadeRule1,fadeRule2,fadeRule3')
		fade.back(elem2, 'fadeRule1_1,fadeRule2,fadeRule3')
		
	}	
	

		
	function submitform()
	{
	  var w = document.getElementById('status_korz').value;
	  if (w>0)
	  {		
		document.getElementById('firstname').style.border="1px solid #000";
		document.getElementById('surname').style.border="1px solid #000";
		document.getElementById('email').style.border="1px solid #000";
		document.getElementById('phone').style.border="1px solid #000";
		
		$("#firstname, #surname, #email, #phone").css('border', '1px solid #000');
		
		
		var err;
		err=0;
		if (document.getElementById('firstname').value=="") 
		{
			document.getElementById('firstname').style.border="1px solid #EC0000";
			err=1;
		}
		if (document.getElementById('surname').value=="") 
		{
			document.getElementById('surname').style.border="1px solid #EC0000";
			err=1;
		}
		if (document.getElementById('email').value=="") 
		{
			document.getElementById('email').style.border="1px solid #EC0000";
			err=1;
		}
		if (document.getElementById('phone').value=="") 
		{
			document.getElementById('phone').style.border="1px solid #EC0000";
			err=1;
		}
		if (err == 0)
		{
			//alert('Форма отправляется!');
			
			var theids, thekolvos, sendon;

			sendon="?firstname="+document.getElementById('firstname').value
			sendon=sendon+"&surname="+document.getElementById('surname').value
			sendon=sendon+"&email="+document.getElementById('email').value
			sendon=sendon+"&phone="+document.getElementById('phone').value

			savetovar2();
			
				//alert('ID = '+theids);
				//alert('KOLVO = '+thekolvos);
				
				//$("#korzina_spisok_full").ajaxStart(function(){
				
					//$(this).html('Идёт обработка заказа... Пожалуйста, подождите...');
					
					//$("#statusbox").hide('slow');
					//$(this).show('slow');
				 //});
				/*
				$("#loading").ajaxStop(function(){
				  $(this).html($(this).attr('value'));
				  $(this).hide('slow');
				 });
				 */
				$.ajax({
				   type: "POST",
				   url: "/korz_zakaz.php"+sendon,
				   
				   success: function(msg){
					   //$("#korzina_spisok_full").html(msg);
						if (msg=='nodata')
						{
							alert('Заполнены не все поля');
						}
						if (msg=='ok')
						{
							alert('Ваш заказ принят!');
						}
						if (msg=='errmail')
						{
							alert('Не верный адрес электронной почты (E-mail).');
						}
						//alert(msg);
						make_korzina();
						document.getElementById('korzina').style.display='none';						
				   },
				   error: function() {
					 $("#korzina_spisok_full").html('Синхронизация прошла неудачно!');
				   }
				 });


			
			
		}
		else
		{
			alert('Заполнены не все поля!');
		}
	  }
	  else
	  {
		alert('В Вашей корзине нет товаров!');
	  }
		
	}
	
