function checkform_1( frm )
{
	var str = "";

	var isgroup = false;
	if( frm.elements["isgroup"] != null )
	{
		if( frm.elements["isgroup"].value > 0 )
			isgroup = true;
	}
	
	cnt = frm.numofitems.value;
	acnt = 0;
	errcnt = 0;
	for( i = 1; i <= cnt; i++ )
	{
		if( isgroup )
		{
			if( frm.elements["Item"+i].value > 0 )
			{
				acnt++;
				if (frm.elements["gfname"+i].value == "" || frm.elements["glname"+i].value == "")
					errcnt++;
			}
		}
		else
		{
			if( frm.elements["Item"+i].checked )
				acnt++;
		}
	}
	if( isgroup )
	{
		if( acnt == 0 )
			str += "At least one student must be entered !!!\n";
		else
		{
			if( errcnt > 0 )
				str += "Not all students' first and last names entered !!!\n";
		}
	}
	else
	{
		if( acnt == 0 )
			str += "At least one course must be selected !!!\n";
	}
	return str;
}

function checkform_2( frm )
{
	var str = "";

	var isgroup = false;
	if( frm.elements["isgroup"] != null )
	{
		if( frm.elements["isgroup"].value > 0 )
			isgroup = true;
	}

	if( frm.firstname.value == "" )
		str += "Please fill First Name field.\n";

	if( frm.lastname.value == "" )
		str += "Please fill Last Name field.\n";
	
	if( frm.street.value == "" )
		str += "Please fill Street field.\n";

	if( frm.city.value == "" )
		str += "Please fill City field.\n";

	if( frm.state.value == "" )
		str += "Please fill State or Province field.\n";

	if( frm.postalcode.value == "" )
		str += "Please fill Postal code field.\n";

	if( frm.phone.value == "" )
		str += "Please fill Phone number field.\n";
	
	re = /^\s*([\-\w]+)(\.[\-\w]+)*\@([\-\w]+)(\.[\-\w]+)+\s*$/;
	if( !re.test(frm.email.value) )
		str += "Please fill email field with your email address.\n";
	
	if ( isgroup && frm.Group.value == "" )
		str += "Please fill Group field.\n";

	return str;
}

function checkform( frm, mode )
{
	var str = "";
	switch(mode) {
		case 1:
			str = checkform_1(frm);
			break;
		case 2:
			str = checkform_2(frm);
			break;
		case 3:
			str = checkform_1(frm) + checkform_2(frm);
			break;
	}
	
	if( str != "" )
	{
		alert(str);
		return false;
	}
	return true;
}
