

function display_data(id) {  
  
    xmlhttp=GetXmlHttpObject(); 
    if (xmlhttp==null) { 
        alert ("Your browser does not support AJAX!"); 
        return; 
    }  
    var url="/js/slider/ajax.php";  //zde je co se má zobrazit 
    url=url+"?id_subcategory="+id; 
    xmlhttp.onreadystatechange=function() { 
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") { 
       //  ošetření tabulky

             // výpis dat       
                
                inc("/js/slider/content.table.php?id_size=" + id);
                inc("/js/slider/content.table.tr2.php?id_size=" + id);
                 setTimeout(function() {
                $('div.product_table').hide(function(){$('div#product_table').show(function(){
               
                        
                       $('#demotable1 tbody').append(tr); 
                       if(tr2!=null){ $('#demotable1 tbody').append(tr2);}
                       
                         $('#demotable1').tableFilter(options); 
                          $('#footer_link').fadeOut(800);
                   
                
                });}); }   ,500);
                 

                document.getElementById('product_table').innerHTML=xmlhttp.responseText;
                              
                                          
                               //ošetření zobrazení obrázku po najetí na sloupce s rozměry
                  $("table").delegate('td','mouseover mouseleave', function(e) {
                      var i = $(this).prevAll('td').length;
                      if (e.type == 'mouseover') {
                       if(i<$('.numberOfSizes').val()){
                              $('#select' + i).addClass("select" + i);
                              $('#select' + i).addClass("betterhover");
                               $('.col' + (i+1)).addClass("betterhover");
                        $('#picto').addClass("showPict");
                           $('#ppicto').addClass("pshowPict" + i);}
                           var proID = $('.proID').val();
                            var proID2 = $('.proID2').val();
                           $('#ppicto').css({'background-image' : 'url("/imgs/prod_variant/'+proID2+'/'+proID+(i+1)+'.gif")', 'width' : '400px', 'background-repeat' : 'no-repeat', 'background-position': '0px 1px'});
                        $(this).parent().addClass("hover");
                        $("colgroup").eq($(this).index()).addClass("hover");
                      } else {
                        $(this).parent().removeClass("hover");
                        if(i<$('.numberOfSizes').val()){
                               var proID = $('.proID').val();
                            $('#ppicto').css({'background-image' : 'url("/imgs/prod_variant/'+proID2+'/'+proID+'.gif")', 'width' : '400px', 'background-repeat' : 'no-repeat', 'background-position': '0px 1px'});
                            $('#ppicto').removeClass("pshowPict" + i); 
                            $('#picto').removeClass("showPict");
                            $('#select' + i).removeClass("select" + i); 
                             $('#select' + i).removeClass("betterhover"); 
                              $('.col' + (i+1)).removeClass("betterhover"); 
                        }
                         
                        $("colgroup").eq($(this).index()).removeClass("hover");
                      }
                  });   
                  
                  // Initialise Plugin
                  var options = {
                          clearFiltersControls: [$('.cleanfilters')],
                          matchingRow: function(state, tr) {
                          if (!state || !state.id) { return true; }
              					   var val =  tr.children('td:eq(2)').text();
              					   switch (state.id) {
              						    case 'onlyyes': return state.value !== 'true' || val === 'yes';
              						    case 'onlyno': return state.value !== 'true' || val === 'no';
              						    default: return true;
              					   }
                      }
                  };


              
             
        //AŽ SE SE JEDNÁ O OŠETŘENÍ TABULKY 
        
            
         
        } 
    } 
    xmlhttp.open("GET",url,true); 
    xmlhttp.send(null); 
} 

//načtení dat z databáze po kliknutí na podkategorii
function display_data2(id) {  
  
    xmlhttp=GetXmlHttpObject(); 
    if (xmlhttp==null) { 
        alert ("Your browser does not support AJAX!"); 
        return; 
    }  
    var url="/js/slider/ajax2.php";  //zde je co se má zobrazit 
    url=url+"?id_subcategory="+id; 
    xmlhttp.onreadystatechange=function() { 
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") { 
       //  ošetření tabulky

             // výpis dat       
                
                inc("/js/slider/content.table2.php?id_size=" + id);
                            $('div.product_table').hide(function(){$('div#product_table').show(function(){
               
                        
                       $('#demotable1 tbody').append(tr);  $('#demotable1').tableFilter(options); 
                          $('#footer_link').fadeOut(800);
                   
                
                });});
                 

                document.getElementById('product_table').innerHTML=xmlhttp.responseText;
                              
                                          
                               //ošetření zobrazení obrázku po najetí na sloupce s rozměry
                  $("table").delegate('td','mouseover mouseleave', function(e) {
                      var i = $(this).prevAll('td').length;
                      if (e.type == 'mouseover') {
                       if(i<$('.numberOfSizes').val()){
                              $('#select' + i).addClass("select" + i);
                              $('#select' + i).addClass("betterhover");
                               $('.col' + (i+1)).addClass("betterhover");
                        $('#picto').addClass("showPict");
                           $('#ppicto').addClass("pshowPict" + i);}
                           var proID = $('.proID').val();
                            var proID2 = $('.proID2').val();
                           $('#ppicto').css({'background-image' : 'url("/imgs/prod_variant/'+proID2+'/'+proID+(i+1)+'.gif")', 'width' : '400px', 'background-repeat' : 'no-repeat', 'background-position': '0px 1px'});
                        $(this).parent().addClass("hover");
                        $("colgroup").eq($(this).index()).addClass("hover");
                      } else {
                        $(this).parent().removeClass("hover");
                        if(i<$('.numberOfSizes').val()){
                               var proID = $('.proID').val();
                            $('#ppicto').css({'background-image' : 'url("/imgs/prod_variant/'+proID2+'/'+proID+'.gif")', 'width' : '400px', 'background-repeat' : 'no-repeat', 'background-position': '0px 1px'});
                            $('#ppicto').removeClass("pshowPict" + i); 
                            $('#picto').removeClass("showPict");
                            $('#select' + i).removeClass("select" + i); 
                             $('#select' + i).removeClass("betterhover"); 
                              $('.col' + (i+1)).removeClass("betterhover"); 
                        }
                         
                        $("colgroup").eq($(this).index()).removeClass("hover");
                      }
                  });   
                  
                  // Initialise Plugin
                  var options = {
                     clearFiltersControls: [$('.cleanfilters')],
                          matchingRow: function(state, tr) {
                          if (!state || !state.id) { return true; }
              					   var val =  tr.children('td:eq(2)').text();
              					   switch (state.id) {
              						    case 'onlyyes': return state.value !== 'true' || val === 'yes';
              						    case 'onlyno': return state.value !== 'true' || val === 'no';
              						    default: return true;
              					   }
                      }
                  };
          
              
                         
        //AŽ SE SE JEDNÁ O OŠETŘENÍ TABULKY  
        } 
    } 
    xmlhttp.open("GET",url,true); 
    xmlhttp.send(null); 
}


