var links_width = 0;
var elem;
var rc_div=null;
var status=0;


function activate_searchbox(button)
{
    if (rc_div==null)
        rc_div = button.parentNode;
    var form = button.nextSibling;
    if (form.nodeName!="FORM")
    	form = form.nextSibling;
    var links = button.previousSibling;
    if (form.children[0].value=="")
    {
        if (status==0)
        {
            //rc_div.style.width = "";
            //links.style.position = "static";
            links.style.width = "1px";
            form.style.visibility = "visible";
            form.style.width = "256px";
            compress_menu();
            elem=form;
            setTimeout('elem.children[0].focus();',500);
            //setTimeout('rc_div.style.width="'+(links_width+26)+'px";',500);
            status=1;
        }
        else
        {
            //rc_div.style.width = "";
            form.style.width = "1px";
            //form.style.visibility = "hidden";
            links.style.width = links_width+"px";
            compress_menu();
            elem=form;
            setTimeout('elem.style.visibility = "hidden";',500);
            //setTimeout('rc_div.style.width="'+(256+26)+'px";',500);
            status=0;
        }
        setTimeout('compress_menu();',500);
    }
    else
        verify_submit(form);
}

function hide()
{
    el2hide.style.display = "none";
}

function prepare_links()
{
    var links = document.getElementById('login');
    if (links.style.display == 'block' && links_width==0)
        links_width = links.offsetWidth;
    links.style.width = links_width+"px";
    elem=links;
    setTimeout('elem.style.webkitTransition = "width 0.5s"; compress_menu();',500);
}

function show_hide_search_form()
{
	formular=document.getElementById("search_form");
	img=document.getElementById("show_search");
	linkuri=document.getElementById("login");
	if (formular.style.display == "inline")
	{
		linkuri.style.display = "inline";
		formular.style.display = "none";
		img.title="Afiseaza campul de cautare";
	}
	else
	{
		formular.style.display = "inline";
		linkuri.style.display = "none";
		img.title="Ascunde campul de cautare";
		with (formular)
		{
			criteria.focus();
			criteria.value="";
		}
	}
}



// show and hide submit button and show form button
function show_hide_submit_search(field)
{
	buton=document.getElementById("submit_search");
	imag=document.getElementById("show_search");
	with (field)
	{
		if (value==null || value=="")
		{
			buton.style.display = "none";
			imag.style.display = "inline-block";
		}
		else
		{
			buton.style.display = "inline";
			imag.style.display = "none";
		}
	}
}

//check if the given filed is empty
function verify_field(field)
{
	with (field)
	{
		if (value==null || value=="")
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

//check if the user is submiting an empty search
function verify_submit(thisform)
{
	with (thisform)
	{
		if (verify_field(criteria)==false)
		{
			criteria.focus();
			return false;
		}
		else
		{
            var search_str = criteria.value;
            search_str = search_str.replace(/"/g,"'");
            window.location = "search(criteria="+encodeURI(search_str)+").html";
			return false;
		}
	}
}

