
/*
 ver January 20 2005
 global variable declarations / definitions
*/
// use number of col in data + 2 for sort bar, to set up table cells
// re-arange loading of js files in all templates for this to work
if (typeof rate != "undefined")	cols = rate[0].length + 2;
if (typeof catagory == "undefined")	var catagory = "rates";

prodName = "";
mort_table = -1;
screen_width = 0;
screen_height = 0;
var rateCookie;
found_cookie = false;
cookie_active = false;
var justLoaded = 1;
var last_sort_col = 0;
var notFirstTime = 0;
var ratealert_obj = "";
var customize_obj = "";
// used for average stats
total = 0;
statusLayer = "";

//global functions shared among all rates
function layerSetup(rate)  {
	if (NS4 || NS_DHTML)	{
		screen_width = innerWidth;
		screen_height = innerHeight;
	}	else if (IE4 || IE_DHTML)	{
		screen_width = document.body.clientWidth;
		screen_height = document.body.clientHeight;
		document.onmousemove = trackIt;
	}
	getCookie();
	rateDisplay(0);
};

function rateDisplay(sort_col)  {
	msg = "";
	var rateHTML = "";
	cfb = "";

	last_sort_col = sort_col;
	if (justLoaded)
		prodName = document.rate.productType.value;

	mort_table = ratetableHeadings[0].toString().search(/Mortgage/i)
	var mtg_disx = ratetableHeadings[0].toString().search(/Mortgage Discharge Fees/i)

	if (nsDHTML)  {
		rateDescHTML = eval(document.rateDescLayer.document);
		rateDescLyr = eval(document.rateDescLayer);
		outerRateLyr = document.relativeLayer;
		rateHTML = eval(document.relativeLayer.document.rateTableLayer.document);
		rateLyr = eval(document.relativeLayer.document.rateTableLayer);
		cfb = eval(document.customizeFloatButton);
	}
	else if (ieDHTML && !DHTML)  {
		rateDescHTML = eval(doc + '["rateDescLayer"]' + htm)
		rateDescLyr = eval( doc + '["rateDescLayer"]' + sty);
		rateHTML = eval(doc + '["rateTableLayer"]' + htm)
		cfb = eval('document.all.customizeFloatButton.style');
	}
	else if (DHTML)	{
		rateDescHTML = document.getElementById("rateDescLayer")
		rateHTML = document.getElementById("rateTableLayer")
		cfb = document.getElementById("customizeFloatButton");
		mBody = document.getElementById("mainBody");
		statusLayer = document.getElementById("statusLayer");
	}

	if (found_cookie && document.rate.reportType.value == "sort")	{
		rateArray = setCustomRateArray(rate);
	} else	{
		rateArray = rate;

	}

	if (rateArray.length == rate.length)	{
		found_cookie = false;
		cookie_active = false;
	} else if (! cookie_active)	{
		clearStats();
		cookie_active = true;
	}

//alert("found_cookie="+found_cookie +"\ncookie_active="+cookie_active +"\nlength of rateArray="+rateArray.length);

	if (mort_table != -1)	sortColumn(rateArray, sort_col, "L");
	else	sortColumn(rateArray, sort_col, "H");

/* rate table description*/
	if (typeof rateDescription != "undefined" && typeof rateDescHTML != "undefined")	{
		msg = "<span class=tableDescription>" + rateDescription[0] + "</span>";
		if (nsDHTML)  {
			rateDescHTML.write(msg);
			rateDescHTML.close();
		}
		else if (ieDHTML || DHTML)  {
			rateDescHTML.innerHTML = msg;
		}
	}
	msg = "";

	if (typeof document.rate != "undefined")	{
// if rateAlert selected add in form tag
		if (document.rate.reportType.value == "ratealert")	msg += '<form name="ratealert">\n';
// if rateSelect selected add in form tag
		else if (document.rate.reportType.value == "customize")	msg += '<form name="customize">\n';
	}
// rate table
/* Mirah - Changes this Section */
	msg += '<table width="' + tableWidth + '" border=1 cellspacing=0 cellpadding=2 bordercolor=#A6DDBD>\n';	
/* Mirah - Changes this Section */	
// column width
  if (ieDHTML || DHTML)  {
    for (i = 0; i < cols; i++)  {
      if (i == sort_col)  {
        msg += '<col width="1%"> ';
      }
      if (i == 0)  {
       msg += '<col width="35%"> ';
      }
      else  {
        msg += '<col width="'+ Math.round(63 / (ratecolHeadings.length-1)) +'%"> ';
      }
      if (i == sort_col)  {
        msg += '<col width="1%"> ';
      }
    }
    msg += '\n';
  }
//table headings
// loop while they exist
/* Mirah - Changes this Section */
  for (i=0, ii=1; i < ratetableHeadings.length; i++,ii++)  {
    msg += '<tr><td height=30 colspan="' + cols + '" class="tableHead'+ ii +'">' + ratetableHeadings[i] + '<br><br></td></tr>';
  }
/* Mirah - Changes this Section */
//column headings

  for (i = 0; i < ratecolHeadings.length; i++)  {
    if (i == 0)  {
      alignType = "left";
    }
    else if (i == 1)  {
      alignType = "middle";
      value = rate[i][ii];
    }
    else  {
      alignType = "middle";
    }
    classType = "dataHead";
    colourType = "#000000";
    if (i == sort_col)  {
      msg += ' <td width="1%" class=dataHeadSort><font size=1>&nbsp;</font></td>';
    }		
// if RateAlert | Customize selected remove sort
		if (typeof document.rate != "undefined" && document.rate.reportType.value != "sort")	msg += ' <td align=' + alignType + ' class=' + classType + '>' + ratecolHeadings[i] + '</td>';
		else	msg += ' <td align=' + alignType + ' class=' + classType + '> <a href="javascript:void(null);" onClick="return rateDisplay(' + i + ');" title="Click to sort by ' + ratecolHeadings[i] + '"><span class=' + classType + '>' + ratecolHeadings[i] + '</span></a></td>';
		if (i == sort_col)	msg += ' <td width="1%" class=dataHeadSort><font size=1>&nbsp;</font></td>';
	}
	msg +='</tr>\n';

//data
	for (i = 0; i < rateArray.length; i++)  {
		var found_product = false;
		for (ii = 0; ii < rateArray[i].length; ii++)    {
			s1 = rateArray[i][0];
			s1 = s1.replace(/<a.*><font .*><u.*>(.*)<\/u><\/font><\/a>/i, "$1");

			if (found_cookie)	{
				for (x = 0; x < rateCookie.length; x++)  {
					if (rateCookie[x][0] == s1 && rateCookie[x][1] == rateArray[i][2]) found_product = true;
				}
				if (! found_product) break;
			}

			if (ii == 0)      {
				msg +='<tr>';
				alignType = "left";

				if (document.rate.reportType.value == "customize")	{
					value = '<INPUT ';
					if (found_cookie && found_product)	value += "checked ";
					value += 'type="checkbox" name="customizeProduct" value="'+ s1 + ':' + rateArray[i][2] +'" class="formObj">'+ rateArray[i][0];
				}
				else	value = rateArray[i][ii];
			}
// fix here for car loan second col - should be right aligned
			else if (ii == 1 && mtg_disx == -1)  {
				alignType = "middle";
				value = rateArray[i][ii];
			}
			else if (ii == 1 && mtg_disx > -1)  {
				alignType = "right";
				if (rateArray[i][ii] == "999.00")        {
					value = "---";
					mort_table = 1;
				}
				else	value = rateArray[i][ii];
			}
			else  {
				alignType = "right";
/*
 if no value for this column, replace with a dash
 this is replaced for display purpases only because it affects sorting
*/
				if (rateArray[i][ii] == "99.00" || rateArray[i][ii] == "999.00")        {
					value = "---";
					mort_table = 1;
				}
				else if (catagory != "mmuts" && catagory != "dmuts" && (rateArray[i][ii] == "0.00" || rateArray[i][ii] == " 0.00"))        {
					value = "---";
					mort_table = -1;
				}
				else {
// if RateAlert selected add in <input> checkboxes - puts checkbox in front of rate
					if (typeof document.rate != "undefined" && document.rate.reportType.value == "ratealert")	{
// product name, amount, rate, date
						if ( rateArray[i][ii].toString().search(/\d+\./) != -1 )	value = '<INPUT type="checkbox" name="ratealertProduct" value="'+ rateArray[i][0] + '|' + rateArray[i][amount] + '|' + rateArray[i][ii] +  '|' + rateArray[i][1] +'">'+ rateArray[i][ii];
						else	{
							amount = ii;
							value = rateArray[i][ii];
						}
					}
					else	value = rateArray[i][ii];
				}
			}
			if (ii == sort_col)	msg += ' <td width="1%" class=dataSort>&nbsp;</td>';
			if (i % 2)	classType = "dataAlt";
			else	classType = "data";

// display negative numbers in red
// display price in red if change negative
// amke this an admin option
			if ( ii == 2 )	{
				if ( catagory == "dmuts" && ( rateArray[i][ii+1] < 0 || rateArray[i][ii+2] < 0 ) )
					msg += ' <td bgcolor=#FFFFFF align=' + alignType + ' class=' + classType + '><font color='+ dataNegColour +'>' + value + '</font></td>';
				else if ( catagory == "dmuts" && ( rateArray[i][ii+1] > 0 || rateArray[i][ii+2] > 0  ))
					msg += ' <td bgcolor=#FFFFFF align=' + alignType + ' class=' + classType + '><font color='+ dataPosColour +'>' + value + '</font></td>';
				else
					msg += ' <td bgcolor=#FFFFFF align=' + alignType + ' class=' + classType + '>' + value + '</td>';
			}	else
				msg += ' <td bgcolor=#FFFFFF align=' + alignType + ' class=' + classType + '>' + value + '</td>';

			if (ii == sort_col)	msg += ' <td width="1%" class=dataSort><font size=1>&nbsp;</font></td>';
		}
		if (found_product)	msg +='</tr>\n';
	}
// mar 30 2007			
	if (typeof statsHigh != "undefined" && typeof statsAvg != "undefined" && typeof statsLow != "undefined")	
	{
		if (DHTML && typeof pageOptions != "undefined" && pageOptions.search(/stats/) != -1 &&
			(typeof document.rate != "undefined" && document.rate.reportType.value == "sort") )	{
			displayStatusPrompt_stats();
			statsDisplay();
			removeStatusPrompt();
		}
	}

	msg += '</table>\n';
// if RateAlert | Customize selected add in form tag
	if (typeof document.rate != "undefined"	&& (document.rate.reportType.value == "ratealert" || document.rate.reportType.value == "customize"))	{
		msg += '</form>\n';
	}
	if (nsDHTML)  {
		var widthAmount = parseInt(800 - tableWidth);
		if (widthAmount > 0)	outerRateLyr.left = parseInt( widthAmount / 2 );
		rateHTML.write(msg);
		rateHTML.close();
	}
	else if (ieDHTML || DHTML)  {
		rateHTML.innerHTML = msg;

/*
		ratealert_obj = eval('document.ratealert');
*/
		customize_obj = eval('document.customize');
	}

// precheck already checked items
	if (typeof document.rate != "undefined"	&& document.rate.reportType.value == "customize") auto_check("custom");

	return false;
};

	function displayStatusPrompt_stats()	{
		removeChildren(statusLayer);
		setupFloatButton(statusLayer, "statusLayer");
		statusLayerText = document.createTextNode( "Sorting Statistics..." );
		statusLayer.appendChild(statusLayerText);
	}
	function removeStatusPrompt()	{
		removeChildren(statusLayer);
		setupFloatButton(statusLayer, "statusLayer");

	}

