function ShowImage(jmeno, sirka, vyska, popis) {
  wokno=window.open("", "_blank", "resizeable=yes,toolbar=no,status=no,menubar=no,scrollbars=no,directories=no,location=no,resize=yes,width="+sirka+",height="+vyska);
  wokno.document.write("<html><head><title>"+popis+"</title></head><body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">");
  wokno.document.write("<img src=\""+jmeno+"\" width="+sirka+" height="+vyska+" border=0 alt=\""+popis+"\" onClick=\"window.close();\">");
  wokno.document.write("</body></html>");
}  

function ShowPageImg(jmeno, sirka, vyska, popis) {
  wokno=window.open("", "_blank", "resizeable=yes,toolbar=no,status=no,menubar=no,scrollbars=no,directories=no,location=no,resize=yes,width="+sirka+",height="+vyska);
  wokno.document.write("<html><head><title>"+popis+"</title></head><body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">");
  wokno.document.write("<img src=\""+jmeno+"\" width="+sirka+" height="+vyska+" border=0 alt=\""+popis+"\" onClick=\"window.close();\">");
  wokno.document.write("</body></html>");
}  

function isEmail(string) {
  if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    return true;
  else return false;
}
function ValidateForm(form) {
    var ret=true;
    var mail=true;
    var help=false;
		for(i=0;i<form.length;i++) {
      var swap=form.elements[i];
      //alert(swap.name +'='+ swap.value + ' | '+ swap.type);
      if((swap.type=='text' || swap.type=='textarea') && (swap.value=='' &&  swap.name.substring(0,6)=='check_')) {	
        ret=false;
      }
      if(swap.type=='checkbox' && swap.name=='info') {
        if(!swap.checked) {
          alert('Objednávku nebylo možno dokončit, protože jste nezaškrtli souhlas s obchodními podmínkami (umístěno na konci formuláře).');
          return false;
        }
      }
      if(swap.name=='f_email' && !isEmail(swap.value)){ mail=false;}
    }
    if(!ret) alert("Formulář nebylo možno odeslat. Pravděpodobně jste nevyplnili některé povinné pole.")
    //if(help && ret) { alert("Formulář nebylo možno odeslat. Pravděpodobně jste nevyplnili některé povinné pole."); ret=false;}
    if(!mail && ret) { alert("Zadali jste špatnou emailovou adresu. Zkuste to prosím znova."); ret=false;}
    return ret;
  }
  
  
  function MenuScrollLeft(max) {
    menu=document.getElementById('menublock');
    if(menu) {
      tmpMargin=menu.style.marginLeft;
      tmp=tmpMargin.substring(0, tmpMargin.length-2);
      tmpMargin=Number(tmp);
      if(tmpMargin!=0) menu.style.marginLeft=(tmpMargin+100)+"px";
    }
  }
  
  function MenuScrollRight(max) {
    menu=document.getElementById('menublock');
    if(menu) {
      tmpMargin=menu.style.marginLeft;
      tmp=tmpMargin.substring(0, tmpMargin.length-2);
      tmpMargin=Number(tmp);
      if(tmpMargin > -max) menu.style.marginLeft=(tmpMargin-100)+"px";
    }
  }

  // pridava do formulare dalsi blahoprani
  function add_table(table) {
    var table = document.getElementById(table);
    var next_name = table.childNodes.length;

    var tr = document.createElement("tr");
    tr.setAttribute("id", "new_comgratulation"+ next_name);
    var td1 = document.createElement("td");
    td1.setAttribute("colspan", "2");
    td1.innerHTML = '<table border="0" cellspacing="1" cellpadding="2" class="basketlist">'+
                      '<tr>'+
                        '<td colspan="2" class="text-right border-top-dotted1px-gray">'+
                          '<a href="javascript:void(0)" onClick="remove_table('+ next_name +')" title="Odstranit toto blahopřání."><img src="images/delete.gif" width="18" height="16" style="" alt=""></a>'+
                        '</td>'+
                      '</tr>'+
                      '<tr class="">'+
                        '<td>Oslovení</td>'+
                        '<td><input type="text" name="blahoprani['+ next_name +'][osloveni]" value="" size="50" class="defedit"></td>'+
                      '</tr>'+
                      '<tr>'+
                        '<td>Blahopřání</td>'+
                        '<td><textarea name="blahoprani['+ next_name +'][text]" rows="5" cols="75" class="defedit"></textarea></td>'+
                      '</tr>'+
                      '<tr class="">'+
                        '<td>Podpis</td>'+
                        '<td><input type="text" name="blahoprani['+ next_name +'][podpis]" value="" size="50" class="defedit"></td>'+
                      '</tr>'+
                    '</table>';

    tr.appendChild(td1);
    table.appendChild(tr);
  }
  function remove_table(num) {
    var table = document.getElementById("congratulation");
    table.removeChild(document.getElementById("new_comgratulation"+ num));
  }
  
  function EmptyField(id) {
    document.getElementById(id).value = '';
  }
  
  /* zapnuti/vypnuti dodaci adresy u objednavky  */
  function switchDeliveryAddr(checkbox) {
    disable=checkbox.checked;
    elems=Array('d_name', 'd_street', 'd_city', 'd_zip', 'd_tel', 'd_email');
    for(i=0; i<checkbox.form.elements.length; i++) {
      if(elems.indexOf(checkbox.form.elements[i].name)>-1) {
        checkbox.form.elements[i].disabled=disable;
        if(disable) checkbox.form.elements[i].value='';
      }
    }
  }



  function showHidePackageForm(cnt, display) {
    for(x = 0; x < cnt; x++) {
      document.getElementById('packageform'+ x).style.display=display;
    }
  }