function Ajax(target, adres){
	plik = adres;
	var element;
	if (target != 'null'){
		element=document.getElementById(target);
	}
		
	xml=null;
	
	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 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(Element, Dzien){
	Ajax('program_div', './ajax/program.php?idd=' + Dzien + '&id=' + Wybrany_SELECT_name(Element));
}

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 Ocena(dana, id){
	document.getElementById('ocena'+id+"_1").style.display="none";
	document.getElementById('ocena'+id+"_2").style.display="none";
	document.getElementById('ocena'+id+"_3").style.display="none";
	document.getElementById('ocena'+id+"_4").style.display="none";
	document.getElementById('ocena'+id+"_5").style.display="none";
	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 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;
}
