/**
* Generic functions for use throughout the app
*/
// Swaps the US Statepicker with a <input type="text"> when 
// country != "" and country != "US"
// When country == "US", text is hidden, and statepicker is shown
//  @state_fld      = ID of statepicker field
//  @province_fld   = ID of province text field
//  @country        = the selected country
function statepickerToInput( state_fld, province_fld,  country )
{
	// statepicker = SELECT
	var states		= document.getElementById( state_fld );
	// province_field = text field
	var province	= document.getElementById( province_fld );
	// Both have a NAME of state so the server can grab the correct value

	// don't work with ""
	if( country.split(' ').join('') != "" )
	{
	    if (country.toLowerCase() == "us" || country.toLowerCase() == "usa" )
		{
			// show SELECT
			states.style.visibility = "visible";
			// set inline so state appears in same spot
			states.style.display	= "inline";

			// hide INPUT
			province.style.visibility = "hidden";
		}
		else
		{
			// We have international
			
			// hide SELECT
			states.style.visibility = "hidden";

			// show INPUT
			province.style.visibility = "visible";
			// set inline so state appears in same spot
			province.style.display	= "inline";
		}
	}
}





/*
This function does the same thing as statepickerToInput
only it works with a State picker and a county picker

It was built specifically for OHIO.
If Ohio is chosen, show the Ohio county list menu
Else show a text box for county

@menu_fld = id of SELECT to show

@txt_fld = id of TEXT field to show

@state = selected value to key off of

*/
function ifOhioShowCounties( menu_fld, txt_fld, state ) 
{
    // statepicker = SELECT
    var dropdown = document.getElementById( menu_fld );
    // county_field = text field
    var textbox = document.getElementById(txt_fld);
    // Both have a NAME of state so the server can grab the correct value

    // don't work with ""
    if ( state.split(' ').join('') != "") 
    {
        if ( state.toLowerCase() == "oh" || state.toLowerCase() == "ohio") 
        {
            // show SELECT
            dropdown.style.visibility = "visible";
            // set inline so state appears in same spot
            dropdown.style.display = "inline";

                    // hide INPUT
            textbox.style.visibility = "hidden";
        }
        else 
        {
            // hide SELECT
            dropdown.style.visibility = "hidden";

            // show INPUT
            textbox.style.visibility = "visible";
            // set inline so state appears in same spot
            textbox.style.display = "inline";
        }
    }
    
}





// Pass in id of text field that holds the zipcode
function toggleTextfield( field_id )
{
// the text field
var txt = document.getElementById( field_id );
	
	txt.disabled = ! txt.disabled;
}






/**
* Create a custom shareThis <a> for the btn-holder section.
* The class="share" attaches the bgImage
*/
function makeSharethisBtnHolder()
{
    // grab page title, or use default
    var sTitle = "Website from ChancellorU.edu";
    if( document.title != "" )
    {
        sTitle = document.title;
    }

    // create unique id to avoid JS cache issues
    var btn_id = new Date().getTime();

    //Output your customized button
    document.write('<a id="'+ btn_id  +'" href="javascript:void(0);" class="share"></a>');

    //Tie customized button to ShareThis button functionality.
    var element = document.getElementById( btn_id );

    // Some pages won't use sharethis, but still use this file so be sure
    if( SHARETHIS )
    {
        // No button, custom position
        var object = SHARETHIS.addEntry(	{title: sTitle }, 
										    {	button:false, 
											    offsetLeft:'115',
											    offsetTop:'-410' } );
        // hook it up
        object.attachButton(element);
    }
}

/**
* Create a custom <a>Share with Friends</a> hyperlink
*/
function makeSharethisLink()
{
    // grab page title, or use default
    var sTitle = "Website from ChancellorU.edu";
    if( document.title != "" )
    {
        sTitle = document.title;
    }

    // create unique id to avoid JS cache issues
    var btn_id = new Date().getTime();

    //Output your customized button
    document.write('<a id="'+ btn_id  +'" href="javascript:void(0);">Share With Friends</a>');

    //Tie customized button to ShareThis button functionality.
    var element = document.getElementById( btn_id );

    // Some pages won't use sharethis, but still use this file so be sure
    if( SHARETHIS )
    {
        // No button, custom position
        var object = SHARETHIS.addEntry(	{title: sTitle }, 
										    {	button:false, 
											    offsetLeft:'-380',
											    offsetTop:'-125' } );

        object.attachButton(element);
    }
}



