function loginOnFocus(defaultLogin) {
  var newValue = '';
  var curentValue = document.getElementById("login").value;
  if(curentValue != defaultLogin){
    newValue = curentValue;     
  }
  document.getElementById("login").setAttribute('class','loginActive');  
  document.getElementById("login").setAttribute('className','loginActive');    
  document.getElementById("login").value = newValue;
}

function passwordOnFocus(defaultPasword) {
  var newPassword = '';
  var curentPassword = document.getElementById("password").value;
  if(curentPassword != defaultPasword){
    newPassword = curentPassword;
  }
  document.getElementById("password").setAttribute('class','passwordActive');
  document.getElementById("password").setAttribute('className','passwordActive');  
  document.getElementById("password").value = newPassword;
}

function updateEndPrice(){
  var price = document.getElementById("cenaProdukt").value;
  var discount = document.getElementById("slevaProdukt").value;
  var endPrice = price * ((100 - discount) / 100);
  document.getElementById("cenaSeSlevouProdukt").value = String(endPrice).split('.')[0];
}

function updateItemEndPrice(itemId){
  var price = document.getElementById("cena" + itemId).value;
  var count = document.getElementById("pocet" + itemId).value;
  var itemPrice = price * count;
  document.getElementById("polozkaCena" + itemId).value = itemPrice;
}

function addPicture() {
  if(document.getElementById("pocetObrazkuFormular").value < 6){
    document.getElementById("pocetObrazkuFormular").value++;
  }
  document.getElementById("pridatObrazek").value = 1;
  saveScrollCoordinates(document);
}

function addItemIntoOrder(){
  document.getElementById("pocetPolozek").value++;
  document.getElementById("pridatPolozku").value = 1;
  document.forms['orderEditForm'].submit();
}

function removePicture() {
  if(document.getElementById("pocetObrazkuFormular").value > 1){
    document.getElementById("pocetObrazkuFormular").value--;
  }
  document.getElementById("odebratObrazek").value = 1;
  saveScrollCoordinates(document);
}

function removeItemFromOrder(itemId){
  document.getElementById("smazatPolozku").value = itemId;
  document.forms['orderEditForm'].submit();
}

function addParameter() {
  if(document.getElementById("pocetParametruFormular").value < 20){
    document.getElementById("pocetParametruFormular").value++;
  }
  document.getElementById("pridatParametr").value = 1;
  saveScrollCoordinates(document);
}

function changeParameter() {
  document.getElementById("zmenitParametr").value = 1;
  saveScrollCoordinates(document);
  document.forms['productAddForm'].submit();
}

function addValue(maxValues) {

  if(document.getElementById("pocetHodnotFormular").value < maxValues){ 
    document.getElementById("pocetHodnotFormular").value++;
  }
  document.getElementById("pridatHodnota").value = 1;
  saveScrollCoordinates(document); 
}

function addItemIntoCart(id){
  document.getElementById("id").value = id;
  document.forms['productBuyForm'].submit();
  return false;
}

function addTipItemIntoCart(id){
  document.getElementById("id_productBuyTipForm").value = id;
  document.forms['productBuyTipForm'].submit();
  return false;
}

function addSaleItemIntoCart(id){
  document.getElementById("id_productBuySaleForm").value = id;
  document.forms['productBuySaleForm'].submit();
  return false;
}

function changeItemCount(itemKey){
  document.getElementById("klic").value = itemKey;
  document.forms['cartPreviewForm'].submit();
}

function changeShippingCharge(){
  saveScrollCoordinates(document);
  document.forms['shippingPreviewForm'].submit();
}

function passShippingCharge(step){
  document.forms["shippingPreviewForm"].action = '/pokladna.php?step=' + step;
  document.forms["shippingPreviewForm"].submit();
}

function passShippingChargeBack(step){
  document.forms["orderAddressForm"].action = '/pokladna.php?step=' + step;
  document.forms["orderAddressForm"].submit();
}

function changeCustomerType() {
  document.getElementById("zmenitZakaznikTyp").value = 1;
  saveScrollCoordinates(document);
  document.forms["orderAddressForm"].submit();
}

function changeDeliveryAddressVisibility() {
  document.getElementById("zmenitViditelnostDorucovaciAdresy").value = 1;
  var prev = document.getElementById("doruceniZapnuto").value;
  var checked = 0;
  if(prev == 0){ checked = 1;}
  document.getElementById("doruceniZapnuto").value = checked;
  saveScrollCoordinates(document);
  document.forms["orderAddressForm"].submit();
}

function changeNewsValue() {
  var prev = document.getElementById("novinky").value;
  var checked = 0;
  if(prev == 0){ checked = 1;}
  document.getElementById("novinky").value = checked;
}

function changeTipValue() {
  var prev = document.getElementById("tip").value;
  var checked = 0;
  if(prev == 0){ checked = 1;}
  document.getElementById("tip").value = checked;
}

function changeActionValue() {
  var prev = document.getElementById("akce").value;
  var checked = 0;
  if(prev == 0){ checked = 1;}
  document.getElementById("akce").value = checked;
}

function changeSaleValue() {
  var prev = document.getElementById("vyprodej").value;
  var checked = 0;
  if(prev == 0){ checked = 1;}
  document.getElementById("vyprodej").value = checked;
}

function submitOrder() {
  document.getElementById("odeslatObednavku").value = 1;
  document.forms["orderAddressForm"].submit();
}

function submitFilters(stranka) {
  document.forms["filterForm"].action += '&stranka=' + stranka;
  document.getElementById("stranka").value = stranka;
  document.forms["filterForm"].submit();
}

function addSubcategories() {

  var oldSubcategories = document.forms["productAddForm"].elements["podkategorie"];
  var oldProductSubcategories = document.forms["productAddForm"].elements["produktNovePodkategorie"];
  
  var produktNovePodkategorieIdsString = "";
  
  for(i = 0; i < oldSubcategories.options.length; i++) { 
    if(oldSubcategories.options[i].selected) { 
      produktNovePodkategorieIdsString += oldSubcategories.options[i].value + ",";
    } 
  }
  
  for(i = 0; i < oldProductSubcategories.options.length; i++) { 
    produktNovePodkategorieIdsString += oldProductSubcategories.options[i].value + ","; 
  }
  
  document.getElementById("zmenitPodkategorii").value = 1;
  document.getElementById("produktNovePodkategorieIdsString").value = produktNovePodkategorieIdsString;  
  saveScrollCoordinates(document);
}

function removeSubcategories() {

  var oldProductSubcategories = document.forms["productAddForm"].elements["produktNovePodkategorie"];
  
  var produktNovePodkategorieIdsString = "";
  
  for(i = 0; i < oldProductSubcategories.options.length; i++) { 
    if(!oldProductSubcategories.options[i].selected) { 
      produktNovePodkategorieIdsString += oldProductSubcategories.options[i].value + ",";
    } 
  }
    
  document.getElementById("zmenitPodkategorii").value = 1;
  document.getElementById("produktNovePodkategorieIdsString").value = produktNovePodkategorieIdsString;  
  saveScrollCoordinates(document);
}

function saveScrollCoordinates(element){
  element.getElementById('scrollx').value = (window.document.all)?window.document.body.scrollLeft:window.pageXOffset;
  element.getElementById('scrolly').value = (window.document.all)?window.document.body.scrollTop:window.pageYOffset;
}

