
Util.isOkClean = Util.isAnyClean =
function /* isOkClean */( o, prop )
{
  if ( (o == null) || (typeof o == "undefined") )
    return false;
  if ( (o[prop] != null) && (typeof o[prop] != "undefined") )
    return true;
  else
    {
      delete o[prop];
      return false;
    }
}

Util.getConstructorName_JS14 =
function /* getConstructorName_JS14 */( c )
{
  if ( this.isAny( c ) && this.isAny( c.constructor ) )
    return c.constructor.name;
}

Util.getConstructorName_JS13 =
function /* getConstructorName_JS13 */( c )
{
  if ( this.isAny( c ) && this.isAny( c.constructor ) )
    {
      if ( typeof c.constructor == 'function' )
  {
    if ( c.constructor.toString )
      {
        var cStr = c.constructor.toString();
        return cStr.slice( 10, cStr.indexOf( "(" ) );
      }
  }
      return '' + c.constructor;
    }
  else
    return '--'
}

// Check whether constructor.name exists
if ( Util.isOk( Util.constructor.name ) ) {
    Util.getConstructorName = Util.getConstructorName_JS14;
} else {
    Util.getConstructorName = Util.getConstructorName_JS13;
}

Util.addURLParameter =
function /* addURLParameter */( s, para )
{
  var result = '' + s;
  var pos = result.indexOf( '?' );
  if ( pos != -1 )
  {
    result += "&" + para;
  }
  else
  {
    result += "?" + para;
  }
  return result;
}

/**
 * Returns an array of key value pairs
 * OJO: If no value exists for a key, the keywork 'true' is used.
 * @param   theUrl
 * @param   pBegin   [optional] Default: '?'
 * @param   pSep     [optional] Default: '&'
 * @param   pKV      [optional] Default: '='
 */
Util.getURLParameters =
function /* getURLParameters */( theUrl, pBegin, pSep, pKV ) {
  // Delimitadores por defecto
  if ( ! Util.isOk( pBegin ) ) pBegin = "?";
  if ( ! Util.isOk( pSep ) ) pSep = "&";
  if ( ! Util.isOk( pKV ) ) pKV = "=";

  var result = [];
  var queryPos = theUrl.lastIndexOf( pBegin );
  if ( queryPos >= 0 ) {
    theUrl = theUrl.substring( queryPos + pBegin.length );
    var params = theUrl.split( pSep );
    for ( var p=0; p<params.length; p++ ) {
      var key, value;
      var keyValue = params[p];
      var equal = keyValue.indexOf( pKV );
      if ( equal > 0 ) {
        key = unescape(keyValue.substring(0, equal));
        value = unescape(keyValue.substring(equal+pKV.length));
      } else {
        key = unescape( keyValue );
        value = 'true';
      }
      result[ key ] = value;
    }
  }
  return result;
}

Util.trim =
function /* trim */( s )
{
  //if ( ! Util.isOk( s ) ) return '';
  // [la interrogacion elimina el modo greedy
  // (feature no documentada de JavaScript) ]
  //s = (''+s).replace( /^\s*(.*?)\s*$/, "$1" );
  //return s;
  if ( !s ) return '';
  var ch;
  for ( var i=0; i < s.length; i++) {
      ch = s.charAt(i);
      if ( ch != " " ) break;
  }
  for ( var j = s.length-1; j>0; j--) {
      ch = s.charAt(j);
      if ( ch != " " ) break;
  }
  return s.substring(i, j+1);

}

Util.isException =
function /* isException */( o ) {
//debug(342);
var result = false;
  if ( this.isOk( o ) ) {
//  debug(345);
//  debug("ExceptionInterface=" + ExceptionInterface);
    result = OOJS.objectImplements( o, ExceptionInterface );
  }
//  debug("result=" + result);
  return result;
}

Util.arrayToURI =
function /* arrayToURI */ ( a ){
  var s="";
  for(var e in a)
    s += e +"="+a[e]+"&";
  return s.slice(0,s.length-1);
}

Util.arrayToList =
function /* arrayToList */( args ) {
  var result = '';

  for (i=0; i < args.length; i++) {
    if (i > 0) result += ', ';
    var a = args[i];
    result += ((typeof a == "string") ? '"' + a.replace(/"/g, '\\"') + '"' : a);
}
return result;
}
