// a function, called onLoad, to set up the list
var class_list = new Array();
var class_price_single = new Array();
var class_price_multiple = new Array();
var EB_date = new Array();
var EB_price_single = new Array();
var EB_price_multiple = new Array();
var promo_codes = new Array();
var promo_price_difference= new Array();
var att_first = new Array();
var att_last = new Array();
var att_addr = new Array();
var att_city = new Array();
var att_state = new Array();
var att_zip = new Array();
var att_title = new Array();
var att_email = new Array();
var att_phone = new Array();
var att_fax = new Array();
var num_att = 0;
var cur_att = 0;
var submitted;

//!!@@## everything taken out with this tag was originally there for the "OLD_ClassRegOnline.html" file

function make_class_list()
{
	// make the class list, name, price, early bird date, early bird price
	// template for adding new classes
	// increase declaration size of arrays, and add values
	// class_list[x] = "class name"
	// class_price_single[x] = "single registrant class price"
	// class_price_multiple[x] = "two or more registrant class price"
	// EB_date[x] = "early bird date"
	// EB_price_single[x] = "single registrant early bird price"
	// EB_price_multiple[x] = "two or more registrant early bird price"
	// promo_codes[x] = "comma separated list of promo codes, all CAPS";
	// promo_price_difference[x] = "corresponding comma separated list of promo price differences";
	/* To edit the list
	*/
	// class 1
	class_list[0] = "Kase's No Gimmick Futures Trading";
	class_price_single[0] = 595;
	class_price_multiple[0] = 595;
	EB_date[0] = "";
	EB_price_single[0] = 595;
	EB_price_multiple[0] = 595;
	promo_codes[0] = "MTA09, NMOGA";
	promo_price_difference[0] = "-100, -100";
	// class 2
	class_list[1] = "Energy Trading and Hedging";
	class_price_single[1] = 595;
	class_price_multiple[1] = 595;
	EB_date[1] = "";
	EB_price_single[1] = 595;
	EB_price_multiple[1] = 595;
	promo_codes[1] = "MTA09, NMOGA";
	promo_price_difference[1] = "-100, -100";
	//add more classes here in same format as above
	
	// we have the list, fill the dropdown
	var opt_el;
	for( i = 0; i < class_list.length; i++ )
	{
		opt_el = document.createElement( "option" );
		opt_el.text = class_list[i];
		opt_el.value = i;
		document.reg_info.list_class.options[i] = opt_el;
	}
	document.reg_info.list_class.selectedIndex = 0;
	// update the details
	update_class_details();
	num_att = 0;
	cur_att = -1;
	submitted = false;
	update_att();
}

// when the class selection is changed, update the price and EB display
function update_class_details()
{
//!!@@##	document.reg_info.EB_date_disp.value = EB_date[document.reg_info.list_class.selectedIndex];
//!!@@##	document.reg_info.EB_price_disp_S.value = "$" + EB_price_single[document.reg_info.list_class.selectedIndex] + ".00";
	document.reg_info.def_price_disp_S.value = "$" + class_price_single[document.reg_info.list_class.selectedIndex] + ".00";
	if( class_price_single[document.reg_info.list_class.selectedIndex] != class_price_multiple[document.reg_info.list_class.selectedIndex] )
	{
		document.reg_info.def_price_disp_M.value = "$" + class_price_multiple[document.reg_info.list_class.selectedIndex] + ".00";
	}
	else
	{
		document.reg_info.def_price_disp_M.value = "N/A";	
	}
//!!@@##	if( EB_price_single[document.reg_info.list_class.selectedIndex] != EB_price_multiple[document.reg_info.list_class.selectedIndex] )
//!!@@##	{
//!!@@##		document.reg_info.EB_price_disp_M.value = "$" + EB_price_multiple[document.reg_info.list_class.selectedIndex] + ".00";
//!!@@##	}
//!!@@##	else
//!!@@##	{
//!!@@##		document.reg_info.EB_price_disp_M.value = "N/A";
//!!@@##	}
}