/*
copies rates to a new array if a custom list exists
*/
	function setCustomRateArray(a)	{
		tmp = new Array();
		for (x = 0, cCount = 0; x < rateCookie.length; x++)  {
			for (i = 0; i < a.length; i++)  {
				var found_product = false;
				s1 = a[i][0];
				s1 = s1.replace(/<a.*><font .*><u.*>(.*)<\/u><\/font><\/a>/i, "$1");
				if (rateCookie[x][0] == s1 && rateCookie[x][1] == a[i][2])	{
					found_product = true;
					break;
				}
			}
			if (found_product)	{
				tmp[cCount] = a[i];
				cCount++;
			}
			else break;
		}
/* if nothing found could be a bad cookie so copy full source array 'a'	*/
		if (tmp.length == 0)
			tmp = a;

		return(tmp);
	}


// sep 16 2004 function sortColumn(arry,col)  {
function sortColumn(arry,col,ord)  {
	if (justLoaded)  {
		justLoaded = 0;
		return;
	}
	BubbleSort(arry, col, ord);
};

// main sort function
// arry = array name, col = column to sort, ord = oder H(igh), A(verage), L(ow)
function BubbleSort(arry,col,ord)  {

/*
	removeChildren(statusLayer);
	setupFloatButton(statusLayer, "statusLayer");
	statusLayerText = document.createTextNode( "Sorting..." );
	statusLayer.appendChild(statusLayerText);
*/
	tmp = new Array();
	var s1, s2;
	for (pass = 0; pass < arry.length; pass++)  {
		madeAchange = 0;

		for (a = 0; a < arry.length-1; a++)  {
			s1 = arry[a][col];
			s2 = arry[a+1][col];

//alert("beginnig sort...\ncol="+col+"\ns1="+s1+"\ns2="+s2);

//if a numerical array column
// jul 31 2006			if (col != 0 && !isNaN(arry[a][col]) )  {
			if (col != 0 && 
			( !isNaN(arry[a][col]) || s1 == "n/a" || s2 == "n/a") )  
			{	
				if (ord == "H")	{
					s1 = s1.replace(/(99)/, "-$1");
					s2 = s2.replace(/(99)/, "-$1");
// jul 31 2006
					s1 = (s1 == "n/a") ? -99.99 : s1;
					s2 = (s2 == "n/a") ? -99.99 : s2;
				}
				else if (ord == "L")	{
					s1 = s1.replace(/(-.*? |0.00)/, "99999");
					s2 = s2.replace(/(-.*? |0.00)/, "99999");
// jul 31 2006
					s1 = (s1 == "n/a") ? 99999 : s1;
					s2 = (s2 == "n/a") ? 99999 : s2;					
				}
// pushes mmuts "0.00" to bottom of list
				if (catagory == "mmuts")	{
					if ( arry[a][col] == "0.00" || arry[a][col] == " 0.00" || (parseFloat(arry[a][col]) < parseFloat(arry[(a+1)][col]) && arry[(a+1)][col] != "0.00" && arry[(a+1)][col] != " 0.00"))  {
						for (i= 0 ; i < arry[a].length; i++)  {
							tmp = arry[a][i];
							arry[a][i] = arry[(a+1)][i];
							arry[(a+1)][i] = tmp;
						}
						madeAchange = 1;
					}
				}	else if ( (ord == "H" && parseFloat(s1) < parseFloat(s2)) ||
							(ord == "L" && parseFloat(s1) > parseFloat(s2)) )  {

					for (i = 0 ; i < arry[a].length; i++)  {
						tmp = arry[a][i];
						arry[a][i] = arry[(a+1)][i];
						arry[(a+1)][i] = tmp;
					}
					madeAchange = 1;
				}
			}
//if an alphanumeric array column
			else  {
// extract name from <a><font><u> here </u></font></a> in tag (if there is background info on this product)
// if there is no background info on this product the copied value is compared
// institution name
				if (col == 0)  {
					s1 = s1.replace(/<a.*><font .*><u.*>(.*)<\/u><\/font><\/a>/i, "$1");
					s2 = s2.replace(/<a.*><font .*><u.*>(.*)<\/u><\/font><\/a>/i, "$1");
					if (s1 > s2)  {
						for (i = 0 ; i < arry[a].length; i++)  {
							tmp = arry[a][i];
							arry[a][i] = arry[(a+1)][i];
							arry[(a+1)][i] = tmp;
						}
						madeAchange = 1;
					}
				}
// date
				else if (col == 1)  {
					if (s1 < s2)  {
						for (i = 0 ; i < arry[a].length; i++)  {
							tmp = arry[a][i];
							arry[a][i] = arry[(a+1)][i];
							arry[(a+1)][i] = tmp;
						}
						madeAchange = 1;
					}
				}
			}
		}
		if (ord == "A")	
		{
			s1 = arry[pass][col];
			s1 = s1.replace(/((99.00|0.00))/, "-$1");
// jul 31 2006			
			s1 = s1.replace(/(n\/a)/, "-00\.0");			
			s1 = s1.replace(/ /g, "");
			if (s1.length > 1 && s1.search(/-/) == -1)  {
				total = total + parseFloat(s1);
			}
		}

// if no changes made after first pass - arry is in order, leave loop
		if (! madeAchange && ord != "A")
			break;
	}


/*
	removeChildren(statusLayer);
	setupFloatButton(statusLayer, "statusLayer");
*/
};

