// 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.IE9	= (this.VER.indexOf("MSIE 9")>-1 && this.DOM && !this.OP)	?true:false;
 this.IE	= (this.IE4 || this.IE5 || this.IE6 || this.IE7 || this.IE8 || this.IE9);


 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;
}

 var cbfRes = function(JScode)
    {
      eval(JScode);
    }

function getE(objectID) {
	return document.getElementById(objectID);
}

function getF(formName) {
	return document.forms[formName];
}

function getFEx(formName, oDocument) {
	return oDocument.forms[formName];
}

function getEEx(objectID, oDocument) {
	return oDocument.getElementById(objectID);
}

function appendEventHandler(el, method, fce) {
	if (el.addEventListener){
  		el.addEventListener(method, fce, true); 
	} else if (el.attachEvent){
  		el.attachEvent('on' + method, fce);
	}
}

function windowOnLoad() {
	var oSearchSuggest = new searchSuggest("txtEXPS");
	oSearchSuggest.init();

	// Test JS
	InsertCookies("hasjs", "1");
}

appendEventHandler(window, "load", windowOnLoad);


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;
}

function SetAlsoNotStored(sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);

	if (ExtractCookies('COMANS')=='1') {
		document.cookie="COMANS=0; expires="+vyprs.toGMTString()+";";
	} else {
		document.cookie="COMANS=1; expires="+vyprs.toGMTString()+";";
	}
	if (getE('RedirOnListCagChange')!=null) window.location.href=sURL;
}

function SetCloseout(sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);

	if (ExtractCookies('COMCLO')=='1') {
		document.cookie="COMCLO=0; expires="+vyprs.toGMTString()+";";
	} else {
		document.cookie="COMCLO=1; expires="+vyprs.toGMTString()+";";
	}
	if (getE('RedirOnListCagChange')!=null) 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;

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 == "") {
	    alert("FormBuy" + sFormSuffix + sFormIndex);
		getF("FormBuy" + 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';
	}
}
*/


//function BuyOrSetVariableParams(sFormSuffix,sFormIndex, bHideCB) {
//		var sSelects, nWindowHeight;
//	    gsFormIndex = sFormIndex;
//	    gsFormSuffix = sFormSuffix;
//	    var e = getE('BuyItem' + sFormIndex);

        //var y = findPosY(e); //y = 0;
        //var x = findPosX(e); //x = 300;

		//if (bHideCB==2)		{x-=40;}  // zneuzita polozka - konfigurator
		
		
//		var y = window.event.clientY + topScroll() - 285;
//		var x = window.event.clientX - 250;
		
		

  //      getE("StateInfo1").style.left = x + 'px';
	//    getE("StateInfo1").style.top = y + 'px';

	//	document.forms["FormBuy" + sFormSuffix + sFormIndex].submit();

//} 

// function BuyOrSetVariableParamsDetail(sParamSizeL,sParamColorL,sParamSize,sParamColor, sParamSizeCouple,bHideCB,x, y) 
// {
// 		
//     
//     
//     
//     
// 		var sSelects, nWindowHeight;
//     var e = getE('BuyItemDetail');
//  		y = y + topScroll() - 285;
//  		x = x - 500;
//     getE("StateInfo1").style.left = x + 'px';
//     getE("StateInfo1").style.top = y + 'px';
//     sSelects = "FormBuyDetail";
// 		document.forms[sSelects].elements.sParamSize.value = $('#tarList').val();
// 		document.forms[sSelects].elements.sParamColor.value = $('#srcList').val();
// 		document.forms[sSelects].elements.sParamSizeL.value = $('#tarList').val();
// 		document.forms[sSelects].elements.sParamColorL.value = $('#srcList').val();
// 		//document.forms[sSelects].elements.sParamSizeCouple.value = sParamSizeCouple;
// 		document.forms[sSelects].submit();
// } 


function BuyOrSetVariableParams(sFormSuffix,sFormIndex, bHideCB,x, y) 
{
		
		var sSelects, nWindowHeight;
	    gsFormIndex = sFormIndex;
	    gsFormSuffix = sFormSuffix;
	    var e = getE('BuyItem' + sFormIndex);

		y = y + topScroll() - 285;
		x = x - 500;

        getE("StateInfo1").style.left = x + 'px';
	    getE("StateInfo1").style.top = y + 'px';
        sSelects = "FormBuy" + sFormSuffix; // + sFormIndex;

		sVarParam = getCustomData('srcList','tarList')
		if(sVarParam != null){
			if(sVarParam == ""){
				alert("Vyberte prosím, parametry zboží !")
				return;
			}else{
				aParams = sVarParam.split(' ');
				document.forms[sSelects].elements.sParamSize.value = aParams[0];
				document.forms[sSelects].elements.sParamColor.value = aParams[1];
			}
		}
		
		//idx = document.forms[sSelects].elements.Code.value.indexOf(' ');
		//if(idx > -1){document.forms[sSelects].elements.Code.value = document.forms[sSelects].elements.Code.value.substring(0,idx)}
		//document.forms[sSelects].elements.Code.value += (" " + sVarParam);
		document.forms[sSelects].submit();
} 


