/*
* jQuery emptyonclick plugin
*
* Created by Andreas Creten (andreas@madewithlove.be) on 2008-06-06.
* Copyright (c) 2008 madewithlove. All rights reserved.
*
* Version: 1.2
*
* Changelog :
* Version 1.2 (17 Jun 2008)
*  - Empty the fields onsubmit when they are not changed
*
* Version 1.1 (11 Jun 2008)
*  - Fixed a bug when working with an empty field (no default value)
*
* Version 1.0 (06 Jun 2008):
*  - Original version
*/

jQuery.fn.extend({
    emptyonclick: function(options) {
        var taal = options;
        return this.each(function(options) {
            // here
            if ($(this).attr('id') == 'ctl00_UcSearchHomeJobs1_jobwhat') {
                //job what
                if (taal == 'nl') { new jQuery.EmptyOnClick(this, 'Wat?'); } else { new jQuery.EmptyOnClick(this, 'Quoi?'); }
            }
            else if ($(this).attr('id') == 'ctl00_UcSearchHomeJobs1_jobwhere') {
                //job where
                if (taal == 'nl') { new jQuery.EmptyOnClick(this, 'Waar?'); } else { new jQuery.EmptyOnClick(this, 'Où?'); }
            }
            else if ($(this).attr('id') == 'ctl00_UcSearchHomeArticles_txtArticle') {
                // article what
                if (taal == 'nl') { new jQuery.EmptyOnClick(this, 'Wat?'); } else { new jQuery.EmptyOnClick(this, 'Quoi?'); }
            }
            else if ($(this).attr('id') == 'ctl00_ContentPlaceHolder_ContentCol1_AdvancedSearch_jobwhat') {
                //adv search
                if (taal == 'nl' ) { new jQuery.EmptyOnClick(this, 'Wat?  Waar?'); } else { new jQuery.EmptyOnClick(this, 'Quoi? Où?'); }
            }
        });
    }
});

jQuery.EmptyOnClick = function(element, options) {
    var defaultValue = $(element).val();
    if ($(element).val() != options) { $(element).removeClass('lbltxt'); }
    // Bind event handlers to the element
    $(element)
    // On Focus: Store the default value if it's not set, empty the field
    .bind("focus", function(e) {
        //alert(defaultValue + ' ' + options);
        defaultValue = $(this).val();
        if (defaultValue == options) {
            $(this).val('');
        }
        $(this).removeClass('lbltxt');

    })
    // On Blur: if the field is empty, reset the default value
    .bind("blur", function(e) {
        if (!$(this).val() && defaultValue == options) {
            $(this).val(defaultValue);

            if (defaultValue == options) { $(this).addClass('lbltxt'); }
        }
    });
    //when value is known it's good.  new search on click = it flies away
};