/* oct 4 2004*/
function statsDisplay()	{
// split apart pageptions
	var pageOptionStuff = pageOptions.split("!");
// split apart stat options "stats:StartCol:EndCol
	var statsStuff = pageOptionStuff[0].split(":");

//alert("statsDisplay: last_sort_col="+last_sort_col);

//	msg += '<tr> <td colspan='+ (ratecolHeadings.length+2) +' class=data>&nbsp;</td> </tr>';
	msg += '<tr> <td align=center valign=center colspan='+ (ratecolHeadings.length+2) +' class=dataHead>Summary of Todays Rates</td> </tr>';
	msg += '<tr>';
	for (cCount = 0; cCount < ratecolHeadings.length; cCount++)  {
		alignType = "left";
		if (cCount >= statsStuff[1])  {
			alignType = "middle";
			value = ratecolHeadings[cCount];
		}
		else	value = "&nbsp;";
		classType = "data";
		if (cCount == last_sort_col)
			msg += ' <td align=' + alignType + ' class=' + classType + ' colspan=3>' + value + '</td>';
		else
			msg += ' <td align=' + alignType + ' class=' + classType + '>' + value + '</td>';
	}
	msg +='</tr>\n';
// if a mortgage table display 'Low' , 'Avg', 'High'
	if (mort_table != -1)	{
// low
/*
		removeChildren(statusLayer);
		setupFloatButton(statusLayer, "statusLayer");
		statusLayerText = document.createTextNode( "Sorting... Low" );
		statusLayer.appendChild(statusLayerText);
*/
		msg += '<tr>';
		for (cCount = 0; cCount < ratecolHeadings.length; cCount++)  {
			alignType = "right"; value = "&nbsp;";
			if (cCount == 0) alignType = "left";
			if (statsLow[cCount].length == 0)	{
				BubbleSort(rateArray, cCount, "L");
				value = rateArray[0][cCount];
				statsLow[cCount] = value;
			}
			else
				value = statsLow[cCount];
			if (cCount == last_sort_col)
				msg += ' <td align=' + alignType + ' class=statsdata colspan=3>' + value + '</td>';
			else
				msg += ' <td align=' + alignType + ' class=statsdata>' + value + '</td>';
		}
		msg +='</tr>\n';

	}
	else	{
// if NOT a mortgage table display 'High' , 'Avg', 'Low'
// high
/*
		removeChildren(statusLayer);
		setupFloatButton(statusLayer, "statusLayer");
		statusLayerText = document.createTextNode( "Sorting... High" );
		statusLayer.appendChild(statusLayerText);
*/
		msg += '<tr>';
		for (cCount = 0; cCount < ratecolHeadings.length; cCount++)  {
			alignType = "right"; value = "&nbsp;";
			if (cCount == 0) alignType = "left";
// only sort if array is empty, empty array occurs after customize clicked
			if (statsHigh[cCount].length == 0)	{
				BubbleSort(rateArray, cCount, "H");
				value = rateArray[0][cCount];
				statsHigh[cCount] = value;
			}
			else
				value = statsHigh[cCount];
			if (cCount == last_sort_col)
				msg += ' <td align=' + alignType + ' class=statsdata colspan=3>' + value + '</td>';
			else
				msg += ' <td align=' + alignType + ' class=statsdata>' + value + '</td>';
		}
		msg +='</tr>\n';

	}


// avg
/*
	removeChildren(statusLayer);
	setupFloatButton(statusLayer, "statusLayer");
	statusLayerText = document.createTextNode( "Sorting... Averages" );
	statusLayer.appendChild(statusLayerText);
*/
	msg += '<tr>';
	for (cCount = 0; cCount < ratecolHeadings.length; cCount++)  {
		alignType = "right"; value = "&nbsp;";
		if (cCount == 0) alignType = "left";
// only sort if array is empty, empty array occurs after customize clicked

		if (statsAvg[cCount].length == 0)	{
			total = 0;
			BubbleSort(rateArray, cCount, "A");
			value = total / rateArray.length;
			if (typeof value.toFixed != "undefined")
				value = value.toFixed(2);
//alert("statsDisplay: avg : value="+value +"\ntotal="+total +"\nlength of rateArray="+rateArray.length);
			statsAvg[cCount] = value;
		}
		else
			value = statsAvg[cCount];
		if (cCount == last_sort_col)
			msg += ' <td align=' + alignType + ' class=statsdata colspan=3>' + value + '</td>';
		else
			msg += ' <td align=' + alignType + ' class=statsdata>' + value + '</td>';
	}
	msg +='</tr>\n';

// if a mortgage table display 'Low' , 'Avg', 'High'
	if (mort_table != -1)	{
// high
/*
		removeChildren(statusLayer);
		setupFloatButton(statusLayer, "statusLayer");
		statusLayerText = document.createTextNode( "Sorting... High" );
		statusLayer.appendChild(statusLayerText);
*/
		msg += '<tr>';
		for (cCount = 0; cCount < ratecolHeadings.length; cCount++)  {
			alignType = "right"; value = "&nbsp;";
			if (cCount == 0) alignType = "left";
// only sort if array is empty, empty array occurs after customize clicked
			if (statsHigh[cCount].length == 0)	{
				BubbleSort(rateArray, cCount, "H");
				value = rateArray[0][cCount];
				statsHigh[cCount] = value;
			}
			else
				value = statsHigh[cCount];
			if (cCount == last_sort_col)
				msg += ' <td align=' + alignType + ' class=statsdata colspan=3>' + value + '</td>';
			else
				msg += ' <td align=' + alignType + ' class=statsdata>' + value + '</td>';
		}
		msg +='</tr>\n';
	}
	else	{
// if NOT a mortgage table display 'High' , 'Avg', 'Low'
// low
/*
	removeChildren(statusLayer);
	setupFloatButton(statusLayer, "statusLayer");
	statusLayerText = document.createTextNode( "Sorting... Low" );
	statusLayer.appendChild(statusLayerText);
*/
		msg += '<tr>';
		for (cCount = 0; cCount < ratecolHeadings.length; cCount++)  {
			alignType = "right"; value = "&nbsp;";
			if (cCount == 0) alignType = "left";
			if (statsLow[cCount].length == 0)	{
				BubbleSort(rateArray, cCount, "L");
				value = rateArray[0][cCount];
				statsLow[cCount] = value;
			}
			else
				value = statsLow[cCount];
			if (cCount == last_sort_col)
				msg += ' <td align=' + alignType + ' class=statsdata colspan=3>' + value + '</td>';
			else
				msg += ' <td align=' + alignType + ' class=statsdata>' + value + '</td>';
		}
		msg +='</tr>\n';
	}
// sep 27 2004
//alert("statsDisplay: msg="+msg);
/*
	removeChildren(statusLayer);
	setupFloatButton(statusLayer, "statusLayer");
*/

}


	function clearStats()	{
		if (typeof statsHigh != "undefined" && typeof statsAvg != "undefined" && typeof statsLow != "undefined")	{
			for (cCount = 0; cCount < ratecolHeadings.length; cCount++)  {
				if (statsHigh[cCount].toString().search(/\d/) != -1) statsHigh[cCount] = "";
				if (statsAvg[cCount].toString().search(/\d/) != -1) statsAvg[cCount] = "";
				if (statsLow[cCount].toString().search(/\d/) != -1) statsLow[cCount] = "";
			}
		}
	}


	function displayPrint()  {
		s = location.pathname;
		s = s.replace(/(_ns|_ie|_sort)?.shtml/i, ".shtml");
		return(s);
	};

