
//Hide any messages after 5 seconds
window.setTimeout('if ( xGetElementById("messageDisplay") ) { Effect.SlideUp("messageDisplay",  { duration: 0.8 });}', 5000);


// Display the help popup with the given URL
function showHelpPop(url) {
	xGetElementById('helpFrame').src = url;
	new xModalDialog('helpModalDialog');
	xModalDialog.instances['helpModalDialog'].show();
}


function showModalPop(url, w, h) {
	xGetElementById('helpFrame').src = url;
	xGetElementById('helpFrame').style.height = h-20 + "px";
	xGetElementById('helpFrame').style.width = w + "px";
	xGetElementById('helpModalDialog').style.height = h + "px";
	xGetElementById('helpModalDialog').style.width = w + "px";
	new xModalDialog('helpModalDialog');
	xModalDialog.instances['helpModalDialog'].show();
}

function closeModalPop() {
	xGetElementById('helpFrame').src = '/sData/blank_file.html';
	xModalDialog.instances.helpModalDialog.hide()
}

function makeDivEmpty (div) {
	outDiv = xGetElementById(div);
	outDiv.className = "";
	outDiv.style.height = "1px";
	outDiv.style.display = "none";
	outDiv.innerHTML = "";
}

function cpopup(mylink, windowname, width, height)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
		href=mylink;
	else
		href=mylink.href;
	window.open(href, windowname, "width=" + width + ",height=" + height + ",scrollbars=yes, screenX=200, screenY=220, status=no");
	return false;
}


var ETCP = new ETColorPicker();
var initPalette = '1';

function ETCBuildCell (R, G, B, w, h) {
	return '<td bgcolor="#' + this.dec2hex((R << 16) + (G << 8) + B) + '"  border="0"><a href="javascript:P.S(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')" onmouseover="P.P(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')" style="text-decoration:none;"> <div style="width:' + w + '; height:' + h + '; border:0px;"> </div> </a></td>';
}

function ETCSelect(c) {
	this.field = document.getElementById('selValue');
	this.field2 = document.getElementById('colorBlock');
	this.field.value = '#' + c.toUpperCase();
	this.field2.style.backgroundColor = '#' + c.toUpperCase();
	this.demo.style.backgroundColor = '#' + c.toUpperCase();
}

function  ETCsetField(field) {
	this.field = field;
}

function ETCPaint(c, b_noPref) {
	c = (b_noPref ? '' : '#') + c.toUpperCase();
	if (this.o_samp)
		this.o_samp.innerHTML = '<font face=Tahoma size=2>' + c +' <font color=white>' + c + '</font></font>'
	if(this.doc.layers)
		this.sample.bgColor = c;
	else {
		if (this.sample.backgroundColor != null) this.sample.backgroundColor = c;
		else if (this.sample.background != null) this.sample.background = c;
	}
}

function ETCGenerateSafe() {
	var s = '';
	var cp = [];
	for (j = 0; j < 12; j ++) {
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i ++)
				cp.push(this.bldCell(k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, i * 51, 8, 10));
	}

	var cols = 45;
	var colCount = 0;

	for (j = 0; j < cp.length; j ++) {

		if (colCount == 0 ) {
			s += "<tr style=\"border: 0px;\">";
		}

		s += cp[j];
		colCount ++;

		if (colCount == cols ) {
			s += "</tr>";
			colCount = 0;
		}

	}

	return s;
}

function ETCGenerateWind() {
	var s = '';
	var cp = [];

	for (j = 0; j < 12; j ++) {
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i++)
				cp.push( this.bldCell(i * 51, k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, 8, 10) );
	}

	var cols = 45;
	var colCount = 0;

	for (j = 0; j < cp.length; j ++) {

		if (colCount == 0 ) {
			s += "<tr>";
		}

		s += cp[j];
		colCount ++;

		if (colCount == cols ) {
			s += "</tr>";
			colCount = 0;
		}

	}

	return s;
}
function ETCGenerateMac() {
	var s = '';
	var cp = [];

	var c = 0,n = 1;
	var r,g,b;
	for (j = 0; j < 15; j ++) {
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i++){
				if(j<12){
				cp.push(  this.bldCell( 255-(Math.floor(j / 2) * 51), 255-(k * 51 + (j % 2) * 51 * 3),255-(i * 51), 8, 10) );
				}else{
					if(n<=14){
						r = 255-(n * 17);
						g=b=0;
					}else if(n>14 && n<=28){
						g = 255-((n-14) * 17);
						r=b=0;
					}else if(n>28 && n<=42){
						b = 255-((n-28) * 17);
						r=g=0;
					}else{
						r=g=b=255-((n-42) * 17);
					}
					cp.push(  this.bldCell( r, g,b, 8, 10) );
					n++;
				}
			}
	}

	var cols = 45;
	var colCount = 0;

	for (j = 0; j < cp.length; j ++) {

		if (colCount == 0 ) {
			s += "<tr>";
		}

		s += cp[j];
		colCount ++;

		if (colCount == cols ) {
			s += "</tr>";
			colCount = 0;
		}

	}

	return s;
}

