/*
CMS 2.0 default javascript functions
Autor: Tibor Stiblar, www.tibiz.net
Rozsirovaie alebo upravovanie programoveho kodu bez suhlasu autora je protipravne.
*/

var strNews = '--- scrollable text ---';
function scrollText(elementId) 
{
    var l = strNews.length;
    var a = strNews.substring(0, 1);
    strNews = strNews.substring(1, l)+a;
    document.getElementById(''+elementId).innerHTML = ''+strNews;
}

function GetStyle(el, styl) {
  if (el.currentStyle) return parseInt(el.currentStyle[styl.replace(/-/g,'')]);
  return parseInt(document.defaultView.getComputedStyle(el,null).getPropertyValue(styl.toLowerCase()));
}

function SetElementSource(elementId, picname)
{
  	o=document.getElementById(elementId);
  	if(o != null) o.src=""+picname;
}

function SetElementBgImage(elementId, picname)
{
  	o=document.getElementById(elementId);
  	if(o != null) o.style.backgroundImage='url('+picname+')';
}

function ConfirmNewLocation(alertText, httpLocation)
{
  if(confirm(alertText)) 
      document.location=httpLocation;
}

function ShowJsElement(elementId)
{
	o=document.getElementById(elementId);
	if(o != null) o.style.display="block";
}

function HideJsElement(elementId)
{
	o=document.getElementById(elementId);
	if(o != null) o.style.display="none";
}

function ShowHideJsElement(elementId)
{
	o=document.getElementById(elementId);
	if(o != null) {
      if(o.style.display!='block') o.style.display="block";
      else o.style.display="none";
  }
}

var lastgroup=0;
function SwitchElementGroup(elementBaseId, idFrom, idTo, idShow)
{
  lastgroup=idShow;
  for(i=idFrom;i<idTo;i++) {
    	o=document.getElementById(elementBaseId+i);
    	if(o != null) o.style.display="none";
  }
	o=document.getElementById(elementBaseId+idShow);
	if(o != null) o.style.display="block";
}
function SwitchElementSubGroup(elementBaseId, idFrom, idTo, idShow)
{
  for(i=idFrom;i<idTo;i++) {
    	o=document.getElementById(elementBaseId+i+lastgroup);
    	if(o != null) o.style.display="none";
  }
	o=document.getElementById(elementBaseId+idShow+lastgroup);
	if(o != null) o.style.display="block";
}

function SetElementTextColor(elementId, color)
{
	o=document.getElementById(elementId);
	if(o != null) o.style.color=""+color;
}

function SetElementBorderColor(elementId, color)
{
	o=document.getElementById(elementId);
	if(o != null) o.style.borderColor=""+color;
}

function SetElementBgColor(elementId, color)
{
	o=document.getElementById(elementId);
	if(o != null) o.style.backgroundColor=""+color;
}

function doIframe()
{
	o = document.getElementById('shopframe');
	if(o != null) {
  	if(o.contentDocument) if(o.contentDocument.body) if(o.contentDocument.body.offsetHeight) o.style.height = o.contentDocument.body.offsetHeight+35+'px';
    else if(o.contentWindow) if(o.contentWindow.document) if(o.contentWindow.document.body) if(o.contentWindow.document.body.scrollHeight) o.style.height = o.contentWindow.document.body.scrollHeight+'px';
	}
}
function adaptIframe()
{
  if(document.getElementById) setInterval('doIframe()', 300);
}

function StretchBox(io)
{
	o = document.getElementById('langselectorwindow');
	if(o != null) {
	   l = GetStyle(o, 'left');
	   t = GetStyle(o, 'top');
	   w = GetStyle(o, 'width');
	   h = GetStyle(o, 'height');
	   l-=io*20;
	   t-=io*6;
	   w+=io*40;
	   h+=io*12;

     if(w < 1) {
       w=h=1;
       o.style.display='none';
     }
     else if(w > 0 && w < 400) { 	   
  	   o.style.display='block';
  	   o.style.left=l+'px';
  	   o.style.top= t+'px';
  	   o.style.width= w+'px';
  	   o.style.height=h+'px';
  	   setTimeout("StretchBox("+io+")", 10);
	   }
	}
}
function StretchWorldLangSelector(elementId)
{
  StretchBox(-5);
  
  o = document.getElementById(elementId);
  wls = document.getElementById('langselectorwindow');
  wls.innerHTML = o.innerHTML;
  
  StretchBox(1);
}