// for moneyman section - does nothing because in rates section on older browser table views,
// the email option is a pop-up. In the moneyman section, the email option is embeded in the page.

	function clearMailForm()  {
		return true;
	};
var mailFormWin;
function mailForm()  {
  var pageName = "<input type=\"hidden\" name=\"sendPageURL\" value=" + window.location.href + ">";
  mailFormWin = window.open('','','dependent=yes,toolbar=no,location=no,directories=no,options=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=520,height=300');
  mailFormWin.document.writeln("<html><head>");
  mailFormWin.document.writeln("<title>Do you want to share this page with someone else?</title>");
  mailFormWin.document.writeln("<style type=\"text/css\">");
  mailFormWin.document.writeln("  .mailForm  {");
  mailFormWin.document.writeln("  font-family:Arial,\"New Times Roman\"; color:#000000; font-style:normal; font-weight:normal; font-size:8pt;");
  mailFormWin.document.writeln("  }");
  mailFormWin.document.writeln("</style>");
  mailFormWin.document.writeln("<SCRIPT LANGUAGE=\"JavaScript\">");
  mailFormWin.document.writeln("function validate_fields()");
  mailFormWin.document.writeln("{");
  mailFormWin.document.writeln("  if (document.mailform[\"toAddress\"].value.length == 0)  {");
  mailFormWin.document.writeln("    alert(\"Please enter the recipient's email address\");");
  mailFormWin.document.writeln("    document.mailform[\"toAddress\"].focus();");
  mailFormWin.document.writeln("    return false;");
  mailFormWin.document.writeln("  }");
  mailFormWin.document.writeln("  else if (document.mailform[\"fromAddress\"].value.length == 0)  {");
  mailFormWin.document.writeln("    alert(\"Please enter your email address\");");
  mailFormWin.document.writeln("    document.mailform[\"fromAddress\"].focus();");
  mailFormWin.document.writeln("    return false;");
  mailFormWin.document.writeln("  }");
  mailFormWin.document.writeln("  return true;");
  mailFormWin.document.writeln("};");
  mailFormWin.document.writeln("</SCRIPT>");
  mailFormWin.document.writeln("</head><body scroll=auto>");
  mailFormWin.document.writeln("<FORM ACTION=\"http://www.fiscalagents.com/mailform.pl\" METHOD=\"POST\" NAME=\"mailform\" onSubmit=\"return validate_fields();\">");
  mailFormWin.document.writeln("<INPUT TYPE=\"hidden\" NAME=\"type\" VALUE=\"send\">");
  mailFormWin.document.writeln("<INPUT TYPE=\"hidden\" NAME=\"pageType\" VALUE=\"CSS\">");
  mailFormWin.document.writeln("<TABLE bgcolor=\"#FFFFFF\" border=\"0\" WIDTH=\"100%\" height=\"225\" cellpadding=\"0\" cellspacing=\"0\" class=\"mailForm\" style=\"border:2px buttonface outset\">");
  mailFormWin.document.writeln("<col width=\"49%\"> <col width=\"2%\"> <col width=\"49%\">");
  mailFormWin.document.writeln("<TR> <TD align=left nowrap> Send this page to</td>  <td>&nbsp;</td> <TD align=left><INPUT NAME=\"toAddress\" SIZE=\"30\" MAXLENGTH=\"50\"></td></tr>");
  mailFormWin.document.writeln("<TR> <TD align=left nowrap> Your email address</td> <td>&nbsp;</td> <TD align=left><INPUT NAME=\"fromAddress\" SIZE=\"30\" MAXLENGTH=\"50\"></td></tr>");
// message
  mailFormWin.document.writeln("<TR> <TD align=left colspan=3> Message</td> </tr>");
  mailFormWin.document.writeln("<TR> <TD align=left colspan=3> <textarea NAME=\"mailMessage\" cols=50 rows=3 wrap=hard></textarea></td></tr>");
  mailFormWin.document.writeln("<TR> <TD align=left> Sending Format</td> <td>&nbsp;</td> <TD align=center><INPUT type=\"radio\" name=\"format\" value=\"text\">Text &nbsp; <INPUT type=\"radio\" checked name=\"format\" value=\"html\">HTML</td></tr>");
  mailFormWin.document.writeln("<TR> <TD align=center colspan=3> <INPUT TYPE=\"Reset\" VALUE=\"Reset\"> <INPUT TYPE=\"Button\" VALUE=\"Cancel\" onClick=\"window.close();\"> <INPUT TYPE=\"Submit\" VALUE=\"Mail\"></td></tr>");
  mailFormWin.document.writeln("</TABLE>" + pageName + "</FORM>");
  mailFormWin.document.writeln("</body></html>");
};


