//zobrazovani leveho stromu
function lm_strid_active(id){
  var idNone, idBlock, el, d
  if(id > 0){
    idNone = 0
    idBlock = 1
    d = new Date(2050, 12, 31)
  }else{
    idNone = 1
    idBlock = 0
    d = new Date(2000, 12, 31)
  }  
  document.cookie = "i6_lm_strtype=" + idBlock + "; expires=" + d.toGMTString() + "; path=/"

  el = document.getElementById('div_strid_' + idNone)
  if(el){
    if(el.style.display != 'none'){
      el.style.display = 'none'
      document.getElementById('td_strid_' + idNone).setAttribute('className', 'td_strid_hide')
      document.getElementById('td_strid_' + idNone).setAttribute('class', 'td_strid_hide')
    }
  }
  el = document.getElementById('div_strid_' + idBlock)
  if(el){
    if(el.style.display != 'block'){
      document.getElementById('td_strid_' + idBlock).setAttribute('className', 'td_strid_block')
      document.getElementById('td_strid_' + idBlock).setAttribute('class', 'td_strid_block')
      el.style.display = 'block'
    }
  }
}

//Zmena nazvu z fulltext na fulltextsiv pro vyhledavani SivCide - pro ACI
function ChangeFullText(form){
  var fullt = form.elements[0]
  if(fullt.value.substring(0, 1) == "/"){
    fullt.name = "fulltextsiv"
    fullt.value = fullt.value.substring(1)
  }
} 

//Scripty pro toolbar tb
function tbClick(input){
  var form = input.form
  switch(input.name){
    case 'cmdNew':
      document.location = form.redirect.value + '-1' + '&u_tbClick=cmdNewWith'
      break;
    case 'cmdNewWith':
      tbCmdDis(true, form, 0, 1)
      form[form.PK_name.value].value = -1
      form.action.value = 'new'
      form.redirect.value = form.redirect.value + 'PRIMARY_KEY'
      break;
    case 'cmdChange':
      tbCmdDis(true, form, 1, 0)
      form.action.value = 'change'
      if(form.redirect.value.substr(form.redirect.value.length - form.PK_value.value.length) != form.PK_value.value) form.redirect.value = form.redirect.value + form.PK_value.value
      //form.redirect.value = form.redirect.value + form.PK_value.value
      break;
    case 'cmdDelete':
      if(DelConfirm()){
        document.location.href = '?cls=' + form.cls.value + '&' + form.PK_name.value + '=' + form.PK_value.value + '&action=delete&redirect=' + escape(form.redir_del.value)
      }
      break;
    case 'cmdSubmit':
      //form.submit()
      break;
    case 'cmdReset':
      form.reset()
      tbCmdDis(false, form, 0, 2)
      break;
  }
}
        
function tbCmdDis(blnDisabled ,form, restricted, empty){
  form.cmdNew.disabled = blnDisabled
  form.cmdNewWith.disabled = blnDisabled
  form.cmdChange.disabled = blnDisabled
  form.cmdDelete.disabled = blnDisabled
  form.cmdSubmit.disabled = !blnDisabled
  form.cmdReset.disabled = !blnDisabled
  var tab
  if(blnDisabled) tab = 'tabedit' 
    else tab = 'tabform'
  document.getElementById('tbfrm').className = tab
  
  for(var i = 0, e; i < form.elements.length; i++){
    e = form.elements[i]
    if(e.type == 'button' || e.type == 'submit'){         //jestlize je nazev butonu obsazen v hidden prvku TB_disabled potom je tento buton disabled
      if(form.TB_disabled.value.indexOf(form.elements[i].name) >= 0) form[form.elements[i].name].disabled = true
      tbStyle(form.elements[i])
    }else{
      if(e.type != 'hidden') if(e.name.indexOf("_disabled") == -1 || (e.name.indexOf("_null") != -1 && empty == 2)) if(e.value != "#NA#") if(form.restricted_fields.value.indexOf(e.name + ",") == -1 || restricted == 0) form.elements[i].disabled = !blnDisabled
      //nepredplnovani prijmeni a jmena firemniho kontaktu
      if(e.name.indexOf("_null") != -1 && empty == 1){
        form.elements[i].value = '';
        form.elements[i].disabled = !blnDisabled;
        if (form.elements[i].name.indexOf("con") != -1) form.elements[i].name = form.elements[i].name.substr(0, e.name.indexOf("_disabled")) //pro typ kontaktu
      }
    }
  }
  if(form.name == "frmordedit") form.comname.disabled = true
}

function tbInit(what){
  var dis = ''
  for(var i = 0; i < document.forms.length; i++){
    var f = document.forms[i]
    for(var j = 0; j < f.elements.length; j++){
      var input = f.elements[j]
      if(input.name == 'TB_disabled') dis = input.value                     //do promenne dis nazvy butonu, ktere maji byt disabled
      if(input.type == 'button'){
        if(dis != '' && dis.indexOf(input.name) >= 0) input.disabled = true   //jestlize nazev butonu je obsazen v promenne dis je tento buton disabled
        if(input.name == what){
          if(input.disabled == false) input.click()
            else alert(GetLng("lngzj2"))
        }
        //tbStyle(input)
      }
      if(input.type != 'text' && input.type != 'hidden' && input.type != 'textarea' && input.type != 'select-one') tbStyle(input)
    }
  }
}

