var nextFileId = 1;
var addedFiles = 0;

// Wykonanie akcji zmiany statusu moderacji podziękownaia
function moderateThanks(thanksId) {
	msg = 'Czy zmienić status moderacji tego podziekowania?';
	if (confirm(msg)) {
		window.document.changethanks._action.value = 'moderatethanks';
		window.document.changethanks.id.value = thanksId;
		window.document.changethanks.submit();
	}
	return true;
}

// Wykonanie akcji zmiany widoczności podziękowania
function showThanks(thanksStatus, thanksId) {
	msg = 'Czy zmienić widoczność tego podziekowania?';
	if (confirm(msg)) {
		window.document.changethanks._action.value = 'showthanks';
		window.document.changethanks.thanksStatus.value = thanksStatus;
		window.document.changethanks.id.value = thanksId;
		window.document.changethanks.submit();
	}
	return true;
}

// Wykonanie akcji zmiany widoczności podziękowania
function addThanks() {
	window.document.addthanks._action.value = 'addthanks';
	window.document.addthanks.submit();
	return true;
}

// Wykonanie akcji zmiany widoczności podziękowania
function removeThanks() {
	window.document.addthanks._action.value = 'removethanks';
	window.document.addthanks.submit();
	return true;
}

// Wykonanie akcji zmiany widoczności podziękowania
function removeThanksById(thanksId) {
	msg = 'Czy usunąć podziekowanie?';
	if (confirm(msg)) {
		window.document.changethanks._action.value = 'removethanks';
		window.document.changethanks.id.value = thanksId;
		window.document.changethanks.submit();
	}
	return true;
}

function showSubNavi(nr) {
	document.getElementById("sB" + nr).style.display = "";
}
function hideSubNavi(nr) {
	document.getElementById("sB" + nr).style.display = "none";
}

// Wykonanie akcji zmiany statusu moderacji stypendium / konkursu
function moderateScholarship(id) {
	msg = 'Czy oznaczyć wpis jako zmoderowany?';
	if (confirm(msg)) {
		window.document.changescholarship._action.value = 'moderatescholarship';
		window.document.changescholarship.scholarshipId.value = id;
		window.document.changescholarship.submit();
	}
	return true;
}

// Wykonanie akcji zmiany widoczności stypendium / konkursu
function showScholarship(scholarshipStatus, id) {
	msg = 'Czy zmienić widoczność tego wpisu?';
	if (confirm(msg)) {
		window.document.changescholarship._action.value = 'showscholarship';
		window.document.changescholarship.scholarshipStatus.value = scholarshipStatus;
		window.document.changescholarship.scholarshipId.value = id;
		window.document.changescholarship.submit();
	}
	return true;
}

// Wykonanie akcji usunięcia stypendium / konkursu
function removeScholarship(id) {
	msg = 'Czy chcesz usunąć ten wpis?';
	if (confirm(msg)) {
		window.document.changescholarship._action.value = 'removescholarship';
		window.document.changescholarship.scholarshipId.value = id;
		window.document.changescholarship.submit();
	}
	return true;
}

// usunięcie pliku z formularza
function removeFile(id, tabid) {

	var msg = 'Czy napewno chcesz usunąć ten załącznik?';

	if (confirm(msg)) {
		var file = $(id);

		$(tabid).removeChild(file);

		addedFiles--;

		if (5 > addedFiles) {
			$('addButton').style.display = "block";
		}

		updateFilesStatus(tabid);
	}
}

function addFile(name, url, description, tabid) {

	if (5 <= addedFiles) {
		alert("Maksymalna liczba załączonych plików to 5!");
		return;
	}

	var file = document.createElement("p");

	var id = "file_"+nextFileId;

	file.setAttribute("id", id);
	file.setAttribute("class", "file");

	file.innerHTML = '<label style="width: 250px;"><a target="_blank" href="'+url+'">'+name+'</a></label>';
	file.innerHTML += '<input type="hidden" class="txt" name="fileUrl[]" value="'+url+'"/>';
	file.innerHTML += '<input type="text" class="txt2" name="fileDesc[]" value="'+description+'"/>';
	file.innerHTML += '<a style="cursor: pointer; color: red; margin-left: 20px;" onClick="removeFile(\''+id+'\', \''+tabid+'\');">usuń</a>';

        window.document.getElementById(tabid).appendChild(file);

	nextFileId++;
	addedFiles++;

	if (5 == addedFiles) {
		$('addButton').style.display = "none";
	}
	updateFilesStatus(tabid);
}

function updateFilesStatus(tabid) {

	$(tabid+'Status').innerHTML = 'Załączonych plików: <b>' + addedFiles + ' / 5</b>';
}

function popup(url, width, height) {
	window.open(url,'Upload','height='+height+',width='+width+',menubar=1');
}

//regulamin serwisu newsletter
WP.$(function($){

                // wyswietlanie okienka z regulaminem
                showRegulamin = function() {
                $('body').prepend('<div id="nwsRegulamin"><div class="nwsTlo" onclick="hideRegulamin();"></div><div class="nwsCnt"><p onclick="hideRegulamin();" class="nwsZamknij">[ zamknij ]</p><div class="loader"></div></div></div>');
                $('#nwsRegulamin .loader').load('regulamin_newsletter.html');
                var szer = ( $(window).width() - 660) /2 ;
                var wys = ( $(window).height() - 800) /2 ;
                if ( wys < 0 ) { wys = 0; };
                $('#nwsRegulamin .nwsCnt').css({'left':szer , 'top':wys});
                $(window).resize(function() {
                        var szer = ( $(window).width() - 660) /2 ;
                        var wys = ( $(window).height() - 800) /2 ;
                        if ( wys < 0 ) { wys = 0; };
                        $('#nwsRegulamin .nwsCnt').css({'left':szer , 'top':wys});
                        });
                }

                // zamykanie regulaminu
                hideRegulamin = function() {
                $('#nwsRegulamin').remove();
                }

});