//funkce pro zobrazení t
function buy(id,id_size,eshopPrice) {  
  
    xmlhttp=GetXmlHttpObject1(); 
    if (xmlhttp==null) { 
        alert ("Your browser does not support AJAX!"); 
        return; 
    }  
    var url="/js/slider/buy_ajax.php";  //zde je co se má zobrazit
    url=url+"?id_size="+id_size+"&id="+id; 
    xmlhttp.onreadystatechange=function() { 
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") { 
                     $('div#footer_link').fadeOut(300,function(){$('div#footer_link').fadeIn(1000);  });
             document.getElementById('footer_link').innerHTML=xmlhttp.responseText;
            				$('a#demand_info_open').click(function () {
					dh = $(document).height();
					wh = $(window).height();
					mh = $('#demand-dialog').height();
					
					dt = $(document).scrollTop();
					
					$('#overlay').height(dh);
					$('#overlay').fadeIn();
					$('#demand-dialog').css('top', dt+(wh/4)+"px");
					$('#demand-dialog').fadeIn();
					return false;
				});
				
				$('#demand-dialog .dialog-close').click(function () {
					$('#overlay').fadeOut();
					$('#demand-dialog').fadeOut();
				});
             
             $('.count0').keyup(function() {
             showResult($('.height0').val(), $('.count0').val(),0, $('.productID').val(),eshopPrice) ;
               
                   });
              $('.height0').keyup(function() {
             showResult($('.height0').val(), $('.count0').val(),0, $('.productID').val(),eshopPrice);
                                                    var zobraz = 0;
                   var barLength =  parseInt($('.bar_length').val());
                   
                   for (i=0;i<=199;i++)  {             
                    if (document.getElementById("height"+i)){
                       var heightValue = parseInt(document.getElementById("height"+i).value); 
 
                         
                          for (k=0;k<=199;k++)  { 
                            if (document.getElementById("height"+k)&&k!=i){
                              var heightValue2 = parseInt(document.getElementById("height"+k).value);
                                if(heightValue==heightValue2){ 
                               
                                  zobraz += 1;
                                } 
                              } 
                            }
                       }
                    }
       
                   if(zobraz>0) {$('#make_order').fadeOut(300,function(){$('div#make_order_note').fadeIn(1000);  });}else{$('div#make_order_note').fadeOut(300,function(){$('#make_order').fadeIn(1000); });}
                   
                  
              });  showResult($('.height0').val(), $('.count0').val(),0, $('.productID').val(),eshopPrice);              
          } 
          
    } 
    xmlhttp.open("GET",url,true); 
    xmlhttp.send(null); 
} 
function buy_simple(id,id_size,eshopPrice) {  
  
    xmlhttp=GetXmlHttpObject1(); 
    if (xmlhttp==null) { 
        alert ("Your browser does not support AJAX!"); 
        return; 
    }  
    var url="/js/slider/buy_simple_ajax.php";  //zde je co se má zobrazit
    url=url+"?id_size="+id_size+"&id="+id; 
    xmlhttp.onreadystatechange=function() { 
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") { 
                     $('div#footer_link').fadeOut(300,function(){$('div#footer_link').fadeIn(1000);  });
             document.getElementById('footer_link').innerHTML=xmlhttp.responseText;
             
             $('.count0').keyup(function() {
             showResult($('.height0').val(), $('.count0').val(),0, $('.productID').val(),eshopPrice) ;
               
                   });
              $('.height0').keyup(function() {
             showResult($('.height0').val(), $('.count0').val(),0, $('.productID').val(),eshopPrice);
                                                    var zobraz = 0;
                   var barLength =  parseInt($('.bar_length').val());
                   
                   for (i=0;i<=199;i++)  {             
                    if (document.getElementById("height"+i)){
                       var heightValue = parseInt(document.getElementById("height"+i).value); 
 
                         
                          for (k=0;k<=199;k++)  { 
                            if (document.getElementById("height"+k)&&k!=i){
                              var heightValue2 = parseInt(document.getElementById("height"+k).value);
                                if(heightValue==heightValue2){ 
                               
                                  zobraz += 1;
                                } 
                              } 
                            }
                       }
                    }
       
                   if(zobraz>0) {$('#make_order').fadeOut(300,function(){$('div#make_order_note').fadeIn(1000);  });}else{$('div#make_order_note').fadeOut(300,function(){$('#make_order').fadeIn(1000); });}
                   
                  
              });  showResult($('.height0').val(), $('.count0').val(),0, $('.productID').val(),eshopPrice);              
          } 
          
    } 
    xmlhttp.open("GET",url,true); 
    xmlhttp.send(null); 
} 
 //funkce pro zobrazení t
