     function clear()
     {
     		document.getElementById("big_b").value = "1";
			document.getElementById("small_b").value = "0";
			document.getElementById("big_b_koz").value = "0";
			document.getElementById("small_b_koz").value = "0";
			
			$("#color-down").css({"background-color" : "cc0000"});				
			document.getElementById("big_b_win").value = "1";
			document.getElementById("small_b_win").value = "0";  	
			
			document.getElementById("band-type").value = "1";			
			document.getElementById("plen-type").value = "1";
			document.getElementById("plen-p").value = "0";
     		     		
			$('#posit_plen_form').trigger( 'reset' );
			$("#rgsp2").css({"display" : "none"});
		    $("#rgsp3").css({"display" : "none"});	
		    $("#rgwp2").css({"display" : "none"});
		    $("#rgwp3").css({"display" : "none"});
		    
		    $("#apDiv1").css({"display" : "none"});	
			
     }
     
     function GetSumma(num)
     {
     	  $.ajax({    
                   url: 'summa_min.php',
	             //  data: 'ind='+index+'&hide='+hide.value,
	               cache: false,
                   dataType: 'html',
                   type: 'POST',	
                   success: function (html) {
                   	  if (num == 1)
                   	  {
                   	  	$("#itog-summa #o5sum").html(html);
                   	    $("#summa-zakaza #itogo").html(html);
                   	  }
                   	  else
                   	    if (num == 2)
                   	    {
                   	       $("#summa-zakaza #itogo").html(html);
                   	    }
                   },
	               error: function(){
					 $("#itog-summa #o5sum").html("ошибка");
                   },
                   beforeSend: function(){
	                // $("#itog-summa #o5sum").html("считаю...");
                   }
            });
     }
     
     
     
     function delete_row(obj) 
     {
       
       var index = $("#text_other #order_table .del").index(obj);
       var tip = $("#text_other #order_table .del:eq("+index+")").attr("id");
       
       if (tip == 0)
       {
       	  var hide = $("#text_other #order_table :hidden").get(index);       	
       }
       else {var hide = "";}   
       
       

       var id = $("#text_other #order_table tr:eq("+(index+1)+") td:eq(0)").text();
       var name = $("#text_other #order_table tr:eq("+(index+1)+") td:eq(1)").text();
       var price = $("#text_other #order_table tr:eq("+(index+1)+") td:eq(2)").text(); 
       
      
       
       var row = obj.parentNode.parentNode;
       $(row).detach();

       
       $.ajax({    
                   url: 'del_item.php',
	               data: 'ind='+index+'&hide='+hide.value+'&type='+tip+'&id='+id+'&name='+name+'&price'+price,
	               cache: false,
                   dataType: 'html',
                   type: 'POST',	
                   success: function (data) {
                   	  GetSumma(1);
                   	  $("#text_other #stat").empty();
                   	  $("#text_other #stat").html(data);
                   },
	               error: function(){
					  $("#text_other #stat").html("ошибка");
                   },
                   beforeSend: function(){
	                  $("#text_other #stat").html("удаляю...");
                   }
            }); 
            
            
            
     }
  
 
     function Show(num)
	 {
		 if (num == 1)
		 {
		    $("#rgsp2").css({"display" : "none"});
		    $("#rgsp3").css({"display" : "none"});	
		    $("#rgwp2").css({"display" : "none"});
		    $("#rgwp3").css({"display" : "none"});	
		 }
		 else
		    if (num == 2)
			{
				$("#rgsp2").css({"display" : "block"});
		        $("#rgsp3").css({"display" : "none"});	
		        $("#rgwp2").css({"display" : "block"});
		        $("#rgwp3").css({"display" : "none"});
			}
			else
			   if (num == 3)
			   {
				   $("#rgsp3").css({"display" : "block"});
		           $("#rgsp2").css({"display" : "none"});	
		           $("#rgwp3").css({"display" : "block"});
		           $("#rgwp2").css({"display" : "none"});
			   }
	 }
	 
	 
   function Rel(type, type_plen, big_b, small_b, big_b_koz, small_b_koz)
   {
	   $.ajax({    
                   url: 'coast.php',
	               data: 'type='+type+'&type_plen='+type_plen+'&big_b='+big_b+'&small_b='+small_b+'&big_b_koz='+big_b_koz+'&small_b_koz='+small_b_koz,
	               cache: false,
                   dataType: 'html',
                   type: 'POST',	
                   success: function (html) {
                   	  $("#itog-coast").html(html);
                   },
	               error: function(){
					  $("#itog-coast").html("Ошибка");
                   },
                   beforeSend: function(){
	                  $("#itog-coast").html("считаю");
                   }	
        });
   }
   
   function finish()
   {
   	  $("#message").css({"display" : "none"});
   	  $("#pole-add").css({"display" : "block"});
   	  $("#left-info #busket #summa-zakaza").css({"background-color" : "#e1e1e1"});
   	  $("#summer").click();
   	  $("#itog-coast").html("Итого: 0 руб.");
   	  clear();
   }
   
   function Add(type, type_plen, plen_p, osnovanie, big_b, small_b, big_b_koz, small_b_koz, id)
   {
	   $.ajax({    
                   url: 'basket.php',
	               data: 'type='+type+'&type_plen='+type_plen+'&plen_p='+plen_p+'&osnovanie='+osnovanie+'&big_b='+big_b+'&small_b='+small_b+'&big_b_koz='+big_b_koz+'&small_b_koz='+small_b_koz+'&id='+id,
	               cache: false,
                   dataType: 'html',
                   type: 'POST',	
                   success: function (html) {
                   	  $("#gobask").html('<a href="index.php?module=catalog&order">перейти в корзину</a>');
                   	  $("#message").css({"background-color" : "#59DF00", "color" : "#FFF", "font-weight" : "bold"});
                   	  $("#message").html("Добавлено в корзину!");                   	  
                   	  $("#left-info #busket #summa-zakaza").css({"background-color" : "#ff9900"});
                   	  GetSumma(2);
                   	  
                   	  setTimeout("finish()", 2000);
                   	  
                   	  $("#status-zakaz").html(html);
                   	  
                   },
	               error: function(){
	               	  $("#message").css({"background-color" : "red", "color" : "#FFF", "font-weight" : "bold"});
					  $("#message").html("Ошибка");
                   },
                   beforeSend: function(){
                   	  $("#message").css({"display" : "block", "background" : "#ffffd7", "color" : "#000", "font-weight" : "normal"});                   	  
	                  $("#message").html("добавляю...");
                   }	
        });
        
   }
   
  
     $(document).ready(function(){
     	
     	
     	$(".color").click(function(){
     		var st =  $(this).css("background-color");     		
     		$("#color-down").css({"background-color" : st});
     	});
		
		
		$("#summer").click(function(){
			$("#color-down").css({"display" : "none"});
			var type = document.getElementById("band-type");			
			type.value = 1;	
			$("#winter-info").css({"display" : "none"});
			$("#summer-info").css({"display" : "block"});		
		});
		
		$("#winter").click(function(){
			$("#color-down").css({"display" : "block"});
			var type = document.getElementById("band-type");
			type.value = 2;
			$("#winter-info").css({"display" : "block"});
			$("#summer-info").css({"display" : "none"});	
		});
		
		
		$("#rgw2").click(function(){
			
			$("#apDiv1").css({"display" : "block"});
			Show(2);	
		});
		
		$("#rgw3").click(function(){
			$("#apDiv1").css({"display" : "block"});
			Show(3);		
		});
		
		$("#rgw1").click(function(){
			$("#apDiv1").css({"display" : "none"});	
			Show(1);
		});
		
		$("#rgs2").click(function(){
			$("#apDiv1").css({"display" : "block"});
			Show(2);		
		});
		
		$("#rgs3").click(function(){
			$("#apDiv1").css({"display" : "block"});
			Show(3);		
		});
		
		$("#rgs1").click(function(){
			$("#apDiv1").css({"display" : "none"});	
			Show(1);	
		});		
		
		$(".position-plen .left").click(function(){			
			$("#apDiv1").css({"margin-left" : "5px"});
	    });
		
		$(".position-plen .right").click(function(){			
			$("#apDiv1").css({"margin-left" : "135px"});
	    });
		
		$(".position-plen .centr").click(function(){			
			$("#apDiv1").css({"margin-left" : "70px"});
	    });
		
		$(".position-plen a").click(function(){			
			$(".position-plen a").css({"font-weight" : "normal"});
			$(this).css({"font-weight" : "bold"});
			
			var index = $(".position-plen a").index(this);
			var plen_p = document.getElementById("plen-p");
			plen_p.value = index;		
		});
		
		
		$("#other-info :radio").click(function(){
			if (this.value == 3) {$("#apDiv1").css({"background-color" : "#b0df0b"});}
			if (this.value == 2) {$("#apDiv1").css({"background-color" : "#F0F0F0"});}
			
			var hide_plen = document.getElementById("plen-type");
			hide_plen.value = this.value;
		});
		
		
		$(".tz .minus").click(function(){			
			var index = $(".tz .minus").index(this);
			var inp = $(".tz input").get(index);			
			if (inp.value > 0) {inp.value--;}			
		});
		
		$(".tz .plus").click(function(){			
			var index = $(".tz .plus").index(this);
			var inp = $(".tz input").get(index);
			if (inp.value < 99) {inp.value++;}
		});
		
		
		
		$("#add-new-band").click(function(){				
			
			var type = document.getElementById("band-type");			
			var type_plen = document.getElementById("plen-type");
			var plen_p = document.getElementById("plen-p");
			var id = document.getElementById("band-id");
			
			if (type.value == 1)
			{
				var big_b = document.getElementById("big_b");
				var small_b = document.getElementById("small_b");
				var big_b_koz = document.getElementById("big_b_koz");
				var small_b_koz = document.getElementById("small_b_koz");
				
			//	if (isNaN(big_b) || isNaN(small_b) || isNaN(big_b_koz) || isNaN(small_b_koz)) 
			//	{
			//		alert("Количество бандан должно быть записано числом!");
			//	}
			//	else 
			//	{
					$("#pole-add").css({"display" : "none"});
					Add(type.value, type_plen.value, plen_p.value, 0, big_b.value, small_b.value, big_b_koz.value, small_b_koz.value, id.value);
			//	}
								
				
			}
			else
			if (type.value == 2)
			{
				var osnovanie = $("#color-down").css("background-color");				
				var big_b_win = document.getElementById("big_b_win");
				var small_b_win = document.getElementById("small_b_win");				
				
			/*	if (isNaN(big_b_win) || isNaN(small_b_win)) 
				{
					alert("Количество бандан должно быть записано числом!");
				}
				else 
				{*/
					$("#pole-add").css({"display" : "none"});
				    Add(type.value, type_plen.value, plen_p.value, osnovanie, big_b_win.value, small_b_win.value, 0, 0, id.value);
				//}
			}
			 
			 
		});
		
		
		$("#rel").click (function(){
			
			var type = document.getElementById("band-type");			
			var type_plen = document.getElementById("plen-type");
			
			if (type.value == 1)
			{
				var big_b = document.getElementById("big_b");
				var small_b = document.getElementById("small_b");
				var big_b_koz = document.getElementById("big_b_koz");
				var small_b_koz = document.getElementById("small_b_koz");
								
				Rel(type.value, type_plen.value, big_b.value, small_b.value, big_b_koz.value, small_b_koz.value);
			}
			else
			if (type.value == 2)
			{
				var big_b_win = document.getElementById("big_b_win");
				var small_b_win = document.getElementById("small_b_win");				
				
				Rel(type.value, type_plen.value, big_b_win.value, small_b_win.value, 0, 0);
			}
			
		});
		
		
		
		$("#text_other #order_table .str").hover(
	          function(){ //over
	               $(this).css({"background-color" : "#ffffd7"});
			  },
              function(){ //out
	               $(this).css({"background-color" : "#F2F1EF"});
			  }
		);
		
		
		
		
		
		$("#text_other #order_table #ref").click(function(){
			
			
            var summa = 0;
            var flag = 0;
            var arr = new Array()
            
            var j = 0;
			$('#order_table input[type="text"]').each(function(){
				
				
				var index = $('#order_table input[type="text"]').index(this);
				var id = $("#text_other #order_table tr:eq("+(index+1)+") td:eq(0)").text();
				var name = $("#text_other #order_table tr:eq("+(index+1)+") td:eq(1)").text();
				var price = $("#text_other #order_table tr:eq("+(index+1)+") td:eq(2)").text();

				var type = $("#text_other #order_table .del:eq("+index+")").attr("id");			
				
				var num = $(this).val();				
				
				if (!isNaN(num) && (num != 0))
				{
					 if ($(this).hasClass("mini_err"))
					 {
					 	$(this).removeClass("mini_err");
					 }

					 var temp_str = new Array (type, id, name, $(this).val());
					 
					 arr[j] = temp_str;
			 
					 j++;
				}
				else
				{
					$(this).addClass("mini_err");
					flag = 1;
				}
				
				if (flag == 0) {summa += (num * price);}			
			});
			
						
			
			if (flag == 0) 
			{
				$("#itog-summa #o5sum").text(summa);
				$("#summa-zakaza #itogo").text(summa);
				
				
			    $.ajax({    
                   url: 'ref.php',
                   data: ({arr_elem : arr}),
	               cache: false,
                   dataType: 'html',
                   type: 'POST',	
                   success: function (html) {
                     $("#text_other #stat").html(html);  
                   },
                   beforeSend: function(){
                     $("#text_other #stat").html("обновляю информацию...");
                   }
                });
			}
						
		});
		
		
		
		
		
		
		$("#other-info a").click(function(){			
			return false;
		});
		
		
		
		$("#send_order_mail").click(function(){
			var fio = document.getElementById("fio");
			var mail = document.getElementById("mail");			
			
			if (fio.value == "") {alert('Не заполнено поле "Ф.И.О. или название компании"'); return false;}
			else 
			  if (mail.value == "") {alert('Не заполнено поле "Ваш E-mail"'); return false;}			
		});	
		
		
		
	
		
		$('#adresa ul a').tooltip({
           track: true,
           delay: 0,
           showURL: false,
           fade: 200
        });
        
        
        
        
        
        /* ====================== Банданы POLA ========================= */
        
        
     	$("#color-place-pola .color").click(function(){
     		var st =  $(this).css("background-color");     		
     		$(".color-pola").css({"background-color" : st});
     	});
        
        
        
        
        
        
        
		
		
     	
     });

