bV  = parseInt(navigator.appVersion)
bNS = navigator.appName=="Netscape"
bIE = navigator.appName=="Microsoft Internet Explorer"

function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    return typeof a == 'string';
}
function isUndefined(a) {
    return typeof a == 'undefined';
} 

    function SetCSS(title) {
       var i, a, main;
       for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
           if((a.getAttribute("rel").indexOf("style") != -1)&&(a.getAttribute("title"))){
               a.disabled = true;//vsechno implicitne vypinam
               if(a.getAttribute("title") == title)//pozadovany styl?
                    a.disabled = false; //opet zapnu
           }
       }
       newCookie('cssfile',title,24*7);
    }

    function newCookie(name,val,hours) {
       var date = new Date();
       date.setTime(date.getTime()+(hours*60*60*1000));
       var expires = "; expires="+date.toGMTString();
       document.cookie = name+"="+val+expires+"; path=/";       
    }
    
    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;
    }
    
    /********************/
        
    /*vratit pole z cookiny aname*/
    function CookieArrayGet(aname){
      var out = new Array();
      var s=readCookie(aname);
      if (s!=null){
		var x=s.split('^'); 
		for(var i=0; i<x.length; i++){
			y=x[i].split('~');
			out[y[0]]=y[1];
		}
	  }
      return out;
    }
    
    function CookieArraySet(aname,a){
      var s = '';
      for(var id in a){
        if (s!='') s=s+'^';
        s=s+id+'~'+a[id];
      }
      newCookie(aname,s,24*7*12);
    }
    
    /* cookiena aname obsahuje pole, ve ktere nastavit [x]=y */
    function CookieArrayStore(aname,Aid,Aval){
      if (Aid==null) return;
      var a=CookieArrayGet(aname);
	  a[Aid]=Aval;
	  CookieArraySet(aname,a);
    }
    
    /* z cookie pole precist hodnotu x a vratit*/
    function CookieArrayRead(aname,Aid){
      var a=CookieArrayGet(aname);
      for(var id in a)
		if (id==Aid)
		  return a[id];
    }


function parseURL(url){
  var i, pos, argname, value, queryString, pairs, out;
  queryString = url.search.substring(1);
  pairs = queryString.split("&");
  out=new Object();
  for (i = 0; i < pairs.length; i++){
   pos = pairs[i].indexOf('=');
   if (pos == -1)
     continue;
   argname = pairs[i].substring(0,pos);
   value = pairs[i].substring(pos+1);
   out[argname]=value;
  }
  return out;
}

//decode pro RFC1738
function decodeURL(url){
  return unescape(url).replace(/&amp;/g,'&');
}

function getId(id){
    if (isObject(id)) return id;
    return document.getElementById(id);
}

function reloadnow(){
  var scrTop = document.body.scrollTop;//pozice scrollu
  var a=window.location.href;//
  var ind=a.lastIndexOf('&scrollto');//hledam, jestli uz parametr existuje
  if (ind>0)//jestli jo
    a=a.slice(0,ind);//tak ho vyseknu
  window.location.href=a+'&scrollto='+scrTop;
}

function pageLoaded(){
  var a=window.location.href;//pozice
  var ind=a.lastIndexOf('&scrollto');//najdu parametr
  var scrTop=a.slice(ind+10);//zjistim hodnotu (tenhle je vzdy posledni)
  if ( scrTop > 40)
    window.scrollTo(0,scrTop);
}

function add2basket(pid){
  p=document.getElementById('hm_'+pid);
  window.location.href='?page=basket&buypid='+pid+'&count='+p.value;
}

function SetVisibility(objid, boolstate){
  if (boolstate){
    s='visible';
  }else{
    s='hidden';
  }
  if (obj=getId(objid)) obj.style.visibility=s;
}
function GetVisibility(objid){
	if (!isObject(objid))
		objid=getId(objid);
	if (!objid) return false;
	if (objid.style.visibility=='hidden')	return false;
	return true;
}

function SetDisplaying(objid, boolstate){
  if (boolstate){
    s='';
  }else{
    s='none';
  }
  if (isObject(objid))
	objid.style.display=s;
  else
    if (obj=getId(objid)) obj.style.display=s;
}

function GetDisplaying(objid){
  if (!isObject(objid))
		objid=getId(objid);
  if (objid)
    s=objid.style.display;
  else
    return false;
  //if (s=='none')
	if (s.indexOf('none')>=0)
      return false;
  return true;
}

function ToogleDisplaying(objid){
  SetDisplaying(objid,!GetDisplaying(objid));
}