var slideshowimages;
var slideshowstarted=false;
function SlideshowKeyChecker(e)
{
   var KeyID = (window.event) ? event.keyCode : e.keyCode;
   switch(KeyID) {
        case 37: // left
            SlideshowShowScroll(-1);
            break;
        case 39: // right
            SlideshowShowScroll(1);
            break;
        case 27: // esc
            SlideshowClose();
            break;
   }
}
function SlideshowAdaptSize()
{
   img=document.getElementById('slideshowwindowimgage');
   if(img != null) {
       img.style.height='auto';
       
       h = (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
       height=img.clientHeight;
       if(height > h-100) { 
            height=h-100;
            img.style.height=height+'px'; 
       }
    }
}
function SlideshowShow(bitmapname)
{
  document.onkeyup = SlideshowKeyChecker;
  slideshowstarted=false;
	o = document.getElementById('slideshowwindow');
	if(o != null) {
	   h = (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
	   o.style.height=h+'px';
	   o.style.display='block';
	   SetElementSource('slideshowwindowimgage', bitmapname);
	   SlideshowAdaptSize();
	}
}
function SlideshowClose()
{
    document.onkeyup = null;
    slideshowstarted=false;
	o = document.getElementById('slideshowwindow');
	if(o != null) {
	   o.style.display='none';
	}
}
function SlideshowShowScroll(left_right)
{
   l = slideshowimages.length;
   if(l < 1) return;
   
   o = document.getElementById('slideshowwindowimgage');
   if(o == null) return;
   
   for(j=o.src.length-1;j>=0;j--) if(o.src.charAt(j) == '/') break;
   subsrc = o.src.substring(j+1, o.src.length);
   
   test=false;
   
   if(left_right == -1) {
      for(i=0;i<l-1;i++) {
          for(j=slideshowimages[i+1].length-1;j>=0;j--) if(slideshowimages[i+1].charAt(j) == '/') break;
          subim = slideshowimages[i+1].substring(j+1, slideshowimages[i+1].length);
          subim = escape(subim);
          if(subim == subsrc) {
              SetElementSource('slideshowwindowimgage', slideshowimages[i]);
              SlideshowAdaptSize();
              test=true;
              break;
          }
      }
      if(!test) SetElementSource('slideshowwindowimgage', slideshowimages[l-1]);
   }
   if(left_right == 1) { 
      for(i=1;i<l;i++) {
          for(j=slideshowimages[i-1].length-1;j>=0;j--) if(slideshowimages[i-1].charAt(j) == '/') break;
          subim = slideshowimages[i-1].substring(j+1, slideshowimages[i-1].length);
          subim = escape(subim);
          if(subim == subsrc) {
              SetElementSource('slideshowwindowimgage', slideshowimages[i]);
              SlideshowAdaptSize();
              test=true;
              break;
          }
      }
      if(!test) SetElementSource('slideshowwindowimgage', slideshowimages[0]);
   }
   
   if(slideshowstarted) setTimeout("SlideshowShowScroll("+left_right+")", 3700);
}
function SlideshowStartStop()
{
    if(!slideshowstarted) {
        slideshowstarted=true;
        setTimeout("SlideshowShowScroll(1)", 1000);
    }
    else {
        slideshowstarted=false;
    }
}
 
function testField(field) {
    var regExpr = new RegExp("^\d*\.?\d*$");
    if (!regExpr.test(field.value)) {
      // Case of error
      field.value = "";
    }
}