function ETCGenerateGray() {
	var s = '';
	var cp = [];

	for (j = 0; j <= 15; j ++) {
		for (k = 0; k <= 15; k ++) {
			g = Math.floor((k + j * 16) % 256);
			cp.push( this.bldCell(g, g, g, 8, 10) );
		}
	}

	var cols = 45;
	var colCount = 0;

	for (e = 0; e < cp.length; e ++) {

		if (colCount == 0 ) {
			s += "<tr>";
		}

		s += cp[e];
		colCount ++;

		if (colCount == cols ) {
			s += "</tr>";
			colCount = 0;
		}

	}

	return s;
}

function ETCDec2Hex(v) {
	v = v.toString(16);
	for(; v.length < 6; v = '0' + v);
	return v;
}

function ETCChgMode(v) {
	for (var k in this.divs) this.hide(k);
	this.show(v);
}

function ETColorPicker(field) {
	this.build0 = ETCGenerateSafe;
	this.build1 = ETCGenerateWind;
	this.build2 = ETCGenerateGray;
	this.build3 = ETCGenerateMac;
	this.show = document.layers ?
		function (div) { this.divs[div].visibility = 'show' } :
		function (div) { this.divs[div].visibility = 'visible' };
	this.hide = document.layers ?
		function (div) { this.divs[div].visibility = 'hide' } :
		function (div) { this.divs[div].visibility = 'hidden' };
	// event handlers
	this.C       = ETCChgMode;
	this.S       = ETCSelect;
	this.P       = ETCPaint;
	this.draw    = ETCDraw;
	this.dec2hex = ETCDec2Hex;
	this.bldCell = ETCBuildCell;
	this.setField= ETCsetField;
	this.divs = [];
}

function ETCDraw(o_win, o_doc) {
	this.win = o_win;
	this.doc = o_doc;
	var
	s_tag_openT  = o_doc.layers ?
		'layer visibility=hidden width=250' :
		'div style=visibility:hidden;width:250px;height:0',
	s_tag_openS  = o_doc.layers ? 'layer' : 'div',
	s_tag_close  = o_doc.layers ? 'layer' : 'div'

	this.doc.write('<' + s_tag_openS + ' id=sam name=sam><table cellpadding=0 cellspacing=0 border=1 width=181 align=center class=bd><tr><td align=center height=18><div id="samp"><font face=Tahoma size=2>sample <font color=white>sample</font></font></div></td></tr></table></' + s_tag_close + '></td></tr><tr><td align="left" colspan="2" height="50" valign="top" style="padding:4px;">');
	this.sample = o_doc.layers ? o_doc.layers['sam'] :
		o_doc.getElementById ? o_doc.getElementById('sam').style : o_doc.all['sam'].style

	for (var k = 0; k < 4; k ++) {
		this.doc.write('<' + s_tag_openT + ' id="p' + k + '" name="p' + k + '"><table cellpadding="0" cellspacing="0" style="border: 0px solid;">' + this['build' + k]() + '</table></' + s_tag_close + '>');
		this.divs[k] = o_doc.layers
			? o_doc.layers['p' + k] : o_doc.all
				? o_doc.all['p' + k].style : o_doc.getElementById('p' + k).style
	}
	if (!o_doc.layers && o_doc.body.innerHTML)
		this.o_samp = o_doc.all
			? o_doc.all.samp : o_doc.getElementById('samp');
	this.C(this.initPalette);
	if (this.field.value) this.P(this.field.value, true)
}


function copyToList(from,to)
{
  fromList = eval('document.forms[0].' + from);
  toList = eval('document.forms[0].' + to);
  if (toList.options.length > 0 && toList.options[0].value == 'temp')
  {
    toList.options.length = 0;
  }
  var sel = false;
  for (i=0;i<fromList.options.length;i++)
  {
    var current = fromList.options[i];
    if (current.selected)
    {
      sel = true;
      if (current.value == 'temp')
      {
        alert ('You cannot move this text!');
        return;
      }
      txt = current.text;
      val = current.value;
      toList.options[toList.length] = new Option(txt,val);
      fromList.options[i] = null;
      i--;
    }
  }
  if (!sel) alert ('You haven\'t selected any options!');
}



