function addElement() {
  var ni = document.getElementById('relation');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 2;
  numi.value = num;
  var newListElement = document.createElement('li');
  var listElementIdName = 'relation'+num;
  newListElement.setAttribute('id',listElementIdName);
  newListElement.setAttribute('class','relationListElement');
  newListElement.setAttribute('name',listElementIdName);


 newListElement.innerHTML = '<label for="relation_firstName'+num+'">FirstName</label><input type="text" name="relation_firstName'+num+'" id="relation_firstName'+num+'"/><label for="relation_lastName'+num+'">Last Name</label><input type="text" name="relation_lastName'+num+'" id="relation_lastName'+num+'"/><label for="relationship'+num+'">Relationship</label><select name="relationship'+num+'" id="relationship'+num+'"/><option value="parent">Parent</option><option value="child">Child</option><option value="former spouse">Former Spouse</option><option value="spouse">Spouse</option><option value="sibling">Sibling</option><option value="life partner">Life Partner</option></select><input type=\'checkbox\' class=\'check\' name="predeceased'+num+'" id="predeceased'+num+'" value=\'1\'">Predeceased or known link?<br/><a href="javascript:;" onClick="removeElement(\'relation'+num+'\')">remove</a></li>';
  ni.appendChild(newListElement);
}

function removeElement(relative) {
  var d = document.getElementById("relation");
  var olddiv = document.getElementById(relative);
    var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1);
  numi.value = num;

 d.removeChild(olddiv);
}

function validate_userForm(){
valid =true;
var message="";
var checkDate=new RegExp("^[0-9]{2}-[0-9]{2}-[0-9]{4}$"); //check dates
var otherDate=new RegExp("^[0-9]{4}$");
		if ( (document.advancedSearch.diedBefore.value != "")  )
			{
				//check to see if it is written in the form MM-DD-YYYY or YYYY else send message
				if (!((checkDate.test(document.advancedSearch.diedBefore.value)==true) || (otherDate.test(document.advancedSearch.diedBefore.value)==true)))
				{
					message =message+"\nPlease fill in the Dates in the format YYYY (i.e. 1984)";
					valid = false;
				}
			}


			if ( (document.advancedSearch.diedAfter.value != "")  )
			{
				//check to see if it is written in the form MM-DD-YYYY or YYYY else send message
				if (!((checkDate.test(document.advancedSearch.diedAfter.value)==true) || (otherDate.test(document.advancedSearch.diedAfter.value)==true)))				{
					message =message+"\nPlease fill in the Dates in the format YYYY (i.e. 1983)";
					valid = false;
				}
			}
				if (message !="") alert(message);
    return valid;

}




function validate_form(){
	valid = true;
	var message="";
	var checkDate=new RegExp("[0-9]{2}-[0-9]{2}-[0-9]{4}"); //check dates

    if ( document.obituaryForm.lastname.value == "" )
		{
        message =message+"\nPlease fill in the Last Name.";
        valid = false;
		}
//check format of the date of death
	if ( (document.obituaryForm.dateOfDeath.value != "")  )
		{
		//check to see if it is written in the form MM-DD-YYYY else send message
			if (checkDate.test(document.obituaryForm.dateOfDeath.value)==false)
			{
				message =message+"\nPlease fill in the Date of Death in the format MM-DD-YYYY.";
			  valid = false;
			}
        }

		//check format of the date of birth
	if ( (document.obituaryForm.birthDate.value != "")  )
		{
		//check to see if it is written in the form MM-DD-YYYY else send message

			if (checkDate.test(document.obituaryForm.birthDate.value)==false)
			{
				message =message+"\nPlease fill in the Date of Birth in the format MM-DD-YYYY.";
			  valid = false;
			}
        }

//check format of the obituary date
	/*if ( (checkDate.test(document.obituaryForm.obituaryDate.value)==false))
		{
        message =message+"\nPlease fill in the Obituary date in the format MM-DD-YYYY.";
        valid = false;
		}*/

	if ( document.obituaryForm.obituarySource.value == "" )
		{
        message =message+"\nPlease fill in the ObituarySource.";
        valid = false;
		}
	if ( document.obituaryForm.pageNumber.value == "" )
		{
        message =message+"\nPlease fill in the page number.";
        valid = false;
		}

/*check to make sure that the number of relatives section is actually filled out...
	if ( document.obituaryForm.theValue.value == "" )
		{
        alert ( "Please fill in all of the Relatives information." );
        valid = false;
		}
*/

	if (message !="") alert(message);
    return valid;
}


