﻿webService = "WsCalculadora"; var i = 0; $(function () { ChangeMenu(2); $("input[name=limpar]").hide(); $("p.info").hide() }); function Calcular() { if ($("p.info").is(":hidden")) { $("p.info span").html("Aguarde 15 segundos..."); i = 15; $("#resultados fieldset").hide(); $("p.info").show() } else { if (i > 0) { i--; $("p.info span").html("Aguarde " + i + " segundos...") } } if (i != 0) { setTimeout("Calcular()", 1000) } else { CalcularBS(); $("p.info").hide() } } function CalcularBS() { if (Validar() == false) { return } var a = "{strike : " + $("#strike").val() + ", precoacao : " + $("#precoacao").val() + ", volatilidade : " + $("#volatilidade").val().replace("%", "") + ", taxajuros : " + $("#taxajuros").val().replace("%", "").replace(",", ".") + ", tempo : " + $("#tempo").val() + "}"; ajaxProxy(webService, "Calcular", a, function (b) { if (b.Error) { alert(b.Error) } else { $("#resultado tbody").append("<tr><td>" + $("#strike").val() + "</td><td>" + b.Gamma + "</td><td>" + b.Delta + "</td><td>" + b.Theta + "</td><td>" + b.PrecoTeorico + "</td></tr>"); $("#resultado tbody tr:even").css("background-color", "#F2F5EB"); $("input[name=limpar]").show(); $("#resultados fieldset").show() } }) } function Validar() { var a = true; $("#variaveis fieldset p input").each(function () { if ($(this).val() == "") { alert("Preencha o campo " + $(this).prev().prev().html() + "."); $(this).focus(); a = false } }); return a } function Limpar() { $("#resultado tbody").html(""); $("input[name=limpar]").hide() } function handledecimal(b) { var a = b.value; while (a.indexOf(",") != -1) { a = a.replace(",", ".") } while (a.indexOf(".") != a.lastIndexOf(".")) { a = a.substring(0, a.indexOf(".")) + a.substring(a.indexOf(".") + 1) } b.value = a };
