//A shorter way to get an element
function getEl(pvID)
{
	return document.getElementById(pvID);
}

//Create an element and add an id to it
function createEl(pvEl, pvId)
{
	var lvEl = document.createElement(pvEl);
	if (pvId != null && pvId != "") { lvEl.id = pvId; }
	return lvEl;
}

//Get 1 element by name
function getElByName(pvId)
{
	return document.getElementsByName(pvId)[0];
}

//A function to find a parent element with a certain tag of the given element
function getParentElByTagName(pvEl, pvTag)
{
	var lvEl = pvEl;
	var lvTag = pvTag.toLowerCase();
	var lvContinue = true;

	while (lvContinue)
	{
		lvContinue = (lvEl == null || lvEl.nodeType != 1) ? false : (lvEl.tagName.toLowerCase() != lvTag);
		if (lvContinue) { lvEl = lvEl.parentNode; }
	}
	return lvEl;
}

//Get the innertext of an element (that means only the next and no html)
function getInnerText(pvEl)
{
	if (isIE) { return pvEl.innerText; }
	else { return pvEl.innerHTML.replace(/<br>/gi, "\n").replace(/<[^>]+>/g, ""); }
}

//Firefox doesn't have an outerHTML function, so we have a custom one
function getOuterHTML(pvEl)
{
	var lvHTML = "";

	if (isIE) { lvHTML = pvEl.outerHTML; }
	else
	{
		var lvDiv = createEl("div");
		var lvParent = pvEl.parentNode;
		lvDiv.appendChild(pvEl);
		lvHTML = lvDiv.innerHTML;
		if (lvParent != null) { lvParent.appendChild(pvEl); }
		lvDiv = null;
	}

	return lvHTML;
}

function generateElementHTML(pvTagName, pvAttributes, pvSelfClose, pvInnerHTML)
{
	var lvHTML = "<" + pvTagName;
	for (var i = 0; i < pvAttributes.length; i++)
	{
		var lvAtt = pvAttributes[i];
		lvHTML += " " + lvAtt[0] + "=\"" + lvAtt[1] + "\"";
	}
	lvHTML += pvSelfClose ? " />" : ">" + pvInnerHTML + "</" + pvTagName + ">";
	return lvHTML;
}

//Check if an element has a certain attribute
function hasAttribute(pvEl, pvAttribute)
{
	if (isIE) { return pvEl.getAttribute(pvAttribute) != null; }
	else { return pvEl.hasAttribute(pvAttribute); }
}

/**
** Set a HTML attribute, if value is empty then remove the attribute from the element
**/
function setOrRemoveAttribute(pvEl, pvAtt, pvVal)
{
	if (pvVal == null || pvVal == "")
	{
		pvEl.removeAttribute(pvAtt);
	}
	else
	{
		pvEl.setAttribute(pvAtt, pvVal);
	}
}

//Check if an element is visible
function isVisible(pvEl)
{
	var lvResult = true;
	var lvEl = pvEl;

	while (lvResult && lvEl.tagName.toLowerCase() != "body")
	{
		lvResult = (lvEl.style.display != "none" && lvEl.style.visibility != "hidden");
		lvEl = lvEl.parentNode;
	}
	return lvResult;
}