// This file contains common javascript functions needed throughout the product

// This function opens a popup window with a particular HTML page in it.
function openWindow(page) {
    var msie=false;
    var appName=navigator.appName;
    if(appName.indexOf("Microsoft")==0) {
        msie=true;
    }
    helpWindow=window.open(page, "helpWindow", "width=505,height=360,resizable=yes,menubar=no,scrollbars=yes,toolbar=no,location=no");
    if(!msie) {
        helpWindow.focus();
    }
}

function openRaisedWindow(page) {
    var msie=false;
    var appName=navigator.appName;
    if(appName.indexOf("Microsoft")==0) {
        msie=true;
    }
    helpWindow=window.open(page, "helpWindow", "width=505,height=360,resizable=yes,menubar=no,scrollbars=yes,toolbar=no,location=no,alwaysraised=yes");
    if(!msie) {
        helpWindow.focus();
    }
}

// This function displays a bible reference in a new window
function showBibleRef(verse,version) {

    if (!version) {
        url = 'http://bible.gospelcom.net/cgi-bin/bg?version=KJV&passage=' + verse
    } else {
        url = 'http://bible.gospelcom.net/cgi-bin/bg?version=' + version + '&passage=' + verse
    }

    openWindow(url,'505','360','yes')

}

function getRadioButtonValue (radio) {

    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) { break }
    }
    return radio[i].value
}

function getPullDownValue (pullDown)
{
    for (var i = 0; i < pullDown.length; i++) {
        if (pullDown[i].selected) { break }
    }
    return pullDown[i].value
}

// This function pops open a new window that displays the help page for the page that the user is on.
function displayHelpWindow(u)
{

    page = u.pathname.split(".");
    page = page[0].split("/");

    switch(page[1]) {
        case "index":
                openWindow('/help/indexHelp.html','505','360','yes')
                break;
        default:
                openWindow('/help/noHelp.html','505','360','yes')
                break;
    }
}

//
function showFeedbackForm() {

    top.location.href = "/feedBackForm.html";
    this.window.close();
}

function checkEmail(email,checkbox)
{
    if (checkbox.checked)
    {
        if ( email === "" )
        {
            alert("Nothing Entered!")
            checkbox.checked = 0;
        }
        else
        {
            alert("An email message will open in your email client window.\n\nPlease send this email to the address that you entered and verify that the recipient receives it as intended.\n\nIf they do not, then please modify the text in the Email field and verify the information again.\n\nPlease note:  email is not instantaneous and it may take a few minutes (or even hours, sometimes) for your recipient to receive this email.")
            parent.location.href='mailto:'+email+'?subject=BibleNet Email Verification';
            checkbox.checked = 0;
        }
    }
}

function checkURL(url,checkbox)
{
    if (checkbox.checked)
    {
        if ( url === "http://" )
        {
            alert("Nothing Entered!")
            checkbox.checked = 0;
        }
        else
        {
            alert("Another browser window will now open pointing to the page that you indicated.\n\nPlease verify that the page that opens is what you intended.\n\nIf it is not, then please modify the text in the URL field and verify the information again.")
            openWindow(url)
            checkbox.checked = 0;
        }
    }
}

/* ---------------------------------------
   author: Vincent Puglia, GrassBlade Software
   site:   http://members.aol.com/grassblad
------------------------------------------- */
function selectAll(formObj, isSelected) {

    for (var i=0; i < formObj.length; i++) {

      fldObj = formObj.elements[i];

      if (fldObj.type == 'checkbox')  { 

         if(isSelected) {

            fldObj.checked = true;

         } else {

            fldObj.checked = false; 

         }

      }
   }
}

function queryAmazon(cdName, checkbox)
{

    if (checkbox.checked)
    {
        if ( cdName === "" )
        {
            alert("No CD Name Entered!")
            checkbox.checked = 0;
        }
        else
        {
            amazonURL = "searchAmazon.html?cdName='" + cdName + "'"

            openWindow(amazonURL)
            checkbox.checked = 0;
        }
    }
}

function checkASIN(asin,checkbox)
{
    if (checkbox.checked)
    {
        if ( asin === "" )
        {
            alert("No ASIN Number Entered!")
            checkbox.checked = 0;
        }
        else
        {
            amazonURL = "http://www.amazon.com/exec/obidos/ASIN/" + asin + "/biblenet"
            openWindow(amazonURL)
            checkbox.checked = 0;
        }
    }
}
