String.trim = function()
  {
    if(arguments.length == 0) return null;
    var str = arguments[0];
    return str.replace(/\s+$|^\s+/g,"");
  }

function contains(var1, var2)
{
  return (var1.indexOf(var2) > -1);
}

function openpopupWindow(popupURL, width, height) {
  var w = width;
  var h = height;
  var l = Math.floor((screen.width-w)/2);
  var t = Math.floor((screen.height-h)/2);
  popupWindow = window.open(popupURL,"popupWindowDoc", "scrollbars=no, location=no, toolbar=no, directories=no, status=no, resizable=no, height=" + height + ",width=" + width + ",top=" + t + ",left=" + l);
  popupWindow.focus();
}

function isNotValidEmail(elem) {
  var str = elem.value;
  var re  = /\b[a-z0-9._%-]+@[a-z0-9._%-]+\.[a-z0-9._%-]{2,4}\b/;
  if (!str.match(re))
    return false;
  else
    return true;
}

String.format = function()
  {
    if(arguments.length == 0) return null;
    var str = arguments[0];

    for(var i=1;i<arguments.length;i++)
    {
      var re = new RegExp('\\{' + (i-1) + '\\}','gm');
      str = str.replace(re, arguments[i]);
    }
    return str;
  }