function demand(id,id_size,eshopPrice) {  
  
    xmlhttp=GetXmlHttpObject1(); 
    if (xmlhttp==null) { 
        alert ("Your browser does not support AJAX!"); 
        return; 
    }  
    var url="/js/slider/demand_ajax.php";  //zde je co se má zobrazit
    url=url+"?id_size="+id_size+"&id="+id; 
    xmlhttp.onreadystatechange=function() { 
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") { 
                    

		
          $('div#footer_link').fadeOut(300,function(){$('div#footer_link').fadeIn(1000);  });
             document.getElementById('footer_link').innerHTML=xmlhttp.responseText;
             
		
	
				$('a#demand_info_open').click(function () {
					dh = $(document).height();
					wh = $(window).height();
					mh = $('#demand-dialog').height();
					
					dt = $(document).scrollTop();
					
					$('#overlay').height(dh);
					$('#overlay').fadeIn();
					$('#demand-dialog').css('top', dt+(wh/4)+"px");
					$('#demand-dialog').fadeIn();
					return false;
				});
				
				$('#demand-dialog .dialog-close').click(function () {
					$('#overlay').fadeOut();
					$('#demand-dialog').fadeOut();
				});
			   
          } 
          
    } 
    xmlhttp.open("GET",url,true); 
    xmlhttp.send(null); 
} 

 function CheckValueMax(input, max) {
    var value = Number(input.value);
    if (NaN == value || input.value>max) { //it is not a number or is too big - revert
        input.value = LastGood;
    } else { //it is ok, save it as the last good value
        LastGood = value;
    }
}
function CheckValueMin(input, min, eshopPrice) {
var LastGood2 = min;
    var value = Number(input.value);
    if (NaN == value || input.value<min) { //it is not a number or is too big - revert
        input.value = LastGood2;
        showResult($('.height0').val(), $('.count0').val(),0, $('.productID').val(), eshopPrice);
    } else { //it is ok, save it as the last good value
        LastGood2 = value;
        
    }
} 
  
  function inc(filename)
                {
                var body = document.getElementsByTagName('head').item(0);
                script = document.createElement('script');
                script.src = filename;
                script.type = 'text/javascript';
                body.appendChild(script)
                }  
                
  function GetXmlHttpObject1() { 
    var xmlhttp=null; 
    try { 
        // Firefox, Opera 8.0+, Safari 
        xmlhttp=new XMLHttpRequest(); 
    } 
    catch (e) { 
        // Internet Explorer 
        try { 
            xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
        } 
        catch (e) { 
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
        } 
    } 
    return xmlhttp; 
}
 
function GetXmlHttpObject() { 
    var xmlhttp=null; 
    try { 
        // Firefox, Opera 8.0+, Safari 
        xmlhttp=new XMLHttpRequest(); 
    } 
    catch (e) { 
        // Internet Explorer 
        try { 
            xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
        } 
        catch (e) { 
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
        } 
    } 
    return xmlhttp; 
}
   
    function endRequest(sender, args) {
        window.scrollTo(0, 0);
    }

function showResult(str,ks,id,productID,eshopPrice)
{
if(eshopPrice==0)
  {
  document.getElementById("price" + id).innerHTML="Cena dohodou";
  return;
  }
else if (str.length==0)
  { 
  document.getElementById("price" + id).innerHTML="Zadejte délku profilu  a počet ks a my Vám spočítáme cenu";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        var retezec = xmlhttp.responseText;
                  
                       var pole = retezec.split(",");
       document.getElementById("price"+id).innerHTML= "Cena položky je "+number_format(parseFloat(pole[0]), 2, ',', ' ')+" Kč";
      if(pole[1]==null){ document.getElementById("priceHidden"+id).value=pole[0];}else{  var celkova_cena=parseFloat(pole[0])+parseFloat(pole[1])+parseFloat(pole[2]);     document.getElementById("priceHidden"+id).value=celkova_cena;};

        if(document.getElementById("remains")){showRemains($('.bar_length').val(),$('.productID').val());} 
        document.getElementById("priceHidden").innerHTML="<img src='/imgs/ajax-loader.gif' id='loading' style='display:none;'/>";
        
     $("img#loading").show(); 
         
            setTimeout("$('img#loading').hide()", 1000);
      setTimeout("showPrice($('#theValue').val())", 1010);   
                  
        
    }
  }
  
