|
Server : Apache/2.4.62 System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64 User : www ( 80) PHP Version : 8.3.8 Disable Function : NONE Directory : /domains/gwsolutions/rio/ |
Upload File : |
var base_path_wp = 'http://media.gwsolutions.com/wp-content/rio/{0}/';
var base_path_local = 'http://10.1.1.24:8080/{0}/';
var base_path_poly = base_path_wp;
var base_path_signal = base_path_wp;
var tile_folder = 'signalx';
var poly_folder = 'poly';
var clickedLat;
var clickedLon;
var lastTechSelected = '4G';
var showAllOperators = false;
var LAYER_COV = 1; // this needs to be 0 when we only have 1 layer
var LAYER_REG = 0; // this needs to be 0 when we have 2 layers
// and set COV to 1
var map;
var infowindow = "";
var mapCenter = new google.maps.LatLng(-22.972123, -43.295432);
var mobileCenter = new google.maps.LatLng(-22.934328, -43.202850);
var initialZoom = 12;
var mobileZoom = 12;
var MAX_ZOOM = 20;
var MIN_ZOOM = 1;
var markers = [];
var routexl = [{ "featureType": "administrative",
"elementType": "all",
"stylers": [{ "visibility": "on" }, { "saturation": -100 }, { "lightness": 20}]
},
{ "featureType": "road", "elementType": "all", "stylers": [{ "visibility": "on" },
{ "saturation": -100 }, { "lightness": 40}]
},
{ "featureType": "road",
"elementType": "labels.text.fill",
"stylers": [
{ "visibility": "on" },
{ "color": "#5a6969" },
{ "lightness": -78 }
]
},
{ "featureType": "water", "elementType": "all",
"stylers": [{ "visibility": "on" }, { "saturation": -70 }, { "lightness": 255 }, { "color": "#d3d4d4"}]
},
{ "featureType": "landscape.man_made", "elementType": "all",
"stylers": [{ "visibility": "simplified" }, { "saturation": -60 }
, { "lightness": 10}]
}, { "featureType": "landscape.natural", "elementType": "all",
"stylers": [{ "visibility": "simplified" }, { "saturation": -60 }, { "lightness": 60}]
},
{ "featureType": "poi", "elementType": "all", "stylers":
[{ "visibility": "on" }, { "saturation": -100 }, { "lightness": 60}]
},
/*{ "featureType": "poi",
"elementType": "labels.icon",
"stylers": [
{ "visibility": "off" },
]
},*/
{ "featureType": "poi",
"elementType": "labels.text.fill",
"stylers": [
{ "visibility": "on" },
{ "color": "#5a6969" },
{ "lightness": -78 }
]
},
{ "featureType": "transit", "elementType": "all",
"stylers": [{ "visibility": "off" }, { "saturation": -100 }, { "lightness": 60}]
}];
var myOptions = {
zoom: initialZoom,
center: mapCenter,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
panControl: false,
zoomControl: false,
scaleControl: false,
streetViewControl: false,
styles: routexl
}
var mobileOptions = {
zoom: mobileZoom,
center: mobileCenter,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
panControl: false,
zoomControl: false,
scaleControl: false,
streetViewControl: false,
styles: routexl
}
var pins = [{"Location":"Maracana Stadium","Latitude":-22.912287,"Longitude":-43.230242, "Color":"#00a84d", "BG":"#00a84d", "Pin":"pin-green.png"},
{"Location":"Christ the Redeemer (Statue)","Latitude":-22.951768,"Longitude":-43.211421, "Color":"#00a84d", "BG":"#00a84d", "Pin":"pin-green.png"},
{"Location":"Christ the Redeemer (Train)","Latitude":-22.945073,"Longitude":-43.205404, "Color":"#0096cf", "BG":"#0096cf", "Pin":"pin-blue.png"},
{"Location":"Lapa","Latitude":-22.914400,"Longitude":-43.182583, "Color":"#0096cf", "BG":"#0096cf", "Pin":"pin-blue.png"},
{"Location":"Copacabana Beach","Latitude":-22.971769,"Longitude":-43.183481, "Color":"#0096cf", "BG":"#0096cf", "Pin":"pin-blue.png"},
{"Location":"Barra Olympic Park","Latitude":-22.973777,"Longitude": -43.389279, "Color":"#57585a", "BG":"#57585a", "Pin":"pin-black.png"},
{"Location":"Botanical Gardens","Latitude":-22.967266,"Longitude":-43.223796, "Color":"#e5212e", "BG":"#e5212e", "Pin":"pin-red.png"},
{"Location":"Cinelandia","Latitude":-22.911292, "Longitude":-43.175599, "Color":"#e5212e", "BG":"#e5212e", "Pin":"pin-red.png"},
{"Location":"Flamengo Park","Latitude":-22.928614,"Longitude":-43.172138, "Color":"#f3c900", "BG":"#f3c900", "Pin":"pin-yellow.png"},
{"Location":"Lagoa de Freitas","Latitude":-22.973525,"Longitude":-43.210678, "Color":"#f3c900", "BG":"#f3c900", "Pin":"pin-yellow.png"},
{"Location":"Sambadrome","Latitude":-22.911097,"Longitude":-43.196796, "Color":"#57585a", "BG":"#57585a", "Pin":"pin-black.png"},
{"Location":"Sao Cristovao Fair","Latitude":-22.897632,"Longitude":-43.220495, "Color":"#f3c900", "BG":"#f3c900", "Pin":"pin-yellow.png"},
{"Location":"Urca","Latitude":-22.953344,"Longitude":-43.167282, "Color":"#57585a", "BG":"#57585a", "Pin":"pin-black.png"},
{"Location":"Sugarloaf Mountain Cable Car","Latitude":-22.950340,"Longitude":-43.161433, "Color":"#00a84d", "BG":"#00a84d", "Pin":"pin-green.png"}
];
var maptiler = new google.maps.ImageMapType({
getTileUrl: function (coord, zoom) {
// check coordinates, so we don't have tons of failed 404 hits
if ((haveZoomFor.indexOf(zoom) > -1) && (havePolyXFor.indexOf(coord.x) > -1) && (havePolyYFor.indexOf(coord.y) > -1)) {
var path = base_path_signal.replace('{0}', tile_folder) + zoom + "/" + coord.x + "/" + coord.y + "/";
path += getCarrier() + "_signal_4g.png";
//alert(path);
return path;
}
},
tileSize: new google.maps.Size(256, 256),
isPng: true
});
var regionLayer = new google.maps.ImageMapType({
getTileUrl: function (coord, zoom) {
//return zoom + "/" + coord.x + "/" + (Math.pow(2,zoom)-coord.y-1) + ".png";
// check coordinates, so we don't have tons of failed 404 hits
if ((haveZoomFor.indexOf(zoom) > -1) && (havePolyXFor.indexOf(coord.x) > -1) && (havePolyYFor.indexOf(coord.y) > -1)) {
var path = base_path_poly.replace('{0}', poly_folder) + zoom + "/" + coord.x + "/" + coord.y + "/geo.png";
//alert(path);
return path;
}
},
tileSize: new google.maps.Size(256, 256),
isPng: true
});
var debugLayer = new google.maps.ImageMapType({
getTileUrl: function (coord, zoom) {
//return zoom + "/" + coord.x + "/" + (Math.pow(2,zoom)-coord.y-1) + ".png";
var path = base_path.replace('{0}', 'debug') + zoom + "/" + coord.x + "/" + coord.y + "/debug.png";
return path;
},
tileSize: new google.maps.Size(256, 256),
isPng: true
});
function getCarrier() {
return $("#carrier").val() || document.getElementById('carrier').value;
}
function changeCarrier() {
if ($("#carrier").val() == 'wifi')
$("#tech").val('wifi');
else if ($("#tech").val() == 'wifi')
$("#tech").prop('selectedIndex', 0);
}
function changeTech() {
if ($("#tech").val() == 'wifi')
$("#carrier").val('wifi');
else if ($("#carrier").val() == 'wifi')
$("#carrier").prop('selectedIndex', 0);
}
function getMeasurement() {
var measurement = 'signal';
return measurement;
}
function setSize() {
var winH = $(window).height();
// firefox fix, wasn't getting window height
try {
if (!(window.mozInnerScreenX == null))
winH = window.innerHeight;
}
catch (ex) {
}
var winW = $(window).width();
//var headH = eval($(".masthead-container").css('height').replace('px', ''));
var headH = $(".masthead-container").outerHeight();
var mapH = winH - headH - 10;
$("#map_canvas").height(mapH);
$("#map_canvas").width(winW);
//$("#map_canvas").css('height', mapH + 'px !IMPORTANT');
// in some cases if we're changing the window size and have previously closed the menu via the legend button
// we could lose the legend entirely, so bring it back...
if (isMenuVisible() == false && $("#legend").is(":visible") == false) {
showHideLegend();
}
google.maps.event.trigger(map, "resize");
}
function isMenuVisible() {
return ($("#legendbutton").is(":visible"));
}
function isMobile() {
var check = false;
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true })(navigator.userAgent || navigator.vendor || window.opera);
return check;
}
function isMobileOrNarrow() {
var winW = $(window).width();
return isMobile() || (winW < 600);
}
function initialize() {
var useOption = myOptions;
if (isMobileOrNarrow() || getParameterByName("mobile") == "on") useOption = mobileOptions;
map = new google.maps.Map(document.getElementById("map_canvas"), useOption);
map.overlayMapTypes.insertAt(LAYER_REG, regionLayer);
map.overlayMapTypes.insertAt(LAYER_COV, maptiler);
if (getParameterByName("op") != '') {
$("#carrier").val(getParameterByName("op"));
}
if (getParameterByName("lands") == 'off') {
onOffLands();
}
setSize();
clearAndReload();
//initializeCarriers();
google.maps.event.addListener(map, 'click', function (e) {
hideOneScore();
closePopup();
});
google.maps.event.addListener(map, 'center_changed', function (e) {
hideOneScore();
});
google.maps.event.addListener(map, 'zoom_changed', function (e) {
hideOneScore();
});
loadPins();
google.maps.event.addListener(map, 'zoom_changed', function () {
if (map.getZoom() > MAX_ZOOM)
map.setZoom(MAX_ZOOM);
if (map.getZoom() < MIN_ZOOM)
map.setZoom(MIN_ZOOM);
});
$(window).on('resize', function () {
setSize();
});
}
function loadPins()
{
for (var i = 0; i < pins.length; i++)
{
var obj = pins[i];
addPin(obj);
}
}
function addPin(obj)
{
var title = obj.Location;
var myLatLng = {lat: obj.Latitude, lng: obj.Longitude};
var pinURL = obj.Pin;
//alert(pinURL);
var icon = { url: 'http://media.gwsolutions.com/wp-content/uploads/2016/07/' + obj.Pin,
size: new google.maps.Size(60,61),
origin: new google.maps.Point(0,0),
anchor: new google.maps.Point(32,30) };
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: title,
icon: icon
});
google.maps.event.addListener(marker,'click',function() {
hideLegend();
hideOneScore();
if (LastTitle != marker.title)
hookIt(map,marker,obj);
else {
closePopup();
LastTitle = '';
}
});
markers.push(marker);
return marker;
}
function closePopup()
{
if (infowindow != "")
infowindow.close();
}
var LastTitle = '';
function hookIt(map,marker,obj) {
var title = marker.title;
LastTitle = title;
//alert(land);
if (infowindow != "")
infowindow.close();
var borderColor = obj.BG;
var captionColor = "#ffffff";
var titleName = title;
var photo = '';
var disableAutoPan = false;
//alert(JSON.stringify(tweets));
var tweet = arrMatching(rankings,'Location',title,'Task','HTTP UL 0.1MB');
var selfie = arrMatching(rankings,'Location',title,'Task','HTTP UL 2MB');
// snapchat
var stream = arrMatching(rankings,'Location',title,'Task','HTTP UL 0.2MB');
var oneScore = arrMatching(speedScores,'Location',title);
//alert(JSON.stringify(stream));
var content = '<table class="pop-table">' +
'<tr><td colspan="5" class="pop-title" style="color:{bg}">{title}</td></tr>' +
'<tr><td colspan="5" class="pop-subtitle">Data Activities<br />Ranked by Speed</td></tr>' +
'<tr><td></td><td class="pop-head">Status Update</td><td class="pop-head">Post<br />Selfie</td><td class="pop-head">Snapchat</td><!--td class="pop-head">*OneScore<br />(Overall)</td--></tr>' +
'<tr><td class="pop-carrier">Claro</td><td class="pop-ranking">{a1}</td><td class="pop-ranking">{a2}</td><td class="pop-ranking">{a3}</td><!--td class="pop-ranking">{a4}</td--></tr>' +
'<tr><td class="pop-carrier">Oi</td><td class="pop-ranking">{s1}</td><td class="pop-ranking">{s2}</td><td class="pop-ranking">{s3}</td><!--td class="pop-ranking">{s4}</td--></tr>' +
'<tr><td class="pop-carrier">TIM</td><td class="pop-ranking">{t1}</td><td class="pop-ranking">{t2}</td><td class="pop-ranking">{t3}</td><!--td class="pop-ranking">{t4}</td--></tr>' +
'<tr><td class="pop-carrier">Vivo</td><td class="pop-ranking">{v1}</td><td class="pop-ranking">{v2}</td><td class="pop-ranking">{v3}</td><!--td class="pop-ranking">{v4}</td--></tr>' +
//'<tr><td colspan="6" class="pop-foot">*GWS rating for overall data capabilities. Top score is 100%</td></tr>' +
'<tr><td colspan="5" class="pop-pad"> </td></tr>' +
'</table>';
if (title == 'Sugarloaf Mountain Cable Car')
content = content.replace('{title}','<span class="pop-title-smaller">Sugarloaf Mtn Cable Car</span>');
else if (title.indexOf('Christ') > -1)
content = content.replace('{title}','<span class="pop-title-smaller">'+title+'</span>');
else
content = content.replace('{title}',title);
content = content.replace('{bg}',obj.BG);
content = content.replace('{a1}',toRanking(tweet['Claro']))
.replace('{a2}',toRanking(selfie['Claro']))
.replace('{a3}',toRanking(stream['Claro']))
.replace('{a4}',toPercent(oneScore['Claro']));
content = content.replace('{s1}',toRanking(tweet['Oi']))
.replace('{s2}',toRanking(selfie['Oi']))
.replace('{s3}',toRanking(stream['Oi']))
.replace('{s4}',toPercent(oneScore['Oi']));
content = content.replace('{v1}',toRanking(tweet['Vivo']))
.replace('{v2}',toRanking(selfie['Vivo']))
.replace('{v3}',toRanking(stream['Vivo']))
.replace('{v4}',toPercent(oneScore['Vivo']));
content = content.replace('{t1}',toRanking(tweet['TIM']))
.replace('{t2}',toRanking(selfie['TIM']))
.replace('{t3}',toRanking(stream['TIM']))
.replace('{t4}',toPercent(oneScore['TIM']));
infowindow = new InfoBubble({
map : map,
content : content,
shadowStyle : 0,
padding : 0,
backgroundColor : 'rgb(255,255,255)',
borderRadius : 0,
arrowSize : 10,
borderWidth : 0,
borderColor : borderColor,
disableAutoPan : disableAutoPan,
hideCloseButton : false,
arrowPosition : 50,
backgroundClassName : 'popbubble',
arrowStyle : 0,
});
//infowindow.setBubbleOffset(0,bubbleOffsetHeight);
infowindow.open(map, marker);
currentMarker = marker;
//currentData = jData;
}
function hideOneScore()
{
$("#onescore").hide();
}
function showOneScore()
{
closePopup();
$("#onescore").show();
}
function hideLegend(force)
{
if (isMobile() || force) {
$("#legend").hide();
$("#legendbutton").css('background-image', 'url(http://media.gwsolutions.com/wp-content/uploads/2016/06/legend-btn.png)');
}
}
function showHideLegend() {
if ($("#legend").is(":visible")) {
hideLegend(true);
}
else {
if (isMobileOrNarrow()) closePopup();
//var height = (showingLands ? legend_landon : legend_landoff) + legend_pad;
//$("#legend").css('height', height + 'px');
$("#legend").show();
$("#legendbutton").css('background-image', 'url(http://media.gwsolutions.com/wp-content/uploads/2016/06/legend-close-btn.png)');
}
}
var legend_landoff = 295;
var legend_landon = 295;
var legend_pad = 38;
var showingLands = true;
function onOffLands() {
if (showingLands) {
map.overlayMapTypes.setAt(0, null);
$(".legendsquarewrapper").hide();
var height = legend_landoff + (isMobileOrNarrow() || isMenuVisible() ? legend_pad : 0);
$("#legend").css('height', height + 'px');
$("#showHideLands").text('Show Lands');
}
else {
map.overlayMapTypes.setAt(0, regionLayer);
$(".legendsquarewrapper").show();
var height = legend_landon + (isMobileOrNarrow() || isMenuVisible() ? legend_pad : 0);
$("#legend").css('height', height + 'px');
$("#showHideLands").text('Hide Lands');
}
showingLands = !showingLands;
updateShortURL();
}
var shortURLs =
[
{ carrier: "oi", lands: false, url: "http://goo.gl/Q8qxfm" },
{ carrier: "vivo", lands: false, url: "http://goo.gl/Q8qxfm" },
{ carrier: "tim", lands: false, url: "http://goo.gl/Q8qxfm" },
{ carrier: "claro", lands: false, url: "http://goo.gl/Q8qxfm" },
{ carrier: "overall", lands: false, url: "http://goo.gl/Q8qxfm" },
];
function updateShortURL() {
var op = $("#carrier").val();
var shareURL = 'http://www.gwsolutions.com/rio/index.html?op=' + op;
var fbURL = shareURL;
for (var i = 0; i < shortURLs.length; i++) {
// alert(shortURLs[i].carrier + ' compare to ' + op);
if (op == shortURLs[i].carrier)
shareURL = shortURLs[i].url;
}
//copyToClipboard(shareURL);
$("#copyLink").text(shareURL);
$("#shareFB").attr('data-href', fbURL);
$("#shareTW").attr('data-url', shareURL);
try {
FB.XFBML.parse(); // need to refresh the FB share button
}
catch (ex) {
// do nothing - this is incase Facebook can't be loaded
}
$.getScript('http://platform.twitter.com/widgets.js');
}
function selectText(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
}
}
function copyToClipboard(text) {
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
var popupContainer = '<div class="point_details">{0}</div>';
var popupRow = '<div class="point_caption">{0}</div><div class="point_value">{1}</div>';
if (!String.prototype.format) {
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
function arrMatching(arr,field,match,field2,match2)
{
for(var i = 0; i < arr.length; i++)
{
if(arr[i][field] == match && (field2 == null || arr[i][field2] == match2))
{
return arr[i];
}
//else alert(arr[i][field] + " NE " + match);
}
for (var i = 0; i < arr.length; i++)
{
if (arr[i][field] == 'Default') return arr[i];
}
return null;
}
function colorTile(rgb) {
return '<div class=\"color_tile\" style=\"background-color: RGB(' + rgb + ')\"></div>';
}
function clearAndReload() {
map.overlayMapTypes.setAt(LAYER_COV, maptiler);
updateShortURL();
$("#carrier").blur();
//map.overlapMapTypes.setAt(LAYER_REG, regionLayer);
}
function resetMap() {
map.setCenter(mapCenter);
map.setZoom(initialZoom);
closePopup();
}
function changeArea() {
if ($("#area option:selected").val() == "0")
{
resetMap();
return;
}
var area = $("#area option:selected").text();
$.each(pins,function(i,obj) {
if (obj.Location == area) {
var myLatLng = {lat: obj.Latitude, lng: obj.Longitude};
map.setCenter(myLatLng);
map.setZoom(16);
}
});
$.each(markers,function(k,v) {
if (v.title == area) {
//alert('found ' + area);
hideOneScore();
closePopup();
google.maps.event.trigger(markers[k], 'click');
}
});
}
$(document).ready(function () {
initialize();
$("#showDebug").change(function () {
if ($("#showDebug").is(':checked')) {
map.overlayMapTypes.setAt(2, debugLayer);
}
else
map.overlayMapTypes.setAt(2, null);
});
});
/*
Math helper
*/
// Closure
(function () {
/**
* Decimal adjustment of a number.
*
* @param {String} type The type of adjustment.
* @param {Number} value The number.
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
* @returns {Number} The adjusted value.
*/
function decimalAdjust(type, value, exp) {
// If the exp is undefined or zero...
if (typeof exp === 'undefined' || +exp === 0) {
return Math[type](value);
}
value = +value;
exp = +exp;
// If the value is not a number or the exp is not an integer...
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
return NaN;
}
// Shift
value = value.toString().split('e');
value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
// Shift back
value = value.toString().split('e');
return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
}
// Decimal round
if (!Math.round10) {
Math.round10 = function (value, exp) {
return decimalAdjust('round', value, exp);
};
}
// Decimal floor
if (!Math.floor10) {
Math.floor10 = function (value, exp) {
return decimalAdjust('floor', value, exp);
};
}
// Decimal ceil
if (!Math.ceil10) {
Math.ceil10 = function (value, exp) {
return decimalAdjust('ceil', value, exp);
};
}
})();
String.prototype.replaceAll = function (find, replace) {
var str = this;
return str.replace(new RegExp(find, 'g'), replace);
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function pct(value) {
if (value == "1") return 100;
else return Math.round10(value*100,0);
}
function toPercent(value) {
if (value == "1") return "100%";
else return Math.round10(value*100,0) + "%";
}
function toRanking (value) {
var img = 'spacer.png';
switch (value.toString())
{
case '1': img = 'gold.png'; break;
case '2': img = 'silver.png'; break;
case '3': img = 'bronze.png'; break;
case '4': img = '4th.png'; break;
default: img = 'unknown.png';
}
return '<img src="http://media.gwsolutions.com/wp-content/uploads/2016/07/' + img + '" width="20" height="20" alt="' + toOrdinal(value) + '" />';
}
function toOrdinal (value) {
try {
if (value.toString().substr(0,1) == "*")
value = value.replace('*','<span class="asterisk">*</span>');
var s = String(value),
len = s.length,
end = s.substr(len - 1, 1),
teen = len > 1 && s.substr(len - 2, 1) === "1",
ord = "th";
if (end === "1" && !teen) {
ord = "st";
} else if (end === "2" && !teen) {
ord = "nd";
} else if (end === "3" && !teen) {
ord = "rd";
}
return value + '' + ord;
}
catch (ex)
{
return value;
}
}
String.prototype.replaceAll = function (find,replace) {
var str = this;
return str.replace(new RegExp(find,'g'), replace);
}