var W3CDOM = (document.getElementsByTagName && document.createElement);

function writeError(obj,message)
{
	firstError = obj;
	if (obj.hasError) return;
	if (W3CDOM)
	{
		obj.className = 'error';
		obj.onkeypress = removeError;
		var sp = document.createElement('p');
		sp.className = 'form_error';
		sp.appendChild(document.createTextNode(message));
		obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else
	{
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
	return obj;
}

function removeError()
{
	if (!this.hasError) return;
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onkeypress = null;
}

function writeErrorCheck(obj,message)
{
	firstError = obj;
	if (obj.hasError) return;
	if (W3CDOM)
	{
		obj.className = 'error';
		obj.onchange = removeErrorCheck;
		var sp = document.createElement('p');
		sp.className = 'form_error';
		sp.appendChild(document.createTextNode(message));
		obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else
	{
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
	return obj;
}

function removeErrorCheck()
{
	if (!this.hasError) return;
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onchange = null;
}

//for 'either - or' field dependencies
function writeError2(obj,message,obj2)
{
	firstError = obj;
	if (obj.hasError) return;
	if (W3CDOM)
	{
		obj.className = 'error';
		obj2.className = 'error';
		obj.onkeypress = removeError2;
		obj.c = obj2;
		obj2.onkeypress = removeError3;
		obj2.c = obj;
		var sp = document.createElement('p');
		sp.className = 'form_error';
		sp.appendChild(document.createTextNode(message));
		obj.parentNode.appendChild(sp);
		obj.hasError = sp;
	}
	else
	{
		errorstring += obj.name + ': ' + message + '\n';
		obj.hasError = true;
	}
	return obj;
}

function removeError2()
{
	if (!this.hasError) return;
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.c.className = this.c.className.substring(0,this.c.className.lastIndexOf(' '));
	this.parentNode.removeChild(this.hasError);
	this.hasError = null;
	this.onkeypress = null;
	this.c.onkeypress = null;
}
function removeError3()
{
	if (!this.c.hasError) return;
	this.className = this.className.substring(0,this.className.lastIndexOf(' '));
	this.c.className = this.c.className.substring(0,this.c.className.lastIndexOf(' '));
	this.c.parentNode.removeChild(this.c.hasError);
	this.c.hasError = null;
	this.c.onkeypress = null;
	this.onkeypress = null;
}


function isValidEmail(string) 
{
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
		return true;
	else
	return false;
}

function table_row_clicked (cell,checkbox,color)
{
	if (checkbox.checked)
		cell.style.background=color;
	else
		cell.style.background='#08c';
	checkbox.checked = !checkbox.checked;
}

function table_row_over (cell,checkbox,color)
{
	cell.style.background=color;
	cell.style.cursor='pointer';
}

function table_row_out (cell,checkbox,color)
{
	if (checkbox.checked)
		cell.style.background='#08c';
	else
		cell.style.background=color;
}