function openerPopWin(url)  {
	if (popWin)	closePopWin();
	if (url.search(/mmuts/) != -1)
		popWin = window.open(url,'','dependent=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=670,height=700,screenX=10,screenY=10,Left=10,Top=10');
	else
		popWin = window.open(url,'','dependent=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=338,height=471,screenX=10,screenY=10,Left=10,Top=10');
	popWin.focus();
};
// if the 'Close this Window' link is clickied in the pop-up window
function closerPopWin()  {
	window.close();
};

// when new pop-up page is displayed or a page is unloaded, close pop-up window (if any open)
function closePopWin()  {
	if (nsDHTML)  {
		if (popWin.closed == "false")	popWin.close();
	}
	else if (ieDHTML)  {
		if (popWin)	popWin.close();
	}
	popWin = "";
};
// ****************************************************************
// displays selection box contents for mmuts - default - catagories
// ****************************************************************
function fp_select()  {
  fpCatArray = eval("catagory");
  fpSpoArray = eval("sponsor");
// add in Sponsors
  for (selectCount = 0; selectCount < fpSpoArray.length; selectCount++)    {
	if (fpSpoArray[selectCount][0].length > 0)	{
	    if (ieDHTML)      {
    	  addFund = document.createElement('OPTION');
	      addFund.text = fpSpoArray[selectCount][0];
    	  addFund.value = fpSpoArray[selectCount][0];
	      document.access_mmuts.select_mmuts_sponsor.options.add(addFund);
    	}
	    else if (nsDHTML || NS_DHTML)      {
    	  optionLength = document.access_mmuts.select_mmuts_sponsor.options.length;
	      document.access_mmuts.select_mmuts_sponsor.options[optionLength] = new Option( fpSpoArray[selectCount][0], fpSpoArray[selectCount][0], 0, 0);
    	}
    }
  }
// add in Catagories
  for (selectCount = 0; selectCount < fpCatArray.length; selectCount++)    {
	if (fpCatArray[selectCount][0].length > 0)	{
	    if (ieDHTML)      {
    	  addFund = document.createElement('OPTION');
	      addFund.text = fpCatArray[selectCount][0];
	      addFund.value = fpCatArray[selectCount][0];
	      document.access_mmuts.select_mmuts_catagory.options.add(addFund);
    	}
	    else if (nsDHTML || NS_DHTML)      {
	      	optionLength = document.access_mmuts.select_mmuts_catagory.options.length;
    	  	document.access_mmuts.select_mmuts_catagory.options[optionLength] = new Option( fpCatArray[selectCount][0], fpCatArray[selectCount][0], 0, 0);
    	}
    }
  }
  return true;
};


