/* ------------------------------------------
  This script sets effects and functions to Volkswagen site.
--------------------------------------------- */

$(function() {
    $('.toggleInput').each(function() {
        var _self = $(this);
        var val = _self.val();
        var ttl = _self.attr('title');
        if( _self.is(':password') ) {
/*
            var span = $('<span />');
            span.text(ttl)
                .addClass('passMes')
                .css({
                    'position': 'absolute',
                    'margin-left': '3px'
                })
                .click(function() {
                    _self.focus();
                });
            _self.before(span);
*/
            _self.focus(function() {
//                span.hide();
                if (document.getElementById("passMes")){
                    document.getElementById("passMes").innerHTML='';
                }
            });
            _self.blur(function() {
                if( !_self.val() ) {
//                    span.show();
                    if (document.getElementById("passMes")){
                        document.getElementById("passMes").innerHTML='パスワード';
                    }
                }
            });
        } else {
            if( val === ttl || !val ) {
                ttl ? _self.val(ttl) : '';
                _self.addClass('noInput');
            } else {
                _self.removeClass('noInput');
            }
            _self.focus(function() {
                if( _self.val() === ttl ) {
                    _self.removeClass('noInput').val('');
                }
                if (_self.attr('id')=='id'){
                    if (document.getElementById("passMes")){
                        document.getElementById("passMes").innerHTML='';
                    }
                }
          }).blur(function() {
                if( !_self.val() ) {
                    _self.addClass('noInput').val(ttl);
                }
                if (_self.attr('id')=='id'){
                    if (document.getElementById("pw")){
                        if (document.getElementById("pw").value=='' && document.getElementById("passMes")){
                            document.getElementById("passMes").innerHTML='パスワード';
                        }
                    }
                }
            });
        }
    });

    //this sets toggle function to input of search.
    if( $.browser.msie || ( navigator.userAgent.toLowerCase().match(/firefox\/([0-9\.]+)/) && navigator.userAgent.toLowerCase().match(/firefox\/([0-9\.]+)/)[1] < "3.5" ) ) {
        //this sets last-child option.
        $('.listDefinition:last-child').addClass('lastChild');

        //this sets first pseudo class to separated list.
        $('.listSeparatedHor li:first-child').addClass('firstChild');

        //this sets last pseudo class to separated list.
        $('.tblSearchForm tr:last-child').addClass('lastChild');

        //this function sets stripe to stripe list and stripe table.
        $('.stripe tr:nth-child(odd), .listLinkStripe li:nth-child(odd)').addClass('odd');
        $('.stripe tr:nth-child(even), .listLinkStripe li:nth-child(even)').addClass('even');
    }

});



