// 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.IE8	= (this.VER.indexOf("MSIE 8")>-1 && this.DOM && !this.OP)	?true:false;
	this.IE	= (this.IE4 || this.IE5 || this.IE6 || this.IE7 || this.IE8);

	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);

	return this;
}

function getE(objectID) { return document.getElementById(objectID); }
function getF(formName) { return document.forms[formName]; }
function trim(str) { return str.replace(/^\s*|\s*$/g,""); }

var tmrMisc = null;

/*==============================================================================
 * MENU KATEGORII
 *==============================================================================*/
 
/*------------------------------------------------------------------------------
 * Meni zobrazenou root kategorii (voda, plyn, hawido)
 */
var selectedCatID = "";
function selectRootCat(catID) {
	var el = getE("rcf" + catID);
	var elS = getE("rc" + catID);

	if (el != null) {
		if (catID == selectedCatID) return;

		var elCur = getE("rcf" + selectedCatID);
		var elSCur = getE("rc" + selectedCatID);

		if (elCur != null) elCur.style.borderBottomColor = "#fff";
		if (elSCur != null) elSCur.style.display = "none";

		if (el != null) el.style.borderBottomColor = "";
		if (elS != null) elS.style.display = "";

		selectedCatID = catID;
	}
}

/*------------------------------------------------------------------------------
 * Vysviti aktualni kategorii
 */
function selectCurrCat(catID) {
	var el = getE("sc" + catID)

	if (el != null) {
		el.style.backgroundPosition = "0px -50px !important";
		el.style.fontWeight = "bold";
	}
}

/*------------------------------------------------------------------------------
 * Zobrazi vyskakovaci obrazek v menu kategorii
 */
function showCategoryMenuImage(sImgURL, sFirstLetter, srcEl) {
	if (sImgURL == "") return;

	el = getE("hoverImageCategory");
	if (el) {
		el.firstChild.src = sImgURL;
		el.className = sFirstLetter;
		el.style.top = (getPosY(srcEl) - 2) + "px";
		el.style.display = "block";
	}
}

/*------------------------------------------------------------------------------
 * Skryje vyskakovaci obrazek v menu kategorii
 */ 
function hideCategoryMenuImage() {
	el = getE("hoverImageCategory");
	if (el) el.style.display = "none";
}

/*==============================================================================
 * RUZNE
 *==============================================================================*/

/*------------------------------------------------------------------------------
 * Pri vstupu nebo vystupu z pole nastavuje vychozi hodnotu
 */
function setInputDefault(el, focus) {
	if (focus == true) {
		if (el.value == el.defaultValue) el.value = '';
	}
	else {
		if (el.value == '') el.value = el.defaultValue;
	}
}

/*------------------------------------------------------------------------------
 * Vrati XMLHttpRequest objekt
 */ 
function getNewHttpObject() {
	var objType = false;
	try {
		objType = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e) {
		try {
			objType = new ActiveXObject('Microsoft.XMLHTTP');
    }
		catch(e) {
			objType = new XMLHttpRequest();
		}
	}

	return objType;
}

/*------------------------------------------------------------------------------
 * Kontrola pri zadavani cisla
 */ 
function controlNumber(e){
	var keynum
	var keychar
	var numcheck

	if(window.event){
		keynum = e.keyCode
	}
	else if(e.which){
		keynum = e.which
	}
	return ((keynum >= 48) && (keynum <= 57)) || keynum == 8 || keynum == 13 || (Br.NS && e.charCode == 0)
}

/*------------------------------------------------------------------------------
 * Zobrazi a vycentruje WaitBox
 */
function showWaitBox(sText) {
	var el = getE("waitBox");
	if (el) {
		if (sText != "") el.innerHTML = sText;
		el.style.display = "block";
		centerElement(el);
	}
}

/*------------------------------------------------------------------------------
 * Schova WaitBox
 */
function hideWaitBox() {
	var el = getE("waitBox");
	if (el) {
		el.style.display = "none";
	}
}

/*------------------------------------------------------------------------------
 * Zobrazi a vycentruje MiscBox
 */
function showMiscBox() {
	var el = getE("miscBox");
	if (el) {
		el.style.display = "block";
		centerElement(el);
	}
}

/*------------------------------------------------------------------------------
 * Schova MiscBox
 */
