// 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;
}

String.prototype.trim = function() {return this.replace( /(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '' ) ;}
function getE(objectID)     {   return document.getElementById(objectID); }
function getF(formName)     {	return document.forms[formName];}
function getTN(sValue)		{ if(sValue=='' || sValue==' '){return document.createTextNode('\u00a0');}return document.createTextNode(sValue);	}
function getCE(sElement)	{ return document.createElement(sElement);	}
function RemoveCh(Node) { if ( Node == null ) return false;  while (Node.childNodes.length>0)   {       Node.removeChild( Node.childNodes[0] );   } }
function GetSRC(e)      { return (window.event)? window.event.srcElement : e.target; }
function setE(id,attr,value){ var el = getE(id); if(el!=null){el[attr] = value;} }



// *************************************************************************************************

// status, args nechany z duvodu kompatibility
function showMyModalDialog(url,title,sizeX,sizeY,status,args,top) //top znaci jak daleko od vrchu okna
{
   var wo = document;
   var frameID = '';
   if(window!=window.top){
      wo = window.top.document;
      frameID = window.self.name;
   }
   
   if(getE('modalIframe')){return;}
    
   if(Br.IE6)
   {
   		var clona = wo.createElement('iframe');
	    clona.id='clona';
	    clona.src = '/administration/clonaIE6.htm';
   		wo.body.appendChild(clona);
   }
   else
   {
   		var div=wo.createElement('div');
	    div.id='clona';
   		wo.body.appendChild(div);
   }
   
    
   var clona=wo.createElement('div');
   clona.id='clona1'; // margin nelze pouzit, bug v IE

   url += ((url.indexOf("?")>-1)?"&":"?") +"title="+ title+"&frameID="+ frameID;
   
   clona.innerHTML="<iframe name='modalIframe' id='modalIframe' width='"+sizeX+"' height='"+sizeY+"' frameborder='0' scrolling='auto' src='"+ url +"'></iframe>";
    
   wo.body.appendChild(clona);
   if(top!==undefined){
      wo.getElementById('modalIframe').style.top=top;
   }
}
 

function prmtest(id, value) {
params_1.newValueReturn(id, value); }
function CloseMyModalDialog(){

	if(window.top.document.getElementById('clona1') && window.top.document.getElementById('clona'))
	{ 
    window.top.document.body.removeChild(getE('clona1'));
    window.top.document.body.removeChild(getE('clona'));
    }
}



function SetDSP(nDSP, sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);

	if (nDSP==1) 
	{
		document.cookie="DSP=1; expires="+vyprs.toGMTString()+";path=\/;";
	} 
	else 
	{
		document.cookie="DSP=0; expires="+vyprs.toGMTString()+";path=\/;";
	}
	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;
	if (sSelects == "") {
		getF("BuyForm" + sFormSuffix + sFormIndex).submit();
	} else {
		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 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);

    if (window.frames) {
        for (var i = 0; i < window.frames.length; i++) {
            if (window.frames[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;
			}
		}
	}
}

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))
		sCurrency = FormatCurrency(nNumber, nDecimal);
	else
		sCurrency = "0";
	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(value,nMax, obj){
    if(value > nMax && value >= 1){    
      alert("Číslo stránky musí být v rozmezí od 1 - " + nMax);
      return false;
    }else{
			if (obj.action.indexOf('pg-0') != -1) obj.action = obj.action.replace(/pg-0/,'pg-'+value)
			else if (obj.action.indexOf('PgID=0') != -1) obj.action = obj.action.replace(/PgID=0/,'PgID='+value)
      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 ControlNumber(eventCode) {
     if (((eventCode.keyCode <96) || (eventCode.keyCode >105)) && ((eventCode.keyCode <37) || (eventCode.keyCode >41)) && ((eventCode.keyCode <48) || (eventCode.keyCode >57)) && (eventCode.keyCode!=13) && (eventCode.keyCode!=8) && (eventCode.keyCode!=18) && (eventCode.keyCode!=46)) return 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.keyCode != 45))
		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;
	}
}

