function vyhledavani()
{
    if(document.getElementById('search-input').value=="vyhledávání...")
    {
        document.getElementById('search-input').value="";
        document.getElementById('search-input').style.color="#EEE";
        document.getElementById('search-input').style.fontStyle="normal";
        document.getElementById('search-input').style.fontWeight="none";
    }
}

function vyhledavani2()
{
    if(document.getElementById('search-input').value=="")
    {
        document.getElementById('search-input').value="vyhledávání...";
        document.getElementById('search-input').style.color="#ddd";
        document.getElementById('search-input').style.fontStyle="italic";
        document.getElementById('search-input').style.fontWeight="bold";
    }
}

function odeslat_search()
{
    if(document.getElementById('search-input').value=="" || document.getElementById('search-input').value=="vyhledávání...")
    {
        alert("Musíte zadat platný řetězec, který chcete vyhledat.");
    }
    else
    {
        var retezec = encodeURIComponent(document.getElementById('search-input').value);
        document.location.href="/search/"+retezec;
    }
}

function setWidth(width,height,ids)
{
    if($(ids).innerWidth()>width)
    {
        $(ids).attr("width",width);
        if($(ids).innerHeight()>height)
        {
            $(ids).attr("height",height);
            $(ids).removeAttr("width");
        }
        mergeHeight();
    }
    else if($(ids).innerHeight()>height)
    {
        $(ids).attr("height",height);
        if($(ids).innerWidth()>width)
        {
            $(ids).attr("width",width);
            $(ids).removeAttr("height");
        }
        mergeHeight();
    }
}

function verifyNumber(inputText)
{
    var ValidChars = "0123456789";
    var Char;
    inputText += "";

    for (var i = 0; i < inputText.length; i++)
    {
        Char = inputText.charAt(i);
        if (ValidChars.indexOf(Char) == -1)
        {
            return false;
        }
    }

    return true;
}

function mergeHeight()
{
    height1 = $("#vlevo").height();
    height2 = $("#vpravo").height();
    if(height1 > height2)
    {
        difference = height1 - height2;
        margin = (difference/2)+30;
        if(verifyNumber(margin)==false)
        {
            margin1 = margin - 0.5;
            margin2 = margin + 0.5;
        }
        else
        {
            margin1 = margin;
            margin2 = margin;
        }
        $("#vpravo .frame").css("margin", margin1 + "px 30px " + margin2 + "px 30px");
    }
    else if(height1 < height2)
    {
        difference = height2 - height1;
        margin = (difference/2)+30;
        if(!verifyNumber(margin))
        {
            margin1 = margin - 0.5;
            margin2 = margin + 0.5;
        }
        else
        {
            margin1 = margin;
            margin2 = margin;
        }
        $("#vlevo .frame").css("margin", margin1 + "px 30px " + margin2 + "px 30px");
    }
}
