/**
 * manage input/textarea with a default value when the input is empty
 * jQuery required
 */

/**
 * USAGE :
 * 
 * html
 * 
 * <input type="text" value="please enter a text" id="myinput" />
 * <script type="text/javascript">
 * myprofile_initEmptyInputMessage('myinput');
 * </script>
 * 
 * style :
 * 
 * .mtcEmptyInput{font-style:italic}
 * 
 * script :
 * 
 * var inputValue = myprofile_getInputValue('myinput'); 
 */

var myprofile_emptyInputMessage = new Array();
function myprofile_initEmptyInputMessage(id)
{
    var el = $j('#'+id);
    if(!el.hasClass('mtcEmptyInput'))
    {
        el.addClass('mtcEmptyInput');
    }
    $j('#' + id).focus(function(){myprofile_focusInput(id)});
    $j('#' + id).blur(function(){myprofile_blurInput(id)});
}
/**
 * function to call when the input is focused
 * @param string id if of the input
 */
function myprofile_focusInput(id)
{
    var el = $j('#'+id);
    if(el.hasClass('mtcEmptyInput'))
    {
        myprofile_emptyInputMessage[id] = el.val();
        el.val('');
        el.removeClass('mtcEmptyInput');
    }
}
/**
 * function to call whe the input is blured
 * @param string id if of the input
 */
function myprofile_blurInput(id)
{
    var el = $j('#'+id);
    if(el.val() == '' && !el.hasClass('mtcEmptyInput'))
    {
        el.addClass('mtcEmptyInput');
        el.val(myprofile_emptyInputMessage[id]);
    }
}
/**
 * get the "real" value of the input
 * @param string id id of the input
 * @return mixed : the value of the input. If the default value is contained, it returns null
 */
function myprofile_getInputValue(id)
{
    var el = $j('#'+id);
    if(el.hasClass('mtcEmptyInput'))
    {
        return null;
    }
    return el.val();
}