function zalozky(click){

//vsechny zalozky vypneme a zobrazime jen predanou v parametru
 var zalozka=document.getElementById("karta1");
 zalozka.style.display='none';
 hzalozka=document.getElementById("hkarta1");
 hzalozka.style.background='#F1EBDB';
 
 zalozka=document.getElementById("karta2");
 zalozka.style.display='none';
 hzalozka=document.getElementById("hkarta2");
 hzalozka.style.background='#F1EBDB';
 
 zalozka=document.getElementById("karta3");
 zalozka.style.display='none'; 
 hzalozka=document.getElementById("hkarta3");
 hzalozka.style.background='#F1EBDB'; 
 
 zalozka=document.getElementById(click);
 zalozka.style.display='block';
 hzalozka=document.getElementById('h'+click);
 //alert("h"+click);
 hzalozka.style.background='#F1FBDB';
}

function enable_pvc_color(){
    barva_je=false;
    for (i=1;i<=18;i++){
      document.getElementById('barva'+i).disabled=(document.getElementById('barva_varianta').value=='bílá barva');
      if (document.getElementById('barva'+i).checked==true)
        barva_je=true;
      if (document.getElementById('barva_varianta').value=='bílá barva')                  
        document.getElementById('barva'+i).checked=false; 
   }
    for (i=50;i<=66;i++){
      document.getElementById('barva'+i).disabled=(document.getElementById('barva_varianta').value=='bílá barva');
      if (document.getElementById('barva'+i).checked==true)
        barva_je=true;
      if (document.getElementById('barva_varianta').value=='bílá barva')                  
        document.getElementById('barva'+i).checked=false; 
   }
      
   if ((document.getElementById('barva_varianta').value!='bílá barva')  && (barva_je==false))
        document.getElementById('barva1').checked=true;
  document.getElementById('barva_varianta').disabled=false;   
   //zakazeme titanium a euro barvy
  for (i=19;i<=39;i++){
      document.getElementById('barva'+i).disabled=true;
      document.getElementById('barva'+i).checked=false;      
   }      
}

function enable_euro_color(){
  //zakazeme pvc a titanium barvy
  for (i=1;i<=25;i++){
      document.getElementById('barva'+i).disabled=true;
      document.getElementById('barva'+i).checked=false;
   }
  for (i=50;i<=66;i++){
      document.getElementById('barva'+i).disabled=true;
      document.getElementById('barva'+i).checked=false;
   }        
   
  document.getElementById('barva_varianta').disabled=true;   
  //povolime euro barvy
  barva_je=false;
  for (i=26;i<=39;i++){
      document.getElementById('barva'+i).disabled=false;
      if (document.getElementById('barva'+i).checked==true)
        barva_je=true; 
   }
   if (barva_je==false)
      document.getElementById('barva26').checked=true;      
}

function enable_titanium_color(){
  //zakazeme pvc barvy
   for (i=1;i<=18;i++){
      document.getElementById('barva'+i).disabled=true;
      document.getElementById('barva'+i).checked=false;      
   }
  for (i=50;i<=66;i++){
      document.getElementById('barva'+i).disabled=true;
      document.getElementById('barva'+i).checked=false;
   }     
  document.getElementById('barva_varianta').disabled=true;   
   //zakazeme euro barvy
  for (i=26;i<=39;i++){
      document.getElementById('barva'+i).disabled=true;
      document.getElementById('barva'+i).checked=false;      
   }      
   //povolime titanium barvy
  barva_je=false;
  for (i=19;i<=25;i++){
      document.getElementById('barva'+i).disabled=false;
      if (document.getElementById('barva'+i).checked==true)
        barva_je=true; 
   }
   if (barva_je==false)
      document.getElementById('barva19').checked=true;   
}

function crEl(name) {
  //vytvori element v dokumentu
      var elem = document.createElement(name);
      return elem;
  }
function crTx(content) {
  //vytvori textovy node v dokumentu
      var text = document.createTextNode(content);
      return text;
  }