function hideMiscBox() {
	var el = getE("miscBox");
	if (el) {
		el.style.display = "none";
	}
}

/*------------------------------------------------------------------------------
 * Zobrazi disableBox
 */
function showDisableBox() {
	var el = getE("disableBox");
	if (el) {
		el.style.height = getWindowHeight() + "px";
		el.style.display = "block";
		if (Br.IE) SelectHide('hidden');
		((document.compatMode=="CSS1Compat")? document.documentElement : document.body).style.overflow = "hidden";
	}
}

/*------------------------------------------------------------------------------
 * Schova disableBox
 */
function hideDisableBox() {
	var el = getE("disableBox");
	if (el) {
		((document.compatMode=="CSS1Compat")? document.documentElement : document.body).style.overflow = "auto";
		el.style.display = "none";
		if (Br.IE) SelectHide('visible');
	}
}

/*------------------------------------------------------------------------------
 * Zobrazi vyber akce - Prevod, kosik, ....
 */
function showActionSelection() {
	window.clearTimeout(tmrMisc);

	var el = getE("actionSelectionBox");
	if (el) el.style.display = "block";
}

/*------------------------------------------------------------------------------
 * Skryje vyber akce - Prevod, kosik, ....
 */
function hideActionSelection() {
	tmrMisc = window.setTimeout(function() { if (getE('actionSelectionBox')) getE('actionSelectionBox').style.display = 'none'; }, 100);
}

/*------------------------------------------------------------------------------
 * Zobrazi vyskakovaci obrazek u mastru v seznamu
 */
function showMasterItemImage(sImgURL, srcEl) {
	if (sImgURL == "") return;

	el = getE("hoverImageMaster");
	if (el) {
		el.firstChild.src = sImgURL;
		el.style.top = (getPosY(srcEl) - 105) + "px";
		el.style.display = "block";
	}
}

/*------------------------------------------------------------------------------
 * Skryje vyskakovaci obrazek v menu kategorii
 */ 
function hideMasterItemImage(sImgURL) {
	el = getE("hoverImageMaster");
	if (el) {
		el.firstChild.src = sImgURL;
		el.style.display = "none";
	}
}

/*------------------------------------------------------------------------------
 * Nacteni skladoveho mnozstvi na lokacich
 */
function showAvailabilityOnLocations(sText) {

	//
	// Vytvorime, nastavime a spustime ajax
	//
	var theHttpRequest = getNewHttpObject();
	theHttpRequest.onreadystatechange = function() { processAJAX(); };
	theHttpRequest.open("get", "/includes/ajax_Availability.asp?a=getAvailabilityOnLocationsBox&text=" + sText);
	theHttpRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	theHttpRequest.send(null);

	function processAJAX() {
		if (theHttpRequest.readyState == 4) {
			var responseTxt = theHttpRequest.responseText;

			getE("miscBox").innerHTML = theHttpRequest.responseText;

			hideWaitBox();
			showMiscBox();
		}
	}
}

/*------------------------------------------------------------------------------
 * Nacteni skladoveho mnozstvi na prihradkach
 */
function showAvailabilityOnBoxes(sText) {

	//
	// Vytvorime, nastavime a spustime ajax
	//
	var theHttpRequest = getNewHttpObject();
	theHttpRequest.onreadystatechange = function() { processAJAX(); };
	theHttpRequest.open("get", "/includes/ajax_Availability.asp?a=getAvailabilityOnBoxesBox&text=" + sText);
	theHttpRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	theHttpRequest.send(null);

	function processAJAX() {
		if (theHttpRequest.readyState == 4) {
			var responseTxt = theHttpRequest.responseText;

			getE("miscBox").innerHTML = theHttpRequest.responseText;

			hideWaitBox();
			showMiscBox();
		}
	}
}

/*------------------------------------------------------------------------------
 * Zobrazi rozsirene hledani
 */
function showAdvSearchBox() {
	window.clearTimeout(tmrMisc);

	var el = getE("selectWin");
	if (el) el.style.display = "block";
}

/*------------------------------------------------------------------------------
 * Skryje rozsirene hledani
 */ 
function hideAdvSearchBox() {
	tmrMisc = window.setTimeout(function() { getE('selectWin').style.display = 'none'; }, 150);
}

