var isNS4, isIE4, isIE5, isNS6;
var coll = "";
var logoset = "n";
var styleObj = "";
var cp = "c"; // differentiate between current or previous image display
var zIndex = 3; // Must be larger than our backgrounds
isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;
if (isNS6) {
    coll = "getElementById('"
    styleObj = "').style" 
} else {
    if (isIE4 || isIE5) {
        coll = "all."
        styleObj = ".style" 
    }
}
// ---------------------
function show(obj) {
  obj.visibility = "visible" 
}
// ---------------------
function hide(obj) {
  obj.visibility = "hidden" 
}
// ---------------------
function setLogo(form) {
    if ( logoset == "n" ) {
        var prntFlag;
        if ( cp == "p" ) { // if working with 'previous' images
            prntFlag = prods[46];
            form[prntFlag].value = "off";
            prntFlag = prods[47];
            form[prntFlag].value = "on";
        } else {
            prntFlag = prods[46];
            form[prntFlag].value = "on";
            prntFlag = prods[47];
            form[prntFlag].value = "off";
        }
        logoset = "y";
    }
}
// ---------------------
function changeVisibility(form,Obj,num) {
    x = num;
    setLogo(form);
    if ( cp == "p" ) { // if working with 'previous' images, set index (num) to reference that set of images
        if ( num > 0 && num < 20 ) { // prior to changing index ensure that maps are not effected
            x = num + 20;
        }
    }
    var imgobj = eval("document." + coll + "image" + x + styleObj);
    if (Obj.checked) {
        if ( num == 0) { // keeps the terrain map (set to '0') underneath all other images
            setZIndex(imgobj, 0);
        } else {
            if ( num > 40) { // keeps maps on top of all other images
                setZIndex(imgobj, num);
            } else {
                zIndex++;
                priority[num] = zIndex; // set to priority level of image
                //alert( "zIndex = " + zIndex + ". Priority number = " + priority[num] + " ." )
                setZIndex(imgobj, zIndex);
            }
        }
        show(imgobj);
        if (firstTime && num > 3 && num < 20 ) {
            firstTime = false;
            if ( cp == "c" ) { // working with 'current' images
                var imgobj = eval("document." + coll + "image20" + styleObj);
                setZIndex(imgobj, 50); // always have logo/time stamp on top
                show(imgobj);
            } else { // working with 'previous' images
                var imgobj = eval("document." + coll + "image40" + styleObj);
                setZIndex(imgobj, 51); // always have logo/time stamp on top
                show(imgobj);
            }
        }
    } else {
        hide(imgobj);
        if ( num > 3 && num < 40 ) {
            chk = priority[num]; // hold priority number of hidden image
            priority[num] = ""; // null array position
            for ( i = 4; i < 14; i++) { // process array
                if ( priority[i] > chk ) { // if any priority is found to be greater than that just hidden
                    priority[i] = priority[i] - 1;
                }
            } // then knock it down one level
            zIndex--;
        }
    }
}

