﻿// BODY EXTENDER CODE - shrink after pageload if we don't need much extra
jQuery(window).load(function () {
    var viewportheight = jQuery(window).height();
    var contentheight = jQuery('#aspnetForm').height();
    var extrapadneeded = Math.max(0, viewportheight - contentheight) + 20;
    jQuery('#bodyextender').css('height', extrapadneeded + 'px');
});

// DEMO MODE!
function sat_demo_activate() {
    $('body').append( $('<div id="wbdemo-flag">Demo Active</div>') );
    $('.wb-smartitem').addClass('wbdemo-smartitem');
}

// add enter-to-submit functionality to an element
// pass in the element you wish to be 'clicked' when enter is pressed
jQuery.fn.satEnterSubmit = function (submitelement) {
    jQuery(this).keypress(function (e) {
        if (e.keyCode == 13) {
            jQuery(submitelement).click();
            return false;
        }
    });
    return jQuery(this);
};

// auto-hint functionality for textboxes
// crafted by Brian 07/26/2010, tweaked 01/14/2011, tested on jQuery 1.4.2
jQuery.fn.autoHint = function () {
    // loop through all our items and set them up one by one
    jQuery(this).each(function (idx) {
        var mytextbox = jQuery(this);
        var myhint = mytextbox.attr('placeholder');
        // needs a title attribute to be set to the hint value
        if (myhint) {
            // on focus, automatically clear the hint
            mytextbox.bind('focus', function () {
                if (jQuery(this).val() == myhint) {
                    jQuery(this).val('');
                }
            });

            // on blur, replace the hint if we have no text
            mytextbox.bind('blur', function () {
                if (jQuery(this).val() == '') {
                    jQuery(this).val(myhint);
                }
            });

            // force focus loss to initialize
            mytextbox.blur();
        }
    });
    return jQuery(this);
};

// set up the auto-hints on any input textbox with a placeholder attribute defined!
jQuery(document).ready( function() {
    jQuery('input[placeholder]').autoHint();
});


