/*
	Written by Patrick Mulligan
	Written on 6.29.2004
	File: order_form_javascript.js
	Description: This is JavaScript used in the main order form. This JavaScript does
		not contain any ColdFusion.
*/

// global variable to hold the dynamically created cert table.
var the_cert_table, inner_table1, inner_table2;
// global arrays to hold the companies ordered.
var ordered_array_c = new Array();
var ordered_array_s = new Array();
var ordered_array_i = new Array();
var ordered_array_id = new Array();
// global variable to hold the number of elements in the second cert table.
var cert_elements = 0;
// global variable to hold the number of elements in the array.
var array_elements = 0;
// function to fade in the order form.
function pbar_fade()
{
	// if the total opacity is less than 100.
	if( parseInt( pbar_opacity ) > 0 )
	{
		pbar_opacity -= 5;
		// if netscape.
		if( navigator.appName == "Netscape" )
		{
			document.getElementById( "progress_bar" ).style.MozOpacity = pbar_opacity + "%";
		}
		// else ie.
		else
		{
			document.getElementById( "progress_bar" ).style.filter = "alpha( opacity = " + pbar_opacity + " )";
		}
	}
	// else
	else
	{
		window.clearInterval( form_intv );
		document.getElementById( "progress_bar" ).style.visibility = "hidden";
		document.getElementById( "portfolio" ).style.visibility = "visible";
		document.getElementById( "all_companies" ).style.visibility = "visible";
	}
}
// function to display gift cost alert.
function cost_alert()
{
	// alert the user.
	alert( "For gifts of enrollment and a single share of stock, a cushion against upward movement in the price of the stock and the service fee are included in the set price we establish as the 'cost of gift.' (We reserve the right to contact you if the price of the stock moves up precipitously before the purchase date.)" );//\n\nFor gifts of more than a single share, you will initially be charged based on an estimated cost of the stock plus a 10% cushion to cover the case of upward movement in the price of the stock. The cost of the transaction fee and the service fee are set prices. After the stock is purchased, any amount of cushion in excess of the cost of the stock will be refunded to you.
}
// function to change the styles onmouseover or onmouseout.
function onmouse_actions( type )
{
	// if the type is out.
	if( type == "out" )
	{
		document.getElementById( "cost_popup" ).style.color = "4266c8";
		document.getElementById( "cost_popup" ).style.textDecoration = "none";
	}
	// if the type is over.
	else
	{
		document.getElementById( "cost_popup" ).style.color = "f09a29";
		document.getElementById( "cost_popup" ).style.textDecoration = "underline";
	}
}
// function to build the gift wrapping included table.
function create_gift_wrap_table()
{
	// variables to hold row, cell, and table.
	var g_row, g_cell, g_table;
	// create the new table.
	g_table = document.createElement( "TABLE" );
	g_table.width = "100%";
	g_table.id = "gift_wrap_table";
	g_table.cellpadding = 0;
	g_table.cellspacing = 0;
	g_table.border = 0;
	// insert the new table.
	document.getElementById( "gift_wrapping_total" ).insertBefore( g_table, null );
	// handle crappy netscape.
	if( navigator.appName == "Netscape" )
	{
		g_row = g_table.insertRow( 0 );
	}
	// else ie.
	else
	{
		g_row = g_table.insertRow( -1 );
	}
	// set an underline.
	g_row.style.borderBottom = 1;
	// loop through the number of columns.
	for( var l = 0; l < 3; l++ )
	{
		// create the current cell.
		g_cell = g_row.insertCell( l );
		// switch through each cell and insert the necessary HTML.
		switch( l )
		{
			case 0:
				g_cell.innerHTML = "Gift Wrapping Charge";
				g_cell.align = "center";
				g_cell.width = "77%";
				break;
				
			case 1:
				g_cell.innerHTML = "$10.00";
				g_cell.align = "center";
				g_cell.width = "14%";
				break;
				
			case 2:
				g_cell.innerHTML = "&nbsp;";
				break;
		}
	}
}
// function to build the shopping cart table.
function create_shopping_cart()
{
	// variables to hold the current row and cell.
	var cell, row;
	// variable to hold the new dynamically created table.
	var new_table;
	// create the table and insert it in the shopping cart td.
	new_table = document.createElement( "TABLE" );
	new_table.width = "100%";
	new_table.id = "shopping_cart_table";
	new_table.cellpadding = 0;
	new_table.cellspacing = 0;
	new_table.border = 0;
	// clear the currently displayed information.
	document.getElementById( "shopping_cart" ).innerHTML = "";
	document.getElementById( "shopping_cart" ).insertBefore( new_table, null );
	// handle netscape differently from ie.
	if( navigator.appName == "Netscape" )
	{
		row = new_table.insertRow( 0 );
	}
	// handle ie.
	else
	{
		row = new_table.insertRow( -1 );
	}
	// loop through the number of columns.
	for( var i = 0; i < 9; i++ )
	{
		// create the current cell.
		cell = row.insertCell( i );
		// switch through each cell and insert the necessary HTML.
		switch( i )
		{
			case 0:
				cell.innerHTML = "<b>Company</b>";
				cell.height = 15;
				cell.width = "23%";
				cell.align = "center";
				break;
				
			case 1:
				cell.innerHTML = "<b>Industry</b>";
				cell.height = 15;
				cell.width = "19%";
				cell.align = "center";
				break;
				
			case 2:
				cell.innerHTML = "<b>$/Sh.*</b>";
				cell.height = 15;
				cell.align = "center";
				break;
				
			case 3:
				cell.innerHTML = "<b>Share(s)<a href='order_form_help.cfm#one_star' target='_blank'></a></b>";
				cell.height = 15;
				cell.width = "10%";
				cell.align = "center";
				break;
				
			case 4:
				cell.innerHTML = "<b>&nbsp;<a href='order_form_help.cfm#pricing' target='_blank'></a></b>";
				cell.height = 15;
				cell.align = "center";
				break;
				
			case 5:
				cell.innerHTML = "<b>&nbsp;<a href='order_form_help.cfm#three_stars' target='_blank'></a></b>";
				cell.height = 15;
				cell.align = "center";
				break;
				
			case 6:
				cell.innerHTML = "<b>&nbsp;</b>";
				cell.height = 15;
				cell.align = "center";
				break;
				
			case 7:
				cell.innerHTML = "<b>Cost of Gift<a href='order_form_help.cfm#pricing' target='_blank'>**</a></b>";
				cell.height = 15;
				cell.width = "14%";
				cell.align = "center";
				break;
				
			case 8:
				cell.innerHTML = "&nbsp;";
				break;
		}
	}
	// handle netscape differently from ie.
	if( navigator.appName == "Netscape" )
	{
		row = new_table.insertRow( 1 );
	}
	// handle ie.
	else
	{
		row = new_table.insertRow( -1 );
	}
	// insert a horizontal rule.
	cell = row.insertCell( 0 );
	cell.innerHTML = "<hr>";
	cell.colSpan = 9;
}
// function to double check the number of shares submitted by the user.
function double_check()
{
	// variable to hold the number of shares requested.
	var the_shares = document.getElementById( "shares" ).value;
	// variable to hold the required amount of shares.
	var req_shares = document.getElementById( "min_shares" ).value;
	// variable to decide if an error exists.
	var error_occurred = false;
	// if the value of shares is not numeric.
	if( isNaN( the_shares ) )
	{
		alert( "Please enter a numeric value greater than zero and less than or equal to 100 for the number of shares." );									
		error_occurred = true;
	}
	// if the amount of shares is less than 1.
	else if( parseInt( Trim( the_shares ) ) <= 0 )
	{
		alert( "Please enter a numeric value greater than zero and less than or equal to 100 for the number of shares." );									
		error_occurred = true;
	}
	// if the amount of shares is less than the required amount.
	else if( parseInt( Trim( the_shares ) ) < parseInt( Trim( req_shares ) ) )
	{
		alert( "The company that you have selected requires that you purchase a minimum of " + Trim( req_shares ) + " shares to qualify for DRIP enrollment." );
		error_occurred = true;
	}
	// if an error occured.
	if( error_occurred == true )
	{
		document.getElementById( "shares" ).value = parseInt( Trim( req_shares ) );
		change_amount( parseInt( Trim( req_shares ) ) );
	}
}
// function to create the company list on the cert.
function create_cert_table()
{
	// variable to hold the new elements to create.
	var new_cert_table, new_cert_row;
	// create the cert cart table.
	new_cert_table = document.createElement( "TABLE" );
	new_cert_table.id = "cert_cart_table";
	new_cert_table.width = "100%";
	// delete the current inner HTML.
	document.getElementById( "cert_cart" ).innerHTML = "";
	// insert the new table.
	document.getElementById( "cert_cart" ).insertBefore( new_cert_table, null );
	// handle netscape differently from ie.
	if( navigator.appName == "Netscape" )
	{
		new_cert_row = new_cert_table.insertRow( 0 );
	}
	// handle ie.
	else
	{
		new_cert_row = new_cert_table.insertRow( -1 );
	}
	// set new row id.
	new_cert_row.id = "cert_top_row";
	// valign top.
	new_cert_row.vAlign = "top";
	// set the global variable equal to the table created.
	the_cert_table = new_cert_table;
}

