var timerID = 0;
var index = 0;
var indexMax = 0;
var images = new Array();

function initImageSwap()
{
	images[0] = new Image;
	images[0].src = "../images/formlilbuf.jpg";
	images[1] = new Image;
	images[1].src = "../images/formlilfont.jpg";
	indexMax = 1;
}

function startImageSwapTimer()
{
	timerID = setTimeout("changePicture()", 5000);
}

function changePicture()
{
	if (index > indexMax)
		index = 0;
		
	document.form1.random.src = images[index++].src;
	clearTimeout(timerID);
	startImageSwapTimer();
}


function ValidateText(strText,strExp)
{		
	var strCandidate = new String(strText);
	var reExpression = new RegExp();
	reExpression.compile(strExp);
	return (strCandidate.search(reExpression) == -1) ? false : true;
}
	
function ValidateField(varField,strExp,strPrompt)
{
	var blnReturn = true;
	if ( !ValidateText(varField.value,strExp) )
	{
		blnReturn = false;						
		if ( strPrompt != "" )
		{
			alert(strPrompt);
		}
		varField.focus();		
	}
	return blnReturn;
}

function ValidateField2(varField,strExp,strPrompt)
{
	var blnReturn = true;
	if (varField.value == strExp)
	{
		blnReturn = false;						
		if ( strPrompt != "" )
		{
			alert(strPrompt);
		}
		varField.focus();		
	}
	return blnReturn;
}

function submitFormPG1(thisForm)
{
	if (!validateFormPG1(thisForm))
	{
		return false;
	}
	var isGift = false;
	for (var i=0; i<thisForm.Gift.length; i++)
	{
		if (thisForm.Gift[i].checked)
		{
			if (thisForm.Gift[i].value == "yes")
			{
				isGift = true;
			}
		}
	} 
	if (!isGift)
	{
		thisForm.OwnerName.value = thisForm.YourName.value;
		thisForm.OwnerCity.value = thisForm.YourCity.value;
		thisForm.OwnerState.value = thisForm.YourState.value;
		thisForm._browser_out.value = "frm_memorial_sel.htm";
	}
	else
	{
		thisForm._browser_out.value = "frm_memorial_gift.htm";
	}
	return true;
}

function validateFormPG1(thisForm)
{
   var returnVar = true;
   // validate all of these fields... if they are ALL valid, return true //
   returnVar = validateYourInformation(thisForm);
   if (returnVar)
   {
	returnVar = validateRadioButton(thisForm.Gift, 'Please select whether or not this is a gift.');
   }
   return returnVar;
}


function submitFormFamWindow(thisForm)
{
	if (!validateFormFamWindow(thisForm))
	{
		return false;
	}
	return true;
}

function validateFormFamWindow(thisForm)
{
	
	if (!validateRadioButton(thisForm.FamWallPhotos, 'Please select how you are sending us your guardian\'s photograph.'))
	{
		return false;
	}
	var PhotoType ="";

	for (var i=0; i<thisForm.FamWallPhotos.length; i++)
	{
		if (thisForm.FamWallPhotos[i].checked)
		{
		  PhotoType = thisForm.FamWallPhotos[i].value;
		}
	} 
   if (thisForm.FamWallPet != null)
   {
	if (!checkInvalidChars(thisForm.FamWallPet))
	{
		return false;
	}
	if (PhotoType != 'None' && !ValidateField(thisForm.FamWallPet,'.+','The Guardian field is required.'))
	{
		return false;
	}
		
   }

	if (PhotoType == 'None' && thisForm.FamWallPet.value.length != 0)
	{
		return confirm("You've specified the name of your guardian, but specified no photo.  We can't add the guardian without one.  Are you sure you don't want to send us a photo of your guardian?");
	}
   return true;
}


function submitFormFamPG1(thisForm)
{
	if (!validateFormFamPG1(thisForm))
	{
		return false;
	}
	calcFamWall(thisForm);
	var option = "";
   	for (var j=0; j<thisForm.FamWall.length; j++)
	{
		if (thisForm.FamWall[j].checked)
		{
			option=thisForm.FamWall[j].value;
		}
	}
	if (option == 'Create')
	{
		thisForm._browser_out.value = "frm_famwall_cottage.htm";
	}
	return true;
}

function submitFormFamPG2(thisForm)
{
	if (thisForm.TotalAmount.value == "0")
	{
		thisForm._send_email_2.value = "bmpfamwallreceipt2.mail";
		thisForm._browser_out.value = "frm_bmp_famwall_success2.htm";
	}
	else
	{
		thisForm._send_email_2.value = "bmpfamwallreceipt.mail";
		thisForm._browser_out.value = "frm_bmp_famwall_success.htm";
	}
	
	return true;
}

