function change_made() {
	if (document.getElementById('save_button') != null) {
		document.getElementById('save_button').disabled = false;
	}
}

function change_page(sNewTab) {
	sCurrentTab = document.getElementById('CurrentTab').value;
	
	document.getElementById(sCurrentTab).className = 'content';
	document.getElementById(sNewTab).className = 'selected_content';
	
	document.getElementById('CurrentTab').value = sNewTab;
}


function change_icon(action,oWhat) {
	if(action == "over" || action == "up") {
		oWhat.style.border = "1px outset";
		oWhat.style.padding = "0px";
	} else if(action == "down") {
		oWhat.style.border = "1px inset";
		oWhat.style.padding = "0px";
	} else {
		oWhat.style.borderWidth = "0px";
		oWhat.style.padding = "1px";
	}
}


function show_hide(sText) {	
	if (document.getElementById(sText).style.display == "none") {
		document.getElementById(sText).style.display = 'inline';
	} else {
		document.getElementById(sText).style.display = 'none';
	}
	
	build_search_types();
}

function build_search_types() {
	sDropdown = '';
	sDropdown += '<select name="Photo_RelatedTopic_0" style="width:220px;">';
	
	aPossibleTypes = new Array("Amputations", "Deformities", "Scars And Marks", "Tattoos", "Piercings", "Medical Implants", "Foreign Objects", "Skeletal Findings", "Organ Absent", "Prior Surgery");
	sDropdown += '<option>Facial/Case ID</option>'
			   + '<option>Fingerprint Card</option>'
			   + '<option>Dental Chart</option>'
			   + '<option>Dental Radiograph</option>'
			   + '<option>Other Radiograph</option>';
			   
	for (i=0; i<aPossibleTypes.length; ++i) {
		sField = aPossibleTypes[i].replace(/ /g, '') + 'Chk_box';
		if (document.getElementById(sField).checked == true) {
			sDropdown += '<option>' + aPossibleTypes[i] + '</option>';
		}
	}
	
	sDropdown += '<option>Other</option>';
	sDropdown += '</select>';
	
	document.getElementById('SearchType').innerHTML = sDropdown;
}

function confirm_delete() {
	sMessage = "Are you sure you want to delete this photo?\nClick \"OK\" to continue.\nClick \"Cancel\" to stop.";
	if (!confirm(sMessage)) {
		return false;
	}
}

function confirm_move(sPath) {
	if (document.getElementById('save_button')  != null && document.getElementById('save_button').disabled == false) {
		sMessage = "All changes to this case will be lost if you continue.\nClick \"OK\" to continue.\nClick \"Cancel\" to stop and then click \"Save\".";
		if (!confirm(sMessage)) {
			return false;
		}
	}
	
	window.location = sPath;
}

function confirm_save() {
	if (document.getElementById('CaseNumber').value == "") {
		alert('You must fill in a Case Number to save.');
		return false;
	}
	if (document.getElementById('DateFound').value == "-Not Recorded-") {
		alert('You must fill in a Date Found to save.');
		return false;
	}
}

function UpperJawNoTeeth(box) {
	if (box.checked == true) {
		for (i = 1; i <= 16; ++i) {
			document.getElementById('Tooth' + i).value = "A";
		}
	}
}

function LowerJawNoTeeth(box) {
	if (box.checked == true) {
		for (i = 17; i <= 32; ++i) {
			document.getElementById('Tooth' + i).value = "A";
		}
	}
}

