function showhide(id){if(document.getElementById(id).style.display!='none')hide(id);else show(id);}
function show(eid){document.getElementById(eid).style.display='';}
function hide(eid){document.getElementById(eid).style.display='none';}
function setStars(val,detail){for(var i=1;i<=5;i++)
if(i<=val)document.getElementById(detail+'star'+i).src='http://crazyfarm.de/images/symbols/star1.png';else document.getElementById(detail+'star'+i).src='http://crazyfarm.de/images/symbols/star0.png';}
function getTimeLeft(sec){h=Math.floor(sec/3600);m=Math.floor((sec-(h*3600))/60);s=Math.floor(sec-((h*3600)+(m*60)));if(h&&m<10)m='0'+m;if((h||m)&&s<10)s='0'+s;return(h?h+'h ':'')+(m?m+'m ':'')+s+'s';}

function ajax(str,val,repl,caller){
	var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	var result;
	xmlhttp.open("GET",'/ajax/'+str+'?val='+val+'&symbol=1&target='+repl+'&caller='+caller+'&rand='+Math.floor(Math.random()*1000),true); 
	xmlhttp.onreadystatechange = function(){ 
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
			if(repl) result = document.getElementById(repl).innerHTML = xmlhttp.responseText;
		}
	} 
	xmlhttp.send(null);
	return result;
}

function ajaxSearch(obj,box,mode){
	if(!obj.value){
		hide(box);
		return;
	}
	el = document.getElementById(box);
	el.style.width = (obj.offsetWidth-10)+'px';
	el.style.left = obj.offsetLeft+'px';
	el.style.top = (obj.offsetTop+obj.offsetHeight-1)+'px';
	result = ajax('search'+(mode ? '/'+mode : ''),obj.value,box,obj.id);
	if(result != '') show(box);
	else hide(box);
}