xmlhttp.open("GET","/js/slider/livesearch.php?delka="+str+"&ks="+ks+"&productID="+productID,true);
xmlhttp.send();
}
function showResultBasket(str,ks,id,productID,eshopPrice)
{
  
 if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5       
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {         
    
     var retezec = xmlhttp.responseText;
                  
                       var pole = retezec.split(",");
        if(parseFloat(pole[0])==0){ document.getElementById("price"+id+"_"+productID).innerHTML="Cena dohodou";}else{
    
        document.getElementById("price"+id+"_"+productID).innerHTML= "<strong>" + number_format(parseFloat(pole[0]), 2, ',', ' ')+"</strong> Kč";
       
       
       
       }
       document.getElementById("priceHidden"+id+"_"+productID).value=pole[0];

       var cena2 =  parseFloat(pole[0])*1.2;
       
               
                    
             if(document.getElementById("priceCP_"+id+"_"+productID)){
     
      document.getElementById("priceCP_"+id+"_"+productID).value=pole[1];
      
      } 
     //   document.getElementById("price_vat"+id+"_"+productID).innerHTML= number_format(cena2, 0, ',', ' ')+" Kč";
      
     
     // document.getElementById("priceHidden2_"+id+"_"+productID).value=cena2;
        
           showRemainsBasket($('.bar_length'+productID).val(),productID);
      
        document.getElementById("priceHidden").innerHTML="<img src='/imgs/ajax-loader.gif' id='loading' style='display:none;'/>";
       //  document.getElementById("priceHidden2").innerHTML="<img src='/imgs/ajax-loader.gif' id='loading2' style='display:none;'/>";
     $("img#loading").show(); 
    //   $("img#loading2").show();          
            setTimeout("$('img#loading').hide()", 2500);
   //         setTimeout("$('img#loading2').hide()", 2500); 
     setTimeout("showPriceBasket()", 1700);
  //   setTimeout("showPriceBasket2()", 2200);
           
       update(productID,str,ks,id);
           
showResultBasket2(str,ks,id,productID,eshopPrice);                                  
         
     
    }
  }
  
xmlhttp.open("GET","/js/slider/livesearch3.php?delka="+str+"&ks="+ks+"&productID="+productID,true);
xmlhttp.send();    
}
function showResultBasket2(str,ks,id,productID,eshopPrice)
{

  
   if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5       
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
         var retezec = xmlhttp.responseText;
                  
                       var pole = retezec.split(",");
          if(parseFloat(pole[0])==0){ document.getElementById("price_vat"+id+"_"+productID).innerHTML="Cena dohodou";}else{
             var cena2 =  pole[0]*1.2;
        
    
          document.getElementById("price_vat"+id+"_"+productID).innerHTML= "<strong>" + number_format(parseFloat(cena2), 2, ',', ' ')+"</strong> Kč";
     
    
       
       }
          var cena3=pole[0]*1.2;
      // alert(pole[0]+"s");


      
      document.getElementById("priceHidden2_"+id+"_"+productID).value=cena3;
           
         showRemainsBasket($('.bar_length'+productID).val(),productID);
           
        document.getElementById("priceHidden2").innerHTML="<img src='/imgs/ajax-loader.gif' id='loading2' style='display:none;'/>";
        
     $("img#loading2").show(); 
              
            setTimeout("$('img#loading2').hide()", 2500);
             
     setTimeout("showPriceBasket2()", 1700);
                                      
         
     
    }
  }
  
xmlhttp.open("GET","/js/slider/livesearch3.php?delka="+str+"&ks="+ks+"&productID="+productID,true);
xmlhttp.send();
 
}

