 function createWindow(cUrl,cName,cFeatures) {
 //alert('New window called');
 var xWin = window.open(cUrl,cName,cFeatures)
 }

function popInfo(c,s) {
//  javascript:createWindow('displayNotes.php?chid=6&sid=68','guide','')
  createWindow('displayNotes.php?chid='+c+'&sid='+s,'guide','');
}

// Function to 'activate' images.
function imgOn(imgName,imgSrc) {
  document[imgName].src = imgSrc;
}

// Function to 'deactivate' images.
function imgOff(imgName,imgSrc) {
        document[imgName].src = imgSrc;
}

  var dottle;
  
  function getUserN() {
    return document.getElementById('usern').value;
  }
  
  function buildPage() {
   //alert("responded");
   var outp = req.responseText;
   
   document.getElementById(dottle).innerHTML=outp;
 }
 
 function openTabl() {
   dottle='editor';
   sel=document.getElementById('tabl');
   //alert('Found');
   tid=sel.options[sel.selectedIndex].value;
   //alert('tid is ' + tid );
   loadXMLDoc('openTable1.php?tabl=' + tid + '&opt=0');
 // location.href='openTable.php?tabl=' + tid + '&opt=0';
}

 function openTablA(tid) {
   dottle='editor';
   loadXMLDoc('openTable1.php?tabl=' + tid + '&opt=0');
}

 function beginopt(tid) {
   dottle='editor';
   sel=document.getElementById('chopt');
   //alert('Found');
   optid=sel.selectedIndex;
   //alert('optid is ' + optid );
   loadXMLDoc('openTable1.php?tabl=' + tid + '&opt=' + optid);
 // location.href='openTable.php?tabl=' + tid + '&opt=' + optid;
}

function findsim(fld,tabl) {
  dottle='y_' + fld;
  selID='z_' + fld;
  alpha=document.getElementById(selID).value;
  strng='tabl=' + tabl + '&alpha=' + alpha + '&fld=' + fld;
  //alert(strng);
  loadXMLDoc('lookItUp.php?' + strng);
  //loadXMLDoc('lookUpTarget.php?' + strng);
 //location.href='lookUpTarget.php?' + strng;
}

function findsimA(fld,tabl,zdot) {
  dottle='y_' + zdot;
  selID='z_' + zdot;
  alpha=document.getElementById(selID).value;
  strng='tabl=' + tabl + '&alpha=' + alpha + '&fld=' + fld + '&zdot=' + zdot;
  //alert(strng);
  loadXMLDoc('lookItUp.php?' + strng);
 // loadXMLDoc('lookUpTarget.php?' + strng);
 //location.href='lookUpTarget.php?' + strng;
}

 function chchoice(fld,tabl) {
   opt='z_' + fld;
   var ch=document.getElementById("choices");
   if (ch.options[ch.selectedIndex].value=='-1') {
     findsim(fld,tabl);
   } else {
     document.getElementById(opt).value = 
       ch.options[ch.selectedIndex].text;
   }
 }
 
