function isEmpty(theItem) {
    if (theItem.value == null || theItem.value=="") {
        return true;
    } else {
		return false;
    }
}

function checkNotEmpty(theItem, theItemLabel) {
    var label = document.getElementById(theItemLabel);
    if (isEmpty(theItem)) {
        label.firstChild.nodeValue = "Required. Please Amend";
    } else {
    	label.firstChild.nodeValue = "";
    }
}

function checkIsEmail(theItem, theItemLabel, isRequired) {
	var label = document.getElementById(theItemLabel);
    if (isEmpty(theItem)) {
       if (isRequired) {
           label.firstChild.nodeValue = "Required. Please Amend";
       } else {
           label.firstChild.nodeValue = "";
       }
    } else {
       var emailRegex = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/;
       if (emailRegex.test(theItem.value)) {
           label.firstChild.nodeValue = "";
       } else {
           label.firstChild.nodeValue = "Invalid email address. Please check";
       }
    }	
}

function checkIsNumeric(theItem, theItemLabel, isRequired) {
    var label = document.getElementById(theItemLabel);
    if (isEmpty(theItem)) {
       if (isRequired) {
           label.firstChild.nodeValue = "Required. Please Amend";
       } else {
           label.firstChild.nodeValue = "";
       }
    } else {
       var positiveIntegerRegularExpression = /(^[0-9]\d*$)/;
       if (positiveIntegerRegularExpression.test(theItem.value)) {
           label.firstChild.nodeValue = "";
       } else {
           label.firstChild.nodeValue = "Please enter numbers only (no spaces)";
       }
    }
}

function setEnabled(items, value) {
    for (i = 0; i < items.length; i++) {
        items[i].disabled = value;
    }
}