/*------------------------------------------------------------------------------
 * Vyber kategorii pro cenik
 */ 
function getCategoriesIdNameForPricelist(nTree, bAlsoDisabled, nUserType) {
	var saCatID,nProID,sProNM;
	var r;

	saCatID = getE('CatID0').value;

	if(Br.IE) {
		var strReturn = showModalDialog("/Includes/PriceListSelectCatsOfProd.asp?TREE=" + nTree + "&ProID=0&DIS=" + bAlsoDisabled + "&CatIDs=" + saCatID + "&ADM=" + nUserType + "&ProNM=", "Info", "status:no; center:yes; help:no; minimize:no;dialogWidth=520px;dialogHeight=500px");
		if (typeof(strReturn) == 'undefined') return;
		with(getE("Categ0")) {
			r = options.length;
			for (var i = 0; i < r; i++) {
				options.remove(options.length-1);
			}
		}
		putCategoriesIdNameToPricelist(strReturn, false);
	} else {
		window.open("/Includes/PriceListSelectCatsOfProd.asp?TREE=" + nTree + "&ProID=0&DIS=" + bAlsoDisabled + "&CatIDs=" + saCatID + "&ADM=" + nUserType + "&ProNM=&nIndex=0", "okno", "toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=520,height=500,left=0,top=0");
	}
}

/*------------------------------------------------------------------------------
 * Naplneni kategorii pro cenik
 */ 
function putCategoriesIdNameToPricelist(saCatIdName, 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-';
				getE('Categ0').options.add(el);
			}
		} else {
			getE('Categ0').options.add(el);
		}
	}

	getE("CatID0").value = saCatID.substr(0,saCatID.length - 1);
}

/*------------------------------------------------------------------------------
 * Smazani kategorii pro cenik
 */ 
function clearCategoriesPricelist() {

	getE("Categ0").options.length = 0;	
	getE("CatID0").value = "";

}

/*------------------------------------------------------------------------------
 * Totez co v ASP
 */ 
function replaceVariables(sText, aVars) {

	if (aVars == null || sText == null) return sText;

	var regEx = null;

	for (var i = 0; i < aVars.length; i++) {
		eval("regEx = /(%" + (i + 1) + "-[a-zA-Z]*%)/gi;");
		sText = sText.replace(regEx, aVars[i]);
	}

	return sText;
}

/*==============================================================================
 * MANIPULACE S ELEMENTEM
 *==============================================================================*/

/*------------------------------------------------------------------------------
 * Vrati x pozici scroll
 */ 
function getViewportScrollX() {
	var scrollX = 0;
	if( document.documentElement && document.documentElement.scrollLeft ) {
		scrollX = document.documentElement.scrollLeft;
	}
	else if( document.body && document.body.scrollLeft ) {
		scrollX = document.body.scrollLeft;
	}
	else if( window.pageXOffset ) {
		scrollX = window.pageXOffset;
	}
	else if( window.scrollX ) {
		scrollX = window.scrollX;
	}
	return scrollX;
}

/*------------------------------------------------------------------------------
 * Vrati y pozici scroll
 */ 
function getViewportScrollY() {
	var scrollY = 0;
	if(document.documentElement && document.documentElement.scrollTop) {
		scrollY = document.documentElement.scrollTop;
	}
	else if(document.body && document.body.scrollTop) {
		scrollY = document.body.scrollTop;
	}
	else if(window.pageYOffset) {
		scrollY = window.pageYOffset;
	}
	else if(window.scrollY) {
		scrollY = window.scrollY;
	}
	return scrollY;
}

/*------------------------------------------------------------------------------
 * Vrati X-ovou pozici elementu
 */ 
function getPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

/*------------------------------------------------------------------------------
 * Vrati Y-ovou pozici elementu
 */ 
function getPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

/*------------------------------------------------------------------------------
 * Vrati sirku okna
 */ 
function getWindowWidth() {
	return (typeof(window.innerWidth) == 'number') ? window.innerWidth : document.documentElement.clientWidth;
}

/*------------------------------------------------------------------------------
 * Vrati vysku okna
 */ 
function getWindowHeight() {
	return (typeof(window.innerHeight) == 'number') ? window.innerHeight : document.documentElement.clientHeight;
}

/*------------------------------------------------------------------------------
 * Vycentruje element
 */ 
