<!-- Javascript starts - hide from javascript impaired browsers with this line. -->

//------------------------------------------------------------------------------------------
// Java Function: doVerifyEmail - confirm email syntax
// Java Function: passwordCheck - checks password for validation
//------------------------------------------------------------------------------------------

/******************************
* Email String Validator
******************************/

function doVerifyEmail(logonID)
{
    var regex = /^[^@]+@([-\w]+\.)+[A-Za-z]{2,7}$/;

    testEmail = regex.test(logonID);

    if ( testEmail == false )
    {
    return false;
    }
} // Ends doVerifyEmail function

/******************************
* Password Validator
******************************/

function passwordCheck(password2,password1)
{
    if (password1 != "" && password1 == password2)
    {
        if (password1.length < 6) 
        {
            return "Error: Password must contain at least six characters.";
        }
/*
        if (password1 == form.username.value)
        {
            alert("Error: Password must be different from Username!");
            form.pwd1.focus(); 
            return false;
        }
*/        
// AC - 20070712 - Removed all except password length requirement per CIRA-99
// AC - 20070816 - Reverted back to all checks per CIRA-99
        reNumber = /[0-9]/;
        if (!reNumber.test(password1)) 
        {
            return "Error: Password must contain at least one number (0-9).";
        }
        
        reLower = /[a-z]/;
        if(!reLower.test(password1))
        {
            return "Error: Password must contain at least one lowercase letter (a-z).";
        }
        
        reUpper = /[A-Z]/;
        if (!reUpper.test(password1))
        {
            return "Error: Password must contain at least one uppercase letter (A-Z).";
        } 
    }
    else
    {
        return "Error: Please check that you've entered and confirmed your password.";
	}
    
//    alert("You entered a valid password: " + password1);
    return null;

/*
    var passwordLength=6;

    // check that the passwords match
    if (password2 != password1)
    {
        return 4;
    }

    // check that passwords are at least 6 characters
    if ((password1.length < passwordLength) || (password2.length < passwordLength))
    {
        return 1;
    }

    // check that the password is using a combination of letters and numbers
    var regex = /^[0-9a-zA-Z]+$/;

    testPassword1 = regex.test(password1);
    testPassword2 = regex.test(password2);

    //check password1 is valid
    if ( testPassword1 == false )
    {
        return 2
    }

    // check password2 is valid
    if ( testPassword2 == false )
    {
        return 3;
    }
*/
} // Ends passwordCheck function

/******************************
* Has Field been Selected or Filled In
******************************/

// returns false if the field has not been selected or filled in
function isSelected(selected)
{

var selected;

   if (selected==0 || selected=="")
   {
       return false;
   }
} // Ends the isSelection function

/******************************
* Has Check Boxes and Radio buttons been selected
* What are the values of check boxes and radio buttons
* var checkBoxArr = getSelectedCheckbox(document.forms[0].MyCheckBox);
* if (checkBoxArr.length == 0) { alert("No check boxes selected"); }
******************************/

function getSelectedRadio(buttonGroup)
{
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0])
   { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++)
      {
         if (buttonGroup[i].checked)
         {
            return i
         }
      }
   } else
   {
      if (buttonGroup.checked)
      { return 0;
      } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
   return false;
   } // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup)
{
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1)
   {
      return "";
   } else
   {
      if (buttonGroup[i])
      { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else
      { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup)
{
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0])
   { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++)
      {
         if (buttonGroup[i].checked)
         {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else
   { // There is only one check box (it's not an array)
      if (buttonGroup.checked)
      { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup)
{
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0)
   { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++)
      {
         if (buttonGroup[selectedItems[i]])
         { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function



