// KOMPATIBILITA

var Br = new BrCheck()

function BrCheck()
{
	this.VER	= navigator.appVersion;
	this.AGENT	= navigator.userAgent.replace(/[\/]/g,' ');
	this.DOM	= document.getElementById ? true:false;

	this.OP5	= this.AGENT.indexOf("Opera 5")>-1							?true:false;
	this.OP6	= this.AGENT.indexOf("Opera 6")>-1							?true:false;
	this.OP7	= this.AGENT.indexOf("Opera 7")>-1							?true:false;
	this.OP8	= this.AGENT.indexOf("Opera 8")>-1							?true:false;
	this.OP		= (this.OP5 || this.OP6 || this.OP7 || this.OP8);

	this.IE4	= (document.all && !this.DOM && !this.OP)					?true:false;
	this.IE5	= (this.VER.indexOf("MSIE 5")>-1 && this.DOM && !this.OP)	?true:false; 
	this.IE6	= (this.VER.indexOf("MSIE 6")>-1 && this.DOM && !this.OP)	?true:false;
	this.IE7	= (this.VER.indexOf("MSIE 7")>-1 && this.DOM && !this.OP)	?true:false;
	this.IE		= (this.IE4 || this.IE5 || this.IE6 || this.IE7);

	this.Gecko  = this.AGENT.lastIndexOf('Gecko')>0;
	this.NS4	= (document.layers && !this.DOM)							?true:false;
	this.NS7	= (this.DOM && parseInt(this.VER) >= 5 && this.AGENT.lastIndexOf('Netscape')<this.AGENT.lastIndexOf('7'))?true:false;
	this.NS6	= (this.DOM && parseInt(this.VER) >= 5 && !this.NS7)		?true:false;
	this.NS		= (this.NS4 || this.NS6 || this.NS7 || this.Gecko);

	return this;
}

function getE(objectID) {
	return document.getElementById(objectID); 
}

function getF(formName) {
	return document.forms[formName];
}


function SetDSP(nDSP, sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);
	
	if (nDSP==1) {
		InsertUserCookie('DSP','1');
	} else {
		InsertUserCookie('DSP','0');
	}
	window.location.href=sURL;
}



// ###   FCE PRO zaskrtnutí a odeslání pk zboží pro Compare.asp   ###

function CompareSelected() {
	var sapkTblCommodity, CompareAdd;
	sapkTblCommodity = "";
	//aby to fungovalo vsude mozzila ie atd....
	for (var x=0; x<document.forms.length;x++){
		if (document.forms[x].name.indexOf("BuyFormBody")){
			if (document.forms[x].CompareAdd){
				if(document.forms[x].CompareAdd.checked){
					if (sapkTblCommodity=="") {
						sapkTblCommodity = document.forms[x].CompareAdd.value;
					}else{
						sapkTblCommodity += "|" + document.forms[x].CompareAdd.value;
					}
				}
			}
		}
	}
	if (sapkTblCommodity.indexOf('|') == -1) {

		alert('Pro porovnání je nutno vybrat nejméně 2 výrobky ...');
	} else {
		window.open('/Compare.asp?CMP=' + sapkTblCommodity, "Compare","scrollbars=1,status=0,toolbar=0,location=0,directories=0,height=500,width=720,left=10,top=10,resizable=1,");
	}
}

function CompareRemoveOne(sapkTblCommodity, sComToRem) {
	var apkTblCommodity, aLen;
	if (sapkTblCommodity == '') {
		window.close();
		return;
	}
	apkTblCommodity = sapkTblCommodity.split('|');
	aLen = apkTblCommodity.length;
	if (aLen == 1) {
		window.close();
		return;
	}
	sapkTblCommodity = '';
	for (var i=0; i<aLen; i++) {
		if (apkTblCommodity[i]!=sComToRem) {
			if (sapkTblCommodity=='') {
				sapkTblCommodity = apkTblCommodity[i];
			} else {
				sapkTblCommodity += "|" + apkTblCommodity[i];
			}
		}
	}
	window.location.href = '/Compare.asp?CMP=' + sapkTblCommodity;
}

// ###   FCE PRO BOXIKY SE SUBKATEGORIEMI   ###

var IdTimeToHideCategoryBox;

