﻿//*****************************************************************
// RAI JAVASCRIPT                                                  
//*****************************************************************


//*****************************************************************
// TOOLTIP DIVS                                                    
//*****************************************************************

//popup window

function MadeInUSA() {
    //KEEP THIS.
    //opens a new window with given image file; window is same size as image.



    alert("here it is");
    
    var x = "../images-rai/made-in-the-usa.jpg"
   var newImg = new Image();
    newImg.src = x
    //temporary: figure out how to make it wait.
    //alert("give it time to load");

    var h = newImg.height;
    var w = newImg.width;

    window.open(x, "mywindow", "menubar=1,resizable=1,width=" + w + ",height=" + h + "");
    // alert('The image size is ' + w + ' * ' + h);
}

function jsfXPop(strTarget) {




    var strOptions = "left=100,top=100,width=500,height=550,toolbar=0, menubar=0,scrollbars=0, resizable=0,location=0, directories=0, status=0";




    window.open(strTarget, "winx", strOptions);
}

function jsfMailPop(strTarget) {

    var strOptions = "left=100,top=100,width=650,height=700,toolbar=0, menubar=0,scrollbars=0, resizable=0,location=0, directories=0, status=0";


    window.open(strTarget, "winx", strOptions);
}


function RAIHelp(xtitle, xtext) {
    var adiv = PopupDiv("MYHELPDIV", "xtitle", "blue", 200, 400, 300, 600, "");
    try {
        var b = document.getElementById("MYHELPDIVDivBody");

        b.style.marginLeft = "auto";
        b.style.marginRight = "auto";


        var xx = "";

        xx += "<div style='text-align: center;'>"
        xx += "<img alt='' src='Images/lightbulb.png' style='width: 30px; height: 30px' />"
        xx += "</div>"

        xx += "<div style='text-align: justify; padding: 0px 20px 20px 20px;'>";


        xx += xtext;


        xx += "</div>";

        b.innerHTML = xx
    }
    catch (err) {
        alert(err);
    }
}

function PopupDiv(divName, xTitle, xColor, xHeight, xWidth, xTop, xLeft, msg) {
    //create div, put on screen
    //have way to close div
    //have heading ribbon

    try {

        //If a div exists with this ID, get rid of it.
        var olddiv = document.getElementById(divName);
        if (olddiv) {
            RemoveElement(divName);
        }

        //Create the OUTER div
        var outerDiv = document.createElement("div");
        document.body.appendChild(outerDiv);

        //Add div name
        outerDiv.setAttribute("id", divName);

        //Create the style
        var myStyle = ""
        myStyle += "border: thin double " + xColor + "; "
        myStyle += "padding: 0px; margin: 0px; "
        myStyle += "position: absolute; "
        myStyle += "top: " + xTop + "px;"
        myStyle += "left: " + xLeft + "px;"
        myStyle += "width: " + xWidth + "px;"
        myStyle += "background-color: white;"
        myStyle += "font-family: verdana, arial, sans-serif; font-size: small;"
        myStyle += "z-index:999;"

        //Add div style
        outerDiv.setAttribute("style", myStyle);

        // Construct HTML for inside of helpDiv.
        var myHTML = ""



        myHTML += "<div id='" + divName + "DivHeader" + "' style='background-color: " + xColor + "; color: #FFFFFF; padding: 3px; text-align: center; '>" + xTitle + "</div>";


        myHTML += "<div id='" + divName + "DivBody" + "'style='margin: 5px;' >"


        myHTML += msg;


        myHTML += "</div>"

        var closecommand = "javascript:RemoveElement('" + divName + "');"


        var xx = "<div id='" + divName + "DivClose" + "'style='text-align: center;'><a href=" + closecommand
        xx += ">close</a> </div>"

        myHTML += xx

        outerDiv.innerHTML = myHTML + "<br />"

        return outerDiv;
    }
    catch (err) {
        alert("PopupDiv: " + err);
    }

}

function MakeLink(address, text) {
    try {
        var mlink = "<a href=\"";
        mlink += address;
        mlink += "\">" + text + "</a>"
        return mlink;
    }
    catch (err) {
        alert("MakeLink: " + err);

    }

}