// some functions for the next/back form changes
function next_form()
{
	if( document.NB_BTNS.next_BTN.value != "Finish" )
	{
		// loop through all the div tags (except the last, no next there) and hide whatever is shown, and show the next one
		for( i = 1; i <= 3; i++ )
		{
			// if this id is shown
			if( document.getElementById( "class_info_form_" + i ).style.display == "block")
			{
				if( ( i == 2 ) && ( num_att <= 0 ) )
				{
					alert("Please enter at least one attendee.");
					okay = false;
				}
				else if( ( i == 3 ) && !check_bills() )
				{
					alert("Billing information isn't complete.  Please fill in missing fields before continuing.");
					okay = false;
				}
				else
				{
					// hide this one
					document.getElementById( "class_info_form_" + i ).style.display = "none";
					q = i + 1;
					if( q == 4 )
					{
						document.NB_BTNS.next_BTN.disabled = true;
						make_review();
					}
					else
					{
						document.NB_BTNS.next_BTN.disabled = false;
					}
					// check to see if we should disable the "next"
					if( q != 4 )
					{
						// display the next one
						document.getElementById( "class_info_form_" + q ).style.display = "block";
					}
					else
					{
						// display the next one
						document.getElementById( "class_info_form_" + q ).style.display = "block";
					}
					// going forward, the back should always be enabled
					document.NB_BTNS.back_BTN.disabled = false;
					// and break
					i = 42;
				}
			}
		}
	}
	else
	{
		document.NB_BTNS.back_BTN.disabled = true;
		alert("Your regrstration has been sent.  Please print this page for your records.  If you have any questions or concerns, feel free to contact the Kase Call Cneter at (505)237-1600.");
		// TODO put in submission code here
	}
}

function back_form()
{
	// loop through all the div tags (except the first, no prev there) and hide whatever is shown, and show the previous one
	for( i = 2; i <= 4; i++ )
	{
		// if this id is shown
		if( document.getElementById( "class_info_form_" + i ).style.display == "block")
		{
			// hide this one
			document.getElementById( "class_info_form_" + i ).style.display = "none";
			q = i - 1;
			// and display the previous one
			document.getElementById( "class_info_form_" + q ).style.display = "block";
			if( q == 4 )
			{
				document.NB_BTNS.next_BTN.disabled = true;
			}
			else
			{
				document.NB_BTNS.next_BTN.disabled = false;
			}
				
			if( q == 1 )
				document.NB_BTNS.back_BTN.disabled = true;
			else
				document.NB_BTNS.back_BTN.disabled = false;
			// going backward, the next should always be enabled
			document.NB_BTNS.next_BTN.disabled = false;
			// and break
			i = 42;
		}
	}
}

function check_bills()
{
	var ret = true;
	if( ( document.reg_info.card_num.value == "" ) ||
		( document.reg_info.card_exp.value == "" ) ||
		( document.reg_info.card_name.value == "" ) ||
		( document.reg_info.card_billing_addr1.value == "" ) ||
		( document.reg_info.card_billing_city.value == "" ) ||
		( document.reg_info.card_billing_zip.value == "" ) )
	{
		ret = false;
	}
	if( document.reg_info.BillRadio[ 0 ].checked )
		ret = true;
	
	return ret;
}

// attendee form funcitons
function check_att()
{
	var ret = true;
	if( ( document.reg_info.att_last_inp.value == "" ) ||
		( document.reg_info.att_first_inp.value == "" ) ||
		( document.reg_info.att_addr_inp.value == "" ) ||
		( document.reg_info.att_city_inp.value == "" ) ||
		( document.reg_info.att_state_inp.value == "" ) ||
		( document.reg_info.att_zip_inp.value == "" ) ||
		( document.reg_info.att_title_inp.value == "" ) ||
		( document.reg_info.att_email_inp.value == "" ) ||
		( document.reg_info.att_phone_inp.value == "" ) ||
		( document.reg_info.att_fax_inp.value == "" ) )
		{
			alert("Please fill in all the fields before trying to add an attendee.");
			ret = false;
		}
	
	return ret;
}

function update_att()
{
	if( num_att == 0 )
	{
		document.getElementById("att_cur").innerHTML = "No attendees, please enter information and press 'add'";
	}
	else
	{
		if( cur_att == num_att )
			document.getElementById("att_cur").innerHTML = "New Attendee, " + num_att + " total";
		else
			document.getElementById("att_cur").innerHTML = (cur_att + 1).toString() + " of " + num_att + " attendees";
	}
}

