
function Required(id) {
	var formval = document.getElementById(id).value;
	if(formval == null || formval.length == 0)
	{
		ErrorOn(id);
		return 1;
	}
	else {
		ErrorOff(id)
		return 0;
	}
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
	// if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function   

// checks if answer radio button selected
function AnswerPicked(theForm)
{
		if(getSelectedRadio(theForm.answer) == -1)
			return 1;
		else
			return 0;
}

function Checked(id) {
	var formval = document.getElementById(id).checked;
	if(formval == false)
	{
		// ErrorOn(id,errorMessage);
		return 1;
	}
	else {
		// ErrorOff(id)
		return 0;
	}
}



function RequiredNoError(id) {
	var formval = document.getElementById(id).value;
	if(formval == null || formval.length == 0)
	{
		return 0;
	}
	else {
		return 1;
	}
}

function EmailValid(id) {
	var formval = document.getElementById(id).value;
	var regEx = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (!formval.match(regEx)) {
		ErrorOn(id);
		return 1;
	} else {
		ErrorOff(id)
		return 0;
	}
}

function ErrorOn(id) {
	var elem = document.getElementById(id);
	elem.className = "textfield formerror";
	
	elem = document.getElementById(id+"_label");
	elem.className = "textfield formerror";

}

function ErrorOff(id) {
	var elem = document.getElementById(id);
	elem.className = "textfield";
	elem = document.getElementById(id+"_label");
	elem.className = "textfield";
}