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 = '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;
}

/*** AJAX ***/

//create a new ajax/xmlrpc request object to query a web server
function createRequestObject () {
	// declare the variable to hold the object.
	var request_o;
	// find the browser name
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		// create the object using MSIE's method
		request_o = new ActiveXObject ("Microsoft.XMLHTTP");
	}else{
		// create the object using other browser's method
		request_o = new XMLHttpRequest();
	}
	// return the object
	return request_o;
}