function F_add_att()
{
	if( check_att() == true )
	{
		num_att++;
		cur_att = num_att;
		att_last[ num_att - 1 ] = document.reg_info.att_last_inp.value;
		att_first[ num_att - 1 ] = document.reg_info.att_first_inp.value;
		att_addr[ num_att - 1 ] = document.reg_info.att_addr_inp.value;
		att_city[ num_att - 1 ] = document.reg_info.att_city_inp.value;
		att_state[ num_att - 1 ] = document.reg_info.att_state_inp.value;
		att_zip[ num_att - 1 ] = document.reg_info.att_zip_inp.value;
		att_title[ num_att - 1 ] = document.reg_info.att_title_inp.value;
		att_email[ num_att - 1 ] = document.reg_info.att_email_inp.value;
		att_phone[ num_att - 1 ] = document.reg_info.att_phone_inp.value;
		att_fax[ num_att - 1 ] = document.reg_info.att_fax_inp.value;
		document.reg_info.att_last_inp.value = "";
		document.reg_info.att_first_inp.value = "";
		document.reg_info.att_addr_inp.value = "";
		document.reg_info.att_city_inp.value = "";
		document.reg_info.att_state_inp.value = "";
		document.reg_info.att_zip_inp.value = "";
		document.reg_info.att_title_inp.value = "";
		document.reg_info.att_email_inp.value = "";
		document.reg_info.att_phone_inp.value = "";
		document.reg_info.att_fax_inp.value = "";
		document.reg_info.prev_att.disabled = false;
	}
	update_att();
}

function F_rem_att()
{
	if( cur_att != num_att )
	{
		att_last.splice( cur_att, 1 );
		att_first.splice( cur_att, 1 );
		att_addr.splice( cur_att, 1 );
		att_city.splice( cur_att, 1 );
		att_state.splice( cur_att, 1 );
		att_zip.splice( cur_att, 1 );
		att_title.splice( cur_att, 1 );
		att_email.splice( cur_att, 1 );
		att_phone.splice( cur_att, 1 );
		att_fax.splice( cur_att, 1 );
		if( cur_att == ( num_att - 1 ) )
			cur_att = num_att - 2;
		num_att--;
		if( num_att != 0 )
		{
			document.reg_info.att_last_inp.value = att_last[ cur_att ];
			document.reg_info.att_first_inp.value = att_first[ cur_att ];
			document.reg_info.att_addr_inp.value = att_addr[ cur_att ];
			document.reg_info.att_city_inp.value = att_city[ cur_att ];
			document.reg_info.att_state_inp.value = att_state[ cur_att ];
			document.reg_info.att_zip_inp.value = att_zip[ cur_att ];
			document.reg_info.att_title_inp.value = att_title[ cur_att ];
			document.reg_info.att_email_inp.value = att_email[ cur_att ];
			document.reg_info.att_phone_inp.value = att_phone[ cur_att ];
			document.reg_info.att_fax_inp.value = att_fax[ cur_att ];
		}
		else
		{
			document.reg_info.att_last_inp.value = "";
			document.reg_info.att_first_inp.value = "";
			document.reg_info.att_addr_inp.value = "";
			document.reg_info.att_city_inp.value = "";
			document.reg_info.att_state_inp.value = "";
			document.reg_info.att_zip_inp.value = "";
			document.reg_info.att_title_inp.value = "";
			document.reg_info.att_email_inp.value = "";
			document.reg_info.att_phone_inp.value = "";
			document.reg_info.att_fax_inp.value = "";
			document.reg_info.rem_att.disabled = true;
			document.reg_info.prev_att.disabled = true;
			document.reg_info.next_att.disabled = true;
			cur_att = 0;
		}
	}
	update_att();
}

