
function isParent(child, parent) {
    if (!child || !parent) {
        return false;
    }
    while (true) {
        if (child == parent) {
            return true;
        }
        if (child.parentElement) {
            child = child.parentElement;
        } else if (child.parentNode) {
            child = child.parentNode;
        } else {
            return false;
        }
    }
}

function toggleSearchBlock(){
	var s = $('options');
	if (s.visible()){
		s.hide();
	} else {
		s.show();
	}
}

function selectOption(link, name, id) {
	$('xcategory').value = id;
	//$('search_in').update(name);
	initOptions();
	$('options').hide();
	link.addClassName('search_sel_option');
	//$('').addClassName('search_sel_option');
}

Event.observe(window, 'click', function(e){
	var clickBlock = $('options');
	var clickLink = $('search_in');
	var clickLink1 = $('searchpopup_link');
	
	if (!clickBlock) return false;
    var el = Event.element(e);   
    if ((el != clickLink) && (el != clickLink1) && clickBlock.visible()){
        if(!isParent(el, clickBlock)) {
            clickBlock.hide();
        }
    }
})

function initOptions(){
	$$('.options a').each(function(e){
		e.removeClassName('search_sel_option');
	})
}