function ToogleVisibility(objid){
  SetVisibility(objid,!GetVisibility(objid));
}

function SetClass(objid,cl){
	if (isString(objid))
		objid=getId(objid);
  if (objid)
    objid.className=cl;
}



var actionsrc="";//vystavuji globalne, aby si ji selektory mohli snadno precist

function popupaction(actsrc){
  if (actsrc.lastIndexOf('javascript:')==0){//je to javascript
      eval(actsrc.slice(11));
  }else
    window.location.href="../index.php"+actsrc;
}

function CheckAll(checked){
    var col = document.getElementsByTagName("INPUT");
    for (var i=0;i<col.length;i++) {
  col[i].checked= checked;
    }
}
/*

Ways of calling the function now are:
To get all a elements in the document with a info-links class. 
<CODE>getElementsByClassName(document, "a", "info-links");</CODE> 
To get all div elements within the element named container, with a col and a left class. 
<CODE>getElementsByClassName(document.getElementById("container"), "div",["col", "left"]); </CODE>
*/

function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
} 

function getElementsByClassName(oElm, strTagName, oClassNames){
    if (oElm==null) oElm=document.body;

    var arrElements = (strTagName == "*" )? getAllChildren(oElm) : 
					  oElm.getElementsByTagName(strTagName);

    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + 
            oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + 
        oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;                      
            }
        }
        if(bMatchesAll)
            arrReturnElements.push(oElement);
		
    }
    return (arrReturnElements)
}

function getElementByClassName(oElm, strTagName, oClassNames){
  arr=getElementsByClassName(oElm, strTagName, oClassNames);
  
  return arr.length==0 ? null : arr[0];
}

function parseClasses(oClassNames){
    return oClassNames.split(' ');
}

function parseClassesContain(oClassNames,testedclass){
	var a = parseClasses(oClassNames);
	for(var i=0; i<a.length; i++){
		if (a[i]==testedclass)
			return true;
	}
	return false;
}

function Smaller(a,b){
  return a<b?a:b;
}
function Bigger(a,b){
  return a>b?a:b;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function str2int(s){
  return parseInt(s);
}


function countLineBreaks (string) {
  var re = /\r\n|\r|\n/g;
  var n = 0;
  while (re.exec(string))
    n++;
  return n;
}

function DynTextArea_SetAreas(parent){
  elements=getElementsByClassName(parent,'TEXTAREA','');
  for(i=0; i < elements.length;i++){
    elements[i].onkeyup=new Function('e',"DynTextArea_SetMe(this);");
    DynTextArea_SetMe(elements[i]);
  }
}

function DynTextArea_SetMe(obj) {
  var Min=2, Max=20, LineAproxHeight=20;
  if (document.all) {//IE simple reseni

    while (((obj.scrollHeight > obj.clientHeight)||(obj.rows<Min))&&(obj.rows<Max))//natahovat
      obj.rows++;
    while (((obj.scrollHeight+LineAproxHeight < obj.clientHeight)||(obj.rows>Max))&&(obj.rows>Min))//a i zkracovat
      obj.rows--;
    //obj.scrollTop = 0;
  }
  else if (obj.rows) {
    obj.rows=7;
    /* tohle je trapny reseni, takze v mozile natvrdo
    var lineBreaks = countLineBreaks(textarea.value);
    var rows = parseInt(textarea.rows);
    var wrap = textarea.getAttribute('wrap');
    if (lineBreaks > rows)
      textarea.rows = ++rows;
    else if (wrap.toLowerCase() == 'soft' || wrap.toLowerCase() == 'hard') {
      while (textarea.rows * textarea.cols <= textarea.value.length) {
        textarea.rows = ++rows;
      }
    }
    */
  }
}

function GetCellRelative(tdobj,offsetrow,offsetcol){
  tdindex=MyOrderNum(tdobj);
  //activetr=activetd.parentElement;
  activetr=activetd.parentNode;
  trindex=MyOrderNum(activetr);
  if (desttr=activetr.parentNode.childNodes[trindex+offsetrow*(document.all?1:2)]){
	if (desttd=desttr.childNodes[tdindex+offsetcol]){
	  return desttd;
    }
  }
  return null;
}

/*vraci kolikaty children sveho rodice jsem*/
function MyOrderNum(obj){
  par=obj.parentNode;
  for(var i=0; i<par.childNodes.length; i++)
    if (par.childNodes[i]==obj)
      return i;
  return -1;
}


function DisableSelecting(){
	document.onselectstart=new Function ("return false");
	document.onmousedown=new Function ("return false");
}

function EnableSelecting(){
	document.onselectstart=null;
	document.onmousedown=null;
}


function explode(inputstring, separators, includeEmpties) {
	inputstring = new String(inputstring);
	separators = new String(separators);

	if(separators == "undefined") { 
		separators = " :;";
	}

	fixedExplode = new Array(1);
	currentElement = "";
	count = 0;

	for(x=0; x < inputstring.length; x++) {
		chr = inputstring.charAt(x);
		if(separators.indexOf(chr) != -1) {
			if ( ( (includeEmpties <= 0) || 
				   (includeEmpties == false) ) 
				  && (currentElement == "")) { 
			} else {
				fixedExplode[count] = currentElement;
				count++;
				currentElement = ""; 
			} 
		}else { 
			currentElement += chr; 
		}
	}

	if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
		fixedExplode[count] = currentElement; 
	}
	return fixedExplode;
}

