
// returns HTML Tag ID's proper DOM of user's browser
function findDOM(objectID) {
	if ( document.getElementById ) {
		return (document.getElementById(objectID)); 
	} else if ( document.all ) {
		return (document.all[objectID]); 
	} else {
		browserVersion = parseInt(navigator.appVersion);
		if ((navigator.appName.indexOf('Netscape') != -1 ) && (browserVersion == 4)) {
			return (document.layers[objectID]); 
		}
	}
}


var x, tagName, idNum, Div;
var child = 1;
var sibling = 1;
var singer = 1;
var pallbearer = 1;
var person = 1;

function show(div) {
	div = findDOM(div);
	div.style.visibility = 'visible';
	div.style.position = 'static';
}

function hide(div) {
	div = findDOM(div);
	div.style.visibility = 'hidden';
	div.style.position = 'absolute';
}

function addObject(tagName, idNum) {
	var removeButton, addButton;
	var Div = tagName + idNum.toString();
	show(Div);
	if ( idNum == 5 ) {
		addButton = 'add' + tagName;
		hide(addButton);
	} else if ( idNum >= 2 ) {
		removeButton = 'remove' + tagName;
		show(removeButton);
	}
}

function addPB(tagName, idNum) {
	var removeButton, addButton;
	var Div = tagName + idNum.toString();
	show(Div);
	if ( idNum == 8 ) {
		addButton = 'add' + tagName;
		hide(addButton);
	} else if ( idNum >= 2 ) {
		removeButton = 'remove' + tagName;
		show(removeButton);
	}
}

function add(x) {
	if ( x == 'child' && child < 5 ) {
		child = child + 1;
		addObject(x,child);
	} else if ( x == 'sibling' && sibling < 5 ) {
		sibling = sibling + 1;
		addObject(x,sibling);
	} else if ( x == 'singer' && singer < 5 ) {
		singer = singer + 1;
		addObject(x,singer);
	} else if ( x == 'pallbearer' && pallbearer < 8 ) {
		pallbearer = pallbearer + 1;
		addPB(x,pallbearer);
	} else if ( x == 'person' && person < 5 ) {
		person = person + 1;
		addObject(x,person);
	}
}

function removeObject(tagName,idNum) {
	var Div = tagName + idNum.toString();
	hide(Div);
	if ( idNum == 2 ) {
		var removeButton = 'remove' + tagName;
		hide(removeButton);
	} else if ( idNum > 2 ) {
		var addButton = 'add' + tagName;
		show(addButton);
	}
}

function removePB(tagName,idNum) {
	var Div = tagName + idNum.toString();
	hide(Div);
	if ( idNum == 2 ) {
		var removeButton = 'remove' + tagName;
		hide(removeButton);
	} else if ( idNum > 2 ) {
		var addButton = 'add' + tagName;
		show(addButton);
	}
}
	
function remove(x) {
	if ( x == 'child' && child > 1 ) {
		removeObject(x,child);
		child = child - 1;
	} else if ( x == 'sibling' && sibling > 1 ) {
		removeObject(x,sibling);
		sibling = sibling - 1;
	} else if ( x == 'singer' && singer > 1 ) {
		removeObject(x,singer);
		singer = singer - 1;
	} else if ( x == 'pallbearer' && pallbearer > 1 ) {
		removePB(x,pallbearer);
		pallbearer = pallbearer - 1;
	} else if ( x == 'person' && person > 1 ) {
		removeObject(x,person);
		person = person - 1;
	}
}
	
function casketInput(x) {
	var domMetal = findDOM('metalDiv');
	var domWood = findDOM('woodDiv');
	if ( x == "wood" ) {
		show('woodDiv');
		hide('metalDiv');
	} else {
		hide('woodDiv');
		show('metalDiv');
	}
}

function check() {
	var form = document.form1;
	
	if ( !form.fName.value ) {
		alert("Please enter a first name in personal information");
		form.fName.focus();
		return false;
	} else if ( !form.lName.value ) {
		alert("Please enter a last name in personal information");
		form.lName.focus();
		return false;
	} else if ( !form.personalAddress1.value ) {
		alert("Please enter an address in personal information" );
		form.personalAddress1.focus();
		return false;
	} else if ( !form.personalCity.value ) {
		alert( "Please enter a city in personal information" );
		form.personalCity.focus();
		return false;
	} else if ( !form.personalState.value ) {
		alert( "Please enter a state in personal information" );
		form.personalState.focus();
		return false;
	} else if ( !form.personalZip.value ) {
		alert( "Please enter a zip code in personal information" );
		form.personalZip.focus();
		return false;
	} else if ( !form.personalPhone.value ) {
		alert( "Please enter a phone number" );
		form.personalPhone.focus();
		return false;
	} else if ( !form.personalEmail.value ) {
		alert("Please enter an email address");
		form.personalEmail.focus();
		return false;
	} else return true;
}