function validateFormFamPG1(thisForm)
{
   var returnVar = true;
   // validate all of these fields... if they are ALL valid, return true //
   returnVar = validateYourInformation(thisForm);
   if (returnVar)
   {
	var selMade = false;
	var option;
   
   	for (var j=0; j<thisForm.FamWall.length; j++)
	{
		if (thisForm.FamWall[j].checked)
		{
			option=thisForm.FamWall[j].value;
			selMade = true;
		}
	}
   	if (!selMade)
   	{
		alert('Please select whether or not this is an existing Family Wall or a new Family Wall');
		returnVar = false;
	}
	if (returnVar)
	{
		if (!checkInvalidChars(thisForm.FamWallName))
		{
			return false;
		}
		returnVar = ValidateField(thisForm.FamWallName,'.+','The Family Name field is required.');
	}
   }
   if (returnVar)
   {
	if (!checkInvalidChars(thisForm.PetMemorials))
	{
		return false;
	}
	returnVar = ValidateField(thisForm.PetMemorials,'.+','You need to tell us the names of the memorials to move.');
   }
   if (returnVar)
   {
	if (!checkInvalidChars(thisForm.addAmount))
	{
		return false;
	}
	returnVar = validateMoneyField(thisForm.addAmount);
   }
   return returnVar;
}


function validateFormGiftPG2(thisForm)
{

   var returnVar = true;
   // validate all of these fields... if they are ALL valid, return true //
   returnVar = validateRadioButton(thisForm.MemType, 'Please select a Gift Option.');
   if (returnVar)
   {
	if (!checkInvalidChars(thisForm.addAmount))
	{
		return false;
	}
	returnVar = validateMoneyField(thisForm.addAmount);
   }
   if (returnVar)
   {
	returnVar = validateGiftRecipient(thisForm);
   }
   if (returnVar && thisForm.PetName != null)
   {
	if (!checkInvalidChars(thisForm.PetName))
	{
		return false;
	}
	returnVar = ValidateField(thisForm.PetName,'.+','The Pet\'s Name field is required.');
   }

   if (returnVar)
   {
	returnVar = validateContact(thisForm);
   }
   return returnVar;
}

function submitFormGiftPG2(thisForm)
{
	if (!validateFormGiftPG2(thisForm))
	{
		return false;
	}

	setMemTypeDesc(thisForm);
	return true;
}

function submitFormSelPG2(thisForm)
{
	if (!validateFormSelPG2(thisForm))
	{
		return false;
	}

	setMemTypeDesc(thisForm);
	var MemType ="";

	for (var i=0; i<thisForm.MemType.length; i++)
	{
		if (thisForm.MemType[i].checked)
		{
		  MemType = thisForm.MemType[i].value;
		}
	} 
	if (MemType == "plq")
	{
		thisForm._browser_out.value = "frm_memorial_plq.htm";
		thisForm.PetMsgLen.value = "0";
	}
	else if (MemType == "plqinfo")
	{
		thisForm._browser_out.value = "frm_memorial_plqinfo.htm";
		thisForm.PetMsgLen.value = "80";
	}
	else if (MemType == "plqpp12")
	{
		thisForm._browser_out.value = "frm_memorial_plqpp.htm";
		thisForm.PetMsgLen.value = "500";
	}
	else if (MemType == "plqpp34")
	{
		thisForm._browser_out.value = "frm_memorial_plqpp.htm";
		thisForm.PetMsgLen.value = "300";
	}
	else if (MemType == "plqpp5")
	{
		thisForm._browser_out.value = "frm_memorial_plqpp.htm";
		thisForm.PetMsgLen.value = "150";
	}
	return true;
}

