function showCategoriesLevel2(divID, parID,bStatus)
{
	if (getE(divID).style.display == "none")
	{
		getE(divID).style.display = "block";
		getE(parID).className = "SubCategory_H"+bStatus
	}
	else
	{
		getE(divID).style.display = "none";
		getE(parID).className = "SubCategory"+bStatus
	}
}
function showCategoriesLevel3(divID, parID)
{
	if (getE(divID).style.display == "none")
	{
		getE(divID).style.display = "block";
		getE(parID).className = "TitleSubCat_H"
	}
	else
	{
		getE(divID).style.display = "none";
		getE(parID).className = "TitleSubCat"
	}
}

function getE(objectID) {
	return document.getElementById(objectID);
}

function getF(formName) {
	return document.forms[formName];
}

function ShowDate(strItem) {
     var strReturn = showModalDialog("/SelectDate.htm","","status:no; center:yes; help:no; minimize:no;dialogWidth=250pt;dialogHeight=200pt");
     if (strReturn == undefined){return;}
     strItem.value = strReturn;
}
function fnParamChanger(v)
{
	if(typeof document.all.idParamChanger == 'object')
	{
		n = v.indexOf('<!--')
		if (!isNaN(n))
		{
			v = v.substr(n+4)
			n = v.indexOf('-->')
			if (!isNaN(n))
			{
				v = v.substr(0, n)
				v=v.replace(' ','&nbsp;')
				document.all.idParamChanger.innerHTML = v;
			}
		}
	}
}


function CheckOnStore(){
	//alert(document.forms.SortForm.bCheckbox);
	if (document.forms.SortForm.bCheckbox.checked){
		document.forms.SortForm.bOnlyOnStock.value=1;
	}else{
		document.forms.SortForm.bOnlyOnStock.value=0;
	}
	document.forms.SortForm.submit();
}

function onAction(imgName){
       document [imgName].src = eval(imgName + "on.src")
  }

function offAction(imgName){
        if (oldImgName.substring(0,4)!=imgName.substring(0,4)){
              document [imgName].src = eval(imgName + "off.src")
            }
  }

function OpenWnd(strURL){
         var objWnd = window.open(strURL,"InfoDetail","scrollbars=no,height=500,width=400,left=10,top=10");
         objWnd.focus();
}

function AddBuy(strName, intPrice, intDph, strCode) {
        var strData,strReturn
        strData = strName+"&"+intPrice+"&"+intDph+"&"+strCode
        strReturn = showModalDialog("/AddUpdBuy.asp",strData,"status:no; center:yes; help:no; minimize:no;dialogWidth=350pt;dialogHeight=200pt");
        if (strReturn == "1"){ActionCookies('BZbuy')
        }else if (strReturn == "2"){window.location.href="/order.asp"}
}
function AddBuyDetail(strName, intPrice, intDph, strCode) {
        var strData,strReturn
        strData = strName+"&"+intPrice+"&"+intDph+"&"+strCode
        strReturn = showModalDialog("/AddUpdBuy.asp",strData,"status:no; center:yes; help:no; minimize:no;dialogWidth=350pt;dialogHeight=200pt");
        if (strReturn == "1"){
                        window.opener.ActionCookies('BZbuy')
        }else if (strReturn == "2"){
                        window.opener.location.href="/order.asp";
                        window.close();
                }
}
function ActionCookies(strName){
        var strString,strSum1,strSum2,intSuma;
        strSum2 = new Array();
        intSuma = 0;

        strString = ExtractCookies(strName);
        if (strString > ""){
                strSum1 = strString.split("#");
                for (var i=0; i< strSum1.length-1; i++){
                              strSum2[i] = strSum1[i].split("&");
                        intSuma += BarterComma(strSum2[i][1])*BarterComma(strSum2[i][4]);
                }
                document.all.CompletPrice.value =  FormatNumber(intSuma);
        }
}