/*HEX to DEC*/
var hD="0123456789ABCDEF";
function d2h(d) {
var h = hD.substr(d&15,1);
while(d>15) {d>>=4;h=hD.substr(d&15,1)+h;}
return h;
}
function h2d(h) {return parseInt(h,16);}




var HelpWindowObj,HelpWindowCall;
function ShowHelp(me,text){
	if (HelpWindowObj){//napoveda je jiz aktivni
		if (HelpWindowCall==me){//a je to ta stejna!!
			HideHelp();//skryt
			return;		//a odejit
		}
		HideHelp(); //jen skryt
	}
	
	x=findPosX(me);
	y=findPosY(me);
	w=300;
	h=200;
	//alert(x+":"+y+" - "+text);
	var obj=document.createElement("div");//hlavni objekt
	obj.id="helpwin";
	obj.className="helpwindow";
    obj.style.position="absolute";
    //obj.style.left=(x-w+10)+"px";
    //obj.style.top=y+6+"px";
    obj.style.left=(x-w+54)+"px";
    obj.style.top=y+10+"px";
    obj.onclick=HideHelp;
    document.body.appendChild(obj);
    
    var obji=document.createElement("div");
    obji.className="helpwindowIN";
    obji.onclick=HideHelp;
    obj.appendChild(obji);
    
    var objii=document.createElement("div");
    objii.className="helpwindowININ";
    objii.onclick=HideHelp;
    obji.appendChild(objii);
    
    var cb=document.createElement("div");
    cb.className="closewin";
    cb.onclick=HideHelp;
    objii.appendChild(cb);
    
    var ta=document.createElement("div");
    ta.className="text";
    ta.innerHTML=text;
    objii.appendChild(ta);
    
    HelpWindowObj=obj;
    HelpWindowCall=me;
	return false;
}
function HideHelp(){
	if (HelpWindowObj){
		document.body.removeChild(HelpWindowObj);
		HelpWindowObj=null;
		HelpWindowCall=null;
	}
}













function nozeros(input) {
		return input;
		if((input.length > 1) && (input.substr(0,1) == "0")) {
			return input.substr(1);
		} else {
			return input;
		}
	}
	function unixtimetodate(time) {
		var theDate = new Date(time*1000);
		if(theDate.toLocaleString)
			return theDate.toLocaleString();
		return theDate.toGMTString();
	}
	function datetounixtime() {
		var humDate = new Date(Date.UTC(document.date2unixtime.vyy.value, (nozeros(document.date2unixtime.vmm.value)-1),
          nozeros(document.date2unixtime.vdd.value), nozeros(document.date2unixtime.vhh.value),
          nozeros(document.date2unixtime.vmin.value), nozeros(document.date2unixtime.vsec.value)));
		document.date2unixtime.output.value = (humDate.getTime()/1000.0);
	}

function popup(URL,w,h){
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '_blank', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left = 320,top = 240');");
	//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left = 320,top = 240');");
}

function AddEvent(obj,etype,fn){
	if (!obj) obj=document;
	if(window.opera && (obj == window)) obj = document;
	
	if(document.addEventListener)   
         obj.addEventListener(etype, fn, false);
	else
         obj.attachEvent('on' + etype, fn);
}

function RemoveEvent(obj,etype,fn){
	if (!obj) obj=document;
	if(window.opera && (obj == window)) obj = document;
	
	if(document.removeEventListener)
        obj.removeEventListener(etype, fn, false);
    else
		obj.detachEvent('on' + etype, fn);
}

