﻿var emailHolder = "Digite aqui o seu e-mail";

var leftAlert = (screen.width - 447) / 2;
var topAlert = (screen.height - 300) / 2;

var top = (screen.height - 86) / 2;

function Success(content) {
    switch (content.Ret) {
        case 1:
            OpenAlert("Success", content.Msg);
            $("#email").val("");
            break;
        case -1:
            OpenAlert("Error", content.Msg);
            break;
    }
}

function OpenAlert(type, text) {
    switch (type) {
        case "Success":
            $(".Alert .Top .Text").text("Obrigado!");

            break;
        case "Error":
            $(".Alert .Top .Text").text("Atenção!");
            break;
    }

    $(".Alert .Middle .Text").text("").html(text);
    $(".Alert").animate(
        {
            'top': topAlert + 'px',
            'left': leftAlert + 'px'
        }, 1);
    $(".Alert").show();
}

function IsWide()
{
    if(screen.width <= 1024)
        return false;
    else 
        return true;
}

function GetCorrectImage()
{
    if(IsWide())
        return '../Content/Images/Backgrounds/wide.jpg';
    else
       return '../Content/Images/Backgrounds/square.jpg';
}

$(function () {
    $(".Content").animate({
        'padding-top' : top -50 + 'px'
    }, 1);

    var imageName = GetCorrectImage();

    $('body').bgStretcher({
        images: [imageName],
        imageWidth : IsWide() ? 1280 : 1024,
    });
    $("#close").click(function () {
        $(".Alert").hide();
    });

    $("#send").click(function(){
        $.ajax({
            type: "POST",
            url: "Index.aspx/Send",
            contentType: "application/json; charset=utf-8",
            data: "{ 'email' : '" + $("#email").val() + "' }",
            dataType: "json",
            success: function (result) {
                var content = eval('(' + result.d + ')');
                Success(content);
            }
        });
    });
});
