function hide(name){ document.getElementById(name).style.display='none'; } 
function hideAfter(time,name){ setTimeout("hide('"+name+"')", time); }
function show(p_id){var o=document.getElementById(p_id); if(o.style){o.style.display='';}else{o.visibility="show";}}
function change_style(p_id, c){var o=document.getElementById(p_id); if(o.className)o.className=c;}

// menu
function onRowOver(t) {
        t.style.backgroundColor = '#FFFBF4';
        t.onmouseout = function() {
                        t.style.backgroundColor = '';
        };
};

// linki _blank
function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) {  var anchor = anchors[i];  if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";}}

window.addEvent(window.ie? "load" : "domready", function(){
	ar = new Ajax(abs_path+"ajax/radio.php", {"onComplete": function(){
		data = Json.evaluate(ar.response.text)
		l1 = function(){$('we_play').setHTML(data[0]);$('we_play_2').setHTML(data[0]); l2.delay(5000);}
		l2 = function(){$('we_play').setHTML(data[1]);$('we_play_2').setHTML(data[1]); l3.delay(5000);}
		l3 = function(){$('we_play').setHTML(data[2]);$('we_play_2').setHTML(data[2]); l1.delay(5000);}
		l1();
	}}).request();
})

// AJAX
function getXmlHttpObject(){var xmlHttp = null; try {xmlHttp = new XMLHttpRequest();}
catch(e) { var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){try{ xmlHttp = new ActiveXObject(XmlHttpVersions[i]); } catch (e){}}
}return xmlHttp;}


ev_call_xmlhttp = getXmlHttpObject();
function EvCal(){
	this.getMonth = getMonth;
	this.__dataLoaded = __dataLoaded;
	this.__xmlhttp = getXmlHttpObject();
	ev_call_xmlhttp = this.__xmlhttp;
	
	function getMonth(m,y){
		document.getElementById('ev_load').style.display = '';
		this.__xmlhttp.onreadystatechange = this.__dataLoaded;
		this.__xmlhttp.open("GET", abs_path+'ajax/events_calendar.php?m='+m+'&y='+y, true);
		this.__xmlhttp.send(null);
	}
	
	function __dataLoaded(){
		var r = ev_call_xmlhttp;
		if(r.readyState == 4 || r.readyState == "complete"){
			if(r.status == 200){
				//a = eval("("+r.responseText+")");
				//alert(a.txt);
				document.getElementById('ev_calendar').innerHTML = r.responseText;
				document.getElementById('ev_load').style.display = 'none';
			}else{}
		}
	}
}


function checkSurvey()
{
	f = document.getElementById('srv_form');
	checked = -1;
	for(i=0;i<f.sonda.length;i++){
	
			if(f.sonda[i].checked){ checked = i; break; }
	}
	if(checked==-1)
		return false;
	else
		(new Survey()).Send();
}

// from: http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


survey_xmlhttp = getXmlHttpObject();
function Survey(){
	this.Send = Send
	this.__results = __results
	
	function Send(){
		survey_xmlhttp.onreadystatechange = this.__results
		survey_xmlhttp.open("POST", 'ajax/survey.php', true)
		
		
		f = document.getElementById('srv_form')
		post_data = "srv_id="+f.srv_id.value
		
		checked = -1;
		for(i=0;f.sonda.length;i++){
			if(f.sonda[i].checked){ checked = i; break; }
		}
		if(checked == -1) return;
		cookie = readCookie("survey_"+f.srv_id.value)
		if(!__checkIfCookieIsEnabled()) return false;
		if(cookie == null || cookie == "0"){
			createCookie("survey_"+f.srv_id.value, "1", 30);
			post_data+= "&glos="+f.sonda[checked].value
		
			survey_xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      		survey_xmlhttp.setRequestHeader("Content-length", post_data.length);
      		survey_xmlhttp.setRequestHeader("Connection", "close");
      	
			survey_xmlhttp.send(post_data);
		}else{
			alert("Głosowałeś już w tej sondzie! Aby zobaczyć wyniki odśwież stronę.");
		}
	} 
	
	function __checkIfCookieIsEnabled(){
		createCookie("test_cookie", "1", 1)
		if(readCookie("test_cookie") != "1"){
			alert("Aby głosować twoja przeglądarka musi mieć włączoną obsługę ciasteczek (cookies).");
			return false;
		}else{
			eraseCookie("test_cookie");
		}
		return true;		 
	}
	
	function __results(){
		var r = survey_xmlhttp;
		if(r.readyState == 4 || r.readyState == "complete"){
			if(r.status == 200){
				document.getElementById('survey').innerHTML = r.responseText;
				//document.getElementById('ev_load').style.display = 'none';
			}else{}
		}
	}
}
