// vyhledavani v katalogu


// prumysl

function filter(id_industry, id_section, lang)
{
  language=lang;
  section_id=id_section;
  industry_id=id_section;
  if (document.getElementById('catalogue-form'))
  {
    getIndustrys(id_industry);
    return true;
  }
  else
  {
    return false;
  }
}


function getIndustrys(industry)

{



  if (document.getElementById('industry-select'))

  {

    if ( (industry_id!=document.getElementById('industry-select').value) && (document.getElementById('section-select')) )

    {

      document.getElementById('section-select').value='';

    }

  }



  if ( document.getElementById('industry-select') )

  {

    industry=document.getElementById('industry-select').value;

  }





industry_id=industry;

if (!industry)

{

  //section_id='';

}



//section_id='';

xmlhttpIndustry=null;

if (window.XMLHttpRequest)

  {// code for IE7, Firefox, Mozilla, etc.

  xmlhttpIndustry=new XMLHttpRequest();

  }

else if (window.ActiveXObject)

  {// code for IE5, IE6

  xmlhttpIndustry=new ActiveXObject("Microsoft.XMLHTTP");

  }

if (xmlhttpIndustry!=null)

  {

    xmlhttpIndustry.onreadystatechange=onResponseIndustrys;

    xmlhttpIndustry.open("GET",'/ajax/industrys.php?l='+language,true);

    xmlhttpIndustry.send(null);

  }

else

  {

    return false;

  }

  



}





function onResponseIndustrys()

{



  if(xmlhttpIndustry.readyState!=4) return;



  if(xmlhttpIndustry.status!=200)

  {

    return false;

  }

  





  var value, text, selected, sel, industry;

  html='';



  if ( document.getElementById('industry-select') )

  {

    industry=document.getElementById('industry-select').value;

  }

  else 

  {

    industry=industry_id;

  }



  x=xmlhttpIndustry.responseXML.documentElement.getElementsByTagName("INDUSTRY");

  



//  document.getElementById('catalogue-form').innerHTML='<div>';

  html+='<div class="input"><label>'+odv[language]+'</label> <select class="select" type="select" name="industry" id="industry-select" onchange="getIndustrys(this.value);"> ';



      if (!industry)

      {

        selected=' selected="selected"';

      }

      else

      {

        selected='';

      }

  html+='<option value=""'+selected+'>'+choose[language]+'</option>';
  



  

  

  for (i=0; i<x.length; i++)

  {

    xx=x[i].getElementsByTagName("ID");

    var id=xx[0].firstChild.nodeValue;

    xx=x[i].getElementsByTagName("NAME");

    var name=xx[0].firstChild.nodeValue;

      

      if (id==industry)

      {

        selected=' selected="selected"';

      }

      else

      {

        selected='';

      }

      

      

      html+='<option value="'+id+'"'+selected+'>'+name+'</option>';

    }

    

      

    html+='</select><div class="clear_both"><!-- --></div></div>';







  

//  alert(html);

  industry_id=industry;





  if (true)

  {

    getSections(industry);

  }

  else

  {

    document.getElementById('catalogue-form').innerHTML=html;

  }

  





}



















// sekce



function getSections(industry)

{





  if (!industry)

  {

//    getIndustrys();

  }

  





xmlhttpSection=null;

if (window.XMLHttpRequest)

  {// code for IE7, Firefox, Mozilla, etc.

  xmlhttpSection=new XMLHttpRequest();

  }

else if (window.ActiveXObject)

  {// code for IE5, IE6

  xmlhttpSection=new ActiveXObject("Microsoft.XMLHTTP");

  }

if (xmlhttpSection!=null)

  {

    xmlhttpSection.onreadystatechange=onResponseSections;

    xmlhttpSection.open("GET",'/ajax/sections.php?industry='+industry,true);

    xmlhttpSection.send(null);

  }

else

  {

    return false;

  }



}





function onResponseProvinces()
{

  if(xmlhttpIndustry.readyState!=4) return;

  if(xmlhttpIndustry.status!=200)
  {
    return false;
  }
  


  var value, text, selected, sel, industry;
  html='';

  if ( document.getElementById('industry-select') )
  {
    industry=document.getElementById('industry-select').value;
  }
  else 
  {
    industry=industry_id;
  }

  x=xmlhttpIndustry.responseXML.documentElement.getElementsByTagName("REGION");
  
  for (i=0; i<x.length; i++)
  {
    xx=x[i].getElementsByTagName("ID");
    var id=xx[0].firstChild.nodeValue;
    xx=x[i].getElementsByTagName("NAME");
    var name=xx[0].firstChild.nodeValue;
      
      if (id==industry)
      {
        selected=' selected="selected"';
      }
      else
      {
        selected='';
      }
      
      
      html+='<option value="'+id+'"'+selected+'>'+name+'</option>';
    }


  document.getElementById('region').innerHTML=html;
  


}









// sekce

function getSections(industry)
{


  if (!industry)
  {
//    getIndustrys();
  }
  


xmlhttpSection=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Mozilla, etc.
  xmlhttpSection=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5, IE6
  xmlhttpSection=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttpSection!=null)
  {
  	
    xmlhttpSection.onreadystatechange=onResponseSections;
    xmlhttpSection.open("GET",'/ajax/sections.php?industry='+industry+'&l='+language,true);
    xmlhttpSection.send(null);
  }
else
  {
    return false;
  }

}


