Sunday, February 6, 2011

mw3 BeakerModeMods *TEST* - for MW3TR 3.5.74


// ==UserScript==
// @name           BeakerModeMods
// @namespace      mw3
// @description    BeakerModeMods for both Production and Test instance(s)
// @include        http://*.crimsonleafgames.com/*
// ==/UserScript==

//==========================================================================================================
// For MW3TR version 3.5.74
//==========================================================================================================
// User-configuration settings:
var putBeakerPanelOnTheRight   = false; // guess what happens if you change this to  true  ? 8-)
var numberOfBeakerPanelButtons = 18;    // these are the buttons at the side   (in  2 columns)
var numberOfBottomPanelButtons = 24;    // these are the buttons at the bottom (in 12 columns)
var moveCombatButtons          = true;; // true makes the combat buttons move to the line where
                                        //  the title "Enter Commands:" originally appears,
                                        //  just below the ChatPanel and just above the command line.
var putCombatButtonsOnTheRight = false; // guess what  true  does? 8-)

var numberOfUserButtonsAfterFire  = 2; // buttons on the Combat Bar -- these only exist
var numberOfUserButtonsAfterTorps = 2; // if moveCombatButtons is true

var suppressLoginName          = false; // set to true if you don't want your account name visible --
                                        //  for example, if you're taking screenshots or making videos
                                        //  you plan to post publicly

var separateLocalScanPanel     = true   // set to true if you want the local-scan info separated from
                                        // the other TermPanel info
//==========================================================================================================
// Use Tools->DOMinspector to inspect the Tree of DOM itself,
// if you want to climb around the Tree,
// *especially* if you want to use .firstChild and .nextSibling.
//==========================================================================================================

if(/Login.aspx/.test(location)){
  return; // avoid throwing an "ip is null" error if the Login has a ReturnUrl to InfoCenter or PlanetManagement

} else if( /InfoCenter/.test(location) ){
  // Add "Fly" and "PM" buttons to the InfoCenter window
  var ip = document.getElementById("iWarriorScoreLabel");
  if(ip == null) return;
  ipTR = ip.parentNode  // TD
           .parentNode; // TR
  ipTR.parentNode       // TBODY
      .parentNode       // TABLE
                 .width = 700
  var flyBkrTD = document.createElement('TD');
  flyBkrTD.innerHTML = "<DIV style='text-align:right'>" +
                         "<a href='Beaker.aspx'>Fly</a>&nbsp;&nbsp;" +
                         "<a href='PlanetManagement.aspx'>PM</a>" +
                       "</DIV>";
  ipTR.appendChild(flyBkrTD);
  return;

} else if( /PlanetManagement/.test(location) ){
  // Add "Fly" and "IC" buttons to the PlanetManagement window
  if(document.getElementById('history')) return; // do not add them if PMmem is active: it adds its own
  // Need to keep checking back: clicking a base's button triggers a Post action that wipes the added links
  function addFlyAndIC(){
    var flyBkrDiv = document.getElementById("BeakerModeModsFlyPM")
    if(flyBkrDiv == null){
      var ip = document.getElementById("m_oSaveChanges");
      flyBkrDiv = document.createElement('DIV');
      flyBkrDiv.setAttribute('id', 'BeakerModeModsFlyPM'); // so PMmem can find and remove this
      flyBkrDiv.innerHTML = "<a href='Beaker.aspx'>Fly</a>" +
                            "&nbsp;&nbsp;<a href='InfoCenter.aspx'>IC</a>";
      ip.parentNode.appendChild(flyBkrDiv);
    }
    window.setTimeout(addFlyAndIC, 4000) // check back in 4 seconds
  }
  addFlyAndIC() // add the links initially
  return

} else if( !/Beaker/.test(location) ) return; // i.e. it's not BeakerWindow

// From here on we know we're either in the BeakerWindow or in one of its child windows.

var isMapWindow = false;
if((document.firstChild.firstChild          != null  ) &&
   (document.firstChild.firstChild.nodeName == 'HEAD') &&
   (document.firstChild.firstChild.firstChild != null) &&
   (document.firstChild.firstChild.firstChild.nodeName == 'TITLE')){
  // GM_log('Map window TITLE=' + document.firstChild.firstChild.firstChild.textContent);
  isMapWindow = document.firstChild.firstChild.firstChild.textContent == "MW3 Map";
  // GM_log('isMapWindow= ' + isMapWindow);
}

var invisibleStyle = 'width:1px;border-left-width:1px;border-right-width:1px;' +
                     'border-spacing:2px 2px;padding-left:0px;padding-right:0px;';

