function GE(i){return document.getElementById(i)}
window.google_analytics_uacct = "UA-4700387-2";
var host =  location.toString().substr(7);host = "http://" + host.substr(0, host.indexOf("/")) + "/";
if (host == "http://localhost/") {host += "YAFUD/"}
var eStr = "";
var showTab = [];

function zmienStyl(nazwa) {
var colMap = [];colMap['niebieski'] = 'blue';colMap['zolty']     = 'yellow';colMap['czarny']    = 'black';
var date = new Date();date.setTime(date.getTime() + (31622400000));var expires = "; expires=" + date.toGMTString();document.cookie = 'styl=' + nazwa + expires + "; path=/";
window.location.reload();
}


var ajaxRequest = function(id,funkcja,url,typ,data) {
var req = false;
var kontroler = GE(id);
if(window.XMLHttpRequest) { req = new XMLHttpRequest();if(req.overrideMimetype) {req.overrideMimetype('text/xml');}} 
else if(window.ActiveXObject) {try {req = new ActiveXObject("Msxml2.XMLHTTP");} catch(e) {try {req = new ActiveXObject("Microsoft.XMLHTTP");} catch(e) {}}}

if(req) {req.onreadystatechange = function() {try {if(req.readyState == 4) {
if(req.status == 200) {funkcja(req.responseXML?req.responseXML:req.responseText,id);} else {kontroler.className = 'fail';kontroler.setAttribute('title','Błąd nr 2!');}
} else if(req.readyState == 1) {kontroler.className = 'loading';kontroler.setAttribute('title','Ładowanie w toku...');}} catch(e) {}};

req.open(typ, url, true);
if(typ == 'post') {req.setRequestHeader('Content-type','application/x-www-form-urlencoded');req.setRequestHeader('Content-length',data.length);req.setRequestHeader('Connection', 'close');}
req.send(data);
} else {kontroler.className = 'fail';kontroler.setAttribute('title','Błąd nr 1!');}
};


var ocen = function(xml,id) {
var e=xml.getElementsByTagName('error').item(0);
var o=GE(id).firstChild;var op=o.parentNode;
id = id.split('-')[1];
if(e.getAttribute('id')==0) {
var xmlScore = e.getAttribute('score');
var xmlVotes = e.getAttribute('votes');
var xmlComms = e.getAttribute('comms');
op.parentNode.appendChild(document.createTextNode('Dziękujemy za oddany głos.'));
if(o.textContent) {o.textContent = xmlScore;} else {op.innerHTML = xmlScore;}
var ilosc_ocen = GE('ilosc_ocen-'+id).firstChild;
if(ilosc_ocen.textContent) {ilosc_ocen.textContent = "Głosy: " + xmlVotes;} else {ilosc_ocen.parentNode.innerHTML = "Głosy: " + xmlVotes;}
} else if(e.getAttribute('id')==4 || e.getAttribute('id')==44) {op.parentNode.appendChild(document.createTextNode('Ten yafud był już oceniany!'));}
GE('kit-'+id).parentNode.setAttribute('href','javascript:void(0)');GE('git-'+id).parentNode.setAttribute('href','javascript:void(0)');
};


var typ = false;
var checkfco = function(id) {if(window.fco) var fco = window.document['fco'];if(document.fco) var fco = document.fco;fco.GotoFrame(1);fco.SetVariable('cid',id);fco.GotoFrame(0);};
var dcreq = function(id, s) {
if (id <= 0) return;

if (!s.length) {
GE('kit-' + id).parentNode.setAttribute('href', 'javascript:void(0)');GE('git-' + id).parentNode.setAttribute('href', 'javascript:void(0)');
GE('ocena-' + id).parentNode.appendChild(document.createTextNode('Ten yafud był już oceniany!'));
return;
}
ajaxRequest('ocena-' + id, ocen, host + '/xml/ocena.dodaj.xml.php?typ=' + typ + '&id=' + id + '&hash=' + s, 'get');
};