function validateFormSelPG2(thisForm)
{
   var returnVar = true;
   // validate all of these fields... if they are ALL valid, return true //
   var option;
   var selMade = false;
   for (var i=0; i<thisForm.MemType.length; i++)
   {
	if (thisForm.MemType[i].checked)
	{
	  selMade = true;;
	}
   } 
   if (!selMade)
   {
	alert('Please select a Memorial Option');
	returnVar = false;
   }

   if (returnVar)
   {
	selMade = false;
   
   	for (var j=0; j<thisForm.FamWall.length; j++)
	{
		if (thisForm.FamWall[j].checked)
		{
			option=thisForm.FamWall[j].value;
			selMade = true;
		}
	}
   	if (!selMade)
   	{
		alert('Please select a Family Wall Option');
		returnVar = false;
	}
	else
	{
		if (option != "No")
		{
			if (!checkInvalidChars(thisForm.FamWallName))
			{
				return false;
			}
			 returnVar = ValidateField(thisForm.FamWallName,'.+','The Family Name field is required.');
			
		}
		else
		{
			thisForm.FamWallName.value = "";
		}
	}
   } 

   if (returnVar)
   {
	if (!checkInvalidChars(thisForm.addAmount))
	{
		return false;
	}
	returnVar = validateMoneyField(thisForm.addAmount);
   }
   if (returnVar)
   {
	returnVar = validateRadioButton(thisForm.PayMethod, 'Please select your payment method.');
   }
   return returnVar;
}


function submitFormPlqPG3(thisForm)
{
	if (!validateFormPlqPG3(thisForm))
	{
		return false;
	}
	doDates(thisForm);
	if (thisForm.FamWall.value == 'Yes')
	{
		thisForm._browser_out.value = "frm_famwall_cottage.htm";
	}
	return true;
}

function validateFormPlqPG3(thisForm)
{
   var returnVar = true;
   // validate all of these fields... if they are ALL valid, return true //

	if (thisForm.PetName != null)
	{
		if (!checkInvalidChars(thisForm.PetName))
		{
			return false;
		}
		returnVar = ValidateField(thisForm.PetName,'.+','The Pet\'s Name field is required.');
	}
	
	if (returnVar)
	{
		returnVar = ValidateDates(thisForm);
	}

	if (returnVar)
   	{
		returnVar = validateRadioButton(thisForm.Photos, 'Please select how you are sending us your photograph(s).');
   	}
	return returnVar;
}

function ValidateDates(thisForm)
{
	var returnVar = true;

   	if (returnVar)
   	{
		returnVar = validateRadioButton(thisForm.dob, 'Select what you want displayed on the plaque regarding their birth date, adoption date or age.');
		if (returnVar)
		{
			var dob = getRadioValue(thisForm.dob);
			if (dob == 'Date of Birth')
			{
				if (returnVar)
				{
					returnVar = ValidateDate(thisForm.PetDOBMonth, thisForm.PetDOBDay, thisForm.PetDOBYear);
				}
			}
			else if (dob == 'Date of Adoption')
			{
				if (returnVar)
				{
					returnVar = ValidateDate(thisForm.PetDOAMonth, thisForm.PetDOADay, thisForm.PetDOAYear);
				}
			}
			else if (dob == 'Age')
			{
				if (returnVar)
				{
					returnVar = validateYearsField(thisForm.PetAgeYears);
				}
				if (returnVar)
				{
					returnVar = validateMonthsField(thisForm.PetAgeMonths);
				}
			}
		}
	}

   	if (returnVar)
   	{
		returnVar = validateRadioButton(thisForm.dod, 'Select what you want displayed on the plaque regarding their date of passing.');
		if (returnVar)
		{
			var dod = getRadioValue(thisForm.dod);
			if (dod == 'Date of Passing')
			{
				if (returnVar)
				{
					returnVar = ValidateDate(thisForm.PetDODMonth, thisForm.PetDODDay, thisForm.PetDODYear);
				}
			}
		}
	}

   	return returnVar;
}

function submitFormPlqInfoPG3(thisForm)
{
	if (!validateFormPlqInfoPG3(thisForm))
	{
		return false;
	}
	doDates(thisForm);
	if (thisForm.FamWall.value == 'Yes')
	{
		thisForm._browser_out.value = "frm_famwall_cottage.htm";
	}
	return true;
}

function validateFormPlqInfoPG3(thisForm)
{
	if (!validateFormPlqPG3(thisForm))
	{
		return false;
	}

//	thisForm.PetMessage.value = textCleanup(thisForm.PetMessage.value);
	if (!checkInvalidChars(thisForm.PetMessage))
	{
		return false;
	}
	if (!validateMessageLength(thisForm.PetMessage, thisForm.PetMsgLen.value))
	{
		return false;
	}
	if (!validateRadioButton(thisForm.Photos, 'Please select how you are sending us your photograph(s).'))
	{
		return false;
	}
	return true;
}