/**
* Google SiteSearch form handler
* see : http://blog.binarybooyah.com/blog/post/Using-Google-Site-Search-on-ASPNET-pages.aspx
*/
function GoogleSearch(q) 
{
    // trim and make sure it's not blank
    var val = q.split(" ").join("");
    // don't search for blank
    if( val != "" )
    {
        // don't use val since it removes all spaces
        window.location =   "http://www.google.com/cse" +
                            "?q=" + q +
                            "&domains=chancelloru.edu" +
                            "&sitesearch=chancelloru.edu" +
                            "&cx=011512762114259224633:yehpx8zjply" +
                            "&ie=UTF-8";
    }
}


/**
* Helper function to get a reference to a menu, clear it, then return it 
* to the caller
*/
function getAndResetMenu( childId )
{
    var menu = document.getElementById( childId );
	// reset the contents of specified select box
	menu.options.length = 0;
	// send the menu back
	return menu;
}


/**
* Change handler for Chancellor location change handler.
* This will populate the degree program dropdown
*
* @parent_val = selectedValue
* @child_id   = id of child dropdown to populate with options
*/
function fillLocationOptionsOne( parent_value, child_id )
{
	var c_menu = getAndResetMenu( child_id );

    var blankLabel = "";    //" -- Please select a Location -- ";

	switch( parent_value )
	{
	    // default no selection
        case "":
            c_menu.options[c_menu.length] = new Option( blankLabel, "", true, true );
        break;

        // UPDATE : all programs in both us and world form, but NOT in JWMI
        default:
            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
            // degrees
            c_menu.options[c_menu.length] = new Option("CERTIFICATES", "", false, false);
            c_menu.options[c_menu.length] = new Option("Accounting - Law", "UNDER-CERT-ACTGLA", false, false);
            c_menu.options[c_menu.length] = new Option("Corporate Management", "UNDER-CERT-CORPMG", false, false);
            c_menu.options[c_menu.length] = new Option("Criminal Justice", "UNDER-CERT-CJ", false, false);
            c_menu.options[c_menu.length] = new Option("Health Services Management", "UNDER-CERT-HS", false, false);
            c_menu.options[c_menu.length] = new Option("Human Resource Management", "UNDER-CERT-HR", false, false);
            c_menu.options[c_menu.length] = new Option("Management Information Systems", "UNDER-CERT-MIS", false, false);
            c_menu.options[c_menu.length] = new Option("Marketing", "UNDER-CERT-MK", false, false);
            c_menu.options[c_menu.length] = new Option("Paralegal Education (Ground Only)", "UNDER-CERT-PA", false, false);
            c_menu.options[c_menu.length] = new Option("Professional Accounting", "UNDER-CERT-PRACTG", false, false);
            c_menu.options[c_menu.length] = new Option("Public Administration", "UNDER-CERT-PU", false, false);
            c_menu.options[c_menu.length] = new Option("Small Business Entrepreneurship", "UNDER-CERT-SBE", false, false);

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);

            c_menu.options[c_menu.length] = new Option("ASSOCIATE OF ARTS (AA)", "", false, false);
            c_menu.options[c_menu.length] = new Option("Associate of Arts", "UNDER-AA-AA", false, false);
			
			// add blank
			c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
            
			c_menu.options[c_menu.length] = new Option("ASSOCIATE OF APPLIED BUSINESS (AAB)", "", false, false);
			c_menu.options[c_menu.length] = new Option("Accounting", "UNDER-AAB-AC", false, false);
			c_menu.options[c_menu.length] = new Option("Corporate Management ", "UNDER-AAB-CORPMG", false, false);
            
			// add blank
			c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
			
			c_menu.options[c_menu.length] = new Option("ASSOCIATE OF APPLIED SCIENCE (AAS)", "", false, false);
			c_menu.options[c_menu.length] = new Option("Criminal Justice", "UNDER-AAS-CJ", false, false);
            c_menu.options[c_menu.length] = new Option("Paralegal Education (Ground Only)", "UNDER-AAS-PA", false, false);
            c_menu.options[c_menu.length] = new Option("Public Administration", "UNDER-AAS-PU", false, false);

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);

            c_menu.options[c_menu.length] = new Option("BSBA SPECIALIZATIONS", "", false, false);
            c_menu.options[c_menu.length] = new Option("Accounting", "UNDER-BSBA-AC", false, false);
            c_menu.options[c_menu.length] = new Option("Corporate Management", "UNDER-BSBA-CORPMG", false, false);
            c_menu.options[c_menu.length] = new Option("Finance", "UNDER-BSBA-FINANC", false, false);
            c_menu.options[c_menu.length] = new Option("Forensic Accounting", "UNDER-BSBA-FORACT", false, false);
            c_menu.options[c_menu.length] = new Option("Human Resource Management", "UNDER-BSBA-HR", false, false);
            c_menu.options[c_menu.length] = new Option("Management Information Systems", "UNDER-BSBA-MIS", false, false);
            c_menu.options[c_menu.length] = new Option("Marketing", "UNDER-BSBA-MK", false, false);
            c_menu.options[c_menu.length] = new Option("Small Business Entrepreneurship", "UNDER-BSBA-SBE", false, false);

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);

            c_menu.options[c_menu.length] = new Option("BACHELOR OF SCIENCE (BS)", "", false, false);
            c_menu.options[c_menu.length] = new Option("Criminal Justice", "UNDER-BS-CJ", false, false);
            c_menu.options[c_menu.length] = new Option("Health Services Management", "UNDER-BS-HS", false, false);
            c_menu.options[c_menu.length] = new Option("Information Technology ", "UNDER-BS-IT", false, false);
            c_menu.options[c_menu.length] = new Option("Paralegal Education (Ground Only)", "UNDER-BS-PA", false, false);
            c_menu.options[c_menu.length] = new Option("Public Administration", "UNDER-BS-PU", false, false);

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
            c_menu.options[c_menu.length] = new Option("Undergraduate Undecided", "Under-Und-Un", false, false);
            break;

        case "all":
            // adds FULL list including JWMI

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
            // degrees
            c_menu.options[c_menu.length] = new Option("CERTIFICATES", "", false, false);
            c_menu.options[c_menu.length] = new Option("Accounting - Law", "UNDER-CERT-ACTGLA", false, false);
            c_menu.options[c_menu.length] = new Option("Corporate Management", "UNDER-CERT-CORPMG", false, false);
            c_menu.options[c_menu.length] = new Option("Criminal Justice", "UNDER-CERT-CJ", false, false);
            c_menu.options[c_menu.length] = new Option("Health Services Management", "UNDER-CERT-HS", false, false);
            c_menu.options[c_menu.length] = new Option("Human Resource Management", "UNDER-CERT-HR", false, false);
            c_menu.options[c_menu.length] = new Option("Management Information Systems", "UNDER-CERT-MIS", false, false);
            c_menu.options[c_menu.length] = new Option("Marketing", "UNDER-CERT-MK", false, false);
            c_menu.options[c_menu.length] = new Option("Paralegal Education (Ground Only)", "UNDER-CERT-PA", false, false);
            c_menu.options[c_menu.length] = new Option("Professional Accounting", "UNDER-CERT-PRACTG", false, false);
            c_menu.options[c_menu.length] = new Option("Public Administration", "UNDER-CERT-PU", false, false);
            c_menu.options[c_menu.length] = new Option("Small Business Entrepreneurship", "UNDER-CERT-SBE", false, false);

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);

            c_menu.options[c_menu.length] = new Option("ASSOCIATE OF ARTS (AA)", "", false, false);
            c_menu.options[c_menu.length] = new Option("Associate of Arts", "UNDER-AA-AA", false, false);
			
			// add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
			
			c_menu.options[c_menu.length] = new Option("ASSOCIATE OF APPLIED BUSINESS (AAB)", "", false, false);
			c_menu.options[c_menu.length] = new Option("Accounting", "UNDER-AAB-AC", false, false);
            c_menu.options[c_menu.length] = new Option("Corporate Management ", "UNDER-AAB-CORPMG", false, false);
            
			// add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
			
			c_menu.options[c_menu.length] = new Option("ASSOCIATE OF APPLIED SCIENCE (AAS)", "", false, false);
			c_menu.options[c_menu.length] = new Option("Criminal Justice", "UNDER-AAS-CJ", false, false);
            c_menu.options[c_menu.length] = new Option("Paralegal Education", "UNDER-AAS-PA", false, false);
            c_menu.options[c_menu.length] = new Option("Public Administration", "UNDER-AAS-PU", false, false);

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);

            c_menu.options[c_menu.length] = new Option("BSBA SPECIALIZATIONS", "", false, false);
            c_menu.options[c_menu.length] = new Option("Accounting", "UNDER-BSBA-AC", false, false);
            c_menu.options[c_menu.length] = new Option("Corporate Management", "UNDER-BSBA-CORPMG", false, false);
            c_menu.options[c_menu.length] = new Option("Finance", "UNDER-BSBA-FINANC", false, false);
            c_menu.options[c_menu.length] = new Option("Forensic Accounting", "UNDER-BSBA-FORACT", false, false);
            c_menu.options[c_menu.length] = new Option("Human Resource Management", "UNDER-BSBA-HR", false, false);
            c_menu.options[c_menu.length] = new Option("Management Information Systems", "UNDER-BSBA-MIS", false, false);
            c_menu.options[c_menu.length] = new Option("Marketing", "UNDER-BSBA-MK", false, false);
            c_menu.options[c_menu.length] = new Option("Small Business Entrepreneurship", "UNDER-BSBA-SBE", false, false);

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);


            c_menu.options[c_menu.length] = new Option("BACHELOR OF SCIENCE (BS)", "", false, false);
            c_menu.options[c_menu.length] = new Option("Criminal Justice", "UNDER-BS-CJ", false, false);
            c_menu.options[c_menu.length] = new Option("Health Services Management", "UNDER-BS-HS", false, false);
            c_menu.options[c_menu.length] = new Option("Information Technology ", "UNDER-BS-IT", false, false);
            c_menu.options[c_menu.length] = new Option("Paralegal Education (Ground Only)", "UNDER-BS-PA", false, false);
            c_menu.options[c_menu.length] = new Option("Public Administration", "UNDER-BS-PU", false, false);

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);

            c_menu.options[c_menu.length] = new Option("GRADUATE DEGREES", "", false, false);
            c_menu.options[c_menu.length] = new Option("Master of Business Administration", "GRAD-Master-BA", false, false);
            c_menu.options[c_menu.length] = new Option("Master of Management", "GRAD-Master-MG", false, false);

            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
            c_menu.options[c_menu.length] = new Option("Graduate Undecided", "Grad-Und-Un", false, false);
            c_menu.options[c_menu.length] = new Option("Undergraduate Undecided", "Under-Und-Un", false, false);
        break;
	}
	
	// make sure first place is selected
    c_menu.selectedIndex     = 0;
}


