function mycolour()
{
 window.status = "colours=" + document.body.style.backgroundColor + " : "
    + document.all["qhead"].style.color + " : "
    + document.body.style.color;
 if (!document.all["pada"])
 {
   creapad();
 }
 document.all["pada"].style.left = event.offsetX;
 document.all["pada"].style.top = event.offsetY;
 document.all["pada"].style.visibility = 'visible';
}

function hidepad()
{
 document.all["pada"].style.visibility = 'hidden';
}

function creapad()
{
 var str1;
 var mystep=8;
 var sides = parseInt(256 / mystep);
 str1 = "<DIV id=pada style='position:absolute;background-color:#ffffff'></div>"
 document.body.insertAdjacentHTML("beforeEnd", str1);

 str1 = "<DIV id=pad1 style='position:relative;height:256;width:256'></div>"
 document.all["pada"].insertAdjacentHTML("beforeEnd", str1);
 document.all["pad1"].style.height = 256 + mystep;
 var i;
 var j;
 var sqrid;
 var thissq;
 var b = 0;
 var maxtop = 0, thistop;
 for (j = 0 ; j < sides ; j++)
   for (i = 0 ; i < sides ; i++)
   {
	sqrid = "colsq" + j + ":" + i;
	if (!document.all[sqrid])
	{
	str1 = "<DIV id=" + sqrid + " style='position:absolute;height:8;width:8;font-size:1' onmouseover=showcolour() onclick=setfieldcolour()></div>"
        document.all["pad1"].insertAdjacentHTML("beforeEnd", str1)
	thissq = document.all[sqrid];
	thissq.style.left = mystep * i;
	thistop = mystep * j;
        thissq.style.top = thistop;
	if (thistop > maxtop)
		maxtop = thistop;
	thissq.style.width = mystep;
	thissq.style.height = mystep;
	}
	thissq = document.all[sqrid];
	thissq.style.backgroundColor = "#" + dRed + dechex(j * mystep) + dechex(i * mystep);

   }
 maxtop += mystep;
 for (i = 0 ; i < sides ;i++)
 {
	sqrid = "colsqr" + i;
	str1 = "<DIV id=" + sqrid + " style='position:absolute;height:8;width:8;font-size:1' onmouseover=showcolour() onclick=setcolour()></div>"
        document.all["pad1"].insertAdjacentHTML("beforeEnd", str1)
	thissq = document.all[sqrid];
	thissq.style.left = mystep * i;
	thissq.style.top = maxtop;
	thissq.style.width = mystep;
	thissq.style.height = mystep;

	thissq.style.backgroundColor = "#" + dechex(i * mystep) + dechex(0) + dechex(0);
    
 }

 str1 = "<input type=button value=hide onclick=hidepad()>"
 str1 += "Background <input type=radio id=radback name=radtype checked>"
 str1 += "Heading <input type=radio id=radhead name=radtype>"
 str1 += "Text <input type=radio id=radtext name=radtype>"
 str1 += "<div id=thiscolour></div>"
 document.all["pada"].insertAdjacentHTML("beforeEnd", str1);

}


function setfieldcolour()
{

 var fid = event.srcElement.id;
 if (document.all["radback"].checked == true)
	 document.body.style.backgroundColor = document.all[fid].style.backgroundColor;
 else
 if (document.all["radhead"].checked == true)
	 document.all["qhead"].style.color = document.all[fid].style.backgroundColor;
 else
 if (document.all["radtext"].checked == true)
	 document.body.style.color = document.all[fid].style.backgroundColor;

//alert(colourObj.style.backgroundColor + document.all[fid].style.backgroundColor);
// document.all["tophead"].style.backgroundColor = document.all[fid].style.backgroundColor;
 window.status = "colours=" + document.body.style.backgroundColor + " : "
    + document.all["qhead"].style.color + " : "
    + document.body.style.color;
}

function padColour()
{
 var str1;
 var mystep=8;
 var sides = parseInt(256 / mystep);
 var i;
 var j;
 var sqrid;
 var thissq;
 var b = 0;
 var maxtop = 0, thistop;
 for (j = 0 ; j < sides ; j++)
   for (i = 0 ; i < sides ; i++)
   {
	sqrid = "colsq" + j + ":" + i;
	thissq = document.all[sqrid];
	thissq.style.backgroundColor = "#" + dRed + dechex(j * mystep) + dechex(i * mystep);
   }
}

function showcolour()
{
 var fid = event.srcElement.id;
 document.all["thiscolour"].innerText = document.all[fid].style.backgroundColor;
// window.status = "Colour = " + document.all[fid].style.backgroundColor;
}

function setcolour()
{
 var fid = event.srcElement.id;
 dRed = document.all[fid].style.backgroundColor.substr(1,2);
 padColour();
}

var colourObj = document.body;
var dRed = "00";


function hexdec(hex1)
{
 var dec1=0;
}

function hexdec1(hex1)
{
  var dec1;
  switch (hex1)
  {
    case 'a' :
	dec1=10;
	break;
    case 'b' :
	dec1=11;
	break;
    case 'c' :
	dec1=12;
	break;
    case 'd' :
	dec1=13;
	break;
    case 'e' :
	dec1=14;
	break;
    case 'f' :
	dec1=15;
	break;
    default:
	dec1=hex1;
	break;
  }
  return dec1;
}

function dechex(dec1)
{
  var hex1, hex2;
  hex1 = parseInt(dec1 / 16);
  hex2 = dec1 - hex1 * 16;
  return(dechex1(hex1) + "" + dechex1(hex2));
}

function dechex1(dec1)
{
 if (dec1 < 10)
	return dec1;
 switch (dec1)
 {
	case 10:
		return 'a';
	case 11:
		return 'b';
	case 12:
		return 'c';
	case 13:
		return 'd';
	case 14:
		return 'e';
	case 15:
		return 'f';

 }
 return 0;
}
