/*
  This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
  (see http://creativecommons.org/licenses/by-nc-sa/3.0)
*/

function updateMenu() {
  if($F('Farmer','fnmurl')) {
    $('fnmMList').innerHTML = genList();
    document.title = $f('Farmer').title;
    $('fnmplugPOPOUT').href = $F('Farmer','fnmurl').value;
  }
  if($F('Farmer','fnmnohits')) {
    if($F('Farmer','fnmnocore')) {
      $S('fnmplugCALC').background = "url(/public/images/process_add.gif)";
    } else {
      $S('fnmplugCALC').background = "url(/public/images/process_accept.gif)";
    }
  } else {
    $S('fnmplugCALC').background = "url(/public/images/process_add.gif)";
  }
  $S('fnmplugCALC').backgroundRepeat = "no-repeat";
}

function runCalc(url) {
  mythis = this;
  var ref = "http://fn.causal.ca/news/xml";
  ref = ref + "?url=" + url;
  makeRequest(ref, "", mythis);
}

function xmlAction(data) {
}

function genList() {
  var text = "<table class='fnmplugBodyLC'>\n";
  var i = 0;
  for(; $F('Farmer','fnmlink'+i); ++i) {
    text += "  <tr class='fnmListItem'>\n";
    text += "   <td class='fnmListItemCo'>";
    text += "<a class='fnmmenu' href=\"javascript:changeFrame(";
    text += "'" + $F('Farmer','fnmlink'+i).value + "')\">";
    text += $F('Farmer','fnmid'+i).value + "</a>  ";
    text += "</td>\n";
    text += "   <td class='fnmListItemTitle'>";
    text += $F('Farmer','fnmname'+i).value;
    text += "</td>\n";
    text += "  </tr>\n";
  }
  text += "</table>\n";
  return text;
}

function toggle(v) {
  $S(v).display = ($S(v).display=='none'?'block':'none');
}

function XY(e,v) {
  var z = browser('msie')?Array(event.clientX+document.body.scrollLeft,event.clientY+document.body.scrollTop):Array(e.pageX,e.pageY);
  return (z[zero(v)]);
}

function getHeight(o) {
  return($(o).clientHeight);
}

function setHeight(o, v) {
  $S(o).height = v + "px";
  return;
}

function getWidth(o) {
  return($(o).clientWidth);
}

function setWidth(o, v) {
  $S(o).width = v + "px";
  return;
}

function zero(v) {
  v = parseInt(v);
  return (!isNaN(v)?v:0);
}

function zindex(d) {
  d.zIndex = zINDEX++;
}

var zINDEX=15,stop=1,rstop=1;

function HSVslide(o,e) {
  function drag(e) { 
    if(!stop) {
      ds.left=XY(e)+oX-eX+'px'; ds.top=XY(e,1)+oY-eY+'px';
    }
  }
  if(o != '') {
  if(stop) {
    stop='';
    var ds=$S(o);
    var oX=parseInt(ds.left), oY=parseInt(ds.top), eX=XY(e), eY=XY(e,1);
    zindex($S(o));
    document.onmousemove=drag;
    document.onmouseup=
    function() {
      stop=1;
      document.onmousemove='';
      document.onmouseup='';
    };
    drag(e);
  }
  }
}

function HSVresize(o,e) {
  function rdrag(e) { 
    if(!rstop) {
      setHeight(o+"Body",XY(e,1)+oH-eX);
      setWidth(o,XY(e)+oW-eY);
    }
  }
  if(o != '') {
  if(rstop) {
    rstop='';
    var oH=getHeight(o+"Body"), eX=XY(e,1), oW=getWidth(o), eY=XY(e);
    document.onmousemove=rdrag;
    document.onmouseup=
    function() {
      rstop=1;
      document.onmousemove='';
      document.onmouseup='';
    };
    rdrag(e);
  }
  }
}