/*
Helper function to select a text value in a <select>
If the value doesn't exist, selectedIndex = 0
*/
function selectedValue(menu_id, value) 
{
    // get menu
    var c_menu = document.getElementById(menu_id);

    if( c_menu )
    {
    
        var option_ct = c_menu.options.length;
        // marker used to let us know if we found value
        var found_val = false;

        for (var xx = 0; xx <= option_ct - 1; xx++) 
        {
            if (value == c_menu.options[xx].text.toLowerCase())
            {
                found_val = true;
                c_menu.selectedIndex = xx;
            }
            
            // get out of loop if we already found value
            if( found_val ) break;
        }
        
        // did we find the val?
        if( ! found_val )
        {
            // NO
            c_menu.selectedIndex = 0;
        }
    }
    else
    {
        alert("Invalid menu id : " + menu_id );
    }
}

/**
 This is another linked list handler just like fillLocationOptionsOne.
 This handles the linkage between degree and sessions
 
 NOTE : the parent value coming in will need to be parsed since it's
 made up of program-degree-curriculum.
 
 This assumes that parent_value comes in with the hyphenated format.
 If that changes, this function will need to be updated
*/
function fillSessionMenu(parent_value, child_id) 
{


    //UPDATED 2/21 - ignore this now, just present a list of months
    return;
    
    
    /*
    var c_menu = getAndResetMenu(child_id);

    var blankLabel = "";    //" -- Please select a Location -- ";

    // parse out parent_value since it's in the format of program-degree-curriculum
    var prog = parent_value.split("-")[0].toLowerCase();

    switch ( prog ) 
    {
        // default no selection 
        case "":
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
        break;

        case "grad":
            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
            // data
            c_menu.options[c_menu.length] = new Option("Term 1", "GRAD1", false, false);
            c_menu.options[c_menu.length] = new Option("Term 2", "GRAD2", false, false);
            c_menu.options[c_menu.length] = new Option("Term A", "GRADA", false, false);
        break;

        default:
            // add blank
            c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
            // data
            c_menu.options[c_menu.length] = new Option("Term 1", "TERM1", false, false);
            c_menu.options[c_menu.length] = new Option("Term 2", "TERM2", false, false);
            c_menu.options[c_menu.length] = new Option("Term A", "TERMA", false, false);
            c_menu.options[c_menu.length] = new Option("Traditional", "TRAD", false, false);
        break;
    }

    // make sure first place is selected
    c_menu.selectedIndex = 0;
    */
}


