﻿

$(document).ready(function() {

/*audit validation*/
    
    $("#audit_form .text").blur(function() {
        $(this).parent().removeClass("select");
        $(this).parent().prev().removeClass("select");

        if ($(this).attr("value") + "" != "undefined" && $(this).attr("value") + "" != "")
            $(this).css("background-image", "url('/files/images/seo_img/textseo.gif')");

    });

    $("#audit_form .text").focus(function() {
        $(this).parent().addClass("select");
        $(this).parent().prev().addClass("select");
    });

    $("#editprofile_form #comments").blur(function() {
        $(this).parent().parent().removeClass("select");
        $(this).parent().parent().prev().removeClass("select");
    });

    $("#editprofile_form #comments").focus(function() {
        $(this).parent().parent().addClass("select");
        $(this).parent().parent().prev().addClass("select");
    });

    //submit event
    $("#audit_form #submitButton").click(function() {
        var all_ok = true;

        all_ok = (ValidateInputControl($("#name")) && all_ok);
        all_ok = (ValidateInputControl($("#phone")) && all_ok);
        all_ok = (ValidateInputControl($("#email")) && all_ok);
        all_ok = (ValidateInputControl($("#companyname")) && all_ok);
        all_ok = (ValidateInputControl($("#site")) && all_ok);

        if (all_ok == true) {
            $("#require_comment").after("<p>&nbsp;<p><p>Обработка...</p>");
            $("#audit_form").ajaxSubmit({
                dataType: 'json',
                success: onSuccessAdd,
                url: "/handlers/AddAuditOrder.ashx"
            });
        }

        return false;
    });

    var onSuccessAdd = function(data)
    {
        if (data.success == true) {
            $("#add_audit_link").show();
            $("#add_audit_link").before("<p>Ваша заявка успешно отправлена...</p>");
            $("#audit_table").hide();
        }
    }



//login validation


    $("#loginForm .text").blur(function() {
        $(this).parent().removeClass("select");
        $(this).parent().prev().removeClass("select");
    });

    $("#loginForm .text").focus(function() {
        $("#login_status_text").html("");
        $(this).parent().addClass("select");
        $(this).parent().prev().addClass("select");
    });


    $("#login").blur(function() {
        if ($("#login").attr("value") + "" != "undefined" && $("#login").attr("value") + "" != "")
            $("#login").css("background-image", "url('/files/images/seo_img/textseo.gif')");
    });

    $("#pass").blur(function() {
        if ($("#pass").attr("value") + "" != "undefined" && $("#pass").attr("value") + "" != "")
            $("#pass").css("background-image", "url('/files/images/seo_img/textseo.gif')");
    });


    $("#loginForm #submitButton").click(function() {
        var all_ok = true;
        all_ok = (ValidateInputControl($("#login")) && all_ok);
        all_ok = (ValidateInputControl($("#pass")) && all_ok);

        if (all_ok == true) {
            $("#loginForm").ajaxSubmit({
                dataType: 'json',
                success: onSuccessLogin,
                url: "/handlers/LoginHandler.ashx"
            });
        }

        return false;
    });

    var onSuccessLogin = function(data) {
        if (data.success == true)
            document.location.reload();
        else {
            $("#login_status_text").html("Неверный логин/пароль.");
        }
    }
    
    
    
    
});


