
blnDOM = (document.getElementById) ? true : false;
blnNS4 = (document.layers) ? true : false;
blnIE = (document.all) ? true : false;
blnIE4 = blnIE && !blnDOM;
blnIE5 = (navigator.appVersion.indexOf("MSIE 5.0") != -1);
blnNS6 = blnDOM && !blnIE;
blnMac = (navigator.appVersion.indexOf("Mac") != -1);
blnOpera = (navigator.userAgent.indexOf("Opera")!=-1);
blnKonqueror = (navigator.userAgent.indexOf("Konqueror")!=-1);


function loginToggle(element, imageName) {
	element.style.background = "url(" + imageName + ") top left no-repeat";
}

//Swap images with an optional fade effect
var transitionToggle = 0;

function imgToggle(id,name,transitionDisable)
	{
	if (transitionDisable || !document.images[id].filters || blnIE5 || blnNS4)
		{
		if (document.images)
			{
			document.images[id].src=eval(name+".src");
			}
		}
	else
		{
		document.images[id].filters[0].Apply();
		// After setting Apply, changes to the object
		// are not displayed until Play is called.

		if (transitionToggle)
			{
			transitionToggle = 0;
			document.images[id].src=eval(name+".src");
			}
		else
			{
			transitionToggle = 1;
			document.images[id].src=eval(name+".src");
			}
		document.images[id].filters[0].Play();
		}
	}

if (document.images)
	{
	b_this_month_off = new Image();b_this_month_off.src = '/images/templates/b_this_month.gif';
	b_this_month_on = new Image();b_this_month_on.src = '/images/templates/b_this_month_on.gif';

	b_last_month_off = new Image();b_last_month_off.src = '/images/templates/b_last_month.gif';
	b_last_month_on = new Image();b_last_month_on.src = '/images/templates/b_last_month_on.gif';

	b_go_off = new Image();b_go_off.src = '/images/templates/b_go_off.gif';
	b_go_on = new Image();b_go_on.src = '/images/templates/b_go_on.gif';

	b_latest_movies_off = new Image();b_latest_movies_off.src = '/images/templates/b_latest_movies.gif';
	b_latest_movies_on = new Image();b_latest_movies_on.src = '/images/templates/b_latest_movies_on.gif';

	b_latest_games_off = new Image();b_latest_games_off.src = '/images/templates/b_latest_games.gif';
	b_latest_games_on = new Image();b_latest_games_on.src = '/images/templates/b_latest_games_on.gif';

	b_about_civic_video_off = new Image();b_about_civic_video_off.src = '/images/templates/b_about_civic_video.gif';
	b_about_civic_video_on = new Image();b_about_civic_video_on.src = '/images/templates/b_about_civic_video_on.gif';

	b_competitions_off = new Image();b_competitions_off.src = '/images/templates/b_competitions.gif';
	b_competitions_on = new Image();b_competitions_on.src = '/images/templates/b_competitions_on.gif';

	b_store_locations_off = new Image();b_store_locations_off.src = '/images/templates/b_store_locations.gif';
	b_store_locations_on = new Image();b_store_locations_on.src = '/images/templates/b_store_locations_on.gif';

	b_contact_civic_video_off = new Image();b_contact_civic_video_off.src = '/images/templates/b_contact_civic_video.gif';
	b_contact_civic_video_on = new Image();b_contact_civic_video_on.src = '/images/templates/b_contact_civic_video_on.gif';
	
	n_moviesdb = new Image();n_moviesdb.src = '/images/templates/n_moviesdb.gif';
	n_moviesdb_on = new Image();n_moviesdb_on.src = '/images/templates/n_moviesdb_on.gif';
	n_latestgames_off = new Image();n_latestgames_off.src = '/images/templates/n_latestgames.gif';
	n_latestgames_on = new Image();n_latestgames_on.src = '/images/templates/n_latestgames_on.gif';
	n_civicinteractive_off = new Image();n_civicinteractive_off.src = '/images/templates/n_civicinteractive.gif';
	n_civicinteractive_on = new Image();n_civicinteractive_on.src = '/images/templates/n_civicinteractive_on.gif';
	n_aboutcivicvideo_off = new Image();n_aboutcivicvideo_off.src = '/images/templates/n_aboutcivicvideo.gif';
	n_aboutcivicvideo_on = new Image();n_aboutcivicvideo_on.src = '/images/templates/n_aboutcivicvideo_on.gif';
	n_compsandpromos_off = new Image();n_compsandpromos_off.src = '/images/templates/n_compsandpromos.gif';
	n_compsandpromos_on = new Image();n_compsandpromos_on.src = '/images/templates/n_compsandpromos_on.gif';
	n_storelocations_off = new Image();n_storelocations_off.src = '/images/templates/n_storelocations.gif';
	n_storelocations_on = new Image();n_storelocations_on.src = '/images/templates/n_storelocations_on.gif';

	}
	