function showRemains(barLength,productID){
  var remains = document.getElementById("remains").value;
 if (remains==1){
       
        var i = 0;
        var k = 0;
        var heights = 0;
        var count = 0;
        var counts = 0;
         var totalHeights = 0;
       for (i=0;i<=199;i++)  {
          
          if (document.getElementById("height"+i)){
            heights += document.getElementById("height"+i).value + ",";
             totalHeights += (parseInt(document.getElementById("height"+i).value)*parseInt(document.getElementById("count"+i).value));
         }
        }
          
            for (k=0;k<=199;k++)  {
              if (document.getElementById("count"+k)){
              
              counts += document.getElementById("count"+k).value + ","; 
              }  
            }

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {                  
                        var retezec = xmlhttp.responseText;
                       var pole = retezec.split(",");
                       totalHeights += parseInt(pole[3]);
        var bars = totalHeights/barLength;  
       //  if(bars<1){bars=0;}      
       if(pole[2]==0){var zobraz = "<p class='remains_note'><strong>Poznámka:</strong> Zbydou-li z řezaných tyčí odřezky, jsou účtovány a přibaleny k objednávce. Do ceny je připočítána cena materiálu (5 mm / 1 řez), který se prořeže.</p><h4>";}else{ var zobraz = "<p class='remains_note'><strong>Poznámka:</strong> Zbydou-li z řezaných tyčí odřezky, jsou účtovány a přibaleny k objednávce. Do ceny je připočítána cena materiálu (5 mm / 1 řez), který se prořeže.</p><h4><strong>Cena a délka zbylého materiálu: </strong></h4> <span id='remains_price'>" + Math.round(pole[2]*100)/100 + " Kč o celkové délce "+ pole[1]+" mm, tyčí: "+Math.round(bars*100)/100+" ("+pole[5] +" mm)</span> " }
       document.getElementById("remains_div").innerHTML= zobraz;
        
        document.getElementById("remains_input").value= pole[2];
       
    }
  }
  
xmlhttp.open("GET","/js/slider/remains.php?heights="+heights+"&counts="+counts+"&bar_length="+barLength+"&productID="+productID,true);
xmlhttp.send(); 
 
       }  

  } 
   function showRemainsNote(cena,zbytek,delka_tyce){
     
     if(cena!=null){document.getElementById("remains_div").innerHTML= " <p class='remains_note'><strong>Poznámka:</strong> Zbydou-li z řezaných tyčí odřezky, jsou účtovány a přibaleny k objednávce. Do ceny je připočítána cena materiálu (5 mm / 1 řez), který se prořeže.</p><h4><strong>Cena a délka zbylého materiálu: </strong></h4> <span id='remains_price'>" + Math.round(cena*100)/100 + " Kč o celkové délce "+ zbytek+" mm, tyčí: "+Math.round(bars*100)/100+" ("+delka_tyce +" mm)</span> ";}else{document.getElementById("remains_div").innerHTML="";} 
   
  
  }
  function showRemainsBasket(barLength,productID){
     
         for (i=0;i<=199;i++)  {
if(document.getElementById("remains"+i+"_"+productID)){
  var remains = document.getElementById("remains"+i+"_"+productID).value;
    break;  }
           }
 if (remains==1){
       
        var i = 0;
        var k = 0;
        var heights = 0;
        var count = 0;
        var counts = 0;
        var lengthInMm = 0;
        var kgPrice = 0;
        var totalKg = 0;
        var priceForMm = 0
        var remainsInKg = 0;
        var totalHeights = 0;
        var counts2 = 0;
       for (i=0;i<=199;i++)  {
          
          if (document.getElementById("height"+i+"_"+productID)){
             
            heights += document.getElementById("height"+i+"_"+productID).value + ","; 
             totalHeights += (parseInt(document.getElementById("height"+i+"_"+productID).value)*parseInt(document.getElementById("count"+i+"_"+productID).value));
            lengthInMm = document.getElementById("height"+i+"_"+productID).value*document.getElementById("count"+i+"_"+productID).value ;
            //alert (document.getElementById("height"+i+"_"+productID).value+"*"+document.getElementById("count"+i+"_"+productID).value+"="+lengthInMm);
            kgPrice = lengthInMm*(document.getElementById("kgm0_"+productID).value/1000);
            //alert ((document.getElementById("kgm0_"+productID).value/1000)+"*"+lengthInMm+"="+kgPrice);
         totalKg += kgPrice;
        
         }
        
        }
             
            for (k=0;k<=199;k++)  {
              if (document.getElementById("count"+k+"_"+productID)){
              
              counts += document.getElementById("count"+k+"_"+productID).value + ","; 
              counts2 += parseInt(document.getElementById("count"+k+"_"+productID).value); 
              }  
            }
          
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {  
            
              var retezec = xmlhttp.responseText;
                  
                       var pole = retezec.split(",");
        
         totalHeights += parseInt(pole[3]);
        var bars = Math.round((totalHeights/barLength)*100)/100;  
        //if(bars<1){bars=0;} 
        var cuttingParts = pole[6].split("=");
  
        var remainsAndBars = pole[4].split("-");           
   //    document.getElementById("remains_div"+productID).innerHTML= "Cena zbylého materiálu je:<span id='remains_price"+productID+"'>" + Math.round(pole[2]*100)/100 + " Kč o celkové délce "+ pole[1] +" mm - celkem tyčí: "+bars+" ("+pole[5] +" mm)</span>";
        if(document.getElementById("remains_div"+productID)){
           if(pole[2]!=0){   document.getElementById("remains_td"+productID).innerHTML = "Cena a délka zbytého materiálu";
          document.getElementById("remains_div"+productID).innerHTML= "<span id='remains_price"+productID+"'>" + Math.round(pole[2]*100)/100 + " Kč ("+ pole[1] +" mm ), tyčí: "+bars+"</span>";
          }else{
           document.getElementById("remains_td"+productID).innerHTML = "";
          document.getElementById("remains_div"+productID).innerHTML= "";}

          }
        
       
       
        var ks = parseFloat(pole[2]);
               
        document.getElementById("remains_input0_"+productID).value=pole[2];
        document.getElementById("remains_inputs0_"+productID).value=pole[2];       
        var price = removeSpaces(document.getElementById("price0_"+productID).innerHTML);
         price = price.replace(",", ".");  
        priceForMm = (document.getElementById("height0_"+productID).value*document.getElementById("count0_"+productID).value)/price;
        
        var price2 = (parseFloat(pole[0])/priceForMm); 
          //alert(document.getElementById("kgm0_"+productID).value) ;
        remainsInKg = price2*(document.getElementById("kgm0_"+productID).value/1000);
      //  alert (remainsInKg);
        totalKg += remainsInKg;      
        //alert (totalKg);
        document.getElementById("kg_input0_"+productID).value=totalKg; 
        updateRemain(productID,ks,totalKg, remainsAndBars, cuttingParts); 
        setTimeout(function() {
          $('span.basket_pieces').html(counts2+" Ks"); 
        }, 1600);
        
        
    }  
  }
  
xmlhttp.open("GET","/js/slider/remains2.php?heights="+heights+"&counts="+counts+"&bar_length="+barLength+"&productID="+productID,true);
xmlhttp.send(); 
 
       }  

  } 
 
   

  
  
                
   function showPrice(id){
 
 if (id==0){ var newPrice = parseFloat(document.getElementById("priceHidden0").value);
   }else{
           var i = 0;
           var newPrice = 0;
         
                                                                                                                                                                                                                                                                                                                                           
  for (i=0;i<=199;i++)  {

  if (document.getElementById("priceHidden"+i)){
   newPrice += parseFloat(document.getElementById("priceHidden"+i).value);   
         }
        }  
       } 
    if (document.getElementById("remains")){   newPrice += parseFloat(document.getElementById("remains_input").value);   }
        if(isNaN(newPrice)){document.getElementById("priceHidden").innerHTML = "- zadejte prosím všechny rozměry a ks abychom Vám mohli spočítat celkovou cenu - ";}else{document.getElementById("priceHidden").innerHTML = number_format(newPrice, 2, ',', ' ');}         
} 
   