function chchoiceA(fld,tabl,zdot) {
   opt='z_' + zdot;
   sel='ch_' + zdot;
   var ch=document.getElementById(sel);
   if (ch.options[ch.selectedIndex].value=='-1') {
     findsimA(fld,tabl,zdot);
   } else {
     document.getElementById(opt).value = 
       ch.options[ch.selectedIndex].text;
   }
 }
 
 function begedit (justme) {
   dottle='editor';
   var nought=1;
   nought=justme.length;
   var strng='opt=3';
   //alert('begedit called' + nought);
   for (var i=0;i<justme.length;i++) {
     na=justme.elements[i].name;
     strng=strng + '&' + na + '=';
     strng=strng + justme.elements[i].value;
   }
     //alert(strng);
     loadXMLDoc('openTable1.php?' + strng);
    // location.href='openTable.php?' + strng;
 }

 function updatentry (justme) {
   dottle='editor';
   var nought=1;
   nought=justme.length;
   var strng='opt=4';
   //alert('begedit called' + nought);
   for (var i=0;i<justme.length;i++) {
     na=justme.elements[i].name;
     ty=justme.elements[i].type;
     switch (ty) {
       case "select-one":
         strng=strng + '&' + na + '=';
         sel=justme.elements[i];
         strng=strng + sel[sel.selectedIndex].text;
         break;
       case "text":
         strng=strng + '&' + na + '=';
         strng=strng + justme.elements[i].value;
         break;
       case "textarea":
         strng=strng + '&' + na + '=';
         strng=strng + justme.elements[i].value;
         break;
       case "hidden":
         strng=strng + '&' + na + '=';
         strng=strng + justme.elements[i].value;
         break;
       case "checkbox":
         strng=strng + '&' + na + '=';
         if (justme.elements[i].checked) {
           strng=strng + justme.elements[i].value;
         } else {
           strng=strng + 'Off';
         }
     }
   }
   strng=strng + '&usern=' + document.getElementById('z_usern').value;
   strng=strng + '&jtmsg=' + document.getElementById('z_jtmsg').value;
     //alert(strng);
     loadXMLDocP('openTable.php',strng);
   //  location.href='openTable.php?' + strng;
 }
 
 function toggleActBack() {
   stat=document.getElementById('minor').checked;
   active=document.getElementById('z_active').value;
   //alert(stat + ' and ' + active);
   if (stat && active=='1') {
     document.getElementById('activate').checked=true;
   }
 }

 
 function toggleAct() {
   stat=document.getElementById('minor').checked;
   active=document.getElementById('z_active').value;
   //alert(stat + ' and ' + active);
   if (stat && active=='1') {
     document.getElementById('activate').checked=true;
   } else {
     document.getElementById('activate').checked=false;
   }
 }
 
  function viewTabl(optid) {
   dottle='editor';
   sel=document.getElementById('crop');
   //alert('Found view table (' + optid + ')');
   ty=sel.type;
   //alert('crop is type ' + ty);
   crop=sel[sel.selectedIndex].text;
   choice=sel[sel.selectedIndex].value;
   //alert('optid is ' + optid );
   strng='tabl=' + tid + '&opt=' + optid + '&crop=' + crop + '&choice=' + choice;
   loadXMLDoc('openTable1.php?' + strng);
 
 //  location.href='openTable.php?tabl=' + tid + '&opt=' + optid + '&crop=' + crop;
   
}

 function getentry (justme,opt) {
   dottle='editor';
   var nought=1;
   nought=justme.length;
   var strng='opt=' + opt;
   //alert('begedit called' + nought);
   for (var i=0;i<justme.length;i++) {
     na=justme.elements[i].name;
     ty=justme.elements[i].type;
     switch (ty) {
       case "checkbox":
         strng=strng + '&' + na + '=';
         if (justme.elements[i].checked) {
           strng=strng + justme.elements[i].value;
         } else {
           strng=strng + 'Off';
         }
         break;
       case "text":
         strng=strng + '&' + na + '=';
         strng=strng + justme.elements[i].value;
         break;
       case "hidden":
         strng=strng + '&' + na + '=';
         strng=strng + justme.elements[i].value;
         break;
       case "select-one":
         strng=strng + '&' + na + '=';
         sel=justme.elements[i];
         strng=strng + sel[sel.selectedIndex].text;
         break;
       //default: alert('Nae = ' + na + ' is ' + ty);
    }
   }
     //alert(strng);
     loadXMLDocP('openTable1.php',strng);
   //  location.href='openTable.php?' + strng;
 }
 
function getentryS (crop,period,target) {
   dottle='editor';
   var strng='opt=11&chem=-Choose-&crop=' + crop + '&period=' + period;
   var strng=strng + '&target=' + target + '&tabl=browse';
   strng=strng + '&jtmsg=' + document.getElementById('z_jtmsg').value;
   loadXMLDocP('openTable1.php',strng);
}
 
 function spanClick(n,tabl,indx,v) {
   //alert("Span " + n + " was clicked: " + tabl + ', ' + indx);
   strng='itemEditor.php?gofor=Edit&cell=' + tabl +'&nid=' + indx;
   strng=strng + '&spanid=' + n;
   //alert(strng);
   createWindow(strng,'itemEditor','height=500,width=650,scrollbars');
   
 }
 
 function otherClick(tabl,indx,v) {
   strng='itemEditor.php?gofor=Edit&cell=' + tabl +'&nid=' + indx;
   createWindow(strng,'itemEditor','height=500,width=650,scrollbars'); 
 }
 
 function findChemReg() {
   dottle='unitDisplay';
  sel=document.getElementById('z_cropid');
  indx = sel.length;
  if (indx) {
    for (var b=0;b<indx;b++) {
      if (sel[b].checked) {
       crop=sel[b].value;
      }
    }
  } else {
    crop=sel.value;
  }
  sel=document.getElementById('chemname');
  dd=sel.selectedIndex;
  chem=sel.options[sel.selectedIndex].value;
  alert(chem + ' (' + dd + ')' + ' on ' + crop);
  strng='cid=' + chem + '&crop=' + crop;
  loadXMLDocP('createRatePrompt.php',strng);
}
 
