function showTable(id) {
	document.getElementById(id).style.display = 'block';
}

function hideTable(id) {
	document.getElementById(id).style.display = 'none';
}

function isNumberKey(evt, id, max) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode == 8 || charCode == 9 || charCode == 46 || charCode == 16 || charCode == 37 || charCode == 39) return true;
	
	if (id != 'reg') {	
		if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
	}
	
	if (id) {
		var entry = document.getElementById(id).value;
		if (entry.length >= max) return false;
	
	}
	return true;
}

function checkFormInput() {
	
	var inputs = new Array();
	inputs[0] = 'fname';
	inputs[1] = 'lname';
	inputs[2] = 'date';
	inputs[3] = 'month';
	inputs[4] = 'year';
	inputs[5] = 'gender';
	inputs[6] = 'city';
	inputs[7] = 'country';
	inputs[8] = 'phone';
	inputs[9] = 'notice';
	inputs[10] = 'street';
	inputs[11] = 'reg';
	inputs[12] = 'exp';

	
	for (var i = 0; i < 13; i++) {
		if(document.getElementById(inputs[i]).value == '') {
			alert('Please make sure you fill in all required fields.');
			return false;
		}
	}

	return true;
}

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

function checkbox(box1) {
	var entry = document.getElementById(box1).value;
	if (entry == '') {
		alert("Please enter a search query.");
		return false;
	} else if (!isNumber(entry)) {
		alert("DVRs and RIDs may only contain numbers.");
		return false;
	}
	return true;	
}

function checksearch(box1) {
	var entry = document.getElementById(box1).value;
	if (entry == '') {
		alert("Please enter a search query.");
		return false;
	} 
	return true;	
}

function addHidden(rowid) {
	if (document.getElementById('mailbox' + rowid).checked == true) {
		var newinput = document.createElement('input');
		newinput.type = 'hidden';
		newinput.name = 'email[]';
		newinput.id = 'hidden' + rowid;
		newinput.value = rowid;
		document.getElementById('mailform').appendChild(newinput);
	} else {
		var oldinput = document.getElementById('hidden' + rowid);
		document.getElementById('mailform').removeChild(oldinput);
	}
}
