﻿$(document).ready(function() {
    //hide the all of the element with class msg_body
    $(".msg_body").hide();
    //toggle the componenet with class msg_body
    $(".msg_head").click(function() {
        $(this).next(".msg_body").slideToggle("fast");
    });

    var page = $("#loginContent").get(0);

    if (page != undefined) {
        $(".password_test").passStrength({
            userid: "#usernameTextBox"
        });
    }
});

function onClientClose(rWindow, args) {
    var arg = args.get_argument();
    if (arg != null) {
        var array = arg.split("|");
        if (array[0] == "Credit") {
            rWindow.close();
            window.location = "creditApplication.aspx?id=" + array[1];
        }
        else if (array[0] == "Contact") {
            rWindow.close();
            openContactWindow();                       
        }
        else {
            rWindow.close();
        }
    }
}

function openDetailWindow(ID) {
    var window = radopen("Details.aspx?id=" + ID, "DetailRadWindow");
    window.set_height(700);
    window.set_width(950);
    window.moveTo(155, 0);
}

function openContactWindow() {
    var window = radopen("ContactUs.aspx", "ContactRadWindow");
    window.set_height(700);
    window.set_width(950);
    window.moveTo(155, 0);
}

function openContactWindowWithParam(queryString) {
    var window = radopen("ContactUs.aspx?" + queryString, "ContactRadWindow");
    window.set_height(700);
    window.set_width(950);
    window.moveTo(155, 0);
}

function paymentSelection() {
    var value = $('input[type=radio][id*=paymentTypeButtonList]:checked').val();
    if (value == "check") {
        $("#overlayDiv2").removeClass().addClass("paymentNotSelected");
        $("#overlayDiv").removeClass().addClass("payment");
    }
    else if (value == "credit") {
        $("#overlayDiv").removeClass().addClass("paymentNotSelected");
        $("#overlayDiv2").removeClass().addClass("payment");
    }
}

function billingChecked() {
    var value = $('input[type=checkbox][id*=billingCheckBox]:checked').val();
    var address = $("[id*=creditAddressTextBox]");
    var city = $("[id*=creditCityTextBox]");
    var state = $("[id*=creditStateDropDown]");
    var zip = $("[id*=creditZipCodeTextBox]");
    if (value == "on") {
        address.attr('disabled', true);
        ValidatorEnable($("[id*=addressRequiredFieldValidator]")[0], false);
        city.attr('disabled', true);
        ValidatorEnable($("[id*=cityRequiredFieldValidator]")[0], false);
        state.attr('disabled', true);
        ValidatorEnable($("[id*=stateRequiredFieldValidator]")[0], false);
        zip.attr('disabled', true);
        ValidatorEnable($("[id*=zipCodeRequiredFieldValidator]")[0], false);
    }
    else {
        address.attr('disabled', false);
        ValidatorEnable($("[id*=addressRequiredFieldValidator]")[0], true);
        city.attr('disabled', false);
        ValidatorEnable($("[id*=cityRequiredFieldValidator]")[0], true);
        state.attr('disabled', false);
        ValidatorEnable($("[id*=stateRequiredFieldValidator]")[0], true);
        zip.attr('disabled', false);
        ValidatorEnable($("[id*=zipCodeRequiredFieldValidator]")[0], true);
    }
}

function addressChecked() {
    var value = $('input[type=checkbox][id*=addressCheckBox]:checked').val();
    var address = $("[id*=checkAddressTextBox]");    
    var city = $("[id*=checkCityTextBox]");
    var state = $("[id*=checkStateDropDown]");
    var zip = $("[id*=checkZipCodeTextBox]");
    if (value == "on") {
        address.attr('disabled', true);
        ValidatorEnable($("[id*=checkAddressValidator]")[0], false);
        city.attr('disabled', true);
        ValidatorEnable($("[id*=checkCityValidator]")[0], false);
        state.attr('disabled', true);
        ValidatorEnable($("[id*=checkStateValidator]")[0], false);
        zip.attr('disabled', true);
        ValidatorEnable($("[id*=checkZipCodeValidator]")[0], false);
    }
    else {
        address.attr('disabled', false);
        ValidatorEnable($("[id*=checkAddressValidator]")[0], true);
        city.attr('disabled', false);
        ValidatorEnable($("[id*=checkCityValidator]")[0], true);
        state.attr('disabled', false);
        ValidatorEnable($("[id*=checkStateValidator]")[0], true);
        zip.attr('disabled', false);
        ValidatorEnable($("[id*=checkZipCodeValidator]")[0], true);
    }
}

