function callback(object, returns) {
	if (returns) {
		object.style.backgroundColor = "white";
		if (object.parentNode.getElementsByTagName("LABEL")[0]) object.parentNode.getElementsByTagName("LABEL")[0].style.color="white";
		object.isValid = true;
	} else {
		object.style.backgroundColor = "#f69679";
		if (object.parentNode.getElementsByTagName("LABEL")[0]) object.parentNode.getElementsByTagName("LABEL")[0].style.color="red";
		object.isValid = false;
	}
}

function phoneCallBack(object, returns) {
	if (returns) {
		var worked = true;
		for (var i = 0; i < object.parentNode.parentNode.getElementsByTagName("INPUT").length; ++i) {
			if (!object.parentNode.parentNode.getElementsByTagName("INPUT")[i].validator.validate2()) {
				worked = false;
			}
		}
		object.style.backgroundColor = "white";
		if (worked) {
			object.parentNode.parentNode.getElementsByTagName("LABEL")[0].style.color="white";
			object.isValid = true;
		}
	} else {
		object.style.backgroundColor = "#f69679";
		object.parentNode.parentNode.getElementsByTagName("LABEL")[0].style.color="red";
		object.isValid = false;
	}
}

function testIndex (object) {
	if (object.selectedIndex == 0) {
		return false;
	}
	return true;
}

function validateAddress (object) {
	var reg = /^[a-zA-Z0-9\s\#]*[a-zA-Z0-9\s\#]*[a-zA-Z0-9\s\#]*$/;
	return (isInput(object)) ? reg.test(object.value) : reg.test(object.options[object.selectedIndex].value);
}

function interpretKeyCode(e) {
	var keynum
	var keychar
	if(window.event) {
		keynum = e.keyCode;
	} else if(e.which) {
		keynum = e.which;
	}
	return keynum;
}

function init() {
	var valid = new Validation();
	var validators = new Array();
	validators.push(new Validator(document.getElementById('request-more-information').program, callback));
	validators[validators.length - 1].addValidation(testIndex);

	validators.push(new Validator(document.getElementById('request-more-information').name, callback));
	validators[validators.length - 1].addValidation(valid.isAlpha(true));
	validators[validators.length - 1].addValidation(valid.isBounded(1,50));

	validators.push(new Validator(document.getElementById('request-more-information').address, callback));
	validators[validators.length - 1].addValidation(validateAddress);
	validators[validators.length - 1].addValidation(valid.isBounded(2,75));

	validators.push(new Validator(document.getElementById('request-more-information').city, callback));
	validators[validators.length - 1].addValidation(valid.isAlphaNumeric(true));
	validators[validators.length - 1].addValidation(valid.isBounded(2,50));

	validators.push(new Validator(document.getElementById('request-more-information').zip, callback));
	validators[validators.length - 1].addValidation(valid.isNumeric(false));
	validators[validators.length - 1].addValidation(valid.isBounded(5,5));
	
	document.getElementById('request-more-information').phone.setAttribute('autocomplete', 'off');
	validators.push(new Validator(document.getElementById('request-more-information').phone, callback));
	validators[validators.length - 1].addValidation(valid.isPhone());
	
	validators.push(new Validator(document.getElementById('request-more-information').email, callback));
	validators[validators.length - 1].addValidation(valid.isEmail());
	
	validators.push(new Validator(document.getElementById('request-more-information').grad_year, callback));
	validators[validators.length - 1].addValidation(valid.isNumeric(false));
	validators[validators.length - 1].addValidation(valid.isBounded(4,4));
	
	validators.push(new Validator(document.getElementById('request-more-information').heard, callback));
	validators[validators.length - 1].addValidation(testIndex);
	
	valid.add(validators);
	valid.addEventToAll("blur");
	var observer = function() {
						if (valid.validate()) {
							return true;
						} else {
							return false;
						}
					};
	document.getElementById('submit').onclick = observer;
}