function tbStyle(input){
    if(input.disabled == true){
      input.style.cursor = 'default'
      switch(input.name){
        case 'cmdNew':
          input.className = 'toolbar toolbar_new_disable';
          break;
        case 'cmdNewWith':
          input.className = 'toolbar toolbar_new_with_disable';
          break;
        case 'cmdChange':
          input.className = 'toolbar toolbar_change_disable';
          break;
        case 'cmdDelete':
          input.className = 'toolbar toolbar_delete_disable';
          break;
        case 'cmdSubmit':
          input.className = 'toolbar toolbar_submit_disable';
          break;
        case 'cmdReset':
          input.className = 'toolbar toolbar_reset_disable';
          break;
      }
    }else{
      input.style.cursor = 'hand'
      switch(input.name){
        case 'cmdNew':
          input.className = 'toolbar toolbar_new_active';
          break;
        case 'cmdNewWith':
          input.className = 'toolbar toolbar_new_with_active';
          break;
        case 'cmdChange':
          input.className = 'toolbar toolbar_change_active';
          break;
        case 'cmdDelete':
          input.className = 'toolbar toolbar_delete_active';
          break;
        case 'cmdSubmit':
          input.className = 'toolbar toolbar_submit_active';
          break;
        case 'cmdReset':
          input.className = 'toolbar toolbar_reset_active';
          break;
      }
    }
}


//Script pro ikony - mouseover
/*
var icos = new Array(2)
icos[0] = new Image(); icos[0].src = 'img/empty.gif';
icos[1] = new Image(); icos[1].src = 'img/ico_mnuover.gif';
function icoSet(imgName, setOver){
  document.images[imgName].src = icos[setOver].src;
}
*/


//Smaze zaznam v klientech, dod. adresach a parametrech
function DelItem(u_mode, id1, id2){
  var action = 'u_mode='
  var msg = ''
  switch(u_mode){
    case 'contact':
      if(DelConfirm()){
        document.location.href = '?cls=contact&conid=' + id1 + '&action=delete&redirect=' + escape('?mtc=2&cls=contacts&catalogs=forcontact&concomid=' + id2)
      }
      break;
    case 'comshipto':
      if(DelConfirm()){
        document.location.href = '?cls=comshipto&cstid=' + id1 + '&action=delete&redirect=' + escape('?mtc=2&cls=comshiptos')
      }
      break;
    case 'cps':
      if(DelConfirm()){
        document.location.href = '?cls=conparset&cpsid=' + id1 + '&action=delete&redirect=' + escape('?mtc=2&cls=contacts&xsl=xcontactsp&conparsets=1&catalog=scategorysys&conid=' + id2)
      }
      break;
    case 'offer':
      if(DelConfirm()){
        document.location.href = '?cls=orditem&oriid=' + id1 + '&action=delete&redirect=' + escape('?mtc=1&cls=orders&xsl=xofferdea&ordid=' + id2)
      }
      break;
    case 'offers':
      if(DelConfirm()){
        document.location.href = '?cls=orders&ordid=' + id1 + '&action=delete&redirect=' + escape('?mtc=1&cls=orderss&xsl=xofferdea')
      }
      break;
  }
  return false;
}



//Odkaz na dane adresy pomoci javascriptu
function g(where, id, tag){
  if(tag == null) tag = ''
  var addr = ''
  switch (where){
    case 'sti':
      addr = '?mtc=0&cls=stoitem&stiid=' + id
      break;
    case 'ord':
      addr = '?mtc=1&cls=orders&ordid=' + id
      break;
    case 'ords':
      addr = '?mtc=1&cls=orderss&items=1&ordid=' + id
      break;
    case 'inv':
      addr = '?mtc=1&cls=invoice&invid=' + id
      break;
    case 'del':
      addr = '?mtc=1&cls=deliveries&items=1&delid=' + id
      break;
    case 'offer':
      addr = '?mtc=1&cls=orders&xsl=xofferdea&ordid=' + id
      break;
    case 'com':
      addr = '?mtc=2&cls=company&catalogs=forcompany&comid=' + id
      break;
    case 'concom':
      addr = '?mtc=2&cls=company&catalogs=forcompany&concomid=' + id
      break;
    case 'con':
      addr = '?mtc=2&cls=contact&catalogs=forcontact&conid=' + id
      break;
    case 'ship':
      addr = '?mtc=2&cls=comshipto&catalog=country&cstid=' + id
      break;
      case 'rec':
      addr = '?mtc=1&cls=reclaim&recid=' + id
      break;
  }
  if(addr != '') document.location.href = addr
}



//Prevede produkt do kosiku nebo aktivni objednavky
//Je-li zadan argument tag typu objekt provadi vlozeni aktualniho radku, jinak projizdi vsechny formy a hleda zaskrtnute produkty
function buy(ordtype, ordid, callform){
  var stiids = new Array();
  var qtys = new Array();
  var n = 0
  var fs;
  var fsn = 0
  
  if(callform == null){
    fs = document.forms;
  }else{
    fs = new Array(0)
    fs[0] = callform;
  }
  
  fsn = fs.length
  for(var i = 0; i < fsn; i++){
    var f = fs[i]
    if(f.elements)
      if(f.qty && f.stiid)
        if(callform != null || (callform == null && f.stiid.checked))
          if(f.qty.value > 0)
            if(f.stiid.value > 0) {
      stiids[n] = (f.stiid.value - 0);
      qtys[n] = (f.qty.value - 0);
      n += 1
    }
  }
  
  if(n > 0){    
    var url = 'default.asp?';
    var prefqty = '';
    var prefstiid = 'stiid';
    //VEP - -3 = vlozit mezi oblibene produkty, -4 odstranit
    if ((ordtype == -1) || (ordtype == -2) || (ordtype == -3) || (ordtype == -4)){
      if (ordtype == -2){
        var url = 'print.asp?';
        url += 'cls=iisutil&action=stiparcomp'
      }else{
        if ((ordtype == -3) || (ordtype==-4))
        {
	        prefqty = 'qty'
	        if (ordtype == -3) {
	       	   url += 'cls=iisutil&action=stifavourites&method=add&redirect=%3Fcls%3Dstoitems%26stifavourites%3D1';
	        }else {
	           url += 'cls=iisutil&action=stifavourites&method=del&redirect=%3Fcls%3Dstoitems%26stifavourites%3D1';
	        }
        } else {
	        prefqty = 'orbqty'
	        url += 'cls=ordbaskets';
        }
      }
    }else{
      prefqty = 'oriqty'
      url += 'cls=orders&ordid=' + ordid + '&action=additem&redirect=' + escape('?mtc=1&cls=orders&ordid=' + ordid);
      if (ordtype == 2){
        url += escape('&xsl=xofferdea&u_edit=1')
      }else{
        url += escape('&xsl=xordersedit&blocations=1&catalogs=fororders&edititems=1&useraction=editnew' + (n == 1 ? '&useraction1=addnew' : '&usereditwhat=oriblock'));
      }
    }
    
    for(var i = 0; i < n; i++){
      if (ordtype == -2){
       url += '&stiid=' + stiids[i]
      }else{
       url += '&' + prefstiid + '=' + stiids[i] + '&' + prefqty + '=' + qtys[i];
      }
    }

    // porovnani produktu se otevira do noveho okna, ostatni veci do stejneho okna
    if (ordtype == -2){
      win = window.open(url, 'ProductsCompare', 'toolbar=yes,scrollbars=yes,location=no,status=yes,resizable=yes,width=950,height=600,top=25,left=25');
      win.focus();
      return false;
    }else{
      document.location.href = url
    }

  }else alert(GetLng("lngzj3"))
  return false
}