if(isMapWindow){ //******************************************************************************

  Xsize = document.getElementById('Xsize');
  Ysize = document.getElementById('Ysize');
  stars = document.getElementById('stars');
  dbt   = document.getElementById('dbt');
  map   = document.getElementById('map');
  ship  = document.getElementById('ship');
  bases = document.getElementById('bases');

  var starCoords = [[-1,-1],
[656.712800,654.580300],
[348.463900,745.307300],
[247.956100,243.892400],
[581.204500,339.174300],
[756.710700,609.470900],
[507.852800,664.072100],
[258.994900,830.495000],
[10.137080,885.096200],
[761.279300,939.697400],
[512.421300,106.120200],
[263.563500,160.721500],
[14.705620,327.144300],
[765.847800,381.745500],
[516.989900,548.168300],
[268.132000,602.769600],
[19.274160,657.370800],
[770.416300,823.793600],
[521.558400,878.394800],
[384.522100,44.817660],
[23.842690,99.418890],
[774.984800,265.841700],
[526.127000,320.442900],
[277.269100,375.044200],
[28.411230,541.467000],
[779.553400,596.068300],
[530.695500,762.491000],
[281.837700,817.092300],
[32.979770,983.515100],
[784.121900,38.116320],
[535.264100,92.717550],
[286.406200,259.140400],
[37.548310,313.741600],
[788.690500,480.164400],
[539.832600,534.765600],
[290.974700,701.188500],
[42.116850,755.789700],
[793.259000,922.212500],
[656.222700,976.813800],
[407.364900,31.414980],
[46.685390,197.837800],
[797.827500,252.439000],
[548.969700,418.861900],
[300.111800,473.463100],
[51.253930,639.885900],
[802.396100,694.487100],
[553.538200,749.088400],
[304.680300,915.511200],
[55.822470,970.112400],
[806.964600,136.535200],
[558.106800,191.136500],
[309.248900,245.737700],
[60.391010,412.160500],
[811.533100,466.761700],
[562.675300,633.184500],
[313.817400,687.785800],
[64.959550,854.208600],
[816.101700,908.809800],
[567.243800,75.232640],
[318.385900,129.833900],
[69.528080,184.435100],
[820.670300,350.857900],
[571.812400,405.459100],
[322.954500,571.882000],
[74.096620,626.483200],
[825.238800,792.906000],
[576.380900,847.507200],
[327.523000,902.108400],
[78.665160,68.531290],
[941.628900,123.132500],
[580.949400,289.555300],
[332.091600,344.156600],
[83.233700,510.579400],
[834.375800,565.180600],
[585.518000,731.603500],
[336.660100,786.204600],
[199.623800,840.805900],
[838.944400,7.228713],
[701.908100,61.829950],
[341.228700,228.252800],
[92.370780,282.854000],
[843.512900,449.276800],
[594.655000,503.878100],
[345.797200,558.479300],
[96.939310,724.902100],
[848.081400,779.503300],
[599.223600,945.926100],
[462.187300,1000.527000],
[101.507900,166.950200],
[964.471600,221.551400],
[603.792100,276.152700],
[354.934300,442.575500],
[106.076400,497.176700],
[857.218500,663.599500],
[608.360700,718.200800],
[359.502800,772.802000],
[110.644900,939.224800],
[861.787100,993.826100],
[612.929200,160.248800],
[364.071300,214.850100],
[115.213500,381.272900],
[866.355600,435.874100],
[617.497800,490.475400],
[368.639900,656.898100],
[119.782000,711.499400],
[870.924100,877.922200],
[622.066300,932.523400],
[373.208400,987.124700],
[124.350500,153.547500],
[875.492700,208.148700],
[626.634800,374.571500],
[377.777000,429.172800],
[128.919100,595.595600],
[880.061200,650.196800],
[631.203400,816.619600],
[382.345500,871.220900],
[133.487600,37.643690],
[884.629800,92.244920],
[635.771900,258.667700],
[386.914000,313.269000],
[138.056200,367.870200],
[889.198300,534.293000],
[640.340500,588.894300],
[391.482600,755.317100],
[142.624700,809.918300],
[893.766900,864.519600],
[644.909000,30.942340],
[396.051100,85.543580],
[147.193200,251.966400],
[898.335400,306.567600],
[649.477600,472.990500],
[400.619600,527.591700],
[151.761800,582.192900],
[902.903900,748.615800],
[654.046000,803.217000],
[405.188200,969.639800],
[156.330300,24.241000],
[795.650900,190.663800],
[770.436200,245.265100],
[409.756700,299.866300],
[160.898900,466.289100],
[23.862570,520.890300],
[663.183100,687.313100],
[414.325300,741.914400],
[165.467400,908.337200],
[28.431110,962.938400],
[667.751600,129.361200],
[418.893800,183.962500],
[58.214350,350.385300],
[32.999650,404.986500],
[672.320200,459.587800],
[423.462400,626.010600],
[286.426100,680.611800],
[925.746600,847.034600],
[676.888800,901.635900],
[428.030900,68.058660],
[290.994600,122.659900],
[930.315100,289.082700],
[681.457300,343.683900],
[320.777800,398.285200],
[183.741600,564.708000],
[934.883700,619.309200],
[686.025800,785.732100],
[548.989500,840.333200],
[188.310100,6.756082],
[939.452200,61.357320],
[690.594400,115.958600],
[553.558100,282.381400],
[192.878600,336.982600],
[944.020800,503.405400],
[583.341300,558.006600],
[446.305000,612.608000],
[197.447200,779.030700],
[948.589300,833.631900],
[811.553100,1000.055000],
[450.873600,54.655970],
[202.015700,221.078800],
[953.157800,275.680000],
[816.121500,330.281300],
[455.442100,496.704100],
[206.584300,551.305300],
[957.726400,717.728100],
[708.868500,772.329400],
[460.010700,826.930600],
[211.152800,993.353400],
[962.294900,47.954630],
[713.437100,214.377500],
[464.579200,268.978700],
[215.721300,435.401500],
[966.863400,490.002700],
[718.005600,544.604000],
[469.147700,711.026800],
[220.289900,765.628000],
[971.432000,932.050800],
[722.574200,986.652100],
[473.716300,153.074900],
[224.858400,207.676100],
[976.000600,262.277400],
[727.142600,428.700200],
[478.284800,483.301400],
[229.426900,649.724200],
[980.569100,704.325500],
[731.711200,758.926700],
[482.853400,925.349500],
[233.995500,979.950700],
[985.137600,146.373500],
[736.279800,200.974800],
[487.421900,367.397600],
[238.564000,421.998800],
[989.706100,476.600100],
[740.848300,643.022800],
[491.990400,697.624100],
[243.132600,864.046900],
[994.274700,918.648100],
[745.416800,973.249400],
[496.559000,139.672200],
[247.701100,194.273400],
[998.843200,360.696200],
[749.985400,415.297500],
[501.127500,581.720300],
[252.269600,636.321500],
[3.411760,802.744300],
[754.553900,857.345600],
[505.696100,23.768370],
[256.838200,78.369600],
[7.980298,244.792400],
[759.122500,299.393700],
[510.264600,465.816500],
[261.406700,520.417700],
[12.548840,686.840500],
[763.691000,741.441700],
[514.833200,907.864600],
[265.975300,962.465800],
[17.117380,17.067020],
[768.259500,183.489800],
[519.401700,238.091100],
[270.543800,404.513900],
[21.685910,459.115100],
[772.828100,513.716400],
[523.970200,680.139200],
[275.112300,734.740500],
[26.254450,901.163200],
[777.396600,955.764400],
[528.538800,122.187300],
[279.680900,176.788500],
[30.822990,231.389700],
[781.965100,397.812500],
[533.107300,452.413800],
[284.249400,618.836600],
[35.391530,673.437800],
[786.533600,728.039100],
[537.675800,894.461900],
[288.817900,949.063100],
[39.960070,115.485900],
[791.102200,170.087100],
[542.244300,336.510000],
[293.386500,391.111200],
[44.528610,445.712500],
[795.670700,612.135300],
[546.812900,666.736500],
[297.955000,833.159300],
[49.097150,887.760600],
[800.239300,54.183340],
[551.381500,108.784600],
[302.523600,163.385800],
[53.665690,329.808600],
[804.807800,384.409900],
[555.950000,550.832600],
[307.092100,605.433900],
[58.234220,660.035200],
[809.376300,826.458000],
[560.518500,881.059200],
[311.660700,47.482000],
[62.802760,102.083200],
[590.301800,268.506100],
[565.087100,323.107300],
[539.872300,377.708500],
[67.371300,544.131400],
[818.513500,598.732600],
[793.298800,765.155400],
[320.797700,819.756600],
[71.939850,986.179400],
[46.725140,40.780660],
[574.224100,95.381890],
[325.366300,261.804700],
[852.865200,316.406000],
[827.650500,482.828800],
[802.435800,537.430000],
[329.934800,703.852800],
[81.076920,758.454100],
[55.862210,924.876800],
[583.361200,979.478100],
[334.503300,145.900900],
[309.288600,200.502100],
[836.787600,366.924900],
[587.929800,421.526200],
[115.428700,587.949000],
[90.213990,642.550300],
[64.999290,808.973000],
[592.498300,863.574200],
[343.640400,918.175500],
[318.425700,84.598310],
[845.924700,139.199600],
[597.066800,305.622400],
[571.852100,360.223600],
[99.351070,414.824800],
[850.493200,581.247600],
[377.992200,635.848900],
[352.777500,690.450100],
[103.919600,968.694500],
[855.061800,23.295740],
[606.203900,77.896980],
[580.989200,132.498200],
[108.488200,187.099400],
[859.630300,465.343900],
[834.415600,519.945100],
[361.914600,574.546300],
[113.056700,629.147500],
[640.555700,683.748800],
[615.341000,961.993200],
[366.483100,16.594400],
[117.625200,71.195630],
[868.767300,125.796900],
[843.552700,404.041300],
[371.051600,458.642500],
[122.193800,513.243700],
[96.979060,567.845000],
[624.478000,622.446200],
[375.620200,900.690600],
[903.119100,955.291800],
[877.904400,9.893051],
[629.046600,64.494290],
[380.188700,119.095500],
[131.330800,397.339900],
[106.116100,451.941200],
[633.615100,506.542400],
[384.757200,561.143600],
[359.542600,615.744800],
[887.041500,893.989200],
[638.183600,948.590400],
[165.682600,3.191708],
[140.467900,57.792940],
[891.610100,224.215800],
[642.752200,390.638600],
[393.894300,445.239800],
[368.679600,499.841100],
[896.178600,666.263900],
[647.320800,832.686600],
[622.106000,887.287900],
[149.605000,941.889200],
[900.747100,108.311900],
[428.246100,162.913200],
[403.031400,329.336000],
[154.173500,383.937200],
[905.315700,550.360100],
[656.457800,604.961300],
[631.243100,659.562500],
[158.742100,825.985300],
[909.884200,992.408100],
[661.026400,47.009370],
[412.168500,101.610600],
[163.310600,156.211800],
[914.452800,434.456300],
[665.595000,489.057500],
[416.737000,543.658700],
[167.879200,598.260000],
[919.021300,652.861100],
[670.163400,931.105500],
[421.305600,985.706800],
[172.447700,40.308030],
[923.589900,94.909260],
[674.732000,373.153700],
[425.874100,427.754900],
[177.016200,482.356100],
[928.158400,536.957300],
[679.300500,591.558600],
[430.442700,869.803000],
[181.584800,924.404200],
[932.726900,979.005400],
[683.869000,33.606680],
[435.011200,88.207920],
[186.153300,366.452300],
[937.295400,421.053600],
[688.437600,475.654800],
[439.579700,530.256000],
[190.721900,584.857300],
[941.863900,863.101600],
[693.006100,917.702900],
[444.148300,972.304100],
[195.290400,26.905340],
[946.432500,305.149700],
[697.574600,359.751000],
[448.716800,414.352200],
[199.858900,468.953500],
[951.001100,523.554700],
[702.143200,801.799100],
[453.285300,856.400200],
[204.427500,911.001500],
[955.569600,965.602800],
[706.711800,20.204000],
[457.853900,298.448400],
[208.996000,464.871200],
[960.138100,407.650900],
[711.280300,574.073700],
[462.422400,516.853400],
[213.564600,906.919300],
[964.706700,849.699000],
[715.848800,16.121760],
[466.991000,958.901400],
[218.133100,125.324200],
[969.275200,291.747100],
[720.417400,458.169900],
[471.559500,400.949500],
[222.701600,567.372300],
[973.843800,733.795200],
[724.985900,900.217900],
[476.128000,842.997600],
[227.270200,9.420421],
[978.412300,952.200100],
[729.554500,342.266100],
[480.696600,285.045700],
[231.838700,451.468500],
[982.980800,394.248200],
[734.123000,560.671000],
[485.265100,727.093800],
[236.407200,893.516600],
[987.549400,836.296300],
[738.691500,2.719077],
[489.833600,945.498700],
[240.975800,335.564700],
[992.117900,278.344400],
[743.260000,444.767200],
[494.402200,387.546900],
[245.544300,553.969700],
[996.686400,720.392500],
[747.828600,886.815200],
[498.970700,829.595000],
[250.112900,996.017800],
[1.254980,162.440600],
[752.397100,328.863400],
[503.539300,271.643000],
[254.681400,438.065900],
[5.823519,604.488600],
[756.965600,770.911500],
[508.107800,713.691100],
[259.249900,880.113900],
[10.392060,46.536740],
[761.534200,989.316400],
[512.676400,155.739200],
[263.818500,322.162000],
[14.960600,488.584900],
[766.102800,431.364500],
[517.244900,597.787300],
[268.387000,764.210100],
[19.529140,930.632900],
[770.671300,873.412600],
[521.813400,39.835400],
[272.955500,206.258200],
[24.097670,372.681000],
[775.239800,315.460700],
[526.382000,481.883500],
[277.524100,424.663200],
[28.666210,814.729100],
[779.808400,757.508800],
[530.950500,923.931600],
[282.092600,866.711200],
[33.234750,33.134050],
[784.376900,199.556900],
[535.519100,365.979700],
[286.661200,308.759400],
[37.803290,475.182200],
[788.945500,417.961800],
[540.087500,808.027800],
[291.229700,750.807500],
[42.371830,917.230200],
[793.514000,860.009900],
[544.656100,26.432710],
[295.798200,192.855500],
[46.940370,359.278400],
[798.082500,302.058000],
[549.224600,468.480800],
[300.366800,634.903600],
[51.508910,801.326500],
[802.651100,744.106100],
[553.793100,910.528900],
[304.935300,853.308600],
[56.077440,243.374500],
[807.219600,186.154200],
[558.361700,352.577000],
[309.503900,295.356600],
[60.645980,461.779500],
[811.788100,628.202300],
[562.930300,794.625100],
[314.072400,737.404800],
[65.214530,903.827600],
[816.356700,846.607200],
[567.498800,236.673200],
[318.640900,179.452800],
[69.783060,345.875700],
[820.925200,288.655300],
[572.067300,455.078200],
[323.209500,621.501000],
[74.351600,787.923800],
[825.493700,730.703400],
[576.635900,897.126200],
[327.778000,63.549030],
[78.920140,229.971900],
[830.062300,172.751500],
[5.568539,443.048100],
[332.346500,505.597100],
[83.488680,672.020000],
[834.630800,614.799600],
[585.773000,781.222500],
[336.915100,947.645200],
[88.057210,890.424900],
[839.199300,56.847680],
[590.341500,223.270500],
[341.483600,389.693300],
[92.625760,332.473000],
[843.767900,498.895800],
[594.910100,665.318600],
[346.052200,831.741400],
[97.194290,774.521100],
[848.336400,940.943900],
[599.478600,107.366700],
[350.620700,273.789500],
[101.762800,216.569200],
[852.904900,382.992000],
[604.047100,325.771600],
[355.189300,715.837600],
[106.331400,658.617300],
[857.473500,825.040100],
[608.615600,767.819700],
[359.757800,934.242600],
[110.899900,100.665300],
[862.042100,267.088100],
[613.184100,209.867800],
[364.326300,376.290600],
[115.468500,319.070300],
[866.610600,709.136300],
[617.752800,651.915900],
[368.894800,818.338800],
[120.037000,761.118400],
[871.179100,927.541200],
[622.321300,93.964000],
[373.463400,260.386800],
[124.605500,203.166500],
[323.034000,369.589300],
[179.603500,536.012100],
[378.031900,702.435000],
[129.174100,645.214600],
[880.316200,811.637400],
[78.744650,754.417100],
[829.886800,144.483000],
[133.742600,87.262650],
[884.884800,253.685500],
[636.026900,196.465100],
[387.169000,362.888000],
[585.597500,529.310800],
[442.167000,695.733600],
[640.595400,638.513300],
[391.737600,804.936100],
[142.879700,971.358800],
[341.308100,137.781700],
[92.450270,80.561310],
[396.306100,246.984100],
[147.448200,189.763800],
[898.590300,356.186600],
[649.732500,522.609500],
[848.160900,689.032300],
[704.730500,631.811900],
[903.158900,798.234700],
[654.301000,964.657600],
[405.443200,131.080300],
[603.871600,73.859970],
[355.013800,240.282800],
[658.869600,406.705600],
[410.011700,573.128500],
[161.153800,515.908100],
[912.295900,682.330900],
[110.724400,848.753700],
[967.293900,791.533300],
[165.722400,957.956200],
[916.864500,124.379000],
[668.006600,290.801800],
[866.435100,233.581400],
[617.577200,400.004300],
[921.433100,566.427100],
[672.575200,732.849900],
[423.717300,675.629500],
[174.859500,842.052400],
[373.287900,8.475159],
[229.857400,174.898000],
[428.285900,117.677600],
[179.428000,284.100400],
[930.570100,226.880100],
[128.998600,616.946100],
[880.140700,559.725700],
[183.996500,726.148600],
[935.138700,668.928200],
[686.280800,835.351000],
[437.423000,1.773816],
[635.851400,168.196600],
[492.420900,110.976300],
[690.849300,277.399100],
[441.991500,220.178800],
[193.133600,610.244800],
[391.562100,553.024400],
[142.704200,719.447200],
[446.560000,662.226900],
[197.702100,828.649700],
[948.844300,771.429300],
[699.986400,161.495300],
[898.414900,327.918100],
[754.984400,270.697800],
[953.412800,437.120600],
[704.555000,379.900200],
[455.697100,546.323100],
[206.839200,936.389100],
[405.267700,655.525500],
[709.123500,45.591480],
[460.265700,988.371100],
[211.407800,154.794000],
[962.549900,321.216700],
[160.978400,263.996400],
[17.547840,430.419200],
[215.976300,373.198900],
[967.118400,539.621700],
[718.260600,929.687700],
[469.402700,872.467400],
[667.831200,38.890130],
[971.686900,981.669800],
[722.829100,148.092600],
[473.971300,314.515400],
[225.113400,257.295100],
[423.541900,423.717900],
[280.111300,366.497500],
[478.539800,756.563600],
[229.681900,922.986300],
[980.824100,865.766000],
[731.966200,32.188790],
[930.394600,974.968400],
[234.250500,141.391300],
[985.392600,307.814100],
[736.534800,250.593700],
[487.676900,640.659800],
[686.105300,807.082500],
[542.674800,749.862200],
[741.103300,916.285000],
[492.245400,859.064600],
[243.387500,25.487450],
[994.529700,191.910300],
[192.958100,134.689900],
[496.814000,301.112700],
[254.426400,388.446900],
[999.098200,633.958400],
[750.240400,800.381200],
[948.668800,743.160800],
[805.238300,909.583600],
[3.666739,852.363300],
[754.808900,18.786100],
[505.951000,185.208900],
[257.093200,127.988600],
[455.521600,518.054600],
[759.377500,237.191100],
[510.519600,627.257000],
[261.661700,793.679800],
[12.803820,736.459500],
[211.232300,902.882300],
[67.801760,845.661900],
[266.230200,12.084760],
[17.372360,402.150700],
[768.514500,121.287200],
[519.656700,511.353200],
[718.085100,230.489700],
[21.940890,620.555700],
[773.083000,786.978500],
[524.225200,729.758100],
[275.367300,896.181000],
[473.795800,838.960600],
[330.365200,5.383416],
[528.793700,395.449400],
[279.935900,114.585900],
[31.077970,504.651900],
[782.220100,447.431500],
[980.648600,613.854300],
[284.504400,780.277200],
[35.646510,723.056800],
[786.788600,889.479600],
[537.930800,832.259300],
[736.359300,998.682100],
[592.928700,388.748100],
[791.357200,331.527700],
[542.499300,497.950600],
[293.641500,664.373400],
[44.783590,607.153000],
[243.212000,773.575800],
[547.067900,716.355500],
[298.210000,882.778200],
[49.352130,272.844300],
[800.494300,215.623900],
[998.922800,382.046700],
[855.492200,324.826400],
[53.920670,491.249200],
[805.062800,657.672000],
[556.205000,600.451700],
[307.347100,766.874500],
[505.775500,709.654100],
[809.631400,99.720080],
[560.773500,266.142900],
[311.915600,208.922600],
[63.057750,375.345400],
[261.486200,318.125000],
[118.055700,484.547800],
[316.484200,650.970600],
[67.626280,593.750300],
[818.768500,983.816300],
[569.910500,702.952800],
[321.052700,93.018740],
[72.194820,259.441600],
[823.337000,202.221200],
[574.479100,368.644000],
[325.621200,311.423700],
[76.763360,477.846500],
[827.905500,867.912500],
[579.047600,587.049000],
[330.189800,977.114900],
[81.331900,696.251400],
[832.474100,86.317390],
[583.616100,252.740200],
[334.758300,195.519900],
[85.900440,361.942700],
[837.042600,304.722300],
[588.184700,471.145200],
[339.326900,861.211100],
[90.468970,580.347600],
[841.611100,970.413600],
[592.753300,136.836400],
[343.895400,79.616050],
[95.037510,246.038900],
[846.179600,188.818500],
[597.321800,355.241300],
[503.284300,222.024100],
[99.606050,464.443800],
[850.748200,854.509800],
[601.890300,573.646300],
[353.032500,963.712200],
[104.174600,130.135100],
[855.316700,72.914710],
[606.458900,239.337500],
[357.601000,182.117200],
[108.743100,348.540000],
[859.885200,738.606000],
[611.027400,457.742500],
[362.169500,847.808400],
[113.311700,790.588100],
[864.453800,957.010900],
[615.596000,123.433700],
[366.738100,66.213360],
[117.880200,232.636200],
[869.022300,175.415800],
[620.164500,341.838700],
[371.306600,731.904600],
[122.448700,674.684300],
[873.590900,841.107100],
[624.733100,783.886800],
[375.875200,950.309600],
[127.017300,116.732400],
[878.159400,59.512020],
[629.301600,225.934800],
[380.443700,168.714500],
[131.585800,558.780500],
[882.727900,725.203300],
[633.870100,667.983000],
[385.012300,834.405800],
[136.154400,777.185400],
[887.296500,943.608200],
[638.438700,110.031000],
[389.580800,52.810680],
[140.722900,442.876700],
[891.865100,609.299500],
[643.007100,552.079100],
[394.149300,718.502000],
[145.291400,661.281600],
[896.433600,827.704500],
[647.575700,994.127200],
[398.717800,936.906900],
[149.860000,326.972900],
[901.002100,46.109340],
[652.144300,436.175300],
[403.286400,602.598100],
[154.428500,545.377800],
[905.570700,711.800600],
[752.142100,167.422800],
[407.854900,821.003100],
[158.997100,211.069000],
[910.139200,930.205500],
[661.281300,320.271500],
[412.423500,39.407990],
[163.565600,429.474000],
[914.707700,595.896800],
[665.849900,538.676500],
[416.992000,928.742400],
[168.134100,424.235800],
[919.276200,814.301700],
[670.418400,204.367700],
[421.560600,147.147300],
[172.702700,89.926990],
[923.844800,32.706650],
[674.987000,422.772600],
[426.129100,812.838600],
[177.271200,308.332000],
[928.413300,698.397900],
[679.555500,641.177600],
[430.697600,31.243530],
[181.839700,974.023200],
[932.981900,916.802900],
[684.124000,306.868800],
[435.266200,249.648500],
[186.408300,192.428100],
[937.550400,582.494100],
[688.692600,525.273800],
[439.834700,915.339800],
[190.976800,858.119400],
[942.118900,800.899100],
[693.261100,190.965000],
[444.403300,133.744700],
[195.545400,76.524310],
[946.687500,466.590300],
[697.829600,409.369900],
[448.971800,799.436000],
[200.113900,742.215600],
[951.256100,684.995300],
[702.398200,75.061190],
[453.540300,17.840840],
[204.682400,960.620500],
[955.824600,903.400100],
[706.966800,293.466100],
[458.108900,683.532100],
[209.251000,626.311800],
[960.393100,569.091400],
[711.535300,511.871100],
[462.677400,901.937000],
[213.819500,844.716700],
[964.961700,787.496300],
[716.103800,177.562300],
[467.245900,120.342000],
[218.388100,510.408000],
[969.530100,453.187600],
[720.672300,395.967300],
[471.814500,786.033200],
[222.956600,728.812900],
[974.098800,671.592500],
[725.240900,61.658500],
[476.383000,4.438154],
[227.525100,394.504100],
[978.667300,889.997400],
[729.809400,280.063500],
[480.951600,670.129400],
[232.093700,612.909100],
[983.235800,555.688800],
[734.378000,498.468400],
[485.520100,888.534400],
[236.662200,278.600300],
[987.804300,774.093700],
[738.946500,164.159600],
[490.088600,106.939300],
[241.230800,497.005300],
[992.372900,439.784900],
[743.515000,382.564600],
[494.657200,772.630600],
[245.799300,162.696500],
[996.941400,658.189800],
[748.083600,48.255820],
[499.225700,991.035400],
[250.367800,381.101500],
[1.509960,323.881100],
[752.652100,266.660700],
[503.794200,656.726800],
[254.936400,599.506500],
[6.078499,542.286000],
[757.220600,932.352000],
[508.362800,875.131600],
[259.504900,265.197600],
[10.647040,207.977300],
[761.789200,150.756900],
[512.931400,540.823000],
[264.073400,483.602600],
[15.215580,426.382300],
[766.357800,369.161900],
[517.499900,759.227900],
[268.642000,149.293800],
[19.784120,92.073480],
[770.926300,34.853130],
[522.068400,977.632800],
[273.210500,367.698800],
[24.352650,310.478400],
[775.494800,253.258100],
[526.636900,643.324100],
[277.779100,586.103700],
[28.921190,976.169700],
[780.063400,918.949300],
[531.205500,861.728900],
[282.347600,251.795000],
[33.489730,194.574600],
[784.631800,137.354300],
[535.774000,527.420300],
[286.916200,470.199900],
[38.058270,860.265900],
[789.200400,355.759200],
[540.342500,745.825100],
[291.484700,135.891100],
[42.626810,78.670800],
[793.769000,21.450440],
[544.911100,411.516400],
[296.053200,354.296100],
[47.195350,744.362100],
[798.337500,239.855400],
[549.479600,629.921300],
[300.621800,19.987320],
[51.763890,962.766900],
[802.906000,905.546600],
[554.048200,848.326300],
[305.190300,238.392300],
[56.332430,628.458300],
[807.474600,123.951600],
[558.616700,514.017600],
[309.758800,456.797200],
[60.900970,846.863200],
[812.043100,789.642800],
[563.185300,732.422500],
[314.327400,122.488500],
[65.469500,65.268110],
[816.611600,8.047753],
[567.753800,398.113800],
[318.895900,340.893400],
[70.038040,730.959400],
[821.180200,673.739000],
[572.322300,616.518700],
[323.464500,6.584637],
[74.606580,949.364300],
[825.748700,892.143900],
[576.890900,834.923600],
[328.033000,224.989600],
[79.175120,615.055600],
[830.317300,557.835200],
[581.459500,500.614900],
[332.601500,443.394500],
[83.743650,833.460500],
[834.885800,776.240100],
[586.027900,719.019800],
[337.170100,109.085800],
[88.312190,51.865420],
[839.454400,441.931400],
[590.596500,384.711000],
[341.738600,327.490700],
[92.880730,717.556600],
[844.022900,660.336300],
[595.165100,603.116000],
[346.307100,993.181900],
[97.449280,935.961600],
[848.591400,878.741200],
[599.733500,268.807200],
[350.875700,211.586900],
[102.017800,601.652800],
[853.160000,544.432500],
[604.302100,487.212200],
[355.444200,877.278100],
[106.586400,820.057800],
[857.728400,762.837500],
[608.870600,705.617100],
[360.012800,95.683080],
[111.154900,485.749100],
[862.297100,428.528700],
[613.439100,371.308400],
[364.581300,314.088000],
[115.723400,704.154000],
[866.865600,646.933600],
[618.007700,589.713300],
[369.149900,979.779300],
[120.292000,922.558900],
[871.434100,312.624900],
[622.576300,255.404600],
[373.718400,198.184200],
[124.860500,588.250200],
[876.002600,531.029900],
[627.144800,473.809500],
[378.286900,863.875400],
[129.429100,806.655100],
[880.571200,196.721100],
[631.713300,692.214500],
[382.855500,82.280390],
[133.997600,472.346400],
[885.139700,415.126000],
[636.281900,357.905700],
[387.424000,300.685300],
[138.566100,690.751300],
[889.708200,80.817270],
[640.850400,576.310600],
[391.992500,966.376600],
[143.134700,909.156200],
[894.276800,299.222200],
[645.419000,242.001900],
[396.561100,184.781500],
[147.703200,574.847500],
[898.845300,964.913400],
[649.987500,460.406800],
[401.129600,850.472800],
[152.271700,793.252400],
[903.413900,183.318400],
[654.556000,126.098100],
[405.698200,68.877700],
[156.840300,458.943700],
[907.982400,401.723300],
[659.124500,344.503000],
[410.266700,734.569000],
[161.408800,677.348600],
[912.550900,67.414580],
[663.693100,10.194240],
[414.835200,952.973900],
[165.977400,343.039900],
[917.119500,285.819500],
[668.261600,228.599200],
[419.403800,171.378800],
[170.545900,561.444800],
[921.688100,951.510800],
[672.830100,894.290400],
[423.972300,837.070100],
[175.114400,779.849800],
[926.256600,169.915700],
[677.398700,112.695400],
[428.540900,55.475020],
[179.683000,445.541000],
[930.825100,388.320700],
[681.967300,778.386600],
[433.109400,721.166300],
[184.251500,663.946000],
[935.393700,54.011900],
[686.535800,996.791600],
[437.677900,939.571200],
[188.820100,329.637200],
[939.962200,272.416900],
[691.104300,662.482800],
[442.246500,157.976100],
[193.388600,548.042100],
[944.530700,938.108100],
[695.672900,880.887800],
[446.815000,823.667500],
[197.957100,213.733400],
[949.099200,156.513000],
[700.241400,546.579000],
[451.383500,42.072330],
[202.525700,432.138300],
[953.667800,822.204300],
[704.810000,764.984000],
[455.952100,707.763600],
[207.094200,650.543200],
[958.236300,40.609210],
[709.378500,430.675200],
[460.520600,926.168500],
[211.662700,316.234500],
[962.804900,259.014100],
[713.947000,649.080100],
[465.089200,591.859800],
[216.231300,534.639400],
[967.373400,924.705400],
[718.515600,867.485100],
[469.657700,810.264700],
[220.799800,200.330700],
[971.941900,143.110300],
[723.084100,533.176300],
[474.226300,475.956000],
[225.368400,418.735600],
[976.510500,808.801600],
[727.652600,751.581300],
[478.794800,694.360900],
[229.936900,637.140600],
[981.079100,27.206520],
[732.221100,417.272500],
[483.363300,360.052200],
[234.505400,302.831800],
[985.647600,245.611500],
[736.789700,635.677500],
[487.931900,578.457100],
[239.074000,521.236800],
[990.216100,911.302800],
[741.358200,854.082400],
[492.500400,244.148400],
[243.642500,186.928000],
[994.784700,129.707700],
[745.926800,519.773700],
[497.068900,462.553300],
[248.211100,405.332900],
[999.353100,795.399000],
[645.068000,738.178600],
[396.210100,128.244500],
[358.207000,71.024190],
[3.921719,13.803840],
[755.063800,403.869800],
[506.206000,346.649500],
[257.348200,289.429100],
[8.490258,679.495100],
[759.632400,622.274800],
[510.774600,12.340720],
[156.489300,507.834100],
[907.631500,897.900000],
[658.773600,287.966000],
[620.770500,230.745700],
[266.485200,173.525300],
[17.627340,116.305000],
[768.769500,506.371000],
[519.911700,896.436900],
[271.053800,391.930200],
[22.195870,781.996200],
[773.338000,724.775900],
[419.052800,114.841800],
[170.194900,57.621500],
[921.337100,1000.401000],
[883.333900,390.467100],
[529.048700,333.246800],
[280.190800,276.026400],
[31.332950,666.092500],
[782.475100,608.872100],
[533.617300,998.938100],
[284.759400,941.717700],
[35.901490,884.497300],
[681.616300,274.563300],
[432.758400,217.343000],
[183.900500,160.122600],
[145.897400,102.902300],
[791.612200,492.968300],
[542.754300,883.034200],
[293.896400,378.527600],
[45.038570,768.593500],
[796.180800,711.373200],
[547.322800,101.439200],
[298.465000,44.218810],
[944.179800,986.998500],
[695.321900,377.064500],
[446.464000,767.130500],
[408.460900,262.623800],
[54.175650,652.689700],
[805.317800,595.469400],
[556.459900,985.535300],
[307.602100,928.315000],
[58.744190,871.094700],
[809.886300,261.160700],
[561.028500,203.940300],
[206.743200,146.719900],
[957.885400,536.785900],
[709.027500,479.565600],
[671.024400,869.631500],
[316.739100,812.411200],
[67.881260,755.190900],
[819.023400,145.256800],
[570.165500,88.036470],
[321.307700,30.816120],
[72.449800,973.595800],
[823.592000,363.661800],
[469.306700,753.727800],
[220.448800,696.507400],
[971.591000,639.287100],
[933.587800,582.066600],
[579.302600,972.132700],
[330.444700,914.912300],
[81.586880,857.691900],
[832.729000,247.757900],
[583.871100,190.537600],
[335.013300,580.603600],
[86.155420,523.383300],
[731.870200,466.162900],
[483.012400,856.228800],
[234.154500,799.008500],
[196.151300,741.788100],
[841.866100,131.854100],
[593.008300,74.633780],
[344.150400,464.699800],
[95.292490,960.193100],
[846.434600,350.259100],
[597.576800,740.325000],
[348.718900,683.104700],
[994.433600,625.884300],
[745.575800,15.950320],
[496.718000,958.730000],
[458.714800,348.795900],
[104.429600,844.289200],
[855.571700,234.355300],
[606.713900,624.421200],
[357.856000,567.200900],
[108.998100,509.980600],
[860.140200,452.760200],
[611.282500,842.826200],
[256.997200,232.892100],
[8.139289,728.385500],
[759.281500,118.451400],
[721.278300,61.231100],
[366.993100,451.297100],
[118.135200,394.076700],
[869.277400,336.856400],
[620.419500,726.922400],
[371.561600,669.702000],
[122.703700,612.481700],
[873.845900,2.547632],
[519.560600,945.327200],
[270.702800,335.393300],
[21.844910,278.172900],
[983.841800,220.952600],
[629.556500,611.018600],
[380.698700,553.798200],
[131.840800,496.577900],
[882.982900,439.357500],
[634.125100,829.423500],
[385.267200,219.489500],
[136.409400,162.269100],
[782.124100,105.048800],
[533.266300,47.828410],
[284.408400,437.894400],
[246.405300,380.674100],
[892.120000,323.453700],
[643.262100,713.519600],
[394.404300,656.299300],
[145.546400,46.365290],
[896.688600,541.858600],
[647.830700,931.924600],
[398.972800,321.990600],
[44.687600,264.770200],
[795.829700,654.836200],
[546.971900,150.329500],
[508.968700,540.395500],
[154.683500,930.461500],
[905.825600,873.241100],
[656.967800,263.307100],
[408.109900,758.800500],
[159.252000,148.866400],
[910.394200,91.646080],
[661.536300,481.712100],
[412.678400,871.778000],
[58.393220,367.271400],
[809.535300,310.051000],
[771.532300,700.117000],
[417.247000,90.182950],
[168.389100,32.962610],
[919.531200,975.742200],
[670.673400,918.521900],
[421.815500,308.587900],
[172.957700,698.653900],
[924.099800,641.433600],
[675.241900,136.926800],
[320.956700,526.992800],
[72.098830,917.058800],
[34.095680,859.838400],
[679.810500,249.904400],
[430.952600,745.397800],
[182.094700,135.463700],
[933.236900,78.243390],
[684.379000,468.309400],
[435.521100,858.375300],
[186.663300,353.868700],
[937.805400,743.934600],
[583.520200,686.714300],
[334.662300,76.780270],
[296.659200,466.846300],
[942.373900,962.339600],
[693.516100,905.119200],
[444.658200,295.185200],
[195.800300,685.251200],
[946.942400,628.030800],
[698.084600,123.524200],
[449.226800,513.590200],
[200.368900,903.656100],
[846.083700,846.435800],
[597.225800,236.501800],
[559.222700,731.995100],
[204.937400,122.061000],
[956.079600,512.127000],
[707.221700,454.906700],
[458.363900,844.972700],
[209.506000,340.466000],
[960.648100,730.532000],
[711.790300,673.311600],
[462.932400,63.377580],
[108.647100,453.443600],
[859.789300,948.936900],
[821.786100,891.716600],
[467.500900,281.782500],
[218.643000,671.848500],
[969.785200,614.628100],
[720.927300,557.407800],
[472.069500,500.187500],
[223.211600,890.253400],
[974.353700,280.319400],
[725.495900,223.099100],
[371.210600,613.165100],
[122.352800,108.658400],
[84.349600,498.724400],
[730.064400,441.504000],
[481.206500,831.570000],
[232.348700,221.635900],
[983.490800,717.129300],
[734.633000,659.909000],
[485.775100,49.974890],
[236.917200,440.040900],
[988.059300,382.820500],
[633.774100,325.600200],
[384.916200,268.379800],
[346.913100,658.445800],
[992.627900,601.225500],
[743.770000,991.291400],
[494.912200,486.784800],
[246.054300,876.850800],
[997.196400,266.916700],
[748.338600,209.696400],
[499.480700,599.762300],
[250.622800,95.255670],
[896.337600,485.321600],
[647.479800,428.101300],
[609.476600,818.167300],
[255.191400,208.233300],
[6.333479,703.726600],
[757.475600,646.506300],
[508.617800,36.572210],
[259.759900,426.638200],
[10.902020,369.417800],
[762.044100,312.197500],
[513.186300,254.977200],
[158.901100,645.043100],
[910.043200,35.109090],
[872.040100,977.888800],
[517.754800,473.382100],
[268.897000,863.448100],
[20.039100,253.514000],
[771.181200,196.293700],
[522.323400,586.359700],
[273.465500,81.852980],
[24.607630,471.919000],
[775.749800,414.698600],
[421.464600,804.764600],
[172.606700,194.830600],
[134.603500,690.324000],
[780.318300,80.389860],
[531.460500,23.169520],
[282.602600,413.235500],
[33.744710,803.301500],
[784.886800,298.794800],
[536.029000,241.574500],
[287.171100,631.640500],
[38.313250,21.706400],
[684.028000,964.486000],
[435.170200,459.979400],
[397.167000,850.045400],
[42.881790,240.111400],
[794.024000,182.891000],
[545.166100,572.957000],
[296.308200,68.450300],
[47.450330,458.516300],
[798.592500,848.582200],
[549.734600,791.361900],
[300.876800,181.427900],
[946.591500,676.921200],
[697.733600,66.987180],
[659.730500,9.766831],
[305.445300,399.832800],
[56.587400,789.898800],
[807.729600,285.392100],
[558.871600,228.171800],
[310.013800,618.237800],
[61.155940,8.303714],
[812.298100,951.083400],
[563.440200,893.863100],
[209.155000,836.642700],
[960.297100,226.708700],
[922.294000,616.774700],
[568.008800,559.554300],
[319.150900,55.047610],
[70.293030,445.113600],
[821.435200,835.179600],
[572.577300,777.959300],
[323.719400,168.025200],
[74.861560,663.518500],
[826.003700,53.584490],
[471.718500,996.364100],
[222.860600,386.430100],
[184.857500,776.496100],
[830.572300,719.275800],
[581.714400,662.055500],
[332.856500,604.835000],
[83.998630,994.901000],
[835.140800,384.967000],
[586.282900,327.746700],
[337.425100,823.240000],
[88.567170,213.306000],
[734.282000,603.372000],
[485.424100,546.151600],
[447.421000,936.217600],
[93.135710,431.710900],
[844.277800,821.776900],
[595.420000,764.556500],
[346.562100,154.622500],
[97.704260,544.688500],
[848.846400,40.181810],
[599.988500,430.247800],
[351.130700,373.027400],
[996.845400,763.093400],
[747.987600,153.159400],
[709.984500,648.652700],
[355.699200,591.432400],
[106.841300,981.498400],
[857.983400,371.564300],
[609.125600,314.344000],
[360.267700,809.837300],
[111.409900,199.903300],
[862.552000,589.969300],
[613.694100,532.748900],
[259.408900,922.814900],
[10.551050,418.308200],
[972.547900,808.374200],
[618.262700,198.440200],
[369.404800,141.219800],
[120.546900,531.285800],
[871.689100,26.779120],
[622.831300,416.845100],
[373.973400,359.624700],
[125.115500,749.690800],
[876.257600,139.756700],
[521.972400,635.250000],
[273.114500,578.029700],
[235.111400,968.095600],
[880.826200,358.161600],
[631.968300,300.941300],
[383.110400,243.720900],
[134.252600,186.500600],
[885.394700,576.566600],
[636.536800,966.632600],
[282.251600,909.412200],
[138.821100,404.905500],
[784.535900,794.971500],
[641.105500,185.037500],
[497.674900,127.817100],
[143.389600,517.883200],
[999.959100,13.376430],
[645.673900,403.442400],
[502.243400,346.222100],
[147.958200,736.288000],
[793.673000,126.354000],
[650.242500,621.847400],
[295.957300,11.913310],
[152.526700,954.692900],
[798.241500,344.759000],
[654.811000,734.824900],
[511.380500,230.318300],
[157.095300,173.097900],
[13.664750,563.163900],
[659.379500,953.229900],
[305.094300,896.009500],
[161.663800,391.502900],
[807.378600,781.568800],
[663.948100,171.634800],
[309.662900,114.414400],
[166.232300,504.480400],
[22.801820,999.973800],
[668.516600,390.039700],
[525.086100,780.105700],
[170.800900,722.885400],
[27.370360,112.951300],
[673.085100,608.444600],
[318.799900,998.510600],
[175.369400,941.290300],
[821.084200,331.356300],
[677.653700,721.422300],
[323.368500,216.915600],
[179.937900,159.695200],
[36.507440,549.761200],
[682.222300,939.827100],
[538.791700,882.606800],
[184.506500,272.672800],
[830.221300,768.166100],
[686.790800,158.232100],
[332.505600,101.011800],
[189.075000,491.077800],
[834.789800,881.143700],
[691.359300,376.637000],
[547.928800,766.703000],
[193.643600,709.482700],
[50.213060,99.548640],
[695.927900,489.614600],
[552.497300,985.107900],
[198.212100,927.887600],
[843.926900,317.953600],
[700.496400,708.019600],
[346.211200,650.799200],
[202.780600,146.292500],
[848.495400,536.358500],
[705.064900,926.424500],
[561.634400,869.204100],
[207.349200,259.270100],
[63.918670,754.763500],
[709.633500,144.829400],
[355.348200,534.895400],
[211.917700,477.675100],
[857.632500,867.741000],
[714.202000,363.234400],
[359.916800,753.300300],
[216.486300,696.080000],
[73.055750,86.145950],
[718.770500,476.211900],
[575.340000,971.705200],
[221.054800,914.484900],
[77.624290,304.550900],
[723.339100,694.616800],
[369.053800,637.396500],
[225.623300,580.176100],
[871.338100,522.955800],
[727.907600,913.021800],
[373.622400,303.087800],
[230.191900,245.867400],
[86.761370,741.360800],
[732.476100,131.426700],
[589.045600,521.492700],
[234.760400,464.272400],
[880.475200,854.338300],
[737.044700,349.831700],
[382.759500,739.897600],
[239.329000,682.677300],
[885.043700,72.743260],
[741.613300,462.809300],
[598.182800,958.302600],
[243.897500,348.368500],
[100.467000,291.148200],
[746.181800,681.214200],
[602.751300,71.280150],
[248.466000,566.773500],
[894.180800,509.553200],
[750.750300,899.619100],
[396.465100,289.685100],
[253.034600,232.464700],
[898.749300,727.958100],
[755.318900,118.024000],
[611.888300,508.090000],
[257.603100,450.869700],
[114.172600,840.935700],
[759.887400,336.429000],
[405.602200,726.495000],
[262.171600,116.560900],
[907.886400,59.340570],
[764.456000,449.406600],
[410.170700,944.899900],
[266.740200,334.965900],
[912.454900,277.745500],
[769.024500,667.811500],
[625.594000,57.877460],
[271.308700,553.370800],
[127.878200,496.150500],
[773.593000,886.216400],
[419.307800,276.282400],
[275.877300,219.062100],
[921.592100,161.841700],
[778.161500,104.621400],
[423.876300,494.687300],
[280.445800,884.753300],
[137.015300,827.533000],
[782.730100,217.598900],
[639.299600,713.092300],
[285.014400,103.158200],
[930.729100,45.937890],
[787.298600,436.003900],
[433.013400,826.069800],
[289.582900,321.563200],
[935.297700,264.342800],
[791.867100,654.408800],
[437.581900,44.474770],
[294.151400,987.254400],
[150.720900,930.034100],
[796.435700,872.813800],
[653.005200,262.879700],
[298.720000,652.945700],
[944.434800,595.725300],
[801.004200,91.218660],
[446.719000,481.284700],
[303.288500,871.350600],
[949.003300,814.130300],
[805.572800,204.196200],
[662.142300,699.689600],
[307.857000,89.755540],
[164.426500,32.535200],
[810.141300,422.601200],
[455.856100,812.667100],
[312.425600,308.160500],
[958.140300,698.226500],
[814.709800,641.006100],
[460.424600,31.072080],
[316.994100,421.138100],
[962.708900,916.631400],
[819.278400,859.411000],
[675.847800,249.477000],
[321.562700,639.543000],
[178.132100,582.322600],
[823.847000,77.815980],
[469.561700,467.882000],
[326.131200,857.947900],
[971.845900,800.727600],
[828.415500,190.793600],
[474.130200,133.573200],
[330.699700,76.352860],
[187.269200,19.132510],
[832.984000,856.484800],
[689.553500,799.264500],
[335.268300,847.471500],
[980.983100,684.823800],
[837.552500,627.603400],
[483.267300,570.383100],
[339.836800,407.735400],
[985.551600,455.942400],
[842.121100,293.294700],
[487.835900,236.074300],
[344.405300,178.854000],
[200.974800,16.206280],
[846.689600,64.413300],
[703.259100,901.765600],
[348.973900,844.545200],
[994.688700,787.324900],
[851.258200,624.677200],
[496.973000,672.884200],
[353.542400,615.663900],
[999.257200,453.016200],
[855.826700,395.795800],
[712.396200,338.575500],
[358.111000,281.355100],
[214.680400,224.134800],
[860.395200,61.487060],
[506.110000,4.266709],
[362.679500,947.046400],
[8.394268,889.826000],
[864.963800,832.605600],
[510.678600,669.958000],
[367.248000,612.737600],
[12.962810,555.517300],
[869.532300,498.296900],
[726.101800,441.076600],
[371.816600,383.856200],
[228.386100,221.208500],
[874.100800,163.988200],
[519.815700,106.767800],
[376.385100,49.547490],
[22.099890,992.327100],
[878.669400,829.679500],
[524.384100,772.459100],
[380.953700,715.238800],
[237.523200,658.018400],
[883.237900,600.798100],
[739.807500,438.150400],
[385.522200,380.930000],
[31.236960,323.709700],
[887.806400,266.489300],
[533.521300,209.269000],
[390.090700,152.048600],
[35.805500,989.400900],
[892.375000,932.180600],
[538.089800,874.960200],
[394.659300,817.739900],
[251.228800,760.519600],
[896.943600,597.871800],
[753.513000,540.651500],
[399.227800,483.431100],
[44.942580,426.210800],
[901.512100,368.990400],
[547.226900,206.342700],
[403.796300,149.122400],
[49.511120,197.329400],
[906.080600,34.681680],
[762.650100,977.461300],
[408.364900,920.240900],
[264.934400,757.593300],
[910.649200,805.800300],
[556.363900,643.152600],
[412.933400,585.932300],
[58.648200,528.712000],
[915.217700,366.064200],
[560.932500,414.271200],
[417.502000,251.623500],
[63.216730,194.403200],
[919.786200,137.182800],
[776.355700,974.535100],
[422.070500,22.742110],
[278.640000,965.521800],
[924.354800,802.874100],
[570.069500,745.653800],
[426.639100,688.433400],
[72.353810,631.213000],
[928.923200,573.992700],
[574.638100,411.345000],
[431.207600,354.124600],
[287.777100,296.904300],
[933.491800,239.683900],
[790.061300,182.463600],
[435.776100,19.815880],
[81.490890,962.595500],
[938.060400,905.375200],
[583.775100,848.154900],
[440.344700,790.934500],
[86.059420,733.714200],
[942.628900,571.066500],
[588.343700,513.846100],
[444.913200,456.625800],
[301.482700,399.405400],
[947.197400,342.185100],
[803.767000,179.537400],
[449.481700,122.317000],
[95.196500,65.096660],
[951.766000,7.876308],
[597.480800,950.655900],
[454.050300,788.008300],
[99.765040,730.787900],
[956.334600,778.995000],
[812.904100,616.347300],
[458.618800,559.126900],
[315.188300,501.906500],
[960.903100,339.258800],
[606.617900,387.465800],
[463.187400,224.818100],
[108.902100,167.597800],
[965.471600,110.377400],
[611.186400,947.729800],
[467.755900,995.936800],
[113.470700,833.289100],
[970.040200,776.068700],
[826.609600,718.848300],
[472.324500,556.200600],
[328.893900,604.407600],
[974.608700,547.187300],
[620.323500,384.539600],
[476.893000,327.319300],
[122.607700,270.098900],
[979.177200,212.878600],
[624.892000,155.658200],
[481.461500,993.010500],
[338.031000,935.790200],
[983.745800,878.569800],
[840.315200,715.922100],
[486.030100,764.129100],
[131.744800,601.481400],
[988.314200,544.261100],
[634.029100,487.040700],
[490.598600,324.393000],
[136.313400,372.600000],
[992.882800,315.379700],
[638.597600,152.732000],
[495.167100,95.511620],
[351.736600,38.291280],
[997.451400,981.070900],
[854.020900,923.850600],
[499.735700,761.202900],
[145.450400,703.982600],
[2.019919,646.762200],
[647.734700,589.541900],
[504.304200,532.321500],
[150.019000,369.673800],
[6.588458,312.453500],
[863.157900,255.233100],
[508.872700,198.012800],
[365.442200,140.792400],
[11.157000,83.572060],
[656.871800,920.924400],
[513.441300,863.704000],
[159.156000,806.483600],
[15.725540,749.263300],
[661.440300,692.043000],
[518.009800,529.395300],
[163.724600,472.175000],
[20.294070,414.954600],
[876.863600,357.734200],
[522.578400,300.513900],
[379.147800,137.866200],
[24.862610,80.645820],
[670.577400,128.852800],
[527.146900,966.205100],
[172.861700,908.984800],
[29.431150,851.764400],
[675.146000,689.116800],
[531.715400,737.323800],
[388.284900,574.676000],
[33.999690,517.455700],
[890.569100,460.235400],
[536.284000,297.587700],
[181.998700,345.794700],
[38.568230,183.147000],
[684.283000,125.926600],
[540.852500,68.706250],
[186.567300,906.058600],
[43.136770,954.265600],
[688.851600,897.045200],
[545.421000,734.397500],
[401.990600,677.177200],
[47.705310,619.956900],
[904.274800,562.736500],
[549.989600,505.516100],
[195.704400,342.868400],
[52.273850,285.648100],
[697.988600,228.427700],
[554.558100,171.207400],
[200.272900,113.987000],
[56.842390,951.339400],
[913.411900,894.118900],
[559.126600,836.898600],
[415.696100,779.678300],
[61.410930,722.458000],
[707.125700,665.237600],
[563.695200,502.589900],
[209.410000,445.369600],
[65.979460,388.149200],
[711.694200,330.928900],
[568.263800,273.708500],
[213.978500,111.060800],
[70.548000,53.840450],
[927.117500,996.620100],
[572.832300,939.399800],
[429.401800,882.179400],
[75.116540,719.531800],
[720.831300,662.311300],
[577.400800,710.518400],
[223.115600,547.870700],
[79.685080,490.650400],
[725.399800,433.430000],
[581.969400,270.782300],
[438.538900,318.989300],
[84.253620,156.341600],
[940.823100,99.121220],
[586.537900,41.900880],
[232.252700,879.253200],
[88.822150,822.032800],
[734.537000,764.812500],
[591.106500,707.592100],
[236.821200,650.371800],
[93.390690,487.724100],
[739.105500,430.503800],
[595.675000,478.710800],
[452.244500,316.063100],
[97.959230,258.842700],
[954.528800,201.622400],
[600.243500,38.974650],
[245.958300,87.181660],
[102.527800,924.533900],
[748.242600,867.313600],
[604.812000,810.093300],
[250.526800,647.445600],
[107.096300,695.652600],
[963.665800,533.004900],
[609.380600,475.784500],
[465.950100,418.564200],
[111.664900,255.916500],
[757.379600,304.123500],
[613.949100,246.903100],
[259.663900,84.255420],
[116.233400,27.035080],
[761.948200,969.814800],
[618.517600,912.594400],
[264.232400,855.374000],
[120.801900,692.726300],
[977.371400,635.506000],
[623.086200,578.285600],
[479.655700,521.065300],
[125.370500,463.845000],
[771.085300,301.197200],
[627.654800,243.976900],
[273.369500,186.756600],
[129.939000,129.536200],
[775.653800,72.315860],
[632.223300,15.095510],
[488.792800,852.447800],
[134.507500,795.227500],
[991.077000,738.007100],
[636.791800,680.786800],
[282.506600,623.566500],
[139.076100,460.918800],
[784.790800,403.698400],
[641.360400,346.478000],
[287.075100,289.257700],
[143.644600,232.037300],
[789.359400,69.389620],
[645.928900,12.169270],
[502.498400,60.376290],
[148.213200,897.728600],
[4.782648,840.508200],
[650.497500,783.287900],
[296.212200,620.640200],
[152.781700,668.847200],
[798.496500,506.199500],
[655.066000,448.979200],
[300.780700,391.758800],
[157.350200,229.111100],
[13.919730,277.318100],
[659.634500,114.670400],
[516.204000,57.450050],
[161.918800,1000.230000],
[807.633600,943.009300],
[664.203100,885.789000],
[309.917800,828.568700],
[166.487300,665.921000],
[812.202100,608.700600],
[668.771600,551.480300],
[314.486400,494.259900],
[171.055900,437.039600],
[27.625340,274.391900],
[673.340100,217.171500],
[529.909600,159.951200],
[175.624400,102.730800],
[821.339200,45.510490],
[677.908600,882.862800],
[323.623500,825.642500],
[180.192900,768.422100],
[825.907700,711.201800],
[682.477200,653.981400],
[539.046700,596.761100],
[184.761500,434.113400],
[41.330960,376.893000],
[687.045700,319.672700],
[332.760500,262.452300],
[189.330000,205.232000],
[835.044800,42.584250],
[691.614300,985.363900],
[337.329100,928.143600],
[193.898600,870.923200],
[839.613300,813.702900],
[696.182800,756.482500],
[552.752300,593.834800],
[198.467100,536.614500],
[55.036570,479.394100],
[700.751300,422.173800],
[346.466100,364.953400],
[203.035600,202.305700],
[848.750400,145.085400],
[705.319900,87.865020],
[351.034700,30.644680],
[207.604200,973.424300],
[64.173650,810.776600],
[709.888500,753.556300],
[566.458000,801.763300],
[212.172700,639.115600],
[857.887400,581.895300],
[714.457000,524.674900],
[360.171800,362.027200],
[216.741300,410.234200],
[862.456000,247.586500],
[719.025500,190.366200],
[364.740300,133.145800],
[221.309800,970.498100],
[77.879260,18.705110],
[723.594100,856.057400],
[580.163500,798.837100],
[225.878300,741.616700],
[871.593100,578.969000],
[728.162600,627.176000],
[373.877400,569.955700],
[230.446900,407.308000],
[876.161600,350.087600],
[732.731100,292.867300],
[589.300600,235.646900],
[235.015400,178.426600],
[91.584890,15.778870],
[737.299700,958.558600],
[383.014400,901.338200],
[239.583900,844.117900],
[885.298700,786.897500],
[741.868200,624.249800],
[387.583000,567.029500],
[244.152500,509.809100],
[889.867200,452.588800],
[746.436800,395.368400],
[603.006300,338.148100],
[248.721000,175.500400],
[105.290500,118.280000],
[751.005300,61.059650],
[396.720100,3.839303],
[253.289600,946.618900],
[899.004300,783.971300],
[755.573800,726.751000],
[401.288600,669.530600],
[257.858100,612.310200],
[114.427600,555.089900],
[760.142300,392.442200],
[616.711900,335.221800],
[262.426600,383.428800],
[908.141400,220.781100],
[764.710900,163.560800],
[410.425700,106.340400],
[266.995200,943.692800],
[912.709900,991.899800],
[769.279500,829.252000],
[414.994200,772.031700],
[271.563700,714.811300],
[128.133200,552.163600],
[773.848000,600.370700],
[630.417500,437.723000],
[276.132200,380.502600],
[921.847100,323.282200],
[778.416500,160.634500],
[424.131300,208.841600],
[280.700800,151.621200],
[926.415500,988.973500],
[782.985100,931.753200],
[639.554600,874.532800],
[285.269300,817.312500],
[141.838800,760.092100],
[787.553600,597.444400],
[433.268400,540.224100],
[289.837900,483.003700],
[935.552600,320.356000],
[792.122100,368.563000],
[437.836900,205.915300],
[294.406400,148.695000],
[940.121100,91.474620],
[796.690700,928.826900],
[653.260100,977.033900],
[298.975000,919.813600],
[155.544400,757.165900],
[801.259200,699.945600],
[446.974000,642.725300],
[303.543500,585.504800],
[949.258200,528.284500],
[805.827800,365.636800],
[451.542500,308.416500],
[308.112000,251.196100],
[164.681500,193.975800],
[810.396300,136.755400],
[666.965800,974.107700],
[312.680600,916.887300],
[958.395300,859.667000],
[814.964800,802.446600],
[460.679600,745.226300],
[317.249100,688.006000],
[962.963900,525.358300],
[819.533400,468.137900],
[465.248200,410.917600],
[321.817600,353.697200],
[178.387100,296.476900],
[824.101900,133.829200],
[680.671400,76.608820],
[326.386200,19.388470],
[972.100900,962.168100],
[828.670500,904.947800],
[474.385200,742.300100],
[330.954700,685.079700],
[976.669500,733.286800],
[833.239000,570.639100],
[689.808500,513.418700],
[335.523300,456.198400],
[192.092700,293.550600],
[837.807500,341.757600],
[483.522300,179.109900]];

  // dbmsg('starCoords.length = ' + starCoords.length);

  var minX = 99999; var minY = 99999;
  var maxX = 0;     var maxY = 0;

  for(var sx = 1; sx <starCoords.length ; sx++){
    var xy = starCoords[sx]; x = xy[0]; y = xy[1];
    minX = Math.min(minX,x); minY = Math.min(minY,y);
    maxX = Math.max(maxX,x); maxY = Math.max(maxY,y);
  }

  function bucketIndex(v, minV, maxV, nbV){
    return Math.floor((v-minV)*nbV/(maxV-minV));
  }

  var charStarCoords = new Array(starCoords.length);

  var plotSizeX;
  var plotSizeY;

  function plusClicked(){
    Xsize.value = String(2*parseInt(Xsize.value));
    Ysize.value = String(2*parseInt(Ysize.value));
    reSizeAndReDraw();
  }
  unsafeWindow.plusClicked = plusClicked;
  function minusClicked(){
    Xsize.value = String(parseInt(Xsize.value)/2);
    Ysize.value = String(parseInt(Ysize.value)/2);
    reSizeAndReDraw();
  }
  unsafeWindow.minusClicked = minusClicked;
  var showAllStars = false;
  function starClicked(){
    showAllStars = !showAllStars;
    if(showAllStars){
      reSizeToMax();
      initPlot();
      for(var sn = 5 ; sn < starCoords.length ; sn++){
        plotStar(sn,'+', '');
      }
      showPlot();
      reSize();
    } else {
      drawListedStars();
    }
  }
  unsafeWindow.starClicked = starClicked;
  function plotOwnBasesClicked(){
    window.setTimeout(function(){
      if(document.getElementById('basesCheckBox').checked)
        GM_setValue('MapBasesChecked', '1');
      else
        GM_setValue('MapBasesChecked', '0');
    }, 0);
  }
  unsafeWindow.plotOwnBasesClicked = plotOwnBasesClicked;
  function reSizeAndReDraw(){
    reSize();
    drawListedStars();
  }
  function reSize(){
    plotSizeX = parseInt(Xsize.value);
    plotSizeY = parseInt(Ysize.value);
    setUpSize();
  }
  unsafeWindow.reSize = reSize;
  function reSizeToMax(){
    plotSizeX = 960;
    plotSizeY = 480;
    setUpSize();
  }

  var blankPlotLine = '';

  function setUpSize(){
    for(var sx = 1 ; sx < starCoords.length ; sx++){
      var fspl = starCoords[sx];
      var ispl = [bucketIndex(fspl[0], minX, maxX, plotSizeX),
                  plotSizeY-bucketIndex(fspl[1], minY, maxY, plotSizeY)];
      charStarCoords[sx] = ispl;
    }
    while(blankPlotLine.length <= (plotSizeX+5)){
      blankPlotLine += '                                ';
    }
    blankPlotLine = blankPlotLine.slice(0, plotSizeX+5);
  }
  reSize(); // i.e. on first loading of this web page

  var plot;
  function plotStr(str, x, y){
    // dbmsg('plotStr: str: *>' + str + '<* x: ' + x + ' y: ' + y);
    var opl = plot[y];
    var npl = opl.slice(0,x) + str + opl.slice(x+str.length);
    plot[y] = npl;
  }

  function dbmsg(txt){
    dbt.appendChild(document.createTextNode(txt + '\n'));
  }

  function plotStar(snInt, plotPfx, plotSfx){
    // dbmsg('snInt: *>' + snInt + '<*');
    if(isNaN(snInt)) return;
    if((snInt < 1) || (snInt >= charStarCoords.length)) return;
    var stp = plotPfx + String(snInt) + plotSfx; // String To Plot
    var x = charStarCoords[snInt][0];
    var y = charStarCoords[snInt][1];
    // dbmsg('stp: ' + stp + ' x= ' + String(x) +
    //                       ' y= ' + String(y));
    var blankSpaceNeeded = '                         '
              .slice(0,  stp.length);
    if(plot[y].slice(x,x+stp.length) == blankSpaceNeeded){
      plotStr(stp, x, y);
    } else {
      // dbmsg('collision: *>' + stp + '  <*\n' +
      //       '       vs: plot[y].slice  (x,x+stp.length) *>' +
      //                   plot[y].slice  (x,x+stp.length) + '<*');
      // displace the plot up or down to   avoid collisions
      var dy = 0;
      while(true){
        if( ((y+dy) >= 0) && ((y+dy) <= plotSizeY) ){
          // dbmsg('Trying: y+dy= ' + (y+dy));
          if( plot[y+dy].slice(x,x+stp.length) == blankSpaceNeeded ){
            plotStr(stp, x, y+dy);
            break;
          }
        }
        if(dy <= 0){
          dy = 1-dy; // 0->1, -1->2 etc.
          if( (y+dy) >= plot.length ){
            dy = -dy; // ran up against the limit
          }
        } else {
          dy = -dy; // 1->-1, 2->-2 etc.
        }
        // dbmsg('dy: ' + dy);
        if( ((y-Math.abs(dy)) < 0) &&
            ((y+Math.abs(dy)) > plotSizeY) ){
          dbmsg('Cannot plot: ' + stp + ': y ' + y + ' dy: ' + dy + ' plotSizeY: ' + plotSizeY);
          break;
        }
      }
    }
  }
  function initPlot(){
    while(dbt.firstChild != null) dbt.removeChild(dbt.firstChild);
    plot = Array(1+plotSizeY);
    for(var y = 0 ; y <= plotSizeY ; y++){
      plot[y] = blankPlotLine;
    }
    for(var ibx = 1 ; ibx <= 4 ; ibx++){
      var xy = charStarCoords[ibx];
      plotStr(String(ibx), xy[0], xy[1]);
    }
    while(map.firstChild != null){
      map.removeChild(map.firstChild);
    }
  }
  function showPlot(){
    map.appendChild(document.createTextNode(plot.join('\r\n')));
  }
  function drawListedStars(){
    var starNum = ((' '+stars.value+' ').replace(' '+ship.value+' ','') +
                   " ^" + ship.value
                  );
    if(document.getElementById('basesCheckBox').checked &&
       bases.value != 'none' && bases.value != 'undefined' ) starNum += " " + bases.value;
    starNum = starNum.replace(/ +/g,' ')
                     .replace(/^ +/,'')
                     .replace(/ +$/,'')
                     .split(' ');
    initPlot();
    // GM_log('drawListedStars/2: starNum: *>' + starNum + '<*');
    for(var snx=0 ; snx < starNum.length ; snx++){
      var sns = starNum[snx].match(/([^0-9]*)(\d+)([^0-9 ]*)/); // starNum separated: [1]prefix [2]num [3]suffix
      // GM_log('starNum[snx] *>' + starNum[snx] + '<*  .charAt(0) *>' + plotChar + '<*');
      if(sns[1]=='') sns[1] = '+'
      plotStar(parseInt(sns[2]), sns[1], sns[3]);
    }
    showPlot();
  }
  unsafeWindow.drawListedStars = drawListedStars;
  function changeListedStars(){
    window.setTimeout(function(){GM_setValue('MapStarsList', document.getElementById('stars').value);}, 0);
  }
  unsafeWindow.changeListedStars = changeListedStars;
  function plotShip(){
    if(!showAllStars) drawListedStars();
  }
  unsafeWindow.plotShip = plotShip;

  // KeyPress handling adapted from http://www.openjs.com/scripts/events/keyboard_shortcuts/, q.v. for BSD license
  function HandleKeyPressEvent(evt){
    evt = evt || window.event
    if(evt.keyCode)    code = evt.keyCode
    else if(evt.shich) code = evt.which
    if(code == 36){ // alert("Home!")
      window.scrollTo(0,0)
    } else if(code == 27) { // Escape
      starClicked()
    }
  }
  window.addEventListener("keypress", HandleKeyPressEvent, false)

  return;

} // end of if(isMapWindow)... ******************************************************************

