var jquery_list_id = 0;
var jquery_list_name = '';
$2(window).bind('onMouseDown', function () {
    jquery_checked(event);
});



function closeOpt(evt) {
    if (evt.keyCode == 9) {
        $2('#suggestions').css('display', 'none');
    }
}



function inputKeysDown(event, _rresults_to_div) {
	_rresults_to_div = _rresults_to_div || '';
    if (event.keyCode == 13) {
		//检查是否需要返回
		if(_rresults_to_div != ''){
			$2('#'+_rresults_to_div).html(document.getElementById('inputString').value);
			}
        if (jquery_list_id == 0 || isUndefined(jquery_list_id)) {
				var value = document.getElementById('inputString').value;
			//检查是否时光小助手
			if(value == 'admin' || value == '时光小助手' || value == '时光助手' || value == 'help' || value == '帮助' || value =='管理员'){
			time_alert('您好,我是时光小助手',150000,-1);
			return false;
			}

			if(value =='hbox'){
			time_alert('请到个人空间模式使用隐藏模块',150000,-1);
			return false;
			}

            location.href = 'network.php?name=' + escape(document.getElementById('inputString').value) + '&ac=space&searchmode=1&method=advanced';
            //doane(event);
        } else {
            location.href = 'space.php?uid=' + jquery_list_name;
        }
    }
    if (event.keyCode == 40) {
        if (jquery_list_id == 0 || isUndefined(jquery_list_id)) jquery_list_id = 0;
        else $2('#jquery_sli' + jquery_list_id).css('background', '#FFFFFF');
        var target = jquery_list_id + 1;
        if (document.getElementById('jquery_sli' + target) == null) {
            $2('#jquery_sli' + jquery_list_id).css('background', '#2C629E');
        } else {
            jquery_list_id = jquery_list_id + 1;
            $2('#jquery_sli' + jquery_list_id).css('background', '#2C629E');
            jquery_list_name = document.getElementById('jquery_sli' + jquery_list_id).title;
        }
    }
    if (event.keyCode == 38) {
        if (jquery_list_id <= 1 || isUndefined(jquery_list_id)) jquery_list_id = 1;
        else $2('#jquery_sli' + jquery_list_id).css('background', '#FFFFFF');
        var target = jquery_list_id - 1;
        if (document.getElementById('jquery_sli' + target) == null) {
            $2('#jquery_sli' + jquery_list_id).css('background', '#2C629E');
        } else {
            jquery_list_id = jquery_list_id - 1;
            $2('#jquery_sli' + jquery_list_id).css('background', '#2C629E');
            jquery_list_name = document.getElementById('jquery_sli' + jquery_list_id).title;
        }
    }
}


function jquary_mouseover() {
    if (jquery_list_id == 0 || isUndefined(jquery_list_id)) jquery_list_id = 0;
    if (!isUndefined(document.getElementById('jquery_sli' + jquery_list_id))) $2('#jquery_sli' + jquery_list_id).css('background', '#FFFFFF');
}


function jquery_checked(e) {
    var tmpv = document.getElementById('suggestions');
    if (tmpv != null && tmpv.style.display != 'none') {
        var targ;
        if (!e) var e = window.event;
        if (e.target) targ = e.target;
        else if (e.srcElement) targ = e.srcElement;
        if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;
        if (targ.name == 'jquery_aele') {
            if (targ.tagName == 'IMG') location.href = targ.id;
            else location.href = targ.href;
        } else tmpv.style.display = 'none';
    }
}

function slookup(obj, event, div, do_output){
    var inputString = obj.value;
    var my_inputbox_id = obj.id;
	div = div || 'suggestions';
	do_output = do_output || false;
	if (event.keyCode == 13 || event.keyCode == 9 || event.keyCode == 40 || event.keyCode == 38) {
        scloseOpt(event,div);
    } else {
		var obj =  $2('#'+div);
        if (inputString.length == 0) {
            obj.fadeOut(); // Hide the suggestions box
        } else {
            $2.post("./search_jquery.php", {
                queryString: "" + inputString + "",
				div: div,
                inputboxID: my_inputbox_id

            },
            function (data) { // Do an AJAX call

			    obj.fadeIn(); // Show the suggestions box
                obj.html(data); // Fill the suggestions box
            });
        }
    }
}

function scloseOpt(evt,div) {
	div = div || 'suggestions';
    if (evt.keyCode == 9) {
        $2('#'+div).css('display', 'none');
    }
}

function return_uid_name(uid,username,inputbox,div) {
	div = div || 'suggestions';
    $2('#'+inputbox).val(username);
    $2('#'+div).css('display', 'none');
    $2('#userid').val(uid);
}


function lookup(inputString, event) {
    if (event.keyCode == 13 || event.keyCode == 9 || event.keyCode == 40 || event.keyCode == 38) {
        closeOpt(event);
    } else {
        if (inputString.length == 0) {
            $2('#suggestions').fadeOut(); // Hide the suggestions box
        } else {
            $2.post("./search_jquery.php", {
                queryString: "" + inputString + ""
            },
            function (data) { // Do an AJAX call

                $2('#suggestions').fadeIn(); // Show the suggestions box
                $2('#suggestions').html(data); // Fill the suggestions box
            });
        }
    }
}