//obsluha panelu pro vyber co s oznacenyma produktama udelat
//bylo by asi dobre to jeste upravit, jako je to v B2C
//POZOR panel co je v XINCSTOITEMS.XSL vola misto teto funkce funkci: buy(ordtype, ordid, callform)
function ProductsChooser(msg){

  var p=0;
  var act = document.getElementById("products_chooser").value;

  switch (act){
  case "-1": //do kosiku - ZATIM NEFUNKCNI!!!
    var url = '?mode=ZObList';
    for (var i=1; document.getElementById("choosed"+i); i++){
      if (document.getElementById("choosed"+i).checked){
        url += '&ZObStiId=' + document.getElementById("choosed"+i).value + '&ZObQty=' + document.getElementById("choosedqty"+i).value;
        p += 1;
      }
    }
    break;
  case "-2": //porovnavani
    var url = 'print.asp?cls=iisutil&action=stiparcomp';
    for (var i=1; document.getElementById("choosed"+i); i++){
      if (document.getElementById("choosed"+i).checked){
        url += '&stiid=' + document.getElementById("choosed"+i).value;
        p += 1;
      }
    }
    break;
  case "-4": //odebrat z kosiku (CHYBA - z kosiku se zde odebira jinak nez v B2C)
    var url = '?cls=ordbaskets';
    for (var i=1; document.getElementById("choosed"+i); i++){
      if (document.getElementById("choosed"+i).checked){
        url += '&stiid=' + document.getElementById("choosed"+i).value + '&orbqty=0';
        p += 1;
      }
    }
    // alert(url);
    break;
  default:
    alert('!!! zatím funkční pouze porovnávání !!!');
    return;
  }

  if (p == 0){
    alert(msg);
  } else {
    // porovnani produktu se otevira do noveho okna, ostatni veci do stejneho okna
    if (act == -2){
      win = window.open(url, 'ProductsCompare', 'toolbar=yes,scrollbars=yes,location=no,status=yes,resizable=yes,width=950,height=600,top=25,left=25');
      win.focus();
      return;
    }else{
      document.location.href = url
    }
  }
}

function PasteToFormX(argstr){
  var a = argstr.split(',');
  var openerFormName, index
  if(a.length > 0) openerFormName = a[0]
  if(a.length > 1) argstr = a[1]
  if(a.length > 2) index = a[2]
  PasteToForm(openerFormName, argstr, index)
}

function PasteToForm(openerFormName, argstr, index){
  var frm = self.opener.document.forms[openerFormName];
  var args = argstr.split('&');
  var sName, sValue, iPoz, inp, isA
  if(index == null) index = 0
  for (var i = 0; i < args.length; i++){
     iPoz = args[i].indexOf('=');
     sName = iPoz > -1 ? args[i].substring(0, iPoz) : '';
     sValue = iPoz > -1 ? args[i].substring(iPoz + 1, args[i].length) : '';
     inp = frm.elements[sName]
     if(inp){
       isA = (inp.length ? true : false)
       if(isA) isA = (inp.type ? false : true)
       if(isA){//pole elementu
         if(inp.length > index) inp[index].value = sValue
       }else{
         if(index == 0) inp.value = sValue
       }
     }
     //if(eval('frm.' + sName)) eval('frm.' + sName + '.value = \'' + sValue + '\'');
  }
 self.close();
}


function DelConfirm(){
  return confirm(GetLng("lngzj1"));
}


function FormClear(form){
  var input, it
  for(var i = 0; i < form.elements.length; i++){
    input = form.elements[i]
    it = input.type
    if(input.disabled == null) return true
    if(it == 'text' || it == 'checkbox'){
      if(input.value == '') input.disabled = true
    } else if(it == 'select-one'){
      if(input.selectedIndex < 0) input.disabled = true
      else if(input.options[input.selectedIndex].value == '') input.disabled = true
    }
  }
  return true
}

//pokud je firma zahranicni a neni vyplneno DIC, pak ComTax=0
function CheckComTax(form){
	if(form.comxcouid.value != 0 && form.comtaxnum.value == '') form.comtax.value = 0
}

