function swapImage(imageName, replacement){

	document.images[imageName].src = replacement;

}

function popWindow(windowName) {

	//alert('in popW'  + windowName)

	aWindow=window.open("", windowName,'left=50,top=50,toolbar=0,status=1,menubar=1,scrollbars=1,resizable=1,width=550,height=540')

}

function checkFrames(newSidebar, newTopbar) {

	if (parent.frames[0].location.href.indexOf(newSidebar) == -1) {

		parent.frames[0].location.href = newSidebar;

	}

	

	if (parent.frames[1].location.href.indexOf(newTopbar) == -1) {

		parent.frames[1].location.href = newTopbar;

	}

	return;



}

	

//Get the href of the 'main' section. Chop it from /legacy/ to it's end. Get the title of the 'main' page.

//Return an href to the jhtml page that will add the link and title to the organizer

function getContentURL()

{

	var thisHref = location.href;

	var url = thisHref.substring(thisHref.indexOf("/legacy/")) // don't include the leading '/'

	var title = escape(document.title) //url encode

    return "/legacy/organizer/popupLink.jhtml?linkpage=" + url + "&title=" + title

}    



//This displays the above content url

function showContentURL() {

	alert("Content info: " + getContentURL());

}



function displaySaveLink() {

	document.write("<br><a href=\"" + getContentURL() + "\"target=\"popup\" onClick=\'window.open(\"\", \"popup\", \"location=no,width=450,height=175\")\'><img src=\"/legacy/images/button_bookmark.gif\" border=\"0\" align=middle></a>");

}	





function displayLegalFooter()

{

	document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td colspan="2" height="5" valign="top"><font size="1" color="#333333" face="arial, helvetica"><hr size=1 noshade></font></td></tr><tr bgcolor="#FFFFFF"><td width="178"><a href="http://www.fidelity.com/" target="_top"><img src="../images/Hlog_web.gif" width="178" height="33" alt="" border="0"></a></td><td valign="bottom" align="right"><font face="Arial, Helvetica, sans-serif" size="1">&copy;2001-2002 FMR Corp.  All rights reserved.</font><br><a href="#" onClick=\'window.open("../home/legal.html", "popupLegal", "location=no,width=440,height=400,scrollbars,resizable=no")\'><font face="Arial" size="1">Important Legal Information.</font></div></td></tr></table>'); 

  

	return;

}



function displayPlanningLinkFooter()

{

	document.writeln('<br><center><a href="#" onClick=\'window.open("../home/ep_legal.html", "popupLegal", "location=no,width=440,height=175,resizable=no")\'><font face="Arial" size="1">Important Estate Planning Information</font></a></center>');

	return;

}



function displayPlanningTextFooter()

{

	document.write('<br><font face="Arial" size="2">Important Estate Planning Information</font><br><font face="Arial" size="1">The information contained herein is general in nature and should not be considered legal or tax advice. This information is provided for general educational purposes only and you should bear in mind that laws of a particular state and your particular situation may affect the information contained herein. You should consult with your attorney or tax advisor regarding your specific legal or tax situation.</font>');

	return;

}





	

function addCommas( textBox )

{

//	alert('in commas');

//	var tmp1 = 'document.estateForm.' + textBox + (isIE() ? '[1]' :'')

	var tmp1 = 'document.estateForm.' + textBox

	var tmp2 = eval(tmp1)

	var tmp3 = tmp2.value

	var tmp4 = stripcomma(tmp3);

	var tmp5 = stripLeadingZeros(tmp4);

	var s = ''

	var len = tmp5.length

//	alert(len);

	var end = len - 1

	

	

	for ( var i = 0; i < len; i++ )

	{

		c = tmp5.charAt( end - i )

		s = c + ((i > 2 && i % 3 == 0) ? ',' : '') + s

	}

	tmp2.value = s

}



function isNumeric(data2) 
{  

	var numStr="0123456789-,";

	var thisChar;

  	var counter = 0;

	for (var i=0; i < data2.length; i++)  
	{
          thisChar = data2.substring(i, i+1);

          if (numStr.indexOf(thisChar) != -1) counter ++;  

	}

	if(counter == data2.length) rflag = true; else rflag = false;

	return rflag;

}



function stripLeadingZeros(data)

{

//	alert('in strip leading zeros');



	var thisChar;

	var nd;

	nd = '';

  	var counter = 0;

	var flag = 0;

	if(data.length==1 && data=='0') return data;

	for (var i=0; i < data.length; i++)  

	{

          thisChar = data.substring(i, i+1);

          if (thisChar == '0' && flag == 0){continue;}else {flag=1;nd = nd + thisChar;}

	}

	return nd;



}





function isIE()

{

if( -1 != navigator.userAgent.indexOf("MSIE"))

{

    return true;

}  

else  //if( -1 != navigator.userAgent.indexOf("Mozilla"))

{

    return false;

}

}





function stripcomma(data)

{

//	var numStr="0123456789-";

	var thisChar;

	var nd;

	nd = '';

  	var counter = 0;

	for (var i=0; i < data.length; i++)  

	{

          thisChar = data.substring(i, i+1);

          if (thisChar != ',') nd = nd + thisChar;  

	}

	return nd;

}



