

  function snd_str(p){
    advAJAX.get({
      url: "psycho/sondy_gl.php?act=strona&p="+p,
      uniqueParameter: "m",
      onInitialization : function() { $('sondodp').innerHTML='ładowanie'; },
      onSuccess : function(obj) { $('sondodp').innerHTML=obj.responseText;   },
      onError : function(obj) { alert("Error: " + obj.status);  }    });
  }

  function sond_gl(id, gl){
    advAJAX.get({
      url: "psycho/sondy_gl.php?act=sond_gl&id="+id+"&gl="+gl,
      uniqueParameter: "m",
      onInitialization : function() { $('sodp'+id).innerHTML='zapisywanie...'; },
      onSuccess : function(obj) { if(obj.responseText=='1') $('sodp'+id).innerHTML='oddała¶ już głos'; else $('sodp'+id).innerHTML='dziękujemy';  },
      onError : function(obj) { alert("Error: " + obj.status);  }    });
  }

  function odpowiedz_etap1(bid, id){
    advAJAX.get({
      url: "psycho/sondy_ajax.php?act=odpowiedz_etap1&bid="+bid+"&sid="+id,
      uniqueParameter: "m",
      onInitialization : function() { $("test").innerHTML = "<img src=\"http://pix.futureshop.ca/images/progress-animation_circles.gif\" alt=\"progress\" style=\"margin:10px auto\" />"; },
      onSuccess : function(obj) { $("test").innerHTML = obj.responseText;  },
      onError : function(obj) { alert("Error: " + obj.status);  }    });
  }

  function odpowiedz_etap2(id){
    advAJAX.submit(document.getElementById("addpole"),
    {
      uniqueParameter: "m",
      onSuccess : function(obj) {
        if(obj.responseText.length<3)
        {
          document.getElementById("test").innerHTML = 'zdobyła¶ '+ obj.responseText +' pkt.';
          if(parseFloat(obj.responseText)<21)
            $('odp1').style.backgroundColor = '#F00';
          else if(parseFloat(obj.responseText)<37)
            $('odp2').style.backgroundColor = '#F00';
          else
            $('odp3').style.backgroundColor = '#F00';
        }
        else
        {
          document.getElementById("test").innerHTML = obj.responseText;          
        }
      },
      onInitialization : function() { $("test").innerHTML = "<img src=\"http://pix.futureshop.ca/images/progress-animation_circles.gif\" alt=\"progress\" style=\"margin:10px auto\" />"; }, onError : function(obj) { alert("Error: " + obj.status);  }
    });
  }

  function odpowiedz_etap3(id){
    advAJAX.submit(document.getElementById("addpole"),{ uniqueParameter: "m",onSuccess : function(obj) {
        if(obj.responseText.length<3)
        {
          document.getElementById("test").innerHTML = 'twój wynik to: '+ obj.responseText +' pkt.';
          if(parseFloat(obj.responseText)<21)
            $('odp1').style.display = 'block';
          else if(parseFloat(obj.responseText)<37)
            $('odp2').style.display = 'block';
          else
            $('odp3').style.display = 'block';

          $('pods').style.display = 'block';
        }
        else
        {
          document.getElementById("test").innerHTML = obj.responseText;          
        }
    }, onInitialization : function() { $("test").innerHTML = "<img src=\"http://pix.futureshop.ca/images/progress-animation_circles.gif\" alt=\"progress\" style=\"margin:10px auto\" />"; }, onError : function(obj) { alert("Error: " + obj.status);  } });
  }

  function odpowiedz_etap5(id){
    advAJAX.submit(document.getElementById("addpole"),{ uniqueParameter: "m",onSuccess : function(obj) {
        if(obj.responseText.length<3)
        {
          document.getElementById("test").innerHTML = '<b>Twój wynik to: '+ obj.responseText +' pkt.</b>';
          if(parseFloat(obj.responseText)<21)
            $('odp1').style.backgroundColor = '#F00';
          else if(parseFloat(obj.responseText)<37)
            $('odp2').style.backgroundColor = '#F00';
          else
            $('odp3').style.backgroundColor = '#F00';
        }
        else
        {
          document.getElementById("test").innerHTML = obj.responseText;
        }
    }, onInitialization : function() { $("test").innerHTML = "<img src=\"http://pix.futureshop.ca/images/progress-animation_circles.gif\" alt=\"progress\" style=\"margin:10px auto\" />"; }, onError : function(obj) { alert("Error: " + obj.status);  } });
  }


