/**
* Without the second parameter, they will trim these characters:
*
* " " (ASCII 32 (0x20)), an ordinary space.
* "\t" (ASCII 9 (0x09)), a tab.
* "\n" (ASCII 10 (0x0A)), a new line (line feed).
* "\r" (ASCII 13 (0x0D)), a carriage return.
* "\0" (ASCII 0 (0x00)), the NUL-byte.
* "\x0B" (ASCII 11 (0x0B)), a vertical tab.
*
**/
function trim(str, chars)
{
  return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars)
{
  chars = chars || "\\s";
  return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars)
{
  chars = chars || "\\s";
  return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function validEmail(email)
{
  var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  //var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/

  return re.test(trim(email));
}
/** openWindow(this, {width:790,height:450,center:true})
*
* optional parameters
* width
* height
* left
* top
* center
* name
* scrollbars
* menubar
* locationbar
* resizable
*
**/
function openWindow(anchor, options) {

  var args = '';

  if (typeof(options) == 'undefined') { var options = new Object(); }
  if (typeof(options.name) == 'undefined') { options.name = 'win' + Math.round(Math.random()*100000); }

  if (typeof(options.height) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
    args += "height=" + options.height + ",";
  }

  if (typeof(options.width) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
    args += "width=" + options.width + ",";
  }

  if (typeof(options.fullscreen) != 'undefined') {
    args += "width=" + screen.availWidth + ",";
    args += "height=" + screen.availHeight + ",";
  }

  if (typeof(options.center) == 'undefined') {
    options.x = 0;
    options.y = 0;
    args += "screenx=" + options.x + ",";
    args += "screeny=" + options.y + ",";
    args += "left=" + options.x + ",";
    args += "top=" + options.y + ",";
  }

  if (typeof(options.center) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
    options.y=Math.floor((screen.availHeight-(options.height || screen.height))/2)-(screen.height-screen.availHeight);
    options.x=Math.floor((screen.availWidth-(options.width || screen.width))/2)-(screen.width-screen.availWidth);
    args += "screenx=" + options.x + ",";
    args += "screeny=" + options.y + ",";
    args += "left=" + options.x + ",";
    args += "top=" + options.y + ",";
  }

  if (typeof(options.scrollbars) != 'undefined') { args += "scrollbars=1,"; }
  if (typeof(options.menubar) != 'undefined') { args += "menubar=1,"; }
  if (typeof(options.locationbar) != 'undefined') { args += "location=1,"; }
  if (typeof(options.toolbar) != 'undefined') { args += "toolbar=1,"; }
  if (typeof(options.resizable) != 'undefined') { args += "resizable=1,"; }


  var win = window.open(anchor, options.name, args);
  win.focus();

  if (typeof(options.refWin) != 'undefined') {return win; }

  return false;

}
function showHideContent (theid)
{
  var img_close = '/images/b_minus.gif';
  var img_open = '/images/b_plus.gif';
  if (document.getElementById)
  {
    var switch_id = document.getElementById(theid);
    var imgid = theid+'Button';
    var button_id = document.getElementById(imgid);

    if (switch_id.className != 'hideContent')
    {
      button_id.setAttribute ('src', img_open);
      switch_id.className = 'hideContent';
    }
    else
    {
      button_id.setAttribute ('src', img_close);
      switch_id.className = 'showContent';
    }
  }
}

function rc(f)
{
  var num_e = f.length;
  var theChar;
  var theInput;
  var theLength;
  var str;
  var haveCode;

  haveCode = 0;
  for( var i = 0 ; i < num_e; i++)
  {
    theInput = f.elements[i].value;
    theLength = theInput.length;

    str = "";
    for(var j = 0; j < theLength; j++)
    {
      theChar = theInput.substring( j , j+1);
      if( theChar == "'")
      {
        haveCode = 1;
      }
      else
      {
        str = str + theChar;
      }
    }
    f.elements[i].value = str;
  }
}
function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++)
    {
        var pair = vars[i].split("=");
        if (pair[0] == variable)
        {
            return pair[1];
        }
    }
}
