function Ocena(dana, id){
	document.getElementById('ocena'+id+"_1").style.visibility="hidden";
	document.getElementById('ocena'+id+"_2").style.visibility="hidden";
	document.getElementById('ocena'+id+"_3").style.visibility="hidden";
	document.getElementById('ocena'+id+"_4").style.visibility="hidden";
	document.getElementById('ocena'+id+"_5").style.visibility="hidden";
	ustawCookie("lupiko"+id,dana, null);
	
	Ajax('wynik'+id,'/ajax/ocena.php?id=' + id + '&ocena=' + dana);
}

function ustawCookie(nazwa, wartosc, expire) {
  document.cookie = nazwa + "=" + escape(wartosc) + ((expire==null)?"" : ("; expires=" + expire.toGMTString()))
} 

function Ajax(target, adres){
	plik = adres;
	var element;
	if (target != 'null'){
		element=document.getElementById(target);
	}
		
	xml=null;
	if (target != 'null'){
		element.innerHTML='<div class="ajax"><img src="./images/progress.gif"></div>';
	}
	try{
		xml=new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		try {
			xml = new XMLHttpRequest();
		} catch(e) {
			xml = null;
		}
	}
	if (xml != null) {
		xml.onreadystatechange = function() {
			if (xml.readyState==4 && target != 'null') {
				element.innerHTML=xml.responseText;
			}
		}
		xml.open("GET",plik,true);
		xml.send(null);
	}
	return false;
}

function dodaj_do_ulubionych(id,przycisk){
	przycisk.style.visibility='hidden';
	
}

function rozwin_komentarze(id,przycisk){
	przycisk.style.visibility='hidden';
	document.getElementById('wynik_one' + id).style.height='300px';
	document.getElementById('komentarze' + id).style.height='300px';
	Ajax('komentarze' + id,'/ajax/komentarze.php?num=' + id);
}

function Wybrany_SELECT(Element){
    var id;
	with (Element)
    for(var loopIndex = 0; loopIndex < length; loopIndex++)
		if (options[loopIndex].selected){
			id = options[loopIndex].value;
			return(id);
		}
	return '';
}

function Wybrany_SELECT_name(Element){
    var id;
	with (Element)
    for(var loopIndex = 0; loopIndex < length; loopIndex++)
		if (options[loopIndex].selected){
			id = options[loopIndex].id;
			return(id);
		}
	return '';
}

function Pogoda(Element){
	Ajax('pogoda_div', './ajax/pogoda.php?id=' + Wybrany_SELECT_name(Element));
}

function Program(Element1, Element2){
	Ajax('program_div', './ajax/program.php?id=' + Wybrany_SELECT_name(Element1) + '&dat=' + Wybrany_SELECT_name(Element2));
}
	
function Kalendarz(Element) {
	o = window.open("/kal.php?p="+Element, "k", "width=250, height=200, left=400,top=200,location=0,status=0, directories=0, scrollbars=0, menubar=0, toolbar=0, resizable=0");
	o.focus();
	return false;
}

function Testuj_Daty(Element_Od,Element_Do){
	if (document.getElementById(Element_Od).value!='' && document.getElementById(Element_Do).value!=''){
		if(document.getElementById(Element_Od).value>document.getElementById(Element_Do).value){
			alert('Błędna zakres dat "Aktywny od", "Aktywny do"');
			return false;
		}
	}else{
		return true;
	}
}

function kontrola_pola_szukania(){
	if (document.getElementById('s').value==''){
		alert('Wpisz szukane słowo');
		return false;
	}else{
		if (!document.getElementById('td').checked && !document.getElementById('tr').checked){
			alert('Wybierz jakie strony Ciebie interesują dla rodziców, czy dla dzieci');
			return false;
		}else{
			return true;
		}
	}
}




function kontrola_pola_dodaj(){
	var wartosc=document.getElementById('tURL').value;
	var status=true;
	if (wartosc==''){
		alert('Wpisz adres');
		status=false;
	}else{
		if (wartosc.search("http://")==-1 && wartosc.search("https://")==-1 && wartosc.search("ftp://")==-1){
			wartosc = "http://" + wartosc;
		}
		
		var v = new RegExp(); 
	    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
	    if (!v.test(wartosc)) { 
			status=false; 
			alert('Błędny format adresu'); 
	    } 
	} 

	if (status==false){
		document.getElementById('tURL').focus();
		return false;
	}
	return true;
}


	
function SizeWin(Par) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if (Par==0) {
		return myWidth;
	}else{
		return myHeight;
	}
}

function addbookmark() {
	var tytul = 'Lupiko.pl';
	var adres = 'http://Lupiko.pl';
	if (window.sidebar) {
		window.sidebar.addPanel(tytul, adres, "");
	} else if (window.external) {
		window.external.AddFavorite(adres, tytul);
	} else if (window.opera && window.print) {
		var a = document.createElement('a');
		a.setAttribute('href', adres);
		a.setAttribute('title', tytul);
		a.setAttribute('rel','sidebar');
		a.click();
	}
}