function RemoveElement(elementID) {

    try {
        var d = document.getElementById(elementID);
        if (d) {
            d.parentNode.removeChild(d);
        }
    }
    catch (err) {
        alert("removeElement: " + err);
    }

}

function helpDivHide(pageObjectName) {
    //This works.

    try {
        var targetObject = document.getElementById(pageObjectName);
        var toremove = document.getElementById('helpdiv');
        targetObject.parentNode.removeChild(document.getElementById('helpdiv'));

        //targetObject.parentNode.removeChild(toremove);
    }
    catch (Error) {
        //don't do anything.
    }

}

function helpDivShow(msg, pageObjectName) {
    //This works.
    var targetObject = document.getElementById(pageObjectName);

    //Get the size of the new div
    var width = 200;
    var height = 100;
    var msgLength = msg.length;

    //Get the top and left for the div
    var top = 0;
    var left = 0;
    top = targetObject.offsetTop + targetObject.offsetHeight;
    left = targetObject.offsetLeft + targetObject.offsetWidth;

    //Create the div
    var doc = document;
    var div = targetObject.parentNode.appendChild(doc.createElement("div"));

    //Add div name
    div.setAttribute("id", "helpdiv");



    // Construct HTML for inside of helpDiv.
    var myHTML = ""
    myHTML += "<div style='margin:3px; border-width: 3px; border-color: #FFFFFF'>"
    myHTML += "<div style='border: 2px solid #CCCCCC; background-color: white;'>"
    myHTML += "<div style='border-style: solid; border-width: 1px; border-color: blue'; padding: 3px;>"
    myHTML += "<p style='margin: 3px; padding: 3px; width: 200px; text-align: left; text-transform: uppercase; font-size: x-small; border: none;'>"
    myHTML += msg;
    myHTML += "</p>"
    myHTML += "</div>"
    myHTML += "</div>"
    myHTML += "</div>"

    div.innerHTML = myHTML + "<br />"


    //Create the style
    var myStyle = ""
    myStyle += "border: none; "
    myStyle += "padding: 0px; margin: 0px; "
    myStyle += "position: absolute; "
    myStyle += "top: " + top + "px;"
    myStyle += "left: " + left + "px;"
    //myStyle += "height: " + height + "px; "
    //myStyle += "width: " + width + "px;"
    myStyle += "background-color: transparent;"
    myStyle += "font-family: verdana, arial, sans-serif; font-size: small;"
    myStyle += "z-index:999;"

    //Add div style
    div.setAttribute("style", myStyle);





}

//*****************************************************************
// COOKIES                                                         
//*****************************************************************

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function xAlert(typeOfMessage, Message) {
    var msg = "\n";
    msg += typeOfMessage + "\n\n";
    msg += Message + "\n\n";
    alert(msg);
}



function TrapSpecialKeys() {
    alert("in TrapSpecialKeys()");
    var x = window.document.event.keycode;
}



function HandleError() {

    //var e = Error.prototype.message;

    alert("An error occurred: " + Error.prototype.message);
}

//*****************************************************************
// IMAGES                                                          
//*****************************************************************

function ImagePopup(myImage) {
    //KEEP THIS.
    //opens a new window with given image file; window is same size as image.
    if (!myImage) {
        alert("No image file specified.");
        return;
    }

    var newImg = new Image();
    newImg.src = myImage;

    //temporary: figure out how to make it wait.
    alert("hi");

    var h = newImg.height;
    var w = newImg.width;

    window.open("bg_main.jpg", "mywindow", "menubar=1,resizable=1,width=" + w + ",height=" + h + "");
    alert('The image size is ' + w + ' * ' + h);
}

