﻿$(document).ready(function() {
    //Email stuff**************************************
    var name = document.getElementById('emailName');
    var email = document.getElementById('emailAdd');
    var what = document.getElementById('emailMsg');
    var nameOn = 1;
    var whatOn = 1;
    var emailOn = 1;

    //open box
    $('#openEmail').click(function() { $('#emailForm').attr('class', ''); });
    //close box
    $('#emailClose').click(function() { $('#emailForm').attr('class', 'hide'); });
    //empty on click
    $(name).focus(function() { if (nameOn == 1) { $(this).attr('value', ''); nameOn = 0; }; });
    $(email).focus(function() { if (emailOn == 1) { $(this).attr('value', ''); emailOn = 0; }; });
    $(what).focus(function() { if (whatOn == 1) { $(this).attr('value', ''); whatOn = 0; }; });

    //send email
    $('#emailSend').click(function() {

        //validation
         if (name.value == '' || name.value == 'your name') {
                $('#emailName').css('background-color', '#fac2c2');
         } else {
             if (email.value == '' || email.value == 'email address of recipiant') {
                $('#emailAdd').css('background-color', '#fac2c2');
            } else {
                $('#emailStatus').html('Sending...');
        //Call server side function
          PageMethods.sendMail(name.value, email.value, what.value, sent, fail);

     //   var email = {
     //       "api_key": "0hCYhWV9fseBGxoUMKgTiKKK81qYHvWD",
     //       "arguments": {
      //          "content": {
       //             "text/plain": "This is a test email"
       //         },
         //       "recipients": [
         //                       "nathanjamal@ymail.com",
         //                       "nathan@wallacehcl.com"
         //                        ],
          //      "headers": {
           //         "subject": "hello",
           //         "from": "hello@somewhere.com",
            //        "reply-to": "no-reply@somewhere.com"
            //    }
           // }
      //  };

      //  var encoded = $.toJSON(email);
      //  alert('come this far');

       // $.ajax({
       //     type: "POST",
       //     url: "http://api.postageapp.com/v.1.0/send_message.json",
        //    data: encoded,
        //    dataType: 'json',
         //   contentType: "application/json; charset=utf-8",
         //   success: function() {
          //      alert("sent");
         //   },
           // error: function(encoded) {
          //  alert(encoded);
       //     }
      //  });

             }
          }
    });

    function sent() { $('#emailStatus').html('Sent'); }
    function fail() { $('#emailStatus').html('Failed'); }

});


//change text size
function resizeText(multiplier) {
    var bod = $('p', '.content');
    var current = $(bod).css('font-size');
    var newSize = parseFloat(current) + (multiplier * 0.5) + "px";
    var currentLH = $(bod).css('line-height');
    var newSizeLH = parseFloat(currentLH) + (multiplier * 0.5) + "px";
    $(bod).css('font-size', newSize);
    $(bod).css('line-height', newSizeLH);
};