// From here on we know we're not in the Map window

if(window.parent != window) return; // i.e. it is not a top-level window

//===============================================================
// From here on we know we're in the main, top-level BeakerWindow
//===============================================================

// functions used to set up user macros:

// Cannot detect alt-mouseClick in Gnome: Gnome intercepts it because Gnome uses
// alt-hold-down-left-mouse-button for grab-and-move-window.
// Controlled by gconf-editor under /apps/metacity/general/mouse_button_modifier

function pctExpanded(vv){ // expands %H and %T constructs
    var buttonCommand = vv
    if(buttonCommand.indexOf("%") >= 0){ // i.e. there is a %H%/%T% construct
      var pct1x = buttonCommand.indexOf("%")
      var pct2x = buttonCommand.indexOf("%", pct1x+1)
      if(pct2x > (pct1x+1)){
        var pctxx = buttonCommand.slice(pct1x+1,pct2x)
        if(pctxx.charAt(0) == "H"){
          var headingValue = parseInt(document.getElementById("m_oCurrentHeading").value)
          if(pctxx.length > 2){ // %H+23% or %H-23%
            var pctSgn = pctxx.charAt(1)
            var pctVal = parseInt(pctxx.slice(2))
            if(pctSgn == "-") headingValue -= pctVal
            else              headingValue += pctVal // yes it allows nonsense like %Ha23%
            buttonCommand = buttonCommand.slice(0,pct1x) + headingValue + buttonCommand.slice(pct2x+1)
          } else { // malformed %-construct
            buttonCommand = "What? " + buttonCommand
          }
        } else if(pctxx.charAt(0) == "T"){ // %T%
          var targetValue = document.getElementById("m_oCurrentTarget").value
          buttonCommand = buttonCommand.slice(0,pct1x) + targetValue + buttonCommand.slice(pct2x+1)
        }
      } else { // malformed %-construct
        buttonCommand = "What? " + buttonCommand
      }
  }
  return buttonCommand
}

