/*
This script sets the targets for an email containing the information on the page to the user's department (based on the 
drop-down list), the bursar (if there is an address change), and the user (for verification).  It finds these three 
targets in the first three methods, then combines them into a single string, and finally sets this string as the value 
for the '*recipient' element, which is used by a university script to send an email.
NOTE: The script also contains an unrelated method that sets the radio button list appropriately if the user changes the 
'different from above' textfield.
*/

var primaryRecipient;
var billingRecipient;
var autoRecipient;
var recipientList;

function setPrimaryRecipient()// searches drop-down list for selected dept and sets primary recip to associated address
    {
    for (i = 0; (i <= document.mainForm.ddlDivision.length - 1); i++)
        {
        if (document.mainForm.ddlDivision[i].selected == true)
            primaryRecipient = document.mainForm.ddlDivision[i].value;
        }
    }
    
function setBillingRecipient()// checks for address change.  If it's changing, the billing recip is set to bursar's address.
    {
    var selectedButtonIndex;
    for (i = 0; (i <= document.mainForm.radNewBillingAddress.length -1); i++)
        {
        if (document.mainForm.radNewBillingAddress[i].checked == true)
            selectedButtonIndex = i;
        }
    if (selectedButtonIndex == (document.mainForm.radNewBillingAddress.length - 1))
        billingRecipient = "";// No address change => billing recip is null.  This should be redundant.
    else
        billingRecipient = "bursar@admin.rochester.edu";
    }

function setAutoRecipient()// sets autoRecipient to the user's own email address
    {
    autoRecipient = document.mainForm.Email.value;
    }

function setRecipientList()// combines all recips into one string, recipientList
    {
    setPrimaryRecipient();
    setBillingRecipient();
//  setAutoRecipient();   //*cc_visitor = 1 handles this inside the script.  -Toby Teel
    recipientList = primaryRecipient + ", " + autoRecipient;
	if ( billingRecipient != "" )// adds billing recip only if it's not null.
	    recipientList = recipientList + ", " + billingRecipient;
    }
    
function setTarget()// replaces value of the selected "*recipient" element option to the combined recipient string, recipientList
    {
    var selectedOptionIndex;
    for (i = 0; (i <= document.mainForm.ddlDivision.length - 1); i++)
        {
        if (document.mainForm.ddlDivision[i].selected == true)
            selectedOptionIndex = i;
        }
    setRecipientList();
    document.mainForm.ddlDivision[selectedOptionIndex].value = recipientList;
    }

function setRadToNewBilling()// nothing to do with setting target.  Sets Rad to 'different from above' choice if assoc textfield is changed.
    {
    document.mainForm.radNewBillingAddress[3].checked = true;
    }
