// JavaScript Document//live comment preview
$(document).ready(function() {
  $('#whatFor').one('focus',function() {
    $('#mysubmit').parent().parent().after('<tr><td colspan="2"><div id="preview-box"><div class="small">Live Preview</div><table id="results" width="100%" cellspacing="4" cellpadding="6"><tr style="background-color: rgb(204, 204, 204);"><td><div id="whatForPreview"></div></td><td><div id="whoForPreview"></div></td><td><div id="cityPreview"></div></td><td><div id="statePreview"></div></td><td><div id="feelPreview"></div></td><td><div id="resultPreview"></div></td></tr></table></div></td></tr>');
  });
  var $comment = '';
  $('#whatFor').keyup(function() {
    $comment = $(this).val();
    $comment = $comment.replace(/\n\n+/g, '<br /><br />').replace(/\n/g, "<br />").replace(/(<\/?)script/g,"$1noscript");
    $('#whatForPreview').html( $comment );
  });
  $('#whoFor').keyup(function() {
    $comment = $(this).val();
    $comment = $comment.replace(/\n\n+/g, '<br /><br />').replace(/\n/g, "<br />").replace(/(<\/?)script/g,"$1noscript");
    $('#whoForPreview').html( $comment );
  });
  $('#city').keyup(function() {
    $comment = $(this).val();
    $comment = $comment.replace(/\n\n+/g, '<br /><br />').replace(/\n/g, "<br />").replace(/(<\/?)script/g,"$1noscript");
    $('#cityPreview').html( $comment );
  });
  $('#state').keyup(function() {
    $comment = $(this).val();
    $comment = $comment.replace(/\n\n+/g, '<br /><br />').replace(/\n/g, "<br />").replace(/(<\/?)script/g,"$1noscript");
    $('#statePreview').html( $comment );
  });
  $('#feel').keyup(function() {
    $comment = $(this).val();
    $comment = $comment.replace(/\n\n+/g, '<br /><br />').replace(/\n/g, "<br />").replace(/(<\/?)script/g,"$1noscript");
    $('#feelPreview').html( $comment );
  });  
  $('#result').keyup(function() {
    $comment = $(this).val();
    $comment = $comment.replace(/\n\n+/g, '<br /><br />').replace(/\n/g, "<br />").replace(/(<\/?)script/g,"$1noscript");
    $('#resultPreview').html( $comment );
  });  
});