/////////////

function zmien_sonde(id)
{
  advAJAX.get({
    url: "/psycho/ajaxs.php?act=zmien_sonde&w="+id,
    uniqueParameter: "m",
    onInitialization : function() { document.getElementById("pytania").innerHTML = '<br ><p style="text-align:center">ładowanie...</p><br/><br />'; },
    onSuccess : function(obj) { document.getElementById("pytania").innerHTML = obj.responseText; }
  });
}

function delcom(id)
{
  if(!confirm("Czy na pewno chcesz usun±ć komentarz?"))
    return 0;
  advAJAX.get({
    url: "/psycho/ajaxs.php?act=delcom&idc="+id,
    uniqueParameter: "m",
    onInitialization : function() { document.getElementById("c"+id).style.display="none"; },
    onError : function(obj) { alert("Error: " + obj.status);  }
  });
}


function str_replace(substr, newsubstr, str)
  {
    replace_count=0;
    while(str.indexOf(substr)>=0)
    {
      str=str.replace(substr, newsubstr);
      replace_count++;
    }
    return(str);
  }
  

function editcom(id)
{
  var tekst = document.getElementById("comm"+id).innerHTML;
  tekst = str_replace('<BR/>', '', tekst);
  document.getElementById("comm"+id).innerHTML = '<form method="post" action="/psycho/ajaxs.php?act=editcomm&amp;id='+id+'" id="cform'+id+'"><textarea name="tresc" id="carea'+id+'" class="editarea">'+tekst+'</textarea><input type="hidden" value="'+document.getElementById("comm"+id).innerHTML+'" id="chid'+id+'" /><br /><input type="button" value="zapisz" onclick="editcomsave('+id+')" /><input type="button" value="anuluj" onclick="editcomanuluj('+id+')" /></form>';
}
function editcomsave(id)
{
  advAJAX.submit(document.getElementById("cform"+id),{
    onSuccess : function(obj) { }});
  document.getElementById("comm"+id).innerHTML = document.getElementById("carea"+id).value;
}
function editcomanuluj(id)
{
  document.getElementById("comm"+id).innerHTML = document.getElementById("chid"+id).value;
}

///////////////////////////////////////// editable ////////////////////////////////////

function editable(co, id, idt, tabl, col)
{
  if(document.getElementById("editable_hidden"+idt))
  {
    if(document.getElementById("editable_area"+idt))    {
      return 0;
    }
    else if(document.getElementById("editable_hidden"+idt).value=='1'){
      document.getElementById("editable_hidden"+idt).value='0';
      return 0;
    }
    else{
      document.getElementById("editable_hidden"+idt).value='1';
    }
    return 0;
  }

  advAJAX.get({
    url: "/psycho/ajaxs.php?act=editable&id="+id+"&idt="+idt+"&tabl="+tabl+"&col="+col,
    uniqueParameter: "m",
    onInitialization : function() { co.innerHTML=co.innerHTML+"<img src=\"images/tiny.gif\" />"; },
    onSuccess : function(obj) { co.innerHTML = obj.responseText; }
  });
}
function editable_close(co)
{
  document.getElementById("editable_hidden"+co).value='1';
  //document.getElementById("editable"+co).innerHTML='[edit]';
}
function editable_large(co)
{
  var area = document.getElementById("editable_area"+co);
  var area_h = area.offsetHeight;
  var area_w = area.offsetWidth;
  area.style.height = area_h+40+"px";
}
function editable_small(co)
{
  var area = document.getElementById("editable_area"+co);
  var area_h = area.offsetHeight;
  var area_w = area.offsetWidth;
  area.style.height = area_h-40+"px";
}

function editable_save(idt)
{
  advAJAX.submit(document.getElementById("editable_form"+idt),{
    onSuccess : function(obj) {
      $("editable"+idt).innerHTML=obj.responseText;
      new Effect.Highlight(document.getElementById("editable"+idt), {startcolor: '#ffff00'});
  }});
}