// ---------------------
function changeVisCO(form,Obj,num) { // used with the 'current' image only page - prod-olay-1img.html
    var imgobj = eval("document." + coll + "image" + num + styleObj)
    if (Obj.checked) {
        if ( num == 0) { // keeps the terrain map (set to '0') underneath all other images
            setZIndex(imgobj, 0);
        } else {
            if ( num > 20) { // keeps maps on top of all other images
                setZIndex(imgobj, num);
            } else {
                zIndex++;
                setZIndex(imgobj, zIndex);
            }
        }
        show(imgobj);
        if (firstTime && num > 3 && num < 20 ) {
            firstTime = false;
            var imgobj = eval("document." + coll + "image20" + styleObj);
            setZIndex(imgobj, 30); // always have logo/time stamp on top
            show(imgobj);
        } 
    } else {
        hide(imgobj);
        zIndex--;
    }
}
// ---------------------
function chgSatVis(form,Obj,num) {
    x = num;
    j = 1; // must equal image number of first satellite image i.e. 'image1'
    k = 4; // must be one greater than number of satellite images
    setLogo(form);
    if ( cp == "p" ) { // if working with 'previous' images, set index (num) to reference that set of images
        x = num + 20;
    }
    if (Obj.checked) {
        if (satFirstTime) {
            satFirstTime = false;
            if ( firstTime) {
                firstTime = false;
                if ( cp == "c" ) { // working with 'current' images
                    var imgobj = eval("document." + coll + "image20" + styleObj);
                    setZIndex(imgobj, 50); // always have logo/time stamp on top
                    show(imgobj);
                } else { // working with 'previous' images
                    var imgobj = eval("document." + coll + "image40" + styleObj);
                    setZIndex(imgobj, 51); // always have logo/time stamp on top
                    show(imgobj);
                } 
            } 
        } else {
            for (var i = j; i<k; i++) {
                if ( i != num ) {
                    clearElement = prods[i];
                    if (form[clearElement].checked) {
                        uncheck(form,i);
                        if ( cp == "p" ) {
                            hide1 = i + 20;
                        } else {
                            hide1 = i;
                        }
                        var imgobj = eval("document." + coll + "image" + hide1 + styleObj);
                        hide(imgobj);
                    }
                }
            } 
        }
        var imgobj = eval("document." + coll + "image" + x + styleObj); // show image
        setZIndex(imgobj, num);
        priority[num] = num; // set to priority level of image
        show(imgobj);
    } else {
        var imgobj = eval("document." + coll + "image" + x + styleObj);
        satFirstTime = true;
        hide(imgobj);
    }
}
// ---------------------
function chgSatVisCO(form,Obj,num) {
    x = num;
    j = 1; // must equal image number of first satellite image i.e. 'image1'
    k = 4; // must be one greater than number of satellite images
    if (Obj.checked) {
        if (satFirstTime) {  // no need to go through clearing checkbox proceedure
            satFirstTime = false;
            if ( firstTime) {  // ensure that the logo - date - time stamp is visible
                firstTime = false;
                var imgobj = eval("document." + coll + "image20" + styleObj);
                setZIndex(imgobj, 30); // always have logo/time stamp on top
                show(imgobj);
            }
        } else {  // not first time through, need to clear 'old' checkbox
            for (var i = j; i<k; i++) {
                if ( i != num ) {
                    clearElement = prods[i];
                    if (form[clearElement].checked) {
                        uncheck(form,i);
                        var imgobj = eval("document." + coll + "image" + i + styleObj);
                        hide(imgobj);
                    }
                }
            } 
        }
        var imgobj = eval("document." + coll + "image" + x + styleObj); // show image
        setZIndex(imgobj, num);
        show(imgobj);
    } else {  // image has been unchecked, need to make image visibility hidden
        var imgobj = eval("document." + coll + "image" + x + styleObj);
        satFirstTime = true;
        hide(imgobj);
    }
}
// ---------------------
function changeWindCO(form, winds) { // used with the 'current' image only page - prod-olay-1img.html
    var num = form.winds.options[form.winds.selectedIndex].value;
    j = 14; // must equal image number of first wind image i.e. 'image14'
    k = 20; // must be one greater than number of wind images
    if (firstWind) { // do we need to make wind image hidden?
        firstWind = false;
    } else { // make wind image - whatever one is currently visble - hidden
        for (var i = j; i<k; i++) { // make visibility hidden for all wind images
            var imgobj = eval("document." + coll + "image" + i + styleObj);
            hide(imgobj);
            prntFlag = prods[i];
            form[prntFlag].value = "off";
        } // reset printing to off (hidden form field)
        zIndex--;
    }
    if ( num != 0 ) { // if user has chosen a wind image (other than 0), process
        zIndex++;
        var imgobj = eval("document." + coll + "image" + num + styleObj)
        setZIndex(imgobj, zIndex);
        show(imgobj);
        prntFlag = prods[num];
        form[prntFlag].value = "on"; // turn on hidden form field for printing image
        if (firstTime) {
            firstTime = false;
            var imgobj = eval("document." + coll + "image20" + styleObj);
            setZIndex(imgobj, 30); // always have logo/time stamp on top
            show(imgobj);
        }
    } else { // user has selected no winds (0) so reset flag
        firstWind = true;
    }
}
// ---------------------
function defaultMapCO( form, n ) {
    zIndex = 3; // reset
    firstTime = true;
    satFirstTime = true;
    for (var i = 1; i<n; i++) {
        var imgobj = eval("document." + coll + "image" + i + styleObj);
        hide(imgobj);
        if (i > 13 && i < 20) { // reset printing to off (hidden form fields)
            prntFlag = prods[i];
            form[prntFlag].value = "off"
        }
    }
    var imgobj = eval("document." + coll + "image0" + styleObj);
    setZIndex(imgobj, 0); // put terrain on bottom
    show(imgobj);
    var imgobj = eval("document." + coll + "basemap" + styleObj);
    setZIndex(imgobj, 0); // put state outline on top of terrain
    show(imgobj);
    var imgobj = eval("document." + coll + "image20" + styleObj);
    setZIndex(imgobj, 30); // put logo ontop of all
    show(imgobj);
}
// ---------------------
function defaultMap( form, n ) {
    zIndex = 3;  // reset
    firstTime = true;
    satFirstTime = true;
    for (var i = 1; i<n; i++) {
        priority[i] = "1"; // reset priority level array
        var imgobj = eval("document." + coll + "image" + i + styleObj);
        hide(imgobj);
    }
    var imgobj = eval("document." + coll + "image0" + styleObj);
    setZIndex(imgobj, 0); // put terrain on bottom
    show(imgobj);
    var imgobj = eval("document." + coll + "basemap" + styleObj);
    setZIndex(imgobj, 0); // put state outline on top of terrain
    show(imgobj);
    var imgobj = eval("document." + coll + "image20" + styleObj);
    setZIndex(imgobj, 30); // put logo ontop of all
    show(imgobj);
    cp = "c";
    logoset = "n";
    form["cpbutton"].value = "PREVIOUS";
}
// ---------------------
function SwitchToPrevious( form, n ) {
    for (var i = 1; i<n; i++) {
        element = prods[i];
        if ( form[element].checked ) {
            cnum = i + 20;
            var imgobj = eval("document." + coll + "image" + i + styleObj);
            var cimgobj = eval("document." + coll + "image" + cnum + styleObj);
            //alert( "This is an alert. Image " + i + " was checked at " + priority[i] + " priority level." )
            hide(imgobj);
            setZIndex(cimgobj, priority[i]); // set display priority level to the same
            show(cimgobj);
        }
    }
    var imgobj = eval("document." + coll + "image20" + styleObj);
    var cimgobj = eval("document." + coll + "image40" + styleObj);
    setZIndex(cimgobj, 51); // set index so logo/time stamp is on top
    hide(imgobj);
    show(cimgobj);
}
// ---------------------
function SwitchToCurrent( form, n ) {
    for (var i = 1; i<n; i++) {
        element = prods[i];
        if ( form[element].checked ) {
            cnum = i + 20;
            var imgobj = eval("document." + coll + "image" + i + styleObj);
            var cimgobj = eval("document." + coll + "image" + cnum + styleObj);
            //alert( "This is an alert. Image " + cum + " was selected and image " + i + " will be made visible." )
            hide(cimgobj);
            setZIndex(imgobj, priority[i]); // set display priority level to the same
            show(imgobj);
        } 
    }
    var imgobj = eval("document." + coll + "image20" + styleObj);
    var cimgobj = eval("document." + coll + "image40" + styleObj);
    setZIndex(imgobj, 50); // set index so logo/time stamp is on top
    hide(cimgobj);
    show(imgobj);
}
// ---------------------
function initpage(ptitle) {
    window.defaultStatus = ptitle;
}
// ---------------------
function uncheck( form, num ) {
    clearElement = prods[num];
    //alert( "This is an alert. " + form[element].name + " has been selected and " + form[clearElement].name + " will be cleared." )
    form[clearElement].checked = false;
}
// ---------------------
function currentPrevious( form ) {
    //alert( "This is an alert. The cp variable = '" + cp + "'." )
    if ( cp == "c" ) {
        cp = "p";
        SwitchToPrevious( form, 14 );
        form["cpbutton"].value = "CURRENT";
    } else {
        cp = "c";
        SwitchToCurrent( form, 14 );
        form["cpbutton"].value = "PREVIOUS";
    } 
    logoset = "n";
    setLogo(form);
}
// ---------------------
function setZIndex(obj, zOrder) {
    obj.zIndex = zOrder;
} 
// ---------------------
function setStatus(msg) {
    window.status = msg;
    return true;
}
// ---------------------
function ShowPopup( popName, t, l, d, s, m, b, r, w, h, lt, tp ) {
    // open the popup window
    var popupURL = popName + ".html";
    var popup = window.open(popupURL,"InfoPopup",
            'toolbar=' +  t + ',location=' + l + ',directories=' + d + ',status=' + s + ',menubar=' + m + ',scrollbars=' + b + ',resizable=' + r + ',width=' + w + ',height=' + h + ',left=' + lt + ',top=' + tp 
        );
    // set the opener if it's not already set.  it's set automatically
    // in netscape 3.0+ and ie 3.0+.
    if( navigator.appName.substring(0,8) == "Netscape" ) {
        popup.location = popupURL;
    } 
}
// ---------------------
function MakeImageArray(n) {
    this.length = n;
    for (var i = 0; i<n; i++) {
        this[i] = new Image();
    }
    return this;
}
// ---------------------
function openWin(url, name, t, l, d, s, m, b, r, w, h, lt, tp ) {
    popupWin = window.open(url, name,
        'toolbar=' +  t + ',location=' + l + ',directories=' + d + ',status=' + s + ',menubar=' + m + ',scrollbars=' + b + ',resizable=' + r + ',width=' + w + ',height=' + h + ',left=' + lt + ',top=' + tp 
    );
}
// --------------
function openNewCloseOld(url, newWin, oldWin) {
    window.open(url, newWin);
    window.close(oldWin);
}
// ---------------------
// updated by: P. Kennedy 14 May 2001
//