function SrcFromEvent(e){
	if(!e) return null;
	if (navigator.appName == "Microsoft Internet Explorer" && e.srcElement) {
      return e.srcElement;
  } else if(e.target) {  // is mozilla/netscape
      // need to crawl up the tree to get the first "real" element
      // i.e. a tag, not raw text
      var o = e.target;
      while (!o.tagName) {
          o = o.parentNode;
      }
      return o;
  }
  return e;
}

//stejna sirka floatujicich elementu:
//pro prvky volej DoSameAdd s vymyslenym stejnym id a objektem
//uzavri zavolanim DoSameGo s onym id
//vsechny prvky pridane pres Add budou mit sirku jako nejsirsi
//element pridany pres Add

  var DoSame = new Array();
  
  function DoSameAdd(id,obj){
    if (!DoSame[id])
      DoSame[id]=new Array();
    DoSame[id].push(obj);
  }
  
  function DoSameGo(id){
    var max=0;
    for(var i in DoSame[id])
      if (DoSame[id][i].offsetWidth>max)
        max=DoSame[id][i].offsetWidth;
    for(var i in DoSame[id])
      DoSame[id][i].style.width=max+"px";
  }
  
  
//BGPROCESS support

function BGPStart(caption,m1,pb1,m2,pb2,m3){
  var bgp = getId('progresswindow');
  SetDisplaying(bgp,true);
  if (!caption) caption='';
  if (!m1) m1='';
  if (!m2) m2='';
  if (!m3) m3='';
  if (!pb1) pb1=-1;
  if (!pb2) pb2=-1;
  BGPSetC(caption);
  BGPSetM1(m1);
  BGPSetM2(m2);
  BGPSetM3(m3);
  BGPSetP1(pb1);
  BGPSetP2(pb2);

  SetDisplaying("windowdisabler",true);
  getId("windowdisabler").style.width=GetPageWidth()+"px";
  getId("windowdisabler").style.height=GetPageHeight()+"px";
}

function GetPageWidth(){
    return (!document.body.scrollWidth)?document.width:document.body.scrollWidth;
}
function GetPageHeight(){
    return (!document.body.scrollHeight)?document.height:document.body.scrollHeight;
}


function BGPSetProgressBar(val,id){
    var obj = getId("progresswindow_p"+id);
    var barobj = getElementByClassName(obj, '*', 'bar');
    var textobj = getElementByClassName(obj, '*', 'text');
    if ((val<-1)||(val>100)) val=-1;
    SetDisplaying(obj,val!=-1);
    barobj.style.width=obj.offsetWidth*val/100+"px";
    textobj.innerHTML=val+"%";
}
			    
function BGPSetC(x){  getId('progresswindow_c').innerHTML=x; }

function BGPSetM1(x){  getId('progresswindow_m1').innerHTML=x; }
function BGPSetM2(x){  getId('progresswindow_m2').innerHTML=x; }
function BGPSetM3(x){  getId('progresswindow_m3').innerHTML=x; }

function BGPSetP1(x){ BGPSetProgressBar(x,1) }
function BGPSetP2(x){ BGPSetProgressBar(x,2) } 



/*************druhy adminbar, example viz watermark****************/
  
  function SASetActive(id){
    var spage = getId('spage'+id);
    var abutton = getId('ab'+id);
    
    //disable all
    i= (getId('spage0')) ? 0 : 1;//cislovani od 0 ci od 1
    
    var tmp;
    while (tmp=getId('spage'+i)){
      if (tmp!=spage){
        SetDisplaying(tmp, false);
        getId('ab'+i).className="button";
      }
      i++;
    }
    //activate 
    SetDisplaying(spage, true);
    abutton.className="button buttonActive";
    
    return false;
  }

/*************** BigImageView ******************/
/**
 * zobrazi obrazek na sedem pozadi pres celou pbrazovku
 **/ 
function BigImageView(idframe,srcframe){
	var objMain=document.createElement("div");
	objMain.id = idframe;
	objMain.style.width=GetPageWidth()+'px';
	objMain.style.height=GetPageHeight()+'px';
	objMain.style.position='absolute';
	objMain.style.left='0';
	objMain.style.top='0';
	objMain.style.zIndex=1000;
	
	AddEvent(objMain,'click',BigImageViewEventClose);
	
	var objIn = document.createElement("div");
	objIn.id = idframe+'INNER';
	objIn.style.position='absolute';
	objIn.style.left='0';
	objIn.style.top='0';
	objIn.style.zIndex=1010;
	objIn.style.width=GetPageWidth()+'px';
	objIn.style.height=GetPageHeight()+'px';
	objIn.style.backgroundImage="url('"+srcframe+"')";
	document.body.appendChild(objIn);
	
	AddEvent(objIn,'click',BigImageViewEventClose);
	
	if(document.all){
		var selects=getElementsByClassName(null,'SELECT','*');
		for(var i in selects){
			SetVisibility(selects[i],false);
		}
	}
	
	document.body.appendChild(objMain);
	return false;
}

