var lastValueSets = new Array();
function FormValueCheck(id) {
set = document.getElementById('set_' + id);
value = document.getElementById(id).value;
value_set = document.getElementById('value_' + id + '_' + value);
//Hide Last Value Set
if (lastValueSets[id]) {
lastValueSets[id].style.display = 'none';
}
//Display Value Set
if (value_set) {
value_set.style.display = 'block';
lastValueSets[id] = value_set;
}
}
var Clones = 1;
Loc = document.location.href;
function FormClone(id) {
//Setup vars
Clones++;
div = document.getElementById(id);
clone = div.cloneNode(true);
var target = document.getElementById(id + "_target");
var parentDiv = target.parentNode;
//Clone
parentDiv.insertBefore(clone, target);
//Setup clone vars
newdiv = target.previousSibling;
code = newdiv.innerHTML;
document.getElementById(id + "_total").value++;
//change id & name
newdiv.innerHTML = code.replace(new RegExp('(="[A-Za-z0-9_]+_)[0-9]+(_div)?(")', 'g'), "$1" + Clones + "$2$3");
newdiv.id = newdiv.id.replace(new RegExp('([A-Za-z0-9_]+_)[0-9]+(_div)?', 'g'), "$1" + Clones + "$2$3");
document.location.href = Loc + '#anchorname_' + Clones;
}
function CheckPhone(obj) {
value = obj.value;
regEx = new RegExp('(.+)?([0-9]{3})(.+)?([0-9A-Za-z]{3})(.+)?([0-9A-Za-z]{4})', 'g');
obj.value = value.replace(regEx, "$2.$4.$6");
}
// -- Password Builder -- //
var hints = new Array();
hints['AlphaNonNumeric'] = 'Use characters that arent letters or numbers, for example: $ or ~.';
hints['letters_numbers'] = 'Use both letters and numbers.';
hints['NumAtEnds'] = 'Try putting the numbers in the middle, for example: pas6w99ord';
hints['CapFirst'] = 'Mix in captial letters, dont just capitilize the first letter.';
hints['UsernameInP'] = 'Do NOT use your username or any variations of it in your password.';
hints['NameInP'] = 'Do NOT use your name or any variations of it in your password.';
hints['characters'] = 'Your password is currently too short, enter more characters.';
hints['none'] = 'No suggestions, you have a very strong password';
function checkPass() {
var uppercase;
var lowercase;
var numbers;
var letters;
var non;
var suggestion;
var reguppercase = '^([A-Z])$';
var reglowercase = '^([a-z])$'
var regnumbers = '^([0-9])$'
var regNumAtEnd = '^([^0-9]+)?([0-9]+)$';
var regNumAtBegin = '^([0-9]+)([^0-9]+)?$';
var regCapFirst = '^([A-Z])([a-z0-9])+$';
var regUsername = '^(.+)?' + document.getElementById('username').value.toLowerCase() + '(.+)?$'
var regFirstname = '^(.+)?' + document.getElementById('first_name').value.toLowerCase() + '(.+)?$'
var regLastname = '^(.+)?' + document.getElementById('last_name').value.toLowerCase() + '(.+)?$'
var i = 0;
var pts = 0;
var len = document.getElementById('password').value.length;
var chr;
//Run length
if (len >=6) {
while (i < len) {
chr = document.getElementById('password').value.charAt(i)
if (chr.match(reglowercase)) {
pts = pts + 2;
lowercase = true;
letters = true;
} else if (chr.match(regnumbers)) {
pts = pts + 1;
numbers = true;
} else if (chr.match(reguppercase)) {
pts = pts + 2;
uppercase = true;
letters = true;
} else {
pts = pts + 4;
non = true;
}
i++;
}
//Bonuses
if (uppercase && lowercase) {
pts = pts + 2;
} else {
suggestion = 'case';
}
if (letters && numbers) {
pts = pts + 3;
if (non) {
pts = pts + 5;
} else {
suggestion = 'AlphaNonNumeric';
}
} else {
suggestion = 'letters_numbers';
}
//Penalities
pn = true;
if (document.getElementById('password').value.match(regNumAtEnd)) {
pts = pts - 3;
suggestion = 'NumAtEnds';
pn = false;
} else if (document.getElementById('password').value.match(regNumAtBegin)) {
pts = pts - 3;
suggestion = 'NumAtEnds';
pn = false;
} else if (document.getElementById('password').value.match(regCapFirst)) {
pts = pts - 2;
suggestion = 'CapFirst';
pn = false;
} else if (document.getElementById('password').value.toLowerCase().match(regUsername) && document.getElementById('username').value.length >= 6) {
pts = pts - 10;
suggestion = 'UsernameInP';
pn = false;
} else if (document.getElementById('password').value.toLowerCase().match(regFirstname) && document.getElementById('first_name').value.length >= 3) {
pts = pts - 10;
suggestion = 'NameInP';
pn = false;
} else if (document.getElementById('password').value.toLowerCase().match(regLastname) && document.getElementById('last_name').value.length >= 3) {
pts = pts - 10;
suggestion = 'NameInP';
pn = false;
}
} else {
pts = 0;
suggestion = 'characters';
}
//Tally
if (pts >= 25 && pn) {
set_strength('Excellent', '#24973A', 'none', pts);
} else if (pts >= 20) {
set_strength('Strong', '#A3EDB8', suggestion, pts);
} else if (pts >= 15) {
set_strength('Fair', '#DEF031', suggestion, pts);
} else if (pts >= 10) {
set_strength('Weak', '#FF0000', suggestion, pts);
} else {
set_strength('Too Short', '#000000', suggestion, 6);
}
}
function set_strength(strength, color, tip, pts) {
var bar_length = pts / 25 * 100;
if (bar_length > 100) { bar_length = 100; }
document.getElementById('password_strength_bar').style.width = bar_length + '%';
document.getElementById('password_strength_bar').style.background = color;
document.getElementById('password_strength_status').innerHTML = ''+strength+'
Password Suggestions:
'+hints[tip];
}
var store;
var box;
var boxValue;
var data;
var sn;
var SearchBox;
var SearchBoxFrame;
var BoxSelected;
var ResultList;
var AutoPopSelection;
var AutoPopSelect;
var AutoPopTotal;
var FirstResult;
var LastKey;
var Change;
function CheckUpdate() {
if (boxValue != box.value) {
if (!SearchBox) {
SearchBox = document.createElement('div');
SearchBox.className = 'AutoPopResults';
SearchBox.style.width = box.clientWidth + 'px';
box.parentNode.insertBefore(SearchBox, box.nextSibling);
}
if (!SearchBoxFrame) {
SearchBoxFrame = document.createElement('iframe');
SearchBoxFrame.style.display = 'none';
document.body.appendChild(SearchBoxFrame);
}
SearchBox.style.display = 'block';
store.value = '';
Change = true;
SearchBoxFrame.src = '/_jsclasses/AutoPopData.php?data='+data+'&search='+box.value+'&sn='+sn;
} else { Change = false; }
AutoPopSelection = 0;
AutoPopSelect = false;
boxValue = box.value;
CheckTO = setTimeout('CheckUpdate()',500);
box.onblur = function() { setTimeout('KillCheck()',100) };
SearchBox.onfocus = function () { BoxSelected = true; }
SearchBox.onblur = function () { BoxSelected = false; }
box.onkeydown = OnPress;
}
function StartCheck(newBox, newData, newSn) {
store = document.getElementById(newBox.id.substring(8));
box = newBox;
data = newData;
sn = newSn;
CheckUpdate();
}
function KillCheck(e) {
if (!BoxSelected) {
clearTimeout(CheckTO); CheckTO = false;
SearchBox.innerHTML = '';
SearchBox.style.display = 'none';
}
}
function OnPress(e) {
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = code;
LastKey = code;
if (character == 13) {
KillCheck();
return false;
} else if (character == 40) {
move = 1;
} else if (character == 38) {
move = -1;
} else if (character == 9) {
move = 0;
clearTimeout(CheckTO); CheckTO = false;
KillCheck();
box.focus();
} else {
move = 0;
if (!CheckTO) {
CheckUpdate();
}
}
if (move != 0) {
AutoPopMoving = setTimeout('AutoPopMove('+move+')', 0);
clearTimeout(CheckTO); CheckTO = false;
}
}
function AutoPopMove(move) {
if (AutoPopTotal > AutoPopSelection + move && AutoPopSelection + move >= 0) {
if (AutoPopSelect) {
ResultList[AutoPopSelection].className = 'AutoPopUnselected';
AutoPopSelection += move;
} else { AutoPopSelect = true; }
ResultList[AutoPopSelection].className = 'AutoPopSelected';
box.value = ResultList[AutoPopSelection].innerHTML;
store.value = ResultList[AutoPopSelection].id.substring(6);
} else if (AutoPopTotal == 1) {
AutoPopSelection = 0;
ResultList[0].className = 'AutoPopSelected';
box.value = ResultList[0].innerHTML;
store.value = ResultList[0].id.substring(6);
}
}
function HighlightSelection(iStart, iLength) {
iStart = box.value.length;
if (iStart > 0) {
iLength = FirstResult.length;
box.value = FirstResult;
boxValue = FirstResult;
if (box.createTextRange) {
var oRange = box.createTextRange();
oRange.moveStart("character", iStart);
oRange.moveEnd("character", iLength - box.value.length);
oRange.select();
} else if (box.setSelectionRange) {
box.setSelectionRange(iStart, iLength);
}
box.focus();
}
};
function GeneratePassword(obj) {
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
pass = "";
for(x=0;x<6;x++)
{
i = Math.floor(Math.random() * 62);
pass += chars.charAt(i);
}
document.getElementById(obj).type = 'text';
document.getElementById(obj).value = pass;
}
function GetTarget(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ) {
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
}
return targ;
}
var TempValue;
function ClearLabel(field, label) {
TempValue = label;
if (field.value == label) {
field.value = '';
}
field.onblur = CheckLabel;
}
function CheckLabel(e) {
field = GetTarget(e);
if (field.value.length < 1 || field.value == 'undefined' || field.value == '') {
field.value = TempValue;
}
TempValue = '';
}