function DeleteCookies(strName){
        var vyprs=new Date();
        vyprs.setDate(vyprs.getDate() - 365);
        document.cookie=strName+"=; expires="+vyprs.toGMTString()+";";
        vyprs.setDate(365 + 365 + vyprs.getDate());
        document.cookie=strName+"=; expires="+vyprs.toGMTString()+";";
        document.all.CompletPrice.value = "0.00";
}
function InsTreeCook(intId,idTree){
        var vyprs=new Date();
        vyprs.setDate(vyprs.getDate() - 365);
        document.cookie="category"+idTree+"="+intId+"; expires="+vyprs.toGMTString()+";";
        vyprs.setDate(365 + 365 + vyprs.getDate());
        document.cookie="category"+idTree+"="+intId+"; expires="+vyprs.toGMTString()+";";
}
function InsertCookies(strName,strData){
        var vyprs=new Date();
        vyprs.setDate(vyprs.getDate() - 365);
        document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+";";
        vyprs.setDate(365 + 365 + vyprs.getDate());
        document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+";";
}

function ExtractCookies(strName){
        var cookieList=document.cookie.split("; ");
        var cookieArray = new Array();
        var name = "#"
        for (var i=0; i < cookieList.length; i++){
                if(cookieList[i].indexOf(strName)>-1){
                      if( cookieList[i].indexOf("=")>-1){name = cookieList[i].split("=");}
                 }
        }
        if (name != "#"){
                        return name[1];
        }else{
                        return "none";
        }
}