function BigImageViewEventClose(e){
	var obj=SrcFromEvent(e);	
	if(obj){
		var obj2 = null;
		if(obj.id.indexOf('INNER')>0){
			obj2=getId(obj.id.substring(0,obj.id.indexOf('INNER')));
		}else 
			obj2=getId(obj.id+'INNER');
		obj.parentNode.removeChild(obj);
		if(obj2)
			obj2.parentNode.removeChild(obj2);
	}
	if(document.all){
		var selects=getElementsByClassName(null,'SELECT','*');
		for(var i in selects){
			SetVisibility(selects[i],true);
		}
	}
}

/**
 * Trida slouzi pro zmenu kursoru nad jakymkoliv objektem po najeti.
 * img - obrazek kursoru
 * w,h - rozmery obrazku s kursorem
 * x,y - pozice v obrazku, ktera bude na pozici mysi 
 **/ 
function CustomCursor(parent,img,w,h,x,y){
	var elThis = this;
	this.objCursor = document.createElement('div');
	this.objCursor.className='custom-cursor';
	this.objCursor.style.position='absolute';
	this.objCursor.style.zIndex='2000';
	if(document.all && document.getElementById && !window.opera){
		this.objCursor.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='crop');";
	}else{
		this.objCursor.style.backgroundImage='url('+img+')';
	}
	this.objCursor.style.width=w+'px';
	this.objCursor.style.height=h+'px';
	this.objCursor.style.display='none';
	this.objCursor.style.left='0';
	this.objCursor.style.top='0';
	
	this.x = x;
	this.y = y;
	
	if(!parent) return false;
	parent.appendChild(this.objCursor);
	parent.style.position='relative';
	this.parent=parent;
	
	this.SetPos = function(x,y){
		elThis.objCursor.style.left=x-findPosX(elThis.parent)-elThis.x+'px';
		elThis.objCursor.style.top=y-findPosY(elThis.parent)-elThis.y+'px';
	}
	
	this.overObj = null;
	this.Over = function(e){
		elThis.overObj = SrcFromEvent(e);
		if(elThis.overObj.tagName.toLowerCase()!='a') 
			elThis.overObj=elThis.overObj.parentNode;
		
		
		e = e || window.event || {};
		x=e.clientX ? e.clientX+document.documentElement.scrollLeft : e.pageX;
		y=e.clientY ? e.clientY+document.documentElement.scrollTop : e.pageY;
		if ((!x)||(!y)) return;
		
		elThis.SetPos(x,y);
		
		SetDisplaying(elThis.objCursor,true);
	}
	
	this.Move = function(e){
		e = e || window.event || {};
		x=e.clientX ? e.clientX+document.documentElement.scrollLeft : e.pageX;
		y=e.clientY ? e.clientY+document.documentElement.scrollTop : e.pageY;
		if ((!x)||(!y)) return;
		
		elThis.SetPos(x,y);
	}
	
	this.Out = function(e){
		SetDisplaying(elThis.objCursor,false);
		elThis.overObj=false;				
	}
	
	this.parentClick = function(e){
		//alert(elThis.overObj);
		//if(elThis.overObj)
		//	elThis.overObj.click();
	}
	
	this.cursorClick = function(e){
		alert(elThis.overObj);
		if(elThis.overObj)
			elThis.overObj.click();
	}
	
	this.Add = function(obj){
		if(!obj) return;
		AddEvent(obj,'mouseover',this.Over);
		//AddEvent(obj,'mousemove',this.Move);
		AddEvent(obj,'mouseout',this.Out);
	}	
	AddEvent(this.objCursor,'mousemove',this.Move);
	AddEvent(this.parent,'mousemove',this.Move);		
	//AddEvent(this.parent,'click',this.parentClick);
	//AddEvent(this.objCursor,'click',this.cursorClick);
}

function findWidth (object){ 
    if (isString(object)) object=getId(object);        
    if(object.offsetWidth) return object.offsetWidth; 
    if(object.clip && object.clip.width) return object.clip.width; 
    return (null); 
}

function findHeight (object){ 
    if (isString(object)) object=getId(object);
    if(object.offsetHeight) return object.offsetHeight; 
    if(object.clip && object.clip.height) return object.clip.height;
		return (null);  
} 