function showPriceBasket(){
          var newPrice2 = 0;
              var cenaDohodou = 0;
              var heights = 0;
              var ccps =0;
              var range =0;
        //  var totalKg2 = 0;
         //  alert (getElementsByName('productID[]').value);
        for (k=0; k<1999; k++)   {   //omezení  pro ID výroku do 1999
        for (i=0; i<99; i++){
        if(document.getElementById("range_"+i+"_"+k)){
          range++;
        }
        
           if(document.getElementById("priceCP_"+i+"_"+k)){
            var ccp=document.getElementById("priceCP_"+i+"_"+k).value;
             var cccp = ccp.replace(",", ".");  
      ccps +=  parseFloat(cccp);
      }
          var productElement = document.getElementById("price"+i+"_"+k);           
    if (productElement != null){
   //alert (i +" "+ k+" " + document.getElementById("count"+i+"_"+k).value+" - "+ document.getElementById("height"+i+"_"+k).value +"="+document.getElementById("remains_input0_"+k).value );
                      // alert (removeSpaces(productElement.innerHTML));
                       if(productElement.innerHTML=="Cena dohodou"){
                       var oldPrice = 0;
                      
                       }else{var oldPrice = removeSpaces(productElement.innerHTML);}
                      
                        oldPrice = oldPrice.replace(",", ".");   
   newPrice2 += parseFloat(oldPrice); 
                  
     if (document.getElementById("remains0_"+k).value==1&&i==0){  
              // alert (i +" "+ k);
          
             newPrice2 += parseFloat(document.getElementById("remains_input0_"+k).value); 
             // var oldKg =  document.getElementById("kg_input0_"+k).value; 
              //totalKg2 += parseFloat(oldKg);
              }  
         }                                                                                 
          
        
          }   
       
         }                    
                                if(range==0){$('tr#range_tr').remove();}
                                if (document.getElementById("range_price")){
         if(range!=0){
          newPrice2 += 200; 
            }
     }
           
      
      if(document.getElementById("cutting-price-vat1")){
      
      document.getElementById("cutting-price-vat1").innerHTML="<strong>"+number_format(parseFloat(ccps), 2, ',', ' ')+"</strong> Kč";
    if(ccps==0){$('tr#cutting_tr').hide();}
          newPrice2 += parseFloat(ccps);
      }

    
        if(isNaN(newPrice2)){document.getElementById("priceHidden").innerHTML = "- zadejte prosím všechny rozměry a ks abychom Vám mohli spočítat celkovou cenu - ";}else{
        
        $('strong.basket_price').html(number_format(newPrice2, 0, ',', ' ') + " Kč");

        document.getElementById("priceHidden").innerHTML = "<strong>" + number_format(newPrice2, 0, ',', ' ') + " Kč </strong>";}         
       // document.getElementById("total_kg").value  = totalKg2; 
}

         function showPriceBasket2(){
    
       var newPrice2 = 0;
              var cenaDohodou = 0;
              var ccps=0;
        //  var totalKg2 = 0;
         //  alert (getElementsByName('productID[]').value);
        for (k=0; k<1999; k++)   {   //omezení  pro ID výroku do 1999
        for (i=0; i<99; i++){
                          if(document.getElementById("priceCP_"+i+"_"+k)){
            var ccp=document.getElementById("priceCP_"+i+"_"+k).value;
             var cccp = ccp.replace(",", ".");  
      ccps +=  parseFloat(cccp);
      }
          var productElement = document.getElementById("price"+i+"_"+k);           
    if (productElement != null){
   //alert (i +" "+ k+" " + document.getElementById("count"+i+"_"+k).value+" - "+ document.getElementById("height"+i+"_"+k).value +"="+document.getElementById("remains_input0_"+k).value );
                      // alert (removeSpaces(productElement.innerHTML));
          
                       if(productElement.innerHTML=="Cena dohodou"){
                       var oldPrice = 0;
                       
                       }else{var oldPrice = removeSpaces(productElement.innerHTML);}
                        
                     oldPrice = oldPrice.replace(",", ".");     
   newPrice2 += parseFloat(oldPrice); 
  
     if (document.getElementById("remains0_"+k).value==1&&i==0){  
              // alert (i +" "+ k);
             newPrice2 += parseFloat(document.getElementById("remains_input0_"+k).value); 
             // var oldKg =  document.getElementById("kg_input0_"+k).value; 
              //totalKg2 += parseFloat(oldKg);
              } 
       
         }                                                                                 
          
        
          }   
        
        
         }
                                        if (document.getElementById("range_price")){
          newPrice2 += 200; 
     
     }
      if(document.getElementById("cutting-price-vat")){
             var ccps_vat=ccps*1.2;
      document.getElementById("cutting-price-vat").innerHTML="<strong>"+number_format(parseFloat(ccps_vat), 2, ',', ' ')+"</strong> Kč";
                 
          newPrice2 += parseFloat(ccps);
      } 
        if(isNaN(newPrice2)){document.getElementById("priceHidden2").innerHTML = "cena nespočítána ";}else{
        
        document.getElementById("priceHidden2").innerHTML = "<strong>" + number_format(newPrice2*1.2, 0, ',', ' ') + " Kč</strong>";}         
       // document.getElementById("total_kg").value  = totalKg2; 
 
 
}     
           
  
  function removeSpaces(string) {
 var noSpace =  string.split(' ').join('');
 var noKc = noSpace.split('Kč').join('');
 var noNBSP = noKc.split('&nbsp;').join('');
 var noStrong = noNBSP.split('<strong>').join('');
 var noStrong2 = noStrong.split('</strong>').join('');
 var noStrong3 = noStrong2.split('<STRONG>').join('');
 var noStrong4 = noStrong3.split('</STRONG>').join('');
 return noStrong4;
}


