function checkForm() {
	if ($('phone1').value == '' || $('phone1').value.length < 3 || $('phone1').value.match(/[^0-9]/) != null) {
		alert('Please enter a valid phone number.');	$('phone1').focus();	return false;
	}
	if ($('phone2').value == '' || $('phone2').value.length < 3 || $('phone2').value.match(/[^0-9]/) != null) {
		alert('Please enter a valid phone number.');	$('phone2').focus();	return false;
	}
	if ($('phone3').value == '' || $('phone3').value.length < 4 || $('phone3').value.match(/[^0-9]/) != null) {
		alert('Please enter a valid phone number.');	$('phone3').focus();	return false;
	}
	if ($('carrierid').selectedIndex <= 0) {
		alert('Please select your mobile carrier.');	$('carrierid').focus();	return false;
	}
	if ($('agree').checked == false) {
		alert('Please check that you have read the Terms & Agreements');	return false;
	}
	var controls = new Array(), messages = new Array();
	controls.push('first_name');
	messages.push('Please enter your first name.');
	controls.push('last_name');
	messages.push('Please enter your last name.');
	controls.push('address1');
	messages.push('Please enter your address.');
	controls.push('city');
	messages.push('Please enter your city.');
	controls.push('zip');
	messages.push('Please enter your Zip code.');
	controls.push('email');
	messages.push('Please enter your email address.');
	for (var i=0; i < controls.length; i++) {
		if ($(controls[i]).value == '') {
			alert(messages[i]);
			$(controls[i]).focus();
			return false;
		}
	}
	
	var alerts = document.getElementsByTagName('input');
	var found = false;
	for (var i=0; i < alerts.length; i++) {
		if (alerts[i].name.substr(0,8) == 'list_cat') {
			found = true;
			break;
		}
	}
	if (!found) {
		alert('Please select the alerts you want to receive.');
		return false;
	}
	
	return true;
}

function addAlert(dropdown) {
	if (dropdown.selectedIndex <= 0) return;
	var alert_type = '';
	var opt = dropdown.options[dropdown.selectedIndex];
	
	if (dropdown.name == 'news_alerts') alert_type='news';
	else if (dropdown.name == 'lottery_alerts') alert_type='lottery';
	else if (dropdown.name == 'sports_alerts') alert_type='sports';
	else if (dropdown.name == 'weather_alerts') alert_type='weather';
	
	var d = document.createElement('div');
	d.innerHTML = opt.text+ ' &nbsp; <a href="#" onclick="removeAlert(this); return false;">Remove</a>';
	d.innerHTML += '<input type="hidden" name="list_cat['+ alert_type+ '][]" value="'+ opt.value+ '" />';
	$('selected_alerts').appendChild(d);
	opt.disabled = true;
	dropdown.selectedIndex = 0;
}
function removeAlert(lnk) {
	var prnt = lnk.parentNode;
	var id = prnt.getElementsByTagName('input')[0].value;
	prnt.parentNode.removeChild(prnt);
	var dropdowns = new Array('news_alerts', 'lottery_alerts', 'sports_alerts', 'weather_alerts');
	for (var i=0; i < dropdowns.length; i++) {
		for (var j=0; j < $(dropdowns[i]).options.length; j++) {
			if ($(dropdowns[i]).options[j].value == id) {
				$(dropdowns[i]).options[j].disabled = false;
				return;
			}
		}
	}
}
function $(id) {
	return document.getElementById(id);
}
function setDropdown(id, value) {
	var d = $(id);
	if (d == null) return;
	for (var i=0; i < d.options.length; i++) {
		if (d.options[i].value == value) {
			d.selectedIndex = i;
			return;
		}
	}
	d.selectedIndex = 0;
	return;
}