function centerElement(el) {
	var nScrollLeft = (isNaN(getViewportScrollY())) ? 0 : getViewportScrollX();
	var nScrollTop = (isNaN(getViewportScrollY())) ? 0 : getViewportScrollY();
	var nWidth = getWindowWidth();
	var nHeight = getWindowHeight();
	var nLeft = ((nWidth - el.offsetWidth) / 2) + nScrollLeft;
	var nTop = ((nHeight - el.offsetHeight) / 2) + nScrollTop;

	el.style.left = nLeft.toString() + "px";
	el.style.top = nTop.toString() + "px";
}

/*function SetDSP(nDSP, sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);

	if (nDSP==1) 
	{
		document.cookie="DSP=1; expires="+vyprs.toGMTString()+";";
	} 
	else 
	{
		document.cookie="DSP=0; expires="+vyprs.toGMTString()+";";
	}
	if (getE('RedirOnListCagChange')!=null) window.location.href=sURL;
}*/



// ###   FCE PRO DIALOG ZADANI VOLITELNYCH PARAMETRU   ###
var gsFormSuffix, gsFormIndex;

function BuyOrSetVariableParams(sFormSuffix,sFormIndex) {
	var sSelects, nWindowHeight;
	gsFormIndex = sFormIndex;
	gsFormSuffix = sFormSuffix;

	sSelects = getE("DivForPars" + sFormSuffix + sFormIndex).innerHTML;
	// ve skeletu musí být ve fci GetFormattedParams "ParamItem" psáno CASE-SENSITIVE !!!
	if (sSelects == "") {
		getF("BuyForm" + sFormSuffix + sFormIndex).submit();
	} else {
		// 22 je výška selectu - definováno raději i podle stylu!
		// nWindowHeight = 86 + 22 * (sSelects.split("ParamItem").length);
		getE('DivForParams').innerHTML = getE("DivForPars" + sFormSuffix + sFormIndex).innerHTML;
		getE('ParamCaption').innerHTML = getE("BuyForm" + sFormSuffix + sFormIndex).NameItem.value;
		getE('ParamTbl').style.top =  window.event.srcElement.offsetTop + 20;
		getE('ParamTbl').style.left =  window.event.srcElement.offsetLeft - 60;
		getE('ParamTbl').style.display = 'inline';
	}
}





// SELECT on/off
function SelectExcept(o){
	return !( (o.id == "AMenu1")||(o.id == "TabMenu1")||(o.id == "TabMenu5")||(o.id == "TabMenu6")||(o.id == "CellMenu1")||(o.id == "CellMenu2")||(o.id == "ImgMenu1")); 
}

function SelectHide(sStyle){
	SelectHideEx(sStyle,document);
	for (var i=0;i<window.frames.length;i++){
		SelectHideEx(sStyle,window.frames[i].document);
	}
}

function SelectHideEx(sStyle,odocument){	
	var o;
	o = odocument.getElementsByTagName("select");
	if (o !=null ){
		if (o.tagName == 'SELECT') {
			if (SelectExcept(o)) o.style.visibility=sStyle;
		} else {
			for(var i=0;i<o.length;i++){
				if (SelectExcept(o[i])) o[i].style.visibility=sStyle;
			}
		}
	}
}

// ###   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 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";
	}
}