function insert_item(){
//vlozi polozku do poptavky
    var vyrobek_text=new Array();
    var barvy_text=new Array();
    var vyrobek_typ=new Array();     
    var zaluzie='';
    var sita='';
    var par_vni='';
    var par_vne='';
    var barva_html='bílá';

    vyrobek_text[0]='';
    vyrobek_text[1]='Klasik 73 - Brügmann';
    vyrobek_text[2]='Original 70 - Zendow';
    vyrobek_text[3]='Energo 76 - Prestige';
    vyrobek_text[4]='Titanium 76 - Prestige';
    vyrobek_text[5]='Energo Plus 76 - Prestige';
    vyrobek_text[6]='Premium 96 - Prestige';
    vyrobek_text[7]='Premium Plus 96 - Prestige';            
    vyrobek_text[8]='Real 78 - Eurookno 78mm';
    vyrobek_text[9]='Real Plus 78 - Eurookno 78mm';
    vyrobek_text[10]='Real Premium 92 - Eurookno 92mm';
    vyrobek_typ[0]='';
    vyrobek_typ[1]='jednokřídlé pevné zasklení';
    vyrobek_typ[2]='jednokřídlé otevíravo sklopné';
    vyrobek_typ[3]='dvoukřídlé otevíravo sklopné';
    vyrobek_typ[4]='trojkřídlé s jedním sloupkem';
    vyrobek_typ[5]='balkónové dveře';
    vyrobek_typ[6]='vchodové dveře jednokřídlé';
    vyrobek_typ[7]='vchodové dveře jednokřídlé s fixem';
    vyrobek_typ[8]='vchodové dveře dvoukřídlé';
    
    barvy_text[0]='';
    barvy_text[1]='006 jedlově zelená';
    barvy_text[2]='008 Palisander';    
    barvy_text[3]='012 Inoutic černá';
    barvy_text[4]='019 teplá bílá';
    barvy_text[5]='004 šedá';
    barvy_text[6]='146 Rustikální třešeň';                
    barvy_text[7]='025 dub tmavý';
    barvy_text[8]='026 mahagon';
    barvy_text[9]='145 Irský dub';
    barvy_text[10]='079 ocelová modrá';                
    barvy_text[11]='096 krémová';
    barvy_text[12]='110 zlatý dub';
    barvy_text[13]='111 višeň';
    barvy_text[14]='144 macore';
    barvy_text[15]='154 ořech';
    barvy_text[16]='402 douglas';
    barvy_text[17]='623 oregon';
    barvy_text[18]='638 nevada';                        
     barvy_text[19]='647 titanově bílá';
    barvy_text[20]='648 lithium šedá';    
    barvy_text[21]='649 thorium šedá';
    barvy_text[22]='650 mosazně hnědá';
    barvy_text[23]='911 aluminium šedá';
    barvy_text[24]='921 grafitově černá';                
    barvy_text[25]='925 hliníková bílá';
    barvy_text[26]='euro-afromosie';
    barvy_text[27]='euro-bílá';
    barvy_text[28]='euro-borovice';                
    barvy_text[29]='euro-jasan';
    barvy_text[30]='euro-kaštan';
    barvy_text[31]='euro-macore';
    barvy_text[32]='euro-mahagon';
    barvy_text[33]='euro-oranž';
    barvy_text[34]='euro-ořech';
    barvy_text[35]='euro-rustikální dub';
    barvy_text[36]='euro-smrk'; 
     barvy_text[37]='euro-dub tmavý';
    barvy_text[38]='euro-třešeň';
    barvy_text[39]='euro-zlatý dub';
    
    barvy_text[50]='656 Třešeň Amaretro';
    barvy_text[51]='673 Třešeň ';    
    barvy_text[52]='071 Modrá';
    barvy_text[53]='134 Mechově zelená';
    barvy_text[54]='625 Signální šedá';
    barvy_text[55]='626 Basalt šedá';
    barvy_text[56]='644 Vínově červená';
    barvy_text[57]='657 Śedá hladká';
    barvy_text[58]='666 Antracit šedá hladká';
    barvy_text[59]='907 Světle šedá';
    barvy_text[60]='020 Přírodní dub';
    barvy_text[61]='072 Antracit šedá';
    barvy_text[62]='115 Dub';
    barvy_text[63]='605 Toscana';                                    
    barvy_text[64]='640 Horská borovice';
    barvy_text[65]='627 Měkká třešeň';
    barvy_text[66]='027 Tmavě červená';        
 
    var vyrobek=0;
    var i=1;
    for (i=1;i<=10;i++){
      if (document.getElementById('vyrobek'+i).checked)
       {
        vyrobek=i;
        vyrobek_html=vyrobek_text[i];
        
       }    
    }
    
    if (document.getElementById("zaluzie").checked)
        zaluzie='checked';    
//        zaluzie='checked="checked"';
    if (document.getElementById("sita").checked)
        sita='checked';    
//        sita='checked="checked"';
    if (document.getElementById("par_vni").checked)
        par_vni='checked';
//        par_vni='checked="checked"';        
    if (document.getElementById("par_vne").checked)
        par_vne='checked';    
//        par_vne='checked="checked"';  
    x = 0;  
    i = 1;
    typ_okna='';
    for (i=1;i<=8;i++){          
      if (document.getElementById('typ-okna'+i).checked){
        x = i;
        typ_okna=vyrobek_typ[i];
       }
    }


    barva = '';
    barva_html2 = document.getElementById('barva_varianta').value+' - ';
    for (i=1;i<=39;i++){
          
      if (document.getElementById('barva'+i).checked) {
        if (i>18)       //pokud je titanium nebo euro tak nedavame variantu
            barva_html2='';
        barva_html = barva_html2+barvy_text[i];
      }
    }
    for (i=50;i<=66;i++){
      if (document.getElementById('barva'+i).checked) {
        barva_html = barva_html2+barvy_text[i];
      }
    }    
        
    if (x==0){
        alert('Vyberte typ okna.');
        return;
      }
    if (vyrobek==0){
      alert('Vyberte typ výrobku.');      
        return;
      }    
//    table_head ='<table><th width="30">pozice</th><th>typ - výrobek - profil</th><th>barva</th><th width="150">šířka / výška (mm)</th><th width="50">počet (kusy)</th><th width="100">doplňky</th><tbody ID=id_tabulka>';
//    table_end  ='</tbody></table>';
//    table_end = table_end.toUpperCase();
    table_cont = document.getElementById('items').innerHTML;
//    table_cont = table_cont.replace(/"id_tabulka"/gi,"id_tabulka");        
    table_contU = table_cont.toUpperCase();    
//    str_start = table_cont.indexOf('id_tabulka')+11; 
//    str_konec = table_contU.lastIndexOf('</TBODY>'); 
//    table_cont = table_cont.substr(str_start,str_konec);  
//    table_contU = table_cont.toUpperCase();
//    str_konec = table_contU.lastIndexOf('</TBODY>');    
//    table_cont = table_cont.substr(0,str_konec);

//ted si musime spocitat kolik je v table_cont elementu <tr> a podle toho dostaneme poradove cislo polozky
    //patt1=/<TR>/g;
    patt1=/POZICE/g;
    i=0
    while (patt1.test(table_contU)==true)
      i++; 
      
//    document.getElementById('items').innerHTML =table_head+table_cont+'<tr><td width="50">'+i+'</td><td><input type="hidden" name="typ'+i+'" value="'+typ_okna+'"><input type="hidden" name="profil'+i+'" value="'+vyrobek_html+'">'+typ_okna+'<br>'+vyrobek_html+'</td><td><input type="hidden" name="barva'+i+'" value="'+barva_html+'">'+barva_html+'</td><td class="poptavka_item"><input type="text" name="sirka'+i+'" value="0" size="5" /> / <input type="text" name="vyska'+i+'" value="0" size="5"></td><td class="poptavka_item"><input type="text" name="pocet'+i+'" value="1" size="3"></td><td class="lichy2"><input name="zaluzie'+i+'" type="checkbox" value="ano" '+zaluzie+'/> žaluzie<br/><input name="sita'+i+'" type="checkbox" value="ano" '+sita+' /> síta<br/><input name="par_vni'+i+'" type="checkbox" value="ano" '+par_vni+'/> vnitřní parapet<br/><input name="par_vne'+i+'" type="checkbox" value="ano" '+par_vne+'/> vnější parapet</td>'+table_end;
      table=document.getElementById('id_tabulka_body');
      var cell=new Array();
      var row = crEl('tr');
//        for (j=0; j<10; j++) {
      //pozice
      cell[1] = crEl('td');
      cell[1].id = 'pozice'+i;
      text = crTx(i);
      cell[1].appendChild(text);
      row.appendChild(cell[1]);
      //typ - produkt - profil
      cell[1] = crEl('td');
      input = crEl('input');
      input.type = 'hidden';
      input.name = 'typ'+i;
      input.value = typ_okna;
      cell[1].appendChild(input);
      input = crEl('input');
      input.type = 'hidden';
      input.name = 'profil'+i;
      input.value = vyrobek_html;
      cell[1].appendChild(input);
      
      text = crTx(typ_okna);
      cell[1].appendChild(text);
      br = crEl('br');      
      cell[1].appendChild(br);      
      text = crTx(vyrobek_html);                  
      cell[1].appendChild(text);
      
      row.appendChild(cell[1]);      
      //barva
      cell[2] = crEl('td');
      input = crEl('input');
      input.type = 'hidden';
      input.name = 'barva'+i;
      input.value = barva_html;
      text = crTx(barva_html);
      cell[2].appendChild(input);
      cell[2].appendChild(text);
      row.appendChild(cell[2]);      
      //sirka a vyska
//<input name="par_vni'+i+'" type="checkbox" value="ano" '+par_vni+'/> vnitřní parapet<br/><input name="par_vne'+i+'" type="checkbox" value="ano" '+par_vne+'/> vnější parapet</td>'+table_end;
      cell[3] = crEl('td');
      input = crEl('input');
      input.type = 'text';
      input.name = 'sirka'+i;
      input.id = 'sirka'+i;
      input.value = 0;
      input.size = 5;
      cell[3].appendChild(input);
      text = crTx('/');
      cell[3].appendChild(text);
      input = crEl('input');
      input.type = 'text';
      input.name = 'vyska'+i;
      input.id = 'vyska'+i;
      input.value = 0;
      input.size = 5;
      cell[3].appendChild(input);            
      row.appendChild(cell[3]);   
      //pocet
      cell[4] = crEl('td');
      input = crEl('input');
      input.type = 'text';
      input.name = 'pocet'+i;
      input.value = 1;
      input.size = 3;
      cell[4].appendChild(input);            
      row.appendChild(cell[4]);        
      //doplnky
      cell[5] = crEl('td');
//      cell[5].class='lichy2';
      cell[5].id='kraj'+i;
      input = crEl('input');
      input.type = 'checkbox';
      input.name = 'zaluzie'+i;
      input.value = 'ano';
      if (zaluzie=='checked')
        input.checked = zaluzie;
      cell[5].appendChild(input); 
      text = crTx(' žaluzie');
      cell[5].appendChild(text);
      
      br = crEl('br');      
      cell[5].appendChild(br);
      input = crEl('input');
      input.type = 'checkbox';
      input.name = 'sita'+i;
      input.value = 'ano';
      if (sita=='checked')
        input.checked = sita;
      cell[5].appendChild(input); 
      text = crTx(' síta');
      cell[5].appendChild(text);

      br = crEl('br');      
      cell[5].appendChild(br);
      input = crEl('input');
      input.type = 'checkbox';
      input.name = 'par_vni'+i;
      input.value = 'ano';
      if (par_vni=='checked')
        input.checked = par_vni;
      cell[5].appendChild(input); 
      text = crTx(' vnitřní parapet');
      cell[5].appendChild(text);      

      br = crEl('br');      
      cell[5].appendChild(br);
      input = crEl('input');
      input.type = 'checkbox';
      input.name = 'par_vne'+i;
      input.value = 'ano';
      if (par_vne=='checked')
        input.checked = par_vne;
      cell[5].appendChild(input); 
      text = crTx(' vnější parapet');
      cell[5].appendChild(text);
      row.appendChild(cell[5]);
             
      table.appendChild(row);      
      document.getElementById('kraj'+i).style.borderRight='0px';
      document.getElementById('pozice'+i).style.textAlign='center';                    

}

