function checkForm(formObj)
{
    resetForm(formObj);

    return checkMtgName(formObj.mtgName) &&
           checkLength(formObj.mtgLength) &&
           checkDay(formObj.day) &&
           checkTime(formObj.time) &&
           checkAccess(formObj.access) &&
           checkContact(formObj.contactName) &&
           checkEmail(formObj.contactEmail);
}

function resetForm(formObj)
{
    // reset field text to black
    formObj.mtgName.style.color = "black";
    formObj.mtgLength.style.color = "black";
    formObj.day.style.color = "black";
    formObj.time.style.color = "black";
    formObj.access.style.color = "black";
    formObj.contactName.style.color = "black";
    formObj.contactEmail.style.color = "black";
    
    // reset asterisks to hidden
    atkMtgName.style.visibility = 'hidden';
    atkMtgLength.style.visibility = 'hidden';
    atkDay.style.visibility = 'hidden';
    atkTime.style.visibility = 'hidden';
    atkAccess.style.visibility = 'hidden';
    atkContactName.style.visibility = 'hidden';
    atkContactEmail.style.visibility = 'hidden';    
}

// Returns true if the value of the text element is null or whitespace:
function isEmpty( textObj ) {
  var regexp = /^\s*$/;
  return regexp.test( textObj.value );
}

function checkMtgName(mtgNameObj)
{
	if (isEmpty(mtgNameObj))
	{
		alert("Please enter a meeting name.");
        atkMtgName.style.visibility = "visible";
        mtgNameObj.focus(); 
        return false;
	}
	
	return true;
}

function checkLength(mtgLengthObj)
{
	var regexp = /^\d+$/;
	
	if (!regexp.test(mtgLengthObj.value))
	{
		alert("Please enter a numeric meeting length (in minutes).");
		atkMtgLength.style.visibility = "visible";
		if (mtgLengthObj.value.length > 0)
		{
			mtgLengthObj.style.color="red";
		}
		mtgLengthObj.focus();
		
		return false;
	}
	
	return true;
}

function checkDay(dayObj)
{
	if (dayObj.selectedIndex == 0)
	{
		alert("Please enter a preferred day for the meeting.");
        atkDay.style.visibility = "visible"; 
        dayObj.style.color = "red";
		dayObj.focus();
        return false;
	}
	
	return true;
}

function checkTime(timeObj)
{
	if (isEmpty(timeObj))
	{
		alert("Please enter a preferred time for the meeting.");
        atkTime.style.visibility = "visible";
    	timeObj.focus(); 
        return false;
    }
    
    return true;
} 

function checkAccess(accessObj) 
{
	if (accessObj.selectedIndex == 0)
	{
		alert("Please enter an access level for the meeting.");
        atkAccess.style.visibility = "visible"; 
        accessObj.style.color = "red";
		accessObj.focus();
        return false;
	}
	
	return true;
}

function checkContact(contactNameObj) 
{
	if (isEmpty(contactNameObj))
	{
		alert("Please enter the name of a person we can contact.");
        atkContactName.style.visibility = "visible"; 
        contactNameObj.focus();
        return false;
    }
    
    return true;
}

function checkEmail(contactEmailObj)
{
	var regexp = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	
	if (!regexp.test(contactEmailObj.value))
	{
		alert("Please enter a valid e-mail address.");
		atkContactEmail.style.visibility = "visible";
		if (contactEmailObj.value.length > 0)
		{
			contactEmailObj.style.color="red";
		}
		contactEmailObj.focus();
		
		return false;
	}
	
	return true;
}

