function addEvent(obj, evType, fn){ try { if (obj.addEventListener){ obj.addEventListener(evType, fn, false); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; }}catch(e){}}
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 hide(name){ document.getElementById(name).style.display='none'; } 
function hideAfter(time,name){ setTimeout("hide('"+name+"')", time); }

function selectRange(oText, start, length){  
if (oText.createTextRange) {  var oRange = oText.createTextRange();  oRange.moveStart("character", start);  oRange.moveEnd("character", length - oText.value.length); oRange.select(); }
else if (oText.setSelectionRange) { oText.setSelectionRange(start, length); } oText.focus(); }

// 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){
		this.__xmlhttp.onreadystatechange = this.__dataLoaded;
		this.__xmlhttp.open("GET", '/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){
				document.getElementById('cal').innerHTML = r.responseText;
			}else{}
		}
	}
}

//ajax add event
function getXMLHttpRequest() {
   var request = false;
   try {
     request = new XMLHttpRequest();
   } catch(err1) {
     try {
       request = new ActiveXObject('Msxml2.XMLHTTP');
     } catch(err2) {
       try {
         request = new ActiveXObject('Microsoft.XMLHTTP');
       } catch(err3) {
         request = false;
       }
     }
   }
   return request;
   }

function CatPos(id)
{
   r = getXMLHttpRequest();
   r.open("GET", '/ajax/CatPos.php?id='+id, true);
   r.onreadystatechange = function(){
         if (r.readyState == 4)
            if (r.status == 200) {
                el = document.getElementById('category_id');
                el.innerHTML=r.responseText;
     }
   }
   r.send(null);
}
//\add event


function PopUp(l, w, h) {
	w = window.open('','','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width='+w+',height='+h+',left=0,top=0');

	d = w.document
	d.writeln('<html>')
	d.writeln('<head>')
	d.writeln('<style type="text/css">body {background-color:0xFFFFFF;margin: 0px 0px 0px 0px;padding: 0px 0px 0px 0px;}</style>')
	d.writeln('<title>Kliknij na zdjęciu, aby zamknąć okno</title>')
	d.writeln('</head>')
	d.writeln('<body>')
	d.writeln('<a href="javascript:self.close()"><img alt="Close window" src="'+l+'" border="0"></a>')
	d.writeln('</body>')
	d.writeln('</html>')
	d.close()
	
	return false;
}

function PopUpLnkWS(l, w, h) {
	w = window.open(l,'','resizable=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=no,width='+w+',height='+h+',left=0,top=0');
	return false;
}

function PopUpLnk(l, w, h) {
	w = window.open(l,'','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width='+w+',height='+h+',left=0,top=0');
}

function vote(ch)
{
   r = getXMLHttpRequest();
   ch=ch+1;
   r.open("GET", '/ajax/Surv.php?id='+document.getElementById('srv_id').value+'&vote='+ch, true);  
   r.onreadystatechange = function(){
         if (r.readyState == 4)
            if (r.status == 200) {
                el = document.getElementById('survey');
                el.innerHTML=r.responseText;
     }
   }
   r.send(null);
}

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
		vote(checked);
}

function fun()
{
	var x = Math.random();
	if (x<0.4)
	{
		var e = document.getElementById('nav');
		e.style.background="url('http://www.tychy.pl/new_img/2c.png')";
		e.style.backgroundRepeat = "no-repeat";
		var w = e.offsetWidth;
		var move = w - 280;
  

		e.style.backgroundPosition = move+"px 14px"		  
		var e2 = document.getElementById('secondary');
		e2.style.background="url('http://www.tychy.pl/new_img/2d.png')";
		e2.style.backgroundRepeat = "no-repeat";
		//alert('1');
	}
	else if (x<0.8)
	{
	  	var e = document.getElementById('nav');
		e.style.background="url('http://www.tychy.pl/new_img/3c.png')";
		e.style.backgroundRepeat = "no-repeat";
		var w = e.offsetWidth;
		var move = w - 280;

	  
		e.style.backgroundPosition = move+"px 14px"
		var e2 = document.getElementById('secondary');
		e2.style.background="url('http://www.tychy.pl/new_img/3d.png')";
		e2.style.backgroundRepeat = "no-repeat";
		//alert('2');	  
	}
	else
	{
   		//alert('3');
 	}
	   
}