function test_poptavka(){
 if (document.poptavka.jmenoprijmeni.value==""){
   alert("Prosím doplňte své jméno a příjmení, případně název firmy.");
   return false;
 }
 if (document.poptavka.telefon.value==""){
   alert("Prosím doplňte kontaktní telefon.");
   return false;
 }
 
 field=document.poptavka.email;
 with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {
    alert("Prosím doplňte kontaktní email.");
    return false;
    }
  }
  
 
 //if (document.poptavka.email.value==""){
//   alert("Prosím doplňte kontaktní email.");
//   return false;
 //}
if (document.poptavka.ulice.value==""){
   alert("Prosím doplňte ulici.");
   return false;
 }
  if (document.poptavka.mesto.value==""){
   alert("Prosím doplňte město.");
   return false;
 } 
  if (document.poptavka.psc.value==""){
   alert("Prosím doplňte PSČ.");
   return false;
 }               
 //ted kontrola na výběr pobočky
 if (document.poptavka.pobocka.value=="--- vyberte pobočku ---"){
  alert("Prosím vyberte pobočku pro zpracování Vaší poptávky.");
  return false;
 }
 //ted kontrola na rozmery oken
 
 //ted kontrola na pocet polozek a zobrazeni zpravy
    table_cont = document.getElementById('items').innerHTML;       
    table_contU = table_cont.toUpperCase();    
//ted si musime spocitat kolik je v table_cont elementu <tr>
//    patt1=/<TR>/g;
    patt1=/POZICE/g;
    i=-1
    while (patt1.test(table_contU)==true)
      i++;  
    if (i==0){
      alert('Poptávka neobsahuje žádný výrobek. Nejprve vložte alespoň jednu položku kliknutím na tlačítko "Vložit do poptávky"');
      return false;
    }
    
   //tady kontrola jestli vsechny polozky maji oba rozmery
    for (i2=1;i2<=i;i2++){
      sirka=document.getElementById('sirka'+i2);
      vyska=document.getElementById('vyska'+i2);
      if (sirka.value=='0' || vyska.value=='0'){ 
        alert('Položka '+i2+' nemá zadány oba rozměry. Doplňte prosím rozměry, jinak nemůže být poptávka odeslána.');
        return false;
       }    
    }    
    
    if (i>1 && i<5){
      odpoved=' položky';
    }
    if (i==1){
      odpoved=' položku';
    }    
    if (i>4){
      odpoved=' položek';
    }    
    
       var r=confirm('Poptávka je správně vyplněna a obsahuje '+i+odpoved+'. Přejete si ji odeslat ke zpracování?');
       return r;
    
 
}
