function changeActionForGetForm(action, form) {
    var lastMethod = form.method;
    form.action = action;
    form.method="post";
    defaultSubmit();
    form.method=lastMethod;
}

function replace(stf,old,rplc) {
    var New='';
    while (stf.indexOf(old)!=-1) {
        var strt=stf.indexOf(old);
        New+=stf.substring(0,strt);
        New+=rplc;
        stf=stf.substring(strt+old.length,stf.length);
    }
    return New+stf;
}

function escapeHTML(text) {
    text=replace(text,'&','&amp;');
    text=replace(text,'<','&lt;');
    text=replace(text,'>','&gt;');
    text=replace(text, '"', '&quot;');
    return text;
}

function unEscapeHTML(text) {
    text=replace(text, '&amp;', '&');
    text=replace(text, '&lt;', '<');
    text=replace(text, '&gt;', '>');
    text=replace(text, '&quot;', '"');
    return text;
}

function normalize (str){
    while (str.indexOf('  ') != -1){
        str = str.replace('  ', ' ');
    }
    if (str == ' ')
        str = '';
    if (str.length > 0)
        if (str.charAt(0) == ' ')
            str = str.substr(1, str.length - 1);
    if (str.length > 0)
        if (str.charAt(str.length - 1) == ' ')
            str = str.substr(0, str.length - 2);
    return str;
}

function getWithCapitalizedFirstChar(word) {
    if (word == null || word.length == 0) {
        return word;
    }
    var firstChar = word.substr(0, 1);
    firstChar = firstChar.toUpperCase();
    var result = firstChar + word.substr(1, word.length);
    return result;
}

function getWithCapitalizedFirstChars(string) {
        var words = string.split(" ");
        var result = "";
        for (var i = 0; i < words.length; i++){
            words[i] = getWithCapitalizedFirstChar(words[i]);
            result += words[i] + " ";
        }
        return result.substr(0, result.length - 1);
    }

function arrayToString(array, delimiter) {
    var result = "";
    for (var i = 0; i < array.length; i++){
        if (!(i == array.length - 1)){
            result += array[i] + delimiter;
        } else {
            result += array[i];            
        }
    }
    return result;
}
