/* -------------------------------------------------------------
    AUTHOR: Stefan Nafra
    UPDATED: 07.07.2010
    CONTENT: Allgemeine Funktionen die immer wieder benötigt werden.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

/* -------------------------------------------------------------
    01. EINSATZGEBIET: DIGITALWORKROOM | STARTSEITE - BOXEN
        BESCHREIBUNG: Folgt noch. ;-)
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function toggleLinkType(thisSelect) {

    var val = $(thisSelect).val();

    if (val === 'channel' || val === 'more' || val === 'dynamic') {
        $(thisSelect).next().show();
    } else {
        $(thisSelect).next().hide().next().hide();
    }
}

function changeLinkPath(thisSelect) {

    var divID = $(thisSelect).closest('div[id^=\'sortable-\']').attr('id'), val = $(thisSelect).val();

    if ($('#' + divID + ' select.linktype option:selected').val() !== 'dynamic') {
        $(thisSelect).parent().prevAll('input').val(val);
    } else {
        $(thisSelect).parent().prevAll('input').val('id_key=' + val.slice(val.lastIndexOf(',') + 1) + '&count=3');
    }
    $(thisSelect).parent().hide();
}

function changeLinkPath2(thisSelect) {
    $(thisSelect).parent().hide().prev().prev().val($(thisSelect).val());
}

$('.toggle-linktypeselection a').live('click', function () {
    $(this).parent().next().toggle();
});

/* -------------------------------------------------------------
    02. EINSATZGEBIET: WEBSEITIG | GLOBAL
        BESCHREIBUNG: Ermöglich das gezielte Ansprechen von Get-Paramtern aus der URL.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$(function () {

    (function ($) {
        $.url = {};
        $.extend($.url, {
            _params: {},
            init: function () {
                var paramsRaw = '';
                try {
                    paramsRaw = (document.location.href.split('?', 2)[1] || '').split('#')[0].split('&') || [];
                    for (var i = 0; i < paramsRaw.length; i++) {
                        var single = paramsRaw[i].split('=');
                        if (single[0]) {
                            this._params[single[0]] = unescape(single[1]);
                        }
                    }
                }
                catch (e) {
                    alert(e);
                }
            },
            param: function (name) {
                return this._params[name] || '';
            },
            paramAll: function () {
                return this._params;
            }
        });
        $.url.init();
    })(jQuery);
});

/* -------------------------------------------------------------
    03. EINSATZGEBIET: WEBSEITIG - BLUMENBUERO | FLASHVIDEOS
        BESCHREIBUNG: Beim Betreten der Flashvideos über den Button auf der Startseite werden nur die 9 aktuellsten Videos angezeigt.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$(function () {

    if ($.url.param('id').match(/4813/) && $.url.param('id').match(/1092/)) {
        $('div#content').children('div:gt(8)').hide();
    }
});

/* -------------------------------------------------------------
    04. EINSATZGEBIET: DIGITALWORKROOM | ANGEBOTE
        BESCHREIBUNG: Folgt noch. ;-)
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function toggleArticleType(thisSelect) {
    $(thisSelect).closest('.container').removeAttr('class').attr('class', 'container clear ' + $(thisSelect).val()).parent().nextAll(':eq(1)').removeAttr('class').attr('class', 'article ' + $(thisSelect).val()).find('div[id^=\'sortable-\']').each(function () {
        if ($(this).attr('id').match(/\-area\d+/).toString() !== '-area1') {
            $(this).remove();
        }
    });
}

$(function () {
    if ($('#dw-keyword-a').length > 0) {
        $('div[id^=dw-keyword-a]:not(#dw-keyword-a)').hide();
    }

    $('#dw-keyword-a input:radio').live('click', function () {
        $('div[id^=dw-keyword-a]:not(#dw-keyword-a)').hide();
        $('#dw-keyword-aa' + $(this).val()).show().find('h2').html('Unterkategorie - ' + $(this).next().html());
    });
});

/* -------------------------------------------------------------
    05. EINSATZGEBIET: GLOBAL | GLOBAL
        BESCHREIBUNG: .
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function toggleSectionByName(thisSelect, target) {
    $('input[name*=' + target + ']').val($(thisSelect).find('option:selected').text());
}

function toggleSection(thisSelect, target) {
    $('input[name*=' + target + ']').val($(thisSelect).find('option:selected').text());
}

function toggleSectionByValue(thisSelect, target) {
    $('input[name*=' + target + ']').val($(thisSelect).val());
}

function toggleClassByAttribute(thisSelect, target, caseJSON, off) {

    var newClass = (typeof caseJSON[$(thisSelect).val()] !== 'undefined') ? caseJSON[$(thisSelect).val()] : off, classArray = $('#' + target).attr('class').split(' ');

    classArray.pop();
    $('#' + target).attr('class', classArray.join(' ')).addClass(newClass);
}

function toggleClassByValue(thisSelect, target) {

    var classArray = $('#' + target).attr('class').split(' ');

    classArray.pop();
    $('#' + target).attr('class', classArray.join(' ')).addClass($(thisSelect).val().toLowerCase());
}

var arrayStatus = [];

function exchangeClass(target, class1, class2) {

    if ($('#' + target).hasClass(class1)) {
        $('#' + target).removeClass(class1).addClass(class2);
        arrayStatus = $.grep(arrayStatus, function (value) {
            return (value !== target + '-' + class1);
        });
        arrayStatus.push(target + '-' + class2);
        document.cookie = arrayStatus;
    } else {
        $('#' + target).removeClass(class2).addClass(class1);
        arrayStatus = $.grep(arrayStatus, function (value) {
            return (value !== target + '-' + class2);
        });
        arrayStatus.push(target + '-' + class1);
        document.cookie = arrayStatus;
    }
}

function loadClass() {
    if (document.cookie && document.cookie.split(';')[1]) {
        var x = $.trim(document.cookie.split(';')[1]);
        $.each(x.split(','), function (index, value) {
            $('#' + value.split('-')[0]).removeClass('hide').removeClass('show').addClass(value.split('-')[1]);
        });
        arrayStatus.push(x);
    }
}

function exchangeClass2(target, addClass, removeClass) {
    var classArray = $.grep($('#' + target).attr('class').split(' '), function (value) {
        return !value.match(removeClass);
    });
    $('#' + target).removeAttr('class').attr('class', classArray.join(' ')).addClass(addClass);
}

function toggleVisibility(target) {
    $('#' + target).toggle();
}

/* -------------------------------------------------------------
    06. EINSATZGEBIET: GLOBAL | GLOBAL
        BESCHREIBUNG: .
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function toggleClass(thisSelect, target, caseJSON, off) {

    var selectedVal = $('.ansprechpartner-search span:visible select option:selected').val(), isStandart = (typeof caseJSON[$(thisSelect).val()] !== 'undefined') ? ' ' + caseJSON[$(thisSelect).val()] : ' ' + off;
    $('#' + target).removeAttr('class').attr('class', 'container clear' + isStandart);

    if ($('.ansprechpartner-search span:visible select option[value=' + selectedVal + ']').length > 0) {
        $('.ansprechpartner-search span:visible select option[value=' + selectedVal + ']').attr('selected', 'selected');
    } else {
        $('.ansprechpartner-search span:visible select option:eq(0)').attr('selected', 'selected');
    }
}

//.................
$(function () {

    var postData = ($('#post-data').length > 0) ? $('#post-data').html().split(';') : '', location = (postData[0] === 'Kärnten') ? postData[1] : postData[2], i;

    if (postData[0] === '') {
        i = postData[3];
    } else if (postData[0] === 'Kärnten') {
        i = postData[4];
    } else {
        i = postData[5];
    }

    $('.st-bld option[value=' + postData[0] + ']').attr('selected', 'selected').change().parent().nextAll('span:visible').find('option[value=' + location + ']').attr('selected', 'selected');
    $('.ansprechpartner-search span:visible option[value=' + i + ']').attr('selected', 'selected');

    $('div.bereich-more').hide();

    $('div.weitere a').click(function (e) {
        if ($(this).children('span').html() !== 'schließen') {
            $(this).children('span').html('schließen').parents(':eq(2)').next().show();
        } else {
            $(this).children('span').html('jetzt anzeigen').parents(':eq(2)').next().hide();
        }
    });

    $('.standort-search input').focus(function () {
        $('.st-bld option:eq(0)').attr('selected', 'selected').parent().nextAll('span:visible').find('option:eq(0)').attr('selected', 'selected');
    });

    $('.standort-search select').change(function () {
        if ($(this).hasClass('st-umkr')) {
            $('.st-bld option:eq(0)').attr('selected', 'selected').parent().nextAll('span:visible').find('option:eq(0)').attr('selected', 'selected');
        } else {
            $('.st-umkr option:eq(0)').attr('selected', 'selected').parent().prev().val('');
        }
    });
});

/* -------------------------------------------------------------
    06. POI
        06.1. Setzt die Dummyfelder beim Abschicken auf leer.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function clearForm() {
    $('div.poi-form input:text').each(function () {
        if ($(this).hasClass('searchinputcolor')) {
            $(this).val('');
        }
    });
}

/* -------------------------------------------------------------
        06.2. Setzt bei leeren Feldern die Dummy Werte wieder ein.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function initLabel() {
    $('div.poi-form input:text').each(function () {
        if ($(this).val() === '') {
            $(this).addClass('searchinputcolor').val($(this).attr('title'));
        }
    });
}

$(function () {
    initLabel();
});

/* -------------------------------------------------------------
        06.3. Löscht den Dummytext des Inputfeldes beim fokusieren.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$('div.poi-form input:text').live('click', function () {
    if ($(this).hasClass('searchinputcolor')) {
        $(this).removeClass('searchinputcolor').val('').focus();
    }
});

/* -------------------------------------------------------------
        06.4. Erstellt aus dem Title den Dummytext sofern der Wert des Inputs leer ist.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$(function () {
    $('div.poi-form input:text').blur(function () {
        if ($(this).val() === '') {
            $(this).addClass('searchinputcolor').val($(this).attr('title'));
        }
    });
});

/* -------------------------------------------------------------
        06.5. Filtert die Liste nach den gewünschten Werten aus den Checkfeldern.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$('input.poi-check').live('click', function () {
    $('.poi-result li').show();
    $(this).closest('div').find('input.poi-check:checked').each(function () {
        $('.poi-result li:not(.' + $(this).val() + ', .poi-header)').hide();
    });
});

$('input.filter').live('click', function () {
    $('ul.sortable li').show();
    $(this).parent().children('input.filter:checked').each(function () {
        $('ul.sortable li:not(.' + $(this).val() + ')').hide();
    });
});

/* -------------------------------------------------------------
        06.6. Setzt das ganze Formular zurück.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$('a.form-delete').live('click', function () {
    $(this).closest('form').find('input:text, input:checkbox, select').each(function () {
        if ($(this).is('input:text')) {
            $(this).addClass('searchinputcolor').val($(this).attr('title'));
        } else if ($(this).is('input:checkbox')) {
            $(this).removeAttr('checked');
        } else if ($(this).hasClass('poi-sel')) {
            $(this).val('');
        }
    });
});

/* -------------------------------------------------------------
    07. EINSATZGEBIET: WEBSEITIG | LAGERHAUS - ANGEBOTE
        BESCHREIBUNG: Versieht Preise ohne Kommazahlen mit einem ,-- und Kommazahlen werden in einen em gewrappt.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$(function () {

    $('div.preis').each(function () {

        var splittext = $(this).children('em').text().split(','), hasSpan = ($(this).children('span').length > 0) ? '<span>' + $(this).children('span').html() + '</span> ' : '';

        if (splittext[1]) {
            $(this).html(hasSpan + splittext[0] + ', <em>' + $.trim(splittext[1]) + '</em>');
        } else if (!isNaN(splittext[0]) && splittext[0] !== '') {
            $(this).html(hasSpan + splittext[0] + ',--');
        } else {
            $(this).html(hasSpan + splittext[0]);
        }
    });
});

/* -------------------------------------------------------------
    08. EINSATZGEBIET: WEBSEITIG | k.a.
        BESCHREIBUNG: Zeigt ein LoaderBild an bis die Jbox den Content geladen hat.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$('#searchbutton').live('click', function () {
    $(this).parent().after('<img class="loader" style="margin: 40px;" src="/pages/img/portal/loading.gif" title="loading" alt="loading" />');
    jbox['dv-content'].ready(function () {
        $('img.loader').remove();
    });
    jbox['ldb-content'].ready(function () {
        $('img.loader').remove();
    });
});

/* -------------------------------------------------------------
    .
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function checkSelect() {
    if ($('select[name=\'xmlval_KEYWORD_OPTIONS[0]\']').length > 0 && $('select[name=\'xmlval_KEYWORD_OPTIONS[0]\'] option:selected').val() === '') {
        $('select[name=\'xmlval_KEYWORD_OPTIONS[0]\']').css('background-color', 'red');
        return false;
    } else {
        return true;
    }
}

function changeStatus(thisSelect) {
    if ($(thisSelect).val() === 'off') {
        var currentDate = new Date();
        $('#dw-informationen input[name=\'xmlval_DATE_OFFLINE[0]\']').val(currentDate.getDate() + '.' + (currentDate.getMonth() + 1) + '.' + currentDate.getFullYear());
        $('#dw-funktionen input[name*=\'[F_VON]\']').each(function () {
            if ($(this).val() !== '') {
                $(this).nextAll('input').val(currentDate.getDate() + '.' + (currentDate.getMonth() + 1) + '.' + currentDate.getFullYear());
            }
        });
    }
}

/* -------------------------------------------------------------
    10. EINSATZGEBIET: DIGITALWORKROOM | LINK
        BESCHREIBUNG: Öffnet/Schließt die Linkbereiche und übernimmt die Werte.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$('.toggle-link').live('click', function () {

    var divID = $(this).closest('div[id^=\'sortable-\']').attr('id'), formElementLength, i;

    if ($('#' + divID + ' .area-full').is(':hidden')) {
        $('#' + divID + ' .toggle-link').html('&Uuml;bernehmen');
    } else {
        $('#' + divID + ' .toggle-link').html('Bearbeiten');

        if (!$(this).parents(':eq(1)').hasClass('toggle-download-area')) {
            $('#' + divID + ' .area-short .formElement1').html('<a href="parse.php?id=2500,' + $('#' + divID + ' .area-full .formElement1 input').val() + '" title="" target="_blank">' + $('#' + divID + ' .area-full .formElement1 input').val() + '</a>');
        } else {
            $('#' + divID + ' .area-short .formElement1').html('<a href="http://dw6.testit.at/mmedia/download' + $('#' + divID + ' .area-full .formElement1 input').val().replace(/download=/, '') + '" title="" target="_blank">' + $('#' + divID + ' .area-full .formElement1 input').val() + '</a>');
        }

        formElementLength = $('#' + divID + ' .area-short div[class*=\'formElement\']').length;
        for (i = 2; i <= formElementLength; i += 1) {
            if ($('#' + divID + ' .area-full .formElement' + i + ' input:text').length > 0) {
                $('#' + divID + ' .area-short .formElement' + i).html($('#' + divID + ' .area-full .formElement' + i + ' input').val());
            } else {
                $('#' + divID + ' .area-short .formElement' + i).html($('#' + divID + ' .area-full .formElement' + i + ' select option:selected').html());
                $('#' + divID + ' .area-short .formElement' + i).html($('#' + divID + ' .area-full .formElement' + i + ' input:checked').parent().text());
            }
        }
    }
    $('#' + divID + ' .area-short').toggle();
    $('#' + divID + ' .area-full').toggle();
});

/* -------------------------------------------------------------
    11. EINSATZGEBIET: DIGITALWORKROOM | MEHRFACH
        BESCHREIBUNG: Stellt das Augenbild auf on/off.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$('.toggle-eye').live('click', function () {
    if (!$(this).hasClass('forum')) {
        if ($(this).hasClass('yes')) {
            $(this).removeClass('yes').addClass('no').parent().next('input').val('no');
        } else {
            $(this).removeClass('no').addClass('yes').parent().next('input').val('yes');
        }
    } else {
        if ($(this).hasClass('open')) {
            $(this).removeClass('open').addClass('closed').parent().next('input').val('closed');
        } else {
            $(this).removeClass('closed').addClass('open').parent().next('input').val('open');
        }
    }
});

/* -------------------------------------------------------------
    12. EINSATZGEBIET: DIGITALWORKROOM | CONTENT
        BESCHREIBUNG: .
        12.1 Entfernt die Bildergröße des ausgwählten Bildes.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function deleteImageSize(divID) {
    $('#' + divID + ' .img-size').removeAttr('class').addClass('img-size');
    $('#' + divID + ' .img-size-bg').children('input').val('');
}

/* -------------------------------------------------------------
        12.2. Entfernt das ausgewählte Bild.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function deleteImage(divID) {
    deleteImageSize(divID);

    // Leert die zum Bild dazugehörigen InputFelder.
    $('#' + divID + ' input[name*=\'_P_\']').each(function () {
        $(this).val('');
    });

    $('#' + divID).find('td').html('<img src="../../../../pages/img/digitalworkroom/light-plus.gif" alt="[light-plus.gif]" />').closest('table').next().val('').next().val('');
}

/* -------------------------------------------------------------
        12.3. Verändert die Anzeigegröße des Bildes.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$('.change-imagesize').live('click', function () {
    var divID = $(this).closest('div[id^=\'sortable-\']').attr('id');
    deleteImageSize(divID);
    $(this).children().removeClass('img-size-active').addClass('img-size' + ($('#' + divID + ' .img-size-bg a').index(this) + 1) + '-active').closest('div').children('input').val($('#' + divID + ' .img-size-bg a').index(this) + 1);
});

/* -------------------------------------------------------------
        12.4. Entfernt das ausgewählte Bild.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$('.delete-image').live('click', function () {
    deleteImage($(this).closest('div[id^=\'sortable-\']').attr('id'));
});

/* -------------------------------------------------------------
    13. EINSATZGEBIET: noch keines.
        BESCHREIBUNG: Noch keine vorhanden.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$(function () {
    $('.tabnavigation').children('li').click(function () {
        $('#tabset' + $(this).parent().attr('id').match(/\d+/)).children('li').hide().end().children('li:eq(' + $('#' + $(this).parent().attr('id') + ' li').index(this) + ')').show();
    });
});

/* -------------------------------------------------------------
    14. EINSATZGEBIET: WEBSEITIG | OEAMTC - MEHRFACH.
        BESCHREIBUNG: Gibt den Bereichen die Anzahl der dazugehörigen Forumseinträgen zurück.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

//$(function () {
//    $.getJSON('comments.php', function (data) {
//
//        $.each(data, function (i, v) {
//
//            var comment = (parseInt(v, 10) === 1) ? ' Kommentar' : ' Kommentare';
//            $('#forumeintrag-' + i).text(v + comment);
//        });
//    });
//});

//..........
$('div.erw-kontinent li').live('click', function () {

    var classArray = $('div.erw-laender').attr('class').split(' ');

    classArray.pop();
    $(this).parent().find('li.selected').removeClass('selected');
    $('div.erw-laender').attr('class', classArray.toString().replace(/,/g, ' ')).addClass($(this).addClass('selected').text().toLowerCase()).find('li.selected').removeClass('selected');
});

$('div.erw-kategorie li, div.erw-laender li').live('click', function () {
    if ($(this).closest('div').children('ul:visible').children('li.selected').length < parseInt($(this).parent().attr('class').match(/\d+/), 10) || $(this).hasClass('selected')) {
        $(this).toggleClass('selected');
    } else {
        alert('schon ' + $(this).parent().attr('class').match(/\d+/) + ' ausgesucht.');
    }
});

function writeInputHidden2() {
    $('div.ldb-selection input').val('');
    $('div.erw-kategorie li.selected, div.erw-laender ul:visible li.selected, div.erw-kontinent li.selected').each(function () {
        $(this).closest('div').children('input').val($(this).closest('div').children('input').val() + $(this).attr('id').split('-')[1].substr(1) + ',');
    });
}

//..........
$(document).click(function (e) {
    $('input.ac-date').each(function () {

        var element = $(this), dateLength = element.val().split('.').length, currentDate = new Date();

        if (dateLength === 2 && element.val() !== '') {
            element.val(element.val() + '.' + currentDate.getFullYear());
        } else if (dateLength === 1 && element.val() !== '') {
            element.val(element.val() + '.' + (currentDate.getMonth() + 1) + '.' + currentDate.getFullYear());
        }
    });

    if ($(e.target).closest('.overlay-closeable').length === 0 && $(e.target).closest('.overlay-open').length === 0) {
        $('.overlay-closeable').hide();
    }
});

//..........
$('#dw-laz input:checkbox').live('click', function () {
    changeFunction($(this));
});

//..........
function changeFunction(thisSelect) {

    if ($(thisSelect).parent().nextAll(':eq(1)').val() === '') {
        var currentDate = new Date();
        $(thisSelect).parent().nextAll(':eq(1)').val(currentDate.getDate() + '.' + currentDate.getMonth() + '.' + currentDate.getFullYear());
    }
}

//..........
function autocomplete(id) {
    if ($('#' + id).val() !== '') {
        $('#plz-result').find('li').hide();
        $('#plz-result').show().find('li[class*=-' + $('#' + id).val().toLowerCase() + ']').show();
    }
}

$('#plz-result li').live('click', function () {
    $('#POSTLEITZAHL').val($(this).children(':eq(0)').html());
    $('#ORT').val($(this).children(':eq(1)').html());
    $('#plz-result').hide().find('li').hide();
});

//..........
function saveStatus() {
    var active = $('#dw-link').attr('class').split(' ').pop();
    active = active.substr(0, 1).toUpperCase() + active.substr(1);
    jbox['mainedit'].ready(function () {
        $('#dw-link h2:contains(' + active + ')').click();
    });
}

/* -------------------------------------------------------------
    0x. EINSATZGEBIET: WEBSEITIG | MEHRFACH.
        BESCHREIBUNG: .
        0x.1 Entfernt den Pretext der Inputs beim Abschicken.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function clearPretext() {
    $('input:text').each(function () {
        if ($(this).hasClass('pretextstyle')) {
            $(this).val('');
        }
    });
}

/* -------------------------------------------------------------
        0x.2. Setzt die Pretexte in die Inputs ein.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$(function () {
    $('input.pretext').each(function () {
        $(this).addClass('pretextstyle').val($(this).attr('title'));
        if ($(this).is(':password')) {
            $(this).replaceWith('<input id="' + $(this).attr('id') + '" class="' + $(this).attr('class') + '" type="text" title="' + $(this).attr('title') + '" maxlength="' + $(this).attr('maxlength') + '" value="' + $(this).val() + '" name="' + $(this).attr('name') + '"');
        }
    })
});

/* -------------------------------------------------------------
        0x.3. Löscht den Dummytext des Inputfeldes beim fokusieren.
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$('input.pretext').live('click', function () {
    if ($(this).hasClass('pretextstyle')) {
        $(this).removeClass('pretextstyle').val('').focus();
        if ($(this).attr('id').match(/password/)) {
            $(this).replaceWith('<input id="' + $(this).attr('id') + '" class="' + $(this).attr('class') + '" type="password" title="' + $(this).attr('title') + '" maxlength="' + $(this).attr('maxlength') + '" value="' + $(this).val() + '" name="' + $(this).attr('name') + '"');
        }
        $('#' + $(this).attr('id')).focus();
    }

    $('input.pretext').blur(function () {
        if ($(this).val() === '') {
            $(this).addClass('pretextstyle').val($(this).attr('title'));
            if ($(this).is(':password')) {
                $(this).replaceWith('<input id="' + $(this).attr('id') + '" class="' + $(this).attr('class') + '" type="text" title="' + $(this).attr('title') + '" maxlength="' + $(this).attr('maxlength') + '" value="' + $(this).val() + '" name="' + $(this).attr('name') + '"');
            }
        }
    });
});

/* -------------------------------------------------------------
    0x. EINSATZGEBIET: Folgt noch. ;-)
        BESCHREIBUNG: Folgt noch. ;-)
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$(function () {
    $.get('pages/sites/portal/portal_main.css', function (data) {
        data = data.match(/(#[a-z0-9]*?\ .?postclass.*?)\s?\{/g);
        if (data) {
            $.each(data, function (index, value) {
                value = value.substring(0, value.length - 2);
                $(value.split(' .')[0]).wrapInner('<div class="' + value.split('.')[1] + '" />');
            });
        }
    });
});