function ShowCategoryBox(img_id, cat_id)
{
	if ((IdTimeToHideCategoryBox!=null) && (cat_id!=cat_id_last)) HideAllCategoryBox(cat_id_last);

	var objElem = img_id;
    var x = 0;
    var y = 0;
    x += parseFloat(objElem.offsetLeft) + parseFloat(objElem.offsetWidth);
    y += parseFloat(objElem.offsetTop);

	getE('categoryBoxtable_' + cat_id).style.left = x;
	getE('categoryBoxtable_' + cat_id).style.top = y - 10;
	getE('categoryBoxtable_' + cat_id).style.display = 'block';
}

function HideCategoryBox(cat_id)
{
	cat_id_last = cat_id;
	IdTimeToHideCategoryBox = window.setTimeout('HideAllCategoryBox(' + cat_id + ')', 300);
}

function HideAllCategoryBox(cat_id)
{
	window.clearTimeout(IdTimeToHideCategoryBox);
	IdTimeToHideCategoryBox = null;
	getE('categoryBoxtable_' + cat_id).style.display = 'none';
}

// ###   FCE PRO DIALOG ZADANI VOLITELNYCH PARAMETRU   ###
var gsFormSuffix, gsFormIndex;


// ###   FCE PRO ROZKLIKAVANI KATEGORII   ###

function InsertCookiesCat(intId,idTree){
	document.cookie="category"+idTree+"="+intId+";path=/;";
}
function checkParent(src, dest) {
	while (src!=null) {
		if (src.tagName == dest) return src;
		src = src.offsetParent;
	}
	return null;
}

function outlineCat(e) {
	var open = (e.target) ? e.target : e.srcElement;
	var el = checkParent(open, "TD");
	if (null!=el) {
		for (var pos=0; pos<el.childNodes.length; pos++) {
			if ((el.childNodes[pos].tagName=="TABLE")) {
				
				var nodeNum = (Br.IE ? 0 : 1);
				
				if (el.childNodes[nodeNum].src.indexOf("plus")>0) {
					el.childNodes[nodeNum].src = el.childNodes[nodeNum].src.replace("plus","minus");
				}else if (el.childNodes[nodeNum].src.indexOf("minus")>0) {
					el.childNodes[nodeNum].src = el.childNodes[nodeNum].src.replace("minus","plus");
				}

				break;
			}
		}
	    if (pos==el.childNodes.length) return;
	} else return;
	el = el.childNodes[pos];
	if ("TABLE"==el.tagName) {
		if (el.style.display!="none") {
			el.style.display = "none";
		} else {
			el.style.display = "block";
		}
	}
//	event.cancelBubble = true;
}



/* COMPARE  */

var gCCompnTree = 1;
var gCCompIDs = ExtractCookies('CComp'+gCCompnTree).replace('none','');

function CCompChCli(o) {

	if (o)
	if (o.checked==true)
	{
		if (gCCompIDs.indexOf('|'+o.value+'|') < 0)	gCCompIDs += '|'+o.value+'|';
		if (gCCompIDs != '') CCompOn();
	}
	else
	{
		gCCompIDs = gCCompIDs.replace('|'+o.value+'|', '');
		if (gCCompIDs == '') CCompOff();
	}
	
	InsertCookies('CComp'+gCCompnTree,gCCompIDs);
}

function CCompChOn()
{
	var ch = document.getElementsByName('ccompCh');
	for (var i=0; i<ch.length; i++) {
		if (gCCompIDs.indexOf('|'+ch[i].value+'|') > -1)
			ch[i].checked = true;
	}
}	
function CCompChOff()
{
	var ch = document.getElementsByName('ccompCh');

	for (var i=0; i<ch.length; i++)
		ch[i].checked = false;

	gCCompIDs = '';
	InsertCookies('CComp'+gCCompnTree,'');

}

function CCompGo() { // open compare

	var q = gCCompIDs;
	
	while(q.indexOf('||') > -1) q = q.replace('||', ',');
	while(q.indexOf('|') > -1) q = q.replace('|', '');
	
	if (gCCompIDs=='')	{
		alert('Zvolte si zboží k porovnání')
	} else {
		compareWindow = window.open('/Compare.asp?d='+q,'compareWin','scrollbars=1,status=0,toolbar=0,location=0,directories=0,height=750,width=900,left=10,top=10,resizable=1');
		compareWindow.focus();
	}
}


function CCompOn()
{
	var im = document.getElementById('idCCompGo');
	var de = document.getElementById('idCCompDel');
}


function CCompOff()
{
	var im = document.getElementById('idCCompGo');
	var de = document.getElementById('idCCompDel');
}


function CCompStartup(nTree)
{
	gCCompnTree = nTree.toString();
	gCCompIDs = ExtractCookies('CComp'+gCCompnTree).replace('none','');

	
	if (gCCompIDs != '')
	{
		CCompOn();
		CCompChOn();
	}
}


