var actualPic = 1; // ktory obrazek jest pokazywany w oknie powiekszenia

function changeBg (obiekt, typ) {
	//obiekt.style.background = url('/images/bg_menu_'+type+'.gif'); // backgroundColor
	document.getElementById(obiekt).style.backgroundImage = 'url(/images/bg_menu_'+typ+'.gif)';
}

// Ustawia warstwe wycentrowana w poziomie i z okreslona odlegloscia od gory
function setDivPosition(oName, obWidth, obHeight, posY) {
	if (!document.getElementById(oName)) {
		return 0;
	}
	if (!posY) {
		posY=0;
	}
	var obj = document.getElementById(oName);
	if (self.innerWidth) {
		frameWidth = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		frameWidth = document.documentElement.clientWidth;
	} else if (document.body) {
		frameWidth = document.body.clientWidth;
	}
	obj.style.left = ((frameWidth/2) - (obWidth/2)) + 'px';
	obj.style.top = posY + 'px';
	obj.style.width = obWidth+'px';
	obj.style.height = obHeight+'px';
}


function setDivPositionXY(oName, obWidth, obHeight, show, offsetX, offsetY) {
	if (!document.getElementById(oName)) {
		return 0;
	}
	if (!offsetX) {
		offsetX=0;
	}
	if (!offsetY) {
		offsetY=0;
	}
	vcBoxID = oName;
	var obj = document.getElementById(oName);
	if (self.innerWidth) {
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	obj.style.left = ((frameWidth/2) - (obWidth/2) + offsetX) + 'px';
	obj.style.top = ((frameHeight/2) - (obHeight/2) + offsetY) + 'px';
	obj.style.width = obWidth;
	obj.style.height = obHeight;
	if (show) {
		obj.style.display = "block";
	} else {
		obj.style.display = "none";
	}
} 


function zoom(pc_imageType, pc_imageName, pn_imageNr, pn_imageCount) {
	if (pn_imageNr=='prev') {
		actualPic = parseInt(actualPic)-1;
		if (actualPic<=0) {
			actualPic = parseInt(pn_imageCount);
		}
	} else if (pn_imageNr=='next') {
		actualPic = parseInt(actualPic)+1;
		if (actualPic>pn_imageCount) {
			actualPic=1
		}
	} else {
		actualPic = pn_imageNr;
	}
	setDivPosition('zoomPicDiv', parseInt(700+26), 480, 10);
	Element.show('zoomPicDiv');
	$('zoomPicContent').innerHTML = '<table width="700" height="404"><tr><td valign="middle" align="center"><a href="javascript:void(null);" onclick="$(\'zoomPicDiv\').style.display=\'none\';"><img src="/images/katalog/card_'+pc_imageType+'_big_'+pc_imageName+'_'+actualPic+'.jpg" border="0" alt=""></a></td></tr></table>';
	Element.show('zoomPicContent');
}

function showImage(pc_imageName, pn_width, pn_height) {
	setDivPosition('imageDiv', parseInt(parseInt(pn_width)+26), parseInt(parseInt(pn_height)+46), 10);
	$('imageDivContent').style.width = pn_width+'px';
	$('imageDivContent').style.height = pn_height+'px';
	Element.show('imageDiv');
	$('imageDivContent').innerHTML = '<a href="javascript:void(null);" onclick="$(\'imageDiv\').style.display=\'none\';"><img src="'+pc_imageName+'" border="0" alt=""></a>';
	Element.show('imageDivContent');
}

function changSubMenu(pc_object, nr) {
	if (pc_object=='group') {
		for (a=0;a<3;a++) {
			$(pc_object+a).style.display = 'none';
		}
	}
	if (pc_object=='type') {
		for (a=0;a<5;a++) {
			$(pc_object+a).style.display = 'none';
		}
	}
	if (nr>=0) {
		$(pc_object+nr).style.display = 'block';
	}
}

function setMidImage(pc_imageType, pc_imageName, pn_imageNr, pn_height, pn_imageCount, pc_enlargeStr) {
	$('midImage').innerHTML = '<a href="javascript:zoom(\''+pc_imageType+'\',\''+pc_imageName+'\',\''+pn_imageNr+'\',\''+pn_imageCount+'\')"><img src="/images/katalog/card_'+pc_imageType+'_mid_'+pc_imageName+'_'+pn_imageNr+'.jpg" width="400" height="'+pn_height+'" border="0" alt="'+pc_enlargeStr+'"></a>';
	actualPic = pn_imageNr;
}

// na stronie dystrybucja - zmiana pokazywanego wojewodztwa
function showRegion(region) {
	$(actualRegion).style.display = 'none';
	$(region).style.display = 'block';
	actualRegion = region;
}

// Powiekszanie obrazkow. Pochodzi od poprzedniego tworcy strony. Dziala w starych aktualnosciach.
function powieksz(image, w, h) {
	popup = window.open('', "Image", "width=" + w + ", height=" + h + ", toolbar=0,location=0,directories=0,scrollbars=0,status=0,menubar=0,resizable=0,top=0,left="+parseInt((screen.width-parseInt(w))/2));
	popup.document.write('<html><head></head><body style="margin:0px; padding:0px;"><a href="#" onclick="window.close();"><img src="'+image+'" border="0" alt=""></a></body></html>');
	popup.document.close();
}

// wykonuje sie po kliknieciu w button SZUKAJ w formularzu wyszukiwania w wyszukiwarka.php - nie dopuszcza do submita niepoprawnych opcji
function textSubmit() {
  if (document.searchForm.searchText.value.length>0) {
	  document.searchForm.submit();
	  return true;
  }
  return false;
}