function replace(productID,height,row,first){

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    var newRow=row+1;
    var pocetZbylych = 0;
    if(first==1){$("span.firstrow").clone().prependTo("input.count"+newRow+"_"+productID);}
  $('tr#height_id_'+row+"_"+productID).fadeOut(200, function(){

   $('tr#height_id_'+row+"_"+productID).remove();
     for (k=0;k<=199;k++)  { 
                            if (document.getElementById("height"+k+"_"+productID)){
                               pocetZbylych += 1;
                          
                            
                            }
    }
  //  alert (pocetZbylych);     
     if(pocetZbylych!=0){
         var oldValue = parseInt(document.getElementById("theValue"+productID).value);
   document.getElementById("theValue"+productID).value = oldValue-1;
      //alert("S");
    showRemainsBasket($('.bar_length'+productID).val(),productID);
    setTimeout("showPriceBasket()", 1000);  
      setTimeout("showPriceBasket2()", 1000);
      
     }else{
      $('span.basket_pieces').html("0 Ks");  
    $('tr#height_id_rest_'+productID).fadeOut(800,function(){$('tr#height_id_rest_'+productID).remove()});
    
    };
    showRemainsBasket($('.bar_length'+productID).val(),productID);
    showPriceBasket();
    showPriceBasket2();
     updateBasket();
  });
            
    }  
  }
  
xmlhttp.open("GET","/objednavka/nakupni-kosik/?productID="+productID+"&basketAction=del&row="+row,true);
xmlhttp.send(); 
 
}
 function updateBasket(){
 
 if($('.proID').val()!=null){
           var id = $('.proID').val();
           var theValue = $('#theValue'+id).val();
         //  alert (theValue);
        showResultBasket($('.height0_'+id).val(),$('.count0_'+id).val(),0,id);
       
 
 }
 }
function update(productID,height,count,id){

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   
   // alert ("UPDATED! "+$('#total_kg').val()+" "+id);
    }  
  }
  
xmlhttp.open("GET","/objednavka/nakupni-kosik/?productID="+productID+"&basketAction=update&height="+height+"&count="+count+"&id_row="+id,true);
xmlhttp.send(); 
 
       }
       function updateRemain(productID,count,totalKg,zbytky,narezaneCasti){

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
  //  alert ("Remain UPDATED! "+count+" "+productID);
    }  
  }
  
