// (c) 2010 Veronica Canterbury - http://www.vimcat.com
// Depends on jQuery.
// This is licensed under the GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

$(document).ready(function () {
    //button hover script
    $(".button").mouseover(function () {
        imgPath = $(this).attr("src");
        imgTypePos = imgPath.lastIndexOf(".");
        imgExtension = imgPath.substring(imgTypePos);
        imgPath = imgPath.substring(0, imgTypePos);
        $(this).attr("src", imgPath + "_hover" + imgExtension);
    });

    $(".button").mouseout(function () {
        imgPath = $(this).attr("src");
        imgTypePos = imgPath.lastIndexOf(".");
        hoverPos = imgPath.indexOf("_hover");
        imgExtension = imgPath.substring(imgTypePos);
        imgPath = imgPath.substring(0, hoverPos);
        $(this).attr("src", imgPath + imgExtension);
    });


    //helper labels inside of input fields
    function placeholders() { //initialize placeholders
        if ('placeholder' in document.createElement('input')) return false;

        var inputs = $('input');
        inputs.each(function (i, el) {
            el = $(el);
            var placeHolderVal = el.attr('placeholder');
            var passwordPlaceHolder = $(".passwordPlaceHolder");
            var oldCSSClass = el.attr('class');
            if (!placeHolderVal) return true;

            el.addClass(oldCSSClass + ' placeholder');

            if (el.attr('type') == 'password') {
                el.addClass('isPassword');
                passwordPlaceHolder.show();
            }

            passwordPlaceHolder.click(function () {
                $(this).prev().focus();
            });

            el.attr('value', placeHolderVal);

            el.focus(function () {
                if (el.val() == placeHolderVal) { el.attr('value', ''); }
                el.removeClass('placeholder');
                if (el.hasClass('isPassword')) {
                    passwordPlaceHolder.hide();
                    el.removeClass('isPassword');
                    el.addClass(oldCSSClass);
                }
            });

            el.blur(function () {
                if (el.val() == '' || el.val == placeHolderVal) {
                    el.attr('value', placeHolderVal);
                    el.addClass(oldCSSClass + ' placeholder');
                    if (el.attr('type') == 'password') {
                        el.addClass(oldCSSClass + ' isPassword');
                        passwordPlaceHolder.show();
                    }
                }
            });
        });
    }

    placeholders();

    $('#ctl00_MainContent_SSN1TB').autotab({ target: 'ctl00_MainContent_SSN2TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_SSN2TB').autotab({ target: 'ctl00_MainContent_SSN3TB', format: 'number', maxlength: '2' });
    $('#ctl00_MainContent_SSN3TB').autotab({ previous: 'ctl00_MainContent_SSN2TB', format: 'number', maxlength: '4' });

    $('#ctl00_MainContent_HPhone1TB').autotab({ target: 'ctl00_MainContent_HPhone2TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_HPhone2TB').autotab({ target: 'ctl00_MainContent_HPhone3TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_HPhone3TB').autotab({ previous: 'ctl00_MainContent_HPhone2TB', format: 'number', maxlength: '4' });

    $('#ctl00_MainContent_CPhone1TB').autotab({ target: 'ctl00_MainContent_CPhone2TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_CPhone2TB').autotab({ target: 'ctl00_MainContent_CPhone3TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_CPhone3TB').autotab({ previous: 'ctl00_MainContent_CPhone2TB', format: 'number', maxlength: '4' });

    $('#ctl00_MainContent_FPhone1TB').autotab({ target: 'ctl00_MainContent_FPhone2TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_FPhone2TB').autotab({ target: 'ctl00_MainContent_FPhone3TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_FPhone3TB').autotab({ previous: 'ctl00_MainContent_FPhone2TB', format: 'number', maxlength: '4' });

    $('#ctl00_MainContent_WPhone1TB').autotab({ target: 'ctl00_MainContent_WPhone2TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_WPhone2TB').autotab({ target: 'ctl00_MainContent_WPhone3TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_WPhone3TB').autotab({ previous: 'ctl00_MainContent_WPhone2TB', format: 'number', maxlength: '4' });

    $('#ctl00_MainContent_SPhone1TB').autotab({ target: 'ctl00_MainContent_SPhone2TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_SPhone2TB').autotab({ target: 'ctl00_MainContent_SPhone3TB', format: 'number', maxlength: '3' });
    $('#ctl00_MainContent_SPhone3TB').autotab({ previous: 'ctl00_MainContent_SPhone2TB', format: 'number', maxlength: '4' });

    $('#ctl00_MainContent_NetPPCTB').autotab_filter('numeric');
});

