﻿/*****************************************************************
** Common JavaScript AJAX Library
*****************************************************************/

/* Common values for the ReadyState of the XMLHttpRequest object */
var READYSTATE_UNINITIALIZED = 0;
var READYSTATE_LOADING = 1;
var READYSTATE_LOADED = 2;
var READYSTATE_INTERACTIVE = 3;
var READYSTATE_COMPLETE = 4;
var levellbl = "Level";

/* Common values for HTTP status codes */
var HTTPSTATUS_OK = 200;


        function doClick(buttonName, e) {
            //the purpose of this function is to allow the enter key to 
            //point to the correct button to click.
            var key;

            if (window.event)
                key = window.event.keyCode;     //IE
            else
                key = e.which;     //firefox

            if (key == 13) {
                //Get the button the user wants to have clicked
                var btn = document.getElementById(buttonName);
                if (btn != null) { //If we find the button click it
                    btn.click();


                    if (!e) var e = window.event;

                    e.cancelBubble = true;
                    e.returnValue = false;

                    if (e.stopPropagation) {
                        e.stopPropagation();
                        e.preventDefault();
                    } 

                    
                    
                    /*if (window.event) {
                        //window.event.returnValue = false;
                        window.event.cancelBubble=true;
                        alert("cancelled event IE");
                    }
                    else {
                        //e.returnValue = false;
                        e.stopPropagation();
                        //e.cancelBubble = true;
                        alert("cancelled event firefox");
                    }*/
                    
                   
                }
            }

            return false;
           
        }




function newConnection() {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
        //alert("Firefox!");
    }
    catch (e) {    // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            //alert("i.e1!");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                //alert("i.e2!");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    return xmlHttp;
}

/**
* Determines version of the Acrobat Reader plugin for FireFox and Netscape
* @returns the major version of the plugin and returns null if PDF is not supported
**/
function OtherPDFVersion() {
    var version = null;
    var plugin = navigator.plugins["Adobe Acrobat"];
    if (plugin == null) return null;
    if (plugin.description == "Adobe PDF Plug-In For Firefox and Netscape") {
        version = '8.0';
    } else {
        version = plugin.description.split('Version ')[1] + '.0';
    }
    return version;
}

/**
* Determines version of the Acrobat Reader plugin for InternetExplorer
* @returns the major version of the plugin and returns null if PDF is not supported
**/
function IEPDFVersion() {
    var version = null;
    if (hasActiveXObject('AcroPDF.PDF.1')) {
        version = '7.0';
    }
    if (hasActiveXObject('PDF.PdfCtrl.1')) {
        version = '4.0';
    }
    for (var i = 2; i < 10; i++) {
        if (hasActiveXObject('PDF.PdfCtrl.' + i)) {
            version = i + '.0';
        }
    }
    return version;
}

/**
* Helper method to determine if IE contains an ActiveXObject with a given name
* @param name - the name of an ActiveXObject
* @returns true if the browser contains the ActiveXObject
**/
function hasActiveXObject(name) {
    var has = false;
    try {
        activeXObject = new ActiveXObject(name);
        if (activeXObject != null) {
            has = true;
        }
    } catch (e) {
        has = false;
    }
    return has;
}



function printWindow() {
    window.print();
}


function showPnl(divpnlid, spanbtnid, spantitleid)
{
    document.getElementById(divpnlid).style.display = "";
    document.getElementById(spanbtnid).innerHTML = "-";
    document.getElementById(spanbtnid).onclick = function() { hidePnl(divpnlid, spanbtnid, spantitleid) };
    document.getElementById(spantitleid).onclick = function() { hidePnl(divpnlid, spanbtnid, spantitleid) };
}

function hidePnl(divpnlid, spanbtnid, spantitleid) {
    document.getElementById(divpnlid).style.display = "none";
    document.getElementById(spanbtnid).innerHTML = "+";
    document.getElementById(spanbtnid).onclick = function() { showPnl(divpnlid, spanbtnid, spantitleid) };
    document.getElementById(spantitleid).onclick = function() { showPnl(divpnlid, spanbtnid, spantitleid) };
}
function setLevelLbl(levelpi) {
    levellbl = levelpi;
}

