function closeResultDiv() {
	var livehakuWrap = document.getElementById('livehakuwrap');
	livehakuWrap.innerHTML = '';
	livehakuWrap.style.display = "none";
}

function openResultDiv() {
	document.getElementById("livehakuwrap").style.display = "block";
}

function LivehakuAjax() {
	var hakukentta = document.getElementById('mod_search_searchword');
	if(hakukentta.value == ''){
		closeResultDiv();
	}else{
		if (hakukentta.value.length < 3) {
			return;
		}
		closeResultDiv();
		var livehakuLoading = document.getElementById('livehaku_loading') ;
		livehakuLoading.style.display = '';
		var url = 'http://www.3darts.fi/www/livehaku.php?haku=' + escape(hakukentta.value);
		jx.load(url, function (data) {
			document.getElementById('livehaku_loading').style.display = 'none' ;
			document.getElementById('livehakuwrap').innerHTML = data;
			openResultDiv();}
		);
	}
}

jx = {

	http:false,
	callback:function(data){},
	error:false,
	getHTTPObject : function() {
		var http = false;
		if(typeof ActiveXObject != 'undefined') {
			try {http = new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e) {
				try {http = new ActiveXObject("Microsoft.XMLHTTP");}
				catch (E) {http = false;}
			}
		} else if (XMLHttpRequest) {
			try {http = new XMLHttpRequest();}
			catch (e) {http = false;}
		}
		return http;
	},
	load : function (url,callback) {
		this.init();
		if(!this.http||!url) return;
		if (this.http.overrideMimeType) this.http.overrideMimeType('text/xml');
		this.callback=callback;
		var ths = this;
		var now = "uid=" + new Date().getTime();
		url += (url.indexOf("?")+1) ? "&" : "?";
		url += now;
		this.http.open("GET", url, true);
		this.http.onreadystatechange = function () {
			if(!ths) return;
			var http = ths.http;
			if (http.readyState == 4) {
				if(http.status == 200) {
					var result = "";
					if(http.responseText) result = http.responseText;
					if(ths.callback) ths.callback(result);
				} else {
					if(ths.error) ths.error(http.status);
				}
			}
		}
		this.http.send(null);
	},
	init : function() {this.http = this.getHTTPObject();}
}
