

// static array of colours for the swatch

colour = new Array("#FFFFFF", "#FCF4E2", "#ECD0C1", "#A98A80",
"#F9F9FA", "#F3E5D5", "#E1BDB8", "#B3836E",
"#FCFCFC", "#FAEED1", "#F8E1D2", "#946B59",
"#FCFCFB", "#F6E4C2", "#E4BDA6", "#E49083",
"#FBFBFA", "#F5DBC8", "#DCADA1", "#D4A9A3",
"#F4F3F4", "#EBD0C6", "#D1B2A1", "#DAA6A6",
"#FCFAF5", "#E6C2B8", "#C7A192",
"#CD5848", "#FFF6F3", "#CD3D43", "#A99176", "#D0C6CA",
"#AB5D51", "#FFE9D9", "#8B2E32", "#CF9DAD", "#C5C5CC",
"#92565A", "#FFE3DF", "#FCEEE3", "#A55963", "#BAB1AF",
"#974435", "#E6BEC6", "#E0CAC4", "#764832", "#AEA5A7",
"#8F443B", "#E39CA5", "#CDB1AE", "#613C3F", "#C4A1AE",
"#A73F3C", "#B47575", "#B9A89C", "#5B2B2D", "#957487",
"#753C32", "#C92F2F", "#AB9397", "#FBEDDD", "#786468",
"#6F5985", "#442E2A", "#F9D8A1", "#C1BAA0", "#4D5434",
"#938A6E", "#FFFEF4", "#FCE021", "#3D9A51", "#C8B9AA",
"#9B866F", "#FFFFE9", "#DAB678", "#94967C", "#B1B29D",
"#5C6054", "#FEFAD6", "#F4C060", "#7A8763", "#A4AFA2",
"#544740", "#FFF5C0", "#DB942A", "#6A7B5D", "#869995",
"#595247", "#F7DDBD", "#D8D3BA", "#70745E", "#505A4C",
"#664E3C", "#FBF3A0", "#E3D5B0", "#5D5D40", "#3F5746",
"#42634F", "#59808F", "#678491", "#4A4E73", "#8E9896",
"#32443E", "#405B67", "#87A6C3", "#403950", "#848793",
"#E3F7F5", "#3B4D54", "#3E71A4", "#D6D8D0", "#474A4C",
"#CCD8DA", "#33363F", "#394687", "#8D8981", "#292729",
"#7CA7A2", "#CBCBE1", "#3D6287", "#929797", "#2D2929",
"#86A1A1", "#73889B", "#355378", "#7A7773",
"#FFFFFF", "#FFF8D4", "#FFFFFD", "#FFFFF7");


// reverse hash of the colour array

var reversepal = new Array();
for (var i=0; i<=colour.length-1; i++) {
    reversepal[colour[i]] = i+1;
}

// mark a colour on the swatch as selected
// and change the target to that colour

function markSelection (cellid, targetid) {
    clearSelection(targetid);
    cell = document.getElementById(cellid);
    cell.style.borderColor='black';
    target = document.getElementById(targetid);
    target.style.backgroundColor=cell.bgColor;

    updateFrameForm();
}

// deselect all the colours on the swatch

function clearSelection (targetid) {
    for (i=1; i<=colour.length; i++) {
	cid = targetid + '-swatch' + i;
	cid = document.getElementById(cid);
	cid.style.borderColor='white';
    }
}

// draws the swatch palette on-the-fly.
// Can be embedded in a DIV for positioning.
// targetid associates this swatch with a particular target element
// to support multiple swatches and targets per page.

function drawSwatch (targetid) {
    
    document.write('<TABLE border=0 cellspacing=0 cellpadding=0><TR>');
    
    for (i=1; i<=colour.length; i++) {
	var hexcol = colour[i-1];
	document.write("<TD onclick='markSelection(\""+targetid+"-swatch"+i+"\", \""+targetid+"\")' BGCOLOR='"+hexcol+"' id='"+targetid+"-swatch"+i+"'>&nbsp;</TD>");

	if (i % 10 == 0) {
	    document.write('</TR><TR>');
	}

    }
    
    document.write('</TR></TABLE>');
}