function findPosX2(Obj)
// nalezne absolutni souradnice objektu
{
  var x= -Obj.offsetLeft; 
  var y= -Obj.offsetTop; 
  var temp;
  
  if (Obj.offsetParent) {
    temp = Obj;
    while (temp.offsetParent) {
      temp = temp.offsetParent;
      x += temp.offsetLeft;
      y += temp.offsetTop;
    }
  }
  
  x += Obj.offsetLeft;
  y += Obj.offsetTop;

  
  return x; 
}
function findPosX(obj)
{
var curleft = 0;
var x = obj;
while (x.parentNode && x.tagName != 'BODY' )
{
    x = x.parentNode;
   curleft += x.offsetLeft ;
}
	
	return curleft;
}


function findPosY2(Obj)
// nalezne absolutni souradnice objektu
{
  var x= -Obj.offsetLeft; 
  var y= -Obj.offsetTop; 
  var temp;
  
  if (Obj.offsetParent) {
    temp = Obj;
    while (temp.offsetParent) {
      temp = temp.offsetParent;
      x += temp.offsetLeft;
      y += temp.offsetTop;
    }
  }
  
  x += Obj.offsetLeft;
  y += Obj.offsetTop;
  
  return y; 
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent && obj.id != 'containerBody')
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}

/*
function BuyOrSetVariableParams(sFormSuffix,sFormIndex) {
	var sSelects, nWindowHeight;
	gsFormIndex = sFormIndex;
	gsFormSuffix = sFormSuffix;
   

    document.forms["FormBuy" + sFormSuffix + sFormIndex].submit();
   
    var e = event.srcElement;
    var y = 0;
    var x = event.clientX;

    while (typeof e == 'object' && e.tagName != 'BODY' && e.tagName != 'HTML')
    {
          y += e.offsetTop;
          e = e.offsetParent;
    }

    getE("StateInfo1").style.top = y - 390;
	
	alert(document.body.clientWidth);
    if (document.body.clientWidth < 933)
    {
      getE("StateInfo1").style.left = x + 100;
    }
    else
    {
      getE("StateInfo1").style.left = 290;
    }
}
*/
function BuyOrSetParams(sFormIndex) {
	var e = getE( "ItemParameters" + sFormIndex );
	e.style.display = "inline";
	e.style.position = "relative";
	e.style.top =  window.event.srcElement.offsetTop + 20;
	e.style.left =  window.event.srcElement.offsetLeft - 60;	
	e.style.border =  "1px solid black";	
}
function CopyParamsBack() {
	getE("DivForPars" + gsFormSuffix + gsFormIndex).innerHTML = getE('DivForParams').innerHTML;
	getF("BuyForm" + gsFormSuffix + gsFormIndex).submit();
}

// ###   FCE PRO ROZKLIKAVANI KATEGORII   ###

function InsertCookiesCat(intId,idTree){
	document.cookie="category"+idTree+"="+intId+";";
	document.cookie="category"+idTree+"="+intId+";";
}
function checkParent(src, dest) {
	while (src!=null) {
		if (src.tagName == dest) return src;
			src = src.parentElement;
	}
	return null;
}

function outlineCat() {
	var open = event.srcElement;
	var el = checkParent(open, "TD");
	if (null!=el) {
		var pos = 0;
		for (var pos=0; pos<el.children.length; pos++) {
			if ("TABLE"==el.children[pos].tagName) {
				if (el.children[0].src.indexOf("/img/catTree/plus.gif")>0) {
					el.children[0].src = "/img/catTree/minus.gif";
				}else{
					el.children[0].src = "/img/catTree/plus.gif";
				}
				break;
			}
		}
	    if (pos==el.children.length) return;
	} else return;
	el = el.children[pos];
	if ("TABLE"==el.tagName) {
		if (""==el.style.display) {
			el.style.display = "none";
		} else {
			el.style.display = "";
		}
	}
	event.cancelBubble = true;
}

// ###   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=330,width=350,left=10,top=10");
	objWnd.focus();
}
function OpenWndForPrint(strURL){
    //window.print();
	var objWnd = window.open(strURL,"Tisk","scrollbars=no,height=500,width=800left=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()+";";
	vyprs.setDate(365 + 365 + vyprs.getDate());
	document.cookie=strName+"=; expires="+vyprs.toGMTString()+";";
	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()+";";
	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(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 ControlIntNumber(e){

	var keynum;

	if(window.event){
		keynum = window.event.keyCode;
	}
	else if(e.which){
		keynum = e.which;
	}
	
	var el = GetSRC(e);
	var value = el.value;
	
	var selStart = getSelectionStart(el);
	
	if(keynum===undefined || keynum==8)return true; //sipky, havet a backspace ve FF
	
	if(keynum==45 || keynum>47 && keynum<58)
	{
		if(keynum==45 && value.indexOf('-')>-1){return false;}
		if(keynum==45 && selStart>0){return false;} 
		return true;
	}
	//alert(String.fromCharCode(keynum));
	
	return false;
}

function getSelectionStart(el) {
	if (el.createTextRange) {
		var r = document.selection.createRange().duplicate();
		r.moveEnd('character', el.value.length);
		if (r.text == '') return el.value.length;
		return el.value.lastIndexOf(r.text);
	} else return el.selectionStart;
}

function GetSRC(e)      { return (window.event)? window.event.srcElement : e.target; }


function ControlPhone() {
    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 (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32))
		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 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;
	}
}

function ControlSendEmailToFriend(){
    var obj1 = document.getElementById('SendToEmail');
    var obj2 = document.getElementById('SendFromEmail'); 
	
	if(obj1.value == ""){alert("Vyplňte email.");obj1.focus();return false;}
	if(obj2.value == ""){alert("Vyplňte email.");obj2.focus();return false;}
	
	if (EmailControl(obj1.value)==false) {obj1.focus();return false;}
	if (EmailControl(obj2.value)==false) {obj2.focus();return false;}
}


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;
	}
}

 
 