function CCompDel()
{
	gCCompIDs = '';
	InsertCookies('CComp'+gCCompnTree,gCCompIDs);
	CCompOff();
	CCompChOff();
}





// ###   FCE PRO PriceList ###

function SHModalDlgPricelist()
{
	var strReturn = showModalDialog("/Includes/EmailPricelist.htm","","status:no; center:yes; help:no; minimize:no;dialogWidth=320px;dialogHeight=124px;");

    if (strReturn == "") return;
	document.location.href = "/EmailPricelist.asp?EmailPricelist=" + strReturn;
}

// ##########

function onAction(imgName){
       getE(imgName).src = eval(imgName + "on.src")
}

function offAction(imgName){
	if (oldImgName.substring(0,4)!=imgName.substring(0,4)){
		getE(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]);
		}
		getE('CompletPrice').value =  FormatNumber(intSuma);
	}
}
function DeleteCookies(strName){
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() - 365);
	document.cookie=strName+"=; expires="+vyprs.toGMTString()+"; path=/;";
	vyprs.setDate(365 + 365 + vyprs.getDate());
	document.cookie=strName+"=; expires="+vyprs.toGMTString()+"; path=/;";
	getE('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()+"; path=/;";
	vyprs.setDate(365 + 365 + vyprs.getDate());
	document.cookie="category"+idTree+"="+intId+"; expires="+vyprs.toGMTString()+"; path=/;";
}
function InsertCookies(strName,strData){
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() - 365);
	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+"; path=/;";
	vyprs.setDate(365 + 365 + vyprs.getDate());
	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+"; path=/;";
}

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";
	}
}
/***************************************************************************/
/***************************************************************************/
	var cookie_expire=new Date();
	cookie_expire.setDate(cookie_expire.getDate() + 365);
function ExtractCookies_simple(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+'=')==0){
			return cookieList[i].substr(cookieList[i].search('=')+1);
		}
	}
	return "";
}
function ExtractUserCookie(strKey){ // vyuziva hlavniho klice USER
	var strKeysValues = ExtractCookies_simple('USER');
	var aKeyValue, aOneKeyValue;
	if ((strKeysValues=="none")||(strKeysValues=="")) return "";
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	aKeyValue = strKeysValues.split("&");
	for (var i = 0; i<aKeyValue.length; i++) {
		aOneKeyValue = aKeyValue[i].split("=");
		if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) { return unescape(aOneKeyValue[1]); }
	}
	return "";
}
function InsertUserCookie(strKey, strValue){
	var strKeysValues = ExtractCookies_simple('USER');
	var sTmp = '';
	var sDelimiter = '';
	var aKeyValue, aOneKeyValue;
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	if ((strKeysValues=="none")||(strKeysValues=="")) {
		document.cookie = 'USER' + "=" + strKey + "=" + strValue + "; path=/;";
	} else if (("&"+strKeysValues.toLowerCase()).indexOf("&"+strKey.toLowerCase()+"=")==-1) {
		document.cookie = 'USER' + "=" + strKeysValues + "&" + strKey + "=" + strValue + "; path=/;";
	} else {
		aKeyValue = strKeysValues.split("&");
		for (var i = 0; i<aKeyValue.length; i++) {
			aOneKeyValue = aKeyValue[i].split("=");
			if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) aOneKeyValue[1] = strValue;
			sTmp += sDelimiter + aOneKeyValue[0] + "=" + aOneKeyValue[1];
			sDelimiter = "&";
		}
		document.cookie = 'USER' + "=" + sTmp + "; expires=" + cookie_expire.toGMTString() + "; path=/; ";		
	}
}
/***************************************************************************/
/***************************************************************************/

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 (getE(strList[i]+'a')) if (getE(strList[i]+'a').tagName=='A') if(typeof(getE(strList[i]+'a')) == "object"){getE(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 FormatFloat(nNumber,nDecimal){
	var sNumber = BarterComma(nNumber);
	sNumber = ''+Math.round(parseFloat(sNumber) * Math.pow(10,nDecimal));
	var sDedimal = sNumber.substring(sNumber.length-nDecimal, sNumber.length);
	var nInt = sNumber.substring(0,sNumber.length-nDecimal);
	if (parseFloat(sNumber) < 1){
	        var sNumber = "0."+sDedimal;
	}else{
	        var sNumber = nInt+"."+sDedimal;
	}
	return sNumber;
}
function FormatCurrency(nNumber,nDecimal){
	var sCurrency, iInsertSpace;
	sCurrency = FormatFloat(nNumber, nDecimal).replace('.',',');
	iInsertSpace = sCurrency.indexOf(',') - 3;
	while (iInsertSpace>0) {
		sCurrency = sCurrency.substring(0,iInsertSpace) + ' ' + sCurrency.substring(iInsertSpace,sCurrency.length);
		iInsertSpace -= 3;
	}
	if (nDecimal==0) sCurrency = sCurrency.substring(0,sCurrency.indexOf(","));
	return sCurrency;
}
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 EmailControl(f){
	if (f.replace(/^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/,"")=="") { 
		return true
	} else {
		return false;
	}
}
function ControlNumber(){
	if (!Br.IE) return;
	if ((event.keyCode <48) || (event.keyCode >57)) event.returnValue = false;
}

function ControlNumberRange(num,rozsah) {
	var minNum = parseInt(rozsah.split('-')[0]);
	var maxNum = parseInt(rozsah.split('-')[1]);
	num = parseInt(num);
	return (num>=minNum && num<=maxNum);
}
function controlMaxNumber(value,nMax){
		if(value > nMax && value >= 1){    
        alert("Číslo stránky musí být v rozmezí od 1 - " + nMax);
        return false;
    }else{    
        return true;
    }
}
function ControlFloat(){
	if (!Br.IE) return;
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode !=46) && (event.keyCode !=44)) event.returnValue = false;
}

