function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];
    
  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();
  
  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }
  
  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}
var flaga_over_submenu = 0;

function MenuMouseOver(zmId, zmImage) {
// Get ID checked menu
    zmObj = document.getElementById('idMenu');
    zmIdMenuChecked = zmObj.value;

// Hide prev SubMenu
    zmObj = document.getElementById('idSubMenu');
    if (zmObj != null)
    {
    	zmIdSubMenuOld = zmObj.value;
       zmObj = document.getElementById("div_sub"+zmIdSubMenuOld);
	if (zmObj != null)
	{
	    	zmObj.style.visibility = 'hidden';
	}
    }

// Set id SubMenu
    zmObj = document.getElementById('idSubMenu');
    zmObj.value = zmId;

// Podmien fotke
    if (zmIdMenuChecked != zmId) 
    {
       zmObj = document.getElementById(zmId);
       zmObj.src = zmImage;
    }

// Pokaz submenu
    zmIdSubMenu = "div_sub"+zmId;
    zmObj = document.getElementById(zmIdSubMenu);
    if (zmObj != null)
    {
    	zmObj.style.visibility = 'visible';
    }
}

function MenuMouseOut(zmId, zmImage) {
// Get ID checked menu
    zmObj = document.getElementById('idMenu');
    zmIdMenuChecked = zmObj.value;

/*
// Hide prev SubMenu
    zmObj = document.getElementById('idSubMenu');
    if (zmObj != null && flaga_over_submenu == 0)
    {
//	document.getElementById("debug").value = flaga_over_submenu;
    	zmIdSubMenuOld = zmObj.value;
       zmObj = document.getElementById("div_sub"+zmIdSubMenuOld);
	if (zmObj != null)
	{
	    	zmObj.style.visibility = 'hidden';
	}
    }
*/

// Podmien fotke
    if (zmIdMenuChecked != zmId) 
    {
	zmObj = document.getElementById(zmId);
	zmObj.src = zmImage;
    }
}

function MenuMouseClick(zmId, zmImage, zmUrl, zmPage) {
// Get ID checked menu
    zmObj = document.getElementById('idMenu');
    zmIdMenuChecked = zmObj.value;

/*
// Reset prev checked menu
    if (zmIdMenuChecked != zmId)
    {
	if (zmIdMenuChecked != "")
       {
          zmObj = document.getElementById(zmIdMenuChecked);
	   if (zmObj != null)
	   {
	   	   zmObj.src = document.getElementById('FotkaMenu').value;
	   }
       }
    }
*/

// Set id Menu
    if (zmIdMenuChecked != zmId)
    {
       zmObj = document.getElementById('idMenu');
       zmObj.value = zmId;
    }

// Set fotka menu
    if (zmIdMenuChecked != zmId)
    {
       zmObj = document.getElementById('FotkaMenu');
       zmObj.value = document.getElementById(zmId).src;
    }

//    zmObj.value = zmId;

// Podmien fotke
    if (zmIdMenuChecked != zmId)
    {
//       zmObj = document.getElementById(zmId);
//       zmObj.src = zmImage;
    }
   
   if (zmUrl != "")
   {
   	window.location.href=zmUrl;
   }

   if (zmPage != "")
   {
   	window.location.href=zmPage;
   }
}

function MenuFooterMouseClick(zmId, zmImage, zmUrl, zmPage) {
   if (zmUrl != "")
   {
   	window.location.href=zmUrl;
   }
}

function SubMenuMouseOver(zmId) {
flaga_over_submenu = 1;
//	document.getElementById("debug").value = flaga_over_submenu;

}

function SubMenuMouseOut(zmId) {
}

function SubMenuMouseClick(zmId) {
}

function PageMouseOver() {
// Hide prev SubMenu
    zmObj = document.getElementById('idSubMenu');
    if (zmObj != null)
    {
    	zmIdSubMenuOld = zmObj.value;
       zmObj = document.getElementById("div_sub"+zmIdSubMenuOld);
	if (zmObj != null)
	{
	    	zmObj.style.visibility = 'hidden';
	}
    }
}

function GaleriaProductMouseOver(zmId) {
    zmObj = document.getElementById(zmId);
    zmObj.style.border = "1px yellow solid";
}

function GaleriaProductMouseOut(zmId) {
    zmObj = document.getElementById(zmId);
    zmObj.style.border = "1px gray solid";
}