// ##### 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=450px;dialogHeight=400px");
		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=450,height=400,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";
}

// ##### PriceList END #####

var iTshLast;
iTshLast = 0;
var arrTsh = new Array();

function showTsh(iTsh, nTshCount, oTshOn) {

	if (iTsh == iTshLast) return;

	var sHidePar, sHideHod, sHideSes, sHideSpec;
	sHidePar = "none";
	sHideHod = "none";
	sHideSes = "none";
	sHideSpec = "none";
	if ("DetSpecifikace" == oTshOn) { sHideSpec = "inline"; }
	else if ("DetParametry" == oTshOn) { sHidePar = "inline"; }
	else if ("DetHodnoceni" == oTshOn) { sHideHod = "inline"; }
	else { sHideSes = "inline"; }

	if (getE('DetSpecifikace')!=null) getE('DetSpecifikace').style.display = sHideSpec;
	if (getE('DetParametry')!=null) getE('DetParametry').style.display = sHidePar;
	if (getE('DetHodnoceni')!=null) getE('DetHodnoceni').style.display = sHideHod;
	if (getE('DetSestava')!=null) getE('DetSestava').style.display = sHideSes;

	getE('tshImg' + (iTshLast * 2 + 1)).style.backgroundImage = 'url(/img/' + gsPlusPath + 'tshMidOff.gif)';
	getE('tshImg' + (iTsh * 2 + 1)).style.backgroundImage = 'url(/img/' + gsPlusPath + 'tshMidOn.gif)';
	getE('tshImg' + (iTshLast * 2 + 1)).className = 'DetTshOff';
	getE('tshImg' + (iTsh * 2 + 1)).className = 'DetTshOn';
	if (iTshLast == 0)
		getE('tshImg0').src = arrTsh[00].src;
	else {
		if (iTshLast!=iTsh+1)
			getE('tshImg' + (iTshLast*2)).src = arrTsh[20].src;
	}
	if (iTshLast == nTshCount - 1) {
		getE('tshImg' + (iTshLast*2+2)).src = arrTsh[30].src;
	} else {
		if (iTshLast!=iTsh-1)
			getE('tshImg' + (iTshLast*2+2)).src = arrTsh[20].src;
	}
	
	if (iTsh == 0)
		getE('tshImg0').src = arrTsh[01].src;
	else
		getE('tshImg' + (iTsh*2)).src = arrTsh[21].src;
	if (iTsh == nTshCount - 1)
		getE('tshImg' + (iTsh*2+2)).src = arrTsh[31].src;
	else
		getE('tshImg' + (iTsh*2+2)).src = arrTsh[22].src;

	iTshLast = iTsh;
}
// ##### Zalozky na detailu END #########################################################

function DisTshParamAndCompare(sImgDisCompareBegin, sImgDisCompareMid, sImgDisCompareEnd, sImgDisParamSearchEndOn) {
	var iTsh;
	iTsh = 0;
	while (getE('tshCompareMid'+iTsh)!=null) {
		if (aDisableTshAndCmp[iTsh]) {
			getE('tshCompareMid'+iTsh).innerHTML = 'Porovnej ceny';
			if (getE('tshParamSearchLR'+iTsh) != null) {
				getE('tshParamSearchLR'+iTsh).src = sImgDisParamSearchEndOn;
				getE('tshParamSearchMid'+iTsh).style.display = "none";
				getE('tshParamSearchEnd'+iTsh).style.display = "none";
			}
		}
		iTsh += 1;
	}
}

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");
}


//       STIFFOVY FCE
// ********************************* 


