// Global Javascript

var no_click = false;

function tableOnClick(url)
{
  if (no_click == true)
  {
    no_click = false;
  }
  else
  {
    this.location = url;
  }
}

function buttonOnClick(url)
{
  no_click = true;
  
  this.location=url;
}

function buttonOnClickAsk(url)
{
  no_click = true;
  if (confirm("Are you sure?"))
  {
    this.location = url;
  }
}

function totalOffsetLeft(item)
{
  var r = 0;
  while (item)
  {
    r += item.offsetLeft;
    item = item.offsetParent
  }
  
  return r;
}

function totalOffsetTop(item)
{
  var r = 0;
  while (item)
  {
    r += item.offsetTop;
    item = item.offsetParent
  }
  
  return r;
}


function setSameLocationAlignLeft(elementSet, elementLoc)
{
  elementSet.style.left = totalOffsetLeft(elementLoc) + elementLoc.offsetWidth - elementSet.offsetWidth;
  elementSet.style.top = totalOffsetTop(elementLoc);
}

function setSameLocationAndSize(elementSet, elementLoc)
{
  elementSet.style.left = totalOffsetLeft(elementLoc);
  elementSet.style.top = totalOffsetTop(elementLoc);
  elementSet.style.width = elementLoc.offsetWidth;
}

function changeParentStyleClass(object, newClassName)
{
  object.parentNode.className = newClassName;
}

function changeStyleClass(object, newClassName)
{
  object.className = newClassName;
}

function changeStyle(object, newClassName)
{
  changeStyleClass(object, newClassName);
}

function popupRightBottom(classname, extravars, width, height)
{
  try
  {
    document.popper.close();
  } catch (error)
  {
  }
  
  var x = screen.width-width-30;
  var y = screen.height-height-100;
  
  var options = "width="+width+",height="+height+",left="+x+",top="+y+",screenx="+x+",screeny="+y;
  
  document.popper = open("./popup.php?class="+classname+"&"+extravars, 'popup', options);
  document.popper.focus();
}

function insertAfter(parent, node, referenceNode)
{
	parent.insertBefore(node, referenceNode.nextSibling);
}

function hover(elem, nextClass)
{
  elem.className = nextClass;
}

function hoverExclude(elem, nextClass, exclClass)
{
  if (elem.className != exclClass)
  {
    elem.className = nextClass;
  }
}
