// deflasherizer [Eolas Patent Remover]
/*
window.onload = function()
{
	objects = document.getElementsByTagName("noscript");
	for (var i = objects.length - 1; i >= 0 ; i--)
	{
		var html = objects[i].innerHTML;
		html = html.substring(12, html.length-12);
		objects[i].outerHTML = html;
	}
	
	prepareImages();
}
*/

/* Przegladarka zdjec */
$(document).ready(function()
{
	$('a[@rel*=lightbox]').lightBox();
	$('a[@class*=lightbox]').lightBox();
});

function insertActiveX(html)
{
	document.write(html);
}

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) {
	}
}

// zdjęcie bez opisu
function showMap(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("/showMap.php?src="+src, '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 == '' || 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" : "");
}

function prepareImages() {
	var images = new Array();
	
	images[0] = 'images/menu3_dol_zaz.gif';
	images[1] = 'images/menu3_dol.gif';
	images[2] = 'images/menu3_gora.gif';
	images[3] = 'images/menu3_gora_zaz.gif';
	images[4] = 'images/menu3_single.gif';
	images[5] = 'images/menu3_single_zaz.gif';
	images[6] = 'images/menu3_srodek.gif';
	images[7] = 'images/menu3_srodek_zaz.gif';
	
	preloadimages(images);
}

function preloadimages(images) {
	if (!images) {
		var images = new Array();
	} //if
	var img = new Array();
	for (i=0; i<images.length; i++) {
		img[i] = new Image();
		img[i].src = images[i];
	} //for
}

/* popup */

function showPopup() 
{
	if (getCookie('popup') != '1')
	{
		document.getElementById('popupdiv').style.display = 'block';
		//setCookie('popup', '1', getExpiryDate(1), '/');
	}
	else
	{
		document.getElementById('popupdiv').style.display = 'none';
	}
	
}

/* popup ankieta */

function showPopupAnkieta() 
{
	if(getCookie('popupankieta') != '1')
	{
		document.getElementById('popupankieta').style.display = 'block';
		setCookie('popupankieta', '1', getExpiryDate(7), '/');
	}
	else
	{
		document.getElementById('popupankieta').style.display = 'none';
	}
	
}

/* popup ankieta zliczanie */
/* wywołanie funkcji zliczającej w php */
function zliczPopupAnkieta(id)
{
	document.getElementById("popupankieta").style.display = "none";
	//sciezka do pliku
	var sciezka = "../../zlicz.php";
	
	$.ajax({
		type: 'get',
		url: sciezka,
		data: 'odp='+id+'&lang='+jsLang+'&id_projektu='+jsIdProjektu
	});
	
	switch(id)
	{
		case 1:
			window.location = "http://www.zak.edu.pl/pl/dlaczego/szkoly_za_darmo/";
			break;
		case 2:
			window.location = "http://www.zak.edu.pl/pl/dlaczego/kalkulator_oszczednosci/";
			break;
		case 3:
			window.location = "http://www.zak.edu.pl/pl/dlaczego/znizki_partnerow/";
			break;
	}
}

function closePopup() 
{
	document.getElementById('popup_div').style.display = 'none';
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function getExpiryDate(nodays)
{
	Today = new Date();
	Today.setTime(Today.getTime() + nodays*24*60*60*1000);
	Today.setHours(0);
	Today.setMinutes(0);
	Today.setSeconds(0);
	
	return Today;
}