function CheckFormVal(form){
  var EmptyVal = '';
  var ErrList = '';
  var ErrLine = '';
										
  //Firma 
  if(document.getElementById('choose_regVal')){
    if (document.getElementById('choose_regVal').value!='0') if(form.comname) if(form.comname.value == '') ErrList = ErrList + '   ' + GetLng("lngzj21") + '\n';
  }    
  //if(form.comregid) if(form.comregid.value == '') ErrList = ErrList + '   ' + GetLng("lngzj14") + '\n'; // jen pro ACI a BGS
  if(form.comregid) if(form.comregid.value.indexOf(" ") != -1) ErrList = ErrList + '   ' + GetLng("lngzj14") + '\n';
  // pokud nekdo chce kontrolovat ICO tak odremovat radek nize
  if(document.getElementById('choose_regVal')){
    if (document.getElementById('choose_regVal').value!='0') if(form.comregid) if ((form.comregid.value == '') || (isNaN(form.comregid.value)) || ((isFinite(form.comregid.value)) && (((form.comregid.value) < 1) || ((form.comregid.value) > 99999999)))) ErrList = ErrList + '   ' + GetLng("lngzj14a") + '\n';
  }    
  if(form.comtaxnum) if(form.comtaxnum.value.indexOf(" ") != -1) ErrList = ErrList + '   ' + GetLng("lngzj15") + '\n';
  if(form.comstreet) if(form.comstreet.value == '') ErrList = ErrList + '   ' + GetLng("lngzj22") + '\n';
  if(form.comcity) if(form.comcity.value == '') ErrList = ErrList + '   ' + GetLng("lngzj8") + '\n';
  if(form.compostcode) if(form.compostcode.value == '') ErrList = ErrList + '   ' + GetLng("lngzj9") + '\n';

  //Kontakt
  if(form.conlname) if(form.conlname.value == '') ErrList = ErrList + '   ' + GetLng("lngzj10") + '\n';
  if(form.confname) if(form.confname.value == '') ErrList = ErrList + '   ' + GetLng("lngzj11") + '\n';
  if(form.conemail){
    if(form.conemail.value == '') ErrList = ErrList + '   ' + GetLng("lngzj12") + '\n';
    if (!CheckEmail(form.conemail.value))ErrList = ErrList + '   ' + "E-mail nemá správný formát" + '\n';
  }
  if(form.contel1) if(form.contel1.value == '') if(form.name == 'Registration') ErrList = ErrList + '   ' + GetLng("lngzj13") + '\n';

  //Je-li vyplněno IČO musí být i DIČ
  //if(form.comregid && form.comtaxnum) if((form.comregid.value != '' && form.comtaxnum.value == '') || (form.comregid.value == '' && form.comtaxnum.value != '')) ErrLine = '\n - ' + GetLng("lngzj16") + '\n';
 
  //Heslo
  if(form.ConLogPswdOld) if(form.ConLogPswdOld.value == '') ErrList = ErrList + '   ' + GetLng("lngzj17") + '\n';
  if(form.ConLogPswdNew) if(form.ConLogPswdNew.value == '') ErrList = ErrList + '   ' + GetLng("lngzj18") + '\n';
  if(form.ConLogPswdNewConfirm) if(form.ConLogPswdNewConfirm.value == '') ErrList = ErrList + '   ' + GetLng("lngzj19") + '\n';
  if(form.ConLogPswdNew && form.ConLogPswdNewConfirm) if(form.ConLogPswdNew.value != form.ConLogPswdNewConfirm.value) ErrLine ='\n - ' + GetLng("lngzj20") + '\n';
  
  //ComShipTo
  if(form.cstname) if(form.cstname.value == '') ErrList = ErrList + '   ' + GetLng("lngzj21") + '\n';
  if(form.cststreet) if(form.cststreet.value == '') ErrList = ErrList + '   ' + GetLng("lngzj22") + '\n';
  if(form.cstcity) if(form.cstcity.value == '') ErrList = ErrList + '   ' + GetLng("lngzj8") + '\n';
  if(form.cstpostcode) if(form.cstpostcode.value == '') ErrList = ErrList + '   ' + GetLng("lngzj9") + '\n';
  
  if(form.souhlas) if(!form.souhlas.checked ) ErrList = ErrList + '   ' + "Pro úspěšnou registraci musíte souhlasit s jejími podmínkami." + '\n';
// alert('qq');
//  if(form.orddemid=='38'){
//	alert('aa');
//	if(form.cstpostcode){
//		if(form.cstpostcode.value == '70200') ErrList = ErrList + '   ' + "Vaše dodací adresa je mimo dojezd kurýra, zvolte prosím jiný typ dopravy." + '\n';
//	}else{
//		if(form.compostcode) if(form.compostcode.value == '70200') ErrList = ErrList + '   ' + "Vaše adresa je mimo dojezd kurýra, zvolte prosím jiný typ dopravy." + '\n';
//	}
//  }

 if(ErrList != '' || ErrLine != ''){
    if(ErrList != ''){
    EmptyVal = '\n\n'  // ' - ' + GetLng("lngzj5") +
    }
    ErrList = GetLng("lngzj6") + '\n' + EmptyVal + ErrList + ErrLine + '\n' + GetLng("lngzj4");
    alert(ErrList);
    return false;
  }else 
    if(form.comregid) if(form.comregid.value != '') form.comsname.value = (form.comname.value != '' ? form.comname.value : form.confname.value + ' ' + form.conlname.value);
    if(form.comname) if(form.comname.value == '') form.comname.value = form.conlname.value + ' ' + form.confname.value;
    return true;
}
//kontrola formatu emailu
function CheckEmail(email){
/* by Cizo
  re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$/;
  return email.search(re) == 0;
*/
  var re = new RegExp("^[_a-zA-Z0-9\.\-]+@(([_a-zA-Z0-9\-]{1,}\.){1,})+\.[a-zA-Z]{2,}$");  
	re.ignoreCase = true;
  return re.test(email);
}

function ControlPhone() {
  if(window.event){
      if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32)  && (event.keyCode!=40) && (event.keyCode!=41) && (event.keyCode!=43))
		  event.returnValue = false;
		} /*else {
		  if (((charCode < 48) || (charCode > 57)) && (charCode != 32)  && (charCode!=40) && (charCode!=41) && (charCode!=43))
		  event.returnValue = false;		  
    }*/
}

function ShowQueues(stiid, queqtyrequired, quexqudid){
  window.open('print.asp?cls=queues&quedir=0&catalog=queuedefinition&queqtyrequired=' + queqtyrequired + '&stiid=' + stiid + (quexqudid == null ? "" : '&quexqudid=' + quexqudid), 'ShowQueues', 'toolbar=no,scrollbars=yes,location=no,status=no,width=500,height=280,top=100,left=150'); 
}

