function isChecked ( inThing )
{
    for ( i = 0 ; i < inThing.length ; i++ )
    {
      if ( inThing [ i ].checked == true )
         return true ;
    }
    return false ;
}

function returnCheckedValue ( inThing )
{
    var theOne = "--" ;
    for ( i = 0 ; i < inThing.length ; i++ )
    {
        if ( inThing [ i ].checked == true )
        {
            theOne = inThing [ i ].value ;
            break ;
        }
    }
    return theOne ;
}

function checkForm ()
{
    var errMsg = "" ;
    var theForm = document.forms.emailCapture ;
    var referredItem = theForm.referredFromDropDown.selectedIndex ;
    var referredValue = theForm.referredFromDropDown.options [ referredItem ].value ;
    var initialBalanceItem = theForm.initialBalanceDropDown.selectedIndex ;
    var initialBalanceValue = theForm.initialBalanceDropDown.options [ initialBalanceItem ].value ;
    var initialTypeItem = theForm.productTypeDropDown.selectedIndex ;
    var initialTypeValue = theForm.productTypeDropDown.options [ initialTypeItem ].value ;
    var initialTypeText = theForm.productTypeDropDown.options [ initialTypeItem ].text ;

    if ( isEmpty ( theForm.firstName ) )
    {
        errMsg += "- Enter a value in the 'First Name' input box.\n" ;
    }

    if ( isEmpty ( theForm.lastName ) )
    {
        errMsg += "- Enter a value in the 'Last name' input box.\n" ;
    }

    if ( isEmpty ( theForm.emailAddress ) )
    {
        errMsg += "- Enter a value in the 'Email address' input box.\n" ;
    }
    else if ( ! emailCheck ( theForm.emailAddress.value ) )
    {
        errMsg += "- Enter a value in the 'Email address' input box.\n" ;
    }
    else if ( theForm.emailRetype.value!=theForm.emailAddress.value )
    {
        errMsg += "- The value in the 'Email address' does not match the 'Confirm Your Email' value.\n" ;
    }

    if ( referredValue == "--" )
    {
        errMsg += "- Select a value in the referred drop down.\n" ;
    }

    if ( initialBalanceValue == "X" )
    {
        errMsg += "- Select a value in the opening deposit drop down.\n" ;
    }

    if ( initialTypeValue == "X" )
    {
        errMsg += "- Select a value in the product drop down.\n" ;
    }

    if ( ! isChecked ( theForm.chexSystemsRadio ) )
    {
        errMsg += "- Select whether or not you have a Chex Systems record.\n" ;
    }

    if ( ! isChecked ( theForm.usCitizenRadio ) )
    {
        errMsg += "- Select whether or not you are a United States Citizen.\n" ;
    }

    if ( errMsg != "" ) {
        window.alert("Please correct the following items before proceeding: \n\n"+errMsg);
        return false;
    }

    chexSystemsYN = returnCheckedValue ( theForm.chexSystemsRadio ) ;
    theForm.chexSystems.value = chexSystemsYN ;

    usCitizenYN = returnCheckedValue ( theForm.usCitizenRadio ) ;
    theForm.usCitizen.value = usCitizenYN ;

    theForm.referralLocation.value = referredValue ;
    theForm.initialBalance.value = initialBalanceValue ;
    theForm.productType.value = initialTypeValue ;

    if ( usCitizenYN == "N" )
    {
        return false ;
    }

    if ( chexSystemsYN != "N" )
    {
        return false ;
    }
    
// Google code goes here!
    pageTracker._addTrans (
      "1234",                               // Order ID
      "Open Account",                       // Affiliation
      initialBalanceValue,                  // Total
      "0",                                  // Tax
      "0",                                  // Shipping
      "",                                   // City
      "",                                   // State
      "USA"                                 // Country
    );
		
		pageTracker._addItem (
      "1234",                               // Order ID
      initialTypeValue,                     // SKU
      initialTypeText,               				// Product Name
      "Deposit Account",                    // Category
      initialBalanceValue,                         // Price
      "1"                                   // Quantity
    );
    
    pageTracker._trackTrans();
    
    
    //window.alert(initialBalanceValue );
    //window.alert(initialTypeValue );
    //window.alert(initialTypeText );
    //window.alert(referredValue );
    
    return true ;
}

function intialBalancePop ()
{
    var theForm = document.forms.emailCapture ;
    var initialBalance = theForm.initialBalanceDropDown.selectedIndex ;
    var initialBalanceValue = theForm.initialBalanceDropDown.options [ initialBalance ].value ;

    if ( initialBalanceValue == 1 )
    {
        window.alert ( "Please note there is a $1,000 minimum balance to open a UNITY Gold E-Savings account." ) ;
    }

    return true ;
}

function chexSystemPop ()
{
    window.open ( "/common/include/formCode/ChexSystems.asp","","menubar=no,toolbar=no,status=no,scrollbars=no,resizeable=no,width=400,height=350" ) ;

    return true ;
}

function usCitizenPop ()
{
    window.alert ( "You must be a United States Citizen to open an Online Account with OneUnited Bank." ) ;

    return true ;
}