function ShowImage(sImgPath, GLI) {
    //window.open('/ShowImage.asp?gli=' + GLI + '&IMG=' + encodeURI(sImgPath) + '', "Foto", "scrollbars=0,status=0,toolbar=0,location=0,directories=0,height=100,width=100,resizable=1");
    window.open('/ShowImage.asp?IMG=' + encodeURI(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" };
}

function styleChange(elementId,classNameStr) {	var e = getE( elementId );	e.className = classNameStr;}

function hideAvaibilityDialog() {
	var e = getE( "avaibilitybox" );
	e.style.display = "none";
}

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 )
	}
}
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 = 25;
	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';
}
function showShopInfoDialog() {
	clearTimeout;
	if (!Br.OP) SelectHide('hidden');
	var e = getE("shopinfobox");
	if (e) {
	    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");
    if (e) {
        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" );
	
	e.style.position = "absolute";
	e.style.top = topScroll() + 300+'px';
	e.style.left = (document.body.clientWidth/2 - 210)+'px';
	fadeInObject ( "shopconfirmbox", 0 );
	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) {
    if (getE("shopinfobox")) { getE("shopinfobox").style.display = 'none'; }
	frm.action = sAction;
	frm.target = sTarget;
	frm.elements.AUO.value = '';
	//alert(frm.action);
	frm.submit();
	
}

function GetBuyDetail(frm,sAction,sTarget, idPNC) {

    if (getE('ParamItemdetail'))     getE('ParamItemdetail').value = idPNC;
    if (getE('countdetail'))         getE('countdetail').value     = getE('Count_' + idPNC).value;
    if (getE("shopinfobox")) { getE("shopinfobox").style.display = 'none'; }
	frm.action = sAction;
	frm.target = sTarget;
	frm.elements.AUO.value = 'ok';
	
	frm.submit();
}

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 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 = '/Includes/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 Bookmark(url,title){
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	}
	else if( document.all){
		window.external.AddFavorite(url, title);
	}
	else{
		return true;
	}
}
function changeProducers(divId)
{
    for (var i=1;i<=5;i++)
    {
        getE("prod"+i).className="foldEx";
        getE("prodList"+i).style.display="none";
    }
    getE("prod"+divId).className="foldEx selFo";
    getE("prodList"+divId).style.display="block";
}

function addBookmark() 
{
    var sTitle, sUrl;
  
    sTitle = document.title;
    sUrl  = document.location.href 
    
    if (window.sidebar) 
    { 
            window.sidebar.addPanel(sTitle, sUrl,""); 
    } 
    else if ( document.all ) 
    {
            window.external.AddFavorite( sUrl, sTitle);
    } 
    else if ( window.opera && window.print ) 
    {
            return true;
    }
}

function ShowImageDetail(sImgPath,sID) {
		getE(sID).src = sImgPath;

}

function ControlDecimalNumber(e){
	var keynum;
	
	if(window.event){
		keynum = window.event.keyCode;
	}
	else if(e.which){
		keynum = e.which;
	}
	if((GetSRC(e).value.indexOf(',')>-1 || GetSRC(e).value.indexOf('.')>-1 )&&(keynum == 44 || keynum == 46)){return false;}
	//alert(keynum);
	//                                                                                      carka           tecka
	return (((keynum >= 48) && (keynum <= 57)) || (keynum == 8 || keynum == 13) || (keynum == 44 || keynum == 46) || keynum === undefined);
}
function chckFrmAssistent()
{
    if (!EmailControl(getE('email').value)) {return false;}
    if (getE('question').value==''){alert('Není vyplněn text dotazu.'); return false;}
    return true;
    
}
function showPrmImage(idc, idp)
{
    window.open("/showParamImages.asp?DPG="+idc+"&ipar="+idp,"Images","toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=520,height=500,left=0,top=0");
}
function showHMcalc(nprice) {
    var objWnd = window.open("/HomeCredit/HomeCredit.asp?nPrice=" + nprice, "_blank", "scrollbars=no,height=450,width=600,left=10,top=10", true);
    objWnd.focus();
}