Такая функция реализована в библиотеке script.aculo.us effects.js (parseColor()).
effects.js использует, в свою очередь, библиотеку prototype.js.
Ради одной только функции, конечно, нет смысла подключать две библиотеки. Поэтому я выбрал то, что тебе нужно, немного видоизменив:
Number.prototype.toColorPart = function() {
    var digits = this.toString(16);
    if (this < 16) return \'0\' + digits;
    return digits;
  }
// converts rgb() and #xxx to #xxxxxx format,  
// returns self (or first argument) if not convertable  
String.prototype.parseColor = function() {  
  var color = \'#\';  
  if(this.slice(0,4) == \'rgb(\') {  
    var cols = this.slice(4,this.length-1).split(\',\');  
    var i=0; do { color += parseInt(cols).toColorPart() } while (++i<3);  
  } else {  
    if(this.slice(0,1) == \'#\') {  
      if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();  
      if(this.length==7) color = this.toLowerCase();  
    }  
  }  
  return(color.length==7 ? color : (arguments[0] || this));  
}
Теперь document.getElementById("m1n1").style.backgroundColor.parseColor() вернет строку с цветом в формате #xxxxxx