function showSMS() {
    $('#sms').show('fast');
}
function hideSMS() {
    $('#sms').hide('fast');
}
function showDisclaimer() {
    $('#disclaimer').show('fast');
}
function hideDisclaimer() {
    $('#disclaimer').hide('fast');
}
function showDomain() {
    $('#domain').show('fast');
}
function hideDomain() {
    $('#domain').hide('fast');
}
function showRef() {
    $('#references').show('fast');
}
function hideRef() {
    $('#references').hide('fast');
}
function switchIntern() {
    $('#login').hide('fast');
    $('#mainTitle').hide('fast');
    $('#internMenu').show('fast');
}

function showKontakte() {

    $.getJSON("kontakte.php", function(d) {
        $('#kontakteContent').html('');
        $.each(d, function(i,kontakt){
            $('#kontakteContent').append(
                '<tr>'
                +'<td><input type="hidden" name="contacts['+i+'][id]" value="'+kontakt.cont_id+'" /><input class="smallinput" type="text" name="contacts['+i+'][name]" value="'+kontakt.cont_name+'" /></td>'
                +'<td><input class="smallinput" type="text" name="contacts['+i+'][address]" value="'+kontakt.cont_address+'" /></td>'
                +'<td><input class="smallinput" type="text" name="contacts['+i+'][email]" value="'+kontakt.cont_email+'" /></td>'
                +'<td><input class="smallinput" type="text" name="contacts['+i+'][birthday]" value="'+kontakt.cont_birthday+'" /></td>'
                +'<td><input class="smallinput" type="text" name="contacts['+i+'][phone1]" value="'+kontakt.cont_phone1+'" /></td>'
                +'<td><input class="smallinput" type="text" name="contacts['+i+'][phone2]" value="'+kontakt.cont_phone2+'" /></td>'
                +'<td><input class="smallinput" type="text" name="contacts['+i+'][remarks]" value="'+kontakt.cont_remarks+'" /></td>'
                +'<td><img src="img/CustomsSign.png" onclick="deleteKontakt('+kontakt.cont_id+')" alt="löschen" title="löschen" /></td>'
                +'</tr>'
            );
        });

        kontaktNeueZeile();
    });
    $('#kontakte').show('fast');
}

function deleteKontakt(id) {
    if (confirm('Wirklich Kontakt löschen?')) {
        $.getJSON("savekontakte.php?delete="+id, function(data) {
            if (data.callbackFunction) window.setTimeout(data.callbackFunction,100);
        });
    }
}


function kontaktNeueZeile() {
    $('#kontakteContent').append(
        '<tr id="neuerKontakt">'
        +'<td><input class="smallinput neu" type="text" default="NAME" name="newcontact[name]" value="NAME" /></td>'
        +'<td><input class="smallinput neu" type="text" default="ADRESSE" name="newcontact[address]" value="ADRESSE" /></td>'
        +'<td><input class="smallinput neu" type="text" default="EMAIL" name="newcontact[email]" value="EMAIL" /></td>'
        +'<td><input class="smallinput neu" type="text" default="GEB.DAT." name="newcontact[birthday]" value="GEB.DAT." /></td>'
        +'<td><input class="smallinput neu" type="text" default="TELEFON" name="newcontact[phone1]" value="TELEFON" /></td>'
        +'<td><input class="smallinput neu" type="text" default="MOBIL" name="newcontact[phone2]" value="MOBIL" /></td>'
        +'<td><input class="smallinput neu" type="text" default="SONSTIGES" name="newcontact[remarks]" value="SONSTIGES" /></td>'
        +'<td>&nbsp;</td>'
        +'</tr>'
    );

    $('#kontakteContent .neu').focus(function() {
        if ($(this).val() == $(this).attr('default')) $(this).val('');
        $(this).addClass('schwarz');
    });

    $('#kontakteContent .neu').blur(function() {
        if ($(this).val()=='') {
            $(this).val($(this).attr('default'));
            $(this).removeClass('schwarz');
        }
    });
}

function speicherKontakte() {
    $('#kontakteContent .neu').each(function() {
        if ($(this).val() == $(this).attr('default')) $(this).val('');
    });
    $('#kontakteForm').submit();
}

function centerBox(titel, text) {
    $("#infocontent").html(text);
    $("#infotitel").html(titel);
    $("#infos").show();

    $(document).keyup( function(event) {
        if (event.keyCode == 27) {
            closeBox();
        }
    });
}

function closeBox() {
    $("#infos").hide();
}

$(document).ready(function(){

    $(".referencePic").mouseover(function() {
        $(".referencePic").css('z-index','1');
        $(this).css('z-index','100');
    });

    $('#services').mouseover(function() {
        $(this).css('opacity',1);
    });

    $(".toogleIcon").mouseover(function() {
        src = $(this).attr('src');
        $(this).attr('src', src.replace(/_disabled.png/g, "_enabled.png"));
    });
    $(".toogleIcon").mouseout(function() {
        src = $(this).attr('src');
        $(this).attr('src', src.replace(/_enabled.png/g, "_disabled.png"));
    });
    $('#references').hide();
    $('#empfehlungen').hide();
    $('#sms').draggable();
    $('#references').draggable();
    $('#kontakte').draggable();


    /* AJAX */
    var options = {
        dataType :"json",
        beforeSubmit : function() {
            if (!$("#ajxDontShowWait").val()) {
                centerBox('HINWEIS', '<img src="img/ajax-loader.gif" /> BITTE WARTEN');
                cboxflag = true;
            } else {
                cboxflag = false;
            }
        }, /* END beforeSubmit */

        success : function(data) {
            if (data.reload) location.reload();
            if (data.msg) centerBox('Hinweis', data.msg);
            if (data.callbackFunction) window.setTimeout(data.callbackFunction,100);

            ajxCallbackFunc = $("#ajxCallbackFunc").val();
            if (ajxCallbackFunc.length>0) {
                window.setTimeout(ajxCallbackFunc, 500);
                $("#ajxCallbackFunc").val('');
            }

            if (cboxflag) closeBox();
        } /* END SUCCESS */


    };
    $('.myAjaxJsonForm').ajaxForm(options);
    /* END AJAX */


});