// FUNKCE PRO VYPLNENI FORMULARE
function vypln(id, default_value, value)
{
  if(value == default_value || value == '')
  {
    document.getElementById(id).value = default_value;
  }
  else
  {
    document.getElementById(id).value = value;
  }
}

// FUNKCE PRO POCATECNI VYMAZANI FORMULARE
function smaz(id, default_value, value)
{
  if(value == default_value || value == '')
  {
    document.getElementById(id).value = '';
  }
  else
  {
    document.getElementById(id).value = value;
  }
}

// FUNKCE PRO SKRYTI/ZOBRAZENI ZNACEK
function zobrazznacky()
{
  if(document.getElementById('content_brands_list').style.display == "block" && document.getElementById('content_brands_footer').style.display == "block")
  {
    document.getElementById('content_brands_list').style.display = "none";
    document.getElementById('content_brands_footer').style.display = "none";
  }
  else
  {
    document.getElementById('content_brands_list').style.display = "block";
    document.getElementById('content_brands_footer').style.display = "block";
  }
}

// FUNKCE PRO ZOBRAZENI BOOKMARKU
function open_bookmark(id)
{
  seznam = document.getElementById('content_detail_bookmarks_menu').getElementsByTagName('li');

  // Zobrazeni jednotlivych obsahu  
  for(i = 0; i < seznam.length; i++)
  {
    document.getElementById('bookmark' + (i+1)).style.display = "none";
    document.getElementById('bookmark_button' + (i+1)).className = "content_detail_bookmarks_noshadow";
  }
  document.getElementById('bookmark' + id).style.display = "block";
  // Prvni tlacitko
  if(id != 1)
  {
    document.getElementById('bookmark_button1').className = "content_detail_bookmarks_noshadow";
  }
  // Posledni tlacitko
  if(id != seznam.length)
  {
    document.getElementById('bookmark_button' + (id + 1)).className = "content_detail_bookmarks_shadow";
  }
  // Aktivni tlacitko
  document.getElementById('bookmark_button' + id).className = "content_detail_bookmarks_active";
}

function popUpWindow() {
    this.offsetX = -40;
    this.offsetY = 20;
    this.ie = document.all;
    this.ns6 = document.getElementById && !document.all;
    this.show = false;
    this.ietruebody = function() {
        return (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
    };
    this.showPopUpWindow = function(content,divName) {
        if (this.ns6||this.ie) {
                this.box = document.all? document.all[divName] : document.getElementById? document.getElementById(divName) : "";
                this.box.innerHTML = content;
                this.show = true;
                return false;
        }
    };
    this.hidePopUpWindow = function() {
        if (this.ns6||this.ie) {
                this.show = false;
                this.box.style.visibility = "hidden";
        }		
    };
}

function setPosition(e) {					
    if (popUpObject.show) {
        var leftCorr = 45;
        var topCorr = 0;
        var edgCorr = 5;
        var varX = (popUpObject.ns6)?e.pageX : event.clientX + popUpObject.ietruebody().scrollLeft;
        var varY = (popUpObject.ns6)?e.pageY : event.clientY + popUpObject.ietruebody().scrollTop;
        var rightEdge = popUpObject.ie&&!window.opera? popUpObject.ietruebody().clientWidth-event.clientX-popUpObject.offsetX : window.innerWidth-e.clientX-popUpObject.offsetX-20;
        var bottomEdge = popUpObject.ie&&!window.opera? popUpObject.ietruebody().clientHeight-event.clientY-popUpObject.offsetY : window.innerHeight-e.clientY-popUpObject.offsetY-20;
        var leftedge=(popUpObject.offsetX < 0) ? popUpObject.offsetX*(-1) : -1000;
        if (rightEdge < popUpObject.box.offsetWidth)
            popUpObject.box.style.left = popUpObject.ie ? popUpObject.ietruebody().scrollLeft + event.clientX-popUpObject.box.offsetWidth + "px" : window.pageXOffset + e.clientX - tipobj.offsetWidth + "px";
        else if (varX < leftedge)
            popUpObject.box.style.left = edgCorr + "px";
        else
            popUpObject.box.style.left = varX + popUpObject.offsetX + leftCorr + "px";
        if (bottomEdge < popUpObject.box.offsetHeight)
            popUpObject.box.style.top = popUpObject.ie ? popUpObject.ietruebody().scrollTop + event.clientY - popUpObject.box.offsetHeight - popUpObject.offsetY + "px" : window.pageYOffset + e.clientY - popUpObject.box.offsetHeight - popUpObject.offsetY + "px";
        else {
            popUpObject.box.style.top=varY + popUpObject.offsetY - topCorr + "px";
            popUpObject.box.style.visibility = "visible";
        }
    }
}

var popUpObject = new popUpWindow();
document.onmousemove = setPosition;

// Schování fakturační adresy u objednávek
function schovej_fakturacni_adresu(schovej) {
	var o; var oid='fakturacniadresatabulka'; // id prvku ke skryti
	// nejdriv najdeme prvek
	if(document.getElementById) o=document.getElementById(oid); // moderni prohlizece
	else if(document.all) o=document.all[oid]; // IE6 a starsi
	else return; // nepodporovano, stary Netscape uz neresim, konec
	if(!o) return; // prvek nenalezen (neni na strance, tj. je jina stranka nez s fakturacni adresou), konec
	// schovej puvodni hodnotu
	if(typeof o.style.oldDisplay=='undefined') o.style.oldDisplay=o.style.display;
	// skryj nebo zobraz podle pozadavku (st=0 zobraz, st=1 skryj)
	o.style.display=(schovej?'none':o.style.oldDisplay);
}

window.onload=function() { schovej_fakturacni_adresu(true); } // skryj fakturacni adresu  pri onload
