﻿function handleParent(parentId)
//shows / hides named divisions
{
    show = document.getElementById("show" + parentId)
    hide = document.getElementById("hide" + parentId)
    list = document.getElementById("list" + parentId)

    if (list.style.display == "none") {
        list.style.display = "block"
        show.style.display = "none"
        hide.style.display = "inline"
    } else {
        list.style.display = "none"
        show.style.display = "inline"
        hide.style.display = "none"
    }
}


function showArticle(ArticleID) {
    //shows / hides named divisions
    var doc = document.getElementsByName('article');
    alert(doc.length);
    for (var i = 0; i < doc.length; i++) {
        //   //Do Work on doc[i], this sets the border of the Div black

        //        if (Left(doc[i].id, 3) = 'Div') {
        if (doc[i].id=="Article"+ArticleID) {
            doc.style.display != "none";
        }
        doc.style.display = "block";
    }
}

function clientSideInclude(id, url) {
    var req = false;
    // For Safari, Firefox, and other non-MS browsers
    if (window.XMLHttpRequest) {
        try {
            req = new XMLHttpRequest();
        } catch (e) {
            req = false;
        }
    } else if (window.ActiveXObject) {
        // For Internet Explorer on Windows
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                req = false;
            }
        }
    }
    var element = document.getElementById(id);
    if (!element) {
        alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
        return;
    }
    if (req) {
        // Synchronous request, wait till we have it all
        req.open('GET', url, false);
        req.send(null);
        element.innerHTML = req.responseText;
    } else {
        element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
    }
}



////////////////////////////////////////////////// General String Functions ///////////////////////////////////////////////////        
function Left(str, n)
/***
IN: str - the string we are LEFTing
n - the number of characters we want to return

RETVAL: n characters from the left side of the string
***/
{
    if (n <= 0)     // Invalid bound, return blank string
        return "";
    else if (n > String(str).length)   // Invalid bound, return
        return str;                // entire string
    else // Valid bound, return appropriate substring
        return String(str).substring(0, n);
}

function Len(str)
/***
IN: str - the string whose length we are interested in

RETVAL: The number of characters in the string
***/
{ return String(str).length; }


function Right(str, n)
/***
IN: str - the string we are RIGHTing
n - the number of characters we want to return

RETVAL: n characters from the right side of the string
***/
{
    if (n <= 0)     // Invalid bound, return blank string
        return "";
    else if (n > String(str).length)   // Invalid bound, return
        return str;                     // entire string
    else { // Valid bound, return appropriate substring
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}

function Mid(str, start, len)
/***
IN: str - the string we are LEFTing
start - our string's starting position (0 based!!)
len - how many characters from start we want to get

RETVAL: The substring from start to start+len
***/
{
    // Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";

    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
        iEnd = iLen;
    else
        iEnd = start + len;

    return String(str).substring(start, iEnd);
}


// Keep in mind that strings in JavaScript are zero-based, so if you ask
// for Mid("Hello",1,1), you will get "e", not "H".  To get "H", you would
// simply type in Mid("Hello",0,1)

// You can alter the above function so that the string is one-based.  Just
// check to make sure start is not <= 0, alter the iEnd = start + len to
// iEnd = (start - 1) + len, and in your final return statement, just
// return ...substring(start-1,iEnd)


// InStr function written by: Steve Bamelis - steve.bamelis@pandora.be

function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
was found in the string str.  (If the character is not
found, -1 is returned.)
                               
Requires use of:
Mid function
Len function
*/
{
    for (i = 0; i < Len(strSearch); i++) {
        if (charSearchFor == Mid(strSearch, i, 1)) {
            return i;
        }
    }
    return -1;
}

//--------------------------------------------- END General String Functions ---------------------------------------------//


