/* 3vi1 code (c) 2006-\infty by Michal GiM Spadlinski
 * you'lle find me somewhere here:
 *  + gim.org.pl
 *  + gim.jogger.pl
 *  + gim913.googlepages.com
 */
function GiMStyleDate(needle, needle2, divi)
{
	var xxcz=document.getElementsByTagName('div');
	for (j=0; j<xxcz.length; j++)
	{
		if (xxcz[j].className == needle)
		{
			var cvb=xxcz[j].getElementsByTagName('*');
			for (k=0; k<cvb.length; k++)
			{
				if (cvb[k].className == needle2)
				{
					cvb[k].innerHTML = cvb[k].innerHTML.substring(0,cvb[k].innerHTML.indexOf(divi));
					cvb[k].style.visibility = "visible";
				} else
					cvb[k].innerHTML = cvb[k].innerHTML.replace(/0/g,"o");
			}
		}
	}
}

var colact=0;
function colhi(p,b,isa)
{
	var xxcz,magic=0;
	if (isa) {
		xxcz=p.parentElement.parentElement.parentElement.children;
		magic=p.parentElement.className.slice(1).replace(/h/g,'');
	} else {
		xxcz=p.parentElement.parentElement.children;
		magic=p.className.substring(1).replace(/h/g,'');
	}

	if (colact == magic && b)
		return;

	/* iterate over 'tr's */
	for (j=0; j<xxcz.length; j++)
	{
		/* there is additional column at the beginning */
		if (colact) {
			cvb1=xxcz[j].children[13-colact];
			cvb1.className='n'+colact;
		}
		if (magic && b) {
			cvb2=xxcz[j].children[13-magic];
			cvb2.className+='h';
		}
	}
	if (magic && b)
		colact=magic;
	else
		colact=0;
}

function nice_arch(arch)
{
	var md=document.getElementById('archive');
	if (md.parentElement)
		nice_arch_elm(arch)
	else
		nice_arch_dom(arch)
}

function nice_arch_elm(arch)
{
	var doloop=1,i=0;
	var md=document.getElementById('archive');
	var str = '<table class="arch" id="archdom">';

	var mon=new Array('sty', 'luty', 'mar', 'kwi', 'maj', 'cze', 'lip', 'sie', 'wrz', 'pa&#378;', 'lis', 'gru');
	/* yeah, I know this sux, but IE7 (i don't know if 6) is shitty and doesn't allow negative starting index */
	var xst = arch[0].substr(arch[0].length-3,2), xen = arch[arch.length-2].substr(arch[arch.length-2].length-3,2);
	var yst = arch[0].substr(arch[0].length-8,4), yen = arch[arch.length-2].substr(arch[arch.length-2].length-8,4);
	/* col:hover doesn't seem to work ;-/
	str += '<colgroup>';
	str += '<col />';
	for (xit=12; xit>0; xit--)
		str += '<col class="n">';
	str += '</colgroup>';
	*/
	str += '<tr><th class="sm">ARCHIWUM</th>';
	for (xit=12; xit>0; xit--) {
		str += '<th scope="col">' + mon[xit-1] + '</th>';
	}
	str += '</tr>';
	archit=0;
	for (yit=yst; yit>=yen; yit--)
	{
		str += '<tr><th scope="row">' + yit + '</th>';
		for (xit=12; xit>0; xit--)
		{
			compa = '/' + yit + '/' + (xit<10?'0':'') + xit + '/';
			if (arch[archit].substr(arch[archit].length-9) == compa) {
				str += '<td class="n'+xit+'" onmouseover="colhi(this,1,0);" onmouseout="colhi(this,0,0);"><a onmouseover="colhi(this,1,913);" onmouseout="colhi(this,2,913);" href="' + compa + '"> * </a> </td>';
				archit++;
			} else
				str += '<td class="n'+xit+'" onmouseover="colhi(this,1,0);" onmouseout="colhi(this,0,0);"> </td>';
		}
		str += '</tr>';
	}
	str += '</table>';
	md.innerHTML=str;
}

var colact=0;
function colhi_dom(p,b,isa)
{
	var xxcz,magic=0;
	if (isa) {
		xxcz=p.parentNode.parentNode.parentNode.childNodes;
		magic=p.parentNode.className.slice(1).replace(/h/g,'');
	} else {
		xxcz=p.parentNode.parentNode.childNodes;
		magic=p.className.substring(1).replace(/h/g,'');
	}

	if (colact == magic && b)
		return;

	/* iterate over 'tr's */
	for (j=0; j<xxcz.length; j++)
	{
		/* there is additional column at the beginning */
		if (colact) {
			cvb1=xxcz[j].childNodes[13-colact];
			cvb1.className='n'+colact;
		}
		if (magic && b) {
			cvb2=xxcz[j].childNodes[13-magic];
			cvb2.className+='h';
		}
	}
	if (magic && b)
		colact=magic;
	else
		colact=0;
}