function ParseCookies(strName){
        var strCook = ExtractCookies(strName)
        if (strCook != "none"){
                var strList = strCook.split("a");
                for (var i=0; i < strList.length-1; i++){
                  if(typeof(document.all[strList[i]+'a']) == "object"){document.all[strList[i]+'a'].click();}
                }
     }
}
function FormatNumber(text){
        var mezi = BarterComma(text);
        mezi = ''+Math.round(parseFloat(mezi) * 100);
        var desetiny = mezi.substring(mezi.length-2, mezi.length);
        var cele = mezi.substring(0,mezi.length-2);
        if (parseFloat(mezi) < 1){
                var mezi = "0."+desetiny;
        }else{
                var mezi = cele+"."+desetiny;
        }
        return mezi;
}
function BarterComma(text){
        var mezi = ''+text;
        if (mezi.indexOf(',') != -1){
                mezi = mezi.split(",");
                mezi = mezi[0]+"."+mezi[1];
        }else{
                mezi = text;
        }
        return parseFloat(mezi);
}
function ControlNumber(){
     if ((event.keyCode <48) || (event.keyCode >57)) event.returnValue = false;
}
//----------info okno-------------------------------------------------------
function InfoWindow(strAddress) {
       showModalDialog(strAddress,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=450pt;dialogHeight=320pt");
}
function WriteDate(){
    var strDay=new Date();
    var d=strDay.getDay();
    if (d==1) {document.writeln('pondělí') }
    else { if (d==2) {document.writeln('úterý') }
    else { if (d==3) {document.writeln('středa') }
    else { if (d==4) {document.writeln('čtvrtek') }
    else { if (d==5) {document.writeln('pátek') }
    else { if (d==6) {document.writeln('sobota') }
    else { if (d==0) {document.writeln('neděle') }}}}}}};
    document.writeln(strDay.getDate(),'.',strDay.getMonth()+1,'.',strDay.getFullYear());
    }
function EmailControl(f){
    if ((f=='' || f=='vas@email.cz') ||(f.indexOf('@') < 1 || f.indexOf('@') != f.lastIndexOf('@') || f.lastIndexOf('.') < f.lastIndexOf('@')+2  || f.lastIndexOf('.') > (f.length-3) || f.lastIndexOf('.') < (f.length-4))){
       alert('Nesprávný formát emailu');
       return false;
       }
    return true;
}
function ShowSearchMenu(x){
    if (x == 1){
        document.all.SearchTable.style.display='';
    }else{
        document.all.SearchTable.style.display='none';
    }
}
function LocInfo(){
    document.all.StateInfo2.innerHTML="  probíhá připojování...";
    var e = event.srcElement;
    var y = 0;
    var x = 0;
    while (typeof e == 'object' && e.tagName != 'BODY'){
          y += e.offsetTop;
          e = e.offsetParent;
    };
    x = (window.screen.width/2)+375
    document.all.StateInfo1.style.top=y-140;
    document.all.StateInfo1.style.left=x;
}

function PositionInfo(strText){
    document.all.StateInfo3.innerHTML=strText;
    document.all.StateInfo2.innerHTML="  probíhá připojování...";
    var e = event.srcElement;
    var y = 0;
    var x = event.clientX;
    while (typeof e == 'object' && e.tagName != 'BODY'){
          y += e.offsetTop;
          e = e.offsetParent;
    };
    document.all.StateInfo1.style.top=y-140;
    if (document.body.clientWidth < 933){
      document.all.StateInfo1.style.left=x-175;
    }else{
      document.all.StateInfo1.style.left=780;
    }
}
function LocState(strCode,intCount){
    window.parent.frames['WinStat'].location.href="/InfoState.asp?ID="+strCode+"&CN="+intCount
    PositionInfo("On-line stav");
}
function ChangeStorage(bState){
    if(bState){
        for(var i = 0; i < document.all['S'].length; i++){
            document.all['S'][i].value="0"
        }
    }else{
        for(var i = 0; i < document.all['S'].length; i++){
            document.all['S'][i].value="-1"
        }

    }
}
function ChangeCloseout(bState){
    if(bState){
        for(var i = 0; i < document.all['C'].length; i++){
            document.all['C'][i].value="1"
        }
    }else{
        for(var i = 0; i < document.all['C'].length; i++){
            document.all['C'][i].value="3"
        }

    }
}

function ControlUserDataSubmit(){
  if((document.UserDataForm.FirstName.value == "" ||document.UserDataForm.LastName.value == "")& document.UserDataForm.Firm.value == ""){alert("Vyplňte název firmy nebo jméno a příjmení.");return false}
  if(document.UserDataForm.Street.value == ""){alert("Vyplňte ulici.");return false}
  if(document.UserDataForm.City.value == ""){alert("Vyplňte město.");return false}
  if(document.UserDataForm.ZipCode.value == ""){alert("Vyplňte PSČ.");return false}
  if(document.UserDataForm.Phone.value == ""){alert("Vyplňte telefon.");return false}
  if(document.UserDataForm.Email.value == ""){alert("Vyplňte email.");return false}
  if(document.UserDataForm.Login.value == ""){alert("Vyplňte přihlašovací jméno.");return false}
  if(document.UserDataForm.Login.value.length < 8){alert("Přihlašovací jméno musí mít minimálně 8 znaků.");return false}
  if(document.UserDataForm.Password.value == ""){alert("Vyplňte heslo.");return false}
  if(document.UserDataForm.Password.value.length < 8){alert("Heslo musí mít minimálně 8 znaků.");return false}
  return true
}
function ControlDataOrder(){
  if(document.OrderForm.DeliveryType.value == "-"){alert("Vyberte způsob dopravy.");return false}
  if(document.OrderForm.PaymentType.value == "-"){alert("Vyberte způsob platby.");return false}
  return true
}
function ShowSearchMenu2(on, x, y, objy){	
   
    if (on == 1){
		//var x = 0;
		//var y = 0;
		
		document.getElementById(objy).style.left = x;
		document.getElementById(objy).style.top = y;
		document.getElementById(objy).style.display='';
		//alert(document.getElementById(objy).style.display);
    }else{
       document.getElementById(objy).style.display='none';
    }
}

function InsCoo(intId){
	InsertCookies('category', intId);
	//document.cookie="category="+intId+";";
	//document.cookie="category="+intId+";";
	//document.cookie="category="+intId+";";
	//document.cookie="category="+intId+";";
	//document.cookie="category="+intId+";";
	//document.cookie="category="+intId+";";
	//document.cookie="category="+intId+";";
	//document.cookie="category="+intId+";";
}
function checkParent(src, dest) {
	while (src!=null) {
		if (src.tagName == dest) return src;
		src = src.parentElement;
	//	alert(src.tagName);
	}
	return null;
}

function outlineCat(e) {

	clickElem = (e.target) ? e.target : e.srcElement;
	
  if (clickElem.tagName == 'IMG') {
  clickElem = clickElem.offsetParent;
  }

	var el = checkParent(clickElem, "TD");
	var ela = checkParent(clickElem, "TD");
	if (null!=el) {
		
		for (var pos=0; pos<el.childNodes.length; pos++) {
			
			if (el.childNodes[pos].tagName=="TABLE") {
				if (el.childNodes[pos].style.display=="block") {
					el.childNodes[0].src = "/img/catTree/plus.gif";
				}else{
					el.childNodes[0].src = "/img/catTree/minus.gif";
				}
				break;
			}
		}
	    if (pos==el.childNodes.length) return;
	} else return;
	el = el.childNodes[pos];
	if ("TABLE"==el.tagName) {
		if (el.style.display=="block") {
			el.style.display = "none";
		} else {
			el.style.display = "block";
		}
	}
	//event.cancelBubble = true;
	
}

var gsCatParentSTR = "";
var gsCatCookie = ExtractCookies('category');
//alert(gsCatCookie);
function CatA(pkCat, sNameCat, sLink, variant, nLevel) {
	//if(nLevel == 1){sNameCat = "<strong>" + sNameCat + "</strong>" }

		return "<a href=\'" + sLink + "\' onclick='javascript: InsCoo(\"" + gsCatParentSTR + "x" + pkCat + "a\");'>" + sNameCat + "</a>";
}
// CatMain
function CM(pkCat, sNameCat, sLink){
	document.write(
			"<tr><th>" + CatA(pkCat, sNameCat, sLink, 1) + "</th></tr>"
			);
}			
// CatSame
function CS(pkCat,nChildren,sNameCat, sLink, nLevel) {
	var i = gsCatParentSTR.lastIndexOf("x");
	var nParentCat = gsCatParentSTR.substr(i+1,gsCatParentSTR.length - i - 2);
	document.write(
		"<tr><td class='KatBG"+nLevel+"' id='x" + pkCat + "a' style='z-index:10;'>" +
		"<img style='float:left;margin:3px 3px 0px 0px;cursor:pointer;' src='/img/catTree/" + ((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "plus" : "minus") : "nic") + ".gif' /><div style='z-index:0;margin-left:10px;_margin-left:0px;width:auto;_width:95%;'>" +
		CatA(pkCat, sNameCat, sLink, 0, nLevel) +
		((nChildren > 0) ? "</div>" :	"</div></td></tr>")
	);
}
// CatLower
function CL(pkCat, nParentCat, nChildren, nRowSpan, sNameCat, sLink, nLevel) {
	gsCatParentSTR = gsCatParentSTR + "x" + nParentCat + "a";
	document.write(
		"<table class='seznam bgSez"+nLevel+"' width='100%' " + ((gsCatCookie.indexOf("x" + nParentCat + "a")==-1)?"":" style='display:block;'") + ">" +
		"<tr><td width='1%'  valign='top' rowspan='" + nRowSpan + "'></td>" +
		"<td id='x" + pkCat + "a' class='KatBG"+nLevel+"'><img style='float:left;margin:3px 3px 0px 0px;cursor:pointer;' src='/img/catTree/" +	((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "plus" : "minus") : "nic") + ".gif'><div style='margin-left:10px;_margin-left:0px;width:auto;_width:95%;'>" +
		CatA(pkCat, sNameCat, sLink, 0, nLevel) + "</div>"
	);
}
// CatEnd
function CE() {
	var i = gsCatParentSTR.lastIndexOf("x");
	gsCatParentSTR = gsCatParentSTR.substr(0,i);
	document.write("</td></tr></table>");
}
// CatHigher
function CH(pkCat, nChildren, sNameCat, sLink, nLevel) {
	document.write(
		"</td></tr>" +
		"<tr><td id='x" + pkCat + "a' class='KatBG"+nLevel+"'><img  style='float:left;margin:3px 3px 0px 0px;cursor:pointer;' onclick='InsCoo(\"" + gsCatParentSTR + "x" + pkCat + "a\");' src='/img/catTree/" + ((nChildren > 0) ? ((gsCatCookie.indexOf("x" + pkCat + "a")==-1) ? "plus" : "minus") : "nic") + ".gif' /><div style='margin-left:10px;_margin-left:0px;width:auto;_width:95%;'>" +
		CatA(pkCat, sNameCat, sLink, 0, nLevel) + "</div>"
	);
}

function OpenWndAdvance(strURL, Y, X){
	var swindowname = "info";
	var sParameters = "scrollbars=yes,height=" + Y + ",width=" + X
  var objWnd = window.open(strURL,swindowname,sParameters);
  objWnd.focus();
}





