// zmiana rozmiaru czcionki w wiadomosci
function setFontSize(fSize) {
    document.getElementById("aTxt").style.fontSize = fSize + "px";
}

// pokazywanie/ukrywanie elementu
function pokaPoka(shID) {
	if (document.getElementById(shID)) {
		if (document.getElementById(shID+'-show').style.display != 'none') {
			document.getElementById(shID+'-show').style.display = 'none';
			document.getElementById(shID).style.display = 'block';
		}
		else {
			document.getElementById(shID+'-show').style.display = 'block';
			document.getElementById(shID).style.display = 'none';
		}
	}
}

// spr czy w ankiecie zaznaczono odp
function checkAnswer(oForm){
        var oNodes = oForm.getElementsByTagName('input');
        var i=0;
        for(i; i<oNodes.length; i++){
                if(oNodes.item(i).getAttribute('type') == 'radio'){
                        if(oNodes.item(i).checked) return true;
                }

        }
        return false;
}

// Ocenianie przez usera
function rate(x) {
	top.document.nratingForm.rate.value = x;
	top.document.nratingForm.submit();
}
// ocenianie wiadomosci Ajaxem
var bArticleRated = false;
function rateArticle(formId){
	if (true === bArticleRated) return false;
	bArticleRated = true; // zapobieganie wielokrotnym requestom

	unsetOpacity = function() {
		$('articleRatingDiv').className = $('articleRatingDiv').className.replace(/opacity/g,'');
	}

	$('articleRatingDiv').className = $('articleRatingDiv').className+' opacity';
	
	var urlTxt = document.location.href;
	var msg = 'Wystąpił błąd. Prosimy spróbować ponownie za chwilę.';
	try {
		WP.ajax.post({
			url: urlTxt,
			form: formId,
			onSuccess: function (ajax) {
				var result = WP.parseJSON(ajax.text);
				if ('OK' == result.status) {
					$('articleRatingDiv').innerHTML = result.html;
					unsetOpacity();
				} else {
					alert(msg);
					bArticleRated = false;
					unsetOpacity();
				}
			},
			onError: function (ajax) {
				alert(msg);
				bArticleRated = false;
				unsetOpacity();
			}
		});
	} catch (e) {
		alert(msg);
		bArticleRated = false;
		unsetOpacity();
	}
	return false;
}

