function fit_window(){
  pictureWidth = objGet('pic').width;
  pictureHeight = objGet('pic').height;
  window.resizeTo(pictureWidth+60, pictureHeight+96);  
}

function check_payment(){
  f=objGet('order_form');
  if(f.payment.value=="dobírkou"){
    if(f.country.value==12 && f.country.value==48) return true;
    else{
      alert("Platba dobírkou je možná pouze pro české a rakouské zákazníky.");
      return false;
    }
  }
  else return true;  
}


//------------------------------------------------------------------------------
// prepnuti zvyrazneni zalozky obrazky / tabulka

function switchTabs(thumbsStyle, tableStyle){
  var thumbs = objGet('thumbs-tab');
  var table = objGet('table-tab');
  
  thumbs.className = thumbsStyle;
  table.className = tableStyle;
}

function wrong_mail_address(adresa){
  var re = /^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
  return re.test(adresa) == 0;
}

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 switchImg(url){
  objGet('main-pic').src=url;
}

function clearPassword(){
  x=objGet('login_form');
  if(x.password.value=='Vložte heslo...') x.password.value='';
}

function clearEmail(){
  x=objGet('login_form');
  if(x.login.value=='Vložte e-mail...') x.login.value='';
}

function clearNewsletter(){
  x=objGet('newsletter-box');
  if(x.value=='Vložte Váš e-mail...') x.value='';
}

function clearkeywords(){
  x=objGet('search');
  if(x.keywords.value=='Zadejte klíčová slova...') x.keywords.value='';
}

function validateReg(){
  f=objGet('reg_form');
  if(regUser==true){
    if(objGet('agreement').checked==true)
      objGet('submit').disabled=false;
    else
      objGet('submit').disabled=true;
  }
  else{
    if(f.address_match.checked==true){
      f.s_name.readOnly=true;
      if(f.company[1].checked) f.s_name.value=f.company_name.value; 
      else f.s_name.value=f.name.value + ' ' + f.surname.value;
      f.s_address.value=f.address.value; f.s_address.readOnly=true;
      f.s_city.value=f.city.value; f.s_city.readOnly=true;
      f.s_post_code.value=f.post_code.value; f.s_post_code.readOnly=true;
    }
    else{
      f.s_name.readOnly=false;
      f.s_address.readOnly=false;
      f.s_city.readOnly=false;
      f.s_post_code.readOnly=false;
    }

    if( (f.company[0].checked && (f.name.value=="" || f.surname.value==""))
      || (f.company[1].checked && f.company_name.value=="")
      || f.address.value=="" 
      || f.city.value=="" || f.post_code.value==""
      || wrong_mail_address(f.email.value) || f.phone.value=="" || !f.agreement.checked
      || f.s_name.value=="" || f.s_address.value=="" || f.s_city.value=="" || f.s_post_code.value=="" 
      || ( f.company[1].checked && (f.contact_name.value=="" || f.contact_surname.value=="" || f.contact_phone.value=="" || wrong_mail_address(f.contact_email.value)) 
      || ( registration && (f.password.value=="" || f.password2.value=="")))
    )
      objGet('submit').disabled=true;
    else 
      objGet('submit').disabled=false;
  } 
}

function updateRegForm(){
  if(objGet('customer_btn').checked){   // ------- koncovy zakaznik -----
    objGet('contact_person').style.display='none';
    objGet('company_name').style.display='none';
    objGet('fax').style.display='none';
    objGet('reg-NOCZ').style.display='none';
    objGet('reg-CZ').style.display='none';
    
    objGet('name').style.display='block';
    objGet('surname').style.display='block';
  }
  else{                            // ------- firma -----
    objGet('contact_person').style.display='block';
    objGet('company_name').style.display='block';
    objGet('fax').style.display='block';
    
    if(objGet('country').value=='48'){
      objGet('reg-CZ').style.display='block';
      objGet('reg-NOCZ').style.display='none';
    }
    else{
      objGet('reg-NOCZ').style.display='block';
      objGet('reg-CZ').style.display='none';
    }
    
    objGet('name').style.display='none';
    objGet('surname').style.display='none';
  }
  
  validateReg();  
}


function setActive(row){
  var rows = document.getElementsByTagName('div');
  for(var i=0; i<rows.length; i++){
    if(rows[i].getAttribute('rel') == 'row'){
      if(rows[i] === row){
        rows[i].className = 'row-active';
        activeItem = i;
      }
      else rows[i].className='row';
    }
  }
  
}