function nice_arch_dom(arch)
{
	var doloop=1,i=0;
	var md=document.getElementById('archive');
	var mt=document.createElement("table");

	mt.setAttribute("class","arch");
	var mon=new Array('sty', 'luty', 'mar', 'kwi', 'maj', 'cze', 'lip', 'sie', 'wrz', 'paź', 'lis', 'gru');
	/* yeah, I know this sux, but IE7 (i don't know if 6) is shitty and doesn't allow negative starting index */
	var xst = arch[0].substr(arch[0].length-3,2), xen = arch[arch.length-2].substr(arch[arch.length-2].length-3,2);
	var yst = arch[0].substr(arch[0].length-8,4), yen = arch[arch.length-2].substr(arch[arch.length-2].length-8,4);

	mtr=document.createElement("tr");

	mtd=document.createElement("th");
	mtt=document.createTextNode("ARCHIWUM");
	mtd.setAttribute("class", "sm");
	mtd.appendChild(mtt);
	mtr.appendChild(mtd);

	for (xit=12; xit>0; xit--) {
		mtd=document.createElement("th");
		mtd.setAttribute("scope", "col");
		mtt=document.createTextNode(mon[xit-1]);
		mtd.appendChild(mtt);
		mtr.appendChild(mtd);
	}
	mt.appendChild(mtr);

	archit=0;
	for (yit=yst; yit>=yen; yit--)
	{
		mtr=document.createElement("tr");

		mtd=document.createElement("th");
		mtd.setAttribute("scope", "row");
		mtt=document.createTextNode(yit);
		mtd.appendChild(mtt);
		mtr.appendChild(mtd);

		for (xit=12; xit>0; xit--)
		{
			compa = '/' + yit + '/' + (xit<10?'0':'') + xit + '/';
			mtd=document.createElement("td");
			mtd.setAttribute("class", "n"+xit);
			mtd.setAttribute("onmouseover", "colhi_dom(this,1,0);");
			mtd.setAttribute("onmouseout", "colhi_dom(this,0,0);");
			if (arch[archit].substr(arch[archit].length-9) == compa) {
				mtse=document.createElement("a");
				mtse.setAttribute("onmouseover", "colhi_dom(this,1,913);");
				mtse.setAttribute("onmouseout", "colhi_dom(this,0,913);");
				mtse.setAttribute("href", compa);
				mtt=document.createTextNode('*');
				mtse.appendChild(mtt);
				mtd.appendChild(mtse);
				archit++;
			} 
			mtr.appendChild(mtd);
		}
		mt.appendChild(mtr);
	}
	md.appendChild(mt);
}

function nice_arch2(arch)
{
	nice_arch2_elm(arch)
}

function nice_arch2_elm(arch)
{
	var doloop=1,i=0;
	var md=document.getElementById('arch2');
	var str = '<table class="arch2">';

	var mon=new Array('I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII', 'XII');
	/* yeah, I know this sux, but IE7 (i don't know if 6) is shitty and doesn't allow negative starting index */
	var xst = arch[0].substr(arch[0].length-3,2), xen = arch[arch.length-2].substr(arch[arch.length-2].length-3,2);
	var yst = arch[0].substr(arch[0].length-8,4), yen = arch[arch.length-2].substr(arch[arch.length-2].length-8,4);
	archit=0;
	for (yit=yst; yit>=yen; yit--)
	{
		str += '<tr><th scope="row" rowspan="2">' + yit + '</th>';
		for (xit=12; xit>6; xit--)
		{
			compa = '/' + yit + '/' + (xit<10?'0':'') + xit + '/';
			if (arch[archit].substr(arch[archit].length-9) == compa) {
				str += '<td><a href="' + compa + '"> ' + mon[xit-1] + ' </a> </td>';
				archit++;
			} else
				str += '<td> </td>';
		}
		str += '</tr><tr class="r2">';
		for (xit=6; xit>0; xit--)
		{
			compa = '/' + yit + '/0' + xit + '/';
			if (arch[archit].substr(arch[archit].length-9) == compa) {
				str += '<td><a href="' + compa + '"> ' + mon[xit-1] + ' </a> </td>';
				archit++;
			} else
				str += '<td> </td>';
		}
		str += '</tr>';

	}
	str += '</table>';
	md.innerHTML=str;
	md.style.visibility='visible';
}



/* I know, this is really intuitive place for this! */
function googleBuzz(response) {
    var select = document.getElementById("buzz");
    var len = response.data.items.length;
    var str = "";
    if (len) str += "<ul>";
    for (var i = 0; i < len; i++) {
        it = response.data.items[i];
        str += "<li> <a rel='ext' href='" + it.links.alternate[0].href + "'>";
	str += " " + it.title + "</a></li> ";
    }
    if (len) str += "</ul>";

    document.getElementById("googlebuzz").innerHTML = str;
}