function rawOnclickHandler(which,evt){
  if(evt.altKey || evt.ctrlKey){ // or evt.shiftKey?
    // Alt- or Ctrl-Clicking the user-button copies the command line into the definition:
    var tb2 = document.getElementById('TextBox2');
    var newdef = tb2.value;
    if(newdef.charAt(0) == ":"){
      c2 = newdef.indexOf(":",1);        // i.e. index of the second ":" character
      which.value = newdef.slice(1,c2);  // label on button
      which.title = newdef.slice(c2+1);  // ToolTip and command to execute
    } else {
      which.value = newdef;
      which.title = newdef;
    }
    tb2.value = "";
    window.setTimeout(function(){
      GM_setValue(which.id, newdef);
    }, 0);
  } else { // just a plain old click
    unsafeWindow.DoCommand(pctExpanded(which.title),false,false,false,false);
  }
}
unsafeWindow.rawOnclickHandler = rawOnclickHandler;

function macroChangeHandler(macroName){ // TODO: Eliminate this (used only in rcURL now)
  return ( function(){
    // GM_log('macro ' + macroName + ' new value ' + document.getElementById(macroName).value);
    GM_setValue(macroName, document.getElementById(macroName).value);
  });
}

function xmitServerMessageA(serverMessage){
  // GM_log('xmitServerMessageA: serverMessage.length = ' + serverMessage.length);
  var rr = GM_xmlhttpRequest({
    method: 'MW3RC', // originally: 'PUT',
    // where should the ship name go? url? headers? data?
    url:    document.getElementById('rcURL').value,
    headers: { 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
               'Accept': 'text/plain', // originally: 'application/atom+xml,application/xml,text/xml',
    },
    data:    serverMessage + '%^%^%', // end-of-message signal for BeakerModeRemoteControl.py
    onload:  function(responseDetails){
      if(false)
      ; // GM_log('GM_xmlhttpRequest:onload');
      else
      GM_log('onload: status        *>' + responseDetails.status          + '<*\n' +
             '   statusText:        *>' + responseDetails.statusText      + '<*\n' +
             '   responseHeaders:   *>' + responseDetails.responseHeaders + '<*\n' +
             '   responseText:      *>' + responseDetails.responseText    + '<*');
      if(responseDetails.responseText != '!idle!')
        unsafeWindow.DoCommand(responseDetails.responseText,false,false,false,false);
    },
    onerror: function(responseDetails){
      if(true)
      ; // GM_log('GM_xmlhttpRequest: onerror: responseDetails: ' + responseDetails);
      else
      GM_log('onerror: status   *>' + responseDetails.status       + '<*\n' +
             '    statusText:   *>' + responseDetails.statusText   + '<*\n' +
             '    responseText: *>' + responseDetails.responseText + '<*');
    }
    // , onreadystatechange: function(){
    // }
  });
  // GM_log('xmitServerMessageA: rr: ' + rr);
}

