/* Array functions (those not added to Array.prototype) */

 // From http://javascript.crockford.com/remedial.html
function isArray (v) {
	return (v && typeof v === 'object' && typeof v.length === 'number' &&
		// Need to test that propertyIsEnumerable is defined on v first, 
		// else IE6 throws an error because propertyIsEnumerable is not defined on HTML elements.
		// This is ok in Firefox. 
		// Note that in both IE and FF, you can test v.propertyIsEnumerable('length')
		// on an object with no length property defined without error - it returns false.
		typeof v.propertyIsEnumerable !== 'undefined' && !v.propertyIsEnumerable('length') && 
		typeof v.splice === 'function');
}

// Convert el to a single-element array if it is not already an array.
function toArray(el) {

	if (!isArray(el)) {
		el = [ el ];
	}
	return el;
}

// Workaround for the fact that you cannot concat() two nodeLists (returned by getElementsByTagName)
// because they are not true Arrays but Objects with a length property.
// RY 7/20/07 This isn't such a good idea - NodeLists are dynamically modified with the DOM, so
// are read-only for good reason.
function joinNodeLists(){

	if (!arguments.length) {
		return null;
	}
	var newList = arguments[0];
	for (var i = 1; i < arguments.length; i++) {
		var list = arguments[i];
   		for (var j = 0; j < list.length; j++) {
			// Don't use push() for IE 5 compatibility
			// newList.push(list[j]);
			newList[newList.length] = list[j];
		}
	}

    return newList;
}

/** @description Create a new array by pre- or postpending the specified string to each element of 
 * a string array. Example:
 * addToArrayElements("/news/", [ "story1.html", "story2.html", "story3.html" ], true) returns a new
 * array [ "/news/story1.html", "/news/story2.html", "/news/story3.html" ].
 * @param {String} str The string to pre- or postpend
 * @param {Array} strarray
 * @param {String} pos (optional) Where to put the additional string: "pre" for prepend, "post" for postpend. 
 * Default to "pre".
 * @return {Array} The new array
 */
function concatStrToArrayElements(str, strarray, pos) {
	
	var i, 
		newarray = [],
		pos = pos || "pre";
		
	for (i = 0; i < strarray.length; i++) {
		newarray[i] = (pos == "pre" ? str + strarray[i] : strarray[i + str]);
	}
	
	return newarray;
}

/*
// Like joinNodeLists() but returns an array rather than a nodelist.	
// RY 2/26/07 Do we ever need this?
function joinNodeListsToArray() {

	var newList = [];
	for (var i = 0; i < arguments.length; i++) {
		var list = arguments[i];
		for (var j = 0; j < list.length; j++) {
			// Don't use push() for IE 5 compatibility
			// newList.push(list[j]);
			newList[newList.length] = list[j];
		}
	}
	
	return newList;
}
*/