function dumb_val_fp_select()  {
  return true;
}
function val_fp_select()  {
  var itemsSelected = 0;
// product
// sponsor
  if (document.access_mmuts.fetchOn_sponsor.checked)  {
// check for a sponsor selection
    for (selectCount = 0; selectCount < document.access_mmuts.select_mmuts_sponsor.options.length; selectCount++)  {
      if (document.access_mmuts.select_mmuts_sponsor.options[selectCount].selected)  {
        itemsSelected++;
        break;
      }
    }
  }
// catagory
  else if (document.access_mmuts.fetchOn_catagory.checked)  {
// check for a catagory selection
    for (selectCount = 0; selectCount < document.access_mmuts.select_mmuts_catagory.options.length; selectCount++)  {
      if (document.access_mmuts.select_mmuts_catagory.options[selectCount].selected)  {
        itemsSelected++;
        break;
      }
    }
  }
  if (itemsSelected == 0)  {
    alert("You must choose a product to proceed.");
    return false;
  }

// time periods
  if ( (!document.access_mmuts["1m"].checked) && (!document.access_mmuts["6m"].checked) && (!document.access_mmuts["1yr"].checked) && (!document.access_mmuts["3yr"].checked) && (!document.access_mmuts["5yr"].checked) && (!document.access_mmuts["10yr"].checked) )  {
    alert("You must choose at least 1 Time Period to proceed.");
    return false;
  }

// expense ratio percentage
  if (document.access_mmuts.exp_ratio.selectedIndex > 0 && document.access_mmuts.exp_ratio_percent.value.length == 0)  {
    alert("You have choosen an Expense Ratio condition.\n\nYou must also enter an Expense Ratio Percentage");
    document.access_mmuts.exp_ratio_percent.focus();
    return false;
  }
  return true;
};