function ControlPhone() {
	if (!Br.IE) return;
    if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32)  && (event.keyCode!=40) && (event.keyCode!=41) && (event.keyCode!=43))
		event.returnValue = false;
}
function ControlPSC() {
	if (!Br.IE) return;
    if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32))
		event.returnValue = false;
}
function ControlStringLength(testedInput,maxLong) {
	if (testedInput.value.length>maxLong) {
		testedInput.value = testedInput.value.substring(0,maxLong-1);
		return false;
	}
	return true;
}
//----------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 ShowSearchMenu(x){
    if (x == 1){
        getE('Searchtable').style.display='';
    }else{
        getE('Searchtable').style.display='none';
    }
}
function LocInfo(){
	getE('StateInfo2').innerHTML="  probíná 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
	getE('StateInfo1').style.top=y-140;
	getE('StateInfo1').style.left=x;
}

function PositionInfo(strText){
	getE('StateInfo3').innerHTML=strText;
	getE('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;
	};
	getE('StateInfo1').style.top=y-140;
	if (document.body.clientWidth < 933){
	  getE('StateInfo1').style.left=x-175;
	}else{
	  getE('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 < getE('S').length; i++){
			getE('S')[i].value="0"
		}
	}else{
		for(var i = 0; i < getE('S').length; i++){
			getE('S')[i].value="-1"
		}
	}
}
function ChangeCloseout(bState){
	if(bState){
		for(var i = 0; i < getE('C').length; i++){
			getE('C')[i].value="1"
		}
	}else{
		for(var i = 0; i < getE('C').length; i++){
			getE('C')[i].value="3"
		}
	}
}
function ValidateAccount(sAccount) {
	var u1,u2,t1,t2,i;
	var vahy = new Array("1","2","4","8","5","10","9","7","3","6")
	u1 = sAccount.substring(0,sAccount.length - 10);
	u2 = sAccount.substring(sAccount.length - 10,12);
	t1 = 0;t2 = 0;
	for(i=u1.length ;i>0;i--) {
		t1 += u1.charAt(i - 1)*vahy[10 - i];
	}	  
	for(i=u2.length ;i>0;i--) {
		t2 += u2.charAt(i - 1)*vahy[10 - i];
	}
	if (((t2%11) == 0)&&((t1%11 == 0))) {
		return true;
	} else {
		return false;
	}
}

// ##### PriceList BEEND #######################################################
function DelProducer(nProd) {
	if (nDeleted==nProducers-1) return;
	getE("bEnabled" + nProd).value='0';
	getE("Producer" + nProd).style.display="none";
	nDeleted += 1;
}