// xmitServerMessageA('hi');

serverMessageToXmit = '';

function rcXclicked(){
  // GM_log('rcXclicked/0');
  xmitServerMessageA(serverMessageToXmit);
  serverMessageToXmit = '';
}
unsafeWindow.rcXclicked = function(){window.setTimeout(rcXclicked,0);};

function checkboxChangeHandler(cbName){
  return ( function(){
    // GM_log('checkbox ' + cbName + ' new state ' + document.getElementById(cbName).clicked);
    // if(document.getElementById(cbName).clicked)
    GM_setValue(cbName, document.getElementById(cbName).checked);
  });
}

// Logging -- by extraction from TermPanel and ChatPanel

var dumpWin;

function asDumpAllPanelsToLog(){
  dumpWin = window.open('javascript:"MW3 Panel Dump"',
                        "", 'width=800,height=300,scrollbars=yes');
  // GM_log('asDumpAllPanelsToLog: dumpWin.document.body.innerHTML/0: **>' +
  //                               dumpWin.document.body.innerHTML + '<**');
  dumpWin.document.write(
    "<title>MW3 Panel Dump " + Date() + "</title>" +
    '<body>' + Date() +
      '<h1>TermPanel:</h1>' +
       document.getElementById("TermPanel").innerHTML +
      '<h1>ChatPanel:</h1>' +
       document.getElementById("ChatPanel").innerHTML +
    '</body></html>');
  dumpWin.document.close();

  document.getElementById("TermPanel").innerHTML = Date();
  document.getElementById("ChatPanel").innerHTML = Date();

}
unsafeWindow.asDumpAllPanelsToLog = asDumpAllPanelsToLog;

