var myWidth = 0;
var myHeight = 0;
var divName = "";

function currentSize()
{
  if(typeof(window.innerWidth) == 'number'){
    // Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  }
  else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
    // IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  }
  else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
    // IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if (navigator.appName == "Netscape"){
    myWidth -= 4;
    myHeight -= 4;
  }
  try {
    if (divName.length > 0)
      resize_div();
  }
  catch(err){
  }
}
function lcase(mvar)
{
  var aa=new String(mvar.value);
  mvar.value=aa.toLowerCase();
  return;
}
function ucase(mvar)
{
  var aa=new String(mvar.value);
  mvar.value=aa.toUpperCase();
  return;
}
var xml;
var pending=new Array();   // next request to send
var target=new Array();    // next target div to put data in
var pproc=new Array();     // next post processing code
var mwait=0;                 // 0- no wait 1- wait

function ajax(page, mtarget, mproc)
{
             // page=section.name : target is div id tag to get the html
             // mproc is post processing
  if (mwait > 0){
    pending.push("G");
    pending.push(page);
    pending.push(mtarget);
    pending.push(mproc);
    return;
  }
  if (page == "dummy"){
    ajax_pproc(mproc, page, mtarget);
    return;
  }
  mwait=1;
  xml=null;
  target.push(mtarget);
  pproc.push(mproc);
  url="ajax.php?"+page;
//alert(url);
  if (window.XMLHttpRequest){      // code for Firefox, Opera, IE7, etc.
    xml=new XMLHttpRequest();
  }
  else if (window.ActiveXObject){  // code for IE6, IE5
    xml=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (xml != null){
    xml.onreadystatechange=ajax_rec;
    xml.open("GET",url,true);
    xml.send(null);
//alert('Sent '+url);
  }
  else{
    alert("Your browser does not support XMLHTTP.");
  }
}
function ajax_post(parms, mtarget, mproc)
{
       // page=section.name : target is div id tag to get the html
  if (mwait > 0){
    pending.push("P");
    pending.push(parms);
    pending.push(mtarget);
    pending.push(mproc);
    return;
  }
  mwait=1;
  xml=null;
  target.push(mtarget);
  pproc.push(mproc);
  url="ajax.php";
//  parms="target=" + mtarget + "&" + parms;
//alert(url);
  if (window.XMLHttpRequest){      // code for Firefox, Opera, IE7, etc.
    xml=new XMLHttpRequest();
  }
  else if (window.ActiveXObject){  // code for IE6, IE5
    xml=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (xml != null){
    xml.onreadystatechange=ajax_rec;
    xml.open("POST",url,true);
    xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//    if (navigator.platform != "Win32" || (/MSIE 
// d+.d+;/.test(navigator.userAgent)) == false
// || (/Windows NT 5.0[;)]/.test(navigator.userAgent)) == false) {
//alert("SENT LENGTH");
//      xml.setRequestHeader("Content-length", parms.length);
//      xml.setRequestHeader("Connection", "close");
//    }
//alert("SEND: "+parms);
    xml.send(parms);
//alert('Sent '+url);
  }
  else{
    alert("Your browser does not support XMLHTTP.");
  }
}
function ajax_rec()        // receive data from server
{
  if (xml.readyState == 4){     // 4 = "loaded"
    if (xml.status == 200){     // 200 = "OK"
      var html=new String();
      var mtarget=new String();
      var xx=new Array();
//      html=xml.responseText;
      html=unescape(xml.responseText);
//alert("REC: "+html);
      mtarget=target.shift();
      mproc=pproc.shift();
      if (mtarget.substring(0,1) != "_")
        document.getElementById(mtarget).innerHTML=html;
//alert(mtarget + "**" + mproc);
      if (mproc.length > 0){
        if (mproc.substring(0,1) == 'A')
          ajax_pprocA(mproc, html, mtarget);   // post processing routine
        else
          ajax_pproc(mproc, html, mtarget);   // post processing routine
      }
    }
    else
      alert("Problem retrieving data:" + xml.statusText);
    mwait=0;
    if (pending.length > 0){
      type=pending.shift();
      html=pending.shift();
      mtarget=pending.shift();
      mproc=pending.shift();
      if (type == "P")    // POST?
        ajax_post(html,mtarget,mproc);
      else
        ajax(html,mtarget,mproc);
    }
  }
  return;
}
function mgoto(mprog)
{
  open(mprog,"_parent");
  return;
}
function okdelete(mform,mbutton)
{
  if (confirm("Are you sure you want to DELETE")){
    mbutton.value="YES";
    mform.submit();
    return true;
  }
  return false;
}
function menu_over(mid)
{
  xx=document.getElementById(mid);
  xx.style.visibility="visible";
  xx=document.getElementsByTagName("div");
  e="";
  for (i=0;i<xx.length;i++){
    if (xx[i].id.length > 0 && xx[i].id.substring(0,2) == "m_"){
      if (xx[i].id != mid)
        xx[i].style.visibility="hidden";
    }
  }
  return;  
}
function menu_click(mid)
{
  xx=document.getElementById(mid);
  xx.style.visibility="hidden";
  return;  
}
var brow_bg_color="";
var brow_color="";
function brow_over(id)
{
  xx=document.getElementById(id);
  brow_bg_color=xx.style.backgroundColor;
  xx.style.backgroundColor="blue";
  brow_color=xx.style.color;
  xx.style.color="white";
}
function brow_out(id)
{
  xx=document.getElementById(id);
  xx.style.backgroundColor=brow_bg_color;
  xx.style.color=brow_color;
}
var ms_sel=new Array("","","","","");
function ms_click(mid, mgrp)
{
// grp - 0-4 : identifies group of buttons : default is 0
//
  msel=ms_sel[mgrp];
  if (msel.length > 0){
    xx=document.getElementById(msel);
    if (xx != undefined)
      xx.src="../BUTTONS/n"+msel+".png";
  }
  xx=document.getElementById(mid);
  ms_sel[mgrp]=mid;
  xx.src="../BUTTONS/s"+mid+".png";
//document.getElementById('oink').innerHTML="Click:"+mid+"*"+ms_sel[mgrp];
  return;
}
function ms_over(mid, mgrp)
{
//document.getElementById('oink').innerHTML="Over:"+mid+"*"+ms_sel[mgrp];
  xx=document.getElementById(mid);
  xx.src="../BUTTONS/o"+mid+".png";
  return;  
}
function ms_out(mid, mgrp)
{
  msel=ms_sel[mgrp];
  xx=document.getElementById(mid);
  if (msel == mid)
    xx.src="../BUTTONS/s"+mid+".png";
  else
    xx.src="../BUTTONS/n"+mid+".png";
//document.getElementById('oink').innerHTML="Out:"+mid+"*"+ms_sel[mgrp];
  return;  
}
function encode(a)
{
  a=encodeURIComponent(a);
  return(a);
}
function focus(id)
{
  document.getElementById(id).focus();
}
function visible(id, status)
{
  document.getElementById(id).style.visibility=status;
}
function efocus()
{
  xx=document.getElementsByName("edit_form");
  if (xx.length > 0){
    for (i=0;i<xx[0].elements.length;i++){
      if (xx[0].elements[i].type != "hidden"){
        xx[0].elements[i].focus();
        break;
      }
    }
  }
}
function xsave(mform)
{
  a="";
  xx=document.getElementById(mform);
  for (j=0;j<xx.elements.length;j++){
    bb=xx.elements[j].name;
    if (bb == "aa[]")
      a=a + "&aa[]=" + encode(xx.elements[j].value);
    if (bb == "mfields")
      a=a + "&mfields=" + encode(xx.elements[j].value);
    if (bb == "refno")
      a=a + "&refno=" + encode(xx.elements[j].value);
    if (bb == "wiki")
      a=a + "&wiki=" + encode(xx.elements[j].value);
    if (bb == "vars")
      a=a + "&vars=" + encode(xx.elements[j].value);
    if (bb == "is_sql")
      a=a + "&sql=" + encode(xx.elements[j].value);
  }
  return(a);
}
function link(a,mtarget)  // used in AJAX links : target can be set with // links
{
  ajax('p='+a,mtarget,"");
}
function mga(mgroup,action,comment)
{
  aa=action;
  mpos=aa.indexOf('&');
  if (mpos >= 0)
    aa=aa.substr(0,mpos);
  mpos=aa.indexOf('.');
  if (mpos >= 0)
    aa=aa.substr(mpos+1);
  aa=aa.replace('&trade;','');
  pageTracker._trackEvent(mgroup, aa, comment);
}