function PutCategoriesIdNameToSelect(saCatIdName, nIndex, bStart) {
	var arrData, arrSubData, saCatID, el;
	arrData = saCatIdName.split("*");
	saCatID = "";
	for (var i=0; i<arrData.length-1; i++) {
	    arrSubData = arrData[i].split("/")
		el = document.createElement("OPTION")
	    el.value = arrSubData[0];
	    el.text = arrSubData[1];
		saCatID += arrSubData[0] + "$"
		if (bStart==true) {
			if (i==0) {
				el.text='-Všechny kategorie-';
				document.PL['Categ'+nIndex].options.add(el);
			}
		} else
		    document.PL['Categ'+nIndex].options.add(el);
	}
		
	document.PL['CatID' + nIndex].value = saCatID.substr(0,saCatID.length - 1);
	if (saCatIdName == "") {
		document.PL['Categ'+nIndex].style.display = "none";
		getE("ChooseCateg"+nIndex).style.display  = "inline";
	} else {
		document.PL['Categ'+nIndex].style.display = "inline";
		getE("ChooseCateg"+nIndex).style.display  = "none";
	}
}

function GetCategoriesIdNameForSelect(nTree,bAlsoDisabled,nIndex,nUserType) {
	var saCatID,nProID,sProNM;
	var r;
	
	nProID = document.PL['ProdID'+nIndex].value;
	
	sProNM = document.PL['ProdID'+nIndex].options[document.PL['ProdID'+nIndex].selectedIndex].innerHTML
	saCatID = document.PL['CatID' + nIndex].value;
	if(Br.IE){
		var strReturn = showModalDialog("/Includes/PriceListSelectCatsOfProd.asp?TREE="+nTree+"&ProID="+nProID+"&DIS="+bAlsoDisabled+"&CatIDs="+saCatID+"&ADM="+nUserType+"&ProNM="+sProNM,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=470px;dialogHeight=450px");
		if (typeof(strReturn) == 'undefined') return;
		with(getE("Categ"+nIndex)){
			r = options.length;
	       		for (var i=0; i<r; i++) {
	               		options.remove(options.length-1);
	       		}
		}
		PutCategoriesIdNameToSelect(strReturn, nIndex, false);
	}else{
		window.open("/Includes/PriceListSelectCatsOfProd.asp?TREE="+nTree+"&ProID="+nProID+"&DIS="+bAlsoDisabled+"&CatIDs="+saCatID+"&ADM="+nUserType+"&ProNM="+sProNM+"&nIndex="+nIndex,"okno","toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=470,height=450,left=0,top=0");
	}
	
}
function ClearCategories(nIndex) {

	while(document.PL['Categ'+nIndex].length>0) {
		document.PL['Categ'+nIndex].options[0] = null;	
		}
	
	document.PL['CatID' + nIndex].value = "";
	document.PL['Categ'+nIndex].style.display = "none";
	getE("ChooseCateg"+nIndex).style.display  = "inline";
}

function ShowImage(sImgPath,sName) {
		window.open('/ShowImage.asp?IMG=' + sImgPath + '&sNAME='+sName, "Foto","scrollbars=0,status=0,toolbar=0,location=0,directories=0,height=100,width=100,resizable=1");
}

function ShowHide(element) {
	var e = (typeof(element)=="object" ? element : getE( element ));
	if (e.style.display=="none") { e.style.display = "" } else { e.style.display = "none" };
//	if (!Br.IE) this.blur(); //aby nam nezustaval v mozile oznacen klikaci text
}
function ShowHide2(element) {
	var e = (typeof(element)=="object" ? element : getE( element ));
	if (e.className.indexOf('closed')>-1) {
		e.className = e.className.replace('closed','opened');
	} else {
		e.className = e.className.replace('opened','closed');
	}
}
function changeCross(element) {
		if (getE(element).className == 'crossClosed') {
			getE(element).className = 'crossOpened' 
		} else {
			getE(element).className = 'crossClosed';
		}
}

function styleChange(elementId,classNameStr) {	
	var e = getE( elementId );	
	e.className = classNameStr;	
}



function showWaitingBox( str ) {
	var box = document.getElementById("hoverbox");
	box.style.left = document.documentElement.clientWidth / 2 - 350 + "px";
	box.style.top = topScroll() + document.documentElement.clientHeight / 2 - 10 + "px";
	box.className = "visible";
	box.innerHTML = "<p>"+str+"</p>"
}

/* positions */
function leftPosition(obj,ev){
	if (ev) {
		if ( obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent)) < ev.clientX )  {
			return obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent))
		} else { // quli dvouradkovym elementum, tak aby se to nezobrazilo daleko od kurzoru na prvnim radku
			return ( ev.clientX );
		}
	} else { // kdyz volame rekurzivne, tak neni objekt ev k dispozici
		return obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent));
	}
}
function topPosition(ev) {
	 return ( ev.clientY + topScroll() );
}
function topScroll() {
	if (window.innerHeight) {
		  return ( window.pageYOffset )
	} else if (document.documentElement && document.documentElement.scrollTop) {
		return ( document.documentElement.scrollTop )
	} else if (document.body) {
		  return ( document.body.scrollTop )
	}
}
/* /positions */

