// For more information, visit http://jQueryHelp.ning.com/forum/topics/blog-hack-categories or email TJ at TJ@BKServ.com


var gBT_Status = ' BlogTags Status...';  // Global BlogTags status message.
// Pre-determined Blog Tags List:
var gBT_Options = '<option>Agency Recruiting</option><option>Corporate Recruiting</option><option>Human Resources</option><option>Job Seekers</option><option>Recruiting Tools / Sourcing</option>';

var gBT_Website = 'http://www.recruitingblogs.com';  // Where Search results go to, set to site that is using this code.

var gBT_Location = window.location.href + '';


// Add Selection from the Pre-determined Blog Tags List to Tags:
if (gBT_Location.indexOf('/forum/topic/new') > 0) {

    // Disable Publish Post button when tags is blank!
    x$('input.action-primary').attr('disabled', 'disabled');
    x$("input#tags").blur(function() {
        var current_val = x$("input#tags").val();
        if (current_val.length > 0) x$('input.action-primary').removeAttr('disabled'); else x$('input.action-primary').attr('disabled', 'disabled');
    });    
    
    // Inject the list:
    var TJBlogTagsList = '<div id="TJBlogTagsWrapper"><select id="TJBlogTags"><option>[Select a Popular Tag]</option>' + gBT_Options + '</select><span id="TJAddBlogMsg"> *Please add at least one tag</span></div>';
    x$("input#tags").parent().append(TJBlogTagsList);
    
    // Do when a list item is selected:
    x$("#TJBlogTags").change(function() {
        var selTag = x$("#TJBlogTags option:selected").text() + '';
        if (selTag.substr(0, 1) != '[') {  // Tags starting with [ are not selectable.
            // If tag has a space in it, it is a multi word tag and must be inside quotes.
            if (selTag.indexOf(' ') > -1) selTag = '"' + selTag + '"';
            var current_val = x$("input#tags").val();
            if (current_val.length > 0) current_val += ", " + selTag; else current_val = selTag;
            x$("input#tags").val(current_val);
            // Member added a tag from the list, enable Publish Post button!
            x$('input.action-primary').removeAttr('disabled');
        }
    });
}

// Search for Blogs with tag equal to the Selection from the Pre-determined Blog Tags List:
if (gBT_Location.indexOf('forum/topic/listForTag') > 0) {
    var TJBlogTagsSearchList = 'Find by Most: <select id="TJBlogTagsSearch"><option>[Popular Tags]</option>' + gBT_Options + '</select>';
    x$(".module_searchbar p.right").prepend(' &nbsp; ' + TJBlogTagsSearchList);
    x$("#TJBlogTagsSearch").change(function() {
        var selTag = x$("#TJBlogTagsSearch option:selected").text();
        if (selTag.substr(0, 1) != '[') {  // Tags starting with [ are not selectable.
            window.location = gBT_Website + '/profiles/blog/list?tag=' + selTag;
        }
    });
}