// the following functions may be removed.
// function to add to the company list on the cert.
function new_to_cert_table( company_id, company, symbol, industry, shares )
{
	// if total rows is 1.
	if( total_rows == 1 )
	{
		// create the cert table.
		create_cert_table();
	}
	// variable to hold the cells
	var new_cell, new_row;
	// variable to hold the cert table.
	var cert_table = the_cert_table;
	// add the current values to the ordered arrays.
	ordered_array_c[ array_elements ] = Trim( company ) + "/" + Trim( symbol );
	ordered_array_i[ array_elements ] = Trim( industry );
	ordered_array_s[ array_elements ] = Trim( shares );
	ordered_array_id[ array_elements ] = parseInt( Trim( company_id ) );
	// increment array elements.
	array_elements += 1;
	// if total rows is less than 8.
	if( total_rows < 10 )
	{
		/*
		// if the total rows is 1.
		if( total_rows == 1 )
		{
			// loop through the three different cells.
			for( var u = 0; u < 1; u++ )
			{
				// variable to hold the top row.
				var top_row = document.getElementById( "cert_top_row" );
				// set the current cell.
				new_cell = top_row.insertCell( u );
				// set attributes.
				new_cell.style.fontFamily = "Times New Roman";
				new_cell.style.fontSize = "1pt";
				new_cell.style.fontWeight = "bold";
				new_cell.style.paddingLeft = "0px";
				new_cell.style.paddingRight = "0px";
				new_cell.style.paddingTop = "0px";
				new_cell.style.paddingBottom = "0px";
				// switch through the cells.
				switch( u )
				{
					// company heading.
					case 0:
						new_cell.innerHTML = "Company";
						new_cell.align = "left";
						new_cell.id = "cert_company0";
						break;
					// industry heading.
					case 1:
						new_cell.innerHTML = "Industry";
						new_cell.align = "left";
						new_cell.id = "cert_industry0";
						break;
					// shares heading.
					case 2:
						new_cell.innerHTML = "Shares";
						new_cell.align = "center";
						new_cell.id = "cert_shares0";
						break;
				}
			}
		}
		*/
		// add a new row.
		// handle netscape differently from ie.
		if( navigator.appName == "Netscape" )
		{
			new_row = cert_table.insertRow( total_rows );
		}
		// handle ie.
		else
		{
			new_row = cert_table.insertRow( -1 );
		}
		// if there is more than 1 share.
		if( parseInt( shares ) > 1 )
		{
			var shares_txt = " (" + Trim( shares ) + " shares)";
		}
		// else.
		else
		{
			var shares_txt = " (" + Trim( shares ) + " share)";
		}
		// set the id.
		new_row.id = company_id;
		// loop through the three different cells and insert the html.
		for( var u = 0; u < 1; u++ )
		{
			// set the current cell.
			new_cell = new_row.insertCell( u );
			// cell attributes.
			new_cell.style.fontFamily = "Times New Roman";
			new_cell.style.fontSize = "1pt";
			new_cell.style.paddingRight = "0px";
			new_cell.style.paddingTop = "0px";
			new_cell.style.paddingBottom = "0px";
			// switch through the cells.
			switch( u )
			{
				case 0:
					new_cell.innerHTML = Trim( company ) + "/" + symbol + shares_txt;
					new_cell.align = "center";
					new_cell.id = "cert_company" + rows_added;
					break;
				/*
				this is no longer.
				case 1:
					new_cell.innerHTML = Trim( industry );
					new_cell.style.paddingLeft = "2px";
					new_cell.id = "cert_industry" + rows_added;
					break;
				case 2:
					new_cell.innerHTML = Trim( shares );
					new_cell.style.paddingLeft = 0;
					new_cell.id = "cert_shares" + rows_added;
					new_cell.align = "center";
					break;
				*/		
			}
		}
	}
	// if the total companies selected is between 9 and 18.
	else
	{
		// if the total rows is 9.
		if( total_rows == 10 )
		{
			// create two tables.
			create_two_cert_tables();
		}
		// else add it to the second table.
		else
		{
			// add to the second table.
			add_company_cert( company_id );
		}
	}
}
// function to create the two tables.
function create_two_cert_tables()
{
	// local variables needed.
	var new_row0, new_cell0;
	// handle crappy netscape.
	if( navigator.appName == "Netscape" )
	{
		// loop through the existing cert table.
		for( h = 0; h <= 10; h++ )
		{
			// verify that the current row exists.
			if( the_cert_table.rows[ 0 ] != null )
			{
				// delete the current row.
				the_cert_table.deleteRow( 0 );
			}
		}
	}
	// else ie.
	else
	{
		// loop through the existing cert table.
		for( var h = 0; h < 10; h++ )
		{
			// verify that the current row exists.
			if( the_cert_table.rows( 0 ) != null )
			{
				// delete the current row.
				the_cert_table.deleteRow( 0 );
			}
		}
	}
	// handle netscape differently from ie.
	if( navigator.appName == "Netscape" )
	{
		new_row0 = the_cert_table.insertRow( 0 );
	}
	// handle ie.
	else
	{
		new_row0 = the_cert_table.insertRow( -1 );
	}
	// loop through the three different cells.
	for( var u = 0; u < 2; u++ )
	{
		// set the current cell.
		new_cell0 = new_row0.insertCell( u );
		// set attributes.
		new_cell0.style.paddingLeft = "0px";
		new_cell0.style.paddingRight = "0px";
		new_cell0.style.paddingTop = "0px";
		new_cell0.style.paddingBottom = "0px";
		new_cell0.align = "center";
		// switch through the cells.
		switch( u )
		{
			// company heading.
			case 0:
				new_cell0.width = "50%";
				new_cell0.vAlign = "top";
				break;
			// industry heading.
			case 1:
				new_cell0.width = "50%";
				new_cell0.vAlign = "top";
				break;
		}
	}
	// build the inner tables.
	build_cert_table( the_cert_table );
}
// function to build the two cert tables for orders of 9 or more companies.
function build_cert_table( cert_table )
{
	// variables to hold the number of companies to put in each table.
	var first_table, second_table;
	// variables to hold the new table elements.
	var new_table1, new_row1, new_cell1;
	// create the cert cart table.
	new_table1 = document.createElement( "TABLE" );
	new_table1.id = "inner_cert_table1";
	new_table1.width = "100%";
	new_table1.cellPadding = 0;
	// handle crappy netscape.
	if( navigator.appName == "Netscape" )
	{
		// insert the new table.
		cert_table.rows[0].cells[0].insertBefore( new_table1, null );
	}
	// else ie.
	else
	{	
		// insert the new table.
		cert_table.cells(0).insertBefore( new_table1, null );
	}
	// set the global variable to the current table.
	inner_table1 = new_table1;
	/*
	// handle netscape differently from ie.
	if( navigator.appName == "Netscape" )
	{
		new_row1 = inner_table1.insertRow( 0 );
	}
	// handle ie.
	else
	{
		new_row1 = inner_table1.insertRow( -1 );
	}
	// loop through the two cells.
	for( var y = 0; y < 2; y++ )
	{
		// set the current cell.
		new_cell1 = new_row1.insertCell( y );
		// cell attributes.
		new_cell1.style.fontFamily = "Times New Roman";
		new_cell1.style.fontSize = "1pt";
		new_cell1.style.fontWeight = "bold";
		new_cell1.style.paddingLeft = "0px";
		new_cell1.style.paddingRight = "0px";
		new_cell1.style.paddingTop = "0px";
		new_cell1.style.paddingBottom = "0px";
		// switch through the cells.
		switch( y )
		{
			case 0:
				new_cell1.innerHTML = "Company";
				new_cell1.align = "left";
				new_cell1.id = "cert_company0";
				break;
			case 1:
				new_cell1.innerHTML = "Shares";
				new_cell1.align = "center";
				new_cell1.id = "cert_shares0";
				break;
		}
	}
	*/
	// loop through the first group of companies.
	for( var b = 0; b < 9; b++ )
	{
		// if there is more than 1 share.
		if( parseInt( ordered_array_s[b] ) > 1 )
		{
			var shares_txt = " (" + ordered_array_s[b] + " shares)";
		}
		// else.
		else
		{
			var shares_txt = " (" + ordered_array_s[b] + " share)";
		}
		// handle netscape differently from ie.
		if( navigator.appName == "Netscape" )
		{
			new_row1 = inner_table1.insertRow( b + 1 );
		}
		// handle ie.
		else
		{
			new_row1 = inner_table1.insertRow( -1 );
		}
		// loop through the two cells.
		for( var y = 0; y < 1; y++ )
		{
			// set the current cell.
			new_cell1 = new_row1.insertCell( y );
			// cell attributes.
			new_cell1.style.fontFamily = "Times New Roman";
			new_cell1.style.fontSize = "1pt";
			new_cell1.style.paddingRight = "0px";
			new_cell1.style.paddingTop = "0px";
			new_cell1.style.paddingBottom = "0px";
			// switch through the cells.
			switch( y )
			{
				case 0:
					new_cell1.innerHTML = ordered_array_c[b] + shares_txt;
					new_cell1.align = "center";
					new_cell1.id = "cert_company" + eval( b );
					break;
				/*
				case 1:
					new_cell1.innerHTML = ordered_array_s[b];
					new_cell1.style.paddingLeft = 0;
					new_cell1.id = "cert_shares" + eval( b + 1 );
					new_cell1.align = "center";
					break;
				*/
			}
		}
	}
	// create the cert cart table.
	new_table1 = document.createElement( "TABLE" );
	new_table1.id = "inner_cert_table2";
	new_table1.width = "100%";
	new_table1.cellPadding = 0;
	// handle crappy netscape.
	if( navigator.appName == "Netscape" )
	{
		// insert the new table.
		cert_table.rows[0].cells[1].insertBefore( new_table1, null );
	}
	// else ie.
	else
	{
		// insert the new table.
		cert_table.cells(1).insertBefore( new_table1, null );
	}
	// set the global variable to the current table.
	inner_table2 = new_table1;
	/*
	// handle netscape differently from ie.
	if( navigator.appName == "Netscape" )
	{
		new_row1 = inner_table2.insertRow( 0 );
	}
	// handle ie.
	else
	{
		new_row1 = inner_table2.insertRow( -1 );
	}
	// loop through the two cells.
	for( var y = 0; y < 2; y++ )
	{
		// set the current cell.
		new_cell1 = new_row1.insertCell( y );
		// cell attributes.
		new_cell1.style.fontFamily = "Times New Roman";
		new_cell1.style.fontSize = "1pt";
		new_cell1.style.fontWeight = "bold";
		new_cell1.style.paddingLeft = "0px";
		new_cell1.style.paddingRight = "0px";
		new_cell1.style.paddingTop = "0px";
		new_cell1.style.paddingBottom = "0px";
		// switch through the cells.
		switch( y )
		{
			case 0:
				new_cell1.innerHTML = "Company";
				new_cell1.align = "left";
				new_cell1.id = "cert_company10";
				break;
			case 1:
				new_cell1.innerHTML = "Shares";
				new_cell1.align = "center";
				new_cell1.id = "cert_shares10";
				break;
		}
	}
	*/
	// loop through the second group of companies.
	for( var c = 9; c < ordered_array_id.length; c++ )
	{
		// if there is more than 1 share.
		if( parseInt( ordered_array_s[c] ) > 1 )
		{
			var shares_txt = " (" + ordered_array_s[c] + " shares)";
		}
		// else.
		else
		{
			var shares_txt = " (" + ordered_array_s[c] + " share)";
		}
		// handle netscape differently from ie.
		if( navigator.appName == "Netscape" )
		{
			new_row1 = inner_table2.insertRow( 1 );
		}
		// handle ie.
		else
		{
			new_row1 = inner_table2.insertRow( -1 );
		}
		// loop through the two cells.
		for( var y = 0; y < 1; y++ )
		{
			// set the current cell.
			new_cell1 = new_row1.insertCell( y );
			// cell attributes.
			new_cell1.style.fontFamily = "Times New Roman";
			new_cell1.style.fontSize = "1pt";
			new_cell1.style.paddingLeft = "0px";
			new_cell1.style.paddingRight = "0px";
			new_cell1.style.paddingTop = "0px";
			new_cell1.style.paddingBottom = "0px";
			// switch through the cells.
			switch( y )
			{
				case 0:
					new_cell1.innerHTML = ordered_array_c[ c ] + shares_txt;
					new_cell1.align = "center";
					new_cell1.id = "cert_company" + eval( c );
					break;
				/*
				case 1:
					new_cell1.innerHTML = ordered_array_s[ c ];
					new_cell1.style.paddingLeft = 0;
					new_cell1.id = "cert_shares" + eval( c + 2 );
					new_cell1.align = "center";
					break;
				*/
			}
		}
	}
}
// function to add another company to the cert table.
function add_company_cert( company_id )
{
	// increment cert elements.
	cert_elements += 1;
	// handle netscape differently from ie.
	if( navigator.appName == "Netscape" )
	{
		new_row1 = inner_table2.insertRow( cert_elements + 1 );
	}
	// handle ie.
	else
	{
		new_row1 = inner_table2.insertRow( -1 );
	}
	// if there is more than 1 share.
	if( parseInt( ordered_array_s[array_elements - 1] ) > 1 )
	{
		var shares_txt = " (" + ordered_array_s[array_elements - 1] + " shares)";
	}
	// else.
	else
	{
		var shares_txt = " (" + ordered_array_s[array_elements - 1] + " share)";
	}
	// set the new row's id.
	new_row1.id = company_id;
	// loop through the two cells.
	for( var y = 0; y < 2; y++ )
	{
		// set the current cell.
		new_cell1 = new_row1.insertCell( y );
		// cell attributes.
		new_cell1.style.fontFamily = "Times New Roman";
		new_cell1.style.fontSize = "1pt";
		new_cell1.style.paddingRight = "0px";
		new_cell1.style.paddingTop = "0px";
		new_cell1.style.paddingBottom = "0px";
		// switch through the cells.
		switch( y )
		{
			case 0:
				new_cell1.innerHTML = ordered_array_c[ array_elements - 1 ] + shares_txt;
				new_cell1.align = "center";
				new_cell1.id = "cert_company" + eval( rows_added );
				break;
			/*
			case 1:
				new_cell1.innerHTML = ordered_array_s[ array_elements - 1 ];
				new_cell1.style.paddingLeft = 0;
				new_cell1.id = "cert_shares" + eval( rows_added + 2 );
				new_cell1.align = "center";
				break;
			*/
		}
	}
}
// function to add shares to a previously entered company.
function add_to_cert_table( row, company_id )
{
	// variable to hold the new shares.
	var new_shares;
	// find the array element in question.
	for( var g = 0; g < ordered_array_id.length; g++ )
	{
		// if the current element is the element in question.
		if( ordered_array_id[g] == company_id )
		{
			// variable to hold the array element in question.
			var array_element = g;
		}
	}
	// handle crappy netscape.
	if( navigator.appName == "Netscape" )
	{
		// set the value of shares.
		new_shares = parseInt( document.getElementById( "shopping_cart_table" ).rows[row].cells[3].innerHTML );
		// html to insert into the cell in question.
		var html_insert = ordered_array_c[array_element] + " (" + new_shares + " shares)";
		// set the new value for the element in question.
		document.getElementById( company_id ).cells[0].innerHTML = html_insert;
	}
	// else ie.
	else
	{
		// set the value of shares.
		new_shares = parseInt( document.getElementById( "shopping_cart_table" ).rows(row).cells(3).innerHTML );
		// html to insert into the cell in question.
		var html_insert = ordered_array_c[array_element] + " (" + new_shares + " shares)";
		// set the new value for the element in question.
		document.getElementById( company_id ).cells(0).innerHTML = html_insert;
	}
	// find the array element in question.
	for( var c = 0; c < ordered_array_id.length; c++ )
	{
		// if the current element is the element in question.
		if( ordered_array_id[c] == company_id )
		{
			// variable to hold the array element in question.
			var the_element = c;
		}
	}
	// reset the value in the global array.
	ordered_array_s[ c ] = new_shares;
}
// function to remove a company from the cert.
function remove_cert( row, row_total )
{	
	// handle crappy netscape.
	if( navigator.appName == "Netscape" )
	{
		// local variable to hold the row in question.
		var the_row_index = parseInt( row.cells[0].id.replace( "cert_cell", "" ) );
	}
	// else ie.
	else
	{
		// local variable to hold the row in question.
		var the_row_index = parseInt( row.cells(0).id.replace( "cert_cell", "" ) );
	}
	// function to delete an element from the arrays.
	array_delete( the_row_index );
	// if the number of companies printed is less than 10.
	if( row_total < 10 )
	{
		// if this isn't the only company selected.
		if( row_total > 1 )
		{
			// delete the relevant row.
			the_cert_table.deleteRow( document.getElementById( the_row_index ).rowIndex );
		}
		// else.
		else
		{
			document.getElementById( "cert_cart" ).innerHTML = "<p align='center' style='font-family: Times New Roman; color: red;'>No stocks have been selected at this time.</p>";
		}
	}
	// else
	else
	{
		// clear the cert.
		document.getElementById( "cert_cart" ).innerHTML = "";
		// function to rebuild the cert cart table.
		rebuild_cert_cart();
	}
}
// function to remove an element from the arrays.
function array_delete( row )
{
	// loop through the id array.
	for( var z = 0; z < ordered_array_id.length; z++ )
	{
		// if the current element is the element in question.
		if( ordered_array_id[z] == row )
		{
			// local variable to hold the position of the element to be deleted.
			var array_item = z;
		}
	}
	// remove the specific element from the company array.
	ordered_array_c.splice( array_item, 1 );
	// remove the specific element from the shares array.
	ordered_array_s.splice( array_item, 1 );
	// remove the specific element from the industry array.
	ordered_array_i.splice( array_item, 1 );
	// remove the specific element from the id array.
	ordered_array_id.splice( array_item, 1 );
	// decrement the number of array elements.
	array_elements -= 1;
}
// function to rebuild the cert cart table.
function rebuild_cert_cart()
{
	// call function to build the table.
	create_cert_table();
	// if there are less than 10 companies left over.
	if( ordered_array_id.length < 10 )
	{
		/*
		// loop through the three different cells.
		for( var u = 0; u < 3; u++ )
		{
			// variable to hold the top row.
			var top_row = document.getElementById( "cert_top_row" );
			// set the current cell.
			new_cell = top_row.insertCell( u );
			// set attributes.
			new_cell.style.fontFamily = "Times New Roman";
			new_cell.style.fontSize = "1pt";
			new_cell.style.fontWeight = "bold";
			new_cell.style.paddingLeft = "0px";
			new_cell.style.paddingRight = "0px";
			new_cell.style.paddingTop = "0px";
			new_cell.style.paddingBottom = "0px";
			// switch through the cells.
			switch( u )
			{
				// company heading.
				case 0:
					new_cell.innerHTML = "Company";
					new_cell.align = "left";
					new_cell.id = "cert_company0";
					break;
				// industry heading.
				case 1:
					new_cell.innerHTML = "Industry";
					new_cell.align = "left";
					new_cell.id = "cert_industry0";
					break;
				// shares heading.
				case 2:
					new_cell.innerHTML = "Shares";
					new_cell.align = "center";
					new_cell.id = "cert_shares0";
					break;
			}
		}
		*/
		// loop through the arrays and output the remaining companies.
		for( var w = 0; w < ordered_array_id.length; w++ )
		{
			// if there is more than 1 share.
			if( parseInt( ordered_array_s[w] ) > 1 )
			{
				var shares_txt = " (" + ordered_array_s[w] + " shares)";
			}
			// else.
			else
			{
				var shares_txt = " (" + ordered_array_s[w] + " share)";
			}
			// add a new row.
			// handle netscape differently from ie.
			if( navigator.appName == "Netscape" )
			{
				new_row = the_cert_table.insertRow( w + 1 );
			}
			// handle ie.
			else
			{
				new_row = the_cert_table.insertRow( -1 );
			}
			// set the id.
			new_row.id = ordered_array_id[w];
			// loop through the three different cells and insert the html.
			for( var u = 0; u < 3; u++ )
			{
				// set the current cell.
				new_cell = new_row.insertCell( u );
				// cell attributes.
				new_cell.style.fontFamily = "Times New Roman";
				new_cell.style.fontSize = "1pt";
				new_cell.style.paddingRight = "0px";
				new_cell.style.paddingTop = "0px";
				new_cell.style.paddingBottom = "0px";
				// switch through the cells.
				switch( u )
				{
					case 0:
						new_cell.innerHTML = Trim( ordered_array_c[w] ) + shares_txt;
						new_cell.align = "center";
						new_cell.id = "cert_company" + eval( w );
						break;
					/*
					case 1:
						new_cell.innerHTML = Trim( ordered_array_i[w] );
						new_cell.style.paddingLeft = "2px";
						new_cell.id = "cert_industry" + eval( w + 1 );
						break;
					case 2:
						new_cell.innerHTML = Trim( ordered_array_s[w] );
						new_cell.style.paddingLeft = 0;
						new_cell.id = "cert_shares" + eval( w + 1 );
						new_cell.align = "center";
						break;
					*/
				}
			}
		}
	}
	// else.
	else
	{
		// call function to rebuild the two cert tables.
		create_two_cert_tables();
	}
}