// JavaScript Document

	var arrSurvivingSpouse = new Array();
	var arrDependentChild = new Array();
	var arrOtherSurvivor = new Array();

	var now    = new Date();
//	var hour   = now.getHours();
//	var minute = now.getMinutes();
//	var second = now.getSeconds();
	var month  = now.getMonth();
	var day    = now.getDate();
	var year   = now.getFullYear();

	// Surviving Spouse Functions
		function addOrRemoveSpouseFields(value)
		{
			if(value=="1")
				addSurvivingSpouse();
			else
				removeSurvivingSpouse(0);
		}
		function addSurvivingSpouse()
		{
			var arrNew = new Array("","","","","","","","","","","","");
		
			saveSurvivingSpouseValues();
			arrSurvivingSpouse.push(arrNew);
			writeSurvivingSpouseTable();
		}
		
		function removeSurvivingSpouse(index)
		{
			saveSurvivingSpouseValues();
			arrSurvivingSpouse.splice(index,1);
			writeSurvivingSpouseTable();
		}
		
		function saveSurvivingSpouseValues()
		{
			for(var i = 0; i < arrSurvivingSpouse.length; i++)
			{
				arrSurvivingSpouse[i][0] = document.getElementById("SurvivingSpouseTitle").value;
				arrSurvivingSpouse[i][1] = document.getElementById("SurvivingSpouseFirstName").value;
				arrSurvivingSpouse[i][2] = document.getElementById("SurvivingSpouseMiddleName").value;
				arrSurvivingSpouse[i][3] = document.getElementById("SurvivingSpouseLastName").value;
				arrSurvivingSpouse[i][4] = document.getElementById("SurvivingSpouseSuffix").value;
				arrSurvivingSpouse[i][5] = document.getElementById("SurvivingSpouseLocation").value;
				arrSurvivingSpouse[i][6] = document.getElementById("SurvivingSpouseStreet").value;
				arrSurvivingSpouse[i][7] = document.getElementById("SurvivingSpouseStreetTwo").value;
				arrSurvivingSpouse[i][8] = document.getElementById("SurvivingSpouseCity").value;
				arrSurvivingSpouse[i][9] = document.getElementById("SurvivingSpouseState").value;
				arrSurvivingSpouse[i][10] = document.getElementById("SurvivingSpouseZip").value;
				//arrSurvivingSpouse[i][11] = document.getElementById("SurvivingSpousePhone").value;
				//arrSurvivingSpouse[i][12] = document.getElementById("SurvivingSpousePhoneType").value;
			}
		}
		
		function writeSurvivingSpouseTable()
		{
			var output = "";

			if(arrSurvivingSpouse.length > 0)
			{
				for(var i = 0; i < arrSurvivingSpouse.length; i++)
				{
    				output += "<table>";
					output += "<tr><td style=\"width:200px;\"><label for=\"SurvivingSpouseTitle\">Title</label></td><td><input type=\"text\" id=\"SurvivingSpouseTitle\" name=\"SurvivingSpouseTitle\" size=\"20\" value=\"" + arrSurvivingSpouse[i][0] + "\" /></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseFirstName\">First Name</label></td><td><input type=\"text\" id=\"SurvivingSpouseFirstName\" name=\"SurvivingSpouseFirstName\" size=\"20\" value=\"" + arrSurvivingSpouse[i][1] + "\" /></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseMiddleName\">Middle Name</label></td><td><input type=\"text\" id=\"SurvivingSpouseMiddleName\" name=\"SurvivingSpouseMiddleName\" size=\"20\" value=\"" + arrSurvivingSpouse[i][2] + "\" /></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseLastName\">Last Name</label></td><td><input type=\"text\" id=\"SurvivingSpouseLastName\" name=\"SurvivingSpouseLastName\" size=\"20\" value=\"" + arrSurvivingSpouse[i][3] + "\" /></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseSuffix\">Suffix</label></td><td><input type=\"text\" id=\"SurvivingSpouseSuffix\" name=\"SurvivingSpouseSuffix\" maxlength=\"4\" size=\"20\" value=\"" + arrSurvivingSpouse[i][4] + "\" /></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseLocation\">Location</label></td><td><select id=\"SurvivingSpouseLocation\" name=\"SurvivingSpouseLocation\" size=\"1\">";
						output += "<option value='1'" + (arrSurvivingSpouse[i][5]=="Home" ? " selected='selected'" : "") + ">Home</option>";
						output += "<option value='0'" + (arrSurvivingSpouse[i][5]=="Work" ? " selected='selected'" : "") + ">Work</option>";
						output += "<option value='2'" + (arrSurvivingSpouse[i][5]=="Physical" ? " selected='selected'" : "") + ">Physical</option>";
					output += "</select></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseStreet\">Street</label></td><td><input type=\"text\" id=\"SurvivingSpouseStreet\" name=\"SurvivingSpouseStreet\" size=\"20\" value=\"" + arrSurvivingSpouse[i][6] + "\" /></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseStreetTwo\">Street 2</label></td><td><input type=\"text\" id=\"SurvivingSpouseStreetTwo\" name=\"SurvivingSpouseStreetTwo\" size=\"20\" value=\"" + arrSurvivingSpouse[i][7] + "\" /></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseCity\">City</label></td><td><input type=\"text\" id=\"SurvivingSpouseCity\" name=\"SurvivingSpouseCity\" size=\"20\" value=\"" + arrSurvivingSpouse[i][8] + "\" /></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseState\">State</label></td><td><input type=\"text\" id=\"SurvivingSpouseState\" name=\"SurvivingSpouseState\" maxlength=\"2\" size=\"20\" value=\"" + arrSurvivingSpouse[i][9] + "\" /></td></tr>";
					output += "<tr><td><label for=\"SurvivingSpouseZip\">Zip</label></td><td><input type=\"text\" id=\"SurvivingSpouseZip\" name=\"SurvivingSpouseZip\" maxlength=\"5\" size=\"20\" value=\"" + arrSurvivingSpouse[i][10] + "\" /></td></tr>";
					//output += "<tr><td><label for=\"SurvivingSpousePhone\">Phone</label></td><td><input type=\"text\" id=\"SurvivingSpousePhone\" name=\"SurvivingSpousePhone\" size=\"20\" value=\"" + arrSurvivingSpouse[i][11] + "\" /></td></tr>";
					//output += "<tr><td><label for=\"SurvivingSpousePhoneType\">Phone Number Type</label></td><td><select id=\"SurvivingSpousePhoneType\" name=\"SurvivingSpousePhoneType\" size=\"1\">";
						//output += "<option value='6'" + (arrSurvivingSpouse[i][12]=="6" ? " selected='selected'" : "") + ">Home</option>";
						//output += "<option value='9'" + (arrSurvivingSpouse[i][12]=="9" ? " selected='selected'" : "") + ">Work</option>";
						//output += "<option value='3'" + (arrSurvivingSpouse[i][12]=="3" ? " selected='selected'" : "") + ">Cell</option>";
						//output += "<option value='7'" + (arrSurvivingSpouse[i][12]=="7" ? " selected='selected'" : "") + ">Other</option>";
					output += "</select></td></tr>";
    				output += "</table>";
				}
			}

			document.getElementById("survivingSpouse").innerHTML = output;
		}

	// Dependent Child Functions
		function addDependentChild()
		{
			var arrNew = new Array("","","","");
		
			saveDependentChildValues();
			arrDependentChild.push(arrNew);
			writeDependentChildTable();
		}
		
		function removeDependentChild(index)
		{
			saveDependentChildValues();
			arrDependentChild.splice(index,1);
			writeDependentChildTable();
		}
		
		function saveDependentChildValues()
		{
			for(var i = 0; i < arrDependentChild.length; i++)
			{
				arrDependentChild[i][0] = document.getElementById("SurvivingChildFirstName" + i).value;
				arrDependentChild[i][1] = document.getElementById("SurvivingChildMiddleName" + i).value;
				arrDependentChild[i][2] = document.getElementById("SurvivingChildLastName" + i).value;
				arrDependentChild[i][3] = document.getElementById("SurvivingChildDateOfBirth" + i).value;
			}
		}
		
		function writeDependentChildTable()
		{
			var output = "";

			if(arrDependentChild.length > 0)
			{
				output += "<table>";
					
				output += "<tr>";
					output += "<th>First Name</th>";
					output += "<th>Middle Name</th>";
					output += "<th>Last Name</th>";
					output += "<th>Date of Birth</th>";
				output += "</tr>";
				
				for(var i = 0; i < arrDependentChild.length; i++)
				{
					output += "<tr>";
						output += "<td><input type=\"text\" id=\"SurvivingChildFirstName" + i + "\" name=\"SurvivingChildFirstName" + i + "\" size=\"20\" value=\"" + arrDependentChild[i][0] + "\" /></td>";
						output += "<td><input type=\"text\" id=\"SurvivingChildMiddleName" + i + "\" name=\"SurvivingChildMiddleName" + i + "\" size=\"20\" value=\"" + arrDependentChild[i][1] + "\" /></td>";
						output += "<td><input type=\"text\" id=\"SurvivingChildLastName" + i + "\" name=\"SurvivingChildLastName" + i + "\" size=\"20\" value=\"" + arrDependentChild[i][2] + "\" /></td>";
						output += "<td><input type=\"text\" readonly=\"readonly\" id=\"SurvivingChildDateOfBirth" + i + "\" name=\"SurvivingChildDateOfBirth" + i + "\" size=\"20\" value=\"" + arrDependentChild[i][3] + "\" /> <a href=\"javascript:ShowCalendar(document.getElementById('SurvivingChildDateOfBirth" + i + "'),'" + (year - 200) + "-" + month + "-" + day + "','" + year + "-" + month + "-" + month + "','mm/dd/yyyy')\"><img src='images/icon_calendar.gif' width='17' height='15' border='0' alt='Calendar' /></a></td>";
						output += "<td><a href=\"javascript:removeDependentChild(" + i + ");\">Remove Child</a></td>";
					output += "</tr>";
				}

				output += "</table>";
			}

			document.getElementById("dependentChild").innerHTML = output;
		}
		
	// Other Survivor Functions
		function addOtherSurvivor()
		{
			var arrNew = new Array("","","","","","","","","","","","","","","","");
		
			saveOtherSurvivorValues();
			arrOtherSurvivor.push(arrNew);
			writeOtherSurvivorTable();
		}
		
		function removeOtherSurvivor(index)
		{
			saveOtherSurvivorValues();
			arrOtherSurvivor.splice(index,1);
			writeOtherSurvivorTable();
		}
		
		function saveOtherSurvivorValues()
		{
			for(var i = 0; i < arrOtherSurvivor.length; i++)
			{
				arrOtherSurvivor[i][0] = document.getElementById("OtherSurvivorCode" + i).value;
				arrOtherSurvivor[i][1] = document.getElementById("OtherSurvivorTitle" + i).value;
				arrOtherSurvivor[i][2] = document.getElementById("OtherSurvivorFirstName" + i).value;
				arrOtherSurvivor[i][3] = document.getElementById("OtherSurvivorMiddleName" + i).value;
				arrOtherSurvivor[i][4] = document.getElementById("OtherSurvivorLastName" + i).value;
				arrOtherSurvivor[i][5] = document.getElementById("OtherSurvivorSuffix" + i).value;
				arrOtherSurvivor[i][6] = document.getElementById("OtherSurvivorDateOfBirth" + i).value;
				//arrOtherSurvivor[i][7] = document.getElementById("OtherSurvivorGuardian" + i).value;
				arrOtherSurvivor[i][7] = document.getElementById("OtherSurvivorLocation" + i).value;
				arrOtherSurvivor[i][8] = document.getElementById("OtherSurvivorStreet" + i).value;
				arrOtherSurvivor[i][9] = document.getElementById("OtherSurvivorStreetTwo" + i).value;
				arrOtherSurvivor[i][10] = document.getElementById("OtherSurvivorCity" + i).value;
				arrOtherSurvivor[i][11] = document.getElementById("OtherSurvivorState" + i).value;
				arrOtherSurvivor[i][12] = document.getElementById("OtherSurvivorZip" + i).value;
				//arrOtherSurvivor[i][12] = document.getElementById("OtherSurvivorPhone" + i).value;
				//arrOtherSurvivor[i][13] = document.getElementById("OtherSurvivorPhoneType" + i).value;
			}
		}
		
		function writeOtherSurvivorTable()
		{
			var output = "";

			if(arrOtherSurvivor.length > 0)
			{
				for(var i = 0; i < arrOtherSurvivor.length; i++)
				{
				
					output += "<table>";
					
					if(i > 0)
					{
						output += "<tr><td colspan=\"2\"><hr /></td></tr>";
					}
					output += "<tr><td><label for=\"OtherSurvivorCode" + i + "\">Relationship to Officer</label></td><td><select id=\"OtherSurvivorCode" + i + "\" name=\"OtherSurvivorCode" + i + "\" size=\"1\">";
						output += "<option value='AC'" + (arrOtherSurvivor[i][0]=="AC" ? " selected='selected'" : "") + ">Adult Child</option>";
						output += "<option value='CW'" + (arrOtherSurvivor[i][0]=="CW" ? " selected='selected'" : "") + ">Co-Worker</option>";
						output += "<option value='F'" + (arrOtherSurvivor[i][0]=="F" ? " selected='selected'" : "") + ">Father</option>";
						output += "<option value='FF'" + (arrOtherSurvivor[i][0]=="FF" ? " selected='selected'" : "") + ">Foster Father</option>";
						output += "<option value='FM'" + (arrOtherSurvivor[i][0]=="FM" ? " selected='selected'" : "") + ">Foster Mother</option>";
						output += "<option value='FN'" + (arrOtherSurvivor[i][0]=="FN" ? " selected='selected'" : "") + ">Fiancee</option>";
						output += "<option value='FS'" + (arrOtherSurvivor[i][0]=="FS" ? " selected='selected'" : "") + ">Former Spouse</option>";
						output += "<option value='GC'" + (arrOtherSurvivor[i][0]=="GC" ? " selected='selected'" : "") + ">Grand Child</option>";
						output += "<option value='GF'" + (arrOtherSurvivor[i][0]=="GF" ? " selected='selected'" : "") + ">Grand Father</option>";
						output += "<option value='GM'" + (arrOtherSurvivor[i][0]=="GM" ? " selected='selected'" : "") + ">Grand Mother</option>";
						output += "<option value='I'" + (arrOtherSurvivor[i][0]=="I" ? " selected='selected'" : "") + ">In-Law</option>";
						output += "<option value='M'" + (arrOtherSurvivor[i][0]=="M" ? " selected='selected'" : "") + ">Mother</option>";
						output += "<option value='O'" + (arrOtherSurvivor[i][0]=="O" ? " selected='selected'" : "") + ">Other</option>";
						output += "<option value='S'" + (arrOtherSurvivor[i][0]=="S" ? " selected='selected'" : "") + ">Sibling</option>";
						output += "<option value='SF'" + (arrOtherSurvivor[i][0]=="SF" ? " selected='selected'" : "") + ">Step Father</option>";
						output += "<option value='SM'" + (arrOtherSurvivor[i][0]=="SM" ? " selected='selected'" : "") + ">Step Mother</option>";
						output += "<option value='SO'" + (arrOtherSurvivor[i][0]=="SO" ? " selected='selected'" : "") + ">Significant Other</option>";
					output += "</select></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorTitle" + i + "\">Title</label></td><td><input type=\"text\" id=\"OtherSurvivorTitle" + i + "\" name=\"OtherSurvivorTitle" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][1] + "\" /></td></tr>";
					output += "<tr><td style=\"width:200px;\"><label for=\"OtherSurvivorFirstName" + i + "\">First Name</label></td><td><input type=\"text\" id=\"OtherSurvivorFirstName" + i + "\" name=\"OtherSurvivorFirstName" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][2] + "\" /></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorMiddleName" + i + "\">Middle Name</label></td><td><input type=\"text\" id=\"OtherSurvivorMiddleName" + i + "\" name=\"OtherSurvivorMiddleName" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][3] + "\" /></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorLastName" + i + "\">Last Name</label></td><td><input type=\"text\" id=\"OtherSurvivorLastName" + i + "\" name=\"OtherSurvivorLastName" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][4] + "\" /></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorSuffix" + i + "\">Suffix</label></td><td><input type=\"text\" id=\"OtherSurvivorSuffix" + i + "\" name=\"OtherSurvivorSuffix" + i + "\" maxlength=\"4\" size=\"20\" value=\"" + arrOtherSurvivor[i][5] + "\" /></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorDateOfBirth" + i + "\">Date of Birth</label></td><td><input type=\"text\" id=\"OtherSurvivorDateOfBirth" + i + "\" name=\"OtherSurvivorDateOfBirth" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][6] + "\" /> <a href=\"javascript:ShowCalendar(document.getElementById('OtherSurvivorDateOfBirth" + i + "'),'" + (year - 200) + "-" + month + "-" + day + "','" + year + "-" + month + "-" + month + "','mm/dd/yyyy')\"><img src='images/icon_calendar.gif' width='17' height='15' border='0' alt='Calendar' /></a></td></tr>";
					//output += "<tr><td><label for=\"OtherSurvivorGuardian" + i + "\">Guardian</label></td><td><input type=\"text\" id=\"OtherSurvivorGuardian" + i + "\" name=\"OtherSurvivorGuardian" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][7] + "\" /></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorLocation" + i + "\">Location</label></td><td><select id=\"OtherSurvivorLocation" + i + "\" name=\"OtherSurvivorLocation" + i + "\" size=\"1\">";
						output += "<option value='1'" + (arrOtherSurvivor[i][8]=="Home" ? " selected='selected'" : "") + ">Home</option>";
						output += "<option value='0'" + (arrOtherSurvivor[i][8]=="Work" ? " selected='selected'" : "") + ">Work</option>";
						output += "<option value='2'" + (arrOtherSurvivor[i][8]=="Physical" ? " selected='selected'" : "") + ">Physical</option>";
					output += "</select></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorStreet" + i + "\">Street</label></td><td><input type=\"text\" id=\"OtherSurvivorStreet" + i + "\" name=\"OtherSurvivorStreet" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][9] + "\" /></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorStreetTwo" + i + "\">Street 2</label></td><td><input type=\"text\" id=\"OtherSurvivorStreetTwo" + i + "\" name=\"OtherSurvivorStreetTwo" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][10] + "\" /></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorCity" + i + "\">City</label></td><td><input type=\"text\" id=\"OtherSurvivorCity" + i + "\" name=\"OtherSurvivorCity" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][11] + "\" /></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorState" + i + "\">State</label></td><td><input type=\"text\" id=\"OtherSurvivorState" + i + "\" name=\"OtherSurvivorState" + i + "\" maxlength=\"2\" size=\"20\" value=\"" + arrOtherSurvivor[i][12] + "\" /></td></tr>";
					output += "<tr><td><label for=\"OtherSurvivorZip" + i + "\">Zip</label></td><td><input type=\"text\" id=\"OtherSurvivorZip" + i + "\" name=\"OtherSurvivorZip" + i + "\" size=\"20\" maxlength=\"5\" value=\"" + arrOtherSurvivor[i][13] + "\" /></td></tr>";
					//output += "<tr><td><label for=\"OtherSurvivorPhone" + i + "\">Phone</label></td><td><input type=\"text\" id=\"OtherSurvivorPhone" + i + "\" name=\"OtherSurvivorPhone" + i + "\" size=\"20\" value=\"" + arrOtherSurvivor[i][14] + "\" /></td></tr>";
					//output += "<tr><td><label for=\"OtherSurvivorPhoneType" + i + "\">Phone Number Type</label></td><td><select id=\"OtherSurvivorPhoneType" + i + "\" name=\"OtherSurvivorPhoneType" + i + "\" size=\"1\">";
						//output += "<option value='6'" + (arrOtherSurvivor[i][15]=="6" ? " selected='selected'" : "") + ">Home</option>";
						//output += "<option value='9'" + (arrOtherSurvivor[i][15]=="9" ? " selected='selected'" : "") + ">Work</option>";
						//output += "<option value='3'" + (arrOtherSurvivor[i][15]=="3" ? " selected='selected'" : "") + ">Cell</option>";
						//output += "<option value='7'" + (arrOtherSurvivor[i][15]=="7" ? " selected='selected'" : "") + ">Other</option>";
					output += "</select></td></tr>";
					output += "<tr><td>&nbsp;</td><td><a href=\"javascript:removeOtherSurvivor(" + i + ");\">Remove Survivor</a></td></tr>";

					output += "<table>";
				}
			}

			document.getElementById("otherSurvivor").innerHTML = output;
		}

	function validate()
	{
		// list the fields that require a valid value
	    var arrValidFields = new Array(new Array("SubmitterPhone", "Your Phone Number")
  									  ,new Array("LiaisonOfficerPhone","Liaison Phone Number")
									  );

    	var phoneRe = /^(\d{10})$/;	

		for (var i = 0; i < arrValidFields.length; i++)
		{
            // remove symbols then check for 10 numbers
            var Phone = document.getElementById(arrValidFields[i][0]).value;
            Phone = Phone.replace(/-/g,"");   //  -
            Phone = Phone.replace(/\(/g,"");  //  (
            Phone = Phone.replace(/\)/g,"");  //  )
            Phone = Phone.replace(/ /g,"");   //  [space]
            Phone = Phone.replace(/\./g,"");  //  .

		    if(!isNull(arrValidFields[i][0]) && !phoneRe.test(Phone))
			{
			    alert(arrValidFields[i][1] + " is invalid");
				if(document.getElementById(arrValidFields[i][0]) != null) 
				    document.getElementById(arrValidFields[i][0]).select();
				return false;
			}
		}
	
		// list the fields that require a value
	    var arrRequiredFields = new Array(new Array("OfficersFirstName", "Officer's First Name"),
										  new Array("OfficersRank","Officer's Rank"),
										  new Array("DateOfIncident","Date of Incident"),
										  new Array("DateOfDeath","Date of Death"),
										  new Array("LiaisonOfficerFirstName", "Liaison Officer First Name"),
										  new Array("LiaisonOfficerPhone", "Phone Number"));

		for (var i = 0; i < arrRequiredFields.length; i++)
		{
			if(isNull(arrRequiredFields[i][0]))
			{
			    alert(arrRequiredFields[i][1] + " is required");
				if(document.getElementById(arrRequiredFields[i][0]) != null) 
				    document.getElementById(arrRequiredFields[i][0]).select();
				return false;
			}
		}
		
		return true;
	}
	
	function isNull(id)
	{
		if(document.getElementById(id) == null || document.getElementById(id).value == "" || document.getElementById(id).value == null)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

