
//------------------------------------------------------------------------------------------------

var canadd = true;
var oid = 0;
var zazfirst = true;

//------------------------------------------------------------------------------------------------

function zaznacz() {
	if(zazfirst == true) {
		document.forms.fnewarticle.link.focus();
		document.forms.fnewarticle.link.select();
		zazfirst = false;
	}
}

//------------------------------------------------------------------------------------------------

function DodajKomentarz() {
	if(canadd && (document.getElementById('nowykomentarz').style.display == 'none')) {
		var x = new Effect.SlideDown('nowykomentarz', { duration: 0.8 });
		canadd = false;
	}
}

//------------------------------------------------------------------------------------------------

function WyslijKomentarz() {
	var form = document.forms.fnewcomment;

	if(form['nick'].value.length == 0) {
		alert('wpisz nick!');
	}else if (form['textarea_nowykomentarz'].value.length == 0) {
		alert('wpisz komentarz!');
	}else{
		form['odpowiedz'].value = parseInt(oid);
		form.submit();
	}
}

//------------------------------------------------------------------------------------------------

function Odpowiedz(i) {
	//location.hash = 'odpowiedz';
	document.getElementById('napisz_title').scrollIntoView(true);
	oid = i;
	nick = document.getElementById('nick_'+i).innerHTML;

	document.getElementById('napisz_title').innerHTML = "Odpowiedz na komentarz&nbsp;"+nick;
}

//------------------------------------------------------------------------------------------------

function Anuluj() {
	oid = 0;
	document.getElementById('napisz_title').innerHTML = "Napisz nowy komentarz";
}

//------------------------------------------------------------------------------------------------

function KZ() {
	alert('Komentarze/Artykuły dla tego produktu są zablokowane.');
}

//------------------------------------------------------------------------------------------------

function Foto(tid, nadd) {
	linkhref = 'showfoto.php?thumb='+nadd+'&id='+tid;
	document.getElementById('obrazek').src = 'http://www.arest.pl/ph/'+tid+'/'+nadd+'_nadd.jpg';
	document.getElementById('obrazekhref').href = linkhref;
	if(typeof(document.getElementById('obrazekhref2')) != 'undefined') document.getElementById('obrazekhref2').href = linkhref;
	document.getElementById('thumb_'+chosenone).className = 'null';
	document.getElementById('thumb_'+nadd).className = 'chosenone';
	chosenone = nadd;
}

//////////////////////////////////////////////////////////////////////////////////////////////////

var psi;
var kropki = 0;

function ZnajdzArtykuly(nazwatowaru,id) {
	var url = 'ajax.php?act=artfind&nazwatowaru='+encodeURIComponent(nazwatowaru)+'&id='+id;
	new Ajax.Request(url, {method: 'get',onSuccess: artwyswietl,onLoading: artwczytuje});
}

//------------------------------------------------------------------------------------------------


function artwyswietl(transport) {
	window.clearInterval(psi);
	document.getElementById('grezultat').innerHTML = transport.responseText;
}

//------------------------------------------------------------------------------------------------

function preloader() {
	if(kropki > 3) { kropki = 0; }
	kropkistr = '';
	for(i=0;i<kropki;i++) kropkistr = kropkistr + '.';
	document.getElementById('grezultat').innerHTML = 'Wczytuję wyniki'+kropkistr;
	kropki++;
}

//------------------------------------------------------------------------------------------------

function artwczytuje() {
	preloader();
	psi = window.setInterval(preloader, 300);
}

//------------------------------------------------------------------------------------------------

function dodajart(stytul,surl) {
	document.forms.fnewarticle.tytul.value = stytul;
	document.forms.fnewarticle.link.value = surl;

}

//------------------------------------------------------------------------------------------------

var socena = 0;

function WyslijArtykul() {
	document.forms.fnewarticle.submit();
}

function podswietlgwiazdki(ile) {
	var pods = ile;
	if(socena > 0) pods = socena;
	var i,ch;
	for(i=1;i<=6;i++) {
		if(i == pods) {
			ch = '3';
		}else if(i <= pods) {
			ch = '1';
		}else{
			ch = '2';
		}
		$('star_'+i).src = 'layout/buttons2/star'+ch+'.gif';
	}
}

function ocen(id, ocena) {
	var url = 'ajax.php?act=ocen_towar&id='+id+'&ocena='+ocena;
	new Ajax.Request(url, {method: 'get',onSuccess: 
		function (transport) {
		var ilosc = transport.responseText;
		var i;
			if(ilosc == '*') {
				$('ilosocen').innerHTML = 'Oddałeś już głos.';
			}else{
				$('ilosocen').innerHTML = 'Twój głos został oddany.';
				podswietlgwiazdki(ocena);
				for(i=1;i<=6;i++) {
					$('star_'+i).style.cursor = 'default';
				}
				socena = ocena;				
			}
		}
	}
	);
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

var cache = new Object();

function ajaxtab(id, co) {
	$('tab_wlasciwosci').className = 'zakladka-off';
	$('tab_komentarze').className = 'zakladka-off';
	$('tab_opis').className = 'zakladka-off'

	if(co == 'wlasciwosci') $('tab_wlasciwosci').className = 'zakladka-on';
	if(co == 'komentarze')  $('tab_komentarze').className = 'zakladka-on';
	if(co == 'opis')  $('tab_opis').className = 'zakladka-on';

	setCookie('tab', co, 365);
	if(typeof(cache[co]) != 'undefined') {
		$('produkttab').innerHTML = cache[co];
	}else{
		var url = 'ajaxtab.php?id='+id+'&tab='+co;
		$('produkttab').innerHTML = '<div style="padding:15px;background:#F8F8F8;border-bottom:1px solid #CCCCCC;">Wczytywanie...&nbsp;&nbsp;<img src="layout/loading14.gif"></div>';
		new Ajax.Request(url, {
			method: 'get',
			onSuccess: function (transport) {
				cache[co] = transport.responseText;
				$('produkttab').innerHTML = transport.responseText;
			}
		});
	}
	return false;
}