
var elementCache = new Array();

function getFileName() {
	var fileName = filePath.split("/")[filePath.split("/").length-1];
	fileName = fileName.replace(/\.[^\.]*$/, "");
	return fileName;
}

function getById(id) {
	if(elementCache[id]) return elementCache[id];
	if(document.getElementById(id)) {
		elementCache[id] = document.getElementById(id);
		return elementCache[id];
	}else {
		return null;
	}
}

function getElementsByClassName(ClassName,tagName,parentElement){
	var elements=new Array();
	var d=parentElement ? parentElement : document;
	var allElements;

	if(tagName)
	allElements=d.all && d.all.tags(tagName)
	|| d.getElementsByTagName && d.getElementsByTagName(tagName);
	else allElements=d.all || d.getElementsByTagName("*");

	for(var i=0,len=allElements.length; i<len; i++)
	if(allElements[i].className==ClassName)
	elements[elements.length]=allElements[i];

	return elements;
}

function makeTag(parentTag, tagName, attrArray, textString) {
	var element;
	// shit-spec. http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/name_2.asp
	if(isWinIE && tagName == "a") {
		for(var i = 0; i < attrArray.length; i++) {
			if(attrArray[i][0].toLowerCase() == "name") {
				element = document.createElement("<a name=\"" + attrArray[i][1] + "\"><\/a>");
				attrArray.splice(i, 1);
				break;
			}
		}
		if(!element) element = document.createElement(tagName);	
	}else {
		element = document.createElement(tagName);
	}
	if(attrArray != null) {
		for(var i = 0; i < attrArray.length; i++) {
			if(isWinIE && attrArray[i][0].toLowerCase() == "style") element.style.cssText += attrArray[i][1];
			else if(isWinIE && attrArray[i][0].toLowerCase() == "class") element.className =  attrArray[i][1];
			else element.setAttribute(attrArray[i][0], attrArray[i][1]);
		}
	}
	if(textString != null) addText(element, textString);
	if(parentTag != null) parentTag.appendChild(element);
	return element;
}

function addText(targetTag, textString) {
	if(!textString) return;
	targetTag.appendChild(document.createTextNode(textString));
}

function equalsTagName(targetTag, tagName) {
	return targetTag.tagName.toLowerCase() == tagName;
}

function clearTag(id) {
	var target = getById(id);
	if(target) {
		target.innerHTML = "";
	}
}

function changeDisplay(id, value) {
	var target = getById(id);
	if(target) {
		target.style.display = value;
	}
}

function changeDisplayByName(name, value) {
	var array;
	if(document.getElementsByName) {
		array = document.getElementsByName(name);
		alert(name);
	} else {
		if (document.all.item(name).length) {
			for (i = 0; i < document.all.item(name).length; i++) {
				document.all.item(name, i).style.display = value;
			}
		} else {
			document.all.item(name).style.display = value;
		}
	}
	for(var i = 0; i < array.length; i++) {
		array[i].style.display = value;
	}
}

function changeDisplayByClassName(name, value) {
	var array = getElementsByClassName(name);
	for(var i = 0; i < array.length; i++) {
		array[i].style.display = value;
	}
}