function validateYourInformation(thisForm)
{
   var returnVar = true;
	if (thisForm.YourName != null)
	{
		if (!checkInvalidChars(thisForm.YourName))
		{
			return false;
		}
		 returnVar = ValidateField(thisForm.YourName,'.+','The Name field is required.');
	}

	if (returnVar && thisForm.YourAddress != null)
	{
		if (!checkInvalidChars(thisForm.YourAddress))
		{
			return false;
		}
		returnVar = (ValidateField(thisForm.YourAddress,'.+','Please enter your address.'));
	}
		
	if (returnVar && (thisForm.YourCity != null))
	{
		if (!checkInvalidChars(thisForm.YourCity))
		{
			return false;
		}
		returnVar = (ValidateField2(thisForm.YourCity,'City','Please enter your city.')
			&& ValidateField(thisForm.YourCity,'.+','Please enter your city.'));
	}
	
	if (returnVar && (thisForm.YourState != null))
	{
		if (!checkInvalidChars(thisForm.YourState))
		{
			return false;
		}
		returnVar = (ValidateField2(thisForm.YourState,'State/Province','Please enter your state/province.')
			&& ValidateField(thisForm.YourState,'.+','Please enter your state/province.'));
	}

	if (returnVar && (thisForm.YourZip != null))
	{
		if (!checkInvalidChars(thisForm.YourZip))
		{
			return false;
		}
		returnVar = (ValidateField2(thisForm.YourZip,'Zip/Postal Code','Please enter your zip code.')
			&& ValidateField(thisForm.YourZip,'.+','Please enter your zip code.'));
	}

	if (returnVar && (thisForm.YourEmail != null))
	{
		if (!checkInvalidChars(thisForm.YourEmail))
		{
			return false;
		}
		returnVar = (ValidateField(thisForm.YourEmail,'^((\\&quot;[^\\&quot;]+\\&quot;|[\\w-_]+)(\\.(\\&quot;[^\\&quot;]+\\&quot;|[\\w-_]+))*@([\\w-]+(\\.[\\w-]+)*\\.[\\w-]{2,4})|(\\[\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\])){0,1}$','The Email field is invalid.')
			&& ValidateField(thisForm.YourEmail,'.+','The Email field is required.'));
	}
	return returnVar;	
}

function validateGiftRecipient(thisForm)
{
   var returnVar = true;
	if (thisForm.GiftName != null)
	{
		if (!checkInvalidChars(thisForm.GiftName))
		{
			return false;
		}
		 returnVar = ValidateField(thisForm.GiftName,'.+','The Name field is required.');
			 
	}

	if (returnVar && thisForm.GiftAddress != null)
	{
		if (!checkInvalidChars(thisForm.GiftAddress))
		{
			return false;
		}
		returnVar = (ValidateField(thisForm.GiftAddress,'.+','Please enter the address.'));
	}
		
	if (returnVar && (thisForm.GiftCity != null))
	{
		if (!checkInvalidChars(thisForm.GiftCity))
		{
			return false;
		}
		returnVar = (ValidateField2(thisForm.GiftCity,'City','Please enter the city.')
			&& ValidateField(thisForm.GiftCity,'.+','Please enter the city.'));
	}
	
	if (returnVar && (thisForm.GiftState != null))
	{
		if (!checkInvalidChars(thisForm.GiftState))
		{
			return false;
		}
		returnVar = (ValidateField2(thisForm.GiftState,'State/Province','Please enter your state/province.')
			&& ValidateField(thisForm.GiftState,'.+','Please enter your state/province.'));
	}

	if (returnVar && (thisForm.GiftZip != null))
	{
		if (!checkInvalidChars(thisForm.GiftZip))
		{
			return false;
		}
		returnVar = (ValidateField2(thisForm.GiftZip,'Zip/Postal Code','Please enter the zip code.')
			&& ValidateField(thisForm.GiftZip,'.+','Please enter this zip code.'));
	}

	if (returnVar && (thisForm.GiftEmail != null))
	{
		if (!checkInvalidChars(thisForm.GiftEmail))
		{
			return false;
		}
		returnVar = ValidateField(thisForm.GiftEmail,'^((\\&quot;[^\\&quot;]+\\&quot;|[\\w-_]+)(\\.(\\&quot;[^\\&quot;]+\\&quot;|[\\w-_]+))*@([\\w-]+(\\.[\\w-]+)*\\.[\\w-]{2,4})|(\\[\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\])){0,1}$','The Email field is invalid.');
	}
	return returnVar;	
}

