var EditoStart = new Object();
EditoStart.functions = new Array();

EditoStart.Add = function(fnc)
{
	EditoStart.functions[EditoStart.functions.length] = fnc;
}

EditoStart.init = function()
{
	for(var i = 0; i < EditoStart.functions.length; i++)
	{
		EditoStart.functions[i]();
	}
}

function findObj(obj) {
	return document.getElementById(obj);
}

function preloadimages(images) {
	if (!images) {
		var images = new Array();
	}
	var img = new Array();
	for (i=0; i<images.length; i++) {
		img[i] = new Image();
		img[i].src = images[i];
	}
}

function swapImage(id, img) {
	o = findObj(id);
	if(o) {
		o.src = img;
	}
}

function SendTo(before, after, user, host, label) {
	label = label.replace(' // ', '@');
	document.write('<a' + before + 'href="mailto:' + user + '@' + host + '"' + after+'>' + label + '</a>');
}

// zdjêcie bez opisu
function showImage(src, w, h) {
	noweOkienko = null;
	if (window.screen) {
		aw = screen.availWidth;
		ah = screen.availHeight;
	} else {
		aw = 640;
		ah = 450;
	}
	if (noweOkienko==null || noweOkienko.closed) {
		ustawienia=
		"left=" + (aw-w)/2 + ","
		+"top=" + (ah-h)/2 + ","
		+"screenX=" + (aw-w)/2 + ","
		+"screenY=" + (ah-h)/2 + ","
		+"width=" + w + ","
		+"height=" + h + ","
		+"innerWidth=" + w + ","
		+"innerHeight=" + h + ","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=yes,"
		+"menubar=no,"
		+"scrollbars=no,"
		+"resizable=no"
		noweOkienko = window.open("/showImage.php?src="+src, 'obrazek', ustawienia);
	}
	try {
		noweOkienko.focus();
	}
	catch (e) {
	}
}

// zdjêcie z opisem
function showOImage(src, w, h, opis) {
	noweOkienko = null;
	if (window.screen) {
		aw = screen.availWidth;
		ah = screen.availHeight;
	} else {
		aw = 640;
		ah = 450;
	}
	if (noweOkienko==null || noweOkienko.closed) {
		w = w + 32;
		oldH = h;
		h = h + 45;
		ustawienia=
		"left=" + (aw-w)/2 + ","
		+"top=" + (ah-h)/2 + ","
		+"screenX=" + (aw-w)/2 + ","
		+"screenY=" + (ah-h)/2 + ","
		+"width=" + w + ","
		+"height=" + h + ","
		+"innerWidth=" + w + ","
		+"innerHeight=" + h + ","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=yes,"
		+"menubar=no,"
		+"scrollbars=yes,"
		+"resizable=no"
		noweOkienko = window.open("/showImage.php?src="+src+":"+opis, 'obrazek', ustawienia);
	}
	try {
		noweOkienko.focus();
	}
	catch (e) {
	}
}

// popup
function popUpWindow(src, w, h) {
	noweOkienko = null;
	if (window.screen) {
		aw = screen.availWidth;
		ah = screen.availHeight;
	} else {
		aw = 640;
		ah = 450;
	}
	if (noweOkienko==null || noweOkienko.closed) {
		ustawienia=
		"left=" + (aw-w)/2 + ","
		+"top=" + (ah-h)/2 + ","
		+"screenX=" + (aw-w)/2 + ","
		+"screenY=" + (ah-h)/2 + ","
		+"width=" + w + ","
		+"height=" + h + ","
		+"innerWidth=" + w + ","
		+"innerHeight=" + h + ","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=yes,"
		+"menubar=no,"
		+"scrollbars=yes,"
		+"resizable=no"
		var url = '/' + src; 
		noweOkienko = window.open(url, 'plik', ustawienia);
		
	}
	try {
		noweOkienko.focus();
	}
	catch (e) {
	}
}

// drukuj
function printWindow(src) {
	popUpWindow(src, 640, 450);
}

// base64 decode script
function decode64(input) {
	var output = "";
	var chr1, chr2, chr3 = "";
	var enc1, enc2, enc3, enc4 = "";
	var i = 0;
	var keyStr = 	"ABCDEFGHIJKLMNOP" +
					"QRSTUVWXYZabcdef" +
					"ghijklmnopqrstuv" +
					"wxyz0123456789+/" +
					"=";

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	var base64test = /[^A-Za-z0-9\+\/\=]/g;
	if (base64test.exec(input)) {
		alert("There were invalid base64 characters in the input text.\n" +
					"Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='\n" +
					"Expect errors in decoding.");
	}
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do {
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = keyStr.indexOf(input.charAt(i++));

		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;

		output = output + String.fromCharCode(chr1);

		if (enc3 != 64) {
			output = output + String.fromCharCode(chr2);
		}
		if (enc4 != 64) {
			output = output + String.fromCharCode(chr3);
		}

		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";

	} while (i < input.length);

	return output;
}

