﻿function DivChanger(divContainerId)
{
  var currentDiv = 0;
  var divs = new Array();

  if(window.document.getElementById)
  {
    var divContainer = window.document.getElementById(divContainerId);

    if(divContainer && divContainer.firstChild)
    {
      var div = divContainer.firstChild;
      do
      {
        if(div.nodeName == divContainer.nodeName)
        {
          divs[divs.length] = div;
        }
        div = div.nextSibling;
      }while(div);
    }
  }

  this.random = function ()
  {
    this.select(Math.floor(Math.random()*divs.length));
  }

  this.next = function ()
  {
    this.select(currentDiv + 1);
  }

  this.prev = function ()
  {
    this.select(currentDiv > 0 ? currentDiv - 1 : divs.length - 1);
  }

  this.select = function (x)
  {
    if(divs.length)
    {
      currentDiv = x % divs.length;

      for(var i in divs)
      {
        if(divs[i].style)
        {
          divs[i].style.display = "none";
        }
      }

      if(divs[currentDiv].style)
      {
        divs[currentDiv].style.display = "";
      }
    }
  }
}

function initialize()
{
  var windowWidth = 0, windowHeight = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  {
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  }
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
  {
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  var bodyBox = document.getElementById('bodyBox');
  if(bodyBox && bodyBox.style && bodyBox.style.width)
  {
    bodyBox.style.width = windowWidth + "px";
    bodyBox.style.height = windowHeight + "px";
  }
  
  if(windowWidth &&  windowHeight)
  {
    var bodyBox = document.getElementById('bodyBox');
    if(bodyBox && bodyBox.style && bodyBox.style.width)
    {
      bodyBox.style.width = windowWidth + 'px';
      bodyBox.style.height = windowHeight + 'px';
    }
    
    var nodeBox = document.getElementById('nodeBox');
    if(nodeBox && nodeBox.style && nodeBox.offsetHeight && nodeBox.offsetWidth)
    {
      var top = (windowHeight - nodeBox.offsetHeight) / 2;
      var left = (windowWidth - nodeBox.offsetWidth) / 2;
      nodeBox.style.position = 'absolute';
      nodeBox.style.margin = '0';
      nodeBox.style.top = top + 'px';
      nodeBox.style.left = left + 'px';
    }
  }
  window.onresize = initialize;
}


function setHistory(id, title)
{
  	var hif = document.getElementById('HIF');
  	hif.src = 'history.php?node=' + id + '&title=' + title; 
  	currentNodeId = id;
  
  	document.title = 'Odlewnia żeliwa FANSULD Końskie - ' + title;

}


function addFavorite()
{
  if (window.external) 
  {
    external.AddFavorite('http://www.17mm.pl', 'www.17mm.pl');
  }
}

function setHomePage()
{
  if(document.getElementsByTagName)
  {
    var bodyElements = document.getElementsByTagName('body');
    if(bodyElements && bodyElements.item)
    {
      var body = bodyElements.item(0);
      if(body && body.style)
      { 
        body.style.behavior='url(#default#homepage)';
        if(window.external)
        {
          body.setHomePage('http://www.17mm.pl');
        }
      }
    }
  }
}
function zamowDemo(lang)
{
	window.open("http://83.18.176.86/baza/customeradd.php?lang="+lang, "tinyWindow", "width=450,height=500");
}
function otworzPDF(plik)
{
	window.open("http://www.17mm.pl/file/"+plik, "tinyWindow", "width=800,height=600");
}

function test(arg)
{
	alert(arg);
}

function fdetect(version){
	var verNum = Number(version.charAt(4));
	if(verNum<8){
		if (confirm("Aby oglądać tę stronę potrzebny jest plugin Flash w wersji 8.\n"+(verNum ? "W Twoim systemie zainstalowana jest wersja "+verNum : "W Twoim systemie nie wykryto plugina")+"\n\nKliknij \"OK\" aby przejść na stronę Adobe i pobrać za darmo najnowszą wersję plugina Flash lub \"Anuluj\" aby kontynuować")) {
			location.href = "http://www.adobe.com/go/getflashplayer";
		}
	}
}