function AnalyzeTags(tagName) {
    //if blank tag name is sent, prompt for one.
    if (!tagName) {
        tagName = prompt("Enter tag.", "")
        //if not tag given, exit function.
        if (!tagName) {
            return
        }
    }
    var links = document.getElementsByTagName(tagName);
    alert("Tags found: " + links.length);
    //
    var msg = "";
    msg += "<a href='javascript:ClosePropertyList();'>click to close</a><br />"
    msg += "TAGS: " + tagName + "\n\n";
    //
    var k = 0;
    for (k = 0; k < links.length; k++) {
        //alert(links[k]);
        msg += links[k] + "<br />";
    }

    //create the div
    var divTag = document.createElement("div");
    //name the div
    divTag.id = "divPropertyList";
    //style the div
    var mystyle = "border: medium solid #0000FF; height:500px; width:500px; position:absolute; left:100px; top:100px; background-color: #CCCCCC; font-family: Arial, Helvetica, sans-serif; font-size: x-small; overflow: scroll;"
    divTag.setAttribute("style", mystyle);
    //put text of message into div
    divTag.innerHTML = msg;
    //add the div to the document
    document.body.appendChild(divTag);

}

function ClosePropertyList() {
    //this can be simplied, put into the original link...
    try {
        var toremove = document.getElementById('divPropertyList');
        document.body.removeChild(toremove);
    }
    catch (Error) {
        alert(Error);
    }
}

function ShowProps(objectName) {




    //if blank object name is sent, prompt for one.
    if (!objectName) {
        objectName = prompt("Enter object name.", "")
        //if not object name give, exit function.
        if (!objectName) {
            return
        }
    }

    var d = document.getElementById(objectName);
    var intProps = 0;
    var arrayProps = [];
    var k = 0;

    //start the text with the closing link.
    var msg = ""

    msg += "<a href='javascript:ClosePropertyList();'>click to close</a><br />"

    msg += "OBJECTNAME: " + objectName + "\n";

    //build array of properties
    for (var prop in d) {
        if (d[prop]) {

            arrayProps[intProps] = prop + "=" + d[prop];
            intProps++;
        }

    }
    //sort the array;
    var na = arrayProps.sort();
    //build display string
    for (k = 0; k < na.length; k++) {
        msg += na[k] + "<br />"
    }


    //create the div
    var divTag = document.createElement("div");
    //name the div
    divTag.id = "divPropertyList";
    //style the div
    var mystyle = "border: medium solid #0000FF; height:500px; width:500px; position:absolute; left:100px; top:100px; background-color: #CCCCCC; font-family: Arial, Helvetica, sans-serif; font-size: x-small; overflow: scroll;"
    divTag.setAttribute("style", mystyle);
    //put text of message into div
    divTag.innerHTML = msg;
    //add the div to the document
    document.body.appendChild(divTag);

}


function AddToFavorites() {
    if (!confirm("Bookmark this page?")) {
        return;
    }


    if (window.external) {
        window.external.AddFavorite(location.href, document.title)

    }
    else {
        alert("Sorry! Bookmarking not available in this browser.");
    }
}

//diagnostics popup
function BrowserDiags() {
    var msg = "";
    msg = msg + "BROWSER FACTS" + "\n" + "\n";
    msg = msg + "appCodeName: " + navigator.appCodeName + "\n";
    msg = msg + "appName: " + navigator.appName + "\n";
    msg = msg + "cookieEnabled: " + navigator.cookieEnabled + "\n";
    msg = msg + "platform: " + navigator.platform + "\n";
    msg = msg + "javaEnabled: " + navigator.javaEnabled() + "\n";
    //
    //
    msg = msg + "screen.availHeight: " + screen.availHeight + "\n";
    msg = msg + "screen.availWidth: " + screen.availWidth + "\n";
    msg = msg + "screen.width: " + screen.width + "\n";
    msg = msg + "screen.height: " + screen.height + "\n";
    //
    //
    msg = msg + "location.host: " + location.host + "\n";
    msg = msg + "location.hostname: " + location.hostname + "\n";
    msg = msg + "location.href: " + location.href + "\n";
    //
    //
    msg = msg + "document.URL: " + document.URL + "\n";
    msg = msg + "document.referrer: " + document.referrer + "\n";
    msg = msg + "document.domain: " + document.domain + "\n";
    msg = msg + "document.modified: " + document.lastmodified + "\n";
    msg = msg + "document.stylesheets: " + document.styleSheets + "\n";
    msg = msg + "history.length: " + history.length + "\n";
    //
    //


    alert(msg);
}




