//--
//left trim the string
function ltrim( s ){ return s.replace( /^\s*/, "" ); }//end function ltrim
//--
//right trim the string
function rtrim( s ){ return s.replace( /\s*$/, "" ); }//end function rtrim
//--
//Combine the rtrim() and ltrim() functions to make the trim() function, which just wraps both calls together:
function trim( s ){ return rtrim(ltrim(s)); }//end function trim
//--
function ucfirst( s ) {
  tmp = s.charAt(0);
  tmp = tmp.toUpperCase();
  for( var i = 1 ; i < s.length ; i++ ){
    tmp = tmp + s.charAt(i);
  }
  return tmp;
}//end function ucfirst
//--
function strtolower( str ){ return str.toLowerCase(); }//end function strtolower
//--
function strtoupper( str ){ return str.toUpperCase(); }//end function strtoupprt
//--
function count( arr ){ return arr.length }//end function count
//--
function end( arr ){ return arr[count(arr)-1]; }//end function end
//--
function is_array(obj) {return !(obj.constructor.toString().indexOf("Array") == -1); }//end function is_array
//--
function setChecked( obj , value ){
  l = obj.length;
  for( var i = 0 ; i < l ; i++ ){
    if( obj[i].value == value ){
      obj[i].checked = true;
      return true;
    }
  }
  return false;
}//end function setChecked
//--
function setSelected( obj , value ){
  l = obj.length;
  for( var i = 0 ; i < l ; i++ ){
    if( obj.options[i].value == value ){
      obj.options[i].selected = true;
      return true;
    }
  }
  return false;
}//end fucntion setSelected
//--
function in_array( needle , haystack ){ for( key in haystack ){ if( haystack[key] == needle ) return true; } return false; }//end function in_array
//--
function empty( value ){ return ( !value || ( trim( value ) == '' ) ); }//end function empty
//--
function urlencode( plaintext ){
  // The Javascript escape and unescape functions do not correspond
  // with what browsers actually do...
  var SAFECHARS = "0123456789" +        // Numeric
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetci
    "abcdefghijklmnopqrstuvwxyz" +
    "-_.!~*'()";			// RFC2396 Mark characters
  var HEX = "0123456789ABCDEF";
  var encoded = "";
  for (var i = 0; i < plaintext.length; i++ ) {
    var ch = plaintext.charAt(i); if (ch == " ") {
      encoded += "+";	
      // x-www-urlencoded, rather than %20
    } else if (SAFECHARS.indexOf(ch) != -1) {
      encoded += ch;
    } else {
      var charCode = ch.charCodeAt(0);
      if (charCode > 255) {
	alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" + "(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted." );
	encoded += "+";
      } else {
	encoded += "%";
	encoded += HEX.charAt((charCode >> 4) & 0xF);
	encoded += HEX.charAt(charCode & 0xF);
      }
    }
  } // for
  return encoded;
}//end function urlencode
//--
function urldecode( encoded ){
  // Replace + with ' '
  // Replace %xx with equivalent character
  var plaintext = "";
  var i = 0;
  while (i < (encoded.length-2)) {
    var ch = encoded.charAt(i);
    if (ch == "+") {
      plaintext += " ";
      i++;
    } else if (ch == "%" && encoded.charAt(i+1) != "%") {
      plaintext += unescape( encoded.substr(i,3) );
      i += 3;
    } else {
      plaintext += ch;
      i++;
    }
  } // while
  if (i < encoded.length) {
    plaintext += encoded.substr(i,encoded.length-i);
  }
  return unescape(plaintext);
}//end function urldecode
//--
function winOpen(url,winname){   
  new_window = window.open(url,winname,'menubar,scrollbars,toolbar,resizable,dependent,status,width=800,height=600,left=200,top=0');
}//end function open_win
//--
function strReplace(s, r, w){
  return s.split(r).join(w);
}
//--
function isAlien(a) { return isObject(a) && typeof a.constructor != 'function';}
function isArray(a) { return isObject(a) && a.constructor == Array; }
function isBoolean(a) { return typeof a == 'boolean'; }
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) { return typeof a == 'function';}
function isNull(a) { return typeof a == 'object' && !a;}
function isNumber(a) { return typeof a == 'number' && isFinite(a);}
function isObject(a) { return (a && typeof a == 'object') || isFunction(a);}
function isString(a) { return typeof a == 'string';}
function isUndefined(a) { return typeof a == 'undefined';}