function F_prev_att()
{
	if( cur_att == num_att )
	{
		document.reg_info.rem_att.disabled = false;
		document.reg_info.next_att.disabled = false;
	}
	if( cur_att != 0 )
	{
		att_last[ cur_att ] = document.reg_info.att_last_inp.value;
		att_first[ cur_att ] = document.reg_info.att_first_inp.value;
		att_addr[ cur_att ] = document.reg_info.att_addr_inp.value;
		att_city[ cur_att ] = document.reg_info.att_city_inp.value;
		att_state[ cur_att ] = document.reg_info.att_state_inp.value;
		att_zip[ cur_att ] = document.reg_info.att_zip_inp.value;
		att_title[ cur_att ] = document.reg_info.att_title_inp.value;
		att_email[ cur_att ] = document.reg_info.att_email_inp.value;
		att_phone[ cur_att ] = document.reg_info.att_phone_inp.value;
		att_fax[ cur_att ] = document.reg_info.att_fax_inp.value;
		cur_att--;
		document.reg_info.att_last_inp.value = att_last[ cur_att ];
		document.reg_info.att_first_inp.value = att_first[ cur_att ];
		document.reg_info.att_addr_inp.value = att_addr[ cur_att ];
		document.reg_info.att_city_inp.value = att_city[ cur_att ];
		document.reg_info.att_state_inp.value = att_state[ cur_att ];
		document.reg_info.att_zip_inp.value = att_zip[ cur_att ];
		document.reg_info.att_title_inp.value = att_title[ cur_att ];
		document.reg_info.att_email_inp.value = att_email[ cur_att ];
		document.reg_info.att_phone_inp.value = att_phone[ cur_att ];
		document.reg_info.att_fax_inp.value = att_fax[ cur_att ];
	}
	update_att();
	if( cur_att == 0 )
		document.reg_info.prev_att.disabled = true;
}

function F_next_att()
{
	if( cur_att == 0 )
		document.reg_info.prev_att.disabled = false;
	if( cur_att != ( num_att - 1 ) )
	{
		att_last[ cur_att ] = document.reg_info.att_last_inp.value;
		att_first[ cur_att ] = document.reg_info.att_first_inp.value;
		att_addr[ cur_att ] = document.reg_info.att_addr_inp.value;
		att_city[ cur_att ] = document.reg_info.att_city_inp.value;
		att_state[ cur_att ] = document.reg_info.att_state_inp.value;
		att_zip[ cur_att ] = document.reg_info.att_zip_inp.value;
		att_title[ cur_att ] = document.reg_info.att_title_inp.value;
		att_email[ cur_att ] = document.reg_info.att_email_inp.value;
		att_phone[ cur_att ] = document.reg_info.att_phone_inp.value;
		att_fax[ cur_att ] = document.reg_info.att_fax_inp.value;
		cur_att++;
		document.reg_info.att_last_inp.value = att_last[ cur_att ];
		document.reg_info.att_first_inp.value = att_first[ cur_att ];
		document.reg_info.att_addr_inp.value = att_addr[ cur_att ];
		document.reg_info.att_city_inp.value = att_city[ cur_att ];
		document.reg_info.att_state_inp.value = att_state[ cur_att ];
		document.reg_info.att_zip_inp.value = att_zip[ cur_att ];
		document.reg_info.att_title_inp.value = att_title[ cur_att ];
		document.reg_info.att_email_inp.value = att_email[ cur_att ];
		document.reg_info.att_phone_inp.value = att_phone[ cur_att ];
		document.reg_info.att_fax_inp.value = att_fax[ cur_att ];
	}
	else
	{
		att_last[ cur_att ] = document.reg_info.att_last_inp.value;
		att_first[ cur_att ] = document.reg_info.att_first_inp.value;
		att_addr[ cur_att ] = document.reg_info.att_addr_inp.value;
		att_city[ cur_att ] = document.reg_info.att_city_inp.value;
		att_state[ cur_att ] = document.reg_info.att_state_inp.value;
		att_zip[ cur_att ] = document.reg_info.att_zip_inp.value;
		att_title[ cur_att ] = document.reg_info.att_title_inp.value;
		att_email[ cur_att ] = document.reg_info.att_email_inp.value;
		att_phone[ cur_att ] = document.reg_info.att_phone_inp.value;
		att_fax[ cur_att ] = document.reg_info.att_fax_inp.value;
		cur_att++;
		document.reg_info.att_last_inp.value = "";
		document.reg_info.att_first_inp.value = "";
		document.reg_info.att_addr_inp.value = "";
		document.reg_info.att_city_inp.value = "";
		document.reg_info.att_state_inp.value = "";
		document.reg_info.att_zip_inp.value = "";
		document.reg_info.att_title_inp.value = "";
		document.reg_info.att_email_inp.value = "";
		document.reg_info.att_phone_inp.value = "";
		document.reg_info.att_fax_inp.value = "";
	}
	if( cur_att == num_att )
	{
		document.reg_info.rem_att.disabled = true;
		document.reg_info.next_att.disabled = true;
	}
	update_att();
}