function validateCalculator(text1)
{
	globalvar = 'false';

	if(text1 == "rateOfEstateGrowth" )
	{

		var rate = document.estateForm.rateOfEstateGrowth.value

		if (!isNumeric(rate) || rate > 99 || rate < -99 || rate=="")
     		{
		     globalvar="true";

	             alert("Please enter a growth rate value between -99 and 99.");

		     document.estateForm.rateOfEstateGrowth.value = '0';

           	     document.estateForm.rateOfEstateGrowth.focus();

                     return false;

     		}
		else 
		{

			globalvar = 'false';
			return true;
		}
   	}
	else if(text1 == "yearsUntilDeath" && globalvar == 'false')
        {
		var years = parseInt(document.estateForm.yearsUntilDeath.value);
		var currentYear = parseInt(new Date().getFullYear());
		var fullYear = currentYear + years;
		var maxYear = 2009;

		if (fullYear > maxYear || fullYear < currentYear || fullYear =="")
     		{
			globalvar="true";

			alert("Please choose a valid whole number representing a year from now to 2009 for years until death.");

			document.estateForm.yearsUntilDeath.focus();

			return false;
		}
		else 
		{
			globalvar = 'false';

			return true;
		}
		
	}
	else if(text1 == "yearsUntil2ndDeath" && globalvar == 'false')
      	{
		var years2 = parseInt(document.estateForm.yearsUntil2ndDeath.value);
		var currentYear = parseInt(new Date().getFullYear());
		var fullYear = currentYear + years2;
		var maxYear = 2009;

		if (fullYear > maxYear || fullYear < currentYear || fullYear =="")
     		{
  			globalvar="true";

			alert("Please choose a valid whole number representing a year from now to 2009.");

			document.estateForm.yearsUntil2ndDeath.focus();

			return false;
		}
		else 
		{
			globalvar = 'false';
			return true;
		}
	}
	else if(text1 != 'rateOfEstateGrowth' && text1 != 'yearsUntilDeath' && text1 != 'yearsUntil2ndDeath' && globalvar == 'false')
	{
		var tmp1;

		var tmp2;

		var tmp3 = text1

		tmp3 = (eval('document.estateForm.' + text1 + '.value'));

		if (!isNumeric(tmp3)  || tmp3 > 999999999 || tmp3 < 0 || tmp3 == "")

     		{

			globalvar="true";

 		    alert("Please enter a valid and whole number between 0 and 999,999,999 for all fields.");

			eval('document.estateForm.' + text1 + '.value = 0');

			eval('document.estateForm.' + text1 + '.focus()');

			

			return false;

		}

		else 

		{

			globalvar = 'false';

			addCommas(text1);

			return true;

		}		

	}

}





//Added below AS - 05-19-2000:



//The following used by date validation functions

var lastValidYr = new Date().getYear()	//'current year' - last year to allow for entered dates

if (lastValidYr < 1000) { 	//certain browsers give year as # of years from 1900, so check for it

	lastValidYr = lastValidYr + 1900 //get the true year since 1900

}



var firstValidYr = 1890 //first year to allow



function isValidDate(inField) {

  inField.errorMessage = "Please enter a valid date (mm/dd/yyyy).";

	inField.strIn = inField.value;

	inField.strIn = stripCharsInBag(inField.strIn, " ");



	if ( inField.strIn.length < 6 || inField.strIn.length > 10 ) {

		return false;

  	}



	var pos1 = inField.strIn.indexOf('/');

	if (pos1 < 1 || pos1 > 2)

		return false;



	var pos2 = inField.strIn.indexOf('/', pos1 + 1);

	if (pos2 < 3 || pos2 > 5)

		return false;



	var month = parseInt(inField.strIn.substring(0, pos1), 10);

	var day   = parseInt(inField.strIn.substring(pos1 + 1, pos2), 10);

	var year  = parseInt(inField.strIn.substring(pos2 + 1, inField.strIn.length), 10);



	if (isNaN(year) || !isValidYear(year)) {

		inField.errorMessage = "Please enter a valid year between " + firstValidYr +" and " + lastValidYr +" (mm/dd/yyyy).";

		return false;

	}



	if (isNaN(month) || !isValidMonth(month))	{

		inField.errorMessage = "Please enter a valid month between 01 and 12 (mm/dd/yyyy).";

		return false;

	}

  

	if (isNaN(day) || !isValidDay(day, month, year)) {

		inField.errorMessage = "Please enter a valid day (mm/dd/yyyy).";

		return false;

	}



  return true;

}



function isValidMonth(month) {

	if (month < 1 || month > 12)

		return false;

	return true;

}



function isValidDay(day,month,year) {

  var aryDaysOfMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);



	if (isValidMonth(month))

	{

		if (aryDaysOfMonth[month-1] >= day)

		{

			return true;

		}

		else

		{

			if (!isLeapYear(year))

				return false;

			else

			{

				if (month == 2 && day == 29)

					return true;

				else

					return false;

			}

		}

	}

	return true;

}



function isValidYear(year) {

	if (year >= firstValidYr && year <= lastValidYr)

		return true;

	return false;

}



function isLeapYear(year) {

  return (((year % 4) == 0) && ((year % 400) != 0));

}



function stripCharsInBag(s, bag) {

  var returnString = "";



  if (s == null) return returnString;



  for (var i = 0; i < s.length; i++) {

    var c = s.charAt(i);

    if (bag.indexOf(c) == -1) returnString += c;

  }



  return returnString;

}





//Redirect to another page on and close the window: this accomplishes submit and close

function doRedirectAndClose(target) {

	if (opener != null) { //did another window open me?

		opener.document.location.href = target //have that other window load with target

		window.close()

	}

}



//Close the window: this accomplishes submit and close

function doClose() {

	if (opener != null) { //did another window open me?

		window.close()

	}

}



function glossaryBox(page) {

	window.open(page, "popupGlossary", "location=no,width=320,height=150,resizable=no");

	return;

}



function glossaryBoxBig(page) {

	window.open(page, "popupGlossary", "location=no,width=320,height=220,resizable=no");

	return;

}



function glossaryBoxFootnote(page) {

	window.open(page, "popupGlossary", "location=no,width=420,height=250,resizable=no");

	return;

}