function SetPageT(){
  var objH1 = document.getElementsByTagName('h1');
  if(objH1.length > 0){
    //document.title = objH1[0].firstChild.nodeValue + ' - ' + document.title
    document.title = document.title + ' - ' + objH1[0].firstChild.nodeValue
  }
}

function SetPageTInit(){
  if(window.attachEvent){
    window.attachEvent("onload", SetPageT)
  }else if(window.addEventListener){
    window.addEventListener("load", SetPageT, false)
  }
}

// ===== AKTIVNI STROM - sbaleni/rozbaleni vetvi ve stromu kategorii =====
function tc_ch(node){
  if((document.getElementById('tc_n' + node)) && (document.getElementById('tc_nl' + node))){
    el = document.getElementById('tc_n' + node)
    ell = document.getElementById('tc_nl' + node)
    if(el.style.display == 'none'){
      el.style.display = 'block'
      ell.style.backgroundImage = "url('img/DECminusGif.gif')"
    } else {
      el.style.display = 'none'
      ell.style.backgroundImage = "url('img/DECplusGIF.gif')"
    }
  }
}
// ===== AKTIVNI STROM - pocatecni rozbaleni vetvi ve stromu kategorii =====
function tc_start_ch(nodes){
  if(document.getElementById('tc_code')){
    nodes += document.getElementById('tc_code').value;
  }
  node = '';
  for(var i = 0; i < nodes.length; i++){
    n = nodes.substring(i, i + 1);
    if(n == ','){
      if((document.getElementById('tc_n' + node)) && (document.getElementById('tc_nl' + node))){
        el = document.getElementById('tc_n' + node);
        ell = document.getElementById('tc_nl' + node);
        el.style.display = 'block';
        ell.style.backgroundImage = "url('img/DECminusGIF.gif')";
      }
      node = '';
      n = '';
    }
    node += n;
  }
}
function obj_on(obj){
  if (document.getElementById(obj)) {
    el = document.getElementById(obj)
    el.style.display = 'block'
  }
}
function obj_off(obj){
  if (document.getElementById(obj)) {
    el = document.getElementById(obj)
    el.style.display = 'none'
  }
}
function obj_swap(obj){
  if (document.getElementById(obj)) {
    el = document.getElementById(obj)
    if(el.style.display == 'block' || el.style.display == ''){
      el.style.display = 'none'
    } else {
      el.style.display = 'block'
    }
  }
}

function OBJ(oId){
	var o;
	if (document.getElementById){
		if (document.getElementById(oId)){
			o = document.getElementById(oId);
		} else {
			if (document.forms[oId]){
				o = document.forms[oId];
			} else {
				o = null;
			}
		}
	} else {
		if (document.all[oId]){
			o = document.all[oId];
		} else {
			if (document.forms[oId]){
				o = document.forms[oId];
			} else {
				o = null;
			}
		}
	}
	return o;
}
//SetPageTInit()

//Ovladani zalozek na detailu produktu
function ShowStiTab(id_tab){
	for (var i = 0; i < document.getElementById("sti_tabs").childNodes.length; i++){
		if(id_tab == i){
			document.getElementById(i + "_tab").className = "sti_tab_block"
			document.getElementById(i + "_content").className = "sti_content_block"
		}else{
			document.getElementById(i + "_tab").className = "sti_tab_hidden"
			document.getElementById(i + "_content").className = "sti_content_hidden"
		}
	}
}
//Galerie
function ScrollImages(sDirection){
  if(!sEnabledScroll){return 0}
  var xMax = document.getElementById('scrollarea').scrollLeft;
  if(sDirection == 'L'){
    document.getElementById('scrollarea').scrollLeft = xMax + 40;
    xCurr = document.getElementById('scrollarea').scrollLeft;
    if(sEnabledScroll){setTimeout("ScrollImages('L')", 100);}
  } else {
    document.getElementById('scrollarea').scrollLeft = xMax - 40;
    xCurr = document.getElementById('scrollarea').scrollLeft;
    if(sEnabledScroll){setTimeout("ScrollImages('R')", 100);}
  }
}
function MoveImages(sDirection){
  var a_img = js_array.split(",");
  if(sDirection == 'L'){
    for (var i = 0; i < a_img.length; i++) {
      if (a_img[i]==sSelImg && a_img[i+1]){
        document.getElementById('origimg').src='img.asp?attid=' + a_img[i+1];
        sSelImg = a_img[i+1];
        break;
      }
    }
  } else {
    for (var i = 0; i < a_img.length; i++) {
      if (a_img[i]==sSelImg && a_img[i-1]){
//        if (i==1) {
//            document.getElementById('origimg').src='img.asp?stiid=' + a_img[i-1];
//          }else{
            document.getElementById('origimg').src='img.asp?attid=' + a_img[i-1];
//          }
        sSelImg = a_img[i-1];
      }
    } 
  }       
}
function topmenuclick(thi,n,name,classn){
	if (n>=thi && thi>0){
		for(var i=1;i<(n+1);i++){
			if (document.getElementById(name+i)) {
			    el = document.getElementById(name+i)
				
			    el.style.display = 'none'
			  }
		}
		if (document.getElementById(name+thi)) {
		    el = document.getElementById(name+thi)
		    el.style.display = 'block'
		  }
		for(var i=1;i<(n+1);i++){
		if (document.getElementById(name+'X'+i)) {
  			document.getElementById(name+'X'+i).className = classn
		  }
		}
		if (document.getElementById(name+'X'+thi)) {
  			document.getElementById(name+'X'+thi).className = classn+" act"
		  }
	}
}
// automatické nastavení skladu podle způsobu dodání pro exasoft - počítá se pouze se sklady CENTRAL, OP, OV
function DeliverymodeVsStore(orddemid_sOPId,orddemid_sOVId,store_sOPId,store_sOVId,store_sCENTRALId){
		if(document.getElementById('ordxqudidexs')){
      if(document.getElementById('choose_delivtypeexs')){
        if(document.getElementById('choose_delivtypeexs').value == orddemid_sOPId) {
          document.getElementById('ordxqudidexs').value = store_sOPId;
        }else if(document.getElementById('choose_delivtypeexs').value == orddemid_sOVId) {
          document.getElementById('ordxqudidexs').value = store_sOVId
        }else {document.getElementById('ordxqudidexs').value = store_sCENTRALId} 
      } 
		}    		  
}

