User:KingKiwiX/global.js

//////////////////////////////////////////////////////////////////////////////// // FUNCTIONS ////////////////////////////////////////////////////////////////////////////////

function alertLink(message)         { alert("This link will need to be implemented later." + (message ? " [" + message + "]" : "")); return false; } function handleSubmit             { return true; } function request(name, defaultValue) { var map = getRequestMap; return (map[name] ? map[name] : defaultValue); }

////////////////////////////////////////////////////////////////////////////////

function getRequestMap { var map   = { }; var query = window.location.search.substring(1); var pairs = query.split("&"); //alert("pairs = " + pairs); for (var i = 0; i < pairs.length; i++) {   var pos = pairs[i].indexOf('='); if (pos != -1) {     var name  = pairs[i].substring(0, pos);   // If not found, skip var value = pairs[i].substring(pos + 1); // Extract the name map[name] = unescape(value);             // Extract the value } }  return map; }

//////////////////////////////////////////////////////////////////////////////// // STRING ////////////////////////////////////////////////////////////////////////////////

function trim(string)               {return string.replace(/^\s*/,"").replace(/\s*$/,""); } function int(value)                 {var intValue   = parseInt(stripCommasFromValue(value));   return (isNaN(intValue)   ? 0 : intValue); } function float(value, numPlaces)    {var floatValue = parseFloat(stripCommasFromValue(value)); return (isNaN(floatValue) ? 0 : (numPlaces ? floatValue.toFixed(numPlaces) : floatValue)); } function stripCommasFromValue(value) {return (typeof value == "undefined" ? "" : value.toString.replace(/,/g, "")); } function unescapeValue(value)       {return value.replace(/&gt;/ig,">").replace(/&lt;/ig,"<").replace(/&#039;/g,"'").replace(/&quot;/ig,'"').replace(/&amp;/ig,'&'); } function urlencode(value)            {return encodeURIComponent(value).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+'); }

//////////////////////////////////////////////////////////////////////////////// // DOM ////////////////////////////////////////////////////////////////////////////////

function getElementWithID(elementID, isStrict) { isStrict    = (isStrict === null ? true : isStrict); var element = document.getElementById(elementID); if (isStrict && !element) {   alert("Could not find element with ID '" + elementID + "'"); } return element; }

//////////////////////////////////////////////////////////////////////////////// // CSS ////////////////////////////////////////////////////////////////////////////////

function isHiddenElement(element)                                         { return (element.style.display == "none" || (element.className &&  element.className.indexOf("hidden") >= 0)); } function isVisibleElement(element)                                        { return (element && !isHiddenElement(element)); } function hideElement(element, isStrict)                                   { return reclassElementFromValueToValue(element, "visible", "hidden", isStrict); } function showElement(element, isStrict)                                   { return reclassElementFromValueToValue(element, "hidden", "visible", isStrict); } function toggleElement(element, isStrict)                                 { return (isHiddenElement(element) ? showElement(element, isStrict) : hideElement(element, isStrict)); }

function isHiddenElementID(elementID, isStrict)                           { return isHiddenElement(getElementWithID(elementID, isStrict)); } function isVisibleElementID(elementID, isStrict)                          { return isVisibleElement(getElementWithID(elementID, isStrict)); } function hideElementID(elementID, isStrict)                               { return hideElement(  getElementWithID(elementID, isStrict), isStrict); } function showElementID(elementID, isStrict)                               { return showElement(  getElementWithID(elementID, isStrict), isStrict); } function toggleElementID(elementID, isStrict)                             { return toggleElement(getElementWithID(elementID, isStrict), isStrict); }

function reclassBodyFromValueToValue(oldValue, newValue)                  { return reclassElementFromValuesToValues(document.body, [oldValue], [newValue]); } function reclassBodyFromValuesToValue(oldValues, newValue)                { return reclassElementFromValuesToValues(document.body, oldValues,  [newValue]); } function reclassBodyFromValuesToValues(oldValues, newValues)              { return reclassElementFromValuesToValues(document.body, oldValues,   newValues); } function reclassElementFromValueToValue(element, oldValue, newValue)      { return reclassElementFromValuesToValues(element,       [oldValue], [newValue]); } function reclassElementFromValuesToValue(element, oldValues, newValue)    { return reclassElementFromValuesToValues(element,       oldValues,  [newValue]); } function reclassElementIDFromValueToValue(elementID, oldValue, newValue)  { return reclassElementFromValuesToValues(getElementWithID(elementID), [oldValue], [newValue]); } function reclassElementIDFromValuesToValue(elementID, oldValues, newValue) { return reclassElementFromValuesToValues(getElementWithID(elementID), oldValues, [newValue]); }

////////////////////////////////////////////////////////////////////////////////

function reclassElementFromValuesToValues(element, oldValues, newValues, isStrict) { if (!element && isStrict) {   alert("reclassElementFromValuesToValues(null, '" + oldValues + "', '" + newValues + "') called"); } var tempClass = " " + element.className + " "; for (var i in oldValues) {   tempClass = tempClass.replace(" " + oldValues[i] + " ", " "); } for (var i in newValues) {   tempClass = tempClass.replace(" " + newValues[i] + " ", " "); } for (var i in newValues) {   tempClass = tempClass + newValues[i] + " "; } element.className = trim(tempClass); }

//////////////////////////////////////////////////////////////////////////////// // FORM ////////////////////////////////////////////////////////////////////////////////

function isEdited                          { return document._isEdited; } function setEdited                         { document._isEdited = true;  return true; } function setNotEdited                      { document._isEdited = false; return true;}

function getForm                           { return document.forms[0]; } function getInputWithName(name)              { return (getForm ? eval("document.forms[0]." + name) : null); } function getValueOfInput(element)            { return (element ? element.value : ""); } function getValueOfSelect(element)           { return (element.selectedIndex >= 0 ? element.options[element.selectedIndex].value : ""); } function getLabelOfSelect(element)           { return (element.selectedIndex >= 0 ? element.options[element.selectedIndex].text  : ""); } function getValueOfInputName(name)           { return getValueOfInput(getInputWithName(name)); } function getValueOfSelectName(name)          { return getValueOfSelect(getInputWithName(name)); } function getLabelOfSelectName(name)          { return getLabelOfSelect(getInputWithName(name)); } function getValueOfCheckboxName(name)        { return (getInputWithName(name).checked ? getValueOfInputName(name) : ""); } function checkCheckboxName(name)             { getInputWithName(name).checked = true; } function uncheckCheckboxName(name)           { getInputWithName(name).checked = false; } function getIntOfInputName(name)             { var value = getValueOfInputName(name); return (value ? int(value)   : 0); } function getFloatOfInputName(name)           { var value = getValueOfInputName(name); return (value ? float(value) : 0); } function submitForm                        { setNotEdited; getForm.submit; } function submitFormWithButtonName(name)      { setNotEdited; getInputWithName(name).click; } function appendToInputNameValue(name, value) { setInputNameValue(name, trim(getValueOfInputName(name) + value)); } function prependToInputNameValue(name, value) { setInputNameValue(name, trim(value + getValueOfInputName(name))); } function isTextareaInput(input)              { return (input.tagName.toLowerCase == "textarea"); }

function setInputNameValue(name, value, isStrict) { isStrict  = (isStrict === null ? true : isStrict); var input = getInputWithName(name); if (input) {   input.value = value; } else if (isStrict) {   alert("ERROR: setInputNameValue(" + name + ")-form lacks element '" + name + "'"); } }

function setSelectNameValue(name, value) { var element = getInputWithName(name); for (var i = element.length - 1; i >= 0; i--) {   element[i].selected = (element[i].value == value); } }

function setRadioNameValue(name, value) { var element = getInputWithName(name); var radios = (element.length && element.length > 0 ? element : [ element ] ); for (var i = 0; i < radios.length; i++) {   radios[i].checked = (radios[i].value == value); } }

function getValueOfRadioName(name) { var value = ""; var element = getInputWithName(name); var radios = (element.length && element.length > 0 ? element : [ element ] ); for (var i = 0; i < radios.length; i++) {   value = (radios[i].checked ? radios[i].value : value); } return value; }

function getBestValueForSelectNameValue(name, value) { var bestValue = ""; var bestDiff = 99999; var element  = getInputWithName(name); for (var i = element.length - 1; i >= 0; i--) {		var optionValue = element[i].value; var optionDiff = Math.abs(optionValue - value); if (optionValue === value || optionDiff < bestDiff) {			bestValue = optionValue; bestDiff = optionDiff; }		 }	return bestValue; }

//////////////////////////////////////////////////////////////////////////////// // VALUES ////////////////////////////////////////////////////////////////////////////////

function getCurrentDatetime { return getIsoDatetimeForDateObject(new Date); }

function getIsoDatetimeForDateObject(o) { var yyyy = o.getFullYear; var m   = o.getMonth + 1; var d   = o.getDate; var h   = o.getHours; var i   = o.getMinutes; var s   = o.getSeconds; var mm  = (m < 10 ? "0" : "") + m;  var dd   = (d < 10 ? "0" : "") + d;  var hh   = (h < 10 ? "0" : "") + h;  var ii   = (i < 10 ? "0" : "") + i;  var ss   = (s < 10 ? "0" : "") + s;  return yyyy + "-" + mm + "-" + dd + " " + hh + ":" + ii + ":" + ss; }

function getDateObjectForIsoDatetime(isoDatetime) { var yyyy = isoDatetime.substring(0,4); var mm  = isoDatetime.substring(5,7); var dd  = isoDatetime.substring(8,10); var hh  = isoDatetime.substring(11,13); var ii  = isoDatetime.substring(14,16); var ss  = isoDatetime.substring(17,19); var oDate = new Date(yyyy, mm-1, dd, hh, ii, ss); return oDate; }

function getEuroDateForDateObject(o) { return o.getDate + "/" + (o.getMonth + 1) + "/" + o.getFullYear; }

function getEuroTimeForDateObject(o) { var h           = o.getHours; var i          = o.getMinutes; var hourLabel  = (h > 12 ? h - 12 : h); var minuteLabel = (i < 10 ? "0"   : "") + i;  var ampm        = (h < 12 ? "am"   : "pm"); return hourLabel + ":" + minuteLabel + " " + ampm; }

function getEuroDatetimeForDateObject(o)           { return getEuroDateForDateObject(o) + " " + getEuroTimeForDateObject(o); } function getEuroDateForIsoDatetime(isoDatetime)    { return getEuroDateForDateObject(getDateObjectForIsoDatetime(isoDatetime)); } function getEuroDatetimeForIsoDatetime(isoDatetime) { return getEuroDatetimeForDateObject(getDateObjectForIsoDatetime(isoDatetime)); }

//////////////////////////////////////////////////////////////////////////////// // WARNINGS ////////////////////////////////////////////////////////////////////////////////

resetWarnings; // always execute //

function resetWarnings    { document.warnings = []; } function addWarning(warning) { document.warnings.push(warning); } function getWarnings      { return document.warnings; } function dumpWarnings { var warnings = getWarnings; var string = ""; for (var i = 0; i < warnings.length; i++) {   string += warnings[i] + "\n\n"; } if (string) {   alert(string); } resetWarnings; return (string !== ""); }

//////////////////////////////////////////////////////////////////////////////// // URL ////////////////////////////////////////////////////////////////////////////////

function redirectToUrl(url) // NOTE: does not propogate url parameters // { window.location = url; }

//////////////////////////////////////////////////////////////////////////////// // POPUP DIVS ////////////////////////////////////////////////////////////////////////////////

document._popupID   = null; document._popupInput = null;

function getPopupInput        { return document._popupInput; } function setPopupInput(input)   { document._popupInput = input; }

function getPopupID           { return document._popupID; } function setPopupID(elementID)  { document._popupID = elementID; }

function setYForPopupIDRefElementIDOffsetXOffsetY(popupID, refElementID, offsetX, offsetY) { setYForPopupIDRefElementOffsetXOffsetY(popupID, getElementWithID(refElementID), offsetX, offsetY); } function openPopupIDRefElementIDOffsetXOffsetY(popupID,   refElementID, offsetX, offsetY) { openPopupIDRefElementOffsetXOffsetY(popupID,    getElementWithID(refElementID), offsetX, offsetY); }

////////////////////////////////////////////////////////////////////////////////

function setYForPopupIDRefElementOffsetXOffsetY(popupID, refElement, offsetX, offsetY) { var popup            = getElementWithID(popupID); var adjustY         = (offsetY - getWindowYOfElement(refElement)); popup.style.position = "absolute"; popup.style.left    = offsetX.toString + "px"; popup.style.top     = adjustY.toString + "px"; //alert("getWindowScrollY = " + getWindowScrollY + "\ngetPageYOfElement(refElement) = " + getPageYOfElement(refElement) + "\ngetWindowYOfElement(refElement) = " + getWindowYOfElement(refElement) + "\nadjustY = " + adjustY + "\npopupY = " + getWindowYOfElement(popup)); }

////////////////////////////////////////////////////////////////////////////////

function openPopupIDRefElementOffsetXOffsetY(popupID, refElement, offsetX, offsetY) { setYForPopupIDRefElementOffsetXOffsetY(popupID, refElement, offsetX, offsetY); openPopupID(popupID); }

////////////////////////////////////////////////////////////////////////////////

function openPopupID(elementID) { closePopup; if (getElementWithID(elementID)) {   showElementID("page-blocker"); showElementID(elementID); setPopupID(elementID); } }

////////////////////////////////////////////////////////////////////////////////

function closePopupID(popupID) { hideElementID("page-blocker"); hideElementID(popupID); setPopupID(0); }

////////////////////////////////////////////////////////////////////////////////

function closePopup { var popupID = getPopupID; if (popupID) {   closePopupID(popupID); } }

//////////////////////////////////////////////////////////////////////////////// // PHOTO POPUPS ////////////////////////////////////////////////////////////////////////////////

function openPhotoPopupID(popupID) {	var refElement = getElementWithID(popupID).parentNode; openPopupIDRefElementOffsetXOffsetY(popupID, refElement, 84, 30); }

//////////////////////////////////////////////////////////////////////////////// // HELP POPUPS //////////////////////////////////////////////////////////////////////////////// // 2015-05-05 txe start //

function openHelpPopup { var popupID    = "help-popup"; var refElement = getElementWithID("main"); openPopupIDRefElementOffsetXOffsetY(popupID, refElement, 84, 30); }

var args = new Object; var query = location.search.substring(1); var pairs = query.split( "," ); for (var i = 0; i < pairs.length; i++) { var pos = pairs[i].indexOf('='); if (pos != -1) {   var name   = pairs[i].substring(0, pos);  // If not found, skip var value = pairs[i].substring(pos + 1); // Extract the name args[name] = unescape(value);            // Extract the value } }

////////////////////////////////////////////////////////////////////////////////

function showVideoCode(code) { showVideoCodeFormat(code, 2); }

function showVideoCodeFormat(code, format) { closePopup;

if (code) {		var controllerUrl = "/videos/" + code + "_controller.swf"; var preloadUrl   = "/videos/" + code + "_preload.swf"; var xmlUrl       = "/videos/" + code + "_config.xml"; var width        = 1020; var height       = (format == 1 ? 755 : 665); var fo           = new SWFObject(controllerUrl, "csSwf", width, height, "7", "#FFFFFF"); fo.addVariable("csConfigFile", xmlUrl); fo.addVariable("csPreloader", preloadUrl); fo.addVariable("csColor",     "FFFFFF"); if (args.movie) {			fo.addVariable("csFilesetBookmark", args.movie); }		fo.write("flashcontent"); var popupHeight = (height + 0);

// 2015-06-01 txe start // //		getElementWithID("video-popup").style.height = popupHeight.toString + "px"; //   openPopupIDRefElementOffsetXOffsetY("video-popup", "left", -39, -220); var popupID       = "video-popup"; var popup         = getElementWithID(popupID); popup.style.height = popupHeight.toString + "px"; var refElement    = popup.parentNode; openPopupIDRefElementOffsetXOffsetY(popupID, refElement, 0, 0); // 2015-06-01 txe end //

}	else {		alert("Sorry, this video is not available yet."); } }

//////////////////////////////////////////////////////////////////////////////// // COORDINATES ////////////////////////////////////////////////////////////////////////////////

function getWindowScrollX          { return (document.all ? document.scrollLeft : window.pageXOffset); } function getWindowScrollY          { return (document.all ? document.scrollTop  : window.pageYOffset); } function getWindowXOfElement(element) { return getPageXOfElement(element) - getWindowScrollX; } function getWindowYOfElement(element) { return getPageYOfElement(element) - getWindowScrollY; }

function getPageXOfElement(element) { var x = 0; if (element) {			for (var e = element; e && e.tagName && e.tagName.toLowerCase != "body"; e = e.offsetParent) {			x += (e.offsetLeft - e.scrollLeft + e.clientLeft); }	}	else { //		alert("getPageXOfElement(null) called"); } return x; }

function getPageYOfElement(element) { var y = 0; if (element) {			for (var e = element; e && e.tagName && e.tagName.toLowerCase != "body"; e = e.offsetParent) {			y += (e.offsetTop - e.scrollTop + e.clientTop); }	}	else { //		alert("getPageYOfElement(null) called"); } return y; }

/*
 * 1) File:    js/map.js
 * 1) File:    js/map.js
 * 1) File:    js/map.js

setInitialMapLat(-43.7); setInitialMapLon(171); setInitialMapZoom(6);

setKmlUrls([]); setKmlLayers([]);

google.maps.event.addDomListener(window, "load", initializeMap);

//////////////////////////////////////////////////////////////////////////////// // FUNCTIONS ////////////////////////////////////////////////////////////////////////////////

function getInitialMapLat     { return document._initialLat; } function getInitialMapLon     { return document._initialLon; } function getInitialMapZoom    { return document._initialZoom; } function setInitialMapLat(lat)  { document._initialLat  = lat; } function setInitialMapLon(lon)  { document._initialLon  = lon; } function setInitialMapZoom(zoom) { document._initialZoom = zoom; }

function getKmlUrls           { return document._kmlUrls; } function setKmlUrls(urls)       { document._kmlUrls = urls; } function addKmlUrl(url)         { document._kmlUrls.push(url); }

function getKmlLayers         { return document._kmlLayers; } function setKmlLayers(layers)   { document._kmlLayers = layers; } function addKmlLayer(layer)     { document._kmlLayers.push(layer); }

function isUseGeoXml3         { return true; } //request("isUseGeoXml3"); }

////////////////////////////////////////////////////////////////////////////////

function initializeMap { var mapOptions = { center               : new google.maps.LatLng(getInitialMapLat, getInitialMapLon), zoom                 : getInitialMapZoom, zoomControl          : true, panControl           : true, streetViewControl    : false, zoomControlOptions   : { style: google.maps.ZoomControlStyle.LARGE }, scaleControl         : true, mapTypeId            : google.maps.MapTypeId.TERRAIN, mapTypeControl       : true, mapTypeControlOptions : { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU } };

document._map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

//if (isUseGeoXml3) alert("using geoxml3"); //alert("isUseGeoXml3 = " + isUseGeoXml3);

document._numParsed = 0;

var kmlUrls = getKmlUrls;

for (var i = 0; i < kmlUrls.length; i++) {		var kmlUrl = kmlUrls[i];

if (isUseGeoXml3) // third party handling, to try to get hover working // {           var parser = new geoXML3.parser( {				map           : document._map,				zoom          : false,				processStyles : true,				afterParse    : addListenersForGeoXml3Docs			} ); parser.parse(kmlUrl);

parser.url = kmlUrl;

addKmlLayer(parser); }				else // standard Google Maps API KML handling // {			var layer = new google.maps.KmlLayer( { 				url             : kmlUrl,				preserveViewport : true						} ); layer.setMap(document._map); google.maps.event.addListener(layer, "click", function(kmlEvent) {				setMapPopupFixerMillis(200);				fixMapPopup;			});

addKmlLayer(layer); }	}		}

////////////////////////////////////////////////////////////////////////////////

function addListenersForGeoXml3Docs(docs) { geoXmlDoc = docs[0]; var lines = docs[0].gpolylines; for (var i = 0; i < lines.length; i++) {		var line = lines[i]; addListenersForGeoXML3Line(line); }	document._numParsed++; }

////////////////////////////////////////////////////////////////////////////////

function addListenersForGeoXML3Line(line) {	line._normalColor = line.strokeColor; line._normalWeight = line.strokeWeight;

google.maps.event.addListener(line, "mouseover", function(evt) {		line.setOptions( { strokeColor : "#ffff00", strokeWeight : 5, });	});	google.maps.event.addListener(line, "mouseout", function(evt) {		line.setOptions({ strokeColor : line._normalColor, strokeWeight : line._normalWeight });	});	}

////////////////////////////////////////////////////////////////////////////////

function getMapPopupFixerMillis      { return document._mapFixerMillis; } function setMapPopupFixerMillis(millis) { document._mapFixerMillis = millis; }

////////////////////////////////////////////////////////////////////////////////

function fixMapPopup {	var isFixed = false; var map    = getElementWithID("map"); var links  = map.getElementsByTagName("a");

for (var i = 0; i < links.length; i++) {		var a = links[i]; //alert("link[" + i + "] label = " + a.innerHTML); if (a.innerHTML == "Click here for a detailed article") { //alert("Found popup link: " + a.href); a.target = "_self"; //			a.innerHTML = "Click here for a detailed article"; isFixed = true; }	}

if (!isFixed) {		setMapPopupFixerMillis(getMapPopupFixerMillis * 2); setTimeout(fixMapPopup, getMapPopupFixerMillis); } }

////////////////////////////////////////////////////////////////////////////////

function resetMap {  var center = new google.maps.LatLng(getInitialMapLat, getInitialMapLon); document._map.setCenter(center); document._map.setZoom(getInitialMapZoom); }

////////////////////////////////////////////////////////////////////////////////

function handleMapFilters {	if (isUseGeoXml3 && document._numParsed < getKmlLayers.length) {		setTimeout(handleMapFilters, 500); }	if (getElementWithID("map-filters", false)) {		var inputs = getElementWithID("map-filters").getElementsByTagName("input"); for (var i = 0; i < inputs.length; i++) {			var input = inputs[i]; if (input.name.indexOf("isMap_") >= 0) {				handleMapFilter(input); }		}	}		}

////////////////////////////////////////////////////////////////////////////////

function handleMapFilter(input) {	var isChecked = input.checked; var group    = input.name.replace("isMap_", ""); var layers   = getKmlLayers; for (var i = 0; i < layers.length; i++) {		var layer  = layers[i]; var url    = layer.url; var isMatch = (url.indexOf("all-" + group + ".kml") >= 0); if (isMatch) {						if (isUseGeoXml3) {				if (layer.docs && layer.docs[0]) {					if (isChecked) {						layer.showDocument(layer.docs[0]); }					else {						layer.hideDocument(layer.docs[0]); }				}			}			else {							layer.setMap(isChecked ? document._map : null); }		}	} }

////////////////////////////////////////////////////////////////////////////////

function openMapKeyPopup {	openPopupID("map-key-popup"); //	openPopupIDRefElementIDOffsetXOffsetY("map-key-popup", "map", -20, 50); }

//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////