function GaleriaProductMouseClick(zmId, zmProdukt, zmCount) {
//    zmObj = document.getElementById(zmId);
//    zmObj.style.backgroundColor = "yellow";
    zmUrl = window.location.href+"&"+zmProdukt+"="+zmId+"&count="+zmCount;
    zmUrl = zmUrl.replace(/table_product_/gi,"");
    zmUrl = zmUrl.replace(/&drewno=-1/gi,"");
    zmUrl = zmUrl.replace(/&korek_naturalny=-1/gi,"");
    zmUrl = zmUrl.replace(/&wnetrze_nowoczesne=-1/gi,"");
    zmUrl = zmUrl.replace(/&wnetrze_klasyczne=-1/gi,"");
    window.location.href=zmUrl;
}

function SetValue(zmId, zmValue) {
    zmObj = document.getElementById(zmId);
    zmObj.value = zmValue;
}

function GaleriaProductKorekNaturalnyReset(zmCount) {
	window.location.href="galeria.php?page=korek_naturalny&korek=-1&count="+zmCount;
}

function GaleriaProductDrewnoReset(zmCount) {
	window.location.href="galeria.php?page=drewno&drewno=-1&count="+zmCount;
}

function GaleriaProductPlytkaCeramicznaReset(zmCount) {
	window.location.href="galeria.php?page=plytka_ceramiczna&plytka_ceramiczna=-1&count="+zmCount;
}

function GaleriaProductWnetrzeKlasyczneReset(zmCount) {
	window.location.href="galeria.php?page=wnetrza_klasyczne&wnetrze_klasyczne=-1&count="+zmCount;
}

function GaleriaProductWnetrzeNowoczesneReset(zmCount) {
	window.location.href="galeria.php?page=wnetrza_nowoczesne&wnetrze_nowoczesne=-1&count="+zmCount;
}

function banCreate(zmStr){
   document.write(zmStr);
}

function RedirectWizualizacjia(){
   window.location.href="galeria.php?page=wizualizacja";
}

function SetDivsPosition(zmCount){
	containerDivId = 'divContainer_1';
	contentDivId = 'divContent_1';
	this.bwCheckObj = lib_bwcheck();
	this.containerObj = new makeObj(this.bwCheckObj, containerDivId);
	this.contentObj   = new makeObj(this.bwCheckObj, contentDivId, containerDivId);
	this.contentObj.moveIt(0, 0);
	this.containerElm = document.getElementById('divContainer_1');

	this.contentElm   = document.getElementById(contentDivId);
	var scrollableSpace = this.contentElm.offsetHeight - this.containerElm.offsetHeight;

	zmNewPos = (scrollableSpace*zmCount) / 100;
	if (zmNewPos > scrollableSpace) zmNewPos = scrollableSpace;
	this.contentObj.moveIt(0, -(zmNewPos));
	this.lastScrollTo = -(zmNewPos);
}

function GaleriaSzukaj(e, zmTxt, idPage){
	if (noNumbers(e) == 13)
	{
		window.location.href="galeria.php?page="+idPage+"&search="+zmTxt;
	}
}

function noNumbers(e)
{
	var keynum;
	var keychar;
	var numcheck;

	if(window.event) // IE
	  {
	  keynum = e.keyCode;
	  }
	else if(e.which) // Netscape/Firefox/Opera
	  {
	  keynum = e.which;
	  }
	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;
	return keynum;
}

function SubMenuMouseOver(zmId)
{
	zmObj = document.getElementById(zmId);
	zmObj.className = "submenuOver";
}

function SubMenuMouseOut(zmId)
{
	zmObj = document.getElementById(zmId);
	zmObj.className = "submenu";
}

function ButtonClick(zmId) {
    zmUrl = window.location.href+"?page="+zmId;
    window.location.href=zmUrl;
}

function GetPrzegladarka() {
var browser=navigator.appName;
var b_version=navigator.appVersion;
return browser;
}

function SzerokoscPolaOpisu() {
zmSzerokosc = "430";
if (GetPrzegladarka() == "Netscape") { zmSzerokosc = "430"; }
if (GetPrzegladarka() == "Microsoft Internet Explorer") { zmSzerokosc = "430"; }

zmObj = document.getElementById('TabelaOpis1');
zmObj.style.width = zmSzerokosc;
}

