function setBGC(n,v,e) {
  p=location.pathname;
  document.cookie='path = '+p.substring(0,p.indexOf('/',1)+1);
  document.cookie=n+'='+escape(v)+((e == null)?'':('; expires='+e.toGMTString()));
}
function getBGC(n) {
  var s=n+'=';
  if (document.cookie.length>0) {
    o=document.cookie.indexOf(s);
    if (o!=-1) {
      o+=s.length;
      e=document.cookie.indexOf(';',o);
      if (e==-1) e=document.cookie.length;
      return unescape(document.cookie.substring(o,e));
    }
  }
  return null;
}
if (getBGC('BGColor')!=null) document.bgColor=getBGC('BGColor');
var hexStr='0123456789abcdef';
function byteToHex(b) {
  return hexStr.charAt(Math.floor(b/16))+hexStr.charAt(b%16);
}
function hexToByte(h) {
  return hexStr.indexOf(h.charAt(0))*16+hexStr.indexOf(h.charAt(1));
}
function changeColorSub(c,a) {
  c=c+17*a;
  if (c>255) c=255
  else if (c<0) c=0;
  return c;
}
function changeColor(c, a) {
  var expires=new Date();
  var r=hexToByte(document.bgColor.substring(1,3));
  var g=hexToByte(document.bgColor.substring(3,5));
  var b=hexToByte(document.bgColor.substring(5,7));
  expires.setTime(expires.getTime()+1000*60*60*24*30);
  if (c==1) r=changeColorSub(r,a)
  else if (c==2) g=changeColorSub(g,a)
  else if (c==3) b=changeColorSub(b,a);
  document.bgColor='#'+byteToHex(r)+byteToHex(g)+byteToHex(b);
  setBGC('BGColor',document.bgColor,expires);
}

