var popup = null;

function checkLinkTarget()
{
    try
    {
        // Get all links in the post content holder <div> and make them open in a new window. 
        var divList = document.getElementsByName("BBSContentHolder");
        for(var x=0; x<divList.length; x++)
        {
            var targetDiv = divList[x];
            var linkList = targetDiv.getElementsByTagName("a");
            for(var i=0; i<linkList.length; i++)
            {
                linkList[i].target="_blank";
            }
        }
    }
   catch(e){}
}

function isEnterKey(e)
{
	var keyCode;
	if(window.event) // IE
	{
		keyCode = e.keyCode;
	}
	else 
	{
		keyCode = e.which;
	}

    if(keyCode == 13)
	{return true;}
    else
    {return false;}
}

function imageSwapOver(cellID,imageURL)
{
	var origLeftBannerImage = new Image();
	origLeftBannerImage.src = getUrlFromBackGround(document.getElementById("HeaderCtrl_BannerLeftTD").style.backgroundImage);
	document.getElementById("HeaderCtrl_BannerLeftTD").style.backgroundImage = "url(" + leftBannerImage.src + ")";
	leftBannerImage = origLeftBannerImage;
}

function swapImage(imageID,newImage)
{
	var originalImage = new Image();
	originalImage.src = document.getElementById(imageID).src;
	document.getElementById(imageID).src = newImage.src;
	return originalImage;
}

function getUrlFromBackGround(urlString)
{
	var start = urlString.indexOf("url(") + 4;
	var end = urlString.indexOf(")") ;
	return (urlString.substring(start,end));
}

function protectEmail(linkText,emailAddress) {
	document.write('<A href="mailto:' + emailAddress + '">' + linkText + '</a>');
}

function toggleElement(elementID,toggleFieldID)
{
	var toggleDiv = document.getElementById(elementID);
	var item = document.getElementById(toggleFieldID);
	if(item != null)
	{
		if(item.value == "1")
		{
			toggleDiv.style.display="none";
			item.value = "0";
		}
		else
		{
			toggleDiv.style.display="";
			item.value = "1";
		}
	}
}

function toggleSingleElement(elementID)
{
	var item = document.getElementById(elementID);
	if(item != null)
	{
		if(item.style.display != "none")
		{
			item.style.display="none";
		}
		else
		{
			item.style.display="";
		}
	}
}

function setFocusOnControl(controlName)
{
	var control = document.getElementById(controlName);
	if( control != null )
	{
		control.focus();
		return;
	}
}

function popPic (url){
	closePopup();
	popup = window.open(url , "picWin", "");
}

function openPopupWithScroll( url, name , height , width ) {
	closePopup();	//ONLY ONE POPUP, and the reference is stored in the variable popup (hardcoded!)
	var dialogparam = ",scrollbars=1,status=0,location=0,menubar=0,resizable=1";
	var screenparam = "height="+ height +",width="+ width ;
	params = screenparam+dialogparam;
	popup = window.open( url , name , params );
}

function openPopup( url, name , height , width ) {
	closePopup();	//ONLY ONE POPUP, and the reference is stored in the variable popup (hardcoded!)
	var dialogparam = ",scrollbars=0,status=0,location=0,menubar=0,resizable=0";
	var screenparam = "height="+height+",width="+width;
	params = screenparam+dialogparam;
	popup = window.open( url , name , params );
}

function closePopup() {
	var popup = popup;
	if (popup != null && popup.open) {
		popup.close();}
	popup = null;
}