var fadeInOut;
function fadeInObject ( objID, speed, opacity ) { // fce necha plynule zobrazit libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
	window.clearTimeout(fadeInOut);
	var obj = getE(objID);
	if (!(opacity>0)) opacity = 0;
	if (!(speed>0)) speed = 5;
	opacity+=speed;
	if (Br.IE) {
		obj.style.filter = 'alpha(Opacity='+opacity+')';
		if (opacity<100) { fade=setTimeout("fadeInObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.filter='' }
	} else if (Br.NS) {
		obj.style.MozOpacity = opacity/100;
		if (opacity<100) { fade=setTimeout("fadeInObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.MozOpacity=1; }
	}
	if (obj.style.display!='block') obj.style.display='block';
}
function fadeOutObject ( objID, speed, opacity ) { // fce necha plynule zmiznout libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
	window.clearTimeout(fadeInOut);
	var obj = getE(objID);
	if (Br.OP) { obj.style.display='none'; return; }
	if (!(opacity>0)) opacity = 100;
	if (!(speed>0)) speed = 5;
	opacity-=speed;
	if (Br.IE) {
		obj.style.filter = 'alpha(Opacity='+opacity+')';
		if (opacity>0) { fade=setTimeout("fadeOutObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.display='none'; obj.style.filter=''; }
	} else if (Br.NS) {
		obj.style.MozOpacity = opacity/100;
		if (opacity>0) { fade=setTimeout("fadeOutObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.display='none'; obj.style.MozOpacity=1; }
	}
}

// basketHoverBox

function showBasketHoverBox() {
	clearTimeout(this.timeouttohide);
	if (Br.IE) {
		if (getE('variantSelector')) getE('variantSelector').style.visibility='hidden';
		if (getE('unitSelector')) getE('unitSelector').style.visibility='hidden';
	}
	getE('basketHoverBox').style.top = topScroll() + 300+'px';
	getE('basketHoverBox').style.left = (document.body.clientWidth/2 - 207)+'px';
	fadeInObject ( "basketHoverBox", 0 );
	this.timeouttohide = setTimeout("hideBasketHoverBox();", 20000);
}

function hideBasketHoverBox() {
	fadeOutObject('basketHoverBox');
	if (getE('sortingSelector')) getE('sortingSelector').style.visibility='visible';
	if (getE('producerSelector')) getE('producerSelector').style.visibility='visible';
}

function GetBuy(frm,sAction,sTarget) {	
	frm.action = sAction;
	frm.target = sTarget;
	frm.elements['do'].value = 'addbasketitem';
	//alert('Po');
	//return false;
}


function changeSelectedBookmark( bkmrkNo, bkmrksCount ) { 
	for (var i=1; i<=bkmrksCount; i++) { 
		if (getE('bookmark_'+i)) getE('bookmark_'+i).className='bookmark';
		if (getE('bookmark_content_'+i)) getE('bookmark_content_'+i).className='bookmark_content';
	} 
	getE('bookmark_'+bkmrkNo).className='bookmark active';
	getE('bookmark_content_'+bkmrkNo).className='bookmark_content active';
} 

function changeCatProd( catprod, obj, firstId) {
	var hidEl = catprod==1 ? getE('sb_producers') : getE('sb_categories');
	var shwEl = catprod==1 ? getE('sb_categories') : getE('sb_producers');
	if(obj.checked){
	    InsertUserCookie('CP', catprod==1 ? 'C' : 'P');
		if(hidEl && shwEl){
			hidEl.style.display='none';
			shwEl.style.display='block';
		}
		else{
			document.location.href = catprod==1 ? '/Category.asp' : '/Producer.asp';
			//'/Default.asp?' + (firstId ? firstId : '');
		}
	}	
}

/* hover images in commodity list */
var bHoverName = 0, bHoverImage = 0, nLastImageId = 0; // jestli mame mys nad nazvem a obrazkem
function hideHoverImage( hoverWhat, idImage ) {
	if (hoverWhat==1) bHoverName = 0;
	if (hoverWhat==2) bHoverImage = 0;
	setTimeout("if (bHoverName==0 & bHoverImage==0) getE('hover_"+idImage+"').style.display='none';", 500); //getE('hover_'+idImage).style.display='none';
}
function showHoverImage( hoverWhat, idImage ) {
	clearTimeout;
	if (idImage!=nLastImageId) { bHoverName = 0; bHoverImage = 0; if (getE('hover_'+nLastImageId)) getE('hover_'+nLastImageId).style.display='none'; }
	if (hoverWhat==1) bHoverName = 1;
	if (hoverWhat==2) bHoverImage = 1;
	nLastImageId = idImage;
	getE('hover_'+idImage).style.display='block';
}


function DeliverySelect(pkDel,pkPay){
	//gaDelivery - array from string 142$143$
	//gaPayment - array from string 41,43,$1,43,$
	//alert("DeliverySelect: " + gaDelivery + "\nPayment: ; " + gaPayment);
	var oPTsel, sDeliveries, oPB, bPayOK;
	var bPaySelectedOK = false;
	var bPaySelected = false;
	for (var i=0; i< gaDelivery.length; i++){
		if (gaDelivery[i] == pkDel) {
			// provedu zobrazení/skrytí platebních metod podle vazby na dopravné
			sPayments = ',' + gaPayment[i]; // 41,43,		
			//alert("sPayments: " + sPayments);
			for(var j = 0; ; j++) {
				oPT = getE('PaymentType' + j);
				if (!oPT) break;

				// nastavím bloku s typem platby modrou/šedou barvu
				oPB = getE('PaymentBlock' + j);
				bPayOK = (sPayments.indexOf(',' + oPT.value + ',') != -1);
				if (pkPay==oPT.value) oPT.checked=true; //default payment type
				if (oPT.checked)
					bPaySelectedOK = bPayOK; // je vybraná plat. met. stále možná i s nově zvoleným dopravným? existuje vazba?

				if (bPayOK) {
					if (!bPaySelected) {
						oPTsel = oPT;
						bPaySelected = true;
					}
					oPB.className = "method-of-payment";
				}
				else
					oPB.className = "method-of-payment payKO";
				oPT.disabled = !bPayOK;
				if (!bPaySelected){
					oPT.checked = true;
				}
			}
			// pokud je vybrána platební metoda, kterou není možné provést s vybraným typem dopravy, změním to na první možnou volbu
			if (bPaySelected && !bPaySelectedOK){
				oPTsel.checked = true;
			}
			break;
		}
	}
}


function ControlUserDataSubmit( bRequestedFirm, bRequestedFirmOrName, bRequestedFirstName, bRequestedLastName, bRequestedPhone, bRequestedBankAccount ){
	if( bRequestedFirm && (getF('UserDataForm').Firm.value == "")){alert("Vyplňte název firmy.");return false}
	if( bRequestedFirmOrName && (getF('UserDataForm').FirstName.value + getF('UserDataForm').LastName.value == "") && (getF('UserDataForm').Firm.value == "")){alert("Vyplňte název firmy, nebo jméno a příjmení.");return false}
	if( bRequestedFirstName && getF('UserDataForm').sFirstName.value == ""){alert("Vyplňte jméno.");getF('UserDataForm').sFirstName.focus();return false}
	if( bRequestedLastName && getF('UserDataForm').sLastName.value == ""){alert("Vyplňte příjmení.");getF('UserDataForm').sLastName.focus();return false}

	if( bRequestedPhone && getF('UserDataForm').sPhone.value == ""){alert("Vyplňte telefon.");getF('UserDataForm').sPhone.focus();return false}
	if(getF('UserDataForm').sEmail.value == ""){alert("Vyplňte email.");getF('UserDataForm').sEmail.focus();return false}

	if(getF('UserDataForm').sStreet.value == ""){alert("Vyplňte ulici.");getF('UserDataForm').sStreet.focus();return false}
	if(getF('UserDataForm').sCity.value == ""){alert("Vyplňte město.");getF('UserDataForm').sCity.focus();return false}
	if(getF('UserDataForm').sZipCode.value == ""){alert("Vyplňte PSČ.");getF('UserDataForm').sZipCode.focus();return false}

	if(bRequestedBankAccount && !ValidateAccount(getF('UserDataForm').sBankAccount.value)){alert("Bankovní účet není platný, zkuste jej zadat znovu, nebo pole nevyplňujte.");getF('UserDataForm').sBankAccount.focus();return false};
	if(getF('UserDataForm').sLogin.value == ""){alert("Vyplňte přihlašovací jméno.");getF('UserDataForm').sLogin.focus();return false}
	if(getF('UserDataForm').sLogin.value.length < 5){alert("Přihlašovací jméno musí mít nejméně 5 znaků.");getF('UserDataForm').sLogin.focus();return false}
	if(getF('UserDataForm').sPassword.value == ""){alert("Vyplňte heslo.");getF('UserDataForm').sPassword.focus();return false}
	if(getF('UserDataForm').sPassword.value.length < 5){alert("Heslo musí mít minimálně 5 znaků.");getF('UserDataForm').sPassword.focus();return false}
	if(getF('UserDataForm').sPassword.value!=getF('UserDataForm').sPassword2.value){alert("Heslo a kontrolní heslo se musí shodovat.");getF('UserDataForm').sPassword2.focus();return false}
	return true;
}
function ControlDataOrder( bAllowUnregisteredOrder ){
	
	if (bAllowUnregisteredOrder==1) {
		if(getF('OrderForm').sFirstName.value == ""){alert("Vyplňte jméno.");getF('OrderForm').sFirstName.focus();return false}
		if(getF('OrderForm').sLastName.value == ""){alert("Vyplňte příjmení.");getF('OrderForm').sLastName.focus();return false}
		if(getF('OrderForm').sStreet.value == ""){alert("Vyplňte ulici.");getF('OrderForm').sStreet.focus();return false}
		if(getF('OrderForm').sCity.value == ""){alert("Vyplňte město.");getF('OrderForm').sCity.focus();return false}
		if(getF('OrderForm').sZipCode.value == ""){alert("Vyplňte PSČ.");getF('OrderForm').sZipCode.focus();return false}	
		if(getF('OrderForm').sPhone.value == ""){alert("Vyplňte telefon.");getF('OrderForm').sPhone.focus();return false}
		if(getF('OrderForm').sEmail.value == ""){alert("Vyplňte email.");getF('OrderForm').sEmail.focus();return false}
	}
	
	if(getE('OrderForm').DeliveryType.value == "-"){alert("Vyberte způsob dopravy."); getF('OrderForm').DeliveryType.focus(); return false}
		if(getE('OrderForm').PaymentType.value == "-"){alert("Vyberte způsob platby."); getF('OrderForm').PaymentType.focus(); return false}
	return true;
}
function ControlPassword(NameOne,NameTwo){
	if (getE(NameOne).value != getE(NameTwo).value){
		alert("Špatně zadané heslo.");
		getE(NameOne).value = "";
		getE(NameTwo).value = "";
		getE(NameOne).focus();
		return false;
	}else{
		return true;
	}
}

function checkCount( myCount, minCount, sUnit, onlyMultiplied ) {
	myCount = parseInt(myCount.replace(",","."));
	minCount = parseInt(minCount.replace(",","."));
	if ( myCount == 0 ) return true;
	if (myCount<0) {
		alert('Zboží nelze objednat v záporném počtu.'); return false;
	}
	if ( myCount < minCount ) {
		alert('Toto zboží lze objednat v minimálním počtu '+minCount+' '+sUnit+'.'); return false;
	}
	if ( (onlyMultiplied==1) && ( (myCount*10) % (minCount*10) != 0) ) {
		alert('Toto zboží lze zakoupit pouze v násobcích '+minCount+' '+sUnit+'.'); return false;
	}
	return true;
}

function confirmEmptyBasket() {
	return confirm('Přejete si zrušit objednávku a vyprázdnit košík?');
}

function GoToPage(nPage, sParam) {
	document.location.href = '?pgID=' + nPage + sParam;
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

 function ShowCalendar(oid)
 {
  var cal = document.getElementById('divcal');
  var calframe = document.getElementById('diviframcal');
  var tbox = document.getElementById(oid);
  var ssrc = '/administration/Calendar_inc.asp?el=' + oid + '&selDate=' + tbox.value;
  
  cal.style.top = tbox.offsetTop + tbox.offsetHeight;
  cal.style.left = tbox.offsetLeft;
  
  calframe.src = ssrc;
  cal.style.display = 'block';
 }
 
 function setBookmark(url,title){
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	}else if (Br.IE){
		window.external.AddFavorite(url, title);
	}else{
	 	alert('Váš prohlížeč bohužel nepodporuje automatické vkládání stránek mezi oblíbené, pro přidání stiskněte CTRL+D.');
	}
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}
function pagerFormSubmit(pc,idx,url,qfp,qps){
    var jtp = getE('jumptopage'+idx);
    if(jtp){ 
        if (jtp.value!=jtp.defaultValue){
            if (jtp.value!='' && jtp.value>pc) {
                alert('Tolik stránek tady bohužel není.');
                return false;
            }
            document.location=url+qfp+jtp.value+qps;
            return false;
        }
    }
}

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();
}