function changeCaptcha(){
	var url = "captcha_ajax.php?random=" + Math.random();

	if (window.ActiveXObject){
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		httpRequest = new XMLHttpRequest();
	}
	httpRequest.open("GET", url, true);
	httpRequest.onreadystatechange = function () {processRequest();};
	httpRequest.send(null);
}

function processRequest(){
	if (httpRequest.readyState == 4){
		if(httpRequest.status == 200){
			var captchaPlace = document.getElementById("captchaPlace");
			var captchaLoader = document.getElementById("captchaLoader");
			captchaPlace.style.display = "block";
			captchaLoader.style.display = "none";
			captchaPlace.innerHTML = httpRequest.responseText;
		}
		else {
			alert("Chyba při načítání stránky "+ httpRequest.status +" : "+ httpRequest.statusText);
		}
	}
	else {
		var captchaLoader = document.getElementById("captchaLoader");
		var captchaPlace = document.getElementById("captchaPlace");
		captchaPlace.style.display = "none";
		captchaLoader.style.display = "block";
	}
}

function replace_atsigns(){
	links = document.getElementsByTagName('a');
	for(i = 0; i < links.length; i++){
		var hrf = links[i].href;
		hrf = hrf.replace(/( |%20)\[zavin(áč|%C3%A1%C4%8D)\]( |%20)/,'@');
		links[i].href = hrf;
		
		var ttl = links[i].title;
		ttl = ttl.replace(/( |%20)\[zavin(áč|%C3%A1%C4%8D)\]( |%20)/,'@');
		links[i].title = ttl;
		
		var val = links[i].innerHTML;
		val = val.replace(/( |%20)\[zavin(áč|%C3%A1%C4%8D)\]( |%20)/,'@');
		links[i].innerHTML = val;
	}
	spans = document.getElementsByTagName('span');
	for(i = 0; i < spans.length; i++){		
		var val = spans[i].innerHTML;
		val = val.replace(/( |%20)\[zavin(áč|%C3%A1%C4%8D)\]( |%20)/,'@');
		spans[i].innerHTML = val;
	}
}

function do_links(){
	js_links = document.getElementsByTagName('h2');
	for(i = 0; i < js_links.length; i++){
		element = js_links[i];
		if (element.className == 'doLink')
			element.style.cursor = 'pointer';
	}
	js_links = document.getElementsByTagName('h3');
	for(i = 0; i < js_links.length; i++){
		element = js_links[i];
		if (element.className == 'doLink')
			element.style.cursor = 'pointer';
	}
	js_links = document.getElementsByTagName('img');
	for(i = 0; i < js_links.length; i++){
		element = js_links[i];
		if (element.className == 'doLink')
			element.style.cursor = 'pointer';
	}
}

function do_new_window_opening(){
	js_links = document.getElementsByTagName('a');
	for(i = 0; i < js_links.length; i++){
		element = js_links[i];
		if (element.className == 'doNewWindow')
			element.onclick = function() {
				var win = window.open(this.href);
				win.focus();
				return false;
			};
	}
}

function change_search_type(type){
	var frm = document.getElementById("searchForm");
	if (type == 1){
		frm.action = "search.php";
		frm.method = "post";
	}
	else {
		frm.method = "get";
		frm.action = "http://www.klemi.cz/google_search.php";
	}
}

function toplist_stats(){
	document.write ('<img src="http://toplist.cz/dot.asp?id=834308&amp;http='+escape(document.referrer)+'&amp;wi='+escape(window.screen.width)+'&amp;he='+escape(window.screen.height)+'&amp;cd='+escape(window.screen.colorDepth)+'&amp;t='+escape(document.title)+'" width="1" height="1" alt="TOPlist" />');
}

window.onload = startup;

function startup(){
	replace_atsigns();
	do_links();
	do_new_window_opening();
}