﻿/// <reference path="jQuery/jquery-1.4.1-vsdoc.js" />

$().ready(function() {
    ValidateForm();
    $("#btnSend").click(function() {
        ValidateForm();
        var isValid = $("#AdviceForm").valid();
        if (isValid == false) {
            $("#boxError").show();
            window.setTimeout(function() {
                $("#boxError").fadeOut(500);
            }, 1500);
        }
        return isValid;
    });
    $(".spanHelpTextPhone").click(function() {
        if ($(".FormHelpTextPlate").is(":visible")) {
            $(".FormHelpTextPlate").fadeOut();
        } else {
            var left = $(this).position().left;
            var top = $(this).position().top;
            var height = $(".FormHelpTextPlate").height() / 2;
            $(".FormHelpTextPlate").css("top", top - height);
            $(".FormHelpTextPlate").css("left", left + 15);
            $(".FormHelpTextPlate").fadeIn();
        }
    });
    $(".FormHelpTextPlateClose").click(function() {
        $(".FormHelpTextPlate").fadeOut();
    });
});

function AdviceSuccess(content) {
    $(".FormProgressPlate").hide();
    $("#btnSend").removeAttr("disabled");
    if (content.get_data().toString().toLowerCase() == 'true') {
        $("#boxSuccess").show();
        $("#Company").val("");
        $("#Name").val("");
        $("#SName").val("");
        $("#Email").val("");
        $("#Phone").val("");
        $("#PhoneNight").val("");
        $("#Message").val("");
        $("#ContactTime").val("");
        $("#ReceiveNewsletter").attr("checked", "checked");
        window.setTimeout(function() {
            $("#boxSuccess").fadeOut(500);
        }, 5500);

    }
    else {
        $("#boxError").show();
        window.setTimeout(function() {
            $("#boxError").fadeOut(500);
        }, 1500);
    }
}

function AdviceValidate() {
    ValidateForm();
    $(".FormProgressPlate").show();
    $("#btnSend").attr("disabled", "disabled");
}
function ValidateForm() {
    return $("#AdviceForm").validate({
        rules: {
            Name: "required",
            SName: "required",
            Phone: { regex: '^(([+]\\d{2}[ ][1-9]\\d{0,2}[ ])|([0]\\d{1,3}[-]))((\\d{2}([ ]\\d{2}){2})|(\\d{3}([ ]\\d{3})*([ ]\\d{2})+)|(\\d{5,8})+)$' },
            PhoneNight: { regex: '^(([+]\\d{2}[ ][1-9]\\d{0,2}[ ])|([0]\\d{1,3}[-]))((\\d{2}([ ]\\d{2}){2})|(\\d{3}([ ]\\d{3})*([ ]\\d{2})+)|(\\d{5,8})+)$' },
            Email:
                {
                    required: true,
                    email: true
                },
            Message: "required"
        },
        messages: {
            Name: "",
            SName: "",
            Phone: "",
            PhoneNight: "",
            Email: "",
            Message: "",
            ReceiveNewsletter: ""
        }
    });
}