// Mapping - here, in the main window, we just create the Map window:

var mapWin = null;

function mapClicked(){
  mapWin = window.open('javascript:"MW3 Map"', "MW3Map", 'width=400,height=300,scrollbars=yes');
  mapWin.document.write(
    "<title>MW3 Map</title>" +
    "<body>" +
      "<input type='button' value='+' style='width:1.0em' onclick='plusClicked();'  />" +
      "<input type='button' value='-' style='width:1.0em' onclick='minusClicked();' />&nbsp;" +
      "Xsize:<input type='text' id='Xsize' size=2 value='48' " +
                   "onchange='reSize();' onblur='drawListedStars();' />&nbsp;" +
      "Ysize:<input type='text' id='Ysize' size=2 value='24' " +
                   "onchange='reSize();' onblur='drawListedStars();' />" +
      "<input type='button' value='*' style='width:1.0em' onclick='starClicked();' " +
                          " title='Toggle display-all-stars -- Esc key is same as clicking this button, Home key returns to upper left corner' />" +
      "B:<input type='checkbox' id='basesCheckBox' title='plot own Bases' onclick='plotOwnBasesClicked();'/>" +
      "Star(s):<input type='text' id='stars' size='20' " +
               "onkeydown='if ((event.keyCode == 13)) {changeListedStars();return false;} else return true;'" +
               "onchange='changeListedStars();' " +
               "title='Stars to plot - add prefixes and suffixes as you like e.g. abc123def'/>" +
      "<input type='text'   id='bases'    style='" + invisibleStyle + "' />" +
      "<input type='text'   id='ship'     style='" + invisibleStyle + "' />" +
      "<input type='button' id='plotShip' style='" + invisibleStyle + "' onclick='plotShip();' />" +
      "<pre id='dbt'></pre> " +
      "<pre id='map'></pre> " +
    "</body></html>");
  mapWin.document.close();
  window.setTimeout(function(){
    mapWin.document.getElementById('stars').value = GM_getValue('MapStarsList', "");
    mapWin.document.getElementById('basesCheckBox').checked = GM_getValue('MapBasesChecked', "") == '1';
    // GM_log('MapWindowOpen := 1');
    GM_setValue('MapWindowOpen', '1');
  }, 0);
}
unsafeWindow.mapClicked = mapClicked;

if(GM_getValue('MapWindowOpen', "") == '1'){
  // GM_log('Re-opening MapWindow');
  // Firefox detects this as an attempt to pop-up a window! --> window.setTimeout(mapClicked, 0);
  // Throws error: window.setTimeout("document.getElementById('MapButton').click()", 0);
  window.setTimeout("mapClicked()", 0);
} else {
  // GM_log('Not re-opening MapWindow');
}
function plotShipTclicked(){
  // copy shipT in main window to ship in mapWin and click plotShip in mapWin
  if(mapWin == null || mapWin.document == null){
    // no map window or map window was closed
    window.setTimeout(function(){
      // GM_log('MapWindowOpen := 0');
      GM_setValue('MapWindowOpen', '0');
    }, 0);
    return;
  }
  mapWin.document.getElementById('ship' ).value = document.getElementById('shipT' ).value;
  var basesT = document.getElementById('basesT');       // text element in main window
  var bases  = mapWin.document.getElementById('bases'); // text element in Map  window
  if(basesT.value == ''){
    // Value in main window is blank - recall previous value
    window.setTimeout(function(){
      var basesT = document.getElementById('basesT');
      basesT.value = GM_getValue('MapBasesList', "");
      mapWin.document.getElementById('bases').value = basesT.value;
    }, 0);
  } else if(bases.value != basesT.value){
    // non-blank value in main window differs from value in Map window - must have changed
    bases.value = basesT.value;
    window.setTimeout(function(){
      GM_setValue('MapBasesList', document.getElementById('basesT').value); // remember it
    }, 0);
  }
  bases.value = basesT.value;
  mapWin.document.getElementById('plotShip').click();
}
unsafeWindow.plotShipTclicked = plotShipTclicked;
//==============================================================================================

// Locate the login name and its parent and grandparent:
var loginSPAN = document.getElementById('ctl00_ctl00_LoginView2_m_oLoginName')

if(loginSPAN == null) return; // must be a secondary window, like the Map

if(suppressLoginName && loginSPAN.firstChild != null){
  loginSPAN.firstChild.data = '[suppressed]';
}
var loginTD   = loginSPAN.parentNode;
var loginTR   = loginTD.parentNode;

// Change the window Title
var headNode = document.getElementById("ctl00_ctl00_Head1");
var titleNode = headNode.firstChild   // #text
                        .nextSibling  // LINK
                        .nextSibling  // LINK
                        .nextSibling  // TITLE
                        .firstChild;  // #text
titleNode.appendData('- MW3TR:Flight:' + loginSPAN.textContent);

// Add CheckBoxes at top:

var hTD   = document.getElementById("header");
var logoTR= hTD   .firstChild       // #text
                  .nextSibling      // TABLE
                  .firstChild       // #text
                  .nextSibling      // TBODY
                  .firstChild;      // TR
var logoTD= logoTR.firstChild       // #text
                  .nextSibling;     // TD

var iTD   = document.createElement("TD");
logoTR.insertBefore(iTD, logoTD.nextSibling);
iTD.style.color = "rgb(111, 200, 253)";
iTD.innerHTML = "Disable  AutoScroll<br/>"+
                "<input type='checkbox' id='dasTmP'>Term&nbsp;"      +
                "<input type='checkbox' id='dasCtP'>Chat<br/><br/>"  +
                "<input type='checkbox' id='timeStamp'>TimeStamp";
                // never implemented: + "<br/><input type='checkbox' id='deMux'    >DeMux Chat";

//=====================================================================================================
// Add Function Key Definitions:

// TODO: ?also Ctrl+1 etc.?
// Firefox uses f1 f3 f4 f5 f6 f7 f8(PrefBar) f11
// That leaves F2 F9 F10 F12 available

// Make room:
logoTD.style.width = "300px";

// Add Fkey definitions box:
var fkTD = document.createElement("TD");
logoTR.insertBefore(fkTD, iTD);
fkTD.style.color = "rgb(111, 200, 253)";
fkTD.innerHTML = "F2&nbsp;&nbsp; <input type='text' size='14' id='f2Command' ><br/>" +
                 "F9&nbsp;&nbsp; <input type='text' size='14' id='f9Command' ><br/>" +
                 "F10            <input type='text' size='14' id='f10Command' ><br/>" +
                 "F12            <input type='text' size='14' id='f12Command' ><br/>";

// TODO: Make these boxes loadable from CommandLine by clicking in the boxes!

// The following  shortcut  object comes from the indicated web page:
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
/**
 * http://www.openjs.com/scripts/events/keyboard_shortcuts/
 * Version : 2.01.B
 * By Binny V A
 * License : BSD
 */
shortcut = {
 'all_shortcuts':{},//All the shortcuts are stored in this array
 'add': function(shortcut_combination,callback,opt) {
  //Provide a set of default options
  var default_options = {
   'type':'keydown',
   'propagate':false,
   'disable_in_input':false,
   'target':document,
   'keycode':false
  }
  if(!opt) opt = default_options;
  else {
   for(var dfo in default_options) {
    if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
   }
  }

  var ele = opt.target;
  if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
  var ths = this;
  shortcut_combination = shortcut_combination.toLowerCase();

  //The function to be called at keypress
  var func = function(e) {
   e = e || window.event;
   
   if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
    var element;
    if(e.target) element=e.target;
    else if(e.srcElement) element=e.srcElement;
    if(element.nodeType==3) element=element.parentNode;

    if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
   }
 
   //Find Which key is pressed
   if (e.keyCode) code = e.keyCode;
   else if (e.which) code = e.which;
   var character = String.fromCharCode(code).toLowerCase();
   
   if(code == 188) character=","; //If the user presses , when the type is onkeydown
   if(code == 190) character="."; //If the user presses , when the type is onkeydown

   var keys = shortcut_combination.split("+");
   //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
   var kp = 0;
   
   //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
   var shift_nums = {
    "`":"~",
    "1":"!",
    "2":"@",
    "3":"#",
    "4":"$",
    "5":"%",
    "6":"^",
    "7":"&",
    "8":"*",
    "9":"(",
    "0":")",
    "-":"_",
    "=":"+",
    ";":":",
    "'":"\"",
    ",":"<",
    ".":">",
    "/":"?",
    "\\":"|"
   }
   //Special Keys - and their codes
   var special_keys = {
    'esc':27,
    'escape':27,
    'tab':9,
    'space':32,
    'return':13,
    'enter':13,
    'backspace':8,
 
    'scrolllock':145,
    'scroll_lock':145,
    'scroll':145,
    'capslock':20,
    'caps_lock':20,
    'caps':20,
    'numlock':144,
    'num_lock':144,
    'num':144,
    
    'pause':19,
    'break':19,
    
    'insert':45,
    'home':36,
    'delete':46,
    'end':35,
    
    'pageup':33,
    'page_up':33,
    'pu':33,
 
    'pagedown':34,
    'page_down':34,
    'pd':34,
 
    'left':37,
    'up':38,
    'right':39,
    'down':40,
 
    'f1':112,
    'f2':113,
    'f3':114,
    'f4':115,
    'f5':116,
    'f6':117,
    'f7':118,
    'f8':119,
    'f9':120,
    'f10':121,
    'f11':122,
    'f12':123
   }
 
   var modifiers = { 
    shift: { wanted:false, pressed:false},
    ctrl : { wanted:false, pressed:false},
    alt  : { wanted:false, pressed:false},
    meta : { wanted:false, pressed:false} //Meta is Mac specific
   };
                        
   if(e.ctrlKey) modifiers.ctrl.pressed = true;
   if(e.shiftKey) modifiers.shift.pressed = true;
   if(e.altKey) modifiers.alt.pressed = true;
   if(e.metaKey)   modifiers.meta.pressed = true;
                        
   for(var i=0; k=keys[i],i<keys.length; i++) {
    //Modifiers
    if(k == 'ctrl' || k == 'control') {
     kp++;
     modifiers.ctrl.wanted = true;

    } else if(k == 'shift') {
     kp++;
     modifiers.shift.wanted = true;

    } else if(k == 'alt') {
     kp++;
     modifiers.alt.wanted = true;
    } else if(k == 'meta') {
     kp++;
     modifiers.meta.wanted = true;
    } else if(k.length > 1) { //If it is a special key
     if(special_keys[k] == code) kp++;
     
    } else if(opt['keycode']) {
     if(opt['keycode'] == code) kp++;

    } else { //The special keys did not match
     if(character == k) kp++;
     else {
      if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
       character = shift_nums[character]; 
       if(character == k) kp++;
      }
     }
    }
   }
   
   if(kp == keys.length && 
      modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
      modifiers.shift.pressed == modifiers.shift.wanted &&
      modifiers.alt.pressed == modifiers.alt.wanted &&
      modifiers.meta.pressed == modifiers.meta.wanted) {
    callback(e);
 
    if(!opt['propagate']) { //Stop the event
     //e.cancelBubble is supported by IE - this will kill the bubbling process.
     e.cancelBubble = true;
     e.returnValue = false;
 
     //e.stopPropagation works in Firefox.
     if (e.stopPropagation) {
      e.stopPropagation();
      e.preventDefault();
     }
     return false;
    }
   }
  }
  this.all_shortcuts[shortcut_combination] = {
   'callback':func, 
   'target':ele, 
   'event': opt['type']
  };
  //Attach the function with the event
  if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
  else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
  else ele['on'+opt['type']] = func;
 },

 //Remove the shortcut - just specify the shortcut and I will remove the binding
 'remove':function(shortcut_combination) {
  shortcut_combination = shortcut_combination.toLowerCase();
  var binding = this.all_shortcuts[shortcut_combination];
  delete(this.all_shortcuts[shortcut_combination])
  if(!binding) return;
  var type = binding['event'];
  var ele = binding['target'];
  var callback = binding['callback'];

  if(ele.detachEvent) ele.detachEvent('on'+type, callback);
  else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
  else ele['on'+type] = false;
 }
} // End of shortcut object definition
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

