-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajaxVWSwx.js
1583 lines (1326 loc) · 59.4 KB
/
ajaxVWSwx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// <![CDATA[
// Special thanks to: Pinto http://www.joske-online.be/ and Tom http://www.carterlake.org/
// They pioneered the basic AJAX code using WD clientraw.txt which was
// cheerfully borrowed from Tom at CarterLake.org and adapted by
// Ken True - Saratoga-weather.org 21-May-2006
// --- added flash-green on data update functions - Ken True 24-Nov-2006
// --- Version 1.00 - 03-Dec-2006 -- Adapted for VWS data.csv usage - Ken True saratoga-weather.org
// --- Version 1.04 - 13-Dec-2006 -- Ken True -repackaged AJAX function,
// also included Mike Challis' counter script to display seconds since last update and error
// handling for the fetch to fix to fix random error: NS_ERROR_NOT_AVAILABLE
// Mike's site: http://www.carmosaic.com/weather/index.php
// Thanks to FourOhFour on wxforum.net ( http://skigod.us/ ) for replacing all the
// x.responseText.split(' ')[n] calls with a simple array lookup.. much better speed and
// for his streamlined version of getUVrange.
//
// --- Version 2.00 - 30-Mar-2007 -- adapted to read VWS WeatherFlash text files by Matt at weatherbus.com
// --- Version 2.01 - 20-Jul-2007 -- packaged and adapted code for more robust loader functions and unit
// conversions by Ken at saratoga-weather.org
// --- Version 2.02 - 23-Jul-2007 -- added checks on heatidx/windchill, added wind display features, new
// uom display logic.
// --- Version 2.03 - 21-Sep-2007 -- added support for dynamic thermometer.php display updates
// --- Version 2.04 - 30-Dec-2007 -- added maxupdates feature, language translation features and
// added optional Wind-Rose display
// --- Version 2.05 - 10-Mar-2008 -- changed toFixed to Math.round in conversions
// --- Version 2.06 - 13-Mar-2008 -- added ajaxfeelslike support
// --- Version 2.07 - 20-Mar-2009 -- added support for IE8 native mode
// --- Version 2.08 - 12-Jan-2011 -- addes support for new universal templates
// --- Version 2.09 - 28-Jan-2011 -- some code cleanup to reduce JavaScript messages
// --- Version 2.10 - 03-Feb-2011 -- fixed NaN issue with I=<ID>& uploads to wflash/wflash2.txt
// --- Version 2.11 - 17-Feb-2011 -- added decimal comma option for international display
//
// for updates to this script, see http://saratoga-weather.org/scripts-VWS-AJAX.php
// announcements of new versions will be on ambientwxsupport.com and wxforum.net
// -- begin settings --------------------------------------------------------------------------
var flashcolor = '#00CC00'; // color to flash for changed observations RGB
var flashtime = 2000; // miliseconds to keep flash color on (2000 = 2 seconds);
var reloadTime = 10000; // reload AJAX conditions every 10 seconds (= 10000 ms)
var maxupdates = 12; // Maxium Number of updates allowed (set to zero for unlimited)
// maxupdates * reloadTime / 1000 = number of seconds to update
var wflashDir = '/wflash/'; // URL for directory for WeatherFlash relative to this script with
// trailing '/'. In Root = '/', in /wflash = '/wflash/'
var imagedir = './ajax-images' // place for wind arrows, rising/falling arrows, etc.
var useunits = 'E'; // 'E'=USA(English) or 'M'=Metric
var decimalComma = false; // =false for '.' as decimal point, =true for ',' (comma) as decimal point
var useKnots = false; // set to true to use wind speed in Knots (otherwise
// wind in km/hr for Metric or mph for English will be used.
var useMPS = false; // set to true for meters/second for metric wind speeds, false= km/h
var useMPH = false; // set to true to force MPH for both English and Metric units
var useFeet = false; // set to true to force Feet for height in both English and Metric
var usehPa = false; // set to true to force hPa for baro in both English and Metric
var showUnits = true; // set to false if no units are to be displayed
var useAMPM = true; // set to false for 24hr time (only used for update time value)
var showNoWind = true; // true shows wind=0 as 'Calm' and gust=0 as 'No Wind'
// // flase shows wind=0 as '0' and gust=0 as '0'
var thermometer = './thermometer.php'; // script for dynamic thermometer PNG image (optional)
// optional settings for the Wind Rose graphic in ajaxwindiconwr as wrName + winddir + wrType
var wrName = 'wr-'; // first part of the graphic filename (followed by winddir to complete it)
var wrType = '.png'; // extension of the graphic filename
var wrHeight = '58'; // windrose graphic height=
var wrWidth = '58'; // windrose graphic width=
var wrCalm = 'wr-calm.png'; // set to full name of graphic for calm display ('wr-calm.gif')
// -- end of settings -------------------------------------------------------------------------
//
// -- language settings -- you don't need to customize this area if you are using English -----
var langPauseMsg = 'Updates paused - reload page to start'; // substitute this for ajaxindicator when
// maxupdates has been reached and updating paused.
var langMonths = new Array ( "January","February","March","April","May",
"June","July","August","September","October","November","December");
var langDays = new Array ( "Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun");
var langBaroTrend = new Array (
"Steady", "Rising Slowly", "Rising Rapidly", "Falling Slowly", "Falling Rapidly");
var langUVWords = new Array (
"None", "Low", "Medium", "High",
"Very High", /* be sure to include for space */
"Extreme" );
var langBeaufort = new Array ( /* Beaufort 0 to 12 in array */
"Calm", "Light air", "Light breeze", "Gentle breeze", "Moderate breeze", "Fresh breeze",
"Strong breeze", "Near gale", "Gale", "Strong gale", "Storm",
"Violent storm", "Hurricane"
);
var langWindDir = new Array( /* used for alt and title tags on wind dir arrow and wind direction display */
"N", "NNE", "NE", "ENE",
"E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW",
"W", "WNW", "NW", "NNW");
var langWindCalm = 'Calm';
var langGustNone = 'None';
var langWindFrom = 'Wind from '; /* used on alt/title tags on wind direction arrow*/
var langBaroRising = 'Rising %s '; /* used for trend arrow alt/title tags .. %s marks where value will be placed */
var langBaroFalling = 'Falling %s ';
var langBaroPerHour = '/hour.'; /* will be assembled as rising/falling + value + uom + perhour text */
var langThermoCurrently = 'Currently: '; /* used on alt/title tags for thermometer */
var langThermoMax = 'Max: ';
var langThermoMin = 'Min: ';
var langTempRising = 'Rising %s '; /* used for trend arrow alt/title tags .. %s marks where value will be placed */
var langTempFalling = 'Falling %s ';
var langTempPerHour = '/hour.';
var langHumRising = 'Rising %s '; /* used for trend arrow alt/title tags .. %s marks where value will be placed */
var langHumFalling = 'Falling %s ';
var langHumPerHour = '/hour.';
var langTransLookup = new Object; // storage area for key/value for current conditions translation
var langHeatWords = new Array (
'Unknown', 'Extreme Heat Danger', 'Heat Danger', 'Extreme Heat Caution', 'Extremely Hot', 'Uncomfortably Hot',
'Hot', 'Warm', 'Comfortable', 'Cool', 'Cold', 'Uncomfortably Cold', 'Very Cold', 'Extreme Cold' );
// -- end of language settings ----------------------------------------------------------
//
// You shouldn't have to change these settings for file locations, they are the defaults for
// WeatherFlash
var wflashFile = wflashDir+'Data/wflash.txt'; // location of wflash.txt relative to this page on website
var wflashFile2 = wflashDir+'Data/wflash2.txt'; // location of wflash2.txt relative to this page on website
var wflashUnitsFile = wflashDir+'Config/Units.txt'; // location of Config/Units.txt file for wflash
// --- you don't need to customize the stuff below, the actions are controlled by the
// settings above.
var ie4=document.all;
var browser = navigator.appName;
var ie8 = false;
if (ie4 && /MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
if (ieversion>=8) {
ie4=false;
ie8=true;
}
}
var counterSecs = 0; // for MCHALLIS counter script from weather-watch.com (adapted by K. True)
var updates = 0; // update counter for limit by maxupdates
var lastajaxtime = 'unknown'; //used to reset the counter when a real update is done
var doTooltip = 0; // set to 1 to have ajaxed variable names appear as tooltips (except for graphics)
// handle setup options for units-of-measure and whether to show them at all
// note.. units to use will be updated automatically from the Weather Flash Config/Units.txt file
// --------------- DON'T change thise defaults ---- they are the units used in wflash.txt, wflash2.txt
var uomTemp = '°F'; var uomTempCnvt = 0;
var uomWind = ' mph'; var uomWindCnvt = 0;
var uomBaro = ' inHg'; var uomBaroCnvt = 0;
var uomRain = ' in'; var uomRainCnvt = 0;
//var uomHumid= '%';
//var uomSolar= ' W/m<sup>2</sup>';
var uomHumid= '';
var uomSolar= '';
var uomHeight = ' ft'; var uomHeightCnvt = 0;
var uomDistance = ' miles'; var uomDistanceCnvt = 0;
var uomPerHr = '/hr';
var uomWindDir = '°';
var dpBaro = 2;
var dpRain = 2;
//----------------------------------------------------------------------------------------------------
function ajax_set_units( units ) {
// Establish overall units for script to use
// Default is English (like in wflash.txt/wflash2.txt
// ='M' chooses Metric C, km/h, hPa, mm, m, km (option for m/s for wind)
// ="W" forces pull of values from Config/Units.txt file (Weather Flash default settings file)
//
if (units == 'M') { // set to metric
uomTemp = '°C'; uomTempCnvt = 1;
uomWind = ' km/h'; uomWindCnvt = 1;
uomBaro = ' hPa'; uomBaroCnvt = 3;
uomRain = ' mm'; uomRainCnvt = 1;
uomHeight = ' m'; uomHeightCnvt = 1;
uomDistance = ' km'; uomDistanceCnvt = 1;
dpBaro = 1;
dpRain = 1;
}
if(useKnots) { uomWind = ' kts'; uomWindCnvt = 2;}
if(useMPS) { uomWind = ' m/s'; uomWindCnvt = 3;}
if(useMPH) { uomWind = ' mph'; uomWindCnvt = 0;}
if(useFeet) { uomHeight = ' ft'; uomHeightCnvt = 0;}
if(usehPa) { uomBaro = ' hPa'; uomBaroCnvt = 3;}
if(units == "W") { // get the units to use first (runs once)
ajaxGetUnits(wflashUnitsFile + '?' + new Date().getTime());
}
} // end ajax_set_units()
ajax_set_units(useunits); // set up the units to ues
// utility function to display UOM based on showUnits flag
function ajaxUOM ( uom ) {
if (showUnits) {
return( uom );
} else {
return( "" );
}
}
// utility function to display UOM based on showUnits flag
function nilWind ( v1, v2 ) {
if (showNoWind) {
return( v1 );
} else {
return( v2 );
}
}
// utility functions to handle conversions from clientraw data to desired units-of-measure
function convertTemp ( rawtemp ) {
var retval = 0;
if (uomTempCnvt == 0) { // leave in F
retval = rawtemp * 1.0 ;
} else { // convert to C
retval = (rawtemp - 32.0) * (100.0/(212.0-32.0));
}
return(Math.round(retval*10.0)/10);
}
function convertTempRate ( rawtemp ) {
var retval = 0;
if (uomTempCnvt == 0) { // leave in F rate
retval = rawtemp * 1.0 ;
} else { // convert to C rate
retval = rawtemp * 0.55555 ;
}
return(Math.round(retval*10.0)/10);
}
function convertWind ( rawwind ) {
var retval = 0;
switch (uomWindCnvt) { // convert from MPH to
case 0 : // MPH
retval = rawwind * 1.0;
break;
case 1: // KPH
retval = rawwind * 1.609344;
break;
case 2: // knots
retval = rawwind * 0.868976242;
break;
case 3: // meters per second
retval = rawwind * 0.44704;
break;
default:
retval = rawwind * 1.0;
}
return (Math.round(retval*10.0)/10);
}
function convertBaro ( rawbaro ) {
var retval = 0;
switch (uomBaroCnvt) { // convert from inHg to
case 0 : // inHg
retval = rawbaro * 1.0;
break;
case 1: // mmHg
retval = rawbaro * 25.4;
break;
case 2: // mb
retval = rawbaro * 33.86;
break;
case 3: // hPa
retval = rawbaro * 33.86;
break;
default:
retval = rawbaro * 1.0;
}
var fudgeIt = 10.0;
if (dpBaro == 2) {fudgeIt = 100.0;}
return (Math.round(retval*fudgeIt)/fudgeIt);
}
function convertRain ( rawrain ) { // convert from inches to
var retval = 0;
if (uomRainCnvt == 0) { // leave in in
retval = rawrain * 1.0 ;
} else { // convert to mm
retval = rawrain * 25.4;
}
var fudgeIt = 10.0;
if (dpRain == 2) {fudgeIt = 100.0;}
return (Math.round(retval*fudgeIt)/fudgeIt);
}
function convertHeight ( rawheight ) { // convert from feet to
var retval = 0;
if (uomHeightCnvt == 0) { // leave in feet
retval = rawrain * 1.0 ;
} else { // convert to meters
retval = rawrain * 0.3048;
}
return(Math.round(retval));
}
function convertDistance ( rawdist ) { // convert from miles to
var retval = 0;
if (uomDistanceCnvt == 0) { // leave in miles
retval = rawdist * 1.0 ;
} else { // convert to km
retval = rawdist * 1.609344;
}
return(Math.round(retval*10.0)/10);
}
// utility functions to navigate the HTML tags in the page
function get_ajax_tags ( ) {
// search all the span tags and return the list with class="ajax" in it
//
if (ie4 && browser != "Opera" && ! ie8) {
var elem = document.body.getElementsByTagName('span');
var lookfor = 'className';
} else {
var elem = document.getElementsByTagName('span');
var lookfor = 'class';
}
var arr = new Array();
var iarr = 0;
for(var i = 0; i < elem.length; i++) {
var att = elem[i].getAttribute(lookfor);
if(att == 'ajax') {
arr[iarr] = elem[i];
iarr++;
}
}
return arr;
}
function reset_ajax_color( usecolor ) {
// reset all the <span class="ajax"...> styles to have no color override
var elements = get_ajax_tags();
var numelements = elements.length;
for (var index=0;index!=numelements;index++) {
var element = elements[index];
element.style.color=usecolor;
}
}
function set_ajax_obs( name, inValue ) {
// store away the current value in both the doc and the span as lastobs="value"
// change color if value != lastobs
var value = inValue;
if(decimalComma) {
value = inValue.replace(/(\d)\.(\d)/,"$1,$2");
}
var element = document.getElementById(name);
if (! element ) { return; } // V1.04 -- don't set if missing the <span id=name> tag
var lastobs = element.getAttribute("lastobs");
element.setAttribute("lastobs",value);
if (value != unescape(lastobs)) {
element.style.color=flashcolor;
if ( doTooltip ) { element.setAttribute("title",'AJAX tag '+name); }
element.innerHTML = value; // moved to suppress excess 'flashing' .. J McMurry
}
}
function set_ajax_uom( name, onoroff ) {
// this function will set an ID= to visible or hidden by setting the style="display: "
// from 'inline' or 'none'
var element = document.getElementById(name);
if (! element ) { return; }
if (onoroff) {
element.style.display='inline';
} else {
element.style.display='none';
}
}
// --- end of flash-green functions
function windDir ($winddir)
// Take wind direction value, return the
// text label based upon 16 point compass -- function by beeker425
// see http://www.weather-watch.com/smf/index.php/topic,20097.0.html
{
var windlabel = new Array("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW");
return windlabel[Math.floor(((parseInt($winddir) + 11) / 22.5) % 16 )];
}
function windDirLang ($winddir)
// Take wind direction value, return the
// text label based upon 16 point compass -- function by beeker425
// see http://www.weather-watch.com/smf/index.php/topic,20097.0.html
{
return langWindDir[Math.floor(((parseInt($winddir) + 11) / 22.5) % 16 )];
}
function ajax_get_beaufort_number ( wind ) {
// return a number for the beaufort scale based on wind mph
if (wind < 1 ) {return("0"); }
if (wind < 4 ) {return("1"); }
if (wind < 8 ) {return("2"); }
if (wind < 13 ) {return("3"); }
if (wind < 19 ) {return("4"); }
if (wind < 25 ) {return("5"); }
if (wind < 32 ) {return("6"); }
if (wind < 39 ) {return("7"); }
if (wind < 47 ) {return("8"); }
if (wind < 55 ) {return("9"); }
if (wind < 64 ) {return("10"); }
if (wind < 73 ) {return("11"); }
if (wind >= 73 ) {return("12"); }
return("0");
}
function ajax_getUVrange ( uv ) { // code simplified by FourOhFour on wxforum.net
var uvword = "Unspec.";
if (uv <= 0) {
uvword = langUVWords[0];
} else if (uv < 3) {
uvword = "<span style=\"border: solid 1px; background-color: #A4CE6a;\"> "+langUVWords[1]+" </span>";
} else if (uv < 6) {
uvword = "<span style=\"border: solid 1px; background-color: #FBEE09;\"> "+langUVWords[2]+" </span>";
} else if (uv < 8) {
uvword = "<span style=\"border: solid 1px; background-color: #FD9125;\"> "+langUVWords[3]+" </span>";
} else if (uv < 11) {
uvword = "<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\"> "+langUVWords[4]+" </span>";
} else {
uvword = "<span style=\"border: solid 1px; color: #FFFF00; background-color: #807780;\"> "+langUVWords[5]+" </span>";
}
return uvword;
} // end ajax_getUVrange function
function ajax_get_barotrend(btrnd) {
// routine from Anole's wxsticker PHP (adapted to JS by Ken True)
// input: trend inHG
// Barometric Trend(3 hour)
// Change Rates
// Rapidly: =.06 inHg; 1.5 mm Hg; 2 hPa; 2 mb
// Slowly: =.02 inHg; 0.5 mm Hg; 0.7 hPa; 0.7 mb
// 5 conditions
// Rising Rapidly
// Rising Slowly
// Steady
// Falling Slowly
// Falling Rapidly
// Page 52 of the PDF Manual
// http://www.davisnet.com/product_documents/weather/manuals/07395.234-VP2_Manual.pdf
// figure out a text value for barometric pressure trend
if ((btrnd >= -0.02) && (btrnd <= 0.02)) { return(langBaroTrend[0]); }
if ((btrnd > 0.02) && (btrnd < 0.06)) { return(langBaroTrend[1]); }
if (btrnd >= 0.06) { return(langBaroTrend[2]); }
if ((btrnd < -0.02) && (btrnd > -0.06)) { return(langBaroTrend[3]); }
if (btrnd <= -0.06) { return(langBaroTrend[4]); }
return(btrnd);
}
function ajax_genarrow( nowTemp, yesterTemp, Legend, textUP, textDN, numDp) {
// generate an <img> tag with alt= and title= for rising/falling values
var diff = nowTemp.toFixed(3) - yesterTemp.toFixed(3);
var absDiff = Math.abs(diff);
var diffStr = '' + diff.toFixed(numDp); // sprintf("%01.0f",$diff);
var absDiffStr = '' + absDiff.toFixed(numDp); // sprintf("%01.0f",$absDiff);
var image = '';
var msg = '';
if (diff == 0) {
// no change
image = ' ';
} else if (diff > 0) {
// today is greater
// msg = textUP + " by " + diff.toFixed(1); // sprintf($textDN,$absDiff);
msg = textUP.replace(/\%s/,absDiffStr);
image = "<img src=\"" + imagedir + "/rising.gif\" alt=\"" + msg +
"\" title=\""+ msg +
"\" width=\"7\" height=\"8\" style=\"border: 0; margin: 1px 3px;\" />";
} else {
// today is lesser
msg = textDN.replace(/\%s/,absDiffStr); // sprintf($textDN,$absDiff);
// msg = textDN.replace(/\%s/,absDiffStr);
image = "<img src=\"" + imagedir + "/falling.gif\" alt=\"" + msg +
"\" title=\""+ msg +
"\" width=\"7\" height=\"8\" style=\"border: 0; margin: 1px 3px;\" />";
}
if (Legend) {
return (diff + Legend + image);
} else {
return image;
}
} // end genarrow function
function ajax_format_time(rawtime) {
// convert 24hr time to 12hr time (for updated time only)
if (! useAMPM ) {
return(rawtime); // keep it as 24hr time
}
var hms = rawtime.split(":");
var amOrPm = "am";
if (hms[0] > 11) {amOrPm = "pm";}
if (hms[0] > 12) {hms[0] = hms[0] - 12;}
if (hms[0] == 0) {hms[0] = 12;}
return(hms[0] + ":" + hms[1] + ":" + hms[2] + amOrPm);
}
// Mike Challis' counter function (adapted by Ken True)
//
function ajax_countup() {
var element = document.getElementById("ajaxcounter");
if (element) {
element.innerHTML = counterSecs;
counterSecs++;
}
}
function ajaxRequest () {
/* find the handler for AJAX based on availability of the request object */
try { var request = new XMLHttpRequest() /* non IE browser (or IE8 native) */ }
catch(e1) {
try { request = ActiveXObject("Msxml2.XMLHTTP") /* try IE6+ */ }
catch(e2) {
try { request = ActiveXObject("Microsoft.XMLHTTP") /* try IE5 */}
catch(e3) // no Ajax support
{ request = false; alert('Sorry.. AJAX updates are not available for your browser.') }
}
}
if (! request) { maxupdates = 1; }
return request;
}
// ------------------------------------------------------------------------------------------
// function.. read Units.txt and reset the uomVVVV and dpVVVV values as needed .. run once
// ------------------------------------------------------------------------------------------
function ajaxGetUnits(url) {
// read the Units.txt file and set our uomVVVV and dpVVVV values
// This routine is run once at startup (load of page)
if (document.getElementById) {
var x = new ajaxRequest();
}
if (x) { // got something back
x.onreadystatechange = function() {
try { if (x.readyState == 4 && x.status == 200) { // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE
var wunits = x.responseText.split('&');
var t = '';
var i = 0;
for (i=0;i<wunits.length;i++) {
var uparts = wunits[i].split('=');
t = t+"'"+uparts[0]+"' = '"+uparts[1]+"'\n";
switch (uparts[0]) { // handle the units values
case "Distance" :
if (uparts[1] == 'miles') { uomDistance = ' miles'; uomDistanceCnvt = 0; }
if (uparts[1] == 'km') { uomDistance = ' km'; uomDistanceCnvt = 1; }
t = t+"Set='"+uomDistance+"'\n";
break;
case "Altitude" :
if (uparts[1] == 'ft') { uomHeight = ' ft'; uomHeightCnvt = 0;}
if (uparts[1] == 'm') { uomHeight = ' m'; uomHeightCnvt = 1;}
t = t+"Set='"+uomHeight+"'\n";
break;
case "Rain" :
if (uparts[1] == 'in') { uomRain = ' in'; dpRain = 2; uomRainCnvt = 0;}
if (uparts[1] == 'mm') { uomRain = ' mm'; dpRain = 1; uomRainCnvt = 1;}
t = t+"Set='"+uomRain+"' dpRain='"+dpRain+"'\n";
break;
case "Wind" :
if (uparts[1] == 'mph') { uomWind = ' mph'; uomWindCnvt = 0;}
if (uparts[1] == 'kph') { uomWind = ' km/h'; uomWindCnvt = 1;}
if (uparts[1] == 'knots') { uomWind = ' kts'; uomWindCnvt = 2;}
if (uparts[1] == 'm/s') { uomWind = ' m/s'; uomWindCnvt = 3;}
t = t+"Set='"+uomWind+"'\n";
break;
case "Pressure" :
if (uparts[1] == 'inHg') { uomBaro = ' inHg'; dpBaro = 2; uomBaroCnvt = 0;}
if (uparts[1] == 'mmHg') { uomBaro = ' mmHg'; dpBaro = 1; uomBaroCnvt = 1;}
if (uparts[1] == 'mb') { uomBaro = ' mb'; dpBaro = 1; uomBaroCnvt = 2;}
if (uparts[1] == 'hPa') { uomBaro = ' hPa'; dpBaro = 1; uomBaroCnvt = 3;}
t = t+"Set='"+uomBaro+"' dpBaro='"+dpBaro+"'\n";
break;
case "Temperature" :
var tmp = uparts[1];
if (tmp.match(/F$/i) ) { uomTemp = '°F'; uomTempCnvt = 0;}
if (tmp.match(/C$/i) ) { uomTemp = '°C'; uomTempCnvt = 1;}
t = t+"Set='"+uomTemp+"'\n";
break;
default :
// no 'default'
} // end switch (uparts[0])
} // end for
// alert(t);
x.abort();
// } // END if(wunits[0]
} // END if (x.readyState == 4 && x.status == 200)
} // END try
catch(e){ } // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE
} // END x.onreadystatechange = function() {
x.open("GET", url, true);
x.send(null);
// alert("did Open and send of null");
}
} // end ajaxGetUnits function
// ------------------------------------------------------------------------------------------
// main function.. read wflash.txt and format <span class="ajax" id="ajax..."></span> areas
// ------------------------------------------------------------------------------------------
function ajaxLoaderVWSf(url) {
var x = new ajaxRequest();
if (x) { // got something back
x.onreadystatechange = function() {
try { if (x.readyState == 4 && x.status == 200) { // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE
var wflash = x.responseText.split(',');
// now make sure we got the entire wflash.txt -- thanks to Johnnywx
// valid wflash.txt has 'F=nnnnnnnnnn'
var wdpattern=/F\=(\d+)/;
if( wdpattern.test(wflash[0]) &&
( updates <= maxupdates || maxupdates > 0 )) { // got it.. process wflash.txt
if (maxupdates > 0 ) {updates++; } // increment counter if needed
// main routine ---
var datestamp = wflash[0]; // extracted from the F=() in the first string
// Note: F=nnnnn: the value is number of seconds since Jan 01, 1900 00:00:00 UTC
datestamp = datestamp.replace(/^I=\S+\&/i,""); // remove I= field if present
datestamp = datestamp.replace(wdpattern,"$1"); // extract timestamp from F=nnnnnnnn field
var datezero = new Date('Jan 01, 1900 00:00:00 UTC');
var datetime = new Date();
datetime.setTime(datestamp*1000 + datezero.getTime()); // adjust date to offset from zero time
set_ajax_obs("ajaxdatetime",datetime);
set_ajax_obs("ajaxdatetimelocale",datetime.toLocaleString());
set_ajax_obs("ajaxdate",datetime.toLocaleDateString());
set_ajax_obs("ajaxtime",datetime.toLocaleTimeString());
set_ajax_obs("gizmodate",datetime.toLocaleDateString());
set_ajax_obs("gizmotime",datetime.toLocaleTimeString());
//BEGIN TEMPERATURE DATA
//CURRENT TEMPERATURE
var temperature = convertTemp(wflash[9]);
set_ajax_obs("ajaxtemp",temperature.toFixed(1)+ajaxUOM(uomTemp));
set_ajax_obs("gizmotemp",temperature.toFixed(1)+ajaxUOM(uomTemp));
set_ajax_obs("ajaxtempNoU",temperature.toFixed(1));
set_ajax_obs("ajaxbigtemp",temperature.toFixed(0) + uomTemp);
set_ajax_obs("ajaxthermometer",
"<img src=\"" + thermometer + "?t=" + temperature + "\" " +
"width=\"54\" height=\"170\" alt=\"Current Temp is " + temperature.toFixed(1)+ajaxUOM(uomTemp) + "\" />" );
//CURRENT TEMPERATURE RATE
var temprate = convertTempRate(wflash[37]);
set_ajax_obs("ajaxtemprate",temprate.toFixed(1)+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
set_ajax_obs("gizmotemprate",temprate.toFixed(1)+ajaxUOM(uomTemp));
var temparrow = ajax_genarrow(temperature*1.0, temperature-temprate*1.0, '',
langTempRising+uomTemp+langTempPerHour,
langTempFalling+uomTemp+langTempPerHour,1);
set_ajax_obs("ajaxtemparrow",temparrow);
set_ajax_obs("gizmotemparrow",temparrow);
//END TEMPERATURE DATA
//BEGIN HEAT INDEX DATA
//CURRENT HEAT INDEX
if (wflash[9] >= 80) { // NOAA sez need 80F+ for Heat Index
var heatindex = convertTemp(wflash[23]);
set_ajax_obs("ajaxheatidx",heatindex.toFixed(1)+ajaxUOM(uomTemp));
//CURRENT HEAT INDEX RATE
var heatindexrate = convertTempRate(wflash[51]);
set_ajax_obs("ajaxheatidxrate",heatindexrate.toFixed(1)+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
set_ajax_obs("ajaxheatidxarrow",
ajax_genarrow(heatindex*1.0, heatindex-heatindexrate*1.0, '',
langTempRising+uomTemp+langTempPerHour,
langTempFalling+uomTemp+langTempPerHour,1)
);
} else {
set_ajax_obs("ajaxheatidx",'---');
set_ajax_obs("ajaxheatidxrate",'---');
set_ajax_obs("ajaxheatidxarrow",'');
}
//END HEAT INDEX DATA
//BEGIN WIND CHILL DATA
//CURRENT WIND CHILL
if (wflash[9] <= 40) { // NOAA sez Wind Chill starts at 40F
var windchill = convertTemp(wflash[21]);
set_ajax_obs("ajaxwindchill",windchill.toFixed(1)+ajaxUOM(uomTemp));
//CURRENT WIND CHILL RATE
var windchillrate = convertTempRate(wflash[49]);
set_ajax_obs("ajaxwindchillrate",windchillrate.toFixed(1)+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
set_ajax_obs("ajaxwindchillarrow",
ajax_genarrow(windchill*1.0, windchill-windchillrate*1.0, '',
langTempRising+uomTemp+langTempPerHour,
langTempFalling+uomTemp+langTempPerHour,1)
);
} else {
set_ajax_obs("ajaxwindchill",'---');
set_ajax_obs("ajaxwindchillrate",'---');
set_ajax_obs("ajaxwindchillarrow",'');
}
//END WIND CHILL DATA
//BEGIN FEELS-LIKE
if (wflash[9] <= 40) { // NOAA sez Wind Chill starts at 40F
set_ajax_obs("ajaxfeelslike",windchill.toFixed(1)+ajaxUOM(uomTemp));
}
if (wflash[9] >= 80) { // NOAA sez need 80F+ for Heat Index
set_ajax_obs("ajaxfeelslike",heatindex.toFixed(1)+ajaxUOM(uomTemp));
}
if (wflash[9] > 40 && wflash[9] < 80) {
set_ajax_obs("ajaxfeelslike",temperature.toFixed(1)+ajaxUOM(uomTemp));
}
//END FEELS-LIKE
//BEGIN PRESSURE DATA
//CURRENT PRESSURE (Sea Level)
var pressure = convertBaro(wflash[25]);
set_ajax_obs("ajaxbaro",pressure.toFixed(dpBaro)+ajaxUOM(uomBaro));
set_ajax_obs("gizmobaro",pressure.toFixed(dpBaro)+ajaxUOM(uomBaro));
//CURRENT PRESSURE RATE (Sea Level)
var barometerrate = convertBaro(wflash[53]);
set_ajax_obs("ajaxbarorate",barometerrate.toFixed(dpBaro)+ajaxUOM(uomBaro)+ajaxUOM(uomPerHr));
set_ajax_obs("gizmobarorate",barometerrate.toFixed(dpBaro)+ajaxUOM(uomBaro)+ajaxUOM(uomPerHr));
var baroarrow = ajax_genarrow(pressure*1.0, pressure-barometerrate*1.0, '',
langBaroRising+uomBaro+langBaroPerHour,
langBaroFalling+uomBaro+langBaroPerHour,1);
set_ajax_obs("ajaxbaroarrow",baroarrow);
set_ajax_obs("gizmobaroarrow",baroarrow);
var barotrendtext = ajax_get_barotrend(wflash[53]*1.0);
set_ajax_obs("ajaxbarotrend",barotrendtext );
set_ajax_obs("gizmobarotrend",barotrendtext );
set_ajax_obs("ajaxbarotrendtext",barotrendtext);
set_ajax_obs("gizmobarotrendtext",barotrendtext);
//END PRESSURE DATA
//BEGIN RAW BAROMETER DATA
//CURRENT RAW BAROMETER
var rawbaro = convertBaro(wflash[10]);
set_ajax_obs("ajaxrawbaro",rawbaro.toFixed(dpBaro)+ajaxUOM(uomBaro));
//CURRENT RAW BAROMETER RATE
var rawbarorate = convertBaro(wflash[38]);
set_ajax_obs("ajaxrawbarorate",rawbarorate.toFixed(dpBaro)+ajaxUOM(uomBaro)+ajaxUOM(uomPerHr));
set_ajax_obs("ajaxrawbaroarrow",
ajax_genarrow(rawbaro*1.0, rawbaro-rawbarorate*1.0, '',
langBaroRising+uomBaro+langBaroPerHour,
langBaroFalling+uomBaro+langBaroPerHour,1)
);
set_ajax_obs("ajaxrawbarotrend",ajax_get_barotrend(wflash[38]*1.0) );
//END RAW BAROMETER DATA
//BEGIN WIND DATA
//CURRENT WIND GUST RATE
var gustrate = convertWind(wflash[33]);
set_ajax_obs("ajaxgustrate",gustrate+ajaxUOM(uomWind)+ajaxUOM(uomPerHr));
//CURRENT WIND RATE
var windrate = convertWind(wflash[32]);
set_ajax_obs("ajaxwindrate",windrate+ajaxUOM(uomWind)+ajaxUOM(uomPerHr));
//WIND DIRECTION DATA
var winddir2 = wflash[3];
winddir2 = winddir2 * 1.0;
set_ajax_obs("ajaxwinddir2",winddir2.toFixed(0)+ajaxUOM(uomWindDir));
//CURRENT WIND GUST
var gust = convertWind(wflash[5]);
//CURRENT WIND SPEED
var wind = convertWind(wflash[4]);
set_ajax_obs("ajaxwinduom",uomWind);
set_ajax_obs("ajaxgustuom",uomWind);
var windcardinal = windDir(wflash[3]);
var windcardinalLang = windDirLang(wflash[3]); // for language translation
if (wind >= 0.1) {
set_ajax_obs("ajaxwind",wind.toFixed(1)+uomWind);
set_ajax_obs("gizmowind",wind.toFixed(1)+uomWind);
set_ajax_uom("ajaxwinduom",true);
} else {
set_ajax_obs("ajaxwind",nilWind(langWindCalm,'0'));
set_ajax_obs("gizmowind",nilWind(langWindCalm,'0'));
set_ajax_uom("ajaxwinduom",false);
}
if (gust > 0.0) {
set_ajax_obs("ajaxgust",gust.toFixed(1)+uomWind);
set_ajax_obs("gizmogust",gust.toFixed(1)+uomWind);
set_ajax_uom("ajaxgustuom",true);
} else {
set_ajax_obs("ajaxgust",nilWind(langGustNone,'0'));
set_ajax_obs("gizmogust",nilWind(langGustNone,'0'));
set_ajax_uom("ajaxgustuom",false);
}
if (gust > 0.0 || wind > 0.0) {
var windicon = "<img src=\""+imagedir+"/"+windcardinal + ".gif\" width=\"12\" height=\"12\" alt=\"" +
langWindFrom + windcardinalLang + "\" title=\"" +
langWindFrom + windcardinalLang + "\" /> ";
set_ajax_obs("ajaxwindicon",windicon);
set_ajax_obs("gizmowindicon",windicon);
set_ajax_obs("ajaxwindiconwr",
"<img src=\"" + imagedir + "/" +wrName + windcardinal + wrType + "\" width=\""+
wrWidth+"\" height=\""+wrHeight+"\" alt=\"" +
langWindFrom + windcardinalLang + "\" title=\"" +
langWindFrom + windcardinalLang + "\" /> ");
set_ajax_obs("ajaxwinddir",windcardinalLang);
set_ajax_obs("gizmowinddir",windcardinalLang);
} else {
var nilwindicon = nilWind(" ",
"<img src=\""+imagedir+"/"+windcardinal + ".gif\" width=\"12\" height=\"12\" alt=\"" +
langWindFrom + windcardinalLang + "\" title=\"" +
langWindFrom + windcardinalLang + "\" /> ");
set_ajax_obs("ajaxwindicon",nilwindicon);
set_ajax_obs("ajaxwinddir",nilWind('',windcardinalLang));
set_ajax_obs("gizmowinddir",nilWind('',windcardinalLang));
if (wrCalm != '') {
set_ajax_obs("ajaxwindiconwr",
"<img src=\"" + imagedir + "/" + wrCalm + "\" width=\""+
wrWidth+"\" height=\""+wrHeight+"\" alt=\"" +
langBeaufort[0] + "\" title=\"" +langBeaufort[0] + "\" /> ");
}
}
var beaufortnum = ajax_get_beaufort_number(wflash[4]); // calculate beaufort from wind speed
set_ajax_obs("ajaxbeaufortnum",beaufortnum);
set_ajax_obs("ajaxbeaufort",langBeaufort[beaufortnum]); // so we can translate if necess.
//CURRENT WIND RATE
var winddirrate = convertWind(wflash[31]);
set_ajax_obs("ajaxwinddirrate",winddirrate+ajaxUOM(uomWindDir)+ajaxUOM(uomPerHr));
//END WIND DATA
//BEGIN RAIN DATA
//YEARLY RAIN
var rainyr = convertRain(wflash[11]);
rainyr = rainyr * 1.0;
set_ajax_obs("ajaxrainyr",rainyr.toFixed(dpRain)+ajaxUOM(uomRain));
//END RAIN DATA
//NOTE THAT OTHER RAIN DATA IS IN THE WFLASH2.TXT FILE SO IT IS IN THE SCRIPT BELOW THIS ONE
//BEGIN HUMIDITY DATA
//CURRENT HUMIDITY
var humidity = wflash[7];
humidity = humidity * 1.0;
set_ajax_obs("ajaxhumidity",humidity.toFixed(0)+ajaxUOM(uomHumid));
set_ajax_obs("gizmohumidity",humidity.toFixed(0)+ajaxUOM(uomHumid));
//CURRENT HUMIDITY RATE
var humidityrate = wflash[35];
humidityrate = humidityrate * 1.0;
set_ajax_obs("ajaxhumidityrate",humidityrate.toFixed(1)+ajaxUOM(uomHumid)+ajaxUOM(uomPerHr));
set_ajax_obs("ajaxhumidityarrow",
ajax_genarrow(humidity*1.0, humidity-humidityrate*1.0, '',
langHumRising+'%'+langHumPerHour,
langHumFalling+'%'+langHumPerHour,1)
);
//END HUMIDITY DATA
//BEGIN DEW POINT DATA
//CURRENT DEW POINT
var dew = convertTemp(wflash[24]);
set_ajax_obs("ajaxdew",dew.toFixed(1)+ajaxUOM(uomTemp));
set_ajax_obs("gizmodew",dew.toFixed(1)+ajaxUOM(uomTemp));
//CURRENT DEW POINT RATE
var dewrate = convertTempRate(wflash[52]);
set_ajax_obs("ajaxdewrate",dewrate.toFixed(1)+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
set_ajax_obs("ajaxdewarrow",
ajax_genarrow(dew*1.0, dew-dewrate*1.0, '',
langTempRising+uomTemp+langTempPerHour,
langTempFalling+uomTemp+langTempPerHour,1)
);
//END DEW POINT DATA
//Current UV Index
var uv = wflash[19];
uv = uv * 1.0;
set_ajax_obs("ajaxuv",uv.toFixed(1));
var uvrate = wflash[47];
uvrate = uvrate * 1.0;
set_ajax_obs("ajaxuvrate",uvrate.toFixed(1)+ajaxUOM(uomPerHr));
set_ajax_obs("gizmouvrate",uvrate.toFixed(1)+ajaxUOM(uomPerHr));
var uvword = ajax_getUVrange(uv);
set_ajax_obs("ajaxuvword",uvword);
set_ajax_obs("gizmouvword",uvword);
//Current Solar Radiation
var solar = wflash[20];
solar = solar * 1.0;
set_ajax_obs("ajaxsolar",solar.toFixed(0)+ajaxUOM(uomSolar));
var solarrate = wflash[48];
solarrate = solarrate * 1.0;
set_ajax_obs("ajaxsolarrate",solarrate.toFixed(0)+ajaxUOM(uomSolar)+ajaxUOM(uomPerHr));
//Current Evaportranspiration
var et = convertRain(wflash[18]);
set_ajax_obs("ajaxet",et+ajaxUOM(uomRain));
var etrate = convertRain(wflash[46]);
etrate = etrate * 1.0;
set_ajax_obs("ajaxetrate",etrate.toFixed(dpRain+1)+ajaxUOM(uomRain)+ajaxUOM(uomPerHr));
//UPDATED TIME AND DATE
// note: date will be from wflash2[275]
var ajaxtime = wflash[1];
ajaxtime = ajaxtime.replace( "+" , "0");
ajaxtime = ajax_format_time(ajaxtime);
set_ajax_obs("ajaxtime",ajaxtime);
if (lastajaxtime != ajaxtime) {
counterSecs = 0; // reset timer
lastajaxtime = ajaxtime; // remember this time
}
// now ensure that the indicator flashes on every AJAX fetch
var element = document.getElementById("ajaxindicator");
if (element) {
element.style.color = flashcolor;
}
element = document.getElementById("gizmoindicator");
if (element) {
element.style.color = flashcolor;
}
if (maxupdates > 0 && updates > maxupdates-1) { /* chg indicator to pause message */
set_ajax_obs("ajaxindicator",langPauseMsg);
set_ajax_obs("gizmoindicator",langPauseMsg);
}
set_ajax_obs('ajaxupdatecount',updates); /* for test pages */
set_ajax_obs('ajaxmaxupdatecount',maxupdates); /* for test pages */
} // END if(wflash[0]
} // END if (x.readyState == 4 && x.status == 200)
} // END try
catch(e){} // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE
} // END x.onreadystatechange = function() {
x.open("GET", url, true);
x.send(null);
setTimeout("reset_ajax_color('')",flashtime); // change text back to default color
if ( (maxupdates == 0) || (updates < maxupdates-1)) {
setTimeout("ajaxLoaderVWSf(wflashFile + '?' + new Date().getTime())", reloadTime); // get new data after 5 secs
}
}
} // end ajaxLoaderVWSf function
// ------------------------------------------------------------------------------------------
// main function.. read wflash2.txt and format <span class="ajax" id="ajax..."></span> areas
// ------------------------------------------------------------------------------------------
function ajaxLoaderVWSf2(url) {
var x = new ajaxRequest();
if (x) { // got something back
x.onreadystatechange = function() {
try { if (x.readyState == 4 && x.status == 200) { // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE
var wflash2 = x.responseText.split(',');
// now make sure we got the entire wflash.txt -- thanks to Johnnywx
// valid wflash2.txt has 'S=HH:MM:SS'