// ##################
// Browser Detection
// ##################

// Note: Browser detection may be outside this file if
// site is heavily JS driven and different JS files are
// loaded for each browser (e.g. separate DOM / NS / IE
// files)

DOM = (document.getElementById) ? true : false;
NS4 = (document.layers) ? true : false;						//Netscape 4 specifically
NS6 = (!document.all && document.getElementById) ? 1 : 0;	//Netscape 6 & 7
IE = (document.all) ? true : false;							//Any IE
IE4 = IE && !DOM;											//IE4 specifically
IE5 = (IE4 && navigator.appVersion.indexOf("5.") != -1);	//Any IE 5 series
IE50 = (navigator.appVersion.indexOf("MSIE 5.0") != -1);	//IE5.0 specifically
ver4 = (NS4 || IE4 || DOM);									//Version 4 or ABOVE
isMac = (navigator.appVersion.indexOf("Mac") != -1);		//Any Mac browser
isDynamic = (DOM || NS4 || NS6 || (IE4 && !isMac) || (IE5 && isMac));
															//Any browsing supporting dHTML (Apparently... This may need work!)
canPrint = (window.print) ? 1 : 0;


// ##################
// Navigation
// ##################

function goThere(frmName,fdName)
	{
	WhichOne = document[frmName].elements[fdName].options.selectedIndex
	URL = document[frmName].elements[fdName].options[WhichOne].value
	document[frmName].elements[fdName].options.selectedIndex = 0
	if (URL != "")
		{
		location.href = URL
		}
	}

// ##################
// Windows & Alerts
// ##################

function wPopup(wPage,wWidth,wHeight,wID,wScrollbars,wLocation,wToolbar,wStatus,wResizable) {
	if (!wID) {wID = "Popup"}
	if (!wWidth) {wWidth = 500}
	if (!wHeight) {wHeight = 320}
	if (!wScrollbars) {wScrollbars = "yes"}
	if (!wLocation) {wLocation = "no"}
	if (!wToolbar) {wToolbar = "no"}
	if (!wStatus) {wStatus = "no"}
	//if (isLoaded == 0) { location.reload() }
	if (!wResizable) {wResizable = "yes"}
	popupWindow = window.open(wPage,wID,"width="+wWidth+",height="+wHeight+",scrollbars="+wScrollbars+",location="+wLocation+",toolbar="+wToolbar+",status="+wStatus+",resizable="+wResizable)
	if (window.focus) { popupWindow.focus() }
}

function wLink(URL)
	{
	top.opener.location.href = URL
	top.close()
	}

// ##################
// Image Manipulation
// ##################

// Swap any image to another
function imgSwap(id,name)
	{
	if (document.images)
		{
		document.images[id].src=eval(name+".src");
		}
	}

// Swap images with an optional fade effect
// - Requires fading style to be set.
// - Only works for IE5.5+ but falls back nicely
var transitionToggle = 0;
function imgSwapFX(id,name,transitionDisable)
	{
	if (transitionDisable || !document.images[id].filters || IE50)
		{
		if (document.images)
			{
			document.images[id].src=eval(name+".src");
			}
		}
	else
		{
		document.images[id].filters[0].Apply();
		// After setting Apply, changes to the object
		// are not displayed until Play is called.

		if (transitionToggle)
			{
			transitionToggle = 0;
			document.images[id].src=eval(name+".src");
			}
		else
			{
			transitionToggle = 1;
			document.images[id].src=eval(name+".src");
			}
		document.images[id].filters[0].Play();
		}
	}

