<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<style type="text/css">
#viewtester-wrapper {
    position: absolute;
    top: 2em;
    left: 2em;
    padding: 1em;
    z-index: 100;
    background-color: #ffa;
    border: 1px solid #000;
    font-family: monospace;
}
#viewtester-title {
    font-size: 130%;
    margin:0;
    padding: 0;
    border-bottom: 1px solid #000;
    margin-bottom: .5em;
}
#viewtester-wrapper form {
    border-top: 1px dashed #000;
    margin-top: .5em;
    padding-top: .5em;
}
#viewtester-wrapper form .errormessage {
    color: red;
    font-weight: bold;
}
#viewtester-wrapper th {
    font-size: 90%;
    font-style: italic;
    text-align: left;
}
#viewtester-wrapper select, #viewtester-wrapper input {
    width: 250px;
    padding: .2em;
}
#viewtester-wrapper select {
    width: 261px;
}
#viewtester-wrapper input[type=submit] {
    width: 7em;
    vertical-align: top;
}
</style>
<script type="text/javascript">
  function createCookie(name,value,days) {
    if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
  }

  function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }

  function eraseCookie(name) {
	createCookie(name,"",-1);
  }

  function viewtester_init(){
    jQuery('#viewtester-title').toggle(
      function(){jQuery('#viewtester-innerwrapper').hide()}, 
      function(){jQuery('#viewtester-innerwrapper').show()}
    );
    jQuery('#viewtester-wrapper')
         .css({ top: readCookie("tm-postop")*1, left: readCookie("tm-posleft")*1 })
         .draggable({ stop: function (event, ui) {
             createCookie("tm-posleft", ui.position.left, 100);
             createCookie("tm-postop", ui.position.top, 100);
           } 
         });
    jQuery('#viewtester-wrapper form').submit(function(){
      jQuery.ajax({
        context: this,
        type: 'post',
        url: jQuery(this).attr('action'),
        data: jQuery(this).serialize(),
        success: function(data){
          jQuery('#viewtester-wrapper').replaceWith(data);
          viewtester_init();
        },
        error: function(xhr, textStatus){
          jQuery(this).find('.errormessage').html(xhr.responseText);
        },
        dataType: 'html'
      });
      return false;
    });
  }
  jQuery(document).ready(function(){
    viewtester_init();
  });
</script>