function setOpacity(myElement, opacityValue) {
    if (window.ActiveXObject) {
        myElement.style.filter = "alpha(opacity=" + (opacityValue * 100) + ")"; // IE
        //alert("Setting opacity in IE to " + (parseInt(opacityValue) * 100))
    }
    else {
        myElement.style.opacity = opacityValue; // Gecko/Opera 
    }
}

function clickBtn(btn, e) {
    //alert("here" + btn);

    // process only the Enter key
    //var e = window.event;
    if (e == null) {
        e = window.event;
    }
    if (e.keyCode == 13) {
        var theBtn = document.getElementById(btn);
        // cancel the default submit 
        e.returnValue = false;
        e.cancel = true;

        // submit the form by programmatically clicking the specified button
        //alert("The btn is " + theBtn.id);
        //window.location = document.getElementById(btn).href;
        document.getElementById(btn).click();
        //document.getElementById(btn).createEvent("click");
    }
}


function f_open_window_max(aURL, aWinName) {
    var wOpen;
    var sOptions;

    sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
    sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
    sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
    sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

    wOpen = window.open('', aWinName, sOptions);
    wOpen.location = aURL;
    wOpen.focus();
    wOpen.moveTo(0, 0);
    wOpen.resizeTo(screen.availWidth, screen.availHeight);
    return wOpen;
}

function getMaxZIndex() {
    var allElems = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all; // or test for that too
    var maxZIndex = 0;
    for (var i = 0; i < allElems.length; i++) {
        var elem = allElems[i];
        var cStyle = null;
        if (elem.currentStyle) { cStyle = elem.currentStyle; }
        else if (document.defaultView && document.defaultView.getComputedStyle) {
            cStyle = document.defaultView.getComputedStyle(elem, "");
        }
        var sNum;
        if (cStyle) {
            sNum = Number(cStyle.zIndex);
        }
        else {
            sNum = Number(elem.style.zIndex);
        }
        if (!isNaN(sNum)) {
            maxZIndex = Math.max(maxZIndex, sNum);
        }
    }
    return maxZIndex;
}

function getRandomString() {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 8;
    var randomstring = '';
    for (var i = 0; i < string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
    }
    return randomstring;
}

function getElementsByClassName(classname, node) {
    if (!node)
        node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for (var i = 0, j = els.length; i < j; i++)
        if (re.test(els[i].className)) a.push(els[i])
    return a;
}

function getFirstChildOfXmlResponse(xmlObj, valueid) {
    var returnValue = ""
    if (xmlObj.getElementsByTagName(valueid)[0].firstChild) {
        returnValue = xmlObj.getElementsByTagName(valueid)[0].firstChild.nodeValue;
    }
    return returnValue;
}

function getFirstChildOfXmlResponseNextLevel(xmlObj, valueid) {
    var returnValue = ""
    if (xmlObj.firstChild.getElementsByTagName(valueid)[0].firstChild) {
        returnValue = xmlObj.firstChild.getElementsByTagName(valueid)[0].firstChild.nodeValue;
    }
    return returnValue;
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
    if (!radioObj)
        return "";
    var radioLength = radioObj.length;
    if (radioLength == undefined)
        if (radioObj.checked)
        return radioObj.value;
    else
        return "";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
    if (!radioObj)
        return;
    var radioLength = radioObj.length;
    if (radioLength == undefined) {
        radioObj.checked = (radioObj.value == newValue.toString());
        return;
    }
    for (var i = 0; i < radioLength; i++) {
        radioObj[i].checked = false;
        if (radioObj[i].value == newValue.toString()) {
            radioObj[i].checked = true;
        }
    }
}

function setRadioButtonGroup(theid, selectvalue) {
    var value = "";

    return value;
}




