//file
function file_getExtension(fileN) {
	var lastPos; var pos;
	pos=fileN.indexOf(".");
	lastPos=pos;
	
	while (pos != -1) {   
		pos=fileN.indexOf(".",pos+1);
		if (pos != -1) lastPos = pos;
	}
	return fileN.substring(lastPos + 1);
}

//image
ns6 = (document.getElementById)?true:false;
ns4 = (document.layers)?true:false;
ie4 = (document.all)?true:false;

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	var preloadFlag = true;
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function hideDiv(divName) {
	if (ns4) document.layers[divName].visibility = "hide";
	else if (ns6) document.getElementById(divName).style.visibility = "hidden";
	else if (ie4) document.all[divName].style.visibility = "hidden";
}

function showDiv(divName) {
    if (ns4) document.layers[divName].visibility = "show";
	else if (ns6) document.getElementById(divName).style.visibility = "visible";
	else if (ie4) document.all[divName].style.visibility = "visible";
}



//Wg. mnie tej funkcji nie powinno byc tu albo powinna byc zmieniona
//ponizej zmodyfikowana przez mnie wersja
function showProv(Prov_id,nr) {
	for(i=1;i<nr+1;i++) { 
		//hideDiv('Prov_' + i);
		hideDiv('provMap_' + i);
	}

	//showDiv('prov_' + Prov_id);
	showDiv('provMap_' + Prov_id);
}
function showProvOld(Prov_id) {
	for(i=1;i<17;i++) { 
		//hideDiv('Prov_' + i);
		hideDiv('provMap_' + i);
	}

	//showDiv('prov_' + Prov_id);
	showDiv('provMap_' + Prov_id);
}

function getSWFCode(imageFileName, imagesFolder, imageWidth, imageHeight) {
	widthCode	= ' width="'+imageWidth+'"';
	heightCode	= ' height="'+imageHeight+'"'; 

	code = "<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ";

	if (imageWidth)	 code += widthCode;
	if (imageHeight) code += heightCode;
	
	code +="><PARAM NAME=movie VALUE=\""+imagesFolder+"/" + imageFileName + "\"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF><PARAM NAME=wmode VALUE=transparent> <EMBED src=\""+imagesFolder+"/" + imageFileName + "\" quality=high wmode=transparent bgcolor=#FFFFFF ";
	
	if (imageWidth)	 code += widthCode;
	if (imageHeight) code += heightCode;

	code +="TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED></OBJECT>";
    return code;

    //return "<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" WIDTH=\""+imageWidth+"\" HEIGHT=\""+imageHeight+"\"><PARAM NAME=movie VALUE=\""+imagesFolder+"/" + imageFileName + "\"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src=\""+imagesFolder+"/" + imageFileName + "\" quality=high bgcolor=#FFFFFF WIDTH=\""+imageWidth+"\" HEIGHT=\""+imageHeight+"\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED></OBJECT>";
}

var noFlash = false;

function showImage(imageFileName, imagesFolder, imageWidth, imageHeight){
	if (imageFileName == 's.gif') {imageFileName = 's.gif';imagesFolder = '';}
	isFlash = (file_getExtension(imageFileName).toUpperCase() == 'SWF');
	if (isFlash && flashversion>=6) {
		var imgText = getSWFCode(imageFileName, imagesFolder, imageWidth, imageHeight);
	} else {
		if (isFlash) {imageFileName +='.png';noFlash = true;}

		var imgText = "<img border=0 src=\""+imagesFolder+"/" + imageFileName + "\""
		if (imageWidth)	imgText += " width=\""+imageWidth+"\"";
		if (imageHeight) imgText += " height=\""+imageHeight+"\"";
		imgText += ">";
	}
	
	
	document.write(imgText);
}