function ShowHide(element) {
	var e = 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 ShowHideX(element,sElName) {
	var e                               = getE( element );
	var sCurrClassName = document.getElementById(sElName).className;

	if (e.style.display=="none") 
	{ 
	    e.style.display = "block"; 
	    document.getElementById(sElName).className = sCurrClassName + 'Sel';
	} 
	else 
	{ 
	    e.style.display = "none";
	    document.getElementById(sElName).className = sCurrClassName.slice(0, -3); 
    }
//	if (!Br.IE) this.blur(); //aby nam nezustaval v mozile oznacen klikaci text
}

function styleChange(elementId,classNameStr) {
	var e = getE( elementId );
	e.className = classNameStr;
}


// ShopConfirmBox - Count Dialog
function showCountDialog( formname, code, minCount, onlyMultiplied ) {
	var e = getE( "shopconfirmbox" );
	e.style.display = "";
	e.style.position = "absolute";
	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 +150)+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	document.forms.shopconfirmform.elements.original_form.value = formname;
	document.forms.shopconfirmform.elements.code.value = code;
	document.forms.shopconfirmform.elements.minCountForOrder.value = minCount;
	document.forms.shopconfirmform.elements.onlyMultipliedCount.value = onlyMultiplied;
	document.forms.shopconfirmform.elements.count.value = minCount;
	document.forms.shopconfirmform.elements.count.focus();
}
function hideCountDialog() {
	var e = getE( "shopconfirmbox" );
	e.style.display = "none";
}
function submitCountDialog() {
	var orig_form;    orig_form    = document.forms["BuyForm"+document.forms.shopconfirmform.elements.original_form.value].elements;
	var shopbox_form; shopbox_form = document.forms.shopconfirmform.elements;

	if ( !((shopbox_form.count.value > 0) && (shopbox_form.count.value < 1000000000)) ) {
		hideCountDialog();
		return false;
	}
	
	if (!checkCount( shopbox_form.count.value, shopbox_form.minCountForOrder.value, shopbox_form.onlyMultipliedCount.value )) return false;
	
	orig_form.Count.value = shopbox_form.count.value;
	orig_form.submit();
}

function shopItemBuyOnSubmit(oForm,bOnlyMultipliedCount){
	return false;
	return checkCount(oForm.elements.count.value,oForm.elements.MinCountForOrder.value,bOnlyMultipliedCount);
}
function checkCount( myCount, minCount, onlyMultiplied) {
	
	if(isNaN(parseFloat(myCount)))return true;
	
	if ( myCount == 0 ) return true;
	if ( myCount < minCount ) {
		alert('Toto zboží lze objednat v minimálním počtu '+minCount+' ks.'); return false;
	}
	if ( (onlyMultiplied==1) && ( (myCount % minCount) != 0) ) {
		alert('Toto zboží lze zakoupit pouze v násobcích '+minCount+' ks.'); return false;
	}

	return true;
}

// AvaibilityBox - Avaibility Dialog
function showAvaibilityDialog( code, posX, posY ) {
	var e = getE( "avaibilitybox" );
	e.style.display = "";
	e.style.position = "absolute";
//	e.style.top = (posY + 50)+'px';
//	e.style.left = (posX + 50)+'px';
	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 -200)+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	document.forms.avaibilityform.elements.code.value = code;
	document.frames.avaibilityFrame.document.location = "Avaibility.asp?sCode=" + code;
	document.forms.avaibilityform.elements.count.value = "Zjišťuje se...";
}
function hideAvaibilityDialog() {
	var e = getE( "avaibilitybox" );
	e.style.display = "none";
}

// ShopInfoBox

function showShopInfoDialog( code, name, count, price ) {
	var e = getE( "shopinfobox" );
	e.style.display = "";
	e.style.position = "absolute";
	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 -100)+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	document.forms.shopinfoform.elements.code.value = code;
	document.forms.shopinfoform.elements.name.value = name;
	document.forms.shopinfoform.elements.count.value = count + ' ks';
	setTimeout("hideShopInfoboxDialog();", 10000);
}
function hideShopInfoboxDialog() {
	var e = getE( "shopinfobox" );
	e.style.display = "none";
}



/* pretahnuti polozek z jednoho slectu do druheho */
	  function move(odkud,kam,cislo){
	          if (document.all[odkud].selectedIndex < 0){alert('Nebylo nic vybráno!');return}
	          var strValue = document.all[odkud].value;
	          var strText = document.all[odkud].options[document.all[odkud].selectedIndex].text;
	          var intIndex = parseFloat(document.all[odkud].selectedIndex)
	          if (strValue != ""){
                 var el = document.createElement("OPTION")
                 el.text = strText;
                 el.value = strValue;
                 document.all[kam].options.add(el);
              }
              var x = "";
              x = "but"+odkud;
              document.all[odkud].options.remove(intIndex);
              if (parseFloat(document.all[odkud].options.length)== 0){
                  document.all[x].disabled = true;
              }
              x = "but"+kam;
              if (parseFloat(document.all[kam].options.length)> 0){
                  document.all[x].disabled = false;
              }
               document.all["total"+cislo].value = ""; 
			   for(var i = 0; i < document.all["SelectMenu"+cislo].length; i++){
			   document.all["total"+cislo].value += "&nbsp;"+(i+1)+"."+document.all["SelectMenu"+cislo].options[i].value+" &nbsp;";
			  }
          } 
		  