var cookieexist = function(id) {dcreq(id,'');};
var cookienotexist = function(id,s) {dcreq(id,s);};
var add = function(id) {checkfco(id);typ = 'plus';};
var sub = function(id) {checkfco(id);typ = 'minus';};


function timestamp(d){var t=d.split(' ');return new Date(t[2], t[1] - 1, t[0], t[3], t[4], 0, 0).getTime()/1000;}
function markNew(prev) {
var t=new Date();var y=new Date();y.setDate(y.getDate()-1);t = t.getDate() + "." + (t.getMonth()+1) + "." + t.getFullYear();y = y.getDate() + "." + (y.getMonth()+1) + "." + y.getFullYear();
var maxTimestamp = 0;var wpisy = document.getElementsByTagName('span');
for (i = 0; i < wpisy.length; i++) {if (wpisy[i].className == "wpis-data") {
var d=wpisy[i].childNodes[0].innerHTML + " " + wpisy[i].innerHTML.substr(-5);d=timestamp(d.replace(/dzisiaj/i, t).replace(/wczoraj/i, y).replace(/[.:]/gi, " "));
if (d > prev){var hdr = wpisy[i].parentNode.childNodes[1];maxTimestamp = Math.max(maxTimestamp, d);hdr.innerHTML = hdr.innerHTML.replace(/#/gi, "<span style='color:#D51F00;'> Nowy ! - </span>#");}}}
if (maxTimestamp > prev){var exdate = new Date();exdate.setDate(exdate.getDate() + 100);document.cookie = "last_yafud=" + maxTimestamp + ";expires=" + exdate.toGMTString();}
}


var mWidth=0;
if(typeof(window.innerWidth)=='number') {
mWidth=window.innerWidth;
} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
mWidth=document.documentElement.clientWidth;
} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
mWidth = document.body.clientWidth;
}

var noweWiadomosci = function(flag) {
if(flag==true) {return noweWiadomosciAktualizuj(window.msg_time_out);}
ajaxRequest("", noweWiadomosciAktualizuj, host + 'xml/msg.check.xml.php', 'get');
};

var noweWiadomosciAktualizuj = function(R) {
if (!R) return;R = R.split(',');if (R[2]<0) return;window.setTimeout(function(){noweWiadomosci(false);},R[2]*1000);if (R[1] <= 0) return;
GE('nowe-msg').innerHTML = '<a href="'+host+'wiadomosci/odebrane/"><img src="'+host+'images/envelope.png" height="13" alt="Masz '+R[1]+' nowych wiadomoĹ›ci"/></a>';
};

function confirmModerate(url, num) { url = url + '&Comments[do]=mod&Comments[id]=' + num; if (confirm('Czy chcesz zgłosić ten komentarz jako nieodpowiedni?')) { ajaxRequest(null, null, url, 'get', null); } return 0; }
function validate_form(frm) {
    var V = '';
    var E = new Array();
    q = '';
    if (typeof frm.elements['Comments[name]'] != 'undefined') {
        V = frm.elements['Comments[name]'].value; if (V == '' && !E['name']) { E['name'] = true; q = q + '\n - Wymagany nick'; }
        V = frm.elements['Comments[captcha]'].value; if (V == '' && !E['captcha']) { E['captcha'] = true; q = q + '\n - Wymagany kod z obrazka'; }
    }
    V = frm.elements['Comments[text]'].value; if (V == '' && !E['text']) { E['text'] = true; q = q + '\n - Wymagana treść komentarza'; }
    if (V.length < 10 && !E['text']) { E['text'] = true; q = q + '\n - Komentarz jest za krótki (minimum 10 znaków)'; }
    if (V.length > 4000 && !E['text']) { E['text'] = true; q = q + '\n - Komentarz jest za długi (maksimum 4000 znaków)'; }
    if (q != '') { q = 'Niepoprawne dane:' + q + '\nProszę poprawić te pola'; alert(q); return false; }
    return true;
}

window.onload = function() {noweWiadomosci(true);};


