function submitForm(frm, url)
{
  frm.action = url;
  frm.submit();
}

function changePage(url)
{
  window.location.href = url;
}


// paging
function paging(from)
{
  var thisURL = window.location.href;
  var re = /&page=[0-9]+/;
  thisURL = thisURL.replace(re, '');
  thisURL += '&page=' + from;
  changePage(thisURL);
}

// user friendly paging
function ufpaging(from)
{
  var thisURL = window.location.href;
  var re = /\/[0-9]*$/;
  thisURL = thisURL.replace(re, '');
  thisURL += '/' + from;
  changePage(thisURL);
}


function $() {
   if (arguments.length == 1) return get$(arguments[0]);
   var elements = [];
   $c(arguments).each(function(el){
      elements.push(get$(el));
   });
   return elements;

   function get$(el){
      if (typeof el == 'string') el = document.getElementById(el);
      return el;
   }
}


// hide
function hideContent(objID)
{
  var obj = document.getElementById(objID);

  if (obj)
  {
    obj.style.visibility = "hidden";
    obj.style.overflow = "hidden";
    obj.style.height = "1px";
    obj.style.display = "none";
  }
}

// show
function showContent(objID)
{
  var obj = document.getElementById(objID);

  if (obj)
  {
    obj.style.visibility = "visible";
    obj.style.overflow = "visible";
    obj.style.display = "block";
    obj.style.height = "auto";
  }
}

function switchContent(objID)
{
  var obj = document.getElementById(objID);

  if (obj)
  {
    if (obj.style.visibility == "hidden")
    {
      showContent(objID);
    }
    else
    {
      hideContent(objID);
    }
  }
}

function lTrim(val)
{
  while (val.length > 0 && val.indexOf(' ') == 0)
  {
    val = val.substring(1, val.length);
  }
  return val;
}

function rTrim(val)
{
  while (val.substring(val.length - 1, val.length) == ' ')
  {
    val = val.substring(0, val.length - 1);
  }
  return val;
}

function allTrim(val)
{
  return rTrim(lTrim(val));
}

function checkEmpty(val)
{
  return (allTrim(val) == '');
}

function checkNoEmpty(arrID, msg)
{
  var obj;
  var i;
  for (i = 0; i < arrID.length; i++)
  {
    obj = document.getElementById(arrID[i]);
    if (obj && checkEmpty(obj.value))
    {
      alert(msg);
      obj.focus();
      return false;
    }
  }
  return true;
}

function checkInt(val)
{
  var re = new RegExp("^[0-9]+$");
  return re.test(allTrim(val));
}

function checkFloat(val)
{
  var re = new RegExp("^-?[0-9]+(\.[0-9]+)?$");
  return re.test(allTrim(val));
}
