function reverseVisibility(p_id) {
	var o = document.getElementById(p_id);
	if(o.style) {
		if(o.style.display == 'none') {
			o.style.display = '';
		} else
			o.style.display = 'none';
		
	} else {
		o.visibility = "show";
	}
}

function showHide(i){
	switch (i)
	{
	case 1:
			if($('infor2').getStyle('display')=='none'){
			  $('sport1').setStyle('display', 'none');
			  $('culture1').setStyle('display', 'none');
			  $('infor2').setStyle('display', 'block');
			  $('info').setHTML('zwiń');
			  $('cult').setHTML('rozwiń');
			  $('sport').setHTML('rozwiń');
			}
			else
			{
			  $('sport1').setStyle('display', 'block');
			  $('culture1').setStyle('display', 'block');
			  $('infor2').setStyle('display', 'none');
			  $('info').setHTML('rozwiń');
			}
			
			$('sport2').setStyle('display', 'none');
			$('culture2').setStyle('display', 'none');
			$('infor1').setStyle('display', 'block');
			  
			  break;
	case 2:
			if($('sport2').getStyle('display')=='none'){
			  $('infor1').setStyle('display', 'none');
			  $('culture1').setStyle('display', 'none');
			  $('sport2').setStyle('display', 'block');
			  $('sport').setHTML('zwiń');
			  $('info').setHTML('rozwiń');
			  $('cult').setHTML('rozwiń');
			}
			else
			{
			  $('infor1').setStyle('display', 'block');
			  $('culture1').setStyle('display', 'block');
			  $('sport2').setStyle('display', 'none');
			  $('sport').setHTML('rozwiń');
			}
			
			$('infor2').setStyle('display', 'none');
			$('culture2').setStyle('display', 'none');
			$('sport1').setStyle('display', 'block');
			  break;
	case 3:
			if($('culture2').getStyle('display')=='none'){
			  $('sport1').setStyle('display', 'none');
			  $('infor1').setStyle('display', 'none');
			  $('culture2').setStyle('display', 'block');
			  $('cult').setHTML('zwiń');
			  $('info').setHTML('rozwiń');
			  $('sport').setHTML('rozwiń');
			}
			else
			{
			  $('sport1').setStyle('display', 'block');
			  $('infor1').setStyle('display', 'block');
			  $('culture2').setStyle('display', 'none');
			  $('cult').setHTML('rozwiń');
			}
			
			$('sport2').setStyle('display', 'none');
			$('infor2').setStyle('display', 'none');
			$('culture1').setStyle('display', 'block');
			  break;
	default:
	  		if($('infor2').getStyle('display')=='none'){
			  $('sport1').setStyle('display', 'none');
			  $('culture1').setStyle('display', 'none');
			  $('infor2').setStyle('display', 'block');
			  $('info').setHTML('zwiń');
			  $('culture').setHTML('rozwiń');
			  $('sport').setHTML('rozwiń');
			}
			else
			{
			  $('sport1').setStyle('display', 'block');
			  $('culture1').setStyle('display', 'block');
			  $('infor2').setStyle('display', 'none');
			  $('info').setHTML('rozwiń');
			}
			
			$('sport2').setStyle('display', 'none');
			$('culture2').setStyle('display', 'none');
			$('infor1').setStyle('display', 'block');
			  break;
	}
}

function showHideComments(commId,aId,commQty){
	if($(commId).getStyle('display')=='none'){
		$(aId).setHTML('zobacz komentarze ('+commQty+')')
	}else{
		$(aId).setHTML('ukryj komentarze ('+commQty+')')
	}
}

function showHideCommentsDiv(commId,aId){
	if($(commId).getStyle('display')=='none'){
		$(aId).setHTML('dodaj komentarz')
	}else{
		$(aId).setHTML('ukryj formularz dodawania')
	}
}

function PopUpLnkWS(l, w, h) {
	w = window.open(l,'','resizable=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,fullscreen=no,dependent=no,width='+w+',height='+h+',left=0,top=0');
	return false;
}

// 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";}}

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);
}

function createXmlHttpRequestObject()
{
	var xmlHttp;
	try
	{
		xmlHttp = new XMLHttpRequest();	
		view='moz';
	}
	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]);
				view='ie';
			}
			catch (e) {}
		}
	}
	if(!xmlHttp)
	 alert("Błąd przy tworzeniu obiektu XMLHTTPREQUEST");
	else
	 return xmlHttp; 
}

survey_xmlhttp = createXmlHttpRequestObject();

function Survey(){
	this.Send = Send
	this.__results = __results
	
	function Send(){
		survey_xmlhttp.onreadystatechange = this.__results
		survey_xmlhttp.open("POST", abs_path+'ajax/survey.php', true)
		
		
		f = document.getElementById('srv_form')
		post_data = "srv_id="+f.srv_id.value;
		post_data += "&center_row="+f.center_row.value;
		
		checked = -1;
		for(i=0;i<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{}
		}
	}
}
// 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{}
		}
	}
}