function onResponseSections()
{


  if(xmlhttpSection.readyState!=4) return;
  if(xmlhttpSection.status!=200)
  {
    return false;
  }

  var value, text, selected, sel, section;

  if ( document.getElementById('section-select') )
  {
    section=document.getElementById('section-select').value;
    if (section_id!=section)
    {
      var selects=document.forms['catalogue-form'].getElementsByTagName('select');

      for (i=2; i<selects.length; i++)
      {
        selects[i].value='';
      }    
    }
    section_id=section;
  }
  else 
  {
    section=section_id;
  }
  
  
  

  x=xmlhttpSection.responseXML.documentElement.getElementsByTagName("SECTION");
  

//  document.getElementById('catalogue-form').innerHTML='<div>';
  html+='<div class="input"><label>'+sections[language]+'</label> <select class="select" type="select" name="section" id="section-select" onchange="getIndustrys('+industry_id+');"> ';

      if (!section && !section_id)
      {
        selected=' selected="selected"';
      }
      else
      {
        selected='';
      }
  html+='<option value=""'+selected+'>'+choose[language]+'</option>';

  
  for (i=0; i<x.length; i++)
  {
    xx=x[i].getElementsByTagName("ID");
    var id=xx[0].firstChild.nodeValue;
    xx=x[i].getElementsByTagName("NAME");
    var name=xx[0].firstChild.nodeValue;
      
      if (id==section || id==section_id)
      { 
        selected=' selected="selected"';
      }
      else
      {
        selected='';
      }
      
      
      html+='<option value="'+id+'"'+selected+'>'+name+'</option>';
    }
    
      
    html+='</select><div class="clear_both"><!-- --></div></div>';



  

  if (section)
  {
    section_id=section;
    getAttributes(section);
  }
  else
  {
    document.getElementById('catalogue-form').innerHTML=html;
  }


}











function getAttributes(s)
{

  section=s;
  var get='?s='+section;

  
  var selects=document.forms['catalogue-form'].getElementsByTagName('select');
  
  for (i=0; i<selects.length; i++)
  {
    if (selects[i].value)
    {
      get+='&'+selects[i].name+'='+selects[i].value;
    }
  }



xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Mozilla, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5, IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
    //alert('/ajax/attributes.php'+get+'&l='+language);
    xmlhttp.onreadystatechange=onResponseAttributes;
    xmlhttp.open("GET",'/ajax/attributes.php'+get+'&l='+language,true);
    xmlhttp.send(null);
  }
else
  {
    return false;
  }

}



function onResponseAttributes()
{


  if(xmlhttp.readyState!=4) return;
  if(xmlhttp.status!=200)
  {
    return false;
  }

  var value, text, selected, sel;



  x=xmlhttp.responseXML.documentElement.getElementsByTagName("ATTRIBUTE");
  

//  document.getElementById('catalogue-form').innerHTML='<div>';

  
  
  for (i=0; i<x.length; i++)
  {
    xx=x[i].getElementsByTagName("ID");
    var id=xx[0].firstChild.nodeValue;
    xx=x[i].getElementsByTagName("NAME");
    var name=xx[0].firstChild.nodeValue;
      
    html+='<div class="input"><label>'+name+'</label> <select class="select" type="select" name="attrs['+id+']" onchange="getIndustrys('+industry_id+');" > ';
    
    xx=x[i].getElementsByTagName("VALUES");

    var values=xx[0].getElementsByTagName("VALUE");
    
    sel=false;
    for (j=0; j<values.length; j++)
    {
      if (true==sel)
      {
        selected=' selected="selected"';
      }
      else
      {
        selected='';
      }
    
      text=values[j].firstChild.nodeValue;
      if (all[language]==text)
      {
        value='';
        selected=' selected="selected"';
        sel=false;
      }
      else
      {
        value=text;
      }
      if ('- cancel -'==text)
      {
        value='';
        text=all[language];
        sel=true;
      }
      
      
      html+='<option value="'+value+'"'+selected+'>'+text+'</option>';
//      document.getElementById('catalogue-form').innerHTML+=values.length;
    }
    
      
    html+='</select><div class="clear_both"><!-- --></div></div>';
  }

//              <option selected="selected" value="">600 x 400</option>
    //document.getElementById('catalogue-form').innerHTML


  xx=xmlhttp.responseXML.documentElement.getElementsByTagName("COUNT");
  var count=xx[0].firstChild.nodeValue;
  
  if (100<count)
  {
    html+='<div class="input"><p>Zadaným parametrům odpovídá příliš mnoho výrobků. Upřesněte prosím výběr.</p><input type="submit" class="button" disabled="disabled" value="'+searchs[language]+'" /></div></div>';
  }
  else
  {
    html+='<div class="input"><input type="submit" class="button" value="'+searchs[language]+'" /></div></div>';
  }

  
  

  
  document.getElementById('catalogue-form').innerHTML=html;


}


var section;
var section_id;
var industry_id;
var html;
var language;

var odv=new Array();
odv[1]='Odvětví';
odv[2]='Odvětví';
odv[3]='Odvětví';
odv[4]='Odvětví';
odv[5]='Odvetvie';


var choose=new Array();
choose[1]='- vyberte -';
choose[2]='- choose -';
choose[3]='- wählen Sie aus  -';
choose[4]='- изберите -';
choose[5]='- vyberte -';

var all=new Array();
all[1]='- všechny -';
all[2]='- all -';
all[3]='- alle -';
all[4]='- все -';
all[5]='- všetky -';

var sections=new Array();
sections[1]='Sekce';
sections[2]='Section';
sections[3]='Sektion';
sections[4]='секция';
sections[5]='Sekcia';

var branches=new Array();
branches[1]='Sekce';
branches[2]='Branch';
branches[3]='Branche';
branches[4]='секция';
branches[5]='Sekcia';

var searchs=new Array();
searchs[1]='Vyhledat';
searchs[2]='Find';
searchs[3]='Suchen';
searchs[4]='найти';
searchs[5]='Vyhľadať';