// ----------------------------------------------------------------------------
// JWMI SPECIFIC DEGREE SELECT HANDLERS
// ----------------------------------------------------------------------------


/**
* Change handler for Chancellor location change handler.
* This will populate the degree program dropdown
*
* @parent_val = selectedValue
* @child_id   = id of child dropdown to populate with options
*/
function JWMIfillLocationOptionsOne(parent_value, child_id) {

    var c_menu = getAndResetMenu(child_id);

    var blankLabel = "";    //" -- Please select a Location -- ";

    // add blank
    c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);

    c_menu.options[c_menu.length] = new Option("GRADUATE DEGREES", "", false, false);
    c_menu.options[c_menu.length] = new Option("Master of Business Administration (MBA)", "GRAD-Master-BA", false, false);
    c_menu.options[c_menu.length] = new Option("Master of Management (MMG)", "GRAD-Master-MG", false, false);
    c_menu.options[c_menu.length] = new Option(blankLabel, "", false, false);
    c_menu.options[c_menu.length] = new Option("Graduate Undecided", "Grad-Und-Un", false, false);

    // make sure first place is selected
    c_menu.selectedIndex = 0;
}



// ----------------------------------------------------------------------------
// Field validators
// ----------------------------------------------------------------------------

/**
* Confirm Email and required field checker
*/
function checkForm(email1, email2, aIds, aNames) {
    if (compareTwoFields(email1, email2)) {
        return checkRequiredFields(aIds, aNames);
    }
    else {
        alert("Email Address fields do not match.  Please confirm email address and submit again.");
        return false;
    }
}