function dental_check(e, box) {
	var key = window.event ? e.keyCode : e.which;
	
	if (key > 20)
	{
		var keychar = String.fromCharCode(key);
		if (box.value == "")
		{
			if (keychar == "n" || keychar == "f" || keychar == "c" || keychar == "b" || keychar == "a" || keychar == "p" || keychar == "i" || keychar == "o"
				|| keychar == "N" || keychar == "F" || keychar == "C" || keychar == "B" || keychar == "A" || keychar == "P" || keychar == "I" || keychar == "O"
				|| keychar == "R" || keychar == "r")
			{
				return true;
			}
			else
			{
				alert("You entered an invalid code.\nN, F, C, B, R, A, P, I, and O are the only valid codes.");
				return false;
			}
		}
		else
		{
			if (box.value == "n" || box.value == "N")
			{
				if (keychar == "o" || keychar == "i" || keychar == "O" || keychar == "I" || keychar == "r" || keychar == "R")
				{
					return true;
				}
				else
				{
					alert("You entered an invalid code.\nCode \"N\" can only be matched with O, R, or I");
					return false;
				}
			}
			else if (box.value == "o" || box.value == "O")
			{
				if (keychar == "n" || keychar == "f" || keychar == "c" || keychar == "b" || keychar == "a" || keychar == "p" || keychar == "i"
					|| keychar == "N" || keychar == "F" || keychar == "C" || keychar == "B" || keychar == "A" || keychar == "P" || keychar == "I"
					|| keychar == "r" || keychar == "R")
				{
					return true;
				}
				else
				{
					alert("You entered an invalid code.\nCode \"O\" can only be matched with N, F, C, B, R, A, P, or I");
					return false;
				}
			}
			else if (box.value == "f" || box.value == "F")
			{
				if (keychar == "o" || keychar == "O" || keychar == "r" || keychar == "R")
				{
					return true;
				}
				else
				{
					alert("You entered an invalid code.\nCode \"F\" can only be matched with O or R");
					return false;
				}
			}
			else if (box.value == "c" || box.value == "C")
			{
				if (keychar == "o" || keychar == "O" || keychar == "r" || keychar == "R")
				{
					return true;
				}
				else
				{
					alert("You entered an invalid code.\nCode \"C\" can only be matched with O or R");
					return false;
				}
			}
			else if (box.value == "b" || box.value == "B")
			{
				if (keychar == "o" || keychar == "O" || keychar == "r" || keychar == "R")
				{
					return true;
				}
				else
				{
					alert("You entered an invalid code.\nCode \"B\" can only be matched with O or R");
					return false;
				}
			}
			else if (box.value == "a" || box.value == "A")
			{
				if (keychar == "o" || keychar == "O")
				{
					return true;
				}
				else
				{
					alert("You entered an invalid code.\nCode \"A\" can only be matched with O");
					return false;
				}
			}
			else if (box.value == "p" || box.value == "P")
			{
				if (keychar == "o" || keychar == "O")
				{
					return true;
				}
				else
				{
					alert("You entered an invalid code.\nCode \"P\" can only be matched with O");
					return false;
				}
			}
			else if (box.value == "i" || box.value == "I")
			{
				if (keychar == "o" || keychar == "O" || keychar == "n" || keychar == "N")
				{
					return true;
				}
				else
				{
					alert("You entered an invalid code.\nCode \"I\" can only be matched with O or N");
					return false;
				}
			}
			else if (box.value == "r" || box.value == "R")
			{
				if (keychar == "n" || keychar == "N" || keychar == "f" || keychar == "F" || keychar == "c" || keychar == "C" 
					|| keychar == "o" || keychar == "O" || keychar == "b" || keychar == "B")
				{
					return true;
				}
				else
				{
					alert("You entered an invalid code.\nCode \"R\" can only be matched with N, F, C, B, or O");
					return false;
				}
			}
			else
			{
				return false;
			}
		}
	}
}


function confirm_change_owner() {
	var sFrom = document.getElementById('FromUserID').options[document.getElementById('FromUserID').selectedIndex].text;
	sFrom = sFrom.split(" - ");
	
	var sTo = document.getElementById('ToUserID').options[document.getElementById('ToUserID').selectedIndex].text;
	sTo = sTo.split(" - ");
	
	msg = "Are you sure you want all cases owned by \"" + sFrom[0] + "\" to have the owner changed to \"" + sTo[0] + "\"";
	if (!confirm(msg)) {
		return false;
	}
}


function confirm_delete_case() {
	if (document.getElementById('DeleteCaseID').value == "")
	{
		alert("You must enter a UDRS Case #");
		return false;
	}
	else if(IsNumeric(document.getElementById('DeleteCaseID').value) == false)
	{
		alert("The UDRS Case # must be all numeric");
		return false;
	}
	else
	{
		var sMsg = "Are you sure you want to delete UDRS Case # " + document.getElementById('DeleteCaseID').value;
		if (!confirm(sMsg))
		{
			return false;
		}
	}
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;


	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}