/*
rate Select Items
*/

function setupFloatButton(objL, objN)	{
	if (typeof document.rate != "undefined")	{
		if (objN == "cfb")	{
			if (document.rate.reportType.value == "customize")	{
				if (NS4)  {
/*
					if (typeof cfb != "undefined")	{
		    			cfb.left = screen_width / 2 - 225;
	    				cfb.top = 0;
		    			cfb.visibility = "visible";
		    		}
					document.captureEvents(Event.MOUSEMOVE);
					document.onmousemove = trackIt;
*/
				}	else if (IE4)  {
					if (typeof objL != "undefined")	{
		   				objL.left = screen_width / 2 - 225;
			   			objL.top = 0;
		    			objL.visibility = "visible";
		    		}
					document.captureEvents(event.MOUSEMOVE);
					document.onmousemove = trackIt;
		    	}	else if (DHTML)	{
					if (objL != "null")	{
						objL.style.left = screen_width / 2 - 225;
						objL.style.top = 0;
						objL.style.visibility = "visible";
					}

					if (NS_DHTML)	mBody.addEventListener("mousemove", trackIt, false);
					else	mBody.onMousemove = trackIt;
				}
			}	else	{
				if (NS4)  {
/*
					if (typeof cfb != "undefined")	{
	    				cfb.visibility = "hidden";
	    			}
					document.releaseEvents(Event.MOUSEMOVE);
*/
				}
				else if (IE4)	{
					if (typeof objL != "undefined")
						objL.visibility = "hidden";
				}
				else if (DHTML)	{
					if (objL != "null")
						objL.style.visibility = "hidden";
					if (NS_DHTML)	{
						mBody.removeEventListener("mousemove", trackIt, false);
					}
				}
			}// end if (document.rate.reportType.value == "customize")	{
		}// end if (objN == "cfb")	{
		else if (objN == "statusLayer")	{
			if (DHTML)	{
				if (objL != "null" && objL.style.visibility != "visible")	{
					objL.style.left = screen_width / 2 - 225;
					objL.style.top = screen_height / 2 - objL.style.height;
					objL.style.visibility = "visible";
				}
				else	{
					if (objL != "null")	{
						objL.style.visibility = "hidden";
					}
				}
			}
		}
	}// end if (typeof document.rate != "undefined")	{
}
/* rate Select Items*/
/* display prompt to allow / disallow selection process to begin*/
	function customizePromptDisplay()	{
		if ( confirm("Place a check in the checkbox next to the product(s) you want to display (a minimum of 2 products).\nA cookie will be saved on your hard drive to maintain these settings. \n\nClick cancel if this is NOT what you want.\n\nDo you wish to continue?") == false )  {
			return false;
		}
		document.rate.reportType.value = "customize";
		notFirstTime = 1;
		rateDisplay(last_sort_col);
		setupFloatButton(cfb, "cfb");
	}
/* rate Select Items*/
/* displays all products if validation passes*/
	function customizeDisplay()	{
		if (customizeValidate())	{
			setCookie(document.customize);
			getCookie();
			notFirstTime = 0;
			document.rate.reportType.value = "sort";
			setupFloatButton(cfb, "cfb");
			rateDisplay(last_sort_col);
		}
		return false;
	};
/* rate Select Items*/
	function customizeValidate()  {
		var validated = 0;
		if (customize_obj)	{
			cookie_var = "";
			for (var i=0; i < customize_obj.length; i++)  {
				if (customize_obj[i].name.search("customizeProduct") != -1)	{
					if (customize_obj[i].checked)	{
	    	   			validated++;
	       			}
	       		}
	        }
		}
		if (validated < 2) {
			if ( confirm("You have selected " + validated + ".\nYou must select at least 2 products.\nPlease Select at least 2 products.") == false )  {
				notFirstTime = 0;
				document.rate.reportType.value = "sort";
				setupFloatButton(cfb, "cfb");
				rateDisplay(last_sort_col);
	        }
			return false;
		}
		return true;
	};
/* rate Select Items*/
	function trackIt(event)	{
		if (NS4 || IE4)	{
			if (NS4)	{
				currentPageY = pageYOffset + 50;
				cfb = eval(document.customizeFloatButton);
			}	else if (IE4)	{
				currentPageY = document.body.scrollTop + 50;
				cfb = eval('document.all.customizeFloatButton.style');
			}
    		if (document.rate.reportType.value == "customize")
				cfb.top = parseInt(currentPageY, 10);
		}
		else	{
			if (typeof document.body.scrollTop != "undefined")
   				currentPageY = document.body.scrollTop + 50;
   			else
   				currentPageY = event.pageY - event.clientY + 50;
    		if (document.rate.reportType.value == "customize")	{
    			mfb = document.getElementById("customizeFloatButton");
				mfb.style.top = parseInt(currentPageY, 10);
			}
		}
		return true;
	};
