<!--
/*
 * Standard functions to aid form validation.
 * (c) Digital Sutras. All rights reserved.
 */

function isblank(s) 
// generic function to verify if a string is blank */
{
	var reg = /\S/;
	return !reg.test(s);
}

function check(element, err) 
// Is the field blank? Returns err if true, '' otherwise
{
	var error = '';
	if(isblank(element.value)) {
		error += err + '\n';
	}
	return error;
}

function checkEmail(element)
{
	var error = '';
	var emailFilter=/^.+@.+\..{2,3}$/;
	var email = element.value;

	if (!(emailFilter.test(email))) { 
		   error += "Invalid email address\n";
	}

	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (email.match(illegalChars)) {
	   error += "Email address contains illegal characters.\n";
	}

	return error;
}

function checkRadio(radio, err)
{
	var error = '';
	var selected = false;
	
	for(var i=0; i<radio.length; ++i)
		if(radio[i].checked)
			selected = true;
	
	if(!selected) 
		error += err + '\n';
	
	return error;
}

function checkCheckboxes(frm, prefix, err)
// It would have been ideal if the checkboxes could have the same
// name so we could loop through the array and check each one of them.
// While this is possible using JavaScript, PHP doesn't seem to like checkbox arrays. 
// Hence this inefficient workaround. 
{
	var error = '';
	var selected = false;
	var el = frm.elements;

	for(var i=0; i < el.length; ++i)
	{
		if((el[i].name.substr(0, prefix.length) == prefix) && el[i].checked)
			selected = true;
	}

	if(!selected)
		error += err + '\n';
	
	return error;
}
//-->