// ##################
// Layer Manipulation
// ##################


// Turn any layer on and off
function layerToggle(togglelayer,state)
	{
	if (document.layers)
		{
		if (document.layers[togglelayer])
			{
			document.layers[togglelayer].visibility = state
			}
		}
	else if (document.getElementById)
		{
		if (document.getElementById(togglelayer))
			{
			document.getElementById(togglelayer).style.visibility = state
			}
		}
	else
		{
		if (document.all[togglelayer])
			{
			document.all[togglelayer].style.visibility = state
			}
		}
	}


// Turn any layer on and off
function layerToggleDisplay(togglelayer,state)
	{
	if (document.layers)
		{
		if (document.layers[togglelayer])
			{
			document.layers[togglelayer].display = state;
			}
		}
	else if (document.getElementById)
		{
		if (document.getElementById(togglelayer))
			{
			document.getElementById(togglelayer).style.display = state;
			}
		}
	else
		{
		if (document.all[togglelayer])
			{
			document.all[togglelayer].style.display = state;
			}
		}
	}

// ##################
// Printing
// ##################

if (IE4 && !canPrint && !isMac) with (document)
	{
	writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
	writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
	writeln('Sub window_onunload');
	writeln('    On Error Resume Next');
	writeln('    Set WB = nothing');
	writeln('End Sub');
	writeln('Sub vbPrintPage');
	writeln('    OLECMDID_PRINT = 6');
	writeln('    OLECMDEXECOPT_DONTPROMPTUSER = 2');
	writeln('    OLECMDEXECOPT_PROMPTUSER = 1');
	writeln('    On Error Resume Next');
	writeln('    WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
	writeln('End Sub');
	writeln('<' + '/SCRIPT>');
	}

function printPage()
	{
	if (canPrint)
		{
		window.print()
		}
	else if (IE4 && !isMac)
		{
		vbPrintPage()
		}
	else
		{
		alert("Your web browser does not appear to support the automatic\nPrint function. To print this page, please select the \"Print\"\noption from the \"File\" menu of your web browser.")
		}
	}

// ##################
// Interface Functions
// ##################

// Alternating table row colours. (Define two or more colours.)
var arrTableRowColors = new Array('#f8f8f8','#ffffff');

// Various table attributes
// These should be set within an interface definition file (i.e. like a style
// sheet) but must be set here otherwise.
//var arrTableRowColors = new Array('#eeeeee','#ffffff');
//var arrOtherAttributes = new Array('value1','value2');
function SetTableRowAttributes(strRowID, i)
{
	if(!arrTableRowColors)
	{
		arrTableRowColors = new Array('#eeeeee','#ffffff');
	}
	if(arrTableRowColors)
	{
		strRowID.style.backgroundColor = arrTableRowColors[i % arrTableRowColors.length];
		//strRowID.style.OtherAttribute = arrOtherAttributes[i % arrOtherAttributes.length];
	}
}

// Paint table rows in a table with 
function PaintTableRows(strTableID)
{
	var objTable = document.getElementById(strTableID);
	var arrTableRows = objTable.getElementsByTagName("tr");

	// Keep track of how far through the attribute array we've come
	intAttributeCounter = 0;
	
	for(i = 0; i < arrTableRows.length; i++)
	{
		// Only process table rows that are direct children of the 
		// requested table. This accounts for embedded tables. Use a
		// double "parentNode" to account for the TBODY element.
		if (arrTableRows[i].parentNode.parentNode.id == strTableID)
		{
			if (arrTableRows[i].className != "")
			{
				// Class name is not blank. This row must be
				// special (e.g. a header) so we'll skip it
				// and reset the attribute counter to 0.
				intAttributeCounter = 0;
			}
			else
			{
				// Alter the row attributes
				SetTableRowAttributes(arrTableRows[i], intAttributeCounter);
				
				// Increment the attribute counter
				intAttributeCounter++;
				if (intAttributeCounter > arrTableRows.length)
				{
					intAttributeCounter = 0;
				}
			}
		}
	}
}

// ====================
// Function:    GetObjectWidth
//
// Purpose:     Returns the width of any passed in block level object
//
// Input:       ID of item
//
// Output:      Returns the width of any passed in block level object
//
// Assumptions: -
//
// History:     SC 2006-05-15
// ====================
function GetObjectWidth(objectRef)
{
	var intWidth = -1;

	if (document.getElementById)
	{
		if (document.getElementById(objectRef))
		{
			intWidth = eval(document.getElementById(objectRef).offsetWidth);
		}
	}
	else if (document.all)
	{
		if (document.all[objectRef])
		{
			intWidth = document.all[objectRef].scrollWidth;
		}
	}
	else if (document.layers)
	{
		if (document[objectRef])
		{
			intWidth = document[objectRef].clip.bottom;
		}
	}

	return intWidth;
}

// ====================
// Function:    GetObjectHeight
//
// Purpose:     Returns the height of any passed in block level object
//
// Input:       ID of item
//
// Output:      Returns the height of any passed in block level object
//
// Assumptions: -
//
// History:     SC 2006-05-15
// ====================
function GetObjectHeight(objectRef)
{
	var intHeight = -1;

	if (document.getElementById)
	{
		if (document.getElementById(objectRef))
		{
			intHeight = eval(document.getElementById(objectRef).offsetHeight);
		}
	}
	else if (document.all)
	{
		if (document.all[objectRef])
		{
			intHeight = document.all[objectRef].scrollHeight;
		}
	}
	else if (document.layers)
	{
		if (document[objectRef])
		{
			intHeight = document[objectRef].clip.bottom;
		}
	}

	return intHeight;
}

// ##################
// Fun Stuff / Easter Eggs
// ##################

// No easter eggs currently present. :-)

// ####################################
// ##
// ##  Form Handling
// ##
// ####################################

// ====================
// Function:    OtherOptionSwitch
//
// Input:
//              -   strOtherOptionTagId
//              -   objTag
//
// Assumptions:
//              -   cm3 version 5.5.3 or up is used
//
// History:
//              -   20090827 GR Created
//              -   20091020 RW Completely re-wrote from SelectOtherOption ;)
// ====================

// function run when "other" radio or dropdown options are selected or "other" checkbox clicked (either checked or unchecked)
function OtherOptionSwitch(strOtherOptionTagId, objTag) {
    objOtherOptionTag = document.getElementById(strOtherOptionTagId);
    strOtherOptionClassName = objOtherOptionTag.className;
    strSelectControlTagId = strOtherOptionTagId + "Enable";
    objSelectControlTag = document.getElementById(strSelectControlTagId);
    if (objSelectControlTag) {
        if (objSelectControlTag.tagName == "OPTION") { // Dropdown (or multiselect, but only dropdowns are available in surveys for now)
            if (objTag[objTag.selectedIndex].id == objSelectControlTag.id) { // Relies on the option being a child of objTag
                OtherOptionShowText(strOtherOptionTagId);
            } else {
                OtherOptionDeselect(strOtherOptionTagId, objOtherOptionTag);
            }
        } else { // Radio or checkbox
            if (objSelectControlTag.checked) {
                OtherOptionShowText(strOtherOptionTagId);
            } else {
                OtherOptionDeselect(strOtherOptionTagId, objOtherOptionTag);
            }
        }
    }
}

// function run when any "standard" radio or dropdown options are selected
function OtherOptionDeselect(strOtherOptionTagId, objTag) {
    objOtherOptionTag = document.getElementById(strOtherOptionTagId);
    strOtherOptionClassName = objOtherOptionTag.className;
    strSelectControlTagId = strOtherOptionTagId + "Enable";
    objSelectControlTag = document.getElementById(strSelectControlTagId);

    // Hide the text box if this is a "SelectTextHidden" option
    // Note: There could be multiple classes on the object
    if (strOtherOptionClassName.indexOf("otherOptionSelectTextHidden") != -1) {
        if (objSelectControlTag.tagName == "OPTION") {
            //alert("otherOptionSelectTextHidden");
        }
        OtherOptionHideText(strOtherOptionTagId);
    } else if (strOtherOptionClassName.indexOf("otherOptionSelectTextVisible") != -1) {
        if (objSelectControlTag.tagName == "OPTION") {
            //alert("otherOptionSelectTextVisible");
        }
        OtherOptionBlankText(objOtherOptionTag);
    }
}

// Function called after div with "other" options loaded.
function OtherOptionLoad(strOtherOptionTagId) {
    strFieldTagId = strOtherOptionTagId.substring(0, strOtherOptionTagId.indexOf("Other"));
    OtherOptionSwitch(strOtherOptionTagId, document.getElementById(strFieldTagId));

    //objOtherOptionTag = document.getElementById(strOtherOptionTagId);
    //strOtherOptionClassName = objOtherOptionTag.className;
    //strSelectControlTagId = strOtherOptionTagId + "Enable";
    //objSelectControlTag = document.getElementById(strSelectControlTagId);

    // Hide the text box if this is a "SelectTextHidden" option
    //if (strOtherOptionClassName == "otherOptionSelectTextHidden") {
    //    if (objSelectControlTag && objSelectControlTag.tagName == "INPUT") { // Radio or checkbox
    //        if (objSelectControlTag.checked) {
    //            OtherOptionShowText(strOtherOptionTagId);
    //        } else {
    //            OtherOptionHideText(strOtherOptionTagId);
    //        }
    //    } else if (objSelectControlTag && objSelectControlTag.tagName == "SELECT") { // Dropdown
    //    }
    //}
}

function OtherOptionHideText(strOtherOptionTagId) {
    objOtherOptionTag = document.getElementById(strOtherOptionTagId);
    strOtherOptionClassName = objOtherOptionTag.className;
    arrOptionTextContainers = getElementsByClassName("otherOptionText", "div", objOtherOptionTag);
    for (i = 0; i < arrOptionTextContainers.length; i++) {
        arrOptionTextContainers[i].className = "otherOptionText otherOptionHideText";

        // If the option is hidden, text fields within it shouldn't have a value
        OtherOptionBlankText(arrOptionTextContainers[i]);
    }
}

function OtherOptionShowText(strOtherOptionTagId) {
    objOtherOptionTag = document.getElementById(strOtherOptionTagId);
    strOtherOptionClassName = objOtherOptionTag.className;
    arrOptionTextContainers = getElementsByClassName("otherOptionText otherOptionHideText", "div", objOtherOptionTag);
    for (i = 0; i < arrOptionTextContainers.length; i++) {
        arrOptionTextContainers[i].className = "otherOptionText";
    }
}

function OtherOptionBlankText(objOtherOptionTextContainer) {
    // If the option is hidden, text fields within it (there might be several, even if we only expect one by design) shouldn't have a value
    arrOptionTextControls = objOtherOptionTextContainer.getElementsByTagName("INPUT");
    if (arrOptionTextControls) {
        for (j = 0; j < arrOptionTextControls.length; j++) {
            if (arrOptionTextControls[j].type == "text") {
                //alert("id=" + arrOptionTextControls[j].id);
                arrOptionTextControls[j].value = "";
            }
        }
    }
}

function SetDefaultFieldValue(strForm, strElement, strValue, blnFocus) {
    var strInitialValue = document.forms[strForm].elements[strElement].value;
    if (blnFocus) {
        if (strInitialValue == strValue) {
            document.forms[strForm].elements[strElement].value = "";
        }
    } else {
        if (strInitialValue == "") {
            document.forms[strForm].elements[strElement].value = strValue;
        }
    }
}

// ====================
// Function:    FloatingDiv
//
// Purpose:     Make a div always visible on the page with a smooth floating effect.
//
// Input:       id - ID of the div 
//              sx - x co-ordinate of where to float the div
//              sy - y co-ordinate of where to float the div
//
// Output:      -
//
// Assumptions: -
//
// History:     20090626 RW Included from http://www.javascript-fx.com/submitscripts/float/float.html
// ====================
function FloatDiv(id, sx, sy) {
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var d = document;
    var el = d.getElementById ? d.getElementById(id) : d.all ? d.all[id] : d.layers[id];
    var px = document.layers ? "" : "px";
    window[id + "_obj"] = el;
    if (d.layers) el.style = el;
    el.cx = el.sx = sx; el.cy = el.sy = sy;
    el.sP = function(x, y) { this.style.left = x + px; this.style.top = y + px; };

    el.floatIt = function() {
        var pX, pY;
        pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
        document.documentElement && document.documentElement.clientWidth ?
        document.documentElement.clientWidth : document.body.clientWidth;
        pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?
        document.documentElement.scrollTop : document.body.scrollTop;
        if (this.sy < 0)
            pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ?
        document.documentElement.clientHeight : document.body.clientHeight;
        this.cx += (pX + this.sx - this.cx) / 8; this.cy += (pY + this.sy - this.cy) / 8;
        this.sP(this.cx, this.cy);
        setTimeout(this.id + "_obj.floatIt()", 40);
    }
    return el;
}

function getWindowDimension(strPlane) {
    var dimension = 0;

    switch (strPlane.toLowerCase()) {
        case "width":
            if (typeof (window.innerWidth) == 'number') {
                //Non-IE
                dimension = window.innerWidth;
            } else if (document.documentElement && (document.documentElement.clientWidth)) {
                //IE 6+ in 'standards compliant mode'
                dimension = document.documentElement.clientWidth;
            } else if (document.body && (document.body.clientWidth)) {
                //IE 4 compatible
                dimension = document.body.clientWidth;
            }
            break;
        case "height":
            if (typeof (window.innerHeight) == 'number') {
                //Non-IE
                dimension = window.innerHeight;
            } else if (document.documentElement && (document.documentElement.clientHeight)) {
                //IE 6+ in 'standards compliant mode'
                dimension = document.documentElement.clientHeight;
            } else if (document.body && (document.body.clientHeight)) {
                //IE 4 compatible
                dimension = document.body.clientHeight;
            }
            break;
    }
    return dimension;
}

/**********************************************************
Function:
getElementsByClassName

Purpose:
Provides compatibility for getElementsByClassName (a native function in
many browsers) for browsers that don't support it (IE).

Input:
className -  Mandatory. One or several class names, separated by space. 
Multiple class names demands that each match have all of the classes 
specified.
tag - Optional. Specifies the tag name of the elements to match.
elm - Optional. Reference to a DOM element to look amongst its children for
matches. Recommended for better performance in larger documents. 
            
Output:
An array of elements

Assumptions:
-

Examples:
To get all elements in the document with a “info-links” class.
getElementsByClassName("info-links");
    
To get all div elements within the element named “container”, with a “col” class.
getElementsByClassName("col", "div", document.getElementById("container")); 
    
To get all elements within in the document with a “click-me” and a “sure-thang” class.
getElementsByClassName("click-me sure-thang"); 

History:
20091022 RW Included from http://www.robertnyman.com

Notes:
Developed by Robert Nyman, http://www.robertnyman.com
Code/licensing: http://code.google.com/p/getelementsbyclassname/
DDSN Note: MIT Licence
**********************************************************/
var getElementsByClassName = function(className, tag, elm) {
    if (document.getElementsByClassName) {
        getElementsByClassName = function(className, tag, elm) {
            elm = elm || document;
            var elements = elm.getElementsByClassName(className),
				nodeName = (tag) ? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
            for (var i = 0, il = elements.length; i < il; i += 1) {
                current = elements[i];
                if (!nodeName || nodeName.test(current.nodeName)) {
                    returnElements.push(current);
                }
            }
            return returnElements;
        };
    }
    else if (document.evaluate) {
        getElementsByClassName = function(className, tag, elm) {
            tag = tag || "*";
            elm = elm || document;
            var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace) ? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
            for (var j = 0, jl = classes.length; j < jl; j += 1) {
                classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
            }
            try {
                elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
            }
            catch (e) {
                elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
            }
            while ((node = elements.iterateNext())) {
                returnElements.push(node);
            }
            return returnElements;
        };
    }
    else {
        getElementsByClassName = function(className, tag, elm) {
            tag = tag || "*";
            elm = elm || document;
            var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
            for (var k = 0, kl = classes.length; k < kl; k += 1) {
                classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
            }
            for (var l = 0, ll = elements.length; l < ll; l += 1) {
                current = elements[l];
                match = false;
                for (var m = 0, ml = classesToCheck.length; m < ml; m += 1) {
                    match = classesToCheck[m].test(current.className);
                    if (!match) {
                        break;
                    }
                }
                if (match) {
                    returnElements.push(current);
                }
            }
            return returnElements;
        };
    }
    return getElementsByClassName(className, tag, elm);
};
