$('#login_username').blur(function() {
    if($(this).attr('value') == '')
        $(this).attr('value', "Gebruikersnaam");
});

$('#login_username').focus(function() {
    if($(this).attr('value') == "Gebruikersnaam")
        $(this).attr('value','');
});

$('#login_password').blur(function() {
    if($(this).attr('value') == '')
        $(this).attr('value', "Wachtwoord");
});

$('#login_password').focus(function() {
    if($(this).attr('value') == "Wachtwoord")
        $(this).attr('value','');
});

$("select[name=login_organisatie]").dropdown({
    total_width: 243
});

$("#login_username").blur(function()
{	

    $.getJSON("login/get_organisaties/"+$(this).attr("value")+"/",function(data)
    {

        var html;


        if(data !== null && data.length>1)
        {
            html = "<li id='val_' class='choice show optgroup'><span>Kies een optie</span></li>";

            for(var i = 0;i < data.length;i++)
            {
                html += "<li id='val_"+data[i].organisatie_id+"' class='show'><span>"+data[i].naam+"</span></li>";
            }

            $("#table_row_organisatie").show();
            $(".top").addClass("top_large");
        }
        else if(data !== null && data.length == 1)
        {
            html = "<li id='val_"+data[0].organisatie_id+"' class='show'><span>"+data[0].naam+"</span></li>";
            $("input[name=login_organisatie]").attr("value",data[0].organisatie_id);

            $("#table_row_organisatie").hide();
            $(".top").removeClass("top_large");
        }
        else
        {
            html = "<li id='val_' class='show choice optgroup'><span>Kies een optie</span></li>";
            $("input[name=login_organisatie]").attr("value","");
            $("#table_row_organisatie").hide();
            $(".top").removeClass("top_large");
        }


        $("#login_organisatie").html(html);
    });
});