function make_review()
{
//!!@@##	var EB = "Yes";
//!!@@##	var ebd = new Date();
//!!@@##	var buff = EB_date[ document.reg_info.list_class.selectedIndex ].substring(0, EB_date[ document.reg_info.list_class.selectedIndex ].indexOf( "/" ) );
//!!@@##	ebd.setMonth( buff - 1 );
//!!@@##	buff = EB_date[ document.reg_info.list_class.selectedIndex ].substring( EB_date[ document.reg_info.list_class.selectedIndex ].indexOf( "/" ) + 1, EB_date[ document.reg_info.list_class.selectedIndex ].lastIndexOf( "/" ) );
//!!@@##	ebd.setDate( buff );
//!!@@##	buff = EB_date[ document.reg_info.list_class.selectedIndex ].substring( EB_date[ document.reg_info.list_class.selectedIndex ].lastIndexOf( "/" ) + 1 );
//!!@@##	ebd.setYear( buff );
//!!@@##	if( Date() > ebd )
//!!@@##		EB = "No";
	var cp;	var tp;	var pc = 0; var pci; var pciArr = new Array(); pci = -1;
	var cBook;
	pciArr = promo_codes[ document.reg_info.list_class.selectedIndex ].split( "," );
	for( i = 0; i < pciArr.length; i++ )
	{
 		if( pciArr[ i ] == document.reg_info.promo_code.value.toUpperCase() )
			pci = i;
	}
	if( pci != -1 )
	{
		pciArr = promo_price_difference[ document.reg_info.list_class.selectedIndex ].split( "," );
		pc = parseInt( pciArr[ pci ] );
	}

	else
		pc = 0;

	if( num_att > 1 )
	{
//!!@@##		if( EB )
//!!@@##			cp = EB_price_multiple[ document.reg_info.list_class.selectedIndex ] + pc;
//!!@@##		else
			cp = class_price_multiple[ document.reg_info.list_class.selectedIndex ] + pc;
		tp = cp * num_att;
	}
	else
	{
//!!@@##		if( EB )
//!!@@##			cp = EB_price_single[ document.reg_info.list_class.selectedIndex ] + pc;
//!!@@##		else
			cp = class_price_single[ document.reg_info.list_class.selectedIndex ] + pc;
		tp = cp;
	}
	
	if( document.reg_info.colorbook[0].checked )
	{
		cBook = "YES";
		tp += 100;
	}
	else if( document.reg_info.colorbook[1].checked )
	{
		cBook = "NO";
	}

	// \n
	document.getElementById("rev1").innerHTML = class_list[ document.reg_info.list_class.selectedIndex ];
	document.getElementById("rev2").innerHTML = cp.toString();
	document.getElementById("rev9").innerHTML = cBook;
	document.getElementById("rev3").innerHTML = tp.toString();
//!!@@##	document.getElementById("rev4").innerHTML = EB;
	document.getElementById("rev5").innerHTML = document.reg_info.company_name.value;
	document.getElementById("rev6").innerHTML = document.reg_info.promo_code.value.toUpperCase();
	
	document.getElementById("rev7").innerHTML = "";
	document.reg_info.H_att_first.value = "";
	document.reg_info.H_att_last.value = "";
	document.reg_info.H_att_addr.value = "";
	document.reg_info.H_att_city.value = "";
	document.reg_info.H_att_state.value = "";
	document.reg_info.H_att_zip.value = "";
	document.reg_info.H_att_title.value = "";
	document.reg_info.H_att_email.value = "";
	document.reg_info.H_att_phone.value = "";
	document.reg_info.H_att_fax.value = "";
	for( i = 0; i < num_att; i++ )
	{
		document.getElementById("rev7").innerHTML += "Name&nbsp;:&nbsp;" + att_last[ i ] + ",&nbsp;" + att_first[ i ] + "<br>";
		document.getElementById("rev7").innerHTML += "Address&nbsp;:&nbsp;" + att_addr[ i ] + "<br>";
		document.getElementById("rev7").innerHTML += "&nbsp;:&nbsp;" + att_city[ i ] + ",&nbsp;" + att_state[ i ] + ",&nbsp;" + att_zip[ i ] + "<br>";
		document.getElementById("rev7").innerHTML += "Title&nbsp;:&nbsp;" + att_title[ i ] + "<br>";
		document.getElementById("rev7").innerHTML += "Email&nbsp;:&nbsp;" + att_email[ i ] + "<br>";
		document.getElementById("rev7").innerHTML += "Phone&nbsp;:&nbsp;" + att_phone[ i ] + "<br>";
		document.getElementById("rev7").innerHTML += "Fax&nbsp;:&nbsp;" + att_fax[ i ] + "<br><br>";
		document.reg_info.H_att_first.value += att_first[ i ] + ";";
		document.reg_info.H_att_last.value += att_last[ i ] + ";";
		document.reg_info.H_att_addr.value += att_addr[ i ] + ";";
		document.reg_info.H_att_city.value += att_city[ i ] + ";";
		document.reg_info.H_att_state.value += att_state[ i ] + ";";
		document.reg_info.H_att_zip.value += att_zip[ i ] + ";";
		document.reg_info.H_att_title.value += att_title[ i ] + ";";
		document.reg_info.H_att_email.value += att_email[ i ] + ";";
		document.reg_info.H_att_phone.value += att_phone[ i ] + ";";
		document.reg_info.H_att_fax.value += att_fax[ i ] + ";";
	}
	
	if( document.reg_info.BillRadio[0].checked )
	{
		document.getElementById("rev8").innerHTML = "You have selected to call in your credit card information to the Kase Call Center.";
	}
	else
	{
		document.getElementById("rev8").innerHTML = "Credit Card Type&nbsp;:&nbsp;" + document.reg_info.card_type[ document.reg_info.card_type.selectedIndex ].value + "<br>";
		document.getElementById("rev8").innerHTML += "Number&nbsp;:&nbsp;" + document.reg_info.card_num.value + "<br>";
		document.getElementById("rev8").innerHTML += "Expiration Date&nbsp;:&nbsp;" + document.reg_info.card_exp.value + "<br>";
		document.getElementById("rev8").innerHTML += "Name on Card&nbsp;:&nbsp;" + document.reg_info.card_name.value + "<br>";
		document.getElementById("rev8").innerHTML += "Billing Address&nbsp;:&nbsp;<br>";
		document.getElementById("rev8").innerHTML += "&nbsp;&nbsp;&nbsp;" + document.reg_info.card_billing_addr1.value + "<br>";
		document.getElementById("rev8").innerHTML += "&nbsp;&nbsp;&nbsp;" + document.reg_info.card_billing_addr2.value + "<br>";
		document.getElementById("rev8").innerHTML += "&nbsp;&nbsp;&nbsp;" + document.reg_info.card_billing_city.value + ",&nbsp;" + document.reg_info.card_billing_state[ document.reg_info.card_billing_state.selectedIndex ].value + "&nbsp;" + document.reg_info.card_billing_zip.value;
	}
	document.reg_info.H_num_att.value = num_att;
	document.reg_info.H_class.value = class_list[ document.reg_info.list_class.selectedIndex ];
	document.reg_info.H_cprice.value = cp;
	document.reg_info.H_cbook.value = cBook;
	document.reg_info.H_tprice.value = tp;
//!!@@##	document.reg_info.H_EB.value = EB;
}

function form_validate()
{
	var needed = "";
	
	if( !check_bills() )
		needed += "Billing Information ";
		
	if( num_att <= 0 )
	{
		if( needed != "" )
			needed += "and ";
		needed += "at least one Attendee ";
	}
	
	if( document.reg_info.company_name.value == "" )
	{
		if( needed != "" )
			needed += "and ";
		needed += " Company Name ";
	}
		
	if( needed == "" )
		document.reg_info.submit();
	else
		alert( "Please fill in " + needed );
}