/**
* Pass in an array of field ids, and this
* will loop through and verify each required field
* contains a value.
* If any of your fields do not get checked, verify
* that field has id="" set to the value in fld_ids
*/
function checkRequiredFields(fld_ids, fld_names) {
    var msg = "The following required fields are empty : \n";
    var good = true; // is form good to submit?
    var first_field = "";   // first empty required field which will get .setFocus

    for (xx = 0; xx <= fld_ids.length - 1; xx++) {
        var fld = document.getElementById(fld_ids[xx]);

        //check for bad fields
        if (fld == null) {
            alert("The field '" + fld_names[xx] + "' doesn't have it's ID (" + fld_ids[xx] + ") set properly");
            good = false;
            xx = fld_ids.length - 1; //force loop break
            break;
        }

        //remove spaces ( not trim )
        field_value = fld.value.split(" ").join("");

        // type specific field checking
        switch (fld.type) {
            // check .checked, not .value 
            case "checkbox":
                if (fld.checked)
                    field_value = "good";
                else
                    field_value = "";
                break;
        }

        // TODO : consider setting bgColor as well since <SELECT>s do not 
        // support CSS borders

        // other fields
        if (field_value == "") {
            msg += " - " + fld_names[xx] + "\n";
            good = false;
            fld.style.border = "1px solid red";

            // track first empty field for setfocus
            if (first_field == "") {
                first_field = fld;
            }

        }
        else {
            fld.style.border = "";
        }
    }

    msg += "Please fill out these fields before submitting the form.";

    if (!good) {
        // show required field msg
        alert(msg);
        // set focus to first empty field
        if (first_field) first_field.focus();
    }

    //if the code makes it here, the form is good
    return good;
}

/**
* Pass in the id of two fields, and this will tell
* you if their values match or not
*/
function compareTwoFields(fld1, fld2) {
    var f1 = document.getElementById(fld1);
    var f2 = document.getElementById(fld2);

    //remove spaces
    pswd1 = f1.value.split(" ").join("");
    pswd2 = f2.value.split(" ").join("");

    if (pswd1 != pswd2) {
        // focus on first field
        f1.focus();

        return false;
    }
    else {
        return true;
    }
}