function validateContact(thisForm)
{
   var returnVar = true;

   if (thisForm.sameasgift != null && thisForm.sameasgift.checked)
   {
	thisForm.ContactName.value = thisForm.GiftName.value;
	thisForm.ContactAddress.value = thisForm.GiftAddress.value;
	thisForm.ContactCity.value = thisForm.GiftCity.value;
	thisForm.ContactState.value = thisForm.GiftState.value;
	thisForm.ContactZip.value = thisForm.GiftZip.value;
	thisForm.ContactEmail.value = thisForm.GiftEmail.value;
	return true;
   }

	if (thisForm.ContactName != null)
	{
		if (!checkInvalidChars(thisForm.ContactName))
		{
			return false;
		}
		 returnVar = ValidateField(thisForm.ContactName,'.+','The Name field is required.');
			 
	}

	if (returnVar && thisForm.ContactAddress != null)
	{
		if (!checkInvalidChars(thisForm.ContactAddress))
		{
			return false;
		}
		returnVar = (ValidateField(thisForm.ContactAddress,'.+','Please enter the address.'));
	}
		
	if (returnVar && (thisForm.ContactCity != null))
	{
		if (!checkInvalidChars(thisForm.ContactCity))
		{
			return false;
		}
		returnVar = (ValidateField2(thisForm.ContactCity,'City','Please enter the city.')
			&& ValidateField(thisForm.ContactCity,'.+','Please enter the city.'));
	}
	
	if (returnVar && (thisForm.ContactState != null))
	{
		if (!checkInvalidChars(thisForm.ContactState))
		{
			return false;
		}
		returnVar = (ValidateField2(thisForm.ContactState,'State/Province','Please enter your state/province.')
			&& ValidateField(thisForm.ContactState,'.+','Please enter your state/province.'));
	}

	if (returnVar && (thisForm.ContactZip != null))
	{
		if (!checkInvalidChars(thisForm.ContactZip))
		{
			return false;
		}
		returnVar = (ValidateField2(thisForm.ContactZip,'Zip/Postal Code','Please enter the zip code.')
			&& ValidateField(thisForm.ContactZip,'.+','Please enter this zip code.'));
	}

	if (returnVar && (thisForm.ContactEmail != null))
	{
		if (!checkInvalidChars(thisForm.ContactEmail))
		{
			return false;
		}
		returnVar = ValidateField(thisForm.ContactEmail,'^((\\&quot;[^\\&quot;]+\\&quot;|[\\w-_]+)(\\.(\\&quot;[^\\&quot;]+\\&quot;|[\\w-_]+))*@([\\w-]+(\\.[\\w-]+)*\\.[\\w-]{2,4})|(\\[\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\])){0,1}$','The Email field is invalid.');
	}
	return returnVar;	
}

function validateRadioButton(field, msg)
{
	if (field != null)
	{
	   var selMade = false;
		for (var i=0; i<field.length; i++)
		{
			if (field[i].checked)
			{
			  selMade = true;
			}
		} 
		if (!selMade)
		{
			alert(msg);
			return false;
		}
	}
	return true;
}

function validateMoneyField(field)
{
   var returnVar = true;
	if (field != null)
	{
		if (field.value.length == 0)
		{
			field.value = "0";
		}
		for (var i=0; i<field.value.length; i++)
		{
			if (field.value.charAt(i) != '0' &&
			field.value.charAt(i) != '1' &&
			field.value.charAt(i) != '2' &&
			field.value.charAt(i) != '3' &&
			field.value.charAt(i) != '4' &&
			field.value.charAt(i) != '5' &&
			field.value.charAt(i) != '6' &&
			field.value.charAt(i) != '7' &&
			field.value.charAt(i) != '8' &&
			field.value.charAt(i) != '9')
			{
				alert('The amount field is invalid.  Enter whole dollar amounts only.  Example:  10 (correct)  10.00 (invalid)');
				field.focus();		
				returnVar = false;
			}
		}
	}
	return returnVar;
}

function validateYearField(field)
{
   var returnVar = true;
	if (field != null)
	{
		if (!ValidateField2(field,'Year','Please enter a valid year or leave it blank'))
		{
			return false;
		}
		if (field.value.length ==0)
		{
			return true;
		}
		if (field.value.length !=2 && field.value.length !=4)
		{
			alert('Enter a valid Year or leave it blank.  Example:  69 or 1969');
			field.focus();		
			return false;
		}
		for (var i=0; i<field.value.length; i++)
		{
			if (field.value.charAt(i) != '0' &&
			field.value.charAt(i) != '1' &&
			field.value.charAt(i) != '2' &&
			field.value.charAt(i) != '3' &&
			field.value.charAt(i) != '4' &&
			field.value.charAt(i) != '5' &&
			field.value.charAt(i) != '6' &&
			field.value.charAt(i) != '7' &&
			field.value.charAt(i) != '8' &&
			field.value.charAt(i) != '9')
			{
				alert('The year field is invalid.  Enter only numbers or leave it blank.');
				field.focus();		
				returnVar = false;
			}
		}
	}
	return returnVar;
}

