var ow = null;
var oh = null;
var cw = null;
var ch = null;

function pa_toggle(id,id1) {
    var elem = pa_get_element(id);
    var pia = pa_get_element(id1);
    elem.style.display = (elem.style.display == "block") ? "none" : "block";
    pia.innerHTML = (pia.innerHTML == "show") ? "hide" : "show";
}

function pa_get_element(id) {
    var elem = (document.getElementById) ?
        document.getElementById(id) : ((document.all) ?
            document.all[id] : null);

    return(elem);
}

function pa_process_comment_submit(obj) {
  obj.argument.btn.disabled = false;

  if (obj.status !== 200) {
    alert("Unexpected server error.  Please try again in a moment.");
    return false;
  }

  obj.argument.name.value = obj.argument.name.value.replace(/</g, "&lt;");
  obj.argument.name.value = obj.argument.name.value.replace(/>/g, "&gt;");
  obj.argument.comment.value = obj.argument.comment.value.replace(/</g, "&lt;");
  obj.argument.comment.value = obj.argument.comment.value.replace(/>/g, "&gt;");

  var tb = YAHOO.util.Dom.get(obj.argument.tbodyId);

  var tr = tb.insertRow(tb.rows.length);
  var td = tr.insertCell(0);
  td.className = "fv_color_3 pad";

  var d = new Date();
  var ampm = "AM";
  var hour = d.getHours();
  if (hour > 12) {
    hour -= 12;
    ampm = "PM";
  }
  var minutes = d.getMinutes()+"";
  if (minutes.length == 1) {
    minutes = "0"+minutes;
  }

  var month = {
    0 : 'Jan', 1 : 'Feb', 2 : 'Mar', 3 : 'Apr', 4 : 'May', 5 : 'Jun',
    6 : 'Jul', 7 : 'Aug', 8 : 'Sep', 9 : 'Oct', 10 : 'Nov', 11 : 'Dec'
  };

  var mydate = hour+":"+minutes+" "+ampm+" on "+month[d.getMonth()]+" "+
    d.getDate()+", "+d.getFullYear();

  td.innerHTML = obj.argument.comment.value + "<br /><br />- "+
    obj.argument.name.value+" @ "+mydate

  obj.argument.name.value = "";
  obj.argument.comment.value = "";
}

function pa_submit_comment(name,comment,seed,btn,idx,tbodyId) {
  var name    = YAHOO.util.Dom.get(name);
  var comment = YAHOO.util.Dom.get(comment);
  var seed    = YAHOO.util.Dom.get(seed);

  if (name.value.length <= 0 || comment.value.length <= 0) {
    alert("The 'Name' or 'Comment' field may not be empty");
    return false;
  }

  btn.disabled = true;

  var n = encodeURIComponent(name.value);
  var c = encodeURIComponent(comment.value);
  var s = encodeURIComponent(seed.value);
  var i = encodeURIComponent(idx);

  YAHOO.util.Connect.asyncRequest(
    "GET",
    "pac.fcgi?q=aXfdZ2Bki0&n="+n+"&c="+c+"&s="+s+"&i="+i+"&ts="+new Date().getTime(),
    {
      success : pa_process_comment_submit,
      failure : pa_process_comment_submit,
      timeout : 120000,
      argument : {
        btn     : btn,
        name    : name,
        comment : comment,
        tbodyId : tbodyId
      }
    }
  );
}

function pa_set_w_h(id,w,h) {
    var imgp = pa_get_element(id);
    var hl = pa_get_element("hl");

    if (ow == null || oh == null) {
        ow = imgp.getAttribute("width");
        oh = imgp.getAttribute("height");
    }

    if (w == ow && h == oh) return;

    if (w == cw || h == ch) {
        cw = ow;
        ch = oh;
        imgp.style.width = ow;
        imgp.style.height = oh;
        imgp.setAttribute('width',ow);
        imgp.setAttribute('height',oh);
        hl.innerHTML = "larger";
    } else {
        cw = w;
        ch = h;
        imgp.style.width = w;
        imgp.style.height = h;
        imgp.setAttribute('width',w);
        imgp.setAttribute('height',h);
        hl.innerHTML = "smaller";
    }
}
