var timo = null;
function timoSet(func, time) {
	clearTimeout(timo);
	timo = null;
	
	timo = setTimeout("eval("+func+")", time);
}

function intSuggest(that, categ) {
	
	var suggBox = $('addIntSuggest');
	if (categ == 'hide') {
		var timo2 = null;
		hideit = function() {
			suggBox.style.display = 'none';
		}
		if (timo2) {
			clearTimeout(timo2);
			timo2 = null;
		}
		timo2 = setTimeout("hideit()", 400);
	}
	else if (typeof(categ) == 'number') {
		suggBox.innerHTML = '';
		suggBox.style.display = 'block';
		suggBox.style.position = 'absolute';
		suggBox.style.top = that.offsetTop + that.offsetHeight + 'px';
		suggBox.style.left = that.offsetLeft + 'px';
	}
}

function usrGetSuggests(that, categ) {
	if (timo) {
		clearTimeout(timo);
		timo = null;
	}
	timo = setTimeout(
        function() {
            if (that.value.length > 2) {
                myAJAX({
                    url: '/modules/interests/ajax_handle.php?action=suggest',
                    data: {
                        cat_id: categ,
                        search: that.value
                    },
                    onSuccess: function (res) {
                        $('addIntSuggest').innerHTML = res;
                    }
                });
            }
        }, 1000);
}
function doComplete(that, catid) {
	var field = $('addInterestN' + catid);
	field.value = that.innerHTML;
	intSuggest(null, 'hide');
}
function delInterest(link, intid) {
	myAJAX({
			url: '/modules/interests/ajax_handle.php?action=del_interest',
            data: {
                intid: intid
            },
            onSuccess: function () {
                fadeOut(link.parentNode, 100, function () {link.parentNode.parentNode.removeChild(link.parentNode)});
            }
	});
}
function addUsrInterest(catid, inp) {
	if (inp.value.length > 2) {
		myAJAX({
			url: '/modules/interests/ajax_handle.php?action=add_interest',
			data:{
                catid: catid,
                txt: inp.value
            },
            onSuccess: function (res) {
                inp.value = '';
                var ul = inp.parentNode.parentNode.getElementsByTagName('ul')[0],
                    li = document.createElement('li');
                
                li.onmouseout = function () {this.className = ''};
                li.onmouseover = function () {this.className = 'del'};
                li.innerHTML = res;
                ul.insertBefore(li, ul.getElementsByTagName('li')[0]);
            }
		});
	}
}
function addInterest(catid, link) {
	
    myAJAX({
        url: '/modules/interests/ajax_handle.php?action=add_interest',
        data:{
            catid: catid,
            txt: link.parentNode.getElementsByTagName('a')[0].innerHTML
        },
        onSuccess: function (res) {
            var li = link.parentNode;
            
            li.removeChild(link);
            li.className ='';
            li.onmouseover = null;
            li.onmouseout = null;
            li.getElementsByTagName('img')[0].src='http://i.kefche.net/ic/b/intr_add.gif';
        }
    });
}