
function hideHint(inElement)
{
    inElement.removeAttribute('title');
    inElement.boHDR = "";
    inElement.boBDY = "";
} 

function disableenable(d, s)
{
	if((s.selectedIndex + 1) == s.options.length)
	  document.getElementById(d).disabled=false;
	else
	{
		document.getElementById(d).disabled=true;
		document.getElementById(d).value='';
	}
}


/**
   * show edit form
   *
   * @param action string   - action to execute
   * @param inFocus string  - set focus to element
   * @param id integer      - ID of editing item if editing
   */
  function showEditForm(action, inFocus, id){
    var inFocus = (inFocus == null) ? null : inFocus;
    var id = (id == null) ? null : id;

    // set parameters
    if (id) document.getElementById('hEditID').value = id;
    document.getElementById('hSubmitAction').value = action; // set action

    // remove all errors if any
    for(i=0; i<document.forms['fEditForm'].elements.length; i++){
      hideHint(document.forms['fEditForm'].elements[i]);
    }

    // set visibility and focus
    setEditFormVisible(true,action);
    setFocusOn(inFocus);
  }

  /**
   * sets visibility of form
   *
   * @param visibility boolean  - set form visible or hidden
   * @param action string       - action to execute
   */
  function setEditFormVisible(visibility, action){
    var action = (action == null) ? null : action;
    showHideDiv('bNew',!visibility);
    showHideDiv('newbox',visibility);
    // set parameters for custom action
    if (action){
      if ("new" == action) document.getElementById('bConfirm').value = "Dodaj";
      else
      if ("edit" == action) document.getElementById('bConfirm').value = "Popravi";
    }
  }

/**
 * shows or hides elements on page
 *
 * @param whotohide string      - id of an object to hide
 * @param visible boolean       - set object to visible or no (if non set try to guess and reverse visibility)
 * @param class_visible string  - set new class name visible class
 * @param class_hidden string   - set new class name hidden class
 * @return boolean              - return curent visibility of object
 */
function showHideDiv(whotohide, visible, class_visible, class_hidden){
  var whotohide_object = document.getElementById(whotohide);
  if (!whotohide_object) return null;
  var visible = (visible == null) ? (whotohide_object.style.visibility == 'visible') : !visible;
  // define clases for show hide if any
  var class_visible = (class_visible == null) ? null : class_visible;
  var class_hidden = (class_hidden == null) ? null : class_hidden;
  class_hidden = ((class_hidden == null) && (class_visible != null)) ? class_visible+'_hidden' : class_hidden;

  if (!visible){
    if (class_visible == null){ // no class defined just show
      //whotohide_object.style.display = (showHideDiv_display=="")?'inherit':showHideDiv_display;
      whotohide_object.style.display = 'inherit';
      whotohide_object.style.visibility = 'visible';
    }else { //set class for shown
      whotohide_object.className = class_visible;
    }
  }else{
    if (class_hidden == null){ //no class defined just hide
      //showHideDiv_display = whotohide_object.style.display;
      whotohide_object.style.display = 'none';
      whotohide_object.style.visibility = 'hidden';
    }else { //set clas for hidden
      whotohide_object.className = class_hidden;
    }
  }
  return visible;
}
/**
 * sets focus on element whos ID we input
 *
 * @param inFocused string  - element id to get focus
 */
function setFocusOn(inFocused){
  document.getElementById(inFocused).focus();
}

/**
 * Select row of generic info table by it's ID
 * set's all TD's clasname rowselected
 *
 * @param idrow integer  - row id to select
 */
var idrowprev = null;
var classprev = "";
function selectTableRow(idrow){
  var i=0;
  var mytd;
  //alert('tdg_'+idrow+'_'+i);
  while((mytd = document.getElementById('tdg_'+idrow+'_'+i))){
    if (null != idrowprev){
      mytdprev = document.getElementById('tdg_'+idrowprev+'_'+i);
      if (mytdprev) mytdprev.className = classprev;
    }
    tmpclass = mytd.className;
    mytd.className = "rowGreen";
    i++;
  }
  idrowprev = idrow;
  classprev = tmpclass;
}
