﻿var backoffice = false;

$(document).ready(function () {
    checkIfFormIsSubmitted();
	
	if ($('div.controlBorder').length > 0)
	{
		$('body').addClass('backoffice');
		backoffice = true;
	}

    capsLockCheck();
});

//CMS-282 - Wouter Dirks - 06-10-2010
function checkIfFormIsSubmitted() {
    $('form').submit(function () {
        if ($('form').attr("isSubmitted")) {
            return false;
        }

        //CMS-441 - Wouter Dirks - 14-10-2010 - Page_IsValid is sometimes undefined
        if (typeof(Page_IsValid) != "undefined" && Page_IsValid) {
            $('form').attr("isSubmitted", true);
        }
    });
}

function capsLockCheck() {
    // Caps lock check
    if ($('.capsLockMessage').length > 0 && $('input[type="password"]').length > 0) {
        $('input[type="password"]').focus(function () {
            $(this).keypress(function (e) {
                e = e || window.event;

                // We need alphabetic characters to make a match.
                var character = String.fromCharCode(e.keyCode | e.which);
                if (character.toUpperCase() === character.toLowerCase()) {
                    return;
                }

                // SHIFT doesn't usually give us a lowercase character. Check for this
                // and for when we get a lowercase character when SHIFT is enabled. 
                if ((e.shiftKey && character.toLowerCase() === character) ||
					(!e.shiftKey && character.toUpperCase() === character)) {
                    $(this).parents('div.customForm').find('.capsLockMessage').show();
                } else {
                    $(this).parents('div.customForm').find('.capsLockMessage').hide();
                }
            });
        });
    }
}
