	// Popup window function
function openWindow(url, name, size, scroll) {
    popupWin=window.open(url, name, '"toolbar=no,' + size +',left=235,top=235,status=no,' + scroll +',resize=no,menubar=no"');
}
  
function openDir(form) {
	window.location=(form.dir.options[form.dir.selectedIndex].value);
}


function open_popup1(URL){
	aWindow = window.open(URL,"tpa","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,width=420,height=550,top=100,left=300");
}

function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
}

//validate prearrange_form.tpl
function validate_prearrange() {
	//alert('Validating Form!');
	if (document.prearrange.principal_lastName.value=='') {
		alert('Please enter your last name.');
		document.prearrange.principal_lastName.focus();
		return false;
	}
	if (document.prearrange.principal_firstName.value=='') {
		alert('Please enter your first name.');
		document.prearrange.principal_firstName.focus();
		return false;
	}
	if (document.prearrange.principal_race.value=='') {
		alert('Please enter your race.');
		document.prearrange.principal_race.focus();
		return false;
	}
	if (document.prearrange.principal_address1.value=='') {
		alert('Please enter your address.');
		document.prearrange.principal_address1.focus();
		return false;
	}
	if (document.prearrange.principal_city.value=='') {
		alert('Please enter the city of your address.');
		document.prearrange.principal_city.focus();
		return false;
	}
	if (document.prearrange.principal_parishcounty.value=='') {
		alert('Please enter the parish or county of your address.');
		document.prearrange.principal_parishcounty.focus();
		return false;
	}
	if (document.prearrange.principal_state.value=='') {
		alert('Please enter the state of your address.');
		document.prearrange.principal_state.focus();
		return false;
	}
	if (document.prearrange.principal_zip.value=='') {
		alert('Please enter the zip code of your address.');
		document.prearrange.principal_zip.focus();
		return false;
	}
	if (document.prearrange.principal_phone.value=='') {
		alert('Please enter your phone number.');
		document.prearrange.principal_phone.focus();
		return false;
	}
	if (document.prearrange.principal_dob_Month.value=='' || document.prearrange.principal_dob_Day.value=='' || document.prearrange.principal_dob_Year.value=='') {
		alert('Please enter a valid date for your birthday.');
		document.prearrange.principal_dob_Month	.focus();
		return false;
	}
	/*if (document.prearrange.spouse_name.value!='') {
		//validate spouse fields
		if (document.prearrange.spouse_name.value!='') {
			alert('Please enter a valid date for your birthday.');
			document.prearrange.principal_dob_Month	.focus();
			return false;
		}
	}*/
	return true;
}

// 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 toggleLayer(whichLayer)
{
  if (document.getElementById)
  {
    // this is the way the standards work
    var style2 = document.getElementById(whichLayer).style;
    style2.display = style2.display? "":"block";
  }
  else if (document.all)
  {
    // this is the way old msie versions work
    var style2 = document.all[whichLayer].style;
    style2.display = style2.display? "":"block";
  }
  else if (document.layers)
  {
    // this is the way nn4 works
    var style2 = document.layers[whichLayer].style;
    style2.display = style2.display? "":"block";
  }
}

function show(div) {
	div = findDOM(div);
	div.style.visibility = 'visible';
	div.style.position = 'static';
	div.style.display = 'inline';
}

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;
	}
}