// rozwijanie listy wynikow w wyszukiwarce
function showResult(id) {
	o = document.getElementById(id);
	if (o.style.display == 'none') {
		o.style.display = 'block';
	} else {
		o.style.display = 'none';
	}
}

function limiter(obj, limit) {
	if (obj.value.length > limit) {
		obj.value = obj.value.substring(0,limit);
	}
}

// obliczanie pozostalych znakow w textarea
function limit(obj, limit, msg) {
	if (obj.value.length > limit) {
		obj.value = obj.value.substring(0,limit);
		alert(msg);
	}
}

function getCookie(name)
{
	var dc = document.cookie;
	var cname = name + "=";
	var clen = dc.length;
	var cbegin = 0;
	
	while (cbegin < clen)
	{ 
		var vbegin = cbegin + cname.length;
	
		if (dc.substring(cbegin, vbegin) == cname)
		{ 
			var vend = dc.indexOf (";", vbegin);
			if (vend == -1) vend = clen;
	
			return unescape(dc.substring(vbegin, vend));
		}
	
		cbegin = dc.indexOf(" ", cbegin) + 1;
	
		if (cbegin== 0) break;
	}
	return null;
}

function setCookie(name, value, expires, path, domain, secure)
{
	path = '/';
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/* Deflasherizer [Eolas Patent Remover] */
function deflasherizer()
{
	var objects = document.getElementsByTagName("noscript");
	for (var i = objects.length - 1; i >= 0 ; i--)
	{
		var html = objects[i].innerHTML;
		var naglowek = html.replace(/^\s+|\s+$/, '').substring(1, 6);
		
		if(naglowek != "embed")
		{
			html = html.substring(12, html.length-12);
		}
		objects[i].outerHTML = html;
	}
}

window.onload = function()
{
	deflasherizer();
}

/*popapy start*/
function getPageSize() {
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

var EditoPopup = new Object();
EditoPopup.BorderSize = 1;
EditoPopup.IcoCloseHeight = 26;
EditoPopup.PaddingWidth = 10;
EditoPopup.PaddingHeight = 10;
		
EditoPopup.Popup = function(popup_src,popup_link,popup_target,popup_width,popup_height,type,popup_id,popup_szablon,popup_padding)
{	
	if (type == 'popup_flash')
	{
		var html = '';
		html += '<div id="EditoPopup$Overlay'+popup_id+'" class="PopupOverlay" style="display:none;"></div>';
		html += '<iframe id="EditoPopup$Background'+popup_id+'" style="display:none;" class="boksik"></iframe>';
		html += '<table cellspacing="0" cellpadding="0" border="0" id="EditoPopup$Panel'+popup_id+'" class="Popup" style="display:none;">';
		html += '	<tr>';
		html += '		<td align="right">';
		html += '			<a href="javascript:void(0)" onclick="EditoPopupClose('+popup_id+')" id="EditoPopup$IcoClose'+popup_id+'" class="IcoClose"></a>';
		html += '		<td>';
		html += '	</tr>';
		html += '	<tr>';
		html += '		<td id="EditoPopup$Container'+popup_id+'" class="ImageContainer">';
		html += '			<div id="EditoPopup$Preview'+popup_id+'" class="Preview">';
		html += '				<object';
		html += '					classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		html += '					codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"';
		html += '					width="'+popup_width+'" height="'+popup_height+'">';
		html += '					<param name="movie" value="../../'+popup_src+'?alink1='+popup_link+'&amp;atar1='+popup_target+'" />';
		html += '					<param name="quality" value="high" />';
		html += '					<param name="flashvars" value="alink1='+popup_link+'&amp;atar1='+popup_target+'" />';
		html += '					<param name="wmode" value="transparent" />';
		html += '					<embed'; 
		html += '						src="../../'+popup_src+'?alink1='+popup_link+'&amp;atar1='+popup_target+'"';
		html += '						flashvars = "alink1='+popup_link+'&amp;atar1='+popup_target+'"';
		html += '						quality="high"'; 
		html += '						pluginspage="http://www.macromedia.com/go/getflashplayer"'; 
		html += '						type="application/x-shockwave-flash"'; 
		html += '						wmode="transparent"';
		html += '						width="'+popup_width+'"';
		html += '						height="'+popup_height+'">';
		html += '					</embed>';
		html += '				</object>';
		html += '			</div>';
		html += '			<div id="EditoPopup$Loader'+popup_id+'" class="Loader"></div>';
		html += '		</td>';
		html += '	</tr>';
		html += '</table>';
		
	}
	else if (type == 'popup_obrazek')
	{

		var html = '';
		html += '<div id="EditoPopup$Overlay'+popup_id+'" class="PopupOverlay" style="display:none;"></div>';
		html += '<iframe id="EditoPopup$Background'+popup_id+'" style="display:none;"></iframe>';
		html += '<table cellspacing="0" cellpadding="0" border="0" id="EditoPopup$Panel'+popup_id+'" class="Popup" style="display:none;">';
		html += '	<tr>';
		html += '		<td align="right">';
		html += '			<a href="javascript:void(0)" onclick="EditoPopupClose('+popup_id+')" id="EditoPopup$IcoClose'+popup_id+'" class="IcoClose"></a>';
		html += '		<td>';
		html += '	</tr>';
		html += '	<tr>';
		html += '		<td id="EditoPopup$Container'+popup_id+'" class="ImageContainer">';
		html += '			<a id="EditoPopup$ImgHref'+popup_id+'"><img id="EditoPopup$Preview'+popup_id+'" class="Preview"/></a>';
		html += '			<div id="EditoPopup$Loader'+popup_id+'" class="Loader"></div>';
		html += '		</td>';
		html += '	</tr>';
		html += '</table>';
	}

	    $(document).ready(function(){

			var body = document.getElementsByTagName("body")[0];
			var span = document.createElement("span");
			span.innerHTML = html;
			body.appendChild(span);
			
			EditoPopup.Show(popup_src,popup_link,popup_target,popup_width,popup_height,type,popup_id,popup_szablon,popup_padding);
			
			var pathsize = getPageSize();
		
			$('.PopupOverlay').css('width', pathsize[2] +'px');
			$('.PopupOverlay').css('height', pathsize[1] +'px');
	

	    });


	
}

EditoPopup.Item = function(id)
{
	return document.getElementById("EditoPopup$" + id);
}

EditoPopup.Screen = function()
{
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		return [window.innerWidth, window.innerHeight];
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		return [document.documentElement.clientWidth, document.documentElement.clientHeight];
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		return [document.body.clientWidth, document.body.clientHeight];
	}
}

EditoPopup.Show = function(popup_src,popup_link,popup_target,popup_width,popup_height,type,popup_id,popup_szablon,popup_padding)
{
	EditoPopup.Item("Preview"+popup_id).style.display = "none";
	EditoPopup.Item("IcoClose"+popup_id).style.display = "none";
	EditoPopup.Item("Loader"+popup_id).style.display = "";
	EditoPopup.Item("Container"+popup_id).style.width = "500px";
	EditoPopup.Item("Container"+popup_id).style.height = "400px";
	EditoPopup.Item("Panel"+popup_id).style.width = "500px";
	EditoPopup.Item("Panel"+popup_id).style.height = "400px";
	EditoPopup.Item("Panel"+popup_id).style.position = "absolute";
	EditoPopup.Item("Panel"+popup_id).style.display = "";
	
	EditoPopup.ChangePosition(popup_id,popup_szablon,popup_padding);
	
	var img = new Image();
	EditoPopup.ImageLoad(popup_src,popup_link,popup_target,popup_width,popup_height,type,popup_id,popup_szablon,popup_padding);
}

EditoPopup.ChangePosition = function(popup_id,popup_szablon,popup_padding)
{
	var screen = EditoPopup.Screen();
	
	var offsetWidth = parseInt(EditoPopup.Item("Panel"+popup_id).style.width) + EditoPopup.PaddingWidth + 4*EditoPopup.BorderSize;
	var offsetHeight = parseInt(EditoPopup.Item("Panel"+popup_id).style.height) + EditoPopup.PaddingHeight + EditoPopup.IcoCloseHeight + 4*EditoPopup.BorderSize;
	
	if (popup_szablon == 1)
	{
		var left = popup_padding;
		var top = popup_padding;
	}
	else if (popup_szablon == 2)
	{
		var left = ((screen[0] - offsetWidth) / 2);
		var top = popup_padding;
	}
	else if (popup_szablon == 3)
	{
		var left = screen[0] - offsetWidth - popup_padding;
		var top = popup_padding;
	}
	else if (popup_szablon == 4)
	{
		var left = popup_padding;
		var top = ((screen[1] - offsetHeight) / 2);
	}
	else if (popup_szablon == 5)
	{
		var left = ((screen[0] - offsetWidth) / 2);
		var top = ((screen[1] - offsetHeight) / 2);
	}
	else if (popup_szablon == 6)
	{
		var left = screen[0] - offsetWidth - popup_padding;
		var top = ((screen[1] - offsetHeight) / 2);
	}
	else if (popup_szablon == 7)
	{
		var left = popup_padding;
		var top = screen[1] - offsetHeight - popup_padding;
	}
	else if (popup_szablon == 8)
	{
		var left = ((screen[0] - offsetWidth) / 2);
		var top = screen[1] - offsetHeight - popup_padding;
	}
	else if (popup_szablon == 9)
	{
		var left = screen[0] - offsetWidth - popup_padding;
		var top = screen[1] - offsetHeight - popup_padding;
	}
	else
	{
		var left = ((screen[0] - offsetWidth) / 2);
		var top = ((screen[1] - offsetHeight) / 2);
	}
	
	EditoPopup.Item("Panel"+popup_id).style.zIndex = "100";
	EditoPopup.Item("Panel"+popup_id).style.left = ((left > 0) ? left : 0) + "px";
	EditoPopup.Item("Panel"+popup_id).style.top = ((top > 0) ? top : 0) + "px";
	
	var overlayHeight = document.body.offsetHeight;
	if(overlayHeight < screen[1])
	{
		overlayHeight = screen[1];
	}
	if(parseInt(EditoPopup.Item("Panel"+popup_id).style.top) + offsetHeight > overlayHeight)
	{
		overlayHeight = parseInt(EditoPopup.Item("Panel"+popup_id).style.top) + offsetHeight;
	}
	
	if(!((document.getElementById && !document.all) || window.opera))
	{
		EditoPopup.Item("Background"+popup_id).style.position = "absolute";
		EditoPopup.Item("Background"+popup_id).style.zIndex = "95";
		EditoPopup.Item("Background"+popup_id).style.left = EditoPopup.Item("Panel"+popup_id).style.left;
		EditoPopup.Item("Background"+popup_id).style.top = EditoPopup.Item("Panel"+popup_id).style.top;
		EditoPopup.Item("Background"+popup_id).style.height = offsetHeight;
		EditoPopup.Item("Background"+popup_id).style.width = offsetWidth;
		EditoPopup.Item("Background"+popup_id).style.display = "";
	}
	
	EditoPopup.Item("Overlay"+popup_id).style.position = "absolute";
	EditoPopup.Item("Overlay"+popup_id).style.zIndex = "90";
	EditoPopup.Item("Overlay"+popup_id).style.left = "0px";
	EditoPopup.Item("Overlay"+popup_id).style.top = "0px";
	EditoPopup.Item("Overlay"+popup_id).style.height = overlayHeight + EditoPopup.PaddingHeight + EditoPopup.IcoCloseHeight + 4*EditoPopup.BorderSize + "px";
	EditoPopup.Item("Overlay"+popup_id).style.display = "";
}

EditoPopup.ImageLoad = function(popup_src,popup_link,popup_target,popup_width,popup_height,type,popup_id,popup_szablon,popup_padding)
{
	EditoPopup.Item("Background"+popup_id).style.display = "none";
	EditoPopup.Item("Panel"+popup_id).style.width = "";
	EditoPopup.Item("Panel"+popup_id).style.height = "";
		
	EditoPopup.Item("Container"+popup_id).style.width = parseInt(popup_width) + "px";
	EditoPopup.Item("Container"+popup_id).style.height = parseInt(popup_height) + "px";
	EditoPopup.Item("Panel"+popup_id).style.width = parseInt(popup_width) + "px";
	EditoPopup.Item("Panel"+popup_id).style.height = parseInt(popup_height) + "px";
	
	EditoPopup.Item("Loader"+popup_id).style.display = "none";
	
	EditoPopup.Item("Preview"+popup_id).style.display = "";
	EditoPopup.Item("IcoClose"+popup_id).style.display = "";
	
	if (type == 'popup_obrazek')
	{
		EditoPopup.Item("Preview"+popup_id).src = popup_src;
		EditoPopup.Item("ImgHref"+popup_id).href = popup_link;
		EditoPopup.Item("ImgHref"+popup_id).target = popup_target;
	}
	
	EditoPopup.ChangePosition(popup_id,popup_szablon,popup_padding);
	
}

function EditoPopupClose(popup_id)
{
	EditoPopup.Item("Preview"+popup_id).style.display = "none";
	EditoPopup.Item("IcoClose"+popup_id).style.display = "none";
	EditoPopup.Item("Panel"+popup_id).style.display = "none";
	EditoPopup.Item("Overlay"+popup_id).style.display = "none";
	EditoPopup.Item("Background"+popup_id).style.display = "none";
}

/* System banerowy - Popupy - koniec */