function keyPressed(e) {
    var keynum;
    var keychar;
    var numcheck;

    if (window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;

    if (keynum == 8) // pressed backspace
    {
        return true;
    }
    else // pressed number?
    {
        return numcheck.test(keychar);
    }
}

//close any div
function closeDiv(divName) {
    document.getElementById(divName).style.display = "none";
    document.getElementById(divName).style.zIndex = "1";
}

// show any div ia a z index and display value, default is 99999
function showDiv(divName, zIndex) {
    if (zIndex.length < 1) {
        zIndex = "99999";
    }
    document.getElementById(divName).style.display = "";
    document.getElementById(divName).style.zIndex = zIndex;
}

//get rid of white space from end of string
function trimEnd(str) {
    return str.replace(/^\s+|\s+$/g, '');
}

//replace any illegal characters that interfere with the querystring etc
function replaceIllegalCharacters(theStr) {
    theStr = theStr.replace(/^\s+|\s+$/g, '', "g");
    theStr = theStr.replace("&nbsp;", ' ', "g");
    theStr = theStr.replace(/\u00a0/g, '');
    theStr = theStr.replace(new RegExp("&nbsp;", "g"), " ");
    theStr = theStr.replace(new RegExp("&", "g"), '%amp');
    //theStr = theStr.replace(new RegExp("\?", "g"), '%que');
    //theStr = theStr.replace("?", "%que", "g");
    theStr = theStr.replace(/\?/g, '%que');
    theStr = theStr.replace(new RegExp("@", "g"), '%at');
    theStr = theStr.replace(/\#/g, 'h%h', "g");
    theStr = theStr.replace(new RegExp("!", "g"), '%exp');
    theStr = theStr.replace(/\$/g, '%dollor');
    theStr = theStr.replace(/\£/g, '%pound');
    theStr = theStr.replace(new RegExp("\'", "g"), '%squ');
    theStr = theStr.replace(new RegExp("\"", "g"), '%dqu');
    theStr = theStr.replace(/\+/g, '%2B');
    //theStr = theStr.replace("+", "%2B", "g");
    theStr = theStr.replace(new RegExp("=", "g"), "%eq");
    //theStr = theStr.replace("=", "%eq", "g");

    //alert("removed js spaces! " + theStr)

    return theStr;

}

function addIllegalCharacters(theStr) {
    theStr = theStr.replace(/^\s+|\s+$/g, '', "g");
    theStr = theStr.replace(new RegExp("%amp", "g"), "&");
    theStr = theStr.replace(new RegExp("%que", "g"), "?");
    theStr = theStr.replace(new RegExp("%at", "g"), "@");
    theStr = theStr.replace(new RegExp("h%h", "g"), '#');
    theStr = theStr.replace(new RegExp("%exp", "g"), "!");
    theStr = theStr.replace(new RegExp("%dollor", "g"), "$");
    theStr = theStr.replace(new RegExp("%pound", "g"), "£");
    theStr = theStr.replace(new RegExp("%squ", "g"), "\'");
    theStr = theStr.replace(new RegExp("&#34;", "g"), "\"");
    theStr = theStr.replace(new RegExp("&#39;", "g"), "\'");
    theStr = theStr.replace(new RegExp("&amp;#34;", "g"), "\"");
    theStr = theStr.replace(new RegExp("&amp;#39;", "g"), "\'");
    theStr = theStr.replace(new RegExp("%dqu", "g"), "\"");
    theStr = theStr.replace(new RegExp("%2B", "g"), "+");

    return theStr;

}

//get the current browser width, this is useful for when browser windows are resized
function getBrowserWidth() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        //myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        //myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        //myHeight = document.body.clientHeight;
    }
    return myWidth;
    //window.alert( 'Height = ' + myHeight );
}

function showHelpMouseOver(helpindex, theidpl) {
    document.getElementById("helpPnl").innerHTML = mouseoverhelp[helpindex];
    document.getElementById("helpPnl").style.display = "";
    fixPosXPB("helpPnl", 80, theidpl);
    fixPosYPB("helpPnl", 40, theidpl);
}

function hideHelpMouseOut() {
    document.getElementById("helpPnl").innerHTML = "";
    document.getElementById("helpPnl").style.display = "none";
}

function expandMessagesFunc() {
    document.getElementById("messagescontentarea").style.display = "";
    document.getElementById("expandMRow").style.display = "none";
    document.getElementById("hideMRow").style.display = "";
}

function expandNotesFunc() {
    document.getElementById("notescontentarea").style.display = "";
    document.getElementById("expandNRow").style.display = "none";
    document.getElementById("hideNRow").style.display = "";
}

function hideMessagesFunc() {
    document.getElementById("messagescontentarea").style.display = "none";
    document.getElementById("expandMRow").style.display = "";
    document.getElementById("hideMRow").style.display = "none";
}

function hideNotesFunc() {
    document.getElementById("notescontentarea").style.display = "none";
    document.getElementById("expandNRow").style.display = "";
    document.getElementById("hideNRow").style.display = "none";
}

