var isMozilla = false;

if (typeof Node != 'undefined' && Node.prototype)
{
	isMozilla = true;
	Node.prototype.__defineGetter__(
	'textContent',
	function ()
	{
		switch (this.nodeType)
		{
			case 2:  //ATTRIBUTE_NODE
			case 3:  //TEXT_NODE
			case 4:  //CDATA_SECTION_NODE
			case 7:  //PROCESSING_INSTRUCTION_NODE
			case 8:  //COMMENT_NODE
				return this.nodeValue;
				break;
			case 1:  //ELEMENT_NODE
			case 5:  //ENTITY_REFERENCE_NODE
			case 6:  //ENTITY_NODE
			case 11: //DOCUMENT_FRAGMENT_NODE
				var range = this.ownerDocument.createRange();
				range.selectNodeContents(this);
				var textContent = range.toString();
				range.detach();
				return textContent;
				break;
			case 9: //DOCUMENT_NODE
			case 10: //DOCUMENT_TYPE_NODE
			case 12: //NOTATION_NODE
				return null;
				break;
			default:
				return null;
		}
	}
	);
   
Node.prototype.__defineSetter__(
	'textContent',
	function (textContent)
	{
		switch (this.nodeType)
		{
		case 2:  //ATTRIBUTE_NODE
		case 3:  //TEXT_NODE
		case 4:  //CDATA_SECTION_NODE
		case 7:  //PROCESSING_INSTRUCTION_NODE
		case 8:  //COMMENT_NODE
			return this.nodeValue = textContent;
			break;
		case 1:  //ELEMENT_NODE
		case 5:  //ENTITY_REFERENCE_NODE
		case 6:  //ENTITY_NODE
		case 11: //DOCUMENT_FRAGMENT_NODE
			var range = this.ownerDocument.createRange();
			range.selectNodeContents(this);
			range.deleteContents();
			range.detach();
			this.appendChild(this.ownerDocument.createTextNode(textContent));
			return textContent;
			break;
		case 9: //DOCUMENT_NODE
		case 10: //DOCUMENT_TYPE_NODE
		case 12: //NOTATION_NODE
			return null;
			break;
		default:
			return null;
		}
	}
	);

}

function hideDivider(totalPlaceholders, placeholderName)
{
	var i;
	var tempObj;
	var tempParent;
	var hRtDividerElement;
	var hLtDividerElement;
	var vDividerElement;
	var leftCol;
	var leftArticleCount = 0;
	var rigthCol;
	var rightArticleCount = 0;
	
	/*
	* For every placeholder, increment either leftArticleCount
	* or rightArticleCount depending on whether the placeholder
	* contains content and whether the placeholder is in the 
	* right or left column
	*/
	
	for(i = 1; i <= totalPlaceholders; i++)
	{
		tempObj = document.getElementById(placeholderName + i);
		tempParent = tempObj.parentNode;
		
		if(tempParent.id == "leftContentColumn")
		{
			if(isMozilla)
			{
				// check to see in the element is empty
				if(tempObj.textContent.replace(/[\s][\n\r]/, "") != "")
				{
					leftArticleCount++;
				}
			}
			else
			{
				// check to see in the element is empty
				if(tempObj.innerText.replace(/[\s][\n\r]/, "") != "")
				{
					leftArticleCount++;
				}
			}
		}
		else if(tempParent.id == "rightContentColumn")
		{
			if(isMozilla)
			{
				// check to see in the element is empty
				if(tempObj.textContent.replace(/[\s][\n\r]/, "") != "")
				{
					rightArticleCount++;
				}
			}
			else
			{
				// check to see in the element is empty
				if(tempObj.innerText.replace(/[\s][\n\r]/, "") != "")
				{
					rightArticleCount++;
				}
			}
		}
		
	}
	
	
	vDividerElement = document.getElementById("vDivider");
	
	// switch the vDivider's class if there aren't any articles
	if(leftArticleCount <= 0 || rightArticleCount <= 0)
	{
		if(vDividerElement)
		{
			vDividerElement.className = "noDivide";
		}
	}
	
	// if there is more than one article remove the 
	// last article's hr tag from the DOM
	if(leftArticleCount > 0)
	{
		leftArticleCount = 2 * leftArticleCount - 1;
		hLtDividerElement = document.getElementById(placeholderName + leftArticleCount + "_Articleplaceholdercontrol" + leftArticleCount + "_hDivider");

		if(hLtDividerElement != null && hLtDividerElement.parentNode != null && hLtDividerElement.parentNode.id.length > 0)
		{
			tempParent = document.getElementById(hLtDividerElement.parentNode.id);
			tempParent.removeChild(hLtDividerElement);
		}

	}

	// if there is more than one article remove the 
	// last article's hr tag from the DOM
	if(rightArticleCount > 0)
	{
		rightArticleCount = 2 * rightArticleCount;
		hRtDividerElement = document.getElementById(placeholderName + rightArticleCount + "_Articleplaceholdercontrol" + rightArticleCount + "_hDivider");
		
		if(hRtDividerElement != null && hRtDividerElement.parentNode != null && hRtDividerElement.parentNode.id.length > 0)
		{
			tempParent = document.getElementById(hRtDividerElement.parentNode.id);
			tempParent.removeChild(hRtDividerElement);
		}
	}
	
	return;

}