xmlhttp.open("GET","/objednavka/nakupni-kosik/?productID="+productID+"&basketAction=updateRemain&count="+count+"&total_kg="+totalKg+"&remainsBars="+zbytky+"&cuttingParts="+narezaneCasti,true);
xmlhttp.send(); 
 
       }
     function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57)){return false;}  else{  return true;}
            

       
      }


 function controlInputs(){
           var zobraz = 0;
                   var barLength =  parseInt($('.bar_length').val());
                   
                   for (i=0;i<=199;i++)  {             
                    if (document.getElementById("height"+i)){
                       var heightValue = parseInt(document.getElementById("height"+i).value); 
                      
                        if(heightValue>barLength){
                          zobraz += 1;
                         }
                         
                          for (k=0;k<=199;k++)  { 
                            if (document.getElementById("height"+k)&&k!=i){
                              var heightValue2 = parseInt(document.getElementById("height"+k).value);
                                if(heightValue==heightValue2){ 
                               
                                  zobraz += 1;
                                } 
                              } 
                            }
                       }
                    }
       
                   if(zobraz>0) {$('.btnOrder').fadeOut(300,function(){$('#make_order_note').fadeIn(1000);  });}else{$('#make_order_note').fadeOut(300,function(){$('.btnOrder').fadeIn(1000); });}
  }
  
  function duplicate(idRow, productID, plechy){
      var number = $('td.number'+productID).html();
      var oldCount = $('#count0_'+productID).val();
       
      var oldCP=$('#priceCP_0_'+productID).val();
      var oldCP2 = oldCP.replace(",", ".");  
      var newCP= parseFloat(oldCP2)/parseFloat(oldCount);
     var name = $('td.name'+productID).html();
     var lastValue = $('#theValue'+productID).val();
var newValue = parseInt($('#theValue'+productID).val())+1; 
     var newValue2 = parseInt($('#theValue'+productID).val())+1;
     var barLength = $('.bar_length'+productID).val();
     var kgm = $('td.kgm'+productID).html();
     if(plechy==null){
  $("#height_id_"+idRow+"_"+productID).after('<tr id=\'height_id_'+lastValue+'_'+productID+'\'><td class=\"number\">'+number+'</td><td>'+name+'</td><td class=\'height\'><input type=\'text\' class=\'input-text-no height'+lastValue+'_'+productID+'\' value=\'30\' name=\'height[]\' id=\'height'+lastValue+'_'+productID+'\' title=\'Délka v mm\' style=\'width: 60px;\' onkeypress=\'return isNumberKey(event)\' onkeyup=\"showResultBasket($(\'.height'+lastValue+'_'+productID+'\').val(), $(\'.count'+lastValue+'_'+productID+'\').val(),'+lastValue+','+productID+');CheckValueMax(this, '+barLength+');CheckValueMin(this, 1);\"></td><td class=\"count\"><input type=\"text\" class=\"input-text-no count'+lastValue+'_'+productID+'\" value=\"1\" name=\"count[]\" id=\"count'+lastValue+'_'+productID+'\" title=\"Počet ks\" style=\"width: 40px;\" onkeypress=\'return isNumberKey(event)\' onkeyup=\"showResultBasket($(\'.height'+lastValue+'_'+productID+'\').val(),$(\'.count'+lastValue+'_'+productID+'\').val(),'+lastValue+','+productID+');CheckValueMin(this, 1);\"><input type=\"hidden\" name=\"productID[]\" value=\"'+productID+'\"><input type=\"hidden\" name=\"productID'+productID+'\" value=\"'+productID+'\" class=\"productID'+lastValue+'_'+productID+'\"><input type=\"hidden\" name=\"bar_length'+productID+'\" value=\"'+barLength+'\" class=\"bar_length'+productID+'\"><input type=\"hidden\" name=\"priceHidden1_50\" value=\"\" id=\"priceHidden'+lastValue+'_'+productID+'\"><input type=\"hidden\" name=\"priceHidden2_'+lastValue+'_'+productID+'\" value=\"\" id=\"priceHidden2_'+lastValue+'_'+productID+'\"><input type=\"hidden\" name=\"priceCP_'+lastValue+'_'+productID+'\" value=\"'+newCP+'\" id=\"priceCP_'+lastValue+'_'+productID+'\" /> Ks</td><td class=\"kgm t_right\">'+kgm+'</td><td class=\"price-item t_right\">125&nbsp;Kč</td><td class=\"price t_right\" id=\"price'+lastValue+'_'+productID+'\"><strong>133&nbsp;</strong>Kč</td><td class=\"price-vat t_right\" id=\"price_vat'+lastValue+'_'+productID+'\"><strong>160&nbsp;</strong>Kč</td><td class=\"del\"><p class=\"button\" onclick=\"duplicate('+lastValue+','+productID+')\">Přidat</p><p onclick=\"replace('+productID+',30,'+lastValue+')\"><img src=\"/imgs/modify/ico-delete.png\" width=\"23\" height=\"23\" alt=\"Odstranit\"></p></tr>');
     }else{
      $("#height_id_"+idRow+"_"+productID).after('<tr id=\'height_id_'+newValue+'_'+productID+'\'><td class=\"number\">'+number+'</td><td>'+name+'</td><td class=\'height\'>--<input type=\'text\' style=\'display:none;\' class=\'input-text-no height'+lastValue+'_'+productID+'\' value=\''+height+'\' name=\'height[]\' id=\'height'+lastValue+'_'+productID+'\' title=\'Délka v mm\' style=\'width: 60px;\' onkeypress=\'return isNumberKey(event)\' onkeyup=\"showResultBasket($(\'.height'+lastValue+'_'+productID+'\').val(), $(\'.count'+lastValue+'_'+productID+'\').val(),'+lastValue+','+productID+');CheckValueMax(this, '+barLength+');CheckValueMin(this, 1);\"></td><td class=\"count\"><input type=\"text\" class=\"input-text-no count'+lastValue+'_'+productID+'\" value=\"1\" name=\"count[]\" id=\"count'+lastValue+'_'+productID+'\" title=\"Počet ks\" style=\"width: 40px;\" onkeypress=\'return isNumberKey(event)\' onkeyup=\"showResultBasket($(\'.height'+lastValue+'_'+productID+'\').val(),$(\'.count'+lastValue+'_'+productID+'\').val(),'+lastValue+','+productID+');CheckValueMin(this, 1);\"><input type=\"hidden\" name=\"productID[]\" value=\"'+productID+'\"><input type=\"hidden\" name=\"productID'+productID+'\" value=\"'+productID+'\" class=\"productID'+lastValue+'_'+productID+'\"><input type=\"hidden\" name=\"bar_length'+productID+'\" value=\"'+barLength+'\" class=\"bar_length'+productID+'\"><input type=\"hidden\" name=\"priceHidden1_50\" value=\"\" id=\"priceHidden'+lastValue+'_'+productID+'\"><input type=\"hidden\" name=\"priceHidden2_'+lastValue+'_'+productID+'\" value=\"\" id=\"priceHidden2_'+lastValue+'_'+productID+'\"> Ks</td><td class=\"kgm\">'+kgm+'</td><td class=\"price-item\">125&nbsp;Kč</td><td class=\"price t_right\" id=\"price'+lastValue+'_'+productID+'\">133&nbsp;Kč</td><td class=\"price-vat t_right\" id=\"price_vat'+lastValue+'_'+productID+'\">160&nbsp;Kč</td><td class=\"del\"><p onclick=\"replace('+productID+','+lastValue+')\"><img src=\"/imgs/modify/ico-delete.png\" width=\"23\" height=\"23\" alt=\"Odstranit\"></p></tr>'); 
     }
       // alert (newValue);
    document.getElementById("theValue"+productID).value = newValue;
    showRemainsBasket($('.bar_length'+productID).val(),productID);
          setTimeout(function() {
        showResultBasket(30,1,lastValue,productID)
        }, 1000);

    update(productID,30,1,lastValue);
    
  }
                
                  
                  
  function number_format(a, b, c, d) {
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}            

function controlRemains(){
    
 /*   for (i=0;i<=1999;i++)  {  
     var productElement2 = $('#remains_div'+i);           
         
   if(productElement2.html() != null){
                   showResultBasket($('.height0_'+i).val(),$('.count0_'+i).val(),0,i);
                   //alert(productElement2.html());
              
            }    
    }   */

}
 function make_blank(id){
 
          document.getElementById("height"+id).value="";
              
}

//setTimeout("controlRemains()", 2000);

//setTimeout("showPriceBasket()", 2200);
//setTimeout("showPriceBasket2()", 2200); 


