/**
 *  @fileoverview Groups together functions relating to
 *                Search Pages in the application
 *  @author Adrian Mclaughlin
 *  @version 1
 */

/**
 * Highlights a selected row in a table and checks a checkbox and unchecks the
 * other checkboxes in the table
 *
 * @param {Object} element DOM Element
 */
function selected(element) {
    $('.checked').each(function() {
        var checkbox = $(this);
        checkbox.removeClass('checked');
        checkbox.prop('checked', false);
    });
    if (element != null) {
        element = $(element);
        element.addClass('checked');
        element.find('input[type=\'checkbox\']').prop('checked', true);
        console.log(element);
    }

}

/**
 * Remove the event onsubmit for the add button
 *
 * @param {Object} button HTML DOM Element
 */
function addClicked(button) {
    var forms = document.getElementsByTagName('form');
    if (forms != null && forms.length > 0) {
        forms[0].onsubmit = '';
    }
}

/**
 * Test to see that at least one checbox has been checked Displays an alert box
 * if no checkboxes have been checked ToDo refactor to use jquery
 *
 * @param {Object}
 *            form element to be checked
 * @param {string}
 *            itemName The user friendly name of the element that should be
 *            selected
 * @param {Object}
 *            alertDiv The div element to display an error message if required
 * @return {Boolean} true if an itemName has been selected
 */
function isChecked(form, itemName, alertDiv) {
    var list = document.getElementsByName('edit');
    console.log(list.length + '\n');
    var checked = false;
    for (var t in list) {
        console.log(list[t] + ' ' + list[t].checked + '\n');
        if (list[t].checked) {
            checked = true;
        }
    }
    if (!checked) {
        var alertBox = document.getElementById(alertDiv);
        if (alertBox != null) {
            alertBox.innerHTML = '<Strong>Error:</Strong>A ' + itemName +
                    ' is not selected';
            alertBox.style.display = 'block';
        } else {
            alert('A ' + itemName + ' is not selected');
        }
        $(document).click(function() {
            $('#' + alertDiv).hide();
        });
        return false;
    } else {
        return true;
    }
}

/**
 * Sets the value of an input element to edit
 *
 * @param {Object} id HTML input element
 */
function enable(id) {
    id.value = 'edit';
}

/**
 * function is executed when script is loaded
 */
$(document).ready(function() {
    /*
     * Stops the search menu closing when clicked on
     * http://stackoverflow.com/questions/10863821/bootstrap-dropdown-closing-when-clicked
     */
    $('.navbar-form').click(function(e) {
        e.stopPropagation();
    });
    /* The user's enter keypress on the search element should submit a search */
    $('.navbar-form').keypress(function(e) {
        var code = (e.keyCode ? e.keyCode : e.which);
        if (code == 13) {
            $('#search-btn').click();
            e.stopPropagation();
            return false;
        }
    });
});

@@ -672,38 +672,8 @@
 e);%0A
-        console.log(element);%0A
     
@@ -1545,45 +1545,8 @@
 ');%0A
-    console.log(list.length + '%5Cn');%0A
     
@@ -1604,61 +1604,41 @@
     
-console.log(list%5Bt%5D + ' ' + list%5Bt%5D.checked + '%5Cn');%0A
+if(list.hasOwnProperty(t)) %7B%0A    
     
@@ -1672,24 +1672,28 @@
             
+    
 checked = tr
@@ -1692,24 +1692,38 @@
 ked = true;%0A
+            %7D%0A
         %7D%0A  
@@ -2902,16 +2902,17 @@
 (code ==
+=
  13) %7B%0A 

fix bugs