var oForm;

function InitializeSearch()
{
    if (g_bGetForm)
        oForm = GetElement("oSearchForm");
    else
        oForm = oSearchForm;
    oForm.oSearchText.focus();
}

function SelectAscDesc()
{
    if (oForm.SearchSort1.checked || oForm.SearchSort5.checked)
            oForm.SearchOrder2.checked = true;
    else
            oForm.SearchOrder1.checked = true;
}

function ValidateForm()
{
    var strText = oForm.oSearchText.value;
    strText = strText.replace(/<!--/g, " ");  // zacatek HTML komentare
    strText = strText.replace(/-->/g, " ");  // konec HTML komentare
    strText = strText.replace(/<[^>]*>/g, " ");  // HTML tagy
    strText = strText.replace(/[!']/g, " ");  // nepovolene znaky

    // pokud nehledame frazi, smazeme jednopismenna slova
    if (oForm.SearchType3.checked == false)
    {
        var strTemp;
        do
        {
            strTemp = strText
            strText = strTemp.replace(/(\s|^)[^\s](\s|$)/g, " ");
        } while (strText != strTemp);
    }

    strText = strText.replace(/\s+/g, " ");  // whitespace nahradime jednou mezerou
    strText = strText.replace(/^ /, "");  // smazeme mezeru na zacatku
    strText = strText.replace(/ $/, "");  // smazeme mezeru na konci

    oForm.oSearchText.value = strText;
    if (strText == "")
    {
        oForm.oSearchText.focus();
        return false;
    }
    if (strText.length < 2)
    {
        alert("Zadejde prosím alespoň 2 znaky!");
        oForm.oSearchText.focus();
        return false;
    }    

    return true;
}

