
function highlight(initObj, action){
  var names = objGet('names');
  var locality = objGet('loc');
  
  if(action==1){
    if(initObj=='names'){
      names.className = 'active';
      locality.className = '';
    }
    else{
      locality.className = 'active';
      names.className = '';
    }
  }
  else{
    if(initObj=='names'){
      names.className = '';
      locality.className = 'active';
    }
    else{
      locality.className = '';
      names.className = 'active';
    }
  }
}


function openImageMineralshop(id, root) {
  url = root + 'm_photo.php?id='+id;
  win = window.open(url, id,'resizable=1,top=20,left=20,menubar=0,scrollbars=1,width=' + 840 + ',height=' + 640);
  win.focus()
}

function switchMenu(type){
  switch(type){
    case 'names' : objGet('locality').style.display = 'none';
                   objGet('names').style.display = 'block';
                   break;
    case 'locality' : objGet('names').style.display = 'none';
                   objGet('locality').style.display = 'block';
                   break;
  }
}

function wrong_mail_address(adresa){
  var error=false;
  var pozice_zavinace = adresa.indexOf("@");
    if (pozice_zavinace < 0)
        error=true;
    var cast_pred_zavinacem = adresa.substring(0,pozice_zavinace);
    var cast_po_zavinaci = adresa.substring(pozice_zavinace+1,adresa.length);
    if (cast_po_zavinaci.indexOf("@") >= 0)
        error=true;
    if (cast_pred_zavinacem.length <= 0)
        error=true;
    if (cast_po_zavinaci.length <= 0)
        error=true;

    return error;
}

function updatePayment(){
  if(objGet('country').value == 48 || objGet('country').value == 159){
    objGet('delivery_nocz').style.display='none';
    objGet('delivery_cz').style.display='block';
  }
  else{
    objGet('delivery_cz').style.display='none';
    objGet('delivery_nocz').style.display='block';
  }
}

/*
function updatePayment(){
  if(objGet('country').value == 48 || objGet('country').value == 159){
    
    objGet('delivery').remove(0);
    objGet('delivery').remove(0);
    objGet('delivery').remove(0);
    
    var no = new Option();
    no.value = 'Česká pošta';
    no.text = 'Česká pošta (dle ceníku)';
    objGet('delivery').add(no,null); 
    
    var no = new Option();
    no.value = 'DPD';
    no.text = 'DPD (dle ceníku)';
    objGet('delivery').add(no,null); 
    
    var no = new Option();
    no.value = 'osobní odběr';
    no.text = 'osobní odběr';
    objGet('delivery').add(no,null);  
    
    
    if(objGet('delivery').selectedIndex  != 2){
      objGet('payment').remove(0);
      objGet('payment').remove(0);
      objGet('payment').remove(0);
      
      var no = new Option();
      no.value = 'dobírkou';
      no.text = 'dobírkou (+ 40 Kč)';
      objGet('payment').add(no,null);
      
      no = new Option();
      no.value = 'kreditní kartou on-line';
      no.text = 'kreditní kartou on-line';
      objGet('payment').add(no,null);    
    }
    else{
      objGet('payment').remove(0);
      objGet('payment').remove(0);
      objGet('payment').remove(0);
      
      var no = new Option();
      no.value = 'kreditní kartou on-line';
      no.text = 'kreditní kartou on-line';
      objGet('payment').add(no,null);  
      
      no = new Option();
      no.value = 'osobně při převzetí';
      no.text = 'osobně při převzetí';
      objGet('payment').add(no,null);    
    }
  }
  else{
      objGet('delivery').remove(0);
      objGet('delivery').remove(0);
      objGet('delivery').remove(0);
      
      objGet('payment').remove(0);
      objGet('payment').remove(0);
      objGet('payment').remove(0);
      
      var no = new Option();
      no.value = 'kreditní kartou on-line';
      no.text = 'kreditní kartou on-line';
      objGet('payment').add(no,null);  
      
      var no = new Option();
      no.value = 'Česká pošta';
      no.text = 'Česká pošta (dle ceníku)';
      objGet('delivery').add(no,null);  
  }
}

*/

function validate_order(){ 
  if(objGet('address_match').checked){
    objGet('fakt_name').value=objGet('name').value; objGet('fakt_name').readOnly=true;
    objGet('fakt_street').value=objGet('street').value; objGet('fakt_street').readOnly=true;
    objGet('fakt_city').value=objGet('city').value; objGet('fakt_city').readOnly=true;
    objGet('fakt_post_code').value=objGet('post_code').value; objGet('fakt_post_code').readOnly=true;
    objGet('fakt_country').selectedIndex=objGet('country').selectedIndex; objGet('fakt_country').readOnly=true;
  }
  else{
    objGet('fakt_name').readOnly=false;
    objGet('fakt_street').readOnly=false;
    objGet('fakt_city').readOnly=false;
    objGet('fakt_post_code').readOnly=false;
    objGet('fakt_country').readOnly=false;
  }
  
  if(objGet('name').value=="" || objGet('street').value=="" 
  || objGet('city').value=="" || objGet('post_code').value==""
  || wrong_mail_address(objGet('email').value) || objGet('phone').value==""
  || ( !objGet('address_match').checked && ( objGet('fakt_name').value=="" || objGet('fakt_street').value=="" 
  || objGet('fakt_city').value=="" || objGet('fakt_post_code').value=="" ))
  ){
    objGet('submit').disabled=true;
    objGet('submit').className='disabled';
  }
  else{
    objGet('submit').disabled=false;
    objGet('submit').className='';
  }
}

function objGet(id) 
{
   if (Boolean(document.getElementById))
      return document.getElementById(id);
   else if (Boolean(document.all))
      return eval('document.all.'+id);
   else
      return eval('document.'+id);
}

function validate_msg(){
  if(objGet('text').value.length > 0)
    objGet('msg_submit').disabled=false;
  else
    objGet('msg_submit').disabled=true;
}