// Handle Fkeys:
function fkeyHandler(which){
  unsafeWindow.DoCommand(pctExpanded(document.getElementById(which).value),
                         false,false,false,false);
}
shortcut.add("F2",  function(){fkeyHandler('f2Command' )});
shortcut.add("F9",  function(){fkeyHandler('f9Command' )});
shortcut.add("F10", function(){fkeyHandler('f10Command')});
shortcut.add("F12", function(){fkeyHandler('f12Command')});

// Handle CapsLock key:
function capsLockKeyHandler(){
  unsafeWindow.DoCommand("CapsLockKeyHit", false,false,false,false);
}
shortcut.add("capslock", capsLockKeyHandler);

// or maybe use Ctrl-capslock either to toggle combat mode
// or to toggle CapsLock state *without* toggling combat mode?
// Put a CombatMode state indicator on screen? A red C character by CommandLine?
// It might be possible to detect the capsLock *state* instead:
// http://24ways.org/2007/capturing-caps-lock
// http://www.experts-exchange.com/Microsoft/Development/Q_22474913.html
//===================================================================================================

// Add CheckBoxes below "Enter Commands:" line:
var sendCmd = document.getElementById('SendCmd');
var lbdDIV  = document.createElement("DIV");
sendCmd.parentNode.insertBefore(lbdDIV, sendCmd);

lbdDIV.innerHTML = "<input type='checkbox' id='noFG'    title='Stop Focus-Grabbing'    >SFG&nbsp;&nbsp;" +
                   "<input type='checkbox' id='rcEnable'title='Enable Remote Control'  >RC:" +
                   "<input type='text'     id='rcURL'   title='Remote Control URL'" +
                                           "size='35'   value='http://LocalHost:30666/'>" +
                   // Remote Control:
                   "<input type='button'   id='rcX' "       + "style='" + invisibleStyle + "' />" +
                   // Plotting own ship location:
                   "<input type='text'     id='shipT' "     + "style='" + invisibleStyle + "' />" +
                 "B:<input type='text'     id='basesT'  title='Own Bases from BAS command to plot on Map - " +
                                    "Edit if you like, but another BAS will destroy any edits you make.' />" +
                   "<input type='button'   id='plotShipT' " + "style='" + invisibleStyle + "' />";

lbdDIV.insertBefore(lbdDIV.parentNode.removeChild(sendCmd), lbdDIV.firstChild);

document.getElementById('rcX')      .setAttribute("onclick", "{rcXclicked();}");
document.getElementById('plotShipT').setAttribute("onclick", "{plotShipTclicked();}");

// Persistent value handling must be done later: not all elements with persistent value are defined yet!

// Changes to the BeakerPanel:

var bfmwTD = document.getElementById('Nav1').parentNode  // TD
                                            .parentNode  // TR
                                            .parentNode  // TBODY
                                            .parentNode  // TABLE
                                            .parentNode; // TD
var bfmwTR = bfmwTD.parentNode;

if(putBeakerPanelOnTheRight){
  bfmwTR.removeChild(bfmwTD);
  bfmwTR.appendChild(bfmwTD);
}

bfmwTD.style.width = '170px';

document.getElementById('Nav1').style.width = '0.8em';
document.getElementById('Nav2').style.width = '0.8em';
document.getElementById('Nav3').style.width = '0.8em';
document.getElementById('Nav4').style.width = '0.8em';

document.getElementById('NavS')  .style.width = '3.5em'; // "Nav S" 4.0 = 5*0.8
document.getElementById('ProS')  .style.width = '3.4em'; // "Pro S" 4.0 = 5*0.8

seaNode = document.getElementById('Sea300');
// seaNode is a DIV. Original contains a SPAN that implements a BlueBeaker button.
// Replace it with a checkbox to enable auto-Sea and a textbox for the range of auto-Sea:
seaNode.className = ""; // removeAttribute("className");
seaNode.innerHTML = "<input    type='checkbox' id='autoSeaCheckBox' title='enable Auto-Search in hyper'/>" +
                    "Sea<input type='text'     id='autoSeaRange' " +
                              "style='width: 55px;' title='range of Auto-Search in hyper'/>";

// Add a MAP button:
mapTR = document.createElement('TR');
mapTR.innerHTML = "<td><div class='BlueBeaker' id='MapButton' onclick='mapClicked()' " +
                           "title='Display map in separate window'>" +
                    "<span>Map</span></div></td>";
seaNode.parentNode.parentNode.parentNode.insertBefore(mapTR, seaNode.parentNode.parentNode.nextSibling);
// DIV  TD         TR         TBODY                          DIV     TD         TR         #text

tgtINPUT = document.getElementById("m_oCurrentTarget" ); // Target box  ??>>ap.style.width='3.2em';
thTABLE  = tgtINPUT.parentNode.parentNode.parentNode.parentNode;
//         INPUT    TD         TR         TBODY      TABLE        << Parent of thTABLE is bfmwTD

bfmwTD.removeChild(thTABLE.previousSibling); // #text  "Combat Computer"
bfmwTD.removeChild(thTABLE.previousSibling); // BR
bfmwTD.removeChild(thTABLE.previousSibling); // #text

thdgINPUT = document.getElementById("m_oCurrentHeading");

tgtLblTD = tgtINPUT.parentNode.previousSibling.previousSibling;
//         INPUT    TD         #text           TD

lasLockDIV = document.getElementById('LocT');
lasFireDIV = document.getElementById('FirT');
lasTABLE   = lasLockDIV.parentNode.parentNode.parentNode.parentNode;
//           DIV        TD         TR         TBODY      TABLE
bfmwTD.removeChild(lasTABLE.previousSibling); // #text  Lasers

// TODO: Add a "BS" (BroadSide) button here? Or maybe not.

minMisDIV = document.getElementById('MinMis'); // "Min Miss" button
misTABLE = minMisDIV.parentNode.parentNode.parentNode.parentNode;
//         DIV       TD         TR         TBODY      TABLE
bfmwTD.removeChild(misTABLE.previousSibling); // #text  Missile Load:

minMisDIV.title = 'Launch minimum-power missile';

document.getElementById('MaxMis'     ).title = 'Launch maximum-power missile';
document.getElementById('MisLoa'     ).title = 'Launch missile loaded as specified';
document.getElementById("MissileLoad").title = 'Missile loading for "Value" button';

imp100DIV = document.getElementById('Imp100');
engTABLE = imp100DIV.parentNode.parentNode.parentNode.parentNode;
//         DIV       TD         TR         TBODY      TABLE
bfmwTD.removeChild(engTABLE.previousSibling); // #text   Engines
bfmwTD.removeChild(engTABLE.previousSibling); // BR

imp100DIV.firstChild.textContent = "I,100";
//        SPAN       #text
imp100DIV.title = "Imp ,100";

war0DIV = document.getElementById('War0');

planetDIV = document.getElementById('PlanetPanel'); // .parentNode is bfmwTD
bfmwTD.removeChild(planetDIV.previousSibling); // #text
bfmwTD.removeChild(planetDIV.previousSibling); // BR
bfmwTD.removeChild(planetDIV.previousSibling); // #text  Planets:
bfmwTD.removeChild(planetDIV.previousSibling); // BR

isbb = planetDIV; // Insert Side Buttons Before "Planets"

// add "PM", "IC" and "dmpL" buttons right after "Planets":
baPls = [{v:'dmpL', w:'3.2em', c:"asDumpAllPanelsToLog()",           t:'Dump Logs to separate window'},
         {v:'PM',   w:'2.1em', c:"{window.location='PlanetManagement.aspx';}", t:'Planet Management' },
         {v:'IC',   w:'2.1em', c:"{window.location='InfoCenter.aspx';}",       t:'Information Center'}];
for( var bx=0 ; bx<baPls.length ; bx++ ){
  aB = document.createElement('INPUT');
  aB.setAttribute('type',    'button');
  aB.setAttribute('style',   'width:' + baPls[bx].w + ';border-left-width:1px;border-right-width:1px;' +
                                                      'text-align:center;padding-left:0px;'            +
                                                      'padding-right:0px;');
  aB.setAttribute('onclick', baPls[bx].c);
  aB.setAttribute('value',   baPls[bx].v);
  aB.setAttribute('title',   baPls[bx].t);
  planetDIV.parentNode.insertBefore(aB, planetDIV.nextSibling);
}

// Remove unneeded white space:

document.getElementById("CmdBuffer").parentNode.style.height = "0px"
document.getElementById("CmdText"  ).parentNode.style.height = "0px"

// Add User Buttons:

function addUserButtons(howMany, toWhatParentNode,
                                 beforeWhatNode, withWhatNameRoot, inHowManyColumns){
  for(bx = 1 ; bx < 1+howMany ; bx++ ){
    var ubName = withWhatNameRoot + bx;
    var ubtn = document.createElement('INPUT'); // the button
    ubtn.setAttribute('type',    'button');
    ubtn.setAttribute('style',   'width:62px;border-left-width:1px;border-right-width:1px;text-align:left');
    ubtn.setAttribute('onclick', "rawOnclickHandler(this,event)");
    toWhatParentNode.insertBefore(ubtn, beforeWhatNode);
    ubtn.setAttribute('id',    ubName);
    var newdef = GM_getValue(ubName, "");
    if(newdef.charAt(0) == ":"){
      c2 = newdef.indexOf(":",1);        // i.e. index of the second ":" character
      ubtn.setAttribute('value', newdef.slice(1,c2));  // label on button
      ubtn.setAttribute('title', newdef.slice(c2+1));  // ToolTip and command to execute
    } else {
      ubtn.setAttribute('value', newdef); // label on button
      ubtn.setAttribute('title', newdef); // ToolTip and command to execute
    }
    if( (bx % inHowManyColumns)==0 ){
      toWhatParentNode.insertBefore(document.createElement('BR'), beforeWhatNode);
    }
  }
}

//=============================
// Add user buttons at the side:
//=============================

addUserButtons(numberOfBeakerPanelButtons, bfmwTD, isbb, "UserButton", 2);

//===========================
// User buttons at the bottom:
//===========================

var bfmwTABLE = bfmwTR.parentNode;                    // Beaker Flight Mode Window TABLE node
var bubTD     = bfmwTABLE.insertRow(1).insertCell(0); // Bottom User Buttons TD node
bubTD.colSpan = 2;

addUserButtons(numberOfBottomPanelButtons, bubTD, null, "BottomUserButton", 12);
//                                                ^^^^ i.e. at the end

// From MW3TR 2.0.28, the fol declarations+initializations are no longer enough
// to give hackedCalledBack access to the values:
var oTxt = document.getElementById("TextBox2"); // commands typed by hand
var oCmd = document.getElementById("CmdText");  // commands generated by buttons i.e. by calls to DoCommand
var oTerm = document.getElementById("TermPanel");
var oScan = document.getElementById("ScanPanel");
var oStat = document.getElementById("StatPanel");
// The loa/tor buttons in the StatPanel are volatile, rebuilt anew with every server message
var oChat = document.getElementById("ChatPanel");
var oPlts = document.getElementById("PlanetPanel");

//====================
// Move Combat Buttons:
//====================

window['moveCombatButtons'] = moveCombatButtons;
if(moveCombatButtons){

  // [Lock] [Fire] [Mis 1e] [Mis 999999e] [Mis Value] [Value Box] 8 torpedos buttons
  oChat.parentNode.removeChild(oChat.nextSibling);  // delete #text: "Enter Commands:"
  oChat.parentNode.removeChild(oChat.nextSibling);  // delete BR that ends that line
  var mcbDIV = document.createElement('DIV'); // to hold the moved buttons
  mcbDIV.setAttribute('id', 'mcbDIV');
  if(putCombatButtonsOnTheRight) mcbDIV.style.textAlign = 'right';
  // mcbDIV.appendChild(whatever); to add things to the CombatButtons area
  oChat.parentNode.insertBefore(mcbDIV, oChat.nextSibling);

  // Move the Lock|Fire buttons:
  ap0TD = document.getElementById('FirT').parentNode; // |Fire
  //                                      TD        
  ap0TABLE = ap0TD.parentNode.parentNode.parentNode;
  //               TR         TBODY      TABLE
  mcbDIV.appendChild(ap0TABLE.parentNode.removeChild(ap0TABLE));
  // Move the whole Lock|Fire TABLE, which becomes the combat bar table

  userButtonsAfterFireTD = document.createElement('TD');
  ap0TD.parentNode.appendChild(userButtonsAfterFireTD);

  // Move the Missile Stuff:
  ap1TD = document.getElementById('MinMis').parentNode; // Min|
  //                                        TD
  ap1TABLE = ap1TD.parentNode.parentNode.parentNode;
  //               TR         TBODY      TABLE
  ap2TD = document.getElementById('MaxMis').parentNode; // |Max

  ap0TD.parentNode.appendChild(ap1TD.parentNode.removeChild(ap1TD)); // Move Min|
  ap0TD.parentNode.appendChild(ap2TD.parentNode.removeChild(ap2TD)); // Move |Max

  ap1TD = document.getElementById('MisLoa').parentNode;      // Value|
  //                                        TD
  ap2TD = document.getElementById('MissileLoad').parentNode; // |[value]

  ap0TD.parentNode.appendChild(ap1TD.parentNode.removeChild(ap1TD)); // Move Value|
  ap0TD.parentNode.appendChild(ap2TD.parentNode.removeChild(ap2TD)); // Move |[value]

  // Remove the now-empty TABLE that had held the Missile Stuff:
  ap1TABLE.parentNode.removeChild(ap1TABLE);

  // Move the Torp buttons:
  // Cannot move them once and for all: StatPanel gets rebuilt on every update from the Game-server
  function removeOldTorpButtons(){  // gets called from CalledBack on every update from server
    var tbx = 1;
    while(true){
      var tbDIV = document.getElementById("Tor_"+tbx);
      if(tbDIV == null) return;
      tbDIV.parentNode.parentNode.removeChild(tbDIV.parentNode);
      tbx++;
    }
  }
  window['removeOldTorpButtons'] = removeOldTorpButtons;
  function moveTorpButtons(){  // gets called from CalledBack on every update from server
    var tb1DIV = document.getElementById("Tor_1");
    if(tb1DIV == null) return; // no torp buttons yet - startup transient
    var otbTABLE = tb1DIV.parentNode.parentNode.parentNode.parentNode;
    //                    TD         TR         TBODY      TABLE
    //  otbTABLE = Old Torp Button TABLE
    var mcbTR = document.getElementById("MisLoa").parentNode.parentNode;
    //                                            TD         TR
    var itbBfr = document.getElementById("UserButtonAfterTorps1");
    //  itbBfr = Insert Torp Buttons Before -- might be null if no User Buttons After Torps
    if(itbBfr != null) itbBfr = itbBfr.parentNode; // i.e. the TD not the button itself
    var tbx = 1;
    while(true){
      var tbDIV = document.getElementById("Tor_"+tbx);
      if(tbDIV == null) break;
      var tbTD = tbDIV.parentNode;
      mcbTR.insertBefore(tbTD.parentNode.removeChild(tbTD), itbBfr);
      tbx++;
    }
    otbTABLE.parentNode.removeChild(otbTABLE); // remove the old TABLE
  }
  window['moveTorpButtons'] = moveTorpButtons;

  userButtonsAfterTorpsTD = document.createElement('TD');
  ap0TD.parentNode.appendChild(userButtonsAfterTorpsTD);

  // Add user buttons to the combat bar:
  //addUserButtons(howMany, toWhatParentNode, beforeWhatNode, withWhatNameRoot, inHowManyColumns)
  addUserButtons(numberOfUserButtonsAfterFire,  userButtonsAfterFireTD,  null, "UserButtonAfterFire",
                 numberOfUserButtonsAfterFire);
  addUserButtons(numberOfUserButtonsAfterTorps, userButtonsAfterTorpsTD, null, "UserButtonAfterTorps",
                 numberOfUserButtonsAfterTorps);

} // End of if(moveCombatButtons)...

