﻿$(function() {
    tips = $("#validateTips");
    function updateTips(t) {
        tips.text(t).effect("highlight", {}, 2000);
    }
    // Dialog			
    $('#dialog').dialog({
        autoOpen: false,
        width: 300,
        modal: true,
        buttons: {
            "Sing-In": function() {
            //alert($('#dialog').attr('class'));
                $.post("/handlers/ajax_auth.ashx",
            $("#SignInForm").formSerialize(),
	    function(data) {
	        //$("#result").html(data);
	        if (data == "authok") {
	            tips.removeClass('ui-state-error');
	            tips.addClass("ui-state-success");
	            tips.text("Redirecting...");
	            setTimeout(function() { document.location.reload(); }, 1500);
	        }
	        else {
	            updateTips("Wrong login/password!");
	            tips.addClass('ui-state-error');
	        }
	        $(this).dialog("close");
	        return;
	    });
            },
            "Cancel": function() {
                $(this).dialog("close");
            }
        }
    });

    // Dialog Link
    $('#dialog_link').click(function() {
        $('#dialog').dialog('open');
        return false;
    });

    $('#openRedir').click(function() {
        $('#openRedir').dialog('open');
        return false;
    });

});