Advertisement
gilcierweb

Calculo Fumante

Feb 15th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 8.07 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.         <title>Fumo</title>
  6.         <!-- jquery for equal height elements -->
  7.         <script type="text/javascript" src="js/jquery-1.6.4.min.js"></script>
  8.         <script type="text/javascript" src="js/formee.js"></script>
  9.  
  10.         <!-- css for structure -->
  11.         <link rel="stylesheet" href="css/formee-structure.css" type="text/css" media="screen" />
  12.  
  13.         <!-- css for style -->
  14.         <link rel="stylesheet" href="css/formee-style.css" type="text/css" media="screen" />
  15.         <link rel="stylesheet" href="css/estilos.css" type="text/css" media="screen" />
  16.  
  17.     </head>
  18.     <body>
  19.         <div id="frm">
  20.             <form class="formee" action="" method="post" id="formFumante">
  21.                 <fieldset>
  22.                     <legend>Perguntas</legend>
  23.                     <div class="grid-3-12">
  24.                         <label>Idade <em class="formee-req">*</em></label>
  25.                         <input type="text" name="idade" id="idade" class="formee-small" value="" />
  26.                     </div>
  27.                     <div class="clear"></div>
  28.                     <div class="grid-6-12">
  29.                         <label>Sexo <em class="formee-req">*</em></label>
  30.                         <ul class="formee-list">
  31.                             <li><input name="sexo" type="radio" value="M"/><label>Masculino</label></li>
  32.                             <li><input name="sexo" type="radio" value="F"/><label>Feminino</label></li>
  33.                         </ul>
  34.                     </div>
  35.                     <div class="clear"></div>
  36.                     <div class="grid-3-12">
  37.                         <label>Preço do maço de cigarro <em class="formee-req">*</em> R$</label>
  38.                         <input type="text" name="precocigarro" id="precocigarro" class="formee-small" value="3,50" />                        
  39.                     </div>
  40.                     <div class="clear"></div>
  41.                     <div class="grid-3-12">
  42.                         <label>Quantos maços fuma por dia ? <em class="formee-req">*</em></label>
  43.                         <input type="text" name="qtemacos" id="qtemacos" class="formee-small" value="" />
  44.                     </div>
  45.                     <div class="clear"></div>
  46.                     <div class="grid-3-12">
  47.                         <label>Há quantos anos você fuma ? <em class="formee-req">*</em></label>
  48.                         <input type="text" name="anosfumo" id="anosfumo" class="formee-small" value="" />
  49.                     </div>
  50.                     <div class="grid-12-12">
  51.                         <input type="submit" title="Calcular" value="Calcular" />
  52.                     </div>
  53.  
  54.  
  55.                 </fieldset>
  56.             </form>
  57.         </div>
  58.  
  59.         <div id="callBack">
  60.  
  61.             <h1>Respostas</h1>
  62.             <div class="left">
  63.                 <p>Carga tabágica <strong id="ct"></strong> maços.ano</p>
  64.                 <p>Você gasta:</p>
  65.                 <p>Por mês: <strong id="gastomes"></strong></p>
  66.                 <p>Por Ano: <strong id="gastoano"></strong></p>
  67.                 <p>Você já gastou o total de: <strong id="gastototal"></strong></p>
  68.             </div>
  69.  
  70.             <div class="left"> <p>Quantidade de cigarros que você já fumou:</p>            
  71.                 <p>Por mês: <strong id="qcfmes"></strong> cigarros</p>
  72.                 <p>Por Ano: <strong id="qcfano"></strong> cigarros</p>
  73.                 <p>Durante toda sua vida: <strong id="qcfvida"></strong> cigarros</p>
  74.             </div>
  75.             <div class="clear"></div>
  76.             <p>Se tivesse aplicado na poupança, você teria: <strong id="poupanca"></strong></p>
  77.             <p>Se tivesse aplicado com rendimentos de 1% ao mês, você teria: <strong id="rendimento"></strong></p>
  78.             <p>Altair da Silva Costa Jr. - cirurgiatoracica@uol.com.br</p>
  79.             <span class="btnOk">
  80.                 <a href="javascript:;" title="Novo Calculo" class="formee-button ok">Novo Calculo</a>
  81.             </span>
  82.  
  83.         </div>
  84.  
  85.         <script type="text/javascript" src="js/accounting.min.js"></script>
  86.         <script type="text/javascript">
  87.             $("#callBack").hide();          
  88.            
  89.             function addCommas(nStr) {
  90.                 nStr += '';
  91.                 var x = nStr.split(',');
  92.                 var x1 = x[0];
  93.                 var x2 = x.length > 1 ? '.' + x[1] : '';
  94.                 var rgx = /(d+)(d{3})/;
  95.      
  96.                 while (rgx.test(x1)) {
  97.                     x1 = x1.replace(rgx, '$1' + ',' + '$2');
  98.                 }
  99.      
  100.                 return x1 + x2;
  101.             }
  102.        
  103.             $(function (){
  104.  
  105.                 $("#formFumante").submit(function (){
  106.                     var msg = "";
  107.                     var teste = false;
  108.                    
  109.                     var cargatabagica=$("input[id='qtemacos']").val()*$("input[id='anosfumo']").val();
  110.                    
  111.                     var gastomes = $("input[id='qtemacos']").val()*30*addCommas($("input[id='precocigarro']").val());
  112.                     var gastoano = gastomes*12;
  113.                     var gastototal = gastoano*$("input[id='anosfumo']").val();
  114.                      
  115.                     var qcfmes = ($("input[id='qtemacos']").val()*20)*30;
  116.                     var qcfano = qcfmes*12;
  117.                     var qcfvida = qcfano*$("input[id='anosfumo']").val();
  118.                    
  119.                     var poupanca = gastomes * (Math.pow((1 + 0.0065),$("input[id='anosfumo']").val()*12)-1)/0.0065 ;                    
  120.                     var rendimento = gastomes * (Math.pow((1 + 0.01),$("input[id='anosfumo']").val()*12)-1)/0.01;
  121.              
  122.                     $('#ct').html(cargatabagica);
  123.                     $('#gastomes').html('R$ '+accounting.formatMoney(gastomes,""));
  124.                     $('#gastoano').html('R$ '+accounting.formatMoney(gastoano,""));
  125.                     $('#gastototal').html('R$ '+accounting.formatMoney(gastototal,""));
  126.                    
  127.                     $('#qcfmes').html(accounting.formatMoney(qcfmes,"",  ".", "."));
  128.                     $('#qcfano').html(accounting.formatMoney(qcfano,"",  ".", "."));
  129.                     $('#qcfvida').html(accounting.formatMoney(qcfvida,"",  ".", "."));
  130.                    
  131.                     $('#poupanca').html(accounting.formatMoney(poupanca,"R$ "));
  132.                     $('#rendimento').html(accounting.formatMoney(rendimento,"R$ "));
  133.  
  134.                     if ($("input[id='idade']").val() == "") {
  135.                         teste = true;                        
  136.                     };
  137.                     if ($("input[id='precocigarro']").val() == "") {
  138.                         teste = true;
  139.                     };
  140.                     if ($("input[id='sexo']").val() == "") {
  141.                         teste = true;
  142.                     };
  143.                     if ($("input[id='qtemacos']").val() == "") {
  144.                         teste = true;
  145.                     };
  146.                     if ($("input[id='anosfumo']").val() == "") {
  147.                         teste = true;
  148.                     };
  149.                     if (teste) {
  150.                         msg = "Todas as perguntas devem ser respondidas!";
  151.                     }
  152.  
  153.                     if (msg){
  154.                         alert(msg);
  155.                         //return false;
  156.                     } else {                  
  157.                         $("#frm").hide();    
  158.                         $("#callBack").fadeIn();
  159.                         //document.formFumante.reset();                                            
  160.                     }
  161.                        
  162.                     return false;  
  163.                 });
  164.  
  165.                 $(".ok").click(function(){
  166.                     document.forms[0].reset();
  167.                     $("#callBack").hide();
  168.                     $("#frm").fadeIn();
  169.                 });
  170.             });
  171.         </script>
  172.  
  173.     </body>
  174. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement