/* -------------------------------------------------
MAP JAVASCRIPT FUNCTIONS:
1. Flash Detection
2. Admin Point Plotting
3. Full Info Window Open
------------------------------------------------- */

//1. detect flash
// -----------------------------------------------------------------------------
// Globals
var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 0;
var jsVersion = 1.0;

// Detect Client Browser type
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;

// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){ if (navigator.plugins != null && navigator.plugins.length > 0) { if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";	var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; var descArray = flashDescription.split(" ");var tempArrayMajor = descArray[2].split(".");var versionMajor = tempArrayMajor[0];var versionMinor = tempArrayMajor[1];if ( descArray[3] != "" ){var tempArrayMinor = descArray[3].split("r");}else{var tempArrayMinor = descArray[4].split("r");}; var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;} else{var flashVer = -1;};}else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) var flashVer = 4;	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) var flashVer = 3;	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) var flashVer = 2;	else {var flashVer = -1;};return flashVer;};

// If called with no parameters this function returns a floating point value 
// which should be the version of the Flash Player or 0.0 
// ex: Flash Player 7r14 returns 7.14
// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) { var reqVer=parseFloat(reqMajorVer + "." + reqRevision);for (var i=25;i>0;i--){	if (isIE && isWin && !isOpera){var versionStr=VBGetSwfVer(i);}else{var versionStr=JSGetSwfVer(i);};if (versionStr == -1 ){ return false;}else if (versionStr != 0){if(isIE && isWin && !isOpera){var tempArray=versionStr.split(" ");var tempString=tempArray[1];var versionArray=tempString .split(",");}else{var versionArray=versionStr.split(".");};var versionMajor=versionArray[0];var versionMinor=versionArray[1];var versionRevision=versionArray[2];var versionString=versionMajor + "." + versionRevision;var versionNum=parseFloat(versionString);if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ){return true;} else{return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );};};}	;return (reqVer ? false : 0.0);};


//---------------------------------------------------------
//2. Admin Point Plotting

//globals
var d=document;

//get coords from the flash file, and post in inputs x: mapCoordsX, y:mapCoordsY
function setCoords(x,y) { window.opener.d.getElementById('mapXCoord').value = x; window.opener.d.getElementById('mapYCoord').value = y; alert('New Point of Interest set at ('+x+','+y+')\n\nYou may close this window if you are satisfied with the positioning.'); };

//3. Open Help file window, open map point full info.
function openHelpFile () { var h = window.open('help.html', 'helpWin', 'height=390,width=335,scrollbars=no,resizeable=no'); h.focus(); };
function openPointInfoWin(url) { var infoWin = window.open(url, 'pointInfoWin', 'height=450,width=450,scrollbars=no,resizeable=no'); infoWin.focus(); };

//4. Open map window for browsing/plotting point in admin
function openMapWin(isAdmin, isBrowse)
{
    var url = "/map/index.html";
    if (typeof isAdmin != "undefined") url += "?admin=true";
    if (typeof isBrowse != "undefined") url += "&browse=true";
    var mapWin = window.open(url, 'mapWindow', 'height=540, width=790, scrollbars=no, resizeable=no');
    mapWin.focus();
}

//5. GET vars
function getVarsInfo (n, v) { this.name = n; this.value = v; };
var tmp = new Array();var GET = new Array();var GETnames = new Array();var GETvalues = new Array();var getVarSearch = location.search.substring(1).split("&");
function getVars () { for(var i=0;i<getVarSearch.length;i++) {var t = getVarSearch[i].split("=");tmp[i] = new getVarsInfo(t[0], unescape(t[1]));GET[tmp[i].name] = tmp[i].value;GETnames[i] = tmp[i].name;GETvalues[i] = tmp[i].value;};};

//6. Print Flash content
function printFlashContent ()
{
    getVars();
    var isAdmin = typeof GET['admin'] != "undefined" ? new Boolean(GET['admin']) : "";
    isAdmin = isAdmin.valueOf();
    var isDebug = typeof GET['debug'] != "undefined" ? new Boolean(GET['debug']) : "";
    isDebug = typeof isDebug != "undefined" ? isDebug.valueOf() : "";
    var browse = typeof GET['browse'] != "undefined" ? new Boolean(GET['browse']) : "";
    browse = typeof browse != "undefined" ? browse.valueOf() : "";
    
    var movieValue = "map.swf";
    
    movieValue += isAdmin ? "?admin=true" : "";
    movieValue += isDebug ? "&debug=true" : "";
    movieValue += browse ? "&browse=true" : "";

    
    var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if(hasRightVersion) {
        var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
        + 'width="790" height="540"'
        + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
        + '<param name="movie" value="'+movieValue+'" /><param name="quality" value="high" /><param name="bgcolor" value="#1a1a1a" />'
        + '<embed src="'+movieValue+'" quality="high" bgcolor="#1a1a1a" '
        + 'width="790" height="540" name="map" align="middle"'
        + 'play="true"'
        + 'loop="false"'
        + 'quality="high"'
        + 'allowScriptAccess="sameDomain"'
        + 'type="application/x-shockwave-flash"'
        + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
        + '<\/embed>'
        + '<\/object>';
        document.write(oeTags);
    } else {
        var alternateContent = "This page requires the latest Macromedia Flash Player."
       	+ "<a href=\"http://www.macromedia.com/go/getflash/\">Get Flash</a>";
        document.write(alternateContent);
    };
}

//-->