//POZOR - musi byt naprosto stejna funkce jako v PHP fce.php!!!!
function remove_diacritics (str) {
    sdiak = "áäčďéěëí?ĺľňóô öŕšťúů üý?řžÁÄČĎÉĚËÍ?ĹĽŇÓÔ ÖŔŠŤÚŮ ÜÝŘŽ";
    bdiak = "aacdeeeiillnoo orstuu uyyrzAACDEEEIILLNOO ORSTUU UYRZ";
    pom = "";
    for(i = 0; i < str.length; i++) {
        if (sdiak.indexOf(str.charAt(i)) != -1) {
            pom = pom + bdiak.charAt(sdiak.indexOf(str.charAt(i)));
        }
        else pom = pom + str.charAt(i);
    }
    return pom;
}

function strToLower (str) {
    big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    small = "abcdefghijklmnopqrstuvwxyz";
    pom = "";
    for(i = 0; i < str.length; i++) {
        if (big.indexOf(str.charAt(i)) != -1) {
            pom = pom + small.charAt(big.indexOf(str.charAt(i)));
        }
        else pom = pom + str.charAt(i);
    }
    return pom;
}

//POZOR - musi byt naprosto stejna funkce jako v PHP fce.php!!!!
function create_cool_url(str) {
    var enable_char = /^([a-zA-Z0-9_ \\/\-])$/;
    str = remove_diacritics(str);
    str = strToLower(str);
    pom = "";
    for (i = 0; i < str.length; i++) {
        if (enable_char.test(str.charAt(i))) {
            if (str.charAt(i) == " " || str.charAt(i) == "-" || str.charAt(i) == "_" || str.charAt(i) == "/" || str.charAt(i) == "\\") {
                if (pom.charAt(pom.length - 1) != "-" && i+1 != str.length) pom = pom + "-";
            }
            else pom = pom + str.charAt(i);
        }
    }
    return pom;
}

//dle http://www.december.com/html/spec/esccodes.html
function create_escape_URL(str) {
    pom = "";
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == " ") pom = pom + '%20';
        else if (str.charAt(i) == "&") pom = pom + '%26';
        else pom = pom + str.charAt(i);
    }
    return pom;
}
function create_ajax_escape_URL(str) {
    pom = "";
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == "&") pom = pom + '%26';
        else pom = pom + str.charAt(i);
    }
    return pom;
}

//zjisti jestli je v poli obsazena arr obsazena hodnota s
function in_array(arr,s) {
    for (var i=0; i < arr.length; i++) {
        if (arr[i] == s) return true;
    }
    return false;
}

//v URL na hrazuje za znak & escape %26 - ale jenom v hodnote!
//napr. index.php?page=rest&aurace&type=denni-menu  -> index.php?page=rest%26aurace&type=denni-menu
//CHYBA - nefunguje jak ma!!!!!
/*function create_ajax_escape_URL(str) {
    pom = "";
    poz = new Array();
    x = 1;
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == "&") {
            poz[x] = i;
            x = x + 1;
        }
        if (str.charAt(i) == "=") {
            poz[x-1] = -1;
        }        
    }
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == "&" && in_array(poz,i)) pom = pom + '%26';
        else pom = pom + str.charAt(i);
    }
    return pom;
} */

function create_keywords (a,b,c,d,e) {
    pom = "";
    if (a != "" && a != "-----") pom = a;
    if (b != "" && b != "-----") {
        if (pom == "") pom = b;
        else pom = pom + ', ' + b;
    }
    if (c != "" && c != "-----") {
        if (pom == "") pom = c;
        else pom = pom + ', ' + c;
    }
    if (d != "") {
        if (pom == "") pom = d;
        else pom = pom + ', ' + d;
    }
    if (e != "") {
        if (pom == "") pom = e;
        else pom = pom + ', ' + e;
    }
    return pom;
}

function create_description (str) {
    pom = "";
    if (str.length <= 150) return str;
    else {
        for (i = 0; i < 151; i++) pom = pom + str.charAt(i);
    }
    return pom;
}