/* rate Select Items*/
	function setCookie(obj)  {
		if (NS4) return true;
		var cookie_name = document.rate.productType.value;
		var cookie_value = "";
		for (x = 0; x < obj.length; x++)  {
			if (obj[x].checked)	{
// remove profile links
				var s1 = obj[x].value.replace(/<a.*><font .*><u.*>(.*)<\/u><\/font><\/a>/i, "$1");
				cookie_value += obj[x].value + "!!";
			}
		}
// expiry in 5 yrs
/*
cookie expires in five years (actually, 365 days)
5 years
365 days in a year
24 hours in a day
60 minutes in an hour
60 seconds in a minute
1000 milliseconds in a second
*/
		var now = new Date();
		now.setTime(now.getTime() + 5 * 365 * 24 * 60 * 60 * 1000);
		document.cookie = cookie_name +"=" + escape(cookie_value) + ";expires=" + now.toGMTString() + ";";
		return true;
	};
/* rate Select Items*/
	function getCookie()	{
		if (document.cookie)  {
			var storedCookie = document.cookie;
			storedCookie = unescape(storedCookie);
			var cookies = storedCookie.split(";");
			for (cCount = 0; cCount < cookies.length; cCount++)	{
				var cookieStuff = cookies[cCount].split("=");
//alert("getCookie: \nstoredCookie=["+storedCookie +"]\ncookieStuff="+cookieStuff +"\ncookieSruff[0]="+cookieStuff[0] +"\ncookieStuff[1]="+ cookieStuff[1] +"\ncookieStuff[2]="+cookieStuff[2] +"\ncookieStuff[3]="+cookieStuff[3]);
				var cookie_CoMin = cookieStuff[1].split("!!");
				found_cookie = false;
				cookie_active = false;
				if (typeof document.rate != "undefined")	{
// remove any spces in cookie name
					cookieStuff[0] = cookieStuff[0].replace(/ /g, "");
					if (cookieStuff[0] == document.rate.productType.value)	{
						found_cookie = true;
						rateCookie = new Array();
						for (x = 0; x < cookie_CoMin.length; x++)  {
							if (cookie_CoMin[x] == "expires") break;
							rateCookie[x] = cookie_CoMin[x].split(":");
						}
// jan 7 2005
						break;
					}
				}
			}
		}
	};

/* rate Select items*/
/* checks | unchecks input boxes depending on <select> choices*/
	function auto_check(mode)  {
		obj = eval('document.customize');
// check all
		if (mode == "all")  {
			for (x=0; x < obj.length; x++)  {
				if (obj[x].checked == false)
					obj[x].checked = true;
			}
		}
// uncheck all
		else if (mode == "none")  {
			for (x=0; x < obj.length; x++)  {
				if (obj[x].checked == true)
					obj[x].checked = false;
			}
		}
// custom - compare list to stored values in cookie and check matches
		else if (mode == "custom")  {
			if (typeof rateCookie != "undefined")	{
				for (x=0; x < obj.length; x++)  {
					s1 = rateArray[x][0];
					s1 = s1.replace(/<a.*><font .*><u.*>(.*)<\/u><\/font><\/a>/i, "$1");
					for (xx = 0; xx < rateCookie.length; xx++)  {
						if (rateCookie[xx][0] == s1 && rateCookie[xx][1] == rateArray[x][2])	{
							obj[x].checked = true;
							break;
						}
						else obj[x].checked = false;
					}
				}
			}
		}
// all other modes
		else   {
			mode = eval(mode);
			for (x=0; x < obj.length; x++)  {
				if (obj[x].value.search(mode) != -1)
					obj[x].checked = true;
				else
					obj[x].checked = false;
			}
		}
	};

// remove child object
	function removeChildren  (myObj)  {
		objChild = myObj.firstChild;
		do  {
			if (objChild)
				myObj.removeChild(objChild);
			objChild = myObj.firstChild;
		} while (objChild)
	}

/*
IN DEVELOPMENT ITEMS
*/

/* Rate Alert items */
function ratealertSubmit()	{
	document.rate.reportType.value = "ratealert";
	if (ratealertValidate())
		document.rate.submit();
	return false;
};
/* Rate Alert items */
// validates that products are selected
function ratealertValidate()  {
	var validated = 0;
	if (ratealert_obj)	{
		document.rate.productName.value = "";
		for (var i=0; i < ratealert_obj.length; i++)  {
			if (ratealert_obj[i].name.search("ratealertProduct") != -1)	{
				if (ratealert_obj[i].checked)	{
					if (document.rate.productName.value.length > 0)
						document.rate.productName.value += "!"
					document.rate.productName.value += ratealert_obj[i].value;
    	   			validated++;
       			}
       		}
        }
	}
	if (validated == 0 && notFirstTime != 1)  {
		if ( confirm("Place a check in the checkbox next to the product(s) you want to receive a RateAlert for.\n\nDo you wish to continue?") == false )  {
			return false;
		}
		notFirstTime = 1;
// display check boxes next to each product
		rateDisplay(last_sort_col);
		return false;
	}
	if (validated < 1) {
		if ( confirm("You have selected " + validated + "\nYou have not selected any products to setup a RateAlert.\nPlease Select at least 1 product.") == false )  {
			notFirstTime = 0;
			document.rate.reportType.value = "sort";
			rateDisplay(last_sort_col);
        }
		return false;
	}
	return true;
};