/***************************************************************************/
/***************************************************************************/
	
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 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 FUCJS(nNumber, nDecimal, bCurrSymbol) {
	var sCurrency;
	nDecimal = (nDecimal > 0) ? nDecimal : gbCurrencyDigitsAfterDecimalSeparator;
	if (parseFloat(nNumber)){
	     if(parseFloat(nNumber) < 1){
	     	sCurrency = "0" + FormatCurrency(nNumber, nDecimal);
		}else{
			sCurrency = FormatCurrency(nNumber, nDecimal);
		}
	}else{
		sCurrency = "0,00";
	}
	sCurrency = sCurrency.replace(" ", gbCurrencyThousandSeparator);
	sCurrency = sCurrency.replace(",", gbCurrencyDecimalSeparator);
	
	if (nDecimal == 0) sCurrency = sCurrency + gbCurrencySuffixNotDecimal;
	
	if (bCurrSymbol) {
		if (gbCurrencyBeforeAmount)
			sCurrency = "<small>" + gbCurrencyName + "</small>&nbsp;" + sCurrency;
		else
			sCurrency = sCurrency + "&nbsp;<small>" + gbCurrencyName + "</small>";
	}
	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 controlMaxNumber(str,value,nMax){
		if(value > nMax && value >= 1){    
        alert(str + 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 ShowSearchMenu(x){
    if (x == 1){
        getE('Searchtable').style.display='';
    }else{
        getE('Searchtable').style.display='none';
    }
}

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 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 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";
}

// ##### PriceList END #####

function ShowImage(sImgPath) {
		window.open('/ShowImage.asp?IMG=' + sImgPath, "Foto","scrollbars=0,status=0,toolbar=0,location=0,directories=0,height=100,width=100,resizable=1");
}

function ShowHide(element) {
	var e = getE( element );
	if (e.style.display=="none") {
		if (!Br.OP) SelectHide('hidden');
		e.style.display = "" }
	else {
		if (!Br.OP) SelectHide('visible');
		e.style.display = "none" };
//	if (!Br.IE) this.blur(); //aby nam nezustaval v mozile oznacen klikaci text
}

function styleChange(elementId,classNameStr) {	var e = getE( elementId );	e.className = classNameStr;}

/* positions */

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 )
	}
}

// specialitky

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=='none') 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 (!(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; }
	}
	if (obj.style.display=='block') obj.style.display='none';
}

// ShopInfoBox

function showShopInfoDialog() {
	clearTimeout;
	if (!Br.OP) SelectHide('hidden');
	var e = getE( "shopinfobox" );
	fadeInObject ( "shopinfobox", 0 );
	e.style.position = "absolute";
	e.style.top = topScroll() + 200+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	setTimeout("hideShopInfoboxDialog();", 20000);
}

function hideShopInfoboxDialog() {
	var e = getE( "shopinfobox" );
	fadeOutObject ( "shopinfobox", 10 );
	clearTimeout;
	if (!Br.OP) SelectHide('visible');
}

function showShopConfirmDialog() {
	clearTimeout;
	hideShopInfoboxDialog();
	if (Br.IE) {
		if (getE('sortingSelector')) getE('sortingSelector').style.visibility='hidden';
		if (getE('producerSelector')) getE('producerSelector').style.visibility='hidden';
	}
	var e = getE( "shopconfirmbox" );
	fadeInObject ( "shopconfirmbox", 0 );
	e.style.position = "absolute";
	e.style.top = topScroll() + 300+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	if (getE('boxformcount')) getE('boxformcount').focus();
}

function hideShopConfirmDialog() {
	if (getE('itemsOnPageSelect')) { getE('itemsOnPageSelect').style.visibility='visible'; }
	if (getE('sortingSelector')) getE('sortingSelector').style.visibility='visible';
	if (getE('producerSelector')) getE('producerSelector').style.visibility='visible';
	var e = getE( "shopconfirmbox" );
	fadeOutObject ( "shopconfirmbox", 10 );
}

function GetBuy(frm,sAction,sTarget) {
	frm.action = sAction;
	frm.target = sTarget;
	frm.elements.AUO.value = 'ok';
}



/* 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 checkCount( myCount, minCount, sUnit, onlyMultiplied ) {
	myCount = parseInt(myCount.replace(",","."));
	minCount = parseInt(minCount.replace(",","."));
	if ( myCount == 0 ) return true;
	
	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;}

/*
 * Zobrazi kalendar
 */
function ShowCalendarEx(oid,x,y, gli)
{
	var cal = document.getElementById('divcal');
	var calframe = document.getElementById('diviframcal');
	var tbox = document.getElementById(oid);
	var ssrc = '/Includes/Calendar_INC.asp?el=' + oid + '&selDate=' + tbox.value + "&gli=" + gli;  
	cal.style.position = "absolute";	
	cal.style.top = (getPosY(tbox) + 18) + 'px';
	cal.style.left = (getPosX(tbox) - 253) + 'px'; 
	calframe.src = ssrc;
	cal.style.display = 'block';
}

function Bookmark(url,title){
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	}
	else if( document.all){
		window.external.AddFavorite(url, title);
	}
	else{
		return true;
	}
}

function DoLogin(){
	getE('do').value='login';
	getE('dagFormLogin').submit();
}