function ForDeliveryfree(){
	var id = 0;

	if(document.getElementById('choose_delivtypeexs')){
        	id = document.getElementById('choose_delivtypeexs').value
		for(var i=1;i<100;i++){
			if(document.getElementById('SumBasktofreedeliv_'+i)){
			    document.getElementById('SumBasktofreedeliv_'+i).style.display = 'none';
			  }
		}
		if(document.getElementById('SumBasktofreedeliv_'+id)){

          		document.getElementById('SumBasktofreedeliv_'+id).style.display = 'block';
		}    		  
	}    		  
}

// pro parametrické vyhledávání - průvodce nákupem
// po kliku na element vymění background a současně nastaví příslušný checkbox
// id=id klikacího elementu, idcheck=id přidruženého checkboxu, iid=id parametru
function fcprcheckswitch(id,idcheck,idd){
  var el, elcheck, elX, elcheckX
  if(document.getElementById(id)){
	el = document.getElementById(id);
	  if(document.getElementById(idcheck)){
	  	elcheck = document.getElementById(idcheck);

	        if(elcheck.checked == false) {
			el.style.background = "url('img/DECprCheckOn.gif') no-repeat 0 0";
			elcheck.checked = true;
			if(document.getElementById('prchX'+idd)){
				elX = document.getElementById('prchX'+idd);
				if(document.getElementById('prchObjX'+idd)){
					elcheckX = document.getElementById('prchObjX'+idd);
					elX.style.background = "url('img/DECprCheckOf.gif') no-repeat 0 0";
					elcheckX.checked = false;
				}
			}
        	}else {
		      el.style.background = "url('img/DECprCheckOf.gif') no-repeat 0 0";
		      elcheck.checked = false;
		} 
	  }
  }
}

// pro parametrické vyhledávání - průvodce nákupem
// nastaví se odpovídající checbox a jsou vynulovány všechny hodnoty daného parametru
// id=id parametru, count=počet možných hodnot
function fcprcheckoff(id,count){
  var el, elcheck
  if(document.getElementById('prchX'+id)){
    el = document.getElementById('prchX'+id);
    if(document.getElementById('prchObjX'+id)){
	elcheck = document.getElementById('prchObjX'+id);
	if(elcheck.checked == false) {
		el.style.background = "url('img/DECprCheckOn.gif') no-repeat 0 0";
		elcheck.checked = true;
			for (var i = 0; i<count; i++) {
			  if(document.getElementById('prch'+id+'x'+(i+1))){
				  if(document.getElementById('prchObj'+id+'x'+(i+1))){
				      document.getElementById('prch'+id+'x'+(i+1)).style.background = "url('img/DECprCheckOf.gif') no-repeat 0 0";
				      document.getElementById('prchObj'+id+'x'+(i+1)).checked = false;
				  }
			  }
			} 
      	}else {
		el.style.background = "url('img/DECprCheckOf.gif') no-repeat 0 0";
		elcheck.checked = false;
	}
    }
  }
}

function cattreebold(id){
	if(document.getElementById('tc_a_' + id)){
    	document.getElementById('tc_a_' + id).className = 'tc_a tc_a_active'
	  }
}

function addtextdateto(id){
	var promenna, el;
	if (document.getElementById(id)) {
		el = document.getElementById(id);
		promenna = new Date();	
		el.setAttribute('value', promenna.getTime() + el.value);
	}
}
function ScrollImagesXX(sDirection){
  if(!sEnabledScroll){return 0}
    var xMax = document.getElementById('scrollarea').scrollLeft;
    var yMax = document.getElementById('scrollarea').scrollTop;
  if(sDirection == 'L'){
    document.getElementById('scrollarea').scrollLeft = xMax + 10;
    xCurr = document.getElementById('scrollarea').scrollLeft;
    if(sEnabledScroll){setTimeout("ScrollImages('L')", 100);}
  } else if(sDirection == 'R'){
    document.getElementById('scrollarea').scrollLeft = xMax - 10;
    xCurr = document.getElementById('scrollarea').scrollLeft;
    if(sEnabledScroll){setTimeout("ScrollImages('R')", 100);}
  } else if(sDirection == 'U'){
    document.getElementById('scrollarea').scrollTop = yMax + 10;
    yCurr = document.getElementById('scrollarea').scrollTop;
    if(sEnabledScroll){setTimeout("ScrollImages('U')", 100);}
  } else if(sDirection == 'D'){
    document.getElementById('scrollarea').scrollTop = yMax - 10;
    yCurr = document.getElementById('scrollarea').scrollTop;
    if(sEnabledScroll){setTimeout("ScrollImages('D')", 100);}
  }
}

function ScrollImages0(sDirection){
  if(!sEnabledScroll0){return 0}
			var xMax = document.getElementById('scrollarea0').scrollLeft;
			var yMax = document.getElementById('scrollarea0').scrollTop;
  if(sDirection == 'L'){
    document.getElementById('scrollarea0').scrollLeft = xMax + 10;
    xCurr = document.getElementById('scrollarea0').scrollLeft;
    if(sEnabledScroll0){setTimeout("ScrollImages0('L')", 100);}
  } else if(sDirection == 'R'){
    document.getElementById('scrollarea0').scrollLeft = xMax - 10;
    xCurr = document.getElementById('scrollarea0').scrollLeft;
    if(sEnabledScroll0){setTimeout("ScrollImages0('R')", 100);}
  } else if(sDirection == 'U'){
    document.getElementById('scrollarea0').scrollTop = yMax + 10;
    yCurr = document.getElementById('scrollarea0').scrollTop;
    if(sEnabledScroll0){setTimeout("ScrollImages0('U')", 100);}
  } else if(sDirection == 'D'){
    document.getElementById('scrollarea0').scrollTop = yMax - 10;
    yCurr = document.getElementById('scrollarea0').scrollTop;
    if(sEnabledScroll0){setTimeout("ScrollImages0('D')", 100);}
  }
}