//fixes the element(theElementID) a set  x distance(ex) away from a element anchor(positionWith)
function fixPosXPB(theElementID, ex, positionWith) {

    //try {
        var theElement = document.getElementById(theElementID);
        var obj = document.getElementById(positionWith);
        var curleft = 0;

        if (obj.offsetParent) {
            while (obj.offsetParent) {
                if (obj.offsetParent) {
                    curleft += obj.offsetLeft
                    obj = obj.offsetParent;
                }
            }
        }
        else if (obj.x) {
            curleft += obj.x;
        }

        theElement.style.left = (parseInt(curleft) + parseInt(ex) - ((parseInt(getBrowserWidth()) - 800) / 2)) + "px";
    /*}
    catch (ex) {

    }*/
}

//fixes the element(theElementID) a set  y distance(ey) away from a element anchor(positionWith)
function fixPosYPB(theElementID, ey, positionWith) {
    //try {
        var theElement = document.getElementById(theElementID);
        var obj = document.getElementById(positionWith);
        var curtop = 0;

        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curtop += obj.offsetTop
                obj = obj.offsetParent;
            }
        }
        else if (obj.y)
            curtop += obj.y;

        theElement.style.top = (parseInt(curtop) + parseInt(ey)) + "px";

    //}
    /*catch (ex) {

    }*/

}

//builds a ajax connection to the server
function buildPostConnection(url, params) {
    var xmlHttp;
    xmlHttp = newConnection();
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    return xmlHttp;
}

//delete a option from a set listbox
function deleteOption(selectObject, theIndex) {
    if (selectObject.options.length != 0) {
        selectObject.options[theIndex] = null;
    }
}

//set the current selection from a listbox when the list box contains only numbers 
function selectCurrentIndexNumber(objectClientID, theValue) {
    try {
        for (i = 0; i < parseInt(document.getElementById(objectClientID).options.length); i++) {
            if (parseInt(theValue) == parseInt(document.getElementById(objectClientID).options[i].value)) {
                document.getElementById(objectClientID).selectedIndex = i;
                break;
            }
        }
    }
    catch (exc) {
        alert("Error with " + objectClientID)
    }
}

//set the current selection from a listbox when the list box contains only strings
function selectCurrentIndexString(objectClientID, theValue) {
    //alert(objectClientID);
    for (i = 0; i < parseInt(document.getElementById(objectClientID).options.length); i++) {
        if (theValue.replace(/^\s+|\s+$/g, '') == document.getElementById(objectClientID).options[i].value.replace(/^\s+|\s+$/g, '')) {
            document.getElementById(objectClientID).selectedIndex = i;
           
            break;
        }
        /*if (objectClientID == "courseinformation-levelddl") {
            alert("value passed in for " + objectClientID + "  is " + theValue.replace(/^\s+|\s+$/g, '') + " --> " + document.getElementById(objectClientID).options[i].value.replace(/^\s+|\s+$/g, ''));
        }*/
    }
}

//get selectedIndex
function getSelectedIndex(objectClientID) {
    return document.getElementById(objectClientID).selectedIndex;
}

function addOption(selectboxID, text, value) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    if (document.getElementById(selectboxID)) {
        document.getElementById(selectboxID).options.add(optn);
    }
}

function clearSelectBox(selectbox) {

    /*for (i=document.getElementById(selectbox).options.length-1; i>=0; i--)
    {
    document.getElementById(selectbox).removeChild(document.getElementById(selectbox).options[i]);
    }*/
    document.getElementById(selectbox).options.length = 0;
    //alert("length is " + document.getElementById(selectbox).options.length);

}


