
$(document).ready(function(){ admin_init(); });

//
function admin_init() {

  // set non-standard attributes
  $('form').attr('autocomplete', 'off');
  $('.setAttr-spellcheck-false').attr('spellcheck', 'false');
  $('.setAttr-wrap-off').attr('wrap', 'off');

  // add behaviour for "alert" Close buttons
  $(".close").click(function() {
    $(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
      $(this).slideUp(400);
    });
    return false;
  });

  // add Sidebar Accordian Menu effects (but not if "show expanded menu" is enabled)
  var showExpandedMenu = $('#jquery_showExpandedMenu').length;
  if (!showExpandedMenu) { admin_init_sidebar_accordian_menu(); }

}

function admin_init_sidebar_accordian_menu() {

  // add behaviour for Sidebar Accordian Menu
  $("#main-nav li a.nav-top-item").click(function () { // When a top menu item is clicked...
    $(this).parent().siblings().find("a.nav-top-item").parent().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
    $(this).next().slideToggle("normal"); // Slide down the clicked sub menu
    return false;
  });

  // add behaviour for Sidebar Accordion Menu Hover Effect
  $("#main-nav li .nav-top-item").hover(
    function() { $(this).stop().animate({ paddingRight: "25px" }, 200); },
    function() { $(this).stop().animate({ paddingRight: "15px" }); }
  );
}

//
function confirmEraseRecord(menu, num, returnUrl) {
  var message = lang_confirm_erase_record;
  var isConfirmed = confirm(message);
  if (isConfirmed) {
    window.location="?menu=" +menu+ "&action=eraseRecords&selectedRecords[]=" + num + (returnUrl ? ('&returnUrl=' + encodeURIComponent(returnUrl)) : '');
  }
}

function htmlspecialchars( str ) {
  if ( typeof( str ) == 'string' ) {
    str = str.replace( /&/g, '&amp;' );
    str = str.replace( /"/g, '&quot;' );
    str = str.replace( /'/g, '&#039;' );
    str = str.replace( /</g, '&lt;' );
    str = str.replace( />/g, '&gt;' );
  }
  return str;
}

//

