﻿$(document).ready(function() {
    $("#thecontent").keyup(CountWords);
    $("#RecipientName").keyup(UpdateOpening);
    CountWords();
    UpdateOpening();
});
function UpdateOpening() {
    if ($("#RecipientName").val() != "")
        $("#opening").text($("#RecipientName").val());
    else
        $("#opening").text("[loved recipient]");
}
function CountWords() {
    var s =  $.trim($("#thecontent").val());
    var ct = s.length > 0 ? s.split(' ').length : 0;
    $("#wrds").text((750 - ct) + " words left").css("color", 750 - ct >= 0 ? "#77c2ec" : "red");
    $("#wrds2").text((750 - ct) + " words left").css("color", 750 - ct >= 0 ? "#77c2ec" : "red");
}
