$(document).ready(function()
{

    var login_dialog = $('<div id="login_dialog" style="display:none;"></div>').appendTo('body');
    var lOptions =
    {
        height:300,
        width:450,
        title: "Login"
    }
    login_dialog.uidialog( lOptions );

    $(".loginbutton").live("click", function()
    {
        var form = $("#login_form").serialize();
        var url = base_url + "adminpanel/login";
/*
        $.post( url, form, function( response )
        {
            if( response.error )
            {
                $(".loginfeedback").html( response.message );

            }
            else
            {
                 window.location = response.message;
            }

        }, 'json');
*/

		$.ajax({
			type: "POST",
			url: url,
			dataType: "json",
			data: form,
			success : function(response)
			{
	            if( response.error )
	            {
	                $(".loginfeedback").html( response.message );

	            }
	            else
	            {
	                 window.location = response.message;
	            }
				return false;
			}
		});

        return false;
    });

    $(".login").click(function()
    {
                                        //ajax call
        $.ajax(
        {
           type: "POST",
           url: base_url + "adminpanel/",
           success : function(html)
           {
               $("#login_dialog").html(html).dialog('open');
			    setTimeout(function()
			    {
			    	$("#loginname").focus();
			    },500);               
           }
        });
        return false;
    });
});
