﻿// JScript File for Default Values of Input and Text Boxes.

/*  JP 06/04/09 - Innoware

    Summary:
            This is a file that will take the innitial value of an input box or text box and turn it into the default value. 
            This means that when they first click into this field it will clear it for the new value, and if it is left blank again it will return it to the default.
            This also sets the text to grey to show it is the default.
            
     Useage:
            To use this you must give all desired Defaulted inputs a class of : hasDefaultValue
            The desired default value must be in the fields when you call defaultify().
            This then handles all the binding/ storing of functions that will make the rest work.
            
            When the Text is the default value it will also add an class(DefaultValueStyle) that can then 
            overide style rules in css. Use the !important Identifier.
*/
	
// The function called when an element is blurred.
function CheckDefaultInputValueBlur(eClicked)   {
   var value = $(eClicked).val(),
        DefaultValue = $(eClicked).data('defaultValue');
        
    if (value === '')  {
        $(eClicked).val(DefaultValue);
        $(eClicked).css('color','#666');
        $(eClicked).addClass('DefaultValueStyle');
    }
}

// The function called when the element is focused.
function CheckDefaultInputValueFocus(eClicked)   {
    var value = $(eClicked).val(),
        DefaultValue = $(eClicked).data('defaultValue');
        
    if (DefaultValue === value) {
        $(eClicked).val('');
        $(eClicked).css('color','black');
        $(eClicked).removeClass('DefaultValueStyle');
    }
}

// The function to call to initiate the default values.
function defaultify()   {
    $('.hasDefaultValue').each(function()   {
        $(this).css('color', '#666');
        $(this).addClass('DefaultValueStyle');
        $(this).data('defaultValue', $(this).val());
        $(this).blur(function() {
            CheckDefaultInputValueBlur(this);
        });
        $(this).focus(function() {
            CheckDefaultInputValueFocus(this);
        });
    });
}
