/* Popups */
function newPopup(url,name,width,height) {
	var popup = window.open(url, name, 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width='+width+',height='+height);
	popup.moveTo(0,0);
}

/* Form Functions */
function swapBg(e, color) {
	if (isEmpty(color)) {
		color = '#FFF';
	}
	e.style.backgroundColor = color;
}
function alertBlank(e) {
	swapBg(e, '#FAA');
	e.focus();
	alert('This field cannot be left blank.');
}

function alertInvalid(e) {
	swapBg(e, '#FAA');
	e.focus();
	alert('Your entry in this field is invalid. Please verify your entry.');
}
function alertMismatch(e1, e2) {
	swapBg(e1, '#FAA');
	swapBg(e2, '#FAA');
	e1.focus();
	alert('These fields to not match. Please verify your entry.');
}

function isEmpty(mixed) {
	if (typeof mixed == 'object') {
		var input = mixed.value;
	} else {
		var input = mixed;
	}
	if (input === "" || input === 0 || input === "0" || input === null || input === false || input === undefined) {
		return true;
	} else {
		return false;
	}
}

function isValidEmail(e) {
	var input = e.value;
	if (isEmpty(input)) {
		alertBlank(e);
		return false;
	} else {
		var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
		if (pattern.test(input)) {
			return true;
		} else {
			alertInvalid(e);
			return false;
		}
	}
}

function isValidPhone(e) {
	var input = e.value;
	if (isEmpty(input)) {
		alertBlank(e);
		return false;
	} else {
		var pattern=/^[0-9]{3}-?[0-9]{3}-?[0-9]{4}$/;
		if (pattern.test(input)) {
			return true;
		} else {
			alertInvalid(e);
			return false;
		}
	}
}

function isValidZip(e) {
	var input = e.value;
	if (isEmpty(input)) {
		alertBlank(e);
		return false;
	} else {
		var pattern=/^[0-9]{5}$/;
		if (pattern.test(input)) {
			return true;
		} else {
			alertInvalid(e);
			return false;
		}
	}
}

function isNumeric(e) {
	var regex = /[0-9\.]+/ig;
	if (e.value.match(regex)) {
		return true;
	} else {
		return false;
	}
}


