//*
//* form-validation.js
//*
//* Various functoins for performing form validation 
//*

//*
//* checkInput
//*
//* Check the input as it is being typed to see if its allowed
//* or now.
//*
//* sAllowedCharacters: A concatenation of the character types allowed
//*     A = A-Z or a-z
//*     1 = 0-9
//*     Other characters are not allowed unless they are specified individually.
//*     < > = + " ! @ # $ % ^ & * ( ) ? / - _ ~ ` '
//* bDisplayMessage: A boolean value. If true an alert will be sent telling the user that the character is invalid
//*         
function checkInput(evt, sAllowedCharacters, bDisplayMessage)
{
    //var charCode = (evt.which) ? evt.which : event.keyCode
    var iLength = 0;
    var i = 0;
    
    var myKeyCode = 0;
    var myShiftKey = false;
    var sMessage = "";
    var sInvalidCharacter = "";
    
    // Internet Explorer 4+
    if ( document.all ) {
        myKeyCode = evt.keyCode;
        myShiftKey = evt.shiftKey;
    
    // Netscape 4
    } else if ( document.layers ) {
        myKeyCode = evt.which;
        myShiftKey=( myKeyCode == 16 ) ? true : false;
    
    // Netscape 6
    } else if ( document.getElementById ) {
        myKeyCode = evt.which;
        myShiftKey=( myKeyCode == 16 ) ? true : false;
    }
    
    
    iLength = sAllowedCharacters.length;
    
    //* Now check the keycodes
    //* A - Z, a-z
    if ( (myKeyCode >= 65 && myKeyCode <= 90) ||    //* Uppercase
         (myKeyCode >= 97 && myKeyCode <= 122) )    //* Lowercase
    {
        //* search the allowedcharacters for an "A"
        if (sAllowedCharacters.indexOf("A") >= 0)
        {
            //* It's in the list
            return true;
            }
    
    }
    //* 0-9
    else if (myKeyCode >= 48 && myKeyCode <= 57)
    {
        //* search the allowedcharacters for an "1"
        if (sAllowedCharacters.indexOf("1") >= 0)
        {
            //* It's in the list
            return true;
            }
    
    }
    //* Check the individual characters
    //* < > = + " ! @ # $ % ^ & * ( ) ? / - _ ~ ` ' .
    else if (myKeyCode == 60)
    {
        //* search the allowedcharacters for an "<"
        if (sAllowedCharacters.indexOf("<") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "<";
    
    }
    else if (myKeyCode == 46)
    {
        //* search the allowedcharacters for an "."
        if (sAllowedCharacters.indexOf("A") >= 0 || sAllowedCharacters.indexOf(".") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = ".";
    
    }
    else if (myKeyCode == 62)
    {
        //* search the allowedcharacters for an ">"
        if (sAllowedCharacters.indexOf(">") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = ">";
    }
    else if (myKeyCode == 61) //* =
    {
        //* search the allowedcharacters for an "="
        if (sAllowedCharacters.indexOf("=") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "=";
    }
    else if (myKeyCode == 43) //* +
    {
        //* search the allowedcharacters for an "+"
        if (sAllowedCharacters.indexOf("+") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "+";
    }
    else if (myKeyCode == 34) //* "
    {
        //* search the allowedcharacters for an "
        if (sAllowedCharacters.indexOf("\"") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "\"";
    }
    else if (myKeyCode == 33) //* !
    {
        //* search the allowedcharacters for an "!"
        if (sAllowedCharacters.indexOf("!") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "!";
    }
    else if (myKeyCode == 64) //* @
    {
        //* search the allowedcharacters for an "@"
        if (sAllowedCharacters.indexOf("@") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "@";
    }
    else if (myKeyCode == 35) //* #
    {
        //* search the allowedcharacters for an "#"
        if (sAllowedCharacters.indexOf("#") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "#";
    }
    else if (myKeyCode == 36) //* $
    {
        //* search the allowedcharacters for an "$"
        if (sAllowedCharacters.indexOf("$") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "$";
    }
    else if (myKeyCode == 37) //* %
    {
        //* search the allowedcharacters for an "%"
        if (sAllowedCharacters.indexOf("%") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "%";
    }
    else if (myKeyCode == 94) //* ^
    {
        //* search the allowedcharacters for an "^"
        if (sAllowedCharacters.indexOf("^") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "^";
    }
    else if (myKeyCode == 38) //* &
    {
        //* search the allowedcharacters for an "&"
        if (sAllowedCharacters.indexOf("&") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "&";
    }
    else if (myKeyCode == 42) //* *
    {
        //* search the allowedcharacters for an "*"
        if (sAllowedCharacters.indexOf("*") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "*";
    }
    else if (myKeyCode == 40) //* (
    {
        //* search the allowedcharacters for an "("
        if (sAllowedCharacters.indexOf("(") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "(";
    }
    else if (myKeyCode == 41) //* )
    {
        //* search the allowedcharacters for an ")"
        if (sAllowedCharacters.indexOf(")") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = ")";
    }
    else if (myKeyCode == 63) //* ?
    {
        //* search the allowedcharacters for an "?"
        if (sAllowedCharacters.indexOf("?") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "?";
    }
    else if (myKeyCode == 47) //* /
    {
        //* search the allowedcharacters for an "/"
        if (sAllowedCharacters.indexOf("/") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "/";
    }
    else if (myKeyCode == 45) //* -
    {
        //* search the allowedcharacters for an "-"
        if (sAllowedCharacters.indexOf("-") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "-";
    }
    else if (myKeyCode == 95) //* _
    {
        //* search the allowedcharacters for an "_"
        if (sAllowedCharacters.indexOf("_") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "_";
    }
    else if (myKeyCode == 126) //* ~
    {
        //* search the allowedcharacters for an "~"
        if (sAllowedCharacters.indexOf("~") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "~";
    }
    else if (myKeyCode == 96) //* `
    {
        //* search the allowedcharacters for an "`"
        if (sAllowedCharacters.indexOf("`") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "`";
    }
    else if (myKeyCode == 39) //* '
    {
        //* search the allowedcharacters for an "'"
        if (sAllowedCharacters.indexOf("'") >= 0)
        {
            //* It's in the list
            return true;
            }
            
            sInvalidCharacter = "'";
    }
    else
    {
        //* We have hit a keycode that we aren't specifically looking for
        //* Go ahead and allow it through
        return true;
    
    }
    
    //* check to see if we want to display a message
    if (bDisplayMessage)
    {
        sMessage = "Character '" + sInvalidCharacter + "' is not allowed.";
        alert(sMessage);
    }
    
    return false;
}

//*
//* checkCountry
//*
//* On the payment form we need to check the country field and display the 
//* appropriate fields.
function checkCountry(dropDown)
{
    //* Get the value od the country dropdown box
    var iIndex = dropDown.selectedIndex;
     var sValue = dropDown.options[iIndex].value;
    
    //* If the country is US, then display the US fields
    if (sValue == "UNITED STATES")
    {
        $("#nonuslabel").hide("slow");
        $("#nonusfield").hide("slow");
        
        $("#uslabel").show("slow");
        $("#usfield").show("slow");
    }
    else
    {
        //* display non us fields
        $("#uslabel").hide("slow");
        $("#usfield").hide("slow");
        
        $("#nonuslabel").show("slow");
        $("#nonusfield").show("slow");
    }
}



//*
//* validatePaymentForm
//*
//* Validate the payment processing form to make sure that 
//* all required fields are present and that the email addresses
//* match.
function validatePaymentForm( iNumAttendees, xValidationArray, iNumEntries) 
{
    var xFrm    = null;
    var bSwitch = false;
    var sMsg    = 'The following errors exist on the form:\n';
    var sValue  = '';   
    
    var bInternationalCards = false;    
    
    //* Get a reference to the form we want.
    xFrm = document.forms['frmProcessPayment'];
    if (xFrm == null) {
        alert('Unable to validate the form: frmProcessPayment');
        return;
    }
    
    //* Check to see if we are allowing international credit cards or not.
    
    var sValue = xFrm.international_cards.value;
    if (sValue.length == 0) {
        bInternationalCards = false;
    } else {
        if (sValue == 'Yes')
        {
            bInternationalCards = true;
        }
        else
        {
            bInternationalCards = false;
        }
    }

    //* Check to make sure we selected a payment option
    var iCount = xFrm.payment.length;   
    if (iCount == undefined)
    {
        //* We either only have one option or we are using freeform pricing
        if (xFrm.freeform == undefined)
        {
            //* we are not using freeform pricing           
            //* we only have one option so there is no array
            if (xFrm.payment.checked)
            {
                bChecked = true;
            }
        }
        else
        {
            //* check the text box
            if (xFrm.payment.value != "")
            {
                bChecked = true;
            }
        }
            
    }
    else
    {
        var iIndex = 0;
        var bChecked = false;
        for (iIndex = 0; iIndex < iCount; iIndex++)
        {
            if (xFrm.payment[iIndex].checked)
            {
                bChecked = true;
            }
        }
    }
    
    if (!bChecked)
    {
        alert('You must select a payment option to continue.');
        return;
    }
    
    //* Name
    sValue = xFrm.first_name.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nFirst Name field is blank\n';
        bSwitch = true;
    }
    
    sValue = xFrm.last_name.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nLast Name field is blank\n';
        bSwitch = true;
    }
    
    //* Email Address
    sEmail1 = xFrm.email1.value;
    if (sEmail1.length == 0) {
        sMsg = sMsg + '\nEmail Address field is blank\n';
        bSwitch = true;
    }
    
    sEmail2 = xFrm.email2.value;
    if (sEmail2.length == 0) {
        sMsg = sMsg + '\nConfirm Email Address field is blank\n';
        bSwitch = true;
    }
    
    if (sEmail1 != sEmail2) {
        sMsg = sMsg + '\nEmail Address fields do not match\n';
        bSwitch = true;
    }
    
    //* Address
    sValue = xFrm.address1.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nAddress field is blank\n';
        bSwitch = true;
    }
    
    sValue = xFrm.city.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nCity field is blank\n';
        bSwitch = true;
    }
    
    //* Find out what our current country selection is
    sValue = xFrm.country.value;
    if (sValue == 'UNITED STATES')
    {
        //* we want to check the state dropdown     
        sValue = xFrm.state.value;
        if (sValue.length == 0) {
            sMsg = sMsg + '\nState field is blank\n';
            bSwitch = true;
        }
    }
    else
    {
        //* we want to check the province field 
        sValue = xFrm.region_province.value;
        if (sValue.length == 0) {
            sMsg = sMsg + '\nRegion / Province field is blank\n';
            bSwitch = true;
        }
        
    }
    
    sValue = xFrm.postal_code.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nPostal Code field is blank\n';
        bSwitch = true;
    }
    
    
    //*
    //* Check the additional fields
    //*
    for (i=0; i < iNumEntries; i++)
    {
        
        //* Lets verify the parameters
        //* we have a text field and it is required
        if (xValidationArray[i][4] == "Text" && xValidationArray[i][2] == 'Yes')
        {
            $sFieldName = xValidationArray[i][0];
            xVar = xFrm[$sFieldName];
            sValue = xFrm[$sFieldName].value;
                if (sValue.length == 0) {
                    sMsg = sMsg + '\n' + xValidationArray[i][1] + ' field is blank\n';
                    bSwitch = true;
                }   
        }
        else if (xValidationArray[i][4] == "Dropdown" && xValidationArray[i][2] == 'Yes')
            {       
                $sFieldName = xValidationArray[i][0];
                xVar = xFrm[$sFieldName];
                sValue = xFrm[$sFieldName].value;
                    if (sValue.length == 0) {
                        sMsg = sMsg + '\n' + xValidationArray[i][1] + ' field is blank\n';
                        bSwitch = true;
                    }    
            }
        else if (xValidationArray[i][4] == "File" && xValidationArray[i][2] == 'Yes')
            {
                $sFieldName = xValidationArray[i][0];
                xVar = xFrm[$sFieldName];
                sValue = xFrm[$sFieldName].value;
                    if (sValue.length == 0) {
                        sMsg = sMsg + '\nNo file is selected\n';
                        bSwitch = true;
                    }    
            }
            
            else if (xValidationArray[i][4] == "Radio" && xValidationArray[i][2] == 'Yes')
            {
               $sFieldName = xValidationArray[i][0];
               var iCount = xFrm[$sFieldName].length;           
               if (iCount == undefined)
               {
               
               }
               else
               {
                var iIndex = 0;
                var bChecked = false;
                for (iIndex = 0; iIndex < iCount; iIndex++)
                {
                    if (xFrm.$sFieldName[iIndex].checked)
                    {
                        bChecked = true;
                    }
                }
                }
            
                //* if bChecked is false then we dont have anything selected
                if (!bChecked)
                {
                    sMsg = sMsg + '\n' + xValidationArray[i][1] + ' has no option selected\n';
                    bSwitch = true;
                }
           }
    }
    
        if (bSwitch) {
                alert(sMsg);
                return;
        }
        xFrm.submit();
}

//*
//* setAttendees
//*
//* Set the number of additional attendees we want on a credit card registration form
//*             
function SetAttendees() {
    var qty = document.getElementById("quantity");
    var att = document.getElementById("attendees");
    var atc = document.getElementById("attendee_count");
    
    var qVal = 0;
    
    if (qty) qVal = (isNaN(qty.value)) ? 0 : Number(qty.value);
//  if (att) att.style.display = (qVal > 1) ? "block" : "none";
//  if (atc) atc.innerHTML = "(" + ((qVal < 1) ? 0 : qVal - 1) + ")";
    
    for (i = 1; i < 5; i++) {
        var obj = document.getElementById("attendee_" + (i + 1));
        if (obj) obj.style.display = (qVal > i) ? "block" : "none";
    }
}


//*
//* validateGBPRsvpForm
//*
//* Validate the GBP RSVP Forms
//*
function validateGBPRsvpForm() 
{
    var xFrm    = null;
    var bSwitch = false;
    var sMsg    = 'The following errors exist on the form:\n';
    var sValue  = '';   
    
    //* Get a reference to the form we want.
    xFrm = document.forms['frmGBPRsvp'];
    if (xFrm == null) {
        alert('Unable to validate the form: frmProcessPayment');
        return;
    }
    
    //* Name
    sValue = xFrm.first_name.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nFirst Name field is blank\n';
        bSwitch = true;
    }
    
    sValue = xFrm.last_name.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nLast Name field is blank\n';
        bSwitch = true;
    }
    
    //* Email Address
    sEmail1 = xFrm.email1.value;
    if (sEmail1.length == 0) {
        sMsg = sMsg + '\nEmail Address field is blank\n';
        bSwitch = true;
    }
    
    //* Date Of Birth
    sValue = xFrm.dobm.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nInvalid Date of Birth month\n';
        bSwitch = true;
    }

    if (sValue < 1 || sValue > 12) {
        sMsg = sMsg + '\nInvalid Month (1 - 12)\n';
        bSwitch = true;
    }
    
    sValue = xFrm.dobd.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nInvalid Date of Birth day\n';
        bSwitch = true;
    }

    if (sValue < 1 || sValue > 31) {
        sMsg = sMsg + '\nInvalid Day (1 - 31)\n';
        bSwitch = true;
    }
    
    sValue = xFrm.doby.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nInvalid Date of Birth year\n';
        bSwitch = true;
    }
    
    if (sValue < 1900 || sValue > 2000) {
        sMsg = sMsg + '\nInvalid Year\n';
        bSwitch = true;
    }
    

    
    
    //* Phone Number
    sValue = xFrm.phone1.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nPhone Number field is blank\n';
        bSwitch = true;
    }
    
    //* Years of work
    sValue = xFrm.years_work_experience.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nYears of Work Experience field is blank\n';
        bSwitch = true;
    }
    
    
    //* Check the event date
    var bDateChecked = false;
    var iCount = xFrm.event_date.length;
    if (iCount == undefined)
    {
        //* we only have on eoption here
        if (xFrm.event_date.checked)
        {
            bDateChecked = true;
        }
    }
    else
    {
        var iIndex = 0;     
        for (iIndex = 0; iIndex < iCount; iIndex++)
        {
            if (xFrm.event_date[iIndex].checked)
            {
                bDateChecked = true;
            }
        }   
    
    }
    
    
    if (!bDateChecked)
    {
        alert('You must select an event date to continue.');
        return;
    }
    
    
    
    
        if (bSwitch) {
                alert(sMsg);
                return;
        }
        xFrm.submit();
}


//*
//* validateNWLRsvpForm
//*
//* Validate the Form
//*
function validateNWLRsvpForm() 
{
    var xFrm    = null;
    var bSwitch = false;
    var sMsg    = 'The following errors exist on the form:\n';
    var sValue  = '';   
    
    //* Get a reference to the form we want.
    xFrm = document.forms['frmLocalRsvp'];
    if (xFrm == null) {
        alert('Unable to validate the form: frmLocalRsvp');
        return;
    }
    
    //* Name
    sValue = xFrm.first_name.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nFirst Name field is blank\n';
        bSwitch = true;
    }
    
    sValue = xFrm.last_name.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nLast Name field is blank\n';
        bSwitch = true;
    }
    
    //* Email Address
    sEmail1 = xFrm.email1.value;
    if (sEmail1.length == 0) {
        sMsg = sMsg + '\nEmail Address field is blank\n';
        bSwitch = true;
    }
    
    //* graduation year
    if (sValue < 1900 || sValue > 2011) {
        sMsg = sMsg + '\nInvalid Graduation Year\n';
        bSwitch = true;
    }

    //* program
    selectmenu=document.getElementById("primary_program")
    sValue = selectmenu.options[selectmenu.selectedIndex];
    if (sValue.lenth == 0)
    {
    sMsg = sMsg + '\nProgram you graduated from can not be empty\n';
    bSwitch = true;
    }
        
    
    //* Phone Number
    sValue = xFrm.phone1.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nPhone Number field is blank\n';
        bSwitch = true;
    }
        
    
        if (bSwitch) {
                alert(sMsg);
                return;
        }
        xFrm.submit();
}


//*
//* validateScholarshipForm
//*
//* Validate the GBF student scholarship form to make sure that 
//* all required fields are present and that the email addresses
//* match.
function validateScholarshipForm() 
{
    var xFrm    = null;
    var bSwitch = false;
    var sMsg    = 'The following errors exist on the form:\n';
    var sValue  = '';   
    
    var bInternationalCards = false;
    
    
    //* Get a reference to the form we want.
    xFrm = document.forms['frmProcessScholarship'];
    if (xFrm == null) {
        alert('Unable to validate the form: frmProcessScholarship');
        return;
    }
    
    //* Check to see if we are allowing international credit cards or not.
    
    var sValue = xFrm.international_cards.value;
    if (sValue.length == 0) {
        bInternationalCards = false;
    } else {
        if (sValue == 'Yes')
        {
            bInternationalCards = true;
        }
        else
        {
            bInternationalCards = false;
        }
    }

    
    
    //* Name
    sValue = xFrm.first_name.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nFirst Name field is blank\n';
        bSwitch = true;
    }
    
    sValue = xFrm.last_name.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nLast Name field is blank\n';
        bSwitch = true;
    }
    
    //* Email Address
    sEmail1 = xFrm.email1.value;
    if (sEmail1.length == 0) {
        sMsg = sMsg + '\nEmail Address field is blank\n';
        bSwitch = true;
    }
    
    sEmail2 = xFrm.email2.value;
    if (sEmail2.length == 0) {
        sMsg = sMsg + '\nConfirm Email Address field is blank\n';
        bSwitch = true;
    }
    
    if (sEmail1 != sEmail2) {
        sMsg = sMsg + '\nEmail Address fields do not match\n';
        bSwitch = true;
    }
    
    //* Address
    sValue = xFrm.address1.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nAddress field is blank\n';
        bSwitch = true;
    }
    
    sValue = xFrm.city.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nCity field is blank\n';
        bSwitch = true;
    }
    
    //* Find out what our current country selection is
    sValue = xFrm.country.value;
    if (sValue == 'UNITED STATES')
    {
        //* we want to check the state dropdown     
        sValue = xFrm.state.value;
        if (sValue.length == 0) {
            sMsg = sMsg + '\nState field is blank\n';
            bSwitch = true;
        }
    }
    else
    {
        //* we want to check the province field 
        sValue = xFrm.region_province.value;
        if (sValue.length == 0) {
            sMsg = sMsg + '\nRegion / Province field is blank\n';
            bSwitch = true;
        }
        
    }
    
    sValue = xFrm.postal_code.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nPostal Code field is blank\n';
        bSwitch = true;
    }
    
    sValue = xFrm.essay.value;
    if (sValue.length == 0) {
        sMsg = sMsg + '\nThe Essay field is blank\n';
        bSwitch = true;
    }
    
        if (bSwitch) {
                alert(sMsg);
                return;
        }
        xFrm.submit();
}


//*
//* validateSBAForm
//*
//* Validate one of the generic forms created using the 
//* SBA-Forms template
//*
//* Each entry in the validation array has the following parameters:
//* 0-fieldName, 1-fieldLabel, 2-required, 3-validation, 4-type
function validateSBAForm( xValidationArray, iNumEntries )
{
    sMsg = "The following errors exist on the form: \n";
    bSwitch = false;
    
    //* Get a reference to the form we want.
    xFrm = document.forms['frmSBAForm'];
    if (xFrm == null) {
         alert('Unable to validate the form: frmSBAForm');
         return;
     }
    
    for (i=0; i < iNumEntries; i++)
    {
        
        //* Lets verify the parameters
        //* we have a text field and it is required
        if (xValidationArray[i][4] == "Text" && xValidationArray[i][2] == 'Yes')
        {
            $sFieldName = xValidationArray[i][0];
            xVar = xFrm[$sFieldName];
            sValue = xFrm[$sFieldName].value;
                if (sValue.length == 0) {
                    sMsg = sMsg + '\n' + xValidationArray[i][1] + ' field is blank\n';
                    bSwitch = true;
                }   
        }
         else if (xValidationArray[i][4] == "HTML" && xValidationArray[i][2] == 'Yes')
            {
               $sFieldName = xValidationArray[i][0];
               xVar = xFrm[$sFieldName];
               sValue = xFrm[$sFieldName].value;
               if (sValue.length == 0) {
                    sMsg = sMsg + '\n' + xValidationArray[i][1] + ' field is blank\n';
                    bSwitch = true;
                }   
            }
            else if (xValidationArray[i][4] == "File" && xValidationArray[i][2] == 'Yes')
                {
                    $sFieldName = xValidationArray[i][0];
                    xVar = xFrm[$sFieldName];
                    sValue = xFrm[$sFieldName].value;
                        if (sValue.length == 0) {
                            sMsg = sMsg + '\nNo file is selected\n';
                            bSwitch = true;
                        }    
                }
                
                 else if (xValidationArray[i][4] == "Checkbox" && xValidationArray[i][2] == 'Yes')
                {
                   $sFieldName = xValidationArray[i][0];
                   if (xFrm[$sFieldName].checked == false) 
                   {
                        sMsg = sMsg + '\n' + xValidationArray[i][1] + ' field is blank\n';
                        bSwitch = true;
                    }   
                }
                
                else if (xValidationArray[i][4] == "Radio" && xValidationArray[i][2] == 'Yes')
                {
               
                   $sFieldName = xValidationArray[i][0];
                   var iCount = xFrm[$sFieldName].length;           
                   if (iCount == undefined)
                   {
                   
                   }
                   else
               {
                var iIndex = 0;
                var bChecked = false;
                for (iIndex = 0; iIndex < iCount; iIndex++)
                {
                    if (xFrm[$sFieldName].checked)
                    {
                        bChecked = true;
                    }
                }
                }
                
                //* if bChecked is false then we dont have anything selected
                if (!bChecked)
                {
                    sMsg = sMsg + '\n' + xValidationArray[i][1] + ' has no option selected\n';
                    bSwitch = true;
                }
             }
    }
    
    
    if (bSwitch) {
                alert(sMsg);
                return;
        }
        xFrm.submit();
}

//*
//* arrayToString
//*
//* Format an array as a string so it can be passed as a paramenter in tha form 
//*
function arrayToString(a, separator) {
    var result = "";
    var iCount = a.length;
    var i=0;
    var sTemp = "";
    
    if (iCount > 0) 
    {
        //* If this is an instance of another array then we need to parse it out to
    if (a[0] instanceof Array)
    {
        sTemp = arrayToString(a[0], separator);
        //a[0] = arrayToString(a[0], separator);
    } 
        result = sTemp;    // start with the first element
        
        for (i=1; i<iCount; i++)
        {   
            if (a[i] instanceof Array)
            {
                result = result + separator + arrayToString(a[i], separator);
            }
            else
            {
                result = result + separator + a[i];
            }
        }
    }
    return result;
}

//*
//* arrayToString2
//*
//* Format an array as a string so it can be passed as a paramenter in tha form 
//*
function arrayToString2(a, separator) {
    var result = "";
    var iCount = a.length;
    var i=0;
    var sTemp = "";
    
    for (i=0; i<iCount; i++)
    {
        //* Check to see if this is a 2 domensional array
        if (a[i] instanceof Array)
        {
            iCount2 = a[i].length;
            for (j=0; j<iCount2; j++)
            {
                result += a[i][j] + separator;
            
            }
        }
        else
        {
            result += a[i] + separator;
        }
    
    }
    
    return result;
}