function validateYearsField(field)
{
   var returnVar = true;
	if (field != null)
	{
		if (!ValidateField2(field,'Years','Please enter a valid number of years or leave it blank'))
		{
			return false;
		}
		if (field.value.length ==0)
		{
			field.value = '0';
			return true;
		}
		for (var i=0; i<field.value.length; i++)
		{
			if (field.value.charAt(i) != '0' &&
			field.value.charAt(i) != '1' &&
			field.value.charAt(i) != '2' &&
			field.value.charAt(i) != '3' &&
			field.value.charAt(i) != '4' &&
			field.value.charAt(i) != '5' &&
			field.value.charAt(i) != '6' &&
			field.value.charAt(i) != '7' &&
			field.value.charAt(i) != '8' &&
			field.value.charAt(i) != '9')
			{
				alert('Enter only numbers or leave it blank.');
				field.focus();		
				returnVar = false;
			}
		}
	}
	return returnVar;
}

function validateMonthsField(field)
{
   var returnVar = true;
	if (field != null)
	{
		if (!ValidateField2(field,'Months','Please enter a valid number of months or leave it blank'))
		{
			return false;
		}
		if (field.value.length ==0)
		{
			field.value = '0';
			return true;
		}
		for (var i=0; i<field.value.length; i++)
		{
			if (field.value.charAt(i) != '0' &&
			field.value.charAt(i) != '1' &&
			field.value.charAt(i) != '2' &&
			field.value.charAt(i) != '3' &&
			field.value.charAt(i) != '4' &&
			field.value.charAt(i) != '5' &&
			field.value.charAt(i) != '6' &&
			field.value.charAt(i) != '7' &&
			field.value.charAt(i) != '8' &&
			field.value.charAt(i) != '9')
			{
				alert('Enter only numbers or leave it blank.');
				field.focus();		
				returnVar = false;
			}
		}
	}
	return returnVar;
}

function setMemTypeDesc(thisForm)
{
	var plqAmt = 100;
	var famAmt = 0;
	var MemType ="";
	var FamWall ="";

	for (var i=0; i<thisForm.MemType.length; i++)
	{
		if (thisForm.MemType[i].checked)
		{
		  MemType = thisForm.MemType[i].value;
		}
	} 
	for (var i=0; i<thisForm.FamWall.length; i++)
	{
		if (thisForm.FamWall[i].checked)
		{
		  FamWall = thisForm.FamWall[i].value;
		}
	} 

	if (MemType == "plq")
	{
		thisForm.MemTypeDesc.value = "Plaque";
		plqAmt = 25;
	}
	else if (MemType == "plqinfo")
	{
		thisForm.MemTypeDesc.value = "Plaque plus Information Window";
		plqAmt = 50;
	}
	else if (MemType == "plqgift")
	{
		thisForm.MemTypeDesc.value = "Plaque plus Personal Page";
		plqAmt = 100;
	}
	else if (MemType == "plqpp12")
	{
		thisForm.MemTypeDesc.value = "Plaque plus Personal Page with 1-2 pictures and 500 character message or less";
		plqAmt = 100;
	}
	else if (MemType == "plqpp34")
	{
		thisForm.MemTypeDesc.value = "Plaque plus Personal Page with 3-4 pictures and 300 character message or less";
		plqAmt = 100;
	}
	else if (MemType == "plqpp5")
	{
		thisForm.MemTypeDesc.value = "Plaque plus Personal Page with 5 pictures and 150 character message or less";
		plqAmt = 100;
	}
	else 
	{
		thisForm.MemTypeDesc.value = "Plaque plus Personal Page";
		plqAmt = 100;
	}
	if (FamWall == "Yes")
	{
		famAmt = 50;
	}
	if (thisForm.addAmount.value.length)
	{
		thisForm.TotalAmount.value = famAmt+plqAmt+parseInt(thisForm.addAmount.value);
	}
	else
	{
		thisForm.TotalAmount.value = famAmt+plqAmt;
	}
}