function GaleryPicture(FormName, ImageSrc, InputUrl, InputWidth, InputHeight, IgnoreImage, StartingPath, GaleryTitle)
{	
	window.open('/Administration/ImageGalery/ImageGalery.asp?fF='+FormName+'&fSRC='+ImageSrc+'&fURL='+InputUrl+'&fW='+InputWidth+'&fH='+InputHeight+'&II='+IgnoreImage+'&Path='+StartingPath+'&Title='+GaleryTitle, 'GaleryPicture', 'toolbar=yes,location=yes,directories=yes,menubar=yes,scrollbars=yes,resizable=yes,status=yes');	
}

function ControlBookofWishSubmit(){

  if(document.wishform.Jmeno.value == ""){alert("Vyplňte jméno.");return false}
  if(document.wishform.Email.value == ""){alert("Vyplňte e-mail.");return false}
  if(document.wishform.Nadpis.value == ""){alert("Vyplňte předmět.");return false}
  if(document.wishform.text.value == ""){alert("Vyplňte zprávu.");return false}
  
  return true
}


function fnCheckParamCommodityUse(objForm) {
	if (objForm.bParamUsed.value=='0') 
		return true;
	else 
		return confirm('Tento parametr je použit u zboží, opravdu jej chcete smazat?');
}


function ZavriKosik(bHideCB)
{
	getE("StateInfo1").style.display="none";
	
	//if (bHideCB == 1)  //potreba skryti/obrazeni elementu select
	//{
	//    window.parent.document.getElementById('PN').style.display = "";
	//}
}

function ShowAvailBox(oForm,count,x,y){
	oForm.count.value = (!isNaN(parseInt(count)))? Math.abs(parseInt(count)) : 1;
	elAvailDiv = getE('AvailInfo');
	if(elAvailDiv){
		y = y + topScroll() - 285;
		x = x - 400;
        elAvailDiv.style.left = x + 'px';
	    elAvailDiv.style.top = y + 'px';
	}
	oForm.submit();
}
function ShowBox(sId, bShow, bWithSelects){
	el = getE(sId);
	if(el){
		if(bShow){
			el.style.display = 'block';
			if(bWithSelects){hideSelects()}
		}else{
			el.style.display = 'none';
			if(bWithSelects){showSelects()}
		}
	}
}

function SearchExt_ShowHide()
{
    var objDiv = document.getElementById("SearchExt");
   
    if (objDiv.style.display == "none")
            objDiv.style.display = "block";
    else         
            objDiv.style.display = "none"; 
}





/////////////////////////////////////////////////////

//onmouseover=""showStoreBox('" & FcenSkladem(nSkladem) & "','"&sCode&"',event.clientY,event.clientX);""  onmouseout=""hideStoreBox();""

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 )
	}
}
function showStoreBox( pcs,code, posY, posX) {
	var e = getE( "StoreBox" );
	e.style.display = "";
	e.style.position = "absolute";

	e.style.top  =topScroll()+(posY-80)+'px'
	e.style.left =(posX-210)+'px'

	getE("pcsCode").innerHTML=code
	getE("pcsOnStore").innerHTML=pcs;
}

function hideStoreBox() {

	var e = getE( "StoreBox" );
	e.style.display = "none";
}



function ChangeFilters(bState, sCookieName)
{
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);
//	var sCookie  = sCookieName + '=' + (bState==true ? '1' : '0') + ';expires=' + vyprs.toGMTString() + ';';
	var sCookie  = sCookieName + '=' + (bState==true ? '1' : '0') + ';';

    document.cookie = sCookie;
}
// Vyber kombinaci parametru v DIVu


function select(el,contID){
	cont = getE(contID);
	clearAll(cont,"");
	el.className = "sel";
}
function clearAll(cont, clName){

	if(clName != null){
		elList = cont.getElementsByTagName("A");
		for(var i = 0; i < elList.length; i++){
			elList[i].className = (clName == "") ? "" : (elList[i].className + " " + clName);
		}
	}else{
		cont.inerHTML = '';
	}
}
function findPositX(obj) {
   var curleft = curtop = 0;
   if (obj.offsetParent) {
      curleft = obj.offsetLeft
      curtop = obj.offsetTop
      while (obj = obj.offsetParent) {
         curleft += obj.offsetLeft
         curtop += obj.offsetTop
      }
   }
   return curtop - 120;
} 
function findPositY(obj) {
   var curleft = curtop = 0;
   if (obj.offsetParent) {
      curleft = obj.offsetLeft
      curtop = obj.offsetTop
      while (obj = obj.offsetParent) {
         curleft += obj.offsetLeft
         curtop += obj.offsetTop
      }
   }
   return curleft - 600;
} 



function getSelElement(parent,clsName){
	elList = parent.getElementsByTagName("A");
	for(var i = 0; i < elList.length; i++){
		if(elList[i].className == clsName){
			return elList[i];
		}
	}
	return null;
}