// required field and email validator function for Application forms
function validateForm(aIds, aNames, email_id) 
{
    // check required fields
    if (checkRequiredFields(aIds, aNames)) {
        // check email format
        return verifyEmail(email_id);
    }
    else {
        return false;
    }
}


// EA FORM VALIDATION

// compare initial fields
function verifyInitials() 
{
    // INITIALS
    var init1 = document.getElementById("ack_1").value;
    var init2 = document.getElementById("ack_2").value;
    var init3 = document.getElementById("ack_3").value;
    // clean up initials
    init1 = lowerRemoveSpace(init1);
    init2 = lowerRemoveSpace(init2);
    init3 = lowerRemoveSpace(init3);

    //if(init1 == init2 == init3)
    if ( (init1 == init2) && ( init2 == init3) )
    {

        setBorder("ack_1", false);
        setBorder("ack_2", false);
        setBorder("ack_3", false);
        // GOOD
        return true;
    }
    else 
    {
        setBorder("ack_1", true);
        setBorder("ack_2", true);
        setBorder("ack_3", true);
        // BAD
        return false;
    }
}

// compares full name with 'signed by' field
function verifySignedBy() 
{
    // FULL NAME
    var first_name  = document.getElementById("first_name").value;
    var last_name   = document.getElementById("last_name").value;
    var signed_by   = document.getElementById("signed_by").value;
    
    var full_name   = lowerRemoveSpace(first_name + last_name);
    signed_by       = lowerRemoveSpace(signed_by);

    // compare value and set field borders appropriately
    if (full_name == signed_by) 
    {

        setBorder("first_name", false);
        setBorder("last_name", false);
        setBorder("signed_by", false);
        // GOOD
        return true;
    }
    else 
    {
        setBorder("first_name", true);
        setBorder("last_name", true);
        setBorder("signed_by", true);
        // BAD
        return false;
    }
}

// compares the values of ssn_student_id and ssn_student_id_ack
function verifySSN() 
{
    // SSN
    var ssn1 = document.getElementById("ssn_student_id").value;
    var ssn2 = document.getElementById("ssn_student_id_ack").value;
    // clean up values
    ssn1 = lowerRemoveSpace(ssn1);
    ssn2 = lowerRemoveSpace(ssn2);

    if (ssn1 == ssn2)
    {

        setBorder("ssn_student_id", false);
        setBorder("ssn_student_id_ack", false);
        // GOOD
        return true;
    }
    else 
    {
        setBorder("ssn_student_id", true);
        setBorder("ssn_student_id_ack", true);
        // BAD
        return false;
    }
}

// compares dob of birth fields with DOB fields at bottom of form
function verifyDOB()
{
    // DOB ( mo - day - yr )
    var dob_mo1 = document.getElementById("dob_mo").value;
    var dob_mo2 = document.getElementById("dob_mo_ack").value;
    var dob_day1 = document.getElementById("dob_day").value;
    var dob_day2 = document.getElementById("dob_day_ack").value;
    var dob_yr1 = document.getElementById("dob_yr").value;
    var dob_yr2 = document.getElementById("dob_yr_ack").value;
    
    if( (dob_mo1 == dob_mo2) && ( dob_day1 == dob_day2) && ( dob_yr1 == dob_yr2) )
    {
        setBorder("dob_mo", false);
        setBorder("dob_mo_ack", false);
        setBorder("dob_day", false);
        setBorder("dob_day_ack", false);
        setBorder("dob_yr", false);
        setBorder("dob_yr_ack", false);
        // GOOD
        return true;
    }
    else 
    {
        setBorder("dob_mo", true);
        setBorder("dob_mo_ack", true);
        setBorder("dob_day", true);
        setBorder("dob_day_ack", true);
        setBorder("dob_yr", true);
        setBorder("dob_yr_ack", true);
        // BAD
        return false;
    }
}