function showBigImage(imageFileName, imagesFolder, imageWidth, imageHeight,pdN,imgName ){
	//pdN = preloaderDivName czyli wzor preloadera do wykorzystania;
	if (imageFileName == 's.gif') {imageFileName = 's.gif';imagesFolder = '';}
	isFlash = (file_getExtension(imageFileName).toUpperCase() == 'SWF');
	if (isFlash && flashversion>=6) {
		var imgText = getSWFCode(imageFileName, imagesFolder, imageWidth, imageHeight);
	} else {
		if (isFlash) {imageFileName +='.png';noFlash = true;}

		var imgText = "<img border=0 src=\""+imagesFolder+"/" + imageFileName + "\" name=\"" + imgName + "\""
		if (imageWidth)	imgText += " width=\""+imageWidth+"\"";
		if (imageHeight) imgText += " height=\""+imageHeight+"\"";
		imgText += ">";
	}

	if (typeof obj_arr == 'undefined')
	{
		obj_arr = new Array();
		objP_arr = new Array();
		objImg_arr = new Array();
		objPattern = '';
	}



	//ekwiwalentna nazwa dla preloadera

	pre="pre_" + imgName;
	pdNI = "i_" + imgName; 

	/**
	* Do tej warstwy kopiujê wzor preloadera
	*/
	htmlPre = '<div id="'+pre+'" style="visibility:visible;position:relative"></div>'; 
	htmlImg = '<div id="'+pdNI+'" style="visibility:hidden;position:absolute;top:-1000">'+imgText+'</div>';

	imgText=htmlPre+htmlImg;

	document.write(imgText);

	if (document.all){
		obj_arr[imgName] = document.all[pdNI];
		objP_arr[imgName] = document.all[pre];
		objImg_arr[imgName] = document.all[imgName];
		objPattern = document.all[pdN];
	}
	if (document.getElementById){
		obj_arr[imgName] = document.getElementById(pdNI);
		objP_arr[imgName]  = document.getElementById(pre);		
		objImg_arr[imgName]  = document.getElementsByName(imgName)[0];		
		objPattern = document.getElementById(pdN);
	}

	/**
	* HTML z objPattern(wzorzec preloadera) przekopiowuje do objP czyli do umiejscowionego preloadera
	*/
	//objP.innerHTML = objPattern.innerHTML;

	objP_arr[imgName].innerHTML = objPattern.innerHTML;
	obj_arr[imgName].style.width=imageWidth;
	obj_arr[imgName].style.height=imageHeight;
	objP_arr[imgName].style.width=imageWidth;
	objP_arr[imgName].style.height=imageHeight;

	Preloader(imgName);
}

function Preloader(imgName){
	if (!objImg_arr[imgName].complete) {
        setTimeout("Preloader('"+imgName+"')",50);
	}else{
		objP_arr[imgName].innerHTML =obj_arr[imgName].innerHTML;
	}
}

//losowanie indeksu z tablicy
function getRandIndex(arr){
	return Math.round(Math.random()*(arr.length-1));
}

function getRandomNumber(m, n) {
    return Math.floor(Math.random() * (n-m+1)) + m;
}


function showRandomImage(imageFileNames, imageWidth, imageHeight){
	iFNL = imageFileNames.length;
	imagesFolder = imageFileNames[iFNL-1];
	f = getRandomNumber(0,(iFNL - 2));
	showImage(imageFileNames[f], imagesFolder, imageWidth, imageHeight);
}


function showRandomBigImage(imageFileNames, imagesFolder,  imageWidth, imageHeight, pdN,imgName){
	//pdN = preloaderDivName czyli wzor preloadera do wykorzystania;
	iFNL = imageFileNames.length;
	imagesFolder = imageFileNames[iFNL-1];
	f = getRandomNumber(0,(iFNL - 2));
	showBigImage(imageFileNames[f], imagesFolder, imageWidth, imageHeight,pdN,imgName )
}


//email
function writeEmail(email_mailbox, email_host, email_show, email_class) 
{
	// protected email script by Joe Maller
	// JavaScripts available at http://www.joemaller.com
	// this script is free to use and distribute
	// but please credit me and/or link to my site
	// Function created by Michal Borychowski
	emailE=(email_mailbox + '@' + email_host);
	if (!email_show) email_show = emailE;
	if (email_class) email_class = ' class="'+email_class+'"'
	else email_class = '';
	document.write('<a' + email_class + ' href="mailto:' + emailE + '">' + email_show + '</a>');
}

function writeSetHomePage(domain, addText) {
	var browserName=navigator.appName; 

	if (browserName=="Netscape") { 

	}
	else if (browserName=="Microsoft Internet Explorer") {
		var version = navigator.appVersion; 
		if (version.indexOf("5.") >= 0 || version.indexOf("6.") >= 0) {
			document.write("<a href=# onClick=\"this.style.behavior='url(#default#homepage)'; this.setHomePage('"+domain+"')\" style=\"text-decoration: none\">"+addText+"</a>");
		}
		else {		 
		}		
	}
	else {		
	}
}

function writeAddFovorites(domain, name, addText) {
	var browserName=navigator.appName; 

	if (browserName=="Netscape") { 

	}
	else if (browserName=="Microsoft Internet Explorer") {
		var version = navigator.appVersion; 
		document.write("<a href=# onClick=\"window.external.AddFavorite('"+domain+"', '"+name+"')\">"+addText+"</a>");
	}
	else {
		
	}
}

function allPagedDDMonClick() {
	document.all.linkType[0].checked=true;
}

function closeWindow() {
    self.close();
	if (window.opener) window.opener.focus();
}

function setCookie(cookieName,cookieValue,nDays) {
	//alert("kuki set");
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	if(nDays>0)
	{
		expire.setTime(today.getTime() + 3600000*24*nDays);
		document.cookie = cookieName+"="+escape(cookieValue)
					+ ";expires="+expire.toGMTString();
	}
	else
		document.cookie = cookieName+"="+escape(cookieValue);
}

function readCookie(cookieName) {
	//alert("kuki read");
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


function df_getDivById(id){
	return (document.all)?document.all[id]:document.getElementById(id);
}