// --- Events ---

// for use in onFocus
function onF(id)
{
	document.getElementById("label_" + id).style.color = "#A5282C";

	var inputs = getInputs(id);
	for(var i = 0; i < inputs.length; i++)
		if(inputs[i].type == "text")
			inputs[i].style.borderColor = "#A5282C";
}
// selects the current input's text
function sel(e)
{
	e.select();
}


// for use in onBlur
function onB(id)
{
	document.getElementById("label_" + id).style.color = "black";
	
	var inputs = getInputs(id);
	for(var i = 0; i < inputs.length; i++)
		if(inputs[i].type == "text")
			inputs[i].style.borderColor = "#7f9db9";
}

// for use in onChange, onKeyUp, etc.
function onC(id)
{
	var checkimg = "siteimgs/form_greencheck.gif";
	var ximg = "siteimgs/form_redx.gif";

	var td = document.getElementById("label_" + id);

	if(validate(id))
		td.style.backgroundImage = "url('" + checkimg + "')";
	else
		td.style.backgroundImage = "url('" + ximg + "')";
}

// for use in onSubmit
function validate_all(submit)
{
	var valid = false;
	
	if(submit == true)
	{
		for(var i = 0; i < fields.length; i++)
			valid = valid | validate(fields[i]);
	
		return valid;
	}
	else
	{
		for(var i = 0; i < fields.length; i++)
			onC(fields[i]);
	}
}

// --- Helper functions ---

// Returns an array of inputs where the input tag's id attribute = "[id variable]-[i variable]" or "[id variable]"
function getInputs(id)
{
	var inputs = new Array();

	if(e = document.getElementById("field_" + id))
		inputs[0] = e;
	else
		for(var i = 0; i <= 2; i++)
			if(e = document.getElementById("field_" + id + "-" + i))
				inputs[inputs.length] = e;

	return inputs;
}

// Returns an array of values, one for each input tag
function getValues(id)
{
	var values = new Array();
	var inputs = getInputs(id);
	
	for(var i = 0; i < inputs.length; i++)
		values[i] = inputs[i].value;
	
	return values;
}