/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function markAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                }
            }
    }

    return false;
}

/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function unMarkAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            if ( checkbox.disabled == false ) {
                checkbox.checked = false;
                }
            }
    }

    return true;
}


// JS Hover
jsHover = function() {
  var hEls = document.getElementById("menu_1").getElementsByTagName("li");
  for (var i=1, len=hEls.length; i<len; i++) {
    hEls[i].onmouseover=function() { this.className+=" jshover"; }
    hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
  }
  var hEls = document.getElementById("menu_2").getElementsByTagName("li");
  for (var i=1, len=hEls.length; i<len; i++) {
    hEls[i].onmouseover=function() { this.className+=" jshover"; }
    hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
  }
  var hEls = document.getElementById("menu_3").getElementsByTagName("li");
  for (var i=1, len=hEls.length; i<len; i++) {
    hEls[i].onmouseover=function() { this.className+=" jshover"; }
    hEls[i].onmouseout=function() { this.className=this.className.replace(" jshover", ""); }
  }
}
if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) window.attachEvent("onload", jsHover);

/**
 * increase upload inputs
 */
function incAttachments(max) {

    var id = document.getElementById('last_set').value;

    if (id < max) {

        var obj_id = 'file_' + id;
        var obj = document.getElementById(obj_id);

        obj.style.display = 'block';
        id++;
        document.getElementById('last_set').value = id;

    }
    else {

        alert('Maximum ' + max + ' files allowed to upload.');

    }

}

/**
 * make pop-up
 */
function ShowWin(url,x,y,name,isscrollbars) {
    cx=screen.width/2-(x/2);
    cy=screen.height/2-(y/2);
    isscrollbars=(isscrollbars=="no")?"no":"yes";
    window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars="+isscrollbars+",top="+cy+",left="+cx);
}

/**
 * show/hide author books block on related page
 */
function toggleAuthorBooks(id) {
    books = document.getElementById(id);
    if (books.style.display == "block") {
        books.style.display = "none";
    }
    else {
        books.style.display = "block";
    }
}


/**
 * checks if group form name field is not empty
 */

function CheckGroupForm()
{

  if ($.trim(document.GroupForm.name.value) == "")
  {
    alert("Please specify name");
    document.GroupForm.name.focus();
      return false;
  }

    document.GroupForm.submit();

}

/**
 * checks if group form name field is not empty
 */


function CheckUserForm()
{

  if ($.trim(document.UserForm.lgn.value)== "")
     {
        alert("Please specify login");
        document.UserForm.lgn.focus();
        return false;
     }


  var cs = document.getElementById('UserForm').getElementsByTagName('input');
  var checkboxes = 0;

    for ( var i = 0; i < cs.length; i++ ) {
        if (cs[i].checked == true ) {
            checkboxes++;
        }
    }

    if (checkboxes == 0) {
            alert("Please select at least one group");
            return false;
    }

    document.UserForm.submit();
}