function ScrollImages1(sDirection){
  if(!sEnabledScroll1){return 0}
			var xMax = document.getElementById('scrollarea1').scrollLeft;
			var yMax = document.getElementById('scrollarea1').scrollTop;
  if(sDirection == 'L'){
    document.getElementById('scrollarea1').scrollLeft = xMax + 10;
    xCurr = document.getElementById('scrollarea1').scrollLeft;
    if(sEnabledScroll1){setTimeout("ScrollImages1('L')", 100);}
  } else if(sDirection == 'R'){
    document.getElementById('scrollarea1').scrollLeft = xMax - 10;
    xCurr = document.getElementById('scrollarea1').scrollLeft;
    if(sEnabledScroll1){setTimeout("ScrollImages1('R')", 100);}
  } else if(sDirection == 'U'){
    document.getElementById('scrollarea1').scrollTop = yMax + 10;
    yCurr = document.getElementById('scrollarea1').scrollTop;
    if(sEnabledScroll1){setTimeout("ScrollImages1('U')", 100);}
  } else if(sDirection == 'D'){
    document.getElementById('scrollarea1').scrollTop = yMax - 10;
    yCurr = document.getElementById('scrollarea1').scrollTop;
    if(sEnabledScroll1){setTimeout("ScrollImages1('D')", 100);}
  }
}


function ScrollImages2(sDirection){
  if(!sEnabledScroll2){return 0}
			var xMax = document.getElementById('scrollarea2').scrollLeft;
			var yMax = document.getElementById('scrollarea2').scrollTop;
  if(sDirection == 'L'){
    document.getElementById('scrollarea2').scrollLeft = xMax + 10;
    xCurr = document.getElementById('scrollarea2').scrollLeft;
    if(sEnabledScroll2){setTimeout("ScrollImages2('L')", 100);}
  } else if(sDirection == 'R'){
    document.getElementById('scrollarea2').scrollLeft = xMax - 10;
    xCurr = document.getElementById('scrollarea2').scrollLeft;
    if(sEnabledScroll2){setTimeout("ScrollImages2('R')", 100);}
  } else if(sDirection == 'U'){
    document.getElementById('scrollarea2').scrollTop = yMax + 10;
    yCurr = document.getElementById('scrollarea2').scrollTop;
    if(sEnabledScroll2){setTimeout("ScrollImages2('U')", 100);}
  } else if(sDirection == 'D'){
    document.getElementById('scrollarea2').scrollTop = yMax - 10;
    yCurr = document.getElementById('scrollarea2').scrollTop;
    if(sEnabledScroll2){setTimeout("ScrollImages2('D')", 100);}
  }
}

function ScrollImages3(sDirection){
  if(!sEnabledScroll3){return 0}
			var xMax = document.getElementById('scrollarea3').scrollLeft;
			var yMax = document.getElementById('scrollarea3').scrollTop;
  if(sDirection == 'L'){
    document.getElementById('scrollarea3').scrollLeft = xMax + 10;
    xCurr = document.getElementById('scrollarea3').scrollLeft;
    if(sEnabledScroll3){setTimeout("ScrollImages3('L')", 100);}
  } else if(sDirection == 'R'){
    document.getElementById('scrollarea3').scrollLeft = xMax - 10;
    xCurr = document.getElementById('scrollarea3').scrollLeft;
    if(sEnabledScroll3){setTimeout("ScrollImages3('R')", 100);}
  } else if(sDirection == 'U'){
    document.getElementById('scrollarea3').scrollTop = yMax + 10;
    yCurr = document.getElementById('scrollarea3').scrollTop;
    if(sEnabledScroll3){setTimeout("ScrollImages3('U')", 100);}
  } else if(sDirection == 'D'){
    document.getElementById('scrollarea3').scrollTop = yMax - 10;
    yCurr = document.getElementById('scrollarea3').scrollTop;
    if(sEnabledScroll3){setTimeout("ScrollImages3('D')", 100);}
  }
}

function shfilter(idbox,idswitch){
	obj_swap(idbox);
	if (document.getElementById(idswitch)) {
    		el = document.getElementById(idswitch)
    		if(el.className == 'filter_switch switchclosed'){
			el.className = 'filter_switch switchopened'
		} else {
			el.className = 'filter_switch switchclosed'
		}
	}
}

function set_cookie(c_name,value,expiredays){
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+
  ((expiredays==null) ? "" : ";path=/;expires="+exdate.toGMTString());
}

