function getHostname(url) {
	var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
	return url.match(re)[1].toString();
}
if (getHostname(window.location.href) == 'localhost') dir = 'http://localhost/midiarte/';
else dir = 'http://www.midiarte.pt/';

function ajaxsearch(oEvent) {
    oEvent = oEvent || window.event;
    var txtField = oEvent.target || oEvent.srcElement;
    var oXmlHttp = zXmlHttp.createRequest();
	if (txtField.value.length < 3) return false;
	//dir = window.location.href.indexOf(".com/users.html")==-1 && window.location.href.indexOf(".eu/users.html")==-1 ?  "../" : "";
    oXmlHttp.open("get", dir+"ajax_search.php?s=" + encodeURIComponent(txtField.value), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                var arrInfo = oXmlHttp.responseText.split("||");
                var divSearch = document.getElementById("ajaxsearch");
                if (!eval(arrInfo[0])) {
                    document.getElementById("ajaxresults").innerHTML = arrInfo[1];
					divSearch.style.display = 'block';
					o = document.getElementById('txtajaxsearch');
					var pos = get_obj_pos(o);
					divSearch.style.top = (pos[1]+20) + "px";
					divSearch.style.left = pos[0]+ "px";
                } else {
                }
            } else {
				//alert("An error occurred while trying to contact the server.");
            }
        }
    };
    oXmlHttp.send(null);
};
function get_obj_pos(obj) {
	var x = 0;
	var y = 0;
	while (obj.offsetParent) {
		x += obj.offsetLeft;
		y += obj.offsetTop;
		obj = obj.offsetParent;	}
	return [ x, y ];
}
window.onload = function () {
    if (zXmlHttp.isSupported()) {
        var txtSearch = document.getElementById("txtajaxsearch");
		txtSearch.onkeyup = ajaxsearch;
	}
}
document.onclick = function (oEvent) {
    var oEvent = oEvent || window.event;
    o = oEvent.target || oEvent.srcElement;
	if (o.id != 'ajaxsearch' && o.id != 'txtajaxsearch') { document.getElementById("ajaxsearch").style.display = 'none'; }
	
}
function Go(x) {parent.location= x; }
function show(id) {
	o = document.getElementById(id);
	butt = document.getElementById(id+'b');
	if (o.style.display=='table-row' || o.style.display=='block') { 
		if (butt) butt.className += ' on';
		o.style.display='none';
	}
	else {
		if (butt) butt.className = '';
		if (navigator.userAgent.indexOf("MSIE")!=-1) o.style.display='block';
		else o.style.display='table-row';
	}
}
function tab(id,group) {
	var styles = new Array('midi','audio','multi');
	for(var i=0; i<styles.length; i++) {
		var el = group+styles[i];
		if (styles[i]==id) { document.getElementById(el).style.display='block'; document.getElementById(el).style.width='698px'; }
		else { document.getElementById(el).style.display='none'; }
	}
}