/////// NEWSLETTER #########################################################################################

  function letter_subm(val, par){
    var checkE = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
    if(checkE.test(val) == false)
    {
      alert("to nie jest poprawny adres email");
      return 0;
    }

    advAJAX.get({
      url: "/psycho/ajaxs.php?act=letter&par="+par+"&email="+val,
      uniqueParameter: "m",
      onInitialization : function() {  },
      onSuccess : function(obj) { $("divletter").innerHTML=obj.responseText; }
    });
    
    //advAJAX.submit(document.getElementById("letter"), {
    //  onSuccess : function(obj){ $("divletter").innerHTML=obj.responseText; } });
  }
  
/////// SONDA ##############################################################################################

  function glosuj(){
    advAJAX.submit(document.getElementById("sonda_form"), {
      onSuccess : function(obj){ $("pytania").innerHTML=obj.responseText; } });
  }
  
  function glosuj1(k){
    advAJAX.submit(document.getElementById("sonda_form"+k), {
      onSuccess : function(obj){ $("pytanie"+k).innerHTML=obj.responseText; } });
  }
  
/////// KOMENTARZE  ########################################################################################

  function dodaj_komentarz(id){
    advAJAX.submit(document.getElementById("com_form"+id), {
      onSuccess : function(obj){ $("comm_n"+id).innerHTML=obj.responseText; } });
  }
  
function onl() {
  sondaText();
  scroll();
	favBan.init();
	newWindow();
}

function sondaText() {
if(document.getElementById('sonda_form')){
  a = document.getElementById('sonda_form');
  var l = a.getElementsByTagName('label');
  
  for(i=0; i<l.length; i++) {
      //if(l[i].getAttribute('for')=='s949') {
      if(l[i].className=='s1090') {
        l[i].onclick = function(){
          b = document.getElementById('sondaText'); 
          b.style.display='block';
        }
      } else {
        l[i].onclick = function(){
          b = document.getElementById('sondaText'); 
          b.style.display='none';
        }
      }
  } 
  
}
}

function scroll()
{
   if(document.getElementById('goToK'))
   {
      var s = document.getElementById('goToK');
      s.onclick = function()
      {
         new Effect.ScrollTo('komentarz', {duration: .5}); return false;
      }      
   }
}

function popup (adr, szer, wys){

  var iH = window.innerHeight;
  var iW = window.innerWidth;

  if (!iH)
    var wh = document.body.clientHeight/2;
  else
    var wh = iH/2;  

  if (!iW)
    var ww = document.body.clientWidth/2;
  else 
    var ww = iW/2;     
      
  var h = wh - (wys/2);
  var w = ww - (szer/2);

  noweOkno = window.open(adr ,'okno' , 'width='+szer+', height='+wys+', top='+h+', left='+w+', menubar=no, status=no, locationbar=no, scrollbars=yes, resizeable=no');
}

function newWindow () {
	var a = document.getElementsByTagName("a");
	for (var i = 0, l = a.length; i < l; i++) {
		if (a[i].className.match("new-window")) {
			a[i].onclick = function () {
				open(this.href);
				return false;
			}
		}
	}
}

var favBan = function () {

	var config = {
    elClass: 'fav-ban',
		elTag: 'ul'
	}	

	var init = function () {
		var parents = document.getElementsByTagName(config.elTag);
		for (var i = 0; i < parents.length; i++) {
			if (parents[i].className == config.elClass) {
				var links = parents[i].getElementsByTagName("a");		
				for (var j = 0; j < links.length; j++) {	
					var img = links[j].getElementsByTagName("img")[0];
					var src = img.getAttribute("src");					
					img.style.visibility = "hidden";					
					links[j].style.backgroundImage = "url(" + src + ")";
					
					links[j].onmouseover = function() {
						this.style.backgroundPosition = "0 -20px";
					}
					
					links[j].onmouseout = function() {
						this.style.backgroundPosition = "0 0";
					}
				}						
			}
		}					
	}
	
	return {
		init: init
	}

}();

window.onload=onl;
  

