﻿jQuery(function () {
    jQuery('.hint').each(function () {
        // Initialize
        var item = jQuery(this);
        var html = item[0];
        if (html.tagName.toLowerCase().substring(0, 6) == 'select') {
            // If the dropdown is empty then use the title attribute value as a hint and add the hintShown class
            if (html.length == 0) {
                item.append(new Option(item.attr('title'), ''));
                html.disabled = true;
                html.addClass('hintShown');
            }
        }
        else if ((item.val() == '') && (!item.hasClass('hintShown'))) {
            item.val(item.attr('title'));
            item.addClass('hintShown');
        }

        // On Focus
        // If the hintShown class is active (hint currently showing) then then clear the value and remove the class
        // Always add the hintActive class ('entering data' effect)
        item.focus(function () {
            var item = jQuery(this);
            if (item.hasClass('hintShown')) {
                item.val('');
                item.removeClass('hintShown');
            }
            item.addClass('hintActive');
        });

        // On Blur
        // If the value is blank then add the hint title and hintShown class
        // Always remove the hintActive class ('entering data' effect)
        item.blur(function () {
            var item = jQuery(this);
            if (item.val() == '') {
                item.val(item.attr('title'));
                item.addClass('hintShown');
            }
            item.removeClass('hintActive');
        });
    });

    jQuery('.PnSearchResultSortOrderItems input:radio:checked + label').addClass('selected');
});


// FormHintsClearField
// Set value to the hint title and add the hintShown class
// Always remove the hintActive class ('entering data' effect)
function FormHintsClearField(item) {
    item = jQuery(item);
    item.val(item.attr('title'));
    item.addClass('hintShown');
    item.removeClass('hintActive');
}



// On Submit
// If the hintShown class is active (hint currently showing)
// then disable the element to keep the value from being submitted
// This minimizes flickering as opposed to clearing the value
function FormHintsOnSubmit() {
    $$('.hintShown').each(function () {
        var item = jQuery(this);
        var html = item[0];
        html.disabled = true;
    });
}