function calcFamWall(thisForm)
{
	var famAmt = 0;
	var FamWall ="";

	for (var i=0; i<thisForm.FamWall.length; i++)
	{
		if (thisForm.FamWall[i].checked)
		{
		  FamWall = thisForm.FamWall[i].value;
		}
	} 

	if (FamWall == "Create")
	{
		famAmt = 50;
	}
	if (thisForm.addAmount.value.length)
	{
		thisForm.TotalAmount.value = famAmt+parseInt(thisForm.addAmount.value);
	}
	else
	{
		thisForm.TotalAmount.value = famAmt;
	}
}

function getComboValue(field)
{
	for (var i = 0; i < field.length; i++)
	{
		if (field.options[i].selected)
		{
			return field.options[i].value;
		}
	}
	return "";
}

function getRadioValue(field)
{
	if (field != null)
	{
		for (var i=0; i<field.length; i++)
		{
			if (field[i].checked)
			{
			  	return field[i].value;
			}
		} 
	}
	return "";
}

function getDate(Month, Day, Year)
{
	var Date = "";
	if (Month.length > 0)
	{
		Date = Month;
		if (Day.length > 0)
		{
			Date = Date + "-" + Day;
		}
	}
	if (Year.length > 0)
	{
		if (Date.length > 0)	
		{
			Date = Date + "-";
		}
		Date = Date + Year;
	}
	return Date;
}

function doDates(thisForm)
{
	var dob = getRadioValue(thisForm.dob);
	var dod = getRadioValue(thisForm.dod);
	if (dob == 'Date of Birth')
	{
		thisForm.PetDOB.value = 'Born ' + setDOB(thisForm);
	}
	else if (dob == 'Date of Adoption')
	{
		thisForm.PetDOB.value = 'Adopted ' + setDOA(thisForm);
	}
	else if (dob == 'Age')
	{
		var years = parseInt(thisForm.PetAgeYears.value);
		var months = parseInt(thisForm.PetAgeMonths.value);

		thisForm.PetDOB.value = '';
		if (years > 0)
			thisForm.PetDOB.value = years + " years";
		if (months > 0)
		{
			if (thisForm.PetDOB.value.length > 0)
				thisForm.PetDOB.value += ", ";
			thisForm.PetDOB.value += months + " months";
		}
		
	}
	else
		thisForm.PetDOB.value = dob;

	if (dod == 'Date of Passing')
	{
		thisForm.PetDOD.value = setDOD(thisForm);
	}
	else
		thisForm.PetDOD.value = dod;
}

function setDOB(thisForm)
{
	var Month = getComboValue(thisForm.PetDOBMonth);	
	var Day = getComboValue(thisForm.PetDOBDay);	
	var Year = thisForm.PetDOBYear.value;
	return getDate(Month, Day, Year);
}

function setDOA(thisForm)
{
	var Month = getComboValue(thisForm.PetDOAMonth);	
	var Day = getComboValue(thisForm.PetDOADay);	
	var Year = thisForm.PetDOAYear.value;
	return getDate(Month, Day, Year);
}

function setDOD(thisForm)
{
	var Month = getComboValue(thisForm.PetDODMonth);	
	var Day = getComboValue(thisForm.PetDODDay);	
	var Year = thisForm.PetDODYear.value;
	return getDate(Month, Day, Year);
}

function ValidateDate(month, day, year)
{
   var returnVar = true;
	if (returnVar && (month != null))
	{
		returnVar = ValidateField2(month,'-1','Please select a month or "Unknown".');
	}
	if (returnVar && (day != null))
	{
		returnVar = (ValidateField2(day,'-1','Please select a day or "Unknown".'));
	}
	if (returnVar && (year != null))
	{
		returnVar = validateYearField(year);
	}
	if (returnVar)
	{
		var m = getComboValue(month);
		var d = getComboValue(day);
		var y = year.value;

		if (d.length > 0 && m.length == 0)
		{
			alert('Because the day is set to something other than "Unknown", the month must be set to something other than "Unknown"');
			month.focus();
			return false;
		}
		if (m.length > 0 && y.length==0)
		{
			alert('Because the month is set to something other than "Unknown", the year must be provided.');
			year.focus();
			return false;
		}
		return true;
	}
	return returnVar;
}

function LeftTrim(String)
{
 String += "";         // Force argument to string.
 if(String.length == 0)
  return(String);
 var Count = 0;
 for(Count = 0;Count < String.length;Count++)
 {
  if(!(String.charAt(Count) == " ") &&
	!(String.charAt(Count) == "\t")  &&
	!(String.charAt(Count) == "\r") &&  
	!(String.charAt(Count) == "\n"))   
   {
   return(String.substring(Count,String.length));
   }
 }
 return("");
}