//=====================
// Command-line history:
//=====================

commandHistory = [];
commandHistoryX = 0; // current index into commandHistory
function captureCommandHistory(){
  // GM_log('captureCommandHistory: TextBox2: *>' + oTxt.value + '<*');
  commandHistory.unshift(oTxt.value);
  if(commandHistory.length > 20) commandHistory.length = 20;
  commandHistoryX = 0;
}
unsafeWindow.captureCommandHistory = captureCommandHistory;
function recallCommandHistory(){
  if(commandHistoryX >= commandHistory.length) return;
  oTxt.value = commandHistory[commandHistoryX];
  commandHistoryX += 1;
  if(commandHistoryX >= commandHistory.length) commandHistoryX = 0;
}
unsafeWindow.recallCommandHistory = recallCommandHistory;
// The Send button always gets clicked when sending a command, either by hand
// or by the onkeydown function of TextBox2 when the key is Enter.
var oSendButton = document.getElementById('SendCmd');
oSendButton.setAttribute("onclick",
                         "{captureCommandHistory(); DoChatCallBack(document.getElementById('TextBox2')); }"
);
function modifyCurrentCommand(){
  oTxt.value = oTxt.value.replace(/^lib /,       '~nav ')
                         .replace(/^(nav|pro) /, '~lib ').replace(/^~/,'');
}
unsafeWindow.modifyCurrentCommand = modifyCurrentCommand;

oTxt.setAttribute("onkeypress", "{if(event.keyCode == 38) recallCommandHistory();" + // arrow up
                                " if(event.keyCode == 40) modifyCurrentCommand();" + // arrow down
                                "}");
oTxt.setAttribute('title', '↑ for command history, ↓ to morph nav ↔ lib');

//=========================
// Handle persistent values:
//=========================

var persistentCheckbox = ['dasTmP', 'dasCtP', 'timeStamp', 'autoSeaCheckBox', 'noFG', 'rcEnable'];
for( pcbx = 0 ; pcbx < persistentCheckbox.length ; pcbx++ ){
  pcbName = persistentCheckbox[pcbx];
  pcbNode = document.getElementById(pcbName);
  pcbNode.checked = GM_getValue(pcbName, "");
  eval("pcbNode.addEventListener('change', function(){" +
    "window.setTimeout(checkboxChangeHandler('" + pcbName + "'), 0);" +
  "}, false);");
}

var persistentTextbox = ['rcURL', 'autoSeaRange', 'f2Command', 'f9Command', 'f10Command', 'f12Command'];
for( ptbx = 0 ; ptbx < persistentTextbox.length ; ptbx++ ){
  ptbName = persistentTextbox[ptbx];
  ptbValueSaved = GM_getValue(ptbName, "");
  ptbElement = document.getElementById(ptbName);
  if((ptbValueSaved != undefined) && (ptbValueSaved != '')) ptbElement.value = ptbValueSaved;
  eval("ptbElement.addEventListener('change', function(){" +
    "window.setTimeout(macroChangeHandler('" + ptbName + "'), 0);" +
  "}, false);");
}

//============================
// Create the local-scan panel:
//============================
unsafeWindow.separateLocalScanPanel = separateLocalScanPanel
if(separateLocalScanPanel){
  // Merchant wants it sortable, esp. by distance
  shipPanel = document.getElementById("ShipPanel") ; shipPanel.style.width  = "370px"
  statPanel = document.getElementById("StatPanel") ; statPanel.style.height = "080px"
  originalShipTR = shipPanel.parentNode.parentNode
  statPanel.parentNode.appendChild(shipPanel)
  originalShipTR.parentNode.removeChild(originalShipTR)
  shipPanel.parentNode.style.width = "370px"
  newChatLocalScanTR = originalShipTR
  chatPanelDIV = document.getElementById("ChatPanel") // ; chatPanelDIV.style.width = "370px"
  chatPanelDIV.parentNode.colSpan = 3

  //newChatLocalScanTR.innerHTML = "<td id='newChatPanelTD'   style='width:700px;height:125px' />" +
  //                               "<td id='localScanPanelTD' style='width:102px;height:125px'>" +
  //                               "  <div id='localScanPanel' />" +
  //                               "<td/>"
  //document.getElementById("newChatPanelTD").appendChild(chatPanelDIV)

  termPanel = document.getElementById("TermPanel") ; termPanel  .style.width = "215px"
  termPanelTD = termPanel.parentNode               ; termPanelTD.style.width = "215px"
  upperTR = termPanelTD.parentNode
  localScanPanelTD = document.createElement("TD")
  localScanPanelTD.innerHTML = "<div id='localScanPanel' class='TermPanel' style='width:215px;height:420px;overflow-y:scroll;text-align:left' />"
  upperTR.appendChild(localScanPanelTD)
  unsafeWindow.localScanPanel = document.getElementById("localScanPanel")
} // end of if(separateLocalScanPanel)...

//=============================
// Hack the CalledBack function:
//=============================

// GM_log( 'original CalledBack:\n' + unsafeWindow.CalledBack );

function hackedCalledBack(result, context) {

  window.clearTimeout(unsafeWindow.WebChatTimeoutID);
  if (result.length > 0) {
    if (result.search("ENTERDRYDOCK") != -1) {
      unsafeWindow.needToConfirm = false; // expansion of function releaseDirtyFlag
      window.location = "DryDock.aspx";
      return;
    }
    var tsDate = new Date();
    var timeStampNow = '+' + tsDate.toTimeString().slice(0,8) +
                       '.' + ('000'+tsDate.getMilliseconds()).slice(-3) + '+';
    if(document.getElementById('timeStamp').checked){
      var ts = timeStampNow + '<br/>';
    } else {
      ts = '';
    }
    var panelTxt = result.split("||");
    if(unsafeWindow.oTerm != null && panelTxt[1].length > 0){
      var pt = panelTxt[1].replace("> NullCommand<br />Bad Command NullCommand<br />", "");
      // ^^ NullCommand comes from DoHyperIdleChatCallBack, q.v.
      //GM_log("::"+pt+"::")
      if(unsafeWindow.separateLocalScanPanel){
        var pts = pt.split("----<br />") // [0] = not local scan  [1] = local scan
        if(pts.length > 1){
          var newPnode = document.createElement("p")
          newPnode.innerHTML = ts + pts[1]
          unsafeWindow.localScanPanel.appendChild(newPnode)
          pt = pts[0]
          if(!document.getElementById('dasTmP').checked){
            unsafeWindow.localScanPanel.scrollTop = unsafeWindow.localScanPanel.scrollHeight;
          }
        }
      }
      if(pt != ""){
        var newPnode = document.createElement("p");
        newPnode.innerHTML = ts + pt;
        unsafeWindow.oTerm.appendChild(newPnode);
        if(!document.getElementById('dasTmP').checked){
          unsafeWindow.oTerm.scrollTop = unsafeWindow.oTerm.scrollHeight;
        }
      }
      if(pt.match("> bas")){ // Extract bases for mapping
        // As of MW3TR 3.5.66 the Game-server no longer returns "No bases found"
        var basesT = document.getElementById('basesT');
        var baseMatches = panelTxt[1].match(/Planet ([a-z]) in system +(\d+) /g);
        //GM_log("baseMatches::"+baseMatches+"::");
        if(baseMatches == null){
          basesT.value = 'none';
        } else {
          basesT.value = '';
          var bStar = '';
          for(var bmx = 0 ; bmx < baseMatches.length ; bmx++){
            var bm = baseMatches[bmx].match(/Planet ([a-z]) in system +(\d+) /);
            // [1] = planet, [2] = star
            if(bStar == bm[2]){
              basesT.value += bm[1];
            } else {
              basesT.value += ' =' + bm[2] + bm[1];
              bStar = bm[2];
            }
          }
        }
      }
    }
    var inHyper = false; // used for timeout handling
    if(unsafeWindow.oScan != null && panelTxt[2].length > 0){
      unsafeWindow.oScan.innerHTML = panelTxt[2];
      unsafeWindow.oScan.scrollTop = 0;
      // Look for a nearby star, to map ship location:
      var sysNum = panelTxt[2].match(/>(\d+)</);
      if(sysNum){
        sysNum = sysNum[1];
        if(sysNum == '0'){ // hyper
          inHyper = true;
          var ls = panelTxt[2].match(/LoadSystem\('(\d+)/);
          if(ls == null) sysNum = '';
          else           sysNum = ls[1];
        }
        document.getElementById('shipT').value = sysNum;
        document.getElementById('plotShipT').click();
      }
    } else {
      unsafeWindow.needToConfirm = false; // expansion of function releaseDirtyFlag
    }
    if(unsafeWindow.oStat != null && panelTxt[3].length > 0){
      if(moveCombatButtons) removeOldTorpButtons();
      unsafeWindow.oStat.innerHTML =
        panelTxt[3].replace(/onclick/g,'style="width:0.8em" onclick');
      if(moveCombatButtons) moveTorpButtons();
      unsafeWindow.oStat.scrollTop = 0;
    }
    if( (unsafeWindow.oChat != null) && (panelTxt[4].length > 0) ){
      newPnode = document.createElement("p");
      newPnode.innerHTML = ts + panelTxt[4].replace(/^<br \/>/,'');
      unsafeWindow.oChat.appendChild(newPnode);
      if(!document.getElementById('dasCtP').checked){
        unsafeWindow.oChat.scrollTop = unsafeWindow.oChat.scrollHeight;
      }
    }
    if(unsafeWindow.oPlts != null && panelTxt[5].length > 0) {
      unsafeWindow.oPlts.innerHTML =
        panelTxt[5].replace(/onclick/g,'style="width:0.8em" onclick')
                   .replace(/DoCommand\([^)]*\)/g,"planetButtonClicked(this,event)");
      unsafeWindow.oPlts.scrollTop = 0;
    }
    if(panelTxt[6].length > 0) {
      if (panelTxt[6].search("ConfirmOFF") != -1) {
        unsafeWindow.needToConfirm = false; // expansion of function releaseDirtyFlag
      }
      if (panelTxt[6].search("ConfirmON") != -1) {
        unsafeWindow.needToConfirm = true; // expansion of function setDirtyFlag
      }
    }
    if(unsafeWindow.oShip != null && panelTxt[7].length > 0){
      // GM_log("panelTxt[7]:"+panelTxt[7])
      if(unsafeWindow.separateLocalScanPanel){ unsafeWindow.oShip.innerHTML = panelTxt[7].replace("800px","360px") }
      else                                   { unsafeWindow.oShip.innerHTML = panelTxt[7] }
      unsafeWindow.oShip.scrollTop = 0;
    }
    var oTargetBox = document.getElementById("m_oCurrentTarget");
    if (panelTxt[8].length > 0 && oTargetBox != null && oTargetBox.value.length > 0) {
      var shipheadings = panelTxt[8].split(",");
      var i = 0;
      for(i=0;i< shipheadings.length; i+=2) {
        if (shipheadings[i].length > 0 && shipheadings[i] == oTargetBox.value) {
          unsafeWindow.LoadTarget(shipheadings[i], shipheadings[i+1]);
        }
      }
    }
    if(!document.getElementById('noFG').checked){
      document.getElementById("TextBox2").focus(); // expansion of function DoFocusSet
    }
    if(document.getElementById('rcEnable').checked){
      serverMessageToXmit = timeStampNow + '||' + result;
      document.getElementById('rcX').click();
    }
  } else { // i.e. (result.length <= 0)
    unsafeWindow.needToConfirm = false; // expansion of function releaseDirtyFlag
    window.location = "../default.aspx";
    return;
  }
  unsafeWindow.bWaitForAjaxResponse = false;
  if(unsafeWindow.sCmdBuffer.length > 0){
    unsafeWindow.WebChatTimeoutID = window.setTimeout('UseCommandBuffer()', 10);
    return;
  }
  var timeoutCall = "DoChatCallBack()";
  if(inHyper) timeoutCall = "DoHyperIdleChatCallBack()";
  unsafeWindow.WebChatTimeoutID = window.setTimeout(timeoutCall, 2500);
} // end of function hackedCalledBack

DoChatCallBack = unsafeWindow.DoChatCallBack; // avoid a naming problem

function DoHyperIdleChatCallBack(){
  if(document.getElementById("autoSeaCheckBox").checked){
    unsafeWindow.DoCommand("Sea " + document.getElementById("autoSeaRange").value,
                           false,false,false,false);
  } else {
    unsafeWindow.DoCommand("NullCommand",
                           false,false,false,false);
    // TODO: Chop out the echo and error message for this from TermPanel before echoing
  }
}
unsafeWindow.DoHyperIdleChatCallBack = DoHyperIdleChatCallBack;

function planetButtonClicked(which,evt){
  if(evt.shiftKey){
    cmd = "Sur ";
  } else {
    cmd = "Nav ";
  }
  unsafeWindow.DoCommand(cmd+which.id.charAt(4),false,false,false,false)
}
unsafeWindow.planetButtonClicked = planetButtonClicked;

var hackedCalledBackString = hackedCalledBack.toString();
unsafeWindow.CalledBack = Function("result", "context",
  hackedCalledBackString.substr(hackedCalledBackString.indexOf('{')) );
  //                     |--drop the header, leaving only the body-|

// To Do:
// Allow tags after star number as well as before. (You can put tags before star numbers now.)
//   Examples: 123 plots as +123, a123 plots as a123, a123ab would plot as a123ab rather than as +123
// Let user position BeakerPanel (left or right) and combat buttons (left or right) independently of each other.

// To Maybe Do:
// pop-up Help? - Help page might be a Forum message? or be wired in?
// Better semi-automation for NAV-or-PRO-then-LIB?
// Separate P: box for Pro?
// capture BAS list? w/buttons for NAV/SUR/??
// %b => star if not same sys, planet if same sys?
// Ctrl-click on LIBdata in TermPanel => stash (sys.p,Hab,Met)
// Demultiplex radios?
// make Map show ship in all-stars (*-button) mode?

0 comments:

Post a Comment