isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

function switchDiv(divId, type)
{
	if (isNS4) {
		objElement = document.layers[divId];
		display = objElement.visibility;
	} else if (isIE4) {
		objElement = document.all[divId].style;
		display = objElement.visibility;
	} else if (isIE5 || isNS6) {
		objElement = document.getElementById(divId).style;
		display = objElement.display;
	}
	if (display == "hidden" || display == "none") {
		if (isNS4 || isIE4) {
			objElement.visibility = "visible";
		} else {
			objElement.display = type;
		}
	} else {
		if (isNS4 || isIE4) {
			objElement.visibility = "hidden";
		} else {
			objElement.display = "none";
		}
	}
}

function copyPayData(form)
{
	form.elements['companyAddressName'].value = form.elements['companyName'].value;
	form.elements['companyAddressStreet'].value = form.elements['companyStreet'].value;
	form.elements['companyAddressCity'].value = form.elements['companyCity'].value;
	form.elements['companyAddressCityCode'].value = form.elements['companyCityCode'].value;
}

function switchImage(x, id)
{
	document.getElementById('big-image').src = x.getElementsByTagName('img')[0].src.replace(/\/mini\//, '/small/');
	document.getElementById('previewPhotoId').value = id;
	return false;
}

function CCopy(id)
{
	window.clipboardData.setData('Text', document.getElementById(id).value);
}

function searchBox() {
	var runServiceNews = ( document.getElementById('searchServiceNews').checked ) ? true : false;
	var runServiceCatalog = ( document.getElementById('searchServiceCatalog').checked ) ? true : false;
	var runServiceAdvments = ( document.getElementById('searchServiceAdvments').checked ) ? true : false;

	var key = document.getElementById('searchKey').value;

	if (!runServiceAdvments && !runServiceNews && !runServiceCatalog) {
		alert('Przynajmniej jedna wyszukiwarka musi być określona!');

		return false;
	}
	if (key.length == 0 || key.length < 3) {
		alert('Słowa kluczowe muszą się składać z minimum 3 znaków.');

		return false;
	}
	if (runServiceNews) {
		document.location.href = '/aktualnosci/archiwum?archiveProceed=1&key=' + key + '&categoryId=0&dateAfter=&dateBefore=#starter';
	}
	if (runServiceCatalog) {
		if (runServiceNews) {
			windowServiceCatalogObjectReference = window.open('http://www.podkarpacie24.pl/katalog_firm/szukaj?searchProceed=1&key=' + key + '&categoryId=0&districId=0&city=#starter');
		} else {
			document.location.href = '/katalog_firm/szukaj?searchProceed=1&key=' + key + '&categoryId=0&districId=0&city=#starter';
		}
	}
	if (runServiceAdvments) {
		if (runServiceNews || runServiceCatalog) {
			windowServiceAdvmentsObjectReference = window.open('http://www.podkarpacie24.pl/ogloszenia/szukaj?searchProceed=1&userId=0&inBody=0&newItems=0&oldItems=0&withPhotoOnly=0&key=' + key + '&without=&districId=0&catId=0&priceFrom=&priceTo=&dateAdded=0&type=0#starter');
		} else {
			document.location.href = '/ogloszenia/szukaj?searchProceed=1&userId=0&inBody=0&newItems=0&oldItems=0&withPhotoOnly=0&key=' + key + '&without=&districId=0&catId=0&priceFrom=&priceTo=&dateAdded=0&type=0#starter';
		}
	}
	return false;
}

function formLoader() {
	var hg = document.getElementById('hourglass');
	var rel_x = (document.body.clientWidth - 300)/ 2;
	var rel_y = 0;
	hg.style.left = rel_x + 'px';
	hg.style.top = window.pageYOffset + 300 + 'px';
	hg.style.display = 'block';
	return true;
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function layer(x)
{
	with(document.getElementById("c"+x))
	{
		className = (className == "hide") ? "" : "hide";
	}
	x = (x == 1) ? 2 : 1;
	document.getElementById("c"+x).className = "hide";
	return false;
}

function categorySelector(URL, cat_id, id) {
	eval("catPopup" + id + " = window.open(URL + '&cat_id=' + cat_id, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,width=650,height=130');");
	return false;
}

function popupContent(URL, ident) {
	eval("popup" + ident + " = window.open(URL, '" + ident + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,width=400,height=300');");
	return false;
}

var temp=self.location.href.split("?");
var picUrl = (temp.length>1)?temp[1]:"";
var NS = (navigator.appName=="Netscape")?true:false;

function fitPic() {
	iWidth = (NS)?window.innerWidth:document.body.clientWidth;
	iHeight = (NS)?window.innerHeight:document.body.clientHeight;
	iWidth = document.images[0].width - iWidth;
	iHeight = document.images[0].height - iHeight;
	window.resizeBy(iWidth, iHeight-1);
	self.focus();
};

noweOkienko = null;
function popup(src, w, h, title, desc){
w_ok=w+20;
h_ok=h+20;
if(window.screen){
 aw=screen.availWidth;
 ah=screen.availHeight-30;
}else{
 aw=640;
 ah=530;
}
if(w_ok>aw){w_ok=aw;}
if(h_ok>ah){h_ok=ah;}
if(noweOkienko==null || noweOkienko.closed){
 ustawienia=
 "left=" + (aw-w_ok)/2 + ","
 +"top=" + (ah-h_ok)/2 + ","
 +"screenX=" + (aw-w_ok)/2 + ","
 +"screenY=" + (ah-h_ok)/2 + ","
 +"width=" + w_ok + ","
 +"height=" + h_ok +  ","
 +"innerWidth=" + w_ok  + ","
 +"innerHeight=" + h_ok + ","
 +"toolbar=no,"
 +"location=no,"
 +"directories=no,"
 +"status=no,"
 +"menubar=no,"
 +"scrollbars=yes,"
 +"resizable=no"
 noweOkienko = window.open("",'obrazek',ustawienia);
}
noweOkienko.document.open();
noweOkienko.document.clear();
noweOkienko.document.write(
"<html><head><title>"+title+"</title>\n"
+"<script language='javascript'>\n"
+"var temp=self.location.href.split('?');\n"
+"var picUrl = (temp.length>1)?temp[1]:'';\n"
+"var NS = (navigator.appName=='Netscape')?true:false;\n"
+"function fitPic() {\n"
+"iWidth = (NS)?window.innerWidth:document.body.clientWidth;\n"
+"iHeight = (NS)?window.innerHeight:document.body.clientHeight;\n"
+"iWidth = document.images[0].width - iWidth;\n"
+"iHeight = document.images[0].height - iHeight;\n"
+"window.resizeBy(iWidth+20, iHeight-1+50);\n"
+"self.focus();\n"
+"};\n"
+"</script>\n"
+"</head><BODY onload='fitPic()' bgcolor=#FFFFFF leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>\n"
+"<TABLE height=100% width=100% border=0 cellspacing=0 cellpadding=0 align=center>  <TR> <TD align=center valign=middle>   <a href='javascript:window.close()'><img src="+src +" border=0></a><br /><span style='font-family: Arial, Sans Serif; font-size: 12px;'>"+desc +"</span></div> </TD>  </TR> </TABLE>\n"
+"</body></html>");
noweOkienko.document.close();
noweOkienko.focus();
}