function ControlSubmit(){
  if((document.OrderForm.FirstName.value == "" ||document.OrderForm.LastName.value == "")& document.OrderForm.Firm.value == ""){alert("Vyplňte název firmy nebo jméno a příjmení.");return false}
  if(document.OrderForm.Street.value == ""){alert("Vyplňte ulici.");return false}
  if(document.OrderForm.City.value == ""){alert("Vyplňte město.");return false}
  if(document.OrderForm.ZipCode.value == ""){alert("Vyplňte PSČ.");return false}
  if(document.OrderForm.Phone.value == "" & document.OrderForm.Email.value == ""){alert("Vyplňte telefon nebo email.");return false}
  return true
}


function changedelivery(pkDelivery,sTitle)
{
  var opayment=document.getElementById("PaymentType");
  var odelivery=document.getElementById("DeliveryType")
  var soptions, srows;
  soptions="";
  srows="";
 
 //alert(pkDelivery);
 
  if (pkDelivery>0) 
  {
  
    for (i=0;arrDelivery[i];i++)
    {   
    
        if (arrDelivery[i][0]==pkDelivery) {
          option = new Option(removeHTMLTags(arrDelivery[i][1]),arrDelivery[i][0]);
          option.selected=true;
          odelivery.options[i]=option;     
          }
        else 
          {
          option = new Option(removeHTMLTags(arrDelivery[i][1]),arrDelivery[i][0]);
          odelivery.options[i]=option;
          }
    }
    odelivery.options[0]=null;
   
    
    for (i=0;opayment.options[i];i++) {opayment.options[i]=null;}
    y=0;
    for (i=0;arrPayment[i];i++)
    {
     //alert (arrPayment[i][0].toString()+' = '+pkDelivery.toString());
    if (arrPayment[i][0]==pkDelivery) 
      {
        
      var sHCnotAvail;
        option = new Option(removeHTMLTags(arrPayment[i][2]),arrPayment[i][1]);
       // if (arrPayment[i][4]==1) {option.disabled='disabled';}
        opayment.options[y]=option;
        //soptions+="<option value='"+arrPayment[i][1].toString()+"'>"+arrPayment[i][2]+"</option>";
        sHCnotAvail="";
        //if (arrPayment[i][4]==1) sHCnotAvail="<br/><em style='color:#9F0000;'>Pro možnost splátek musí být všechno zboží ve Vašem košíku skladem!</em>";
        srows+="<tr><th>"+arrPayment[i][4]+"</th><td>"+arrPayment[i][3]+sHCnotAvail+"</td></tr>";
        y++;  
      }
    }
  
   //opayment.innerHTML=soptions;
   opayment.disabled="";
   document.getElementById('deliveryinfo').innerHTML="<h4>"+sTitle+"</h4><table cellspacin='0' cellpadding='0'>"+srows+"</table>";
   
   ativaOptionsDisabled();
   
  } 
   //alert(srows);

}

function ativaOptionsDisabled(){
    var sels = document.getElementById('PaymentType');
    if (sels)
    {
        for(var i=0; i < sels.length; i++){
            sels[i].onchange= function(){ //pra se mudar pro desabilitado
                if(this.options[this.selectedIndex].disabled){
                    if(this.options.length<=1){
                        this.selectedIndex = -1;
                    }else if(this.selectedIndex < this.options.length - 1){
                        this.selectedIndex++;
                    }else{
                        this.selectedIndex--;
                    }
                }
            }
            if (sels[i].options)
            {
              if(sels[i].options[sels[i].selectedIndex].disabled){
                  //se o selecionado atual é desabilitado chamo o onchange
                  sels[i].onchange();
              }
               
            
            for(var j=0; j < sels[i].options.length; j++){ //colocando o estilo
                if(sels[i].options[j].disabled){
                    sels[i].options[j].style.color = '#CCC';
                }
            }
            }
            
        }
    }
}