// confirm identity fields match
// NOTE : this is used by the Enrollment Agreement forms ( us and world )
function verifySignatureFields()
{
    // full name
    if (!verifySignedBy()) 
    {
        alert("Please verify you entered the same first and last name at the top of the form as well as in " +
                "the 'Signed By' field before submitting this form");
        return false;
    }

    // INITIALS
    if (!verifyInitials()) 
    {
        alert("Initial fields do not match.  Please type the correct initials in each initial field before" +
                " submitting this form");
        return false;
    }
    
    // SSN
    if (!verifySSN()) {
        alert("Please confirm you have entered the same Social Security Number or " +
              "Country Identification Number" );
        return false;
    }

    // DOB
    if (!verifyDOB()) 
    {
        alert("Please verify your Date Of Birth at the top of the form as well as in " +
                "the Date Of Birth at the end of rthis form before submitting");
        return false;
    }

    return true;
}

// helper function that lowerCases, and removes all spaces from a string
function lowerRemoveSpace(msg) 
{
    return msg.toLowerCase().split(' ').join('');
}

// verify the value in a field is at least as long as the specified len
// fid = id of html field to validate
// len = length to verify against
function validateFieldValueLen(fId, len)
{
    var fld_value = document.getElementById(fId).value;
    // don't count spaces in value length
    fld_value = lowerRemoveSpace(fld_value);

    return fld_value.length >= len;
}

/*
Use this when you want to enforce letters only in a text input box

fId     = ID of input box
fName   = Name you want to show
*/
function verifyLettersOnly( fId, fName )
{
    var fld = document.getElementById( fId );
    var str = fld.value;

    // matches "all letters" OR "all letters"SPACE"all letters"
    // 2nd regern to support "Full Name"
    var reg = RegExp("^[a-zA-Z||a-zA-Z a-zA-Z]+$");

    if ( reg.test(str)) 
    {
        setBorder(fId, false);
        return true;
    }
    else 
    {
        setBorder(fId, true);
        fld.focus();
        alert("The field '" + fName + "' should only have letters in it");
        return false;
    }
}


/*
Use this when you want to enforce numbers only in a text input box

fId     = ID of input box
fName   = Name you want to show
*/
function verifyNumbersOnly(fId, fName) 
{
    var fld = document.getElementById(fId);
    var str = fld.value;

    // make sure field isn't blank
    if ("" != fld.value) 
    {
        // letters only regern
        var reg = RegExp("^[0-9||0-9 0-9]+$");

        if (reg.test(str)) {
            setBorder(fId, false);
            return true;
        }
        else {
            setBorder(fId, true);
            fld.focus();
            alert("The field '" + fName + "' should only have numbers in it");
            return false;
        }
    }

    return true;
}

// Use RegExp to confirm a valid formatted email
function verifyEmail(email_id) {
    var email_fld = document.getElementById(email_id);
    var str = email_fld.value;

    // verify email RegExp
    var reg = new RegExp("\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");

    if (reg.test(str) == true) 
    {
        setBorder(email_id, false);
        return true;
    }
    else 
    {
        setBorder(email_id, true);
        email_fld.focus();

        alert("The email entered does not appear to be correct. Please verify and submit again.");
        return false;
    }

}

/*
    Check field formats
    
    Pass in a collection of field definition objects ( { id, name, format } ),
    and this will check each field and alert you if the text inside
    that field is invalid.
    
    Sample field definition collection :
    
    var field_objs = [
        { id: "city", name: "City", format: "letters" },
        { id: "email", name: "Email", format: "email" },
        { id: "num", name: "Id Number", format: "numbers" }
    ];
    
    Supported formats : email, letters, numbers
*/
function checkFieldFormat( field_objs )
{
    if (field_objs) 
    {
        var field_ct = field_objs.length;

        for (xx = 0; xx <= field_ct - 1; xx++) 
        {
            var fld = field_objs[xx];
            // which format?
            switch (fld.format) 
            {
                case "email":
                    // if bad, get out of here
                    if (!verifyEmail(fld.id)) 
                    {
                        return false;
                    }
                break;

                case "letters":
                    // if bad, get out of here
                    if (!verifyLettersOnly(fld.id, fld.name)) 
                    {
                        return false;
                    }
                break;


                case "numbers":
                    // if bad, get out of here
                    if (!verifyNumbersOnly(fld.id, fld.name)) 
                    {
                        return false;
                    }
                break;
            }
            
        }
    }

    // if you make it here, all is good
    return true;
}

// helper to set the border of a field to red or ""
// isBad = true > red border
// isBad = false > "" border
function setBorder(id, isBad) 
{
    var fld = document.getElementById(id);
    if (fld) 
    {
        if (isBad) 
            fld.style.border = "1px solid red";
        else
            fld.style.border = "";
    }
}