function numericOnly(e, o) {
    var entry = e.charCode ? e.charCode : e.keyCode
    if (entry < 8 || entry > 9) {
        if (entry < 48 || entry > 57) {
            o.style.backgroundColor = "#FF4040";
            return false
        }
        else
            o.style.borderColor = "";
            o.style.backgroundColor = "";
    }
}

function moneyOnly(e, o) {
    var entry = e.charCode ? e.charCode : e.keyCode
    if (entry < 8 || entry > 9) {
        if ((entry < 48 || entry > 57) && entry != 46) {
            o.style.backgroundColor = "#FF4040";
            return false
        }
        else
            o.style.borderColor = "";
            o.style.backgroundColor = "";
    }
}

var commonPasswords = new Array('password', 'pass', '1234', '1246');

var numbers = "0123456789";
var lowercase = "abcdefghijklmnopqrstuvwxyz";
var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var punctuation = "!.@$£#*()%~<>{}[]";

function checkPassword(password) {

    var combinations = 0;

    if (contains(password, numbers) > 0) {
        combinations += 10;
    }

    if (contains(password, lowercase) > 0) {
        combinations += 26;
    }

    if (contains(password, uppercase) > 0) {
        combinations += 26;
    }

    if (contains(password, punctuation) > 0) {
        combinations += punctuation.length;
    }

    // work out the total combinations 
    var totalCombinations = Math.pow(combinations, password.length);

    // if the password is a common password, then everthing changes... 
    if (isCommonPassword(password)) {
        totalCombinations = 75000 // about the size of the dictionary 
    }

    // work out how long it would take to crack this (@ 200 attempts per second) 
    var timeInSeconds = (totalCombinations / 200) / 2;

    // this is how many days? (there are 86,400 seconds in a day. 
    var timeInDays = timeInSeconds / 86400

    // how long we want it to last 
    var lifetime = 365;

    // how close is the time to the projected time? 
    var percentage = timeInDays / lifetime;

    var friendlyPercentage = cap(Math.round(percentage * 100), 100);
    if (totalCombinations != 75000 && friendlyPercentage < (password.length * 5)) {
        friendlyPercentage += password.length * 5;
    }

    var progressBar = document.getElementById("progressBar");
    progressBar.style.width = friendlyPercentage + "%";

    if (percentage > 1) {
        // strong password 
        progressBar.style.backgroundColor = "#3bce08";
        return;
    }

    if (percentage > 0.5) {
        // reasonable password 
        progressBar.style.backgroundColor = "#ffd801";
        return;
    }

    if (percentage > 0.10) {
        // weak password 
        progressBar.style.backgroundColor = "orange";
        return;
    }

    // useless password! 
    if (percentage <= 0.10) {
        // weak password 
        progressBar.style.backgroundColor = "red";
        return;
    }


}

function cap(number, max) {
    if (number > max) {
        return max;
    } else {
        return number;
    }
}

function isCommonPassword(password) {

    for (i = 0; i < commonPasswords.length; i++) {
        var commonPassword = commonPasswords[i];
        if (password == commonPassword) {
            return true;
        }
    }

    return false;

}

function contains(password, validChars) {

    count = 0;

    for (i = 0; i < password.length; i++) {
        var char = password.charAt(i);
        if (validChars.indexOf(char) > -1) {
            count++;
        }
    }

    return count;
} 
 
 //Disappearing Post-it note Script
 $(document).mouseover(function(){
  setTimeout(function() {    
    $("div.postItText").delay(3000).fadeOut(3000)
  });
});

$(document).mouseover(function(){
  setTimeout(function() {    
    $("div.postIt").delay(3000).fadeOut(3000)
  });
});
 
 