function getCustomData(sSource,sTarget){
	oSrc = getE(sSource);
	oDst = getE(sTarget);
	if(oSrc == null && oDst == null){return null}

	elSelSrc = getSelElement(oSrc,"sel");
	elSelDst = getSelElement(oDst,"sel");

	if(elSelSrc != null && elSelDst != null){
		return (elSelDst.getAttribute("val") + " " + elSelSrc.getAttribute("val"));
	}
	return "";
}
function ExecOrderFormValidate(elInpDate1,elInpDate2){
	return (IsDate(elInpDate1,'Datum od') && IsDate(elInpDate2,'Datum do'));
}
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 hideSelects() {
	if(Br.IE){
		var els = document.getElementsByTagName('select'); 
		for (var i=0;i<els.length;i++) { els[i].style.visibility='hidden'; }
		if(window.top != window){
			els = top.document.getElementsByTagName('select');
			for (var i=0;i<els.length;i++) { els[i].style.visibility='hidden'; }
		}
	}
}
function showSelects() {
	if(Br.IE){ 
		var els = document.getElementsByTagName('select'); for (var i=0;i<els.length;i++) { els[i].style.visibility='visible'; }
	}
}

function showSelectsDetail() {
	if(Br.IE){
		var els = window.parent.document.getElementsByTagName('select'); for (var i=0;i<els.length;i++) { els[i].style.visibility='visible'; }
	}
}

function parentbgchange(sClass, obj){

	if (obj.childNodes[0] != null) {
  obj.childNodes[0].className = sClass;
  }
	if (obj.childNodes[1] != null) {
  obj.childNodes[1].className = sClass;
  }
  if (obj.childNodes[2] != null) {
  obj.childNodes[2].className = sClass;
  }
  	if (obj.childNodes[3] != null) {
  obj.childNodes[3].className = sClass;
  }
  if (obj.childNodes[4] != null) {
  obj.childNodes[4].className = sClass;
  }
	if (obj.childNodes[5] != null) {
  obj.childNodes[5].className = sClass;
  }
  if (obj.childNodes[6] != null) {
  obj.childNodes[6].className = sClass;
  }
	if (obj.childNodes[7] != null) {
  obj.childNodes[7].className = sClass;
  }
  if (obj.childNodes[8] != null) {
  obj.childNodes[8].className = sClass;
  }	
}


