// SpryValidationPassword.js - version 0.4 - Spry Pre-Release 1.6.1
//
// Copyright (c) 2006. Adobe Systems Incorporated.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of Adobe Systems Incorporated nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
(function() { // BeginSpryComponent
if (typeof Spry == "undefined") window.Spry = {}; if (!Spry.Widget) Spry.Widget = {};
Spry.Widget.BrowserSniff = function()
{
var b = navigator.appName.toString();
var up = navigator.platform.toString();
var ua = navigator.userAgent.toString();
this.mozilla = this.ie = this.opera = this.safari = false;
var re_opera = /Opera.([0-9\.]*)/i;
var re_msie = /MSIE.([0-9\.]*)/i;
var re_gecko = /gecko/i;
var re_safari = /(applewebkit|safari)\/([\d\.]*)/i;
var r = false;
if ( (r = ua.match(re_opera))) {
this.opera = true;
this.version = parseFloat(r[1]);
} else if ( (r = ua.match(re_msie))) {
this.ie = true;
this.version = parseFloat(r[1]);
} else if ( (r = ua.match(re_safari))) {
this.safari = true;
this.version = parseFloat(r[2]);
} else if (ua.match(re_gecko)) {
var re_gecko_version = /rv:\s*([0-9\.]+)/i;
r = ua.match(re_gecko_version);
this.mozilla = true;
this.version = parseFloat(r[1]);
}
this.windows = this.mac = this.linux = false;
this.Platform = ua.match(/windows/i) ? "windows" :
(ua.match(/linux/i) ? "linux" :
(ua.match(/mac/i) ? "mac" :
ua.match(/unix/i)? "unix" : "unknown"));
this[this.Platform] = true;
this.v = this.version;
if (this.safari && this.mac && this.mozilla) {
this.mozilla = false;
}
};
Spry.is = new Spry.Widget.BrowserSniff();
Spry.Widget.ValidationPassword = function(element, options)
{
options = Spry.Widget.Utils.firstValid(options, {});
if (!this.isBrowserSupported())
return;
if (this.init(element, options) === false)
return false;
var validateOn = ['submit'].concat(Spry.Widget.Utils.firstValid(this.options.validateOn, []));
validateOn = validateOn.join(",");
this.validateOn = 0;
this.validateOn = this.validateOn | (validateOn.indexOf('submit') != -1 ? Spry.Widget.ValidationPassword.ONSUBMIT : 0);
this.validateOn = this.validateOn | (validateOn.indexOf('blur') != -1 ? Spry.Widget.ValidationPassword.ONBLUR : 0);
this.validateOn = this.validateOn | (validateOn.indexOf('change') != -1 ? Spry.Widget.ValidationPassword.ONCHANGE : 0);
if (Spry.Widget.ValidationPassword.onloadDidFire)
this.attachBehaviors();
else
Spry.Widget.ValidationPassword.loadQueue.push(this);
};
Spry.Widget.ValidationPassword.ONCHANGE = 1;
Spry.Widget.ValidationPassword.ONBLUR = 2;
Spry.Widget.ValidationPassword.ONSUBMIT = 4;
Spry.Widget.ValidationPassword.prototype.init = function(element, options)
{
options = Spry.Widget.Utils.firstValid(options, []);
this.options = [];
this.element = this.getElement(element);
if (!this.element)
{
return false;
}
else
{
if (this.element.nodeName.toUpperCase() == 'INPUT' && typeof this.element.type != 'undefined' && this.element.type.toUpperCase() == 'PASSWORD')
{
this.input = this.element;
}
else
{
var inputs = Spry.Widget.Utils.getValidChildrenWithNodeNameAtAnyLevel(this.element, 'INPUT', 'PASSWORD');
if (inputs && inputs.length > 0)
this.input = inputs[0];
else
this.input = false;
}
}
if (!this.input)
return false;
this.event_handlers = [];
this.validClass = "passwordValidState";
this.focusClass = "passwordFocusState";
this.requiredClass = "passwordRequiredState";
this.invalidStrengthClass = "passwordInvalidStrengthState";
this.invalidCharsMinClass = "passwordMinCharsState";
this.invalidCharsMaxClass = "passwordMaxCharsState";
this.invalidCustomClass = "passwordCustomState";
options.isRequired = Spry.Widget.Utils.firstValid(options.isRequired, true);
options.additionalError = Spry.Widget.Utils.firstValid(options.additionalError, false);
if (options.additionalError)
options.additionalError = this.getElement(options.additionalError);
var getRealValue = Spry.Widget.Utils.getOptionRealValue;
options.minChars = getRealValue(options.minChars, false);
options.maxChars = getRealValue(options.maxChars, false);
// copy the default textfield behavior
if (options.maxChars)
this.input.removeAttribute("maxLength");
options.minAlphaChars = getRealValue(options.minAlphaChars, false);
options.maxAlphaChars = getRealValue(options.maxAlphaChars, false);
options.minUpperAlphaChars = getRealValue(options.minUpperAlphaChars, false);
options.maxUpperAlphaChars = getRealValue(options.maxUpperAlphaChars, false);
options.minSpecialChars = getRealValue(options.minSpecialChars, false);
options.maxSpecialChars = getRealValue(options.maxSpecialChars, false);
options.minNumbers = getRealValue(options.minNumbers, false);
options.maxNumbers = getRealValue(options.maxNumbers, false);
if ((options.minAlphaChars !== false && options.maxAlphaChars !== false && options.minAlphaChars > options.maxAlphaChars) ||
(options.minUpperAlphaChars !== false && options.maxUpperAlphaChars !== false && options.minUpperAlphaChars > options.maxUpperAlphaChars) ||
(options.minSpecialChars !== false && options.maxSpecialChars !== false && options.minSpecialChars > options.maxSpecialChars) ||
(options.minNumbers !== false && options.maxNumbers !== false && options.minNumbers > options.maxNumbers) ||
(options.maxUpperAlphaChars !== false && options.maxAlphaChars !== false && options.maxUpperAlphaChars > options.maxAlphaChars) ||
(options.maxChars !== false && options.minAlphaChars + options.minUpperAlphaChars + options.minSpecialChars + options.minNumbers > options.maxChars)
)
{
this.showError('Invalid Strength Options!');
return false;
}
Spry.Widget.Utils.setOptions(this, options);
Spry.Widget.Utils.setOptions(this.options, options);
};
Spry.Widget.ValidationPassword.loadQueue = [];
Spry.Widget.ValidationPassword.onloadDidFire = false;
Spry.Widget.ValidationPassword.prototype.getElement = function(ele)
{
if (ele && typeof ele == "string")
ele=document.getElementById(ele);
return ele;
};
Spry.Widget.ValidationPassword.processLoadQueue = function(handler)
{
Spry.Widget.ValidationPassword.onloadDidFire = true;
var q = Spry.Widget.ValidationPassword.loadQueue;
var qlen = q.length;
for (var i = 0; i < qlen; i++)
q[i].attachBehaviors();
};
Spry.Widget.ValidationPassword.addLoadListener = function(handler)
{
if (typeof window.addEventListener != 'undefined')
window.addEventListener('load', handler, false);
else if (typeof document.addEventListener != 'undefined')
document.addEventListener('load', handler, false);
else if (typeof window.attachEvent != 'undefined')
window.attachEvent('onload', handler);
};
Spry.Widget.ValidationPassword.addLoadListener(Spry.Widget.ValidationPassword.processLoadQueue);
Spry.Widget.ValidationPassword.prototype.destroy = function()
{
if (this.event_handlers)
for (var i=0; i