//check a email address is valid pass in either email address or a pointer to element with email address in
// if byvalue is set to true then its the actual email address passed in else its the element pointer.
function validEmail(emailAddrID, byvalue)	//---------validEmail()------------checks email validity---------------
{
    var error = false;
    var errorString = "";
    var email = ""
    if (byvalue) {
        email = emailAddrID;
    }
    else {
        email = document.getElementById(emailAddrID).value;
    }

    invalidChars = "/:,; ";
    if (email == "")//email not entered
    {
        errorString = "You have not entered any email address.\n";
        error = true;
    }

    for (i = 0; i < invalidChars.length; i++)//checks for the invalid characters
    {
        badChar = invalidChars.charAt(i)
        if (email.indexOf(badChar, 0) > -1) {
            if (badChar == ' ') {

                errorString = errorString + "Error: Email must not contain spaces.\n";
                error = true;
            }
            else
                errorString = errorString + "Error: Email must not contain the character: ' " + badChar + " '.\n";
            error = true;
        }
    }

    atPos = email.indexOf("@", 1); //checks position
    if (atPos == -1) {
        errorString = errorString + "Email Error: Misplaced ' @ ' symbol.\n";
        error = true;
    }
    if (email.indexOf("@", atPos + 1) != -1)//checks pos
    {
        errorString = errorString + "Email Error: Misplaced ' @ ' symbol.\n";
        error = true;
    }
    periodPos = email.indexOf(".", atPos)//checks point for .provider
    if (periodPos == -1) {
        errorString = errorString + "Email Error: Misplaced ' . ' symbol.\n";
        error = true;
    }
    if (periodPos + 3 > email.length)//checks length of provider atleast 3 as standard
    {
        errorString = errorString + "Email Error: Error with right hand side of address.\n";
        error = true;
    }
    if (error) {
        alert(errorString + "Please correct.");
        return false;
    }
    for (i = 0; i < email.length; i++)//checks for 'www' in email address
        if (email.charAt(i) == 'w' && email.charAt(i + 1) == 'w' && email.charAt(i + 2) == 'w' && wwwCheck == true) {
        if (confirm("Caution: WWW is for surfing the web, it is not usually part of an email address.\nClick OK to confirm or cancel to correct address.") == false) {
            return false;
        }
        else
            wwwCheck = false;
    }

    return true;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function unselectselct(selectClientID) {
    var element = document.getElementById(selectClientID);

    var allElements = element.getElementsByTagName("OPTION");
    for (var i = 0; i < allElements.length; i++) {
        var testElement = allElements[i];
        testElement.selected = false;
    }
}


function checkPostCode(postcodeID, byvalue) { //---------------------check postcode format is valid----------------------
    var test = ""
    if (byvalue) {
        test = postcodeID;
    }
    else {
        test = document.getElementById(postcodeID).value;
    }
    test = document.form1.sPostcode.value; size = test.length
    test = test.toUpperCase(); //Change to uppercase
    while (test.slice(0, 1) == " ") //Strip leading spaces
    {
        test = test.substr(1, size - 1); size = test.length
    }
    while (test.slice(size - 1, size) == " ") //Strip trailing spaces
    {
        test = test.substr(0, size - 1); size = test.length
    }
    document.form1.sPostcode.value = test; //write back to form field
    if (size < 6 || size > 8) { //Code length rule
        alert(test + " is not a valid UK postcode - wrong length");
        return false;
    }
    if (!(isNaN(test.charAt(0)))) { //leftmost character must be alpha character rule
        alert(test + " is not a valid UK postcode - cannot start with a number");
        return false;
    }
    if (isNaN(test.charAt(size - 3))) { //first character of inward code must be numeric rule
        alert(test + " is not a valid UK postcode - alpha character in wrong position");
        return false;
    }
    if (!(isNaN(test.charAt(size - 2)))) { //second character of inward code must be alpha rule
        alert(test + " is not a valid UK postcode - number in wrong position");
        return false;
    }
    if (!(isNaN(test.charAt(size - 1)))) { //third character of inward code must be alpha rule
        alert(test + " is not a valid UK postcode - number in wrong position");
        return false;
    }
    if (!(test.charAt(size - 4) == " ")) {//space in position length-3 rule
        alert(test + " is not a valid UK postcode - no space or space in wrong position");
        return false;
    }
    count1 = test.indexOf(" "); count2 = test.lastIndexOf(" ");
    if (count1 != count2) {//only one space rule
        alert(test + " is not a valid UK postcode - only one space allowed");
        return false;
    }
    return true;
}

function capitalise()//-------This function capitalizes the first character of every word in a string---
{
    var htext, nhtext, mcFound, slashFound, hyphFound, slash1, slash2, hyph1, hyph2;
    var htext = inputString;
    j = htext.length;
    nhtext = "";
    for (i = 0; i < j; i++) {
        if (htext.charAt(i) == "M" && htext.charAt(i + 1) == "c" && (htext.charCodeAt(i + 2) > 64 && htext.charCodeAt(i + 2) < 91))//Checks for the Scotich McDonald type of text
        {
            mcFound = true;
        }
        if (htext.charAt(i) == "-" && (htext.charCodeAt(i + 1) > 64 && htext.charCodeAt(i + 1) < 91))//checks for capital after a slash
        {
            slashFound = true;
            slash1 = i;
        }
        if (htext.charAt(i) == "'" && (htext.charCodeAt(i + 1) > 64 && htext.charCodeAt(i + 1) < 91))//checks for capital after a hyphen
        {
            hyphFound = true;
            hyph1 = i;
        }
    }

    htext = htext.toLowerCase(); 			// changes string to lower case
    for (i = 0; i < j; i++) {
        if (i == 0)	// capitalize the first character.
        {
            nhtext = nhtext + htext.substr(i, 1).toUpperCase();
        }
        else if (htext.charAt(i) == " ")// looks for a space
        {
            nhtext = nhtext + htext.substr(i, 1); // Adds that space character to the new string
            nhtext = nhtext + htext.substr(++i, 1).toUpperCase(); // Capitalizes and adds the next character
        }
        else if (htext.charAt(i) == "")	// Checks for the appearance of the newline	character.
        {
            nhtext = nhtext + htext.substr(i, 1); // Adds the newline character to the string.
            nhtext = nhtext + htext.substr(++i, 1).toUpperCase(); // Capitalizes and adds the next character 
        }
        else {
            nhtext = nhtext + htext.substr(i, 1); // Adds the character in a normal way.
        }
        if (slashFound && i == slash1 || slashFound && i == slash2)//if string has slash then capital letter
        {
            nhtext = nhtext + htext.substr(++i, 1).toUpperCase(); // Capitalizes and adds the next character			
        }
        if (htext.charAt(i) == "'")// looks for a single quote
        {
            if (!(htext.charAt(i + 1) == "'" || htext.charAt(i - 1) == "'")) {
                nhtext = nhtext + "'"; //Adds another quote only if not already added
                if (hyphFound && i == hyph1 || hyphFound && i == hyph2)//if string has hyphen then capital letter
                {
                    nhtext = nhtext + htext.substr(++i, 1).toUpperCase(); // Capitalizes and adds the next character		
                }
            } 													//if already converted
            else if (hyphFound && i == hyph1 || hyphFound && i == hyph2)//if string has hyphen then capital letter
            {
                nhtext = nhtext + htext.substr(++i, 1).toUpperCase(); // Capitalizes and adds the next character		
            }
        }
    }
    if (mcFound > 0) {
        var shtext;
        shtext = nhtext;
        j = shtext.length;
        nhtext = "";
        for (i = 0; i < j; i++) {
            if (shtext.charAt(i) == "M" && shtext.charAt(i + 1) == "c")//Checks for the Scotich McDonald type of text
            {
                nhtext = nhtext + "Mc" + shtext.charAt(i + 2).toUpperCase();
                i = i + 2;
            }
            else
                nhtext = nhtext + shtext.charAt(i);
        }
    }
    inputString = nhtext;
}


/*
Copyright Robert Nyman, http://www.robertnyman.com
Free to use if this text is included
*/
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue) {
    var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var oAttributeValue = (typeof strAttributeValue != "undefined") ? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
    var oCurrent;
    var oAttribute;
    for (var i = 0; i < arrElements.length; i++) {
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
        if (typeof oAttribute == "string" && oAttribute.length > 0) {
            if (typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))) {
                arrReturnElements.push(oCurrent);
            }
        }
    }
    return arrReturnElements;
}

/*function getCheckedValue(radioObj) {
    if (!radioObj)
        return "";
    var radioLength = radioObj.length;
    if (radioLength == undefined)
        if (radioObj.checked)
        return radioObj.value;
    else
        return "";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

function setCheckedValue(radioObj, newValue) {
    if (!radioObj)
        return;
    var radioLength = radioObj.length;
    if (radioLength == undefined) {
        radioObj.checked = (radioObj.value == newValue.toString());
        return;
    }
    for (var i = 0; i < radioLength; i++) {
        radioObj[i].checked = false;
        if (radioObj[i].value == newValue.toString()) {
            radioObj[i].checked = true;
        }
    }
}*/