function RightTrim(String)
{
 String += "";        // Force argument to string.
 if(String.length == 0)
  return(String);
 var Count = 0;
 for(Count = String.length -1;Count >= 0;Count--)
 {
  if(!(String.charAt(Count) == " ") &&
	!(String.charAt(Count) == "\t")  &&
	!(String.charAt(Count) == "\r") &&  
	!(String.charAt(Count) == "\n"))   
   {
   return(String.substring(0,Count + 1));
   }
 }
 return("");
}

function AllTrim(String)
{
 String += ""        // Force argument to string.
 return(RightTrim(LeftTrim(String)))
}


function validateMessageLength(msgfld, msglen)
{
	var len = parseInt(msglen)*1.2;
	var len2 = 0;
	var tmp = AllTrim(msgfld.value);
	var inws = false;


	if (tmp.length == 0)
	{
		return confirm("Are you sure you don't want to submit a message at this time?  NOTE:  You can always send it later if you don't know what you want to say now.");
	}

	for (var i = 0; i < tmp.length; i++)
	{
		var ch = tmp.charAt(i);

		if (ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t')
		{
			if (!inws)
			{
				len2++;
			}
			inws = true;
		}
		else if (inws)
		{
			inws = false;
		}
	}
	len2++;
	if (len2 > len)
	{
		alert("The message has exceeded "+msglen+" words.  Your message is currently "+len2+" words");
		msgfld.focus();
		return false;
	}
	return true;
}

var helpwin = null;
function SampleWindow(strURL, width, height)
{
	if (!helpwin || helpwin.closed)
	{
		helpwin = window.open(strURL, 'samplepopup'+width+height,'width='+width+',height='+height+',dependent=yes,location=no,menubars=no,toolbars=no,resizable=yes,scrollbars=no');
	}
	else
	{
		helpwin.close();
		helpwin = window.open(strURL, 'samplepopup'+width+height,'width='+width+',height='+height+',dependent=yes,location=no,menubars=no,toolbars=no,resizable=yes,scrollbars=no');
	}
	helpwin.focus();
}

function SampleWallpaperWindow(strURL, width, height)
{
	if (!helpwin || helpwin.closed)
	{
		helpwin = window.open('', '_newSample');
	}
	else
	{
		helpwin.close();
		helpwin = window.open('', '_newSample');
	}
	var	content;

	content = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">';
	content += '<meta name="GENERATOR" content="Microsoft FrontPage 4.0">';
	content += '<meta name="ProgId" content="FrontPage.Editor.Document">';
	content += '<base href="http://wall.cairnrescue.com/">';
	content += '<link rel="stylesheet" type="text/css" href="css/wall.css">';
	content += '<title>Col. Potter Buf Memorial Park: Sample Family Wall</title></head><body class="form">';
	content += '<img border="0" src="';
	content += strURL;
	content += '" width="700" height="700"></body></html>';
	helpwin.document.write(content);
	helpwin.document.close();
	helpwin.focus();
}

var wordalert = true; // true = if there are forbidden words alert them and don't post the form, false = replace forbidden words with 3stars and post the form anyway
var words = "\"|<|>";
var replacewords = "'|*|*";
var temp = new Array();
var temp = words.split("|");
var wa = new Array();
var repl = replacewords.split("|");
for(i=0;i<temp.length;i++) wa[i] = new Array(temp[i],0);

function checkInvalidChars(obj)
{

 stop = false
 txt = obj.value.toLowerCase();
 for(i=0;i<wa.length;i++)
 {
   if(txt.indexOf(wa[i][0]) != -1)
   {
     htxt = txt;
     pos = htxt.lastIndexOf(wa[i][0]);
     while(pos != -1)
     {
       htxt = htxt.substr(0,pos); 
       pos = htxt.lastIndexOf(wa[i][0]);
       wa[i][1]= wa[i][1] + 1;
     }
     stop = true
   }
 }
 str="The form cannot be submitted:\n______________________________\n\n";
 for(i=0;i<wa.length;i++) 
 {
  if(wa[i][1] > 0) str+= "This illegal character:  " + wa[i][0] + "\n  was found " + wa[i][1] + " time(s)\n"
  wa[i][1] = 0;
 }
 str+= "______________________________\n\n";
 str+= "NOTE:  instead of using double quotes (\"), use a single quote (').";
 if(stop) 
 {
  obj.focus();
  alert(str);
  return false;
 }
return true;
}

