function currentButton($bt) {
    $buttons = document.getElementsByName($bt.name);
    for ($i = 0; $i < $buttons.length; $i++) {
        $buttons[$i].className='';
    }
    $bt.className='current';
}

function closePopup() {
    xajax.$('popup').innerHTML='';
}

function account_DeleteFriend($login) {
    if ( confirm("Вы действительно хотите удалить "+$login+" из друзей ?") ) {
        account_Proced_DeleteFriend($login);
    }
}

function bookmarks_Delete($id, $element, $attribute) {
    if ( confirm("Вы действительно хотите удалить закладку ?") ) {
        bookmarks_Proced_Delete($id, $element, $attribute);
    }
}

function catalogue_DeleteCatalogue($id, $element, $attribute) {
    if ( confirm("Вы действительно хотите удалить каталог ?") ) {
        if ( confirm("Вы хотите удалить все закладки и каталоги из удаляемого каталога ?") ) {
            bookmarks_Proced_DeleteCatalogue($id, $element, $attribute, 1);
        }else{
            bookmarks_Proced_DeleteCatalogue($id, $element, $attribute, 0);
        }
    }
}

// add tag
function addTag($element, $tagName) {
    var $tagsValue = xajax.$($element).value;
    $tags = $tagsValue.split(",");
    
    var $tagExists = false;
    for(var $i=0; $i<$tags.length; $i++) {
        var $trimmedTag = $tags[$i].replace(/^\s+|\s+$/g, '');
        if ( $trimmedTag == $tagName ) {
            $tagExists = true;
            break;
        }
    }
    
    if ( $tagExists ) {
        var $newValue = "";
        for(var $i=0; $i<$tags.length; $i++) {
            var $trimmedTag = $tags[$i].replace(/^\s+|\s+$/g, '');
            if ( $trimmedTag != $tagName ) {
                if ( $newValue != "" ) {
                    $newValue = $newValue + ", ";
                }
                $newValue = $newValue + $trimmedTag;
            }
        }
        xajax.$($element).value = $newValue;
    }else{
        if ( $tagsValue != "" ) {
            $tagsValue = $tagsValue + ", ";
        }
        xajax.$($element).value = "" + $tagsValue + $tagName;
    }
}
function chars(textarea, input) {
    xajax.$(input).value = xajax.$(textarea).value.length;
}
