var hD="0123456789ABCDEF";
function d2h(d) {
  var h = hD.substr(d&15,1);
  while(d>15) {d>>=4;h=hD.substr(d&15,1)+h;}
  if(h.length<2) h = "0"+h;
  return h;
}
function rgb2h(str) {
  str = str.substring(str.indexOf("(")+1);
  r = d2h(parseInt(str.substring(0,str.indexOf(","))));
  str = str.substring(str.indexOf(",")+2);
  g = d2h(parseInt(str.substring(0,str.indexOf(","))));
  str = str.substring(str.indexOf(",")+2);
  b = d2h(parseInt(str.substring(0,str.indexOf(")"))));
  return r+g+b;
}
function getHex(str) {
  if(str.length==7) {
    return str.substring(1);
  } else if(str.length==4) {
    return str.charAt(1)+str.charAt(1) + str.charAt(2)+str.charAt(2) + str.charAt(3)+str.charAt(3);
  } else if(str.length>6 && str.indexOf("rgb(")==0) {
    return rgb2h(str);
  } else {
    return "000000";
  }
}
document.write('<div id="googlecolors1"><a href="#">Link</a> and Text</div>');
document.write('<div id="googlecolors2">Text</div>');
var el1 = document.getElementById("googlecolors1");
var el2 = document.getElementById("googlecolors2");
var gc_border,gc_bg,gc_link,gc_url,gc_text;
var google_color_border,google_color_bg,google_color_link,google_color_url,google_color_text;
if(document.all) {
  var bgtest = el1.currentStyle.backgroundColor;
  if(bgtest != "transparent") {
    gc_bg = getHex(bgtest);
    gc_link = getHex(el1.firstChild.currentStyle.color);
    gc_text = getHex(el1.currentStyle.color);
    gc_border = getHex(el2.currentStyle.backgroundColor);
    gc_url = getHex(el2.currentStyle.color);
  }
  el1.removeNode(true);
  el2.removeNode(true);
} else {
  var bgtest = document.defaultView.getComputedStyle(el1,null).getPropertyValue("background-color");
  if(bgtest!="transparent") {
    gc_bg = rgb2h(bgtest);
    gc_link = rgb2h(document.defaultView.getComputedStyle(el1.firstChild,null).getPropertyValue("color"));
    gc_text = rgb2h(document.defaultView.getComputedStyle(el1,null).getPropertyValue("color"));
    gc_border = rgb2h(document.defaultView.getComputedStyle(el2,null).getPropertyValue("background-color"));
    gc_url = rgb2h(document.defaultView.getComputedStyle(el2,null).getPropertyValue("color"));
  }
  el1.parentNode.removeChild(el1);
  el2.parentNode.removeChild(el2);
}
google_color_border = gc_border;
google_color_bg = gc_bg;
google_color_link = gc_link;
google_color_url = gc_url;
google_color_text = gc_text;
