//--------------------------------------------------------------------------
//
// global
//
//--------------------------------------------------------------------------

cCountWhat = 7;
aCountWhat = new Array(cCountWhat);

aCountWhat[0] = "1+";
aCountWhat[1] = "1";
aCountWhat[2] = "2+";
aCountWhat[3] = "2";
aCountWhat[4] = "3+";
aCountWhat[5] = "3";
aCountWhat[6] = "4";
	
//--------------------------------------------------------------------------
//
// ::props
//
//--------------------------------------------------------------------------
function props(v)
{
	s = "";
	for (i in v)
	{
		s = s + " " + i;
	}
	alert (s);
}

//--------------------------------------------------------------------------
//
// ::getNumericValue
//
//--------------------------------------------------------------------------
function getNumericValue(s)
{
    i = 0;
    c = s.length;
    while (i < c && '0' <= s.charAt(i) && s.charAt(i) <= '9')
    {
        i++;
    }
    if (i == c && 0 < c)
        return s;
    else
        return "1";
}

//--------------------------------------------------------------------------
//
// ::getCheck
//
//--------------------------------------------------------------------------
function getCheck(check)
{
	return check.checked ? 1 : 0;
}

//--------------------------------------------------------------------------
//
// ::setCheck
// guess why would I need this function
//--------------------------------------------------------------------------
function setCheck(check, value)
{
	check.checked = value ? 1 : 0;
}

//--------------------------------------------------------------------------
//
// ::getCountWhat
//
//--------------------------------------------------------------------------
function getCountWhat (choice)
{
	i = choice.selectedIndex;

	return (i < cCountWhat) ? aCountWhat[i] : "1+";
}

//--------------------------------------------------------------------------
//
// ::setCountWhat
//
//--------------------------------------------------------------------------
function setCountWhat (choice, sValue)
{
	for (i = 0; i < cCountWhat; i++)
	{
		if (aCountWhat[i] == sValue)
		{
			choice.selectedIndex = i;
			break;
		}
	}
}

//--------------------------------------------------------------------------
//
// ::found
//
//--------------------------------------------------------------------------
function found(paramsStr, name)
{
    return (0 <= paramsStr.indexOf(name));
}

//--------------------------------------------------------------------------
//
// ::makeParamsString
//
//--------------------------------------------------------------------------
function makeParamsString(form)
{
	c = form.elements.length;
	s = "";
	for (i = 0; i < c; i++)
	{
		e = form.elements[i];
		s = s + e.name + "; ";
	}
	return s;
}

//--------------------------------------------------------------------------
//
// ::params2t
//
//--------------------------------------------------------------------------
function params2t(t, params)
{
	//
	// tranfer params from html page into applet
	//

    s = makeParamsString(params); //alert (s);

	t.setPreview			(found(s, "preview")            ? getCheck(params.preview)          : 1);
	t.setStopOnTimeCount	(found(s, "stopOnTimeCount")    ? getCheck(params.stopOnTimeCount)  : 0);
	t.setStopOnRowCount		(found(s, "stopOnRowCount")     ? getCheck(params.stopOnRowCount)   : 0);

	t.setDelay				(found(s, "delay")              ? params.delay.				value   : 100);
	t.setStartingRows		(found(s, "startingRows")       ? params.startingRows.		value   : 0);
	t.setTimeCountStopValue	(found(s, "timeCountStopValue") ? params.timeCountStopValue.value   : 60);
	t.setRowCountStopValue	(found(s, "rowCountStopValue")  ? params.rowCountStopValue.	value   : 21);

	t.setCountWhat			(found(s, "countWhat")          ? getCountWhat(params.countWhat)    : "1+");
}

//--------------------------------------------------------------------------
//
// ::t2params
//
//--------------------------------------------------------------------------
function t2params(t, params)
{
	//
	// transfer params from applet back to html page;
	// this is the data applet is running with.
	// E.g., delay = "75sec" will get back here as "75"
	//

    s = makeParamsString(params);

	if (found(s, "preview"))            setCheck (params.preview,			t.getPreview());
	if (found(s, "stopOnTimeCount"))    setCheck (params.stopOnTimeCount,	t.getStopOnTimeCount());
	if (found(s, "stopOnRowCount"))     setCheck (params.stopOnRowCount,	t.getStopOnRowCount());

	if (found(s, "delay"))              params.delay.				value = t.getDelay				();
	if (found(s, "startingRows"))       params.startingRows.		value = t.getStartingRows		();
	if (found(s, "timeCountStopValue")) params.timeCountStopValue.	value = t.getTimeCountStopValue	();
	if (found(s, "rowCountStopValue"))  params.rowCountStopValue.	value = t.getRowCountStopValue	();

	if (found(s, "countWhat"))          setCountWhat (params.countWhat, t.getCountWhat());
}

//--------------------------------------------------------------------------
//
// ::doStart
//
//--------------------------------------------------------------------------
function doStart(t, params)
{
    params2t (t, params);

	t.doStart();

    t2params (t, params);
}

//--------------------------------------------------------------------------
//
// ::doStart22
//
//--------------------------------------------------------------------------
function doStart22(t1, t2, params1, params2)
{
    params2t (t1, params1);
    params2t (t2, params2);

	t1.doStart();

    t2params (t1, params1);
    t2params (t2, params2);
}

//--------------------------------------------------------------------------
//
// ::doStop
//
//--------------------------------------------------------------------------
function doStop(t)
{
    t.doStop();
}