<!-- basic javascript procedures -->

function textCounter(field, countfield, maxlimit) {
        if (field.value.length > maxlimit)
                field.value = field.value.substring(0, maxlimit);
        else
                countfield.value = maxlimit - field.value.length;
}


// clear the select box (dropdown)
function resetSelect(obj, startIndex)
{
        if(startIndex == null) starIndex = 1;
        while (obj.options.length > startIndex)
        {
                deleteIndex = obj.options.length-1;
                obj.options[deleteIndex] = null;
        }
}

//copies an entire select content to another
function cloneSelectContent(src, dst)
{
        resetSelect(dst, 0);
        for(i = 0; i < src.options.length; i++)
        {
                dst.options[dst.options.length] = new Option(src.options[i].text, src.options[i].value);
        }
}

function easyFriendlyUrl(category_title){

                var str = "";
                var i;
                var exp_reg = new RegExp("[a-zA-Z0-9_\n]");
                var exp_reg2 = new RegExp("[ ]");
                var exp_reg3 = new RegExp("[&]");

                category_title.toString();

                for(i=0 ; i < category_title.length; i++){
                        if(exp_reg.test(category_title.charAt(i))){
                                str = str+category_title.charAt(i);
                        } else {
                                if(exp_reg2.test(category_title.charAt(i))) {
                                        if(str.charAt(str.length-1) != "_"){
                                                str = str+"_";
                                        }
                                }
                                if(exp_reg3.test(category_title.charAt(i))) {
                                        str = str + "and";
                                }
                        }
                }

                if(str.charAt(str.length-1) == "_")
                        str = str.substr(0, str.length-1);

                document.getElementById('friendly_url').value = str;
}
