
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function two_decimal(val) 
{ 
  val = (val + "").replace(/\,/g,""); // convert to string, strip commas
  val = (Math.round(val * 100) + (val < 0 ? -0.01 : +0.01)) / 100;
  val = "" + val;
  return val.replace(/(.*\.\d\d)\d*/,'$1'); // fill in any missing zeroes
}

function addTimeStamp( field ) 
{
  var date = new Date();

  var d  = date.getDate();
  var day = ( d < 10 ) ? '0' + d : d;
  var m = date.getMonth() + 1;
  var month = ( m < 10 ) ? '0' + m : m;
  var yy = date.getYear();
  var year = ( yy < 1000 ) ? yy + 1900 : yy;

  dateString = year + "-" + month + "-" + day;

  field.value += "\n\n" + dateString;
}

function setCurrentTimeStamp( field ) 
{
  var date = new Date();

  var d  = date.getDate();
  var day = ( d < 10 ) ? '0' + d : d;
  var m = date.getMonth() + 1;
  var month = ( m < 10 ) ? '0' + m : m;
  var yy = date.getYear();
  var year = ( yy < 1000 ) ? yy + 1900 : yy;

  dateString = year + "-" + month + "-" + day;

  field.value = dateString;
}

function appendToSectionTitle(newTitle)
{
  document.title = document.title + newTitle;
  if (document.getElementById("page-header")) document.getElementById("page-header").appendChild(document.createTextNode(newTitle));
}

function expand_collapse(icon, section)
{
  if (icon.tagName.toLowerCase() == "img") // at least ensure that an image was clicked
  {
    var start = icon.src.lastIndexOf("/") + 1;
    var imgname = icon.src.substring(start);
    if (imgname == "expand.gif")
    {
      icon.src = "../images/collapse.gif";
      document.getElementById(section).style.visibility = "visible";
      document.getElementById(section).style.display = "block";
    }
    else if (imgname == "collapse.gif")
    {
      icon.src = "../images/expand.gif";
      document.getElementById(section).style.visibility = "hidden";
      document.getElementById(section).style.display = "none";
    }
  }
}

function openWin( url, width, height, clean ) {
    if( !width )
        width = 820;

    if( !height )
        height = 600;

    if( clean )
        usestr = ",toolbar=yes,scrollbars=yes,resizable=yes,menubar=yes,status=no";
    else
        usestr = ",menubar=yes,toolbar=yes,status=yes,location=yes,scrollbars=yes,resizable=yes";
        
    if( url )
        newWin = window.open( url, '', 'width=' + width + ',height=' + height + usestr );
}

function winWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && 
              ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myHeight;
}

function winHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && 
              ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function makeReadOnly()
{
  allforms = document.forms;
  
  for (var j=0; j<allforms.length; j++)
  {
    allelements = allforms[j].elements;
    for (var i=0; i<allelements.length; i++)
    {
      el = allelements[i];
      if (el.type == "text" || el.type == "textarea") el.readOnly = true;
      else if (el.type == "button" || el.type=="reset" || el.type=="submit") el.style.visibility = "hidden";
      else el.disabled = true;
    }
  }
    
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++)
  {
    anchors[i].href = "javascript:doNothing();";
    anchors[i].onclick = doNothing;
    anchors[i].title = "disabled in print mode";
  }
}

function doNothing()
{
  return false;
}