function redirLangVersion1(sLangVersion, nLang){
   if (confirm(sLangVersion)) 
      {
        //getF('Form1').action = getF('Form1').action + '?lang='+nLang  
        //getF('Form1').Oredir.value = '1';
        //getE('Form1').submit();
        //window.location.href='/order.asp?OrderPart=3&Oredir=1&lang='+nLang
        }
   else 
      {history.back(-1);}
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function redirLangVersion2(sLangVersion, nLang){
   if (confirm(sLangVersion)) 
      {
        //getF('Form1').action = getF('Form1').action + '?lang='+nLang  
        //getF('Form1').Oredir.value = '1';
        //getE('Form1').submit();
        //window.location.href='/order.asp?OrderPart=3&Oredir=1&lang='+nLang
        }
   else 
      {history.back(-1);}
}

function checkAllProducers () {
	for (var x=0; x<getF('PNSORTx').MRK.length;x++){
       getF('PNSORTx').MRK[x].checked = "check";	
		}
}

function checOutkAllProducers () {
	for (var x=0; x<getF('PNSORTx').selVlastnost.length;x++){
       getF('PNSORTx').selVlastnost[x].checked = "";	
		}
}



function showHideVisitedItems() {
  if (getE('hideVisited').style.display == 'none') {
    getE('hideVisited').style.display = 'block';
    getE('showVisited').style.display = 'none';
    
  } else {
    getE('showVisited').style.display = 'block';
    getE('hideVisited').style.display = 'none';
  }  
}

function is_child_of(parent, child) {
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}


function changeClass(obj, cl1, cl2){
  if (obj.className == cl1) {obj.className = cl2} else {obj.className = cl1};
}         

function ShowHideNew(element) {
	var e = getE(element);
	if (e.style.display=="none") { e.style.display = "block";  } else { e.style.display = "none";};
}

function ShowRememberPart(targetId, bRememberPage) {


  var e1 = getE("ir"+targetId);
  var sToDo;
  
  var xpos = findPositX(e1)
  var ypos = findPositY(e1)
  // Docasne
  if (e1.src.indexOf('/img/bt-rememberRemove.gif') >-1) {sToDo = 'removeitem';} else {sToDo = 'loadgroups'}
	
   var ajax = new Ajax('/RememberBack.asp?task='+sToDo+'&id='+ targetId + '&brememberpage=' +  bRememberPage  + '&xpos=' + xpos + 'px&ypos=' +ypos + 'px','get',cbfRes);
   ajax.sendRQ( '' , false );

}

function RememberAdd (idItem, bRememberPage) {
  
	
	 var sGrpName;
	 var sIdgrp;
   
  
   if (getE('addGroup') == null) {sGrpName = '';} else {sGrpName = encodeURI(getE('addGroup').value);} 
   if (getE('grpSel') == null) {sIdgrp = 0;} else {sIdgrp = getE('grpSel')[getE('grpSel').selectedIndex].value}      
		
   var ajax = new Ajax('/RememberBack.asp?task=addItem&id='+ idItem + '&grpName=' + sGrpName + '&grpID=' + sIdgrp + '&brememberpage=' +  bRememberPage ,'get',cbfRes);
   ajax.sendRQ( '' , false );
}

function RemoveGrpDialog (grpID) {
  
   var e = getE("del"+grpID);
		
   var ajax = new Ajax('/RememberBack.asp?task=removegrpdialog&grpID='+ grpID + '&xpos=' + findPositX(e) + 'px&ypos=' + findPositY(e)  + 'px' ,'get',cbfRes);
   ajax.sendRQ( '' , false );
}

function RemoveGrp (grpID) {
  
  var e = getE("del"+grpID);
	
   var ajax = new Ajax('/RememberBack.asp?task=removegrp&grpID='+ grpID + '&xpos=' + e.offsetTop + 'px&ypos=' +e.offsetLeft + 'px' ,'get',cbfRes);
   ajax.sendRQ( '' , false );
}


function RememberSendDialog (grpID) {
  
   var e = getE("send"+grpID);
	
   var ajax = new Ajax('/RememberBack.asp?task=remembersenddialog&grpID='+ grpID + '&xpos=' + findPositX(e) + 'px&ypos=' + findPositY(e)  + 'px' ,'get',cbfRes);
   ajax.sendRQ( '' , false );
}


function RememberSend (grpID, sEmail, sText) {
  
	 var grpID, sEmail, sText;

   if (getE(grpID) == null) {grpID = 0;} else {grpID = getE(grpID).value} 
   if (getE(sEmail) == null) {sEmail = '';} else {sEmail = getE(sEmail).value}      
   if (getE(sText) == null) {sText = '';} else {sText = getE(sText).value}
	
  sText = sText.replace(/\n/g,'<br>');
		
   var ajax = new Ajax('/RememberBack.asp?task=remembersend&grpID=' + grpID + '&email=' + encodeURI(sEmail) + '&text=' +  encodeURI(sText) ,'get',cbfRes);
   ajax.sendRQ( '' , false );
}



function competitionSubmit(nCountItems, nTypeComp) {

  if (nTypeComp == 0) {
    if (EmailControl(getF('frmCompetition').s_EMAIL.value)==false) {getF('frmCompetition').s_EMAIL.focus();return false;}
  	if(getF('frmCompetition').s_EMAIL.value == ""){alert("Vyplňte email.");getF('frmCompetition').s_EMAIL.focus();return false}
   getE('frmCompetition').submit();
 
  } else {
    getE('frmCompetition').submit();    
  }

}


function showWriteUs(e) {
  var divBox = getE('writeUs');  
  
  if (divBox==null) return false;  

  divBox.style.display='block';  
	divBox.style.position = 'absolute';
	divBox.style.top = findPositX(e) + 'px';
	divBox.style.left = findPositY(e) - 600 + 'px';
	divBox.style.zIndex = 99;
}

function SendWriteUs() {
  var form = getF('WriteUs');  
		
	 var sEmail, sText, product, bCh;
    
   sEmail = form.email.value;
   sText = form.dotaz.value;   
   product = location.href;
   if(form.bCopy.checked == true ) {bCh=1} else {bCh=2}   
	
  //if (product == "") {product = location.href;}
  if (sEmail == "") {alert("Není zadán e-mail."); return false;}
  
   sText = sText.replace(/\n/g,'<br>');
		
   var ajax = new Ajax('/Back_WriteUs.asp?task=sendEmail&email=' + encodeURI(sEmail) + '&text=' +  encodeURI(sText) + '&product=' +  encodeURI(product) + '&bchecked=' +  bCh,'get',cbfRes);
   ajax.sendRQ( '' , false );
}


function showWatchDogDialog(e) {
  var divBox = getE('watchdogDialog');  
  
  if (divBox==null) return false;  

  divBox.style.display='block';  
	divBox.style.position = 'absolute';
	divBox.style.top = findPositX(e) + 'px';
	divBox.style.left = findPositY(e) + 'px';
	divBox.style.zIndex = 99;
}

function WatchDogAdd(idProd) {
  var form = getF('WatchDog');  
  var sEmail = form.email.value; 
	
  var ajax = new Ajax('/Back_WatchDog.asp?task=addEmail&email=' + encodeURI(sEmail) + '&id='+idProd,'get',cbfRes);
  ajax.sendRQ( '' , false );
}

function WatchDogRemove() {
  var form = getF('watchdogDialogQ');  
  var sEmail = form.email.value;
  var idProd = form.idProd.value;  
	
  var ajax = new Ajax('/Back_WatchDog.asp?task=removeemail&email=' + encodeURI(sEmail) +'&id='+idProd,'get',cbfRes);
  ajax.sendRQ( '' , false );
}

function showSendToF(e) {
  var divBox = getE('sendToF');  
  
  if (divBox==null) return false;  

  divBox.style.display='block';  
	divBox.style.position = 'absolute';
	divBox.style.top = findPositX(e) + 'px';
	divBox.style.left = findPositY(e) - 600 + 'px';
	divBox.style.zIndex = 99;
}

function SendToF() {
  var form = getF('sendToF');  
		
	 var sEmail, sEmailTo, sText, bCh, sNameProd, sUrlProd;
    
   sEmail = form.email.value;   
   sEmailTo = form.emailTo.value;
   sText = form.dotaz.value;            
   sNameProd = form.prod_name.value;
   sUrlProd = form.prod_url.value;
   if(form.bCopy.checked == true ) {bCh=1} else {bCh=2}   
	
   sText = sText.replace(/\n/g,'<br>');
		
   var ajax = new Ajax('/Back_SendToFriend.asp?task=sendEmail&email=' + encodeURI(sEmail) + '&emailTo=' + encodeURI(sEmailTo) + '&sNameProd=' + encodeURI(sNameProd) + '&sUrlProd=' + encodeURI(sUrlProd) + '&text=' +  encodeURI(sText) + '&bchecked=' +  bCh,'get',cbfRes);
   ajax.sendRQ( '' , false );
}

function showChangeFormLogin(e) {
  var divBox = getE('changeEmail');  
  
  if (divBox==null) return false;  

  divBox.style.display='block';  
	divBox.style.position = 'absolute';
	divBox.style.top = findPositX(e) + 'px';
	divBox.style.left = findPositY(e) - 200 + 'px';
	divBox.style.zIndex = 99;
}

function ShowHideTopMenuSet(nType) {

  var divMain, divBody, classShow, classHide;  

  switch(nType)
  {
  case 1:
    // Kontakt    
    divMain = 'contactMn'; divBody = 'cont'; classShow = 'contacts contacts-s' ; classHide = 'contacts' ; 
    break;
  case 2:
    // Informace / poradna    
    divMain = 'infoMn'; divBody = 'inf'; classShow = 'info info-s' ; classHide = 'info' ; 
    break;
  case 3:
    // Volba státu    
    divMain = 'cntrMn'; divBody = 'cntr'; classShow = 'country country-s' ; classHide = 'country' ; 
    break;
  default:
    divMain = 'contactMn'; divBody = 'cont'; classShow = 'contacts contacts-s' ; classHide = 'contacts';  
  }

  
	var e = getE(divBody);
  var e2 = getE(divMain);
	
  if (e.style.display=="none") 
       {
        e.style.display = "block"; 
        e2.className = classShow;
       } 
  else { 
          e.style.display = "none";          
          e2.className = classHide;
       }
}

function showProductVideo(e, sVideoUrl) {

  var divBox = getE('productVideo');  
  if (divBox==null) return false;  

  MovieAdd('productVideoPart','725','395',sVideoUrl)

  divBox.style.display='block';  
	divBox.style.position = 'absolute';
	divBox.style.top = '0px';
	divBox.style.left = '0px';
	divBox.style.zIndex = 99;

}

function MovieAdd(idDiv, width, height, url) {

   var container = document.getElementById(idDiv);
   if (!container)
        return;

   container.innerHTML = '';

   var object = document.createElement("object");
   object.setAttribute("width", width);
   object.setAttribute("height", height);

   var param1 = document.createElement("param");
   param1.setAttribute("name", "movie");
   param1.setAttribute("value", url);
   
   var param2 = document.createElement("param");
   param2.setAttribute("name", "allowFullScreen");
   param2.setAttribute("value", "true");   

   var param3 = document.createElement("param");
   param3.setAttribute("name", "allowscriptaccess");
   param3.setAttribute("value", "always");   


   var embed = document.createElement("embed");
   embed.setAttribute("src", url);
   embed.setAttribute("type", "application/x-shockwave-flash");
   embed.setAttribute("allowFullScreen", "true");   
   embed.setAttribute("allowscriptaccess", "always");
   embed.setAttribute("width", width);
   embed.setAttribute("height", height);
  
   object.appendChild(param1);
   object.appendChild(param2);   
   object.appendChild(param3);   

    if (object.outerHTML) {
    document.getElementById(idDiv).innerHTML = object.outerHTML;    
    document.getElementById(idDiv).innerHTML = embed.outerHTML;
    } else {
    document.getElementById(idDiv).appendChild(embed);
    }
}


function showSendTaskFromProvision(e) {
  var divBox = getE('SendProvisionTask');  
  
  if (divBox==null) return false;  

  divBox.style.display='block';  
	divBox.style.position = 'absolute';
	divBox.style.top = findPositX(e) + 'px';
	divBox.style.left = findPositY(e) - 600 + 'px';
	divBox.style.zIndex = 99;
}

function SendProvisionTask(sEmail, sName) {
  var form = getF('SendProvisionTaskF');  
		
	 var sText;
    
   sText = form.SendFromComent.value;            
   sText = sText.replace(/\n/g,'<br>');
		
   var ajax = new Ajax('/Back_SendTaskFromProvision.asp?task=sendEmail&email=' + encodeURI(sEmail) + '&name=' + encodeURI(sName) + '&text=' +  encodeURI(sText) ,'get',cbfRes);
   ajax.sendRQ( '' , false );
}


function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}




