String.prototype.trim=function(){
  return this.replace(/^\s*|\s*$/g,'');
}
String.prototype.ltrim=function(){
  return this.replace(/^\s*/g,'');
}
String.prototype.rtrim=function(){
  return this.replace(/\s*$/g,'');
}

function strtr(str, from, to) {
  var fr = '', i = 0, lgth = 0;

  if (typeof from === 'object') {
      for (fr in from) {
          str = str.replace(fr, from[fr]);
      }
      return str;
  }
  
  lgth = to.length;
  if (from.length < to.length) {
      lgth = from.length;
  }
  for (i = 0; i < lgth; i++) {
      str = str.replace(from[i], to[i], 'g');
  }
  
  return str;
}

function isUndefined(val) {
  return YAHOO.lang.isUndefined(val);
}

function checkDate(y, m, d){
  var chkDate = new Date(y, m, d);
  if (y != chkDate.getFullYear() || d != chkDate.getDate() || m != chkDate.getMonth()) {
    return false;
  }
  return true;
}

function in_array(needle, haystack) {
  if (array_search(needle, haystack) !== false) {
    return true;
  }
  return false;
}

function array_search(needle, haystack, argStrict) {
  // Searches the array for a given value and returns the corresponding key if successful  
  // 
  // version: 909.322
  // discuss at: http://phpjs.org/functions/array_search
  // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // +      input by: Brett Zamir (http://brett-zamir.me)
  // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // *     example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
  // *     returns 1: 'surname'

  var strict = !!argStrict;
  var key = '';

  for (key in haystack) {
      if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
          return key;
      }
  }
  return false;
}

function wo(o, width, height, extra) {
  if (!o.name) o.name = 'popup_window';
  if (!width) width = 900;
  if (!height) height = 600;
  var params = [];
  params[params.length] ='width=' + width;
  params[params.length] ='height=' + height;
  var w = window.open(o.href, o.name + '_popup', params.join(',') + (extra ? ',' + extra : ''));
  if (typeof(w) != 'undefined') w.focus();
  return false;
}