function get_cookie(c_name){
  if (document.cookie.length>0){
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1){
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function fcprcheckswitch_basic(id,idcheck1,idcheck2){
  var el, elcheck1, elcheck2
  if(document.getElementById(id)){
	el = document.getElementById(id);
	  if(document.getElementById(idcheck1)){
	  	elcheck1 = document.getElementById(idcheck1);
		  if(document.getElementById(idcheck2)){
		  	elcheck2 = document.getElementById(idcheck2);

		        if(elcheck1.checked == false) {
				el.style.background = "url('img/DECprCheckOn.gif') no-repeat 0 0";
				elcheck1.checked = true;
				elcheck2.checked = false;
	        	}else {
			      el.style.background = "url('img/DECprCheckOf.gif') no-repeat 0 0";
			      elcheck1.checked = false;
			      elcheck2.checked = true;
			} 
		  }
	  }
  }
}

function obj_tabon(obj){
  if (document.getElementById(obj)) {
    el = document.getElementById(obj)
    el.style.display = 'table'
  }
}


function obj_checkset(obj,val){
  if (document.getElementById(obj)) {
    el = document.getElementById(obj)
    el.checked = val
  }
}

function prntoolsel_location(){
  if (document.getElementById('prntoolsel2')) {
    el = document.getElementById('prntoolsel2');
    adresa = el.options[el.selectedIndex].value+'&deep=-2&printnavigator=2';
    if (adresa=='&deep=-2&printnavigator=2'){
      document.location='default.asp?cls=spresenttrees&strtype=7&deep=2&printnavigator=1'
    }else{
      document.location=adresa
    }
  }	
}

function prnttool_show(n){
  if (document.getElementById('prntoolsel1') && document.getElementById('prntoolsel2')) {
    el1 = document.getElementById('prntoolsel1');
    el2 = document.getElementById('prntoolsel2');
    string = el1.options[el1.selectedIndex].value;
    for (var i = 1; i<n+1; i++) {
      if (document.getElementById('prntoolsel2X'+i)){
	el3 = document.getElementById('prntoolsel2X'+i);
	if (el3.className.substring(0,4)==string){
  	  el3.style.display='';
	  el3.style.color='black';
	  el3.disabled=false;
	}else{
  	  el3.style.display='none';
	  el3.style.color='silver';
	  el3.disabled=true;
          el3.selected=false;
	}
      }
    } 
  }	
}

function prntoolsel(i){
  if (document.getElementById('prntoolsel'+i)){
    el = document.getElementById('prntoolsel'+i);
    string = el.options[el.selectedIndex].value;
    if (string=='') string='default.asp?cls=spresenttrees&strtype=7';
    if (i==1) document.location=string+'&printnavigator=2';
    if (i==2) document.location=string+'&printnavigator=3';
  }
}


/*----------------------------------------------------------*/
/* Memo form  - pokud form ma class 'memoForm' hodnoty jeho prvku jsou zalohovany do cookie*/
var memoCookiePrefix = 'I6_frmmem_';
var spch = '$$';
var eqch = '##';

function initMemoForms(){

  var frmelm

  var formColl = document.forms;

  if(formColl && formColl != null && formColl.length )
  {
    for (z=0;z<formColl.length ;z++)
      {
        if(formColl[z].className.toString().indexOf("memoform")>-1)
          {
            fillMemoForm(formColl[z].name);
            
            frmelm = formColl[z].elements;
            for(iii=0;iii<frmelm.length;iii++)
            {
              if(frmelm[iii].type!='hidden')
                {
                  frmelm[iii].onchange= function (e) {var e=window.event || e; memoFormChanged(e);};
                }
            }
          }
      }
  }
  
}

function fillMemoForm(objFormName){
  /*naplni inputy s cookiny*/
  var objForm
  var inpName
  var inpValue  
  var arrInp
  
  //alert('fillmemoform...'+objForm.name);
  objForm = document.forms[objFormName];
  
  var cookieString = unescape(get_cookie(memoCookiePrefix+objFormName));
  arrInp = cookieString.split(spch);
  
  if(cookieString == null || cookieString=='')
  return;
  
  //alert('filling form...  InCookie:s'+cookieString+'e');
  
  if(!arrInp || arrInp == null)
    return;
   
    
  for(ii=0;ii<arrInp.length;ii++)
  {
    if(arrInp[ii].split(eqch) == null || arrInp[ii].split(eqch).length !=2 )
      return;
  
    //alert('inpstring:'+arrInp[ii]+';');
    //alert('name:'+arrInp[ii].split(eqch)[0]+';value:'+arrInp[ii].split(eqch)[1]+';');
  
    inpName = arrInp[ii].split(eqch)[0];
    inpValue = arrInp[ii].split(eqch)[1];
    
    //alert('next input named: '+inpName)
    //alert(objForm.elements[inpName]);
    
    if((objForm.elements[inpName] && (objForm.elements[inpName].type== 'text' || objForm.elements[inpName].type== 'textarea')) && inpValue.length >0)
      {
      if(objForm.elements[inpName] && objForm.elements[inpName] != null)
        {
          if(!objForm.elements[inpName].value || objForm.elements[inpName].value =='' || objForm.elements[inpName].value ==null)
              {
                objForm.elements[inpName].value = inpValue;   
              }
        }
        
      } 
  }
  return;
}

function memoFormChanged(e){
  //alert('memo form changed...!');
  var contName = '';
  var objForm,objInput  
  var cookieString = '';
  var arr
 
 objInput = e.currentTarget || e.srcElement
 if(!objInput || objInput == null)
  return;
  
  objForm = objInput.form
 if(!objForm || objForm == null)
  return;
  
  /* vyhodim oktualni hodnotu inputu z cookiny*/ 
  cookieString = unescape(get_cookie(memoCookiePrefix+objForm.name));
  arr = cookieString.split(spch)
  cookieString = '';  
  if(!arr || arr == null)
    return;
  
  for(ii=0;ii<arr.length;ii++)
    {
      if(!arr[ii].match(objInput.name) && arr[ii].length >0)   
         {
            if(cookieString.length >0)
              cookieString = cookieString +spch+ arr[ii];
            else
              cookieString = arr[ii];
         }
    }
  
  /*pridam novou hodnotu do cookiny*/
  if(cookieString.length >0)
    cookieString = cookieString + spch +objInput.name+eqch+objInput.value;  
  else
    cookieString = objInput.name+eqch+objInput.value;
    
  set_cookie(memoCookiePrefix+objForm.name,cookieString,10000);

}

function fireEventOnChange(objToFire)
{

//On IE
if(objToFire.fireEvent)
{
  objToFire.fireEvent('onchange');
}
//On Gecko based browsers
if(document.createEvent)
{
var evt = document.createEvent('HTMLEvents');
if(evt.initEvent)
{
evt.initEvent('change', true, true);
}
if(objToFire.dispatchEvent)
{
objToFire.dispatchEvent(evt);
}

}
} 

/* end of  Memo form */


