function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReqDetails(action) {
	http.open('get','http://www.slaboslyszacy.pl/komentarz,'+action+'.html');
	http.onreadystatechange = handleResponse;
	http.send(null);
}

function handleResponse() {
	if(http.readyState == 4){
		var response = http.responseText;
		var update = new Array();
		if(response.indexOf('|' != -1)) {
			update = response.split('|');
			i = 0;		
			var obj = document.getElementById(update[0]);
			if (obj != null)
				obj.innerHTML = update[1];			
		}
	}
}

function cache(identifiant) {
	  if (document.getElementById('i' + identifiant).style.display == "none") {
		 document.getElementById('i' + identifiant).style.display = "";
		 var obj = document.getElementById('m'+identifiant);
		 if (obj != null)
		 	obj.src = 'http://www.slaboslyszacy.pl/img/m.gif' ;
	
	  } 
	  else {
		 document.getElementById('i' + identifiant).style.display = "none";
		 var obj = document.getElementById('m'+identifiant);
		 if (obj != null)
		 	obj.src = 'http://www.slaboslyszacy.pl/img/p.gif' ;
	  } 		  
   }	
   
var _catHover,_ad,_adTop,_maxScroll,_lastPos=0;

window.onload=init;
function init(){
	if(document.getElementById('ad-right'))
	{
		_ad=document.getElementById('ad-right');
		_adTop=_ad.offsetTop;
		_maxScroll=document.getElementById('main').offsetHeight+_adTop-_ad.offsetHeight;
		adScroll();
	}
}   

function adScroll(){
	if(_maxScroll>_adTop&&_lastPos!=pos())
		{
			_lastPos=pos();
			if(pos()<_maxScroll&&pos()>_adTop)
				_ad.style.top=pos()+'px';
			else if(pos()<_maxScroll)_ad.style.top=_adTop+'px';
			else _ad.style.top=_maxScroll+'px';
		}
		setTimeout('adScroll();',10);
	}

function pos(){
	if(window.innerHeight)
		return window.pageYOffset;
	else if(document.documentElement&&document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	else if(document.body)
		return document.body.scrollTop;
}	

function tabselected(element)
{
	for (var x = 1; x <= 4; x++)
		document.getElementById('tab'+x).className="";
	element.className='selected';	
}

function addComment(repdeb, repfin) {
  var input = document.commentform.comment;
  input.focus();
  if(typeof document.selection != 'undefined') {
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = repdeb + insText + repfin;
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -repfin.length);
    } else {
      range.moveStart('character', repdeb.length + insText.length + repfin.length);
    }
    range.select();
  }
  else if(typeof input.selectionStart != 'undefined')
  {
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);
    var pos;
    if (insText.length == 0) {
      pos = start + repdeb.length;
    } else {
      pos = start + repdeb.length + insText.length + repfin.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  else
  {
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Inserting at position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    var insText = prompt("Please input the text to format:");
    input.value = input.value.substr(0, pos) + repdeb + insText + repfin + input.value.substr(pos);
  }
}
	
function change_height(element, height)
{
	obj =document.getElementById(element);
	if (obj != null)
	{
		if (obj.style.height == '96px' && height == '32')
			obj.style.height = '64px';	
		else obj.style.height = height + 'px';	
	}
}

