function validateChgPassword(theForm) {
var reason = "";

  reason += ValCurrentPassword(theForm.CurrentPassword);	
  reason += validatePassword(theForm.NewPassword);
  reason += confirmPassword(theForm.ConfirmPassword);
  reason += MatchPassword(theForm.NewPassword,theForm.ConfirmPassword);


      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

   return SRCM_WebChgPassword_wfsubmit('BUTTON',12294,0);
}


function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function ValCurrentPassword(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter your current password.\n";
    } else {
        fld.style.background = 'White';
    }
   return error;
} 

function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a new password.\n";
    } else if ((fld.value.length < 6) || (fld.value.length > 20)) {
        error = "Your password must be between 6 and 20 characters in length.\n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
} 

function confirmPassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't confirm your password.\n";
    } else {
        fld.style.background = 'White';
    }
   return error;
} 

function MatchPassword(fld,fld2) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
	
    if (fld.value != "" && fld2.value != ""){
    if (fld.value != fld2.value) {
	fld.style.background = 'Yellow';
        fld2.style.background = 'Yellow';
        error = "The passwords that you have entered do not match.\n";
    } else {
	if (fld.value == "") {
	  fld.style.background = 'yellow';
	}
	else
	{
	  fld.style.background = 'white';
	}

	if (fld2.value == "") {
	  fld2.style.background = 'yellow';
	}
	else
	{
	  fld.style.background = 'white';
	}

    }
   }
   return error;
}      
