$(document).ready(function () {
    $('#tabs').tabs();
	$('.notice, .success, .error').hide();
    $('.notice, .success, .error').fadeIn('slow');
    $('#check_all').toggle(function() {
        $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
        }, function() {
            $('input[type=checkbox]:checked').removeAttr('checked');
        });
    return false;
});
$(function() {
    $('.confirm').click(function(){
        var text = 'Are you sure you want to delete this from your thread log?';
        return confirm(text);
        });
});


function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
} // end getElementByClass

function quotePlain(post_div_id,sTextarea_id) {
    div = document.getElementById(post_div_id);
    textarea = document.getElementById(sTextarea_id);

    window.location.hash = "post";
    textarea.value += "<blockquote>" + div.innerHTML + "</blockquote>\n\n";
    textarea.focus();
    setCaretToEnd(textarea);

    return true;
} // end quote

function quoteTinyMce(post_div_id,tinyMCE) {
    div = document.getElementById(post_div_id);
    
    window.location.hash = "post";
    tinyMCE.execInstanceCommand('mce_editor_0','mceInsertContent',false,"<blockquote>" + div.innerHTML + "</blockquote>\n\n");
}

function addToField(container_id)
{
    maxTo = 5;
    button = document.getElementById('add_to');
    container = document.getElementById(container_id);
    if(container == null) return false;
    
    fields = getElementsByClass('to_field',container);
    if(fields.length >= maxTo) 
    {
        button.style.display = 'none'; 
        return false;
    }

    copy = fields[0].cloneNode(false);
    copy.value = ''; 

    if((fields.length + 1) == maxTo) button.style.display = 'none'; 

    br = document.createElement('BR');
    container.appendChild(br);
    container.appendChild(copy);

    return true;
} // end addToField

function imagePicker(file,url_base,image_id,hide_if_null)
{
    if(hide_if_null == null) hide_if_null = true;
    
    image = document.getElementById(image_id);
    if(image == null) return false;

    if(file == '')
    {
        if(hide_if_null == true) image.style.display = 'none';
        return true;
    }
    
    image.src = url_base + file;
    image.style.display = '';

    return true;
} // end avatarPicker

function setCaretToEnd(element) 
{
    var pos = element.value.length;
    if(element.createTextRange) 
    {
        var range = element.createTextRange();
        range.moveStart('character', pos);
        range.select();
    } 
    else if(element.setSelectionRange) 
    {
        element.setSelectionRange(pos, pos);
    }
} // end setCaretToEnd

function doForumAdminConfirms(action) {
    if(action == null) return false;
    confirmation_text = '';
    if(action == 'delete_post'){
         confirmation_text = 'Are you sure you wish to delete this post?';
    }
    else if(action == 'delete_thread'){
        confirmation_text = 'Are you sure you wish to delete this ENTIRE THREAD?';
    }
    else{
        return true;
    }

    return confirm(confirmation_text);
}
