// FrameChecker -- Remove if frames site.
if (window!=top) { top.location.replace(document.location.href); }

// Show/Hide element
function fnToggleElementVisibility(strElementId) {
	//alert("fnToggleVisibility('" + strElementId + "');");
	var objElement = document.getElementById(strElementId);
	var blnVisible;
	if ( objElement != null ) {
			//alert("Found element named '" + strElementId + "'.");
		blnVisible = objElement.style.display != "none";
		if ( blnVisible == true ) {
				//alert("Hiding element '" + strElementId + "'.");
			objElement.style.display = "none"; } else {
				//alert("Showing element '" + strElementId + "'.");
			objElement.style.display = "block"; }
	} else { alert("Could not find '" + strElementId + "' element."); }
}

// Simplified Popup
// Usage: <a onclick="return popUp(this.href,250,250);" href="popup.aspx">Link</a>
function popUp(theLink, popUpWidth, popUpHeight) {
	var popUpWindow = window.open(theLink, "popUp", "width=" + popUpWidth +
	", height=" + popUpHeight +
	", left=50, top=50, resizable=yes, scrollbars=yes", false);
	if ( popUpWindow != null ) {
		popUpWindow.focus();
	}
	return false;
}
function closePopUp() {
window.close();
}

// Swap visible elements based on radio button clicks
function swapElements(idShown, idHidden) {
	document.getElementById(idShown).style.display = "block";
	document.getElementById(idHidden).style.display = "none";
}

// Cross-Browser Block Element Display Toggler
function toggleElement(elId) {
	var visibleStyle = "block";
	if (!document.all) {
		var el = document.getElementById(elId);
		if((el != null) && (typeof(el) == 'object')) {
			var elName = el.tagName.toLowerCase();
			if (elName == "tr") {
				visibleStyle = "table-row";
			}
			else if (elName == "tbody") {
				visibleStyle = "table-row-group";
			}
			else {
				visibleStyle = "block";
			}
		} else {
			alert("ElementId '" + elId + "' is null or not an object.");
		}
	}
	var v = ((document.getElementById(elId).style.display == visibleStyle) || (document.getElementById(elId).style.display == ""));
	document.getElementById(elId).style.display = v ? "none" : visibleStyle;
}

function hideElement(hiddenElId) {
	document.getElementById(hiddenElId).style.display = "none";
}

function showElement(elId) {
	var visibleStyle = "block";
	if (!document.all) {
		var el = document.getElementById(elId);
		if((el != null) && (typeof(el) == 'object')) {
			var elName = el.tagName.toLowerCase();
			if (elName == "tr") {
				visibleStyle = "table-row";
			}
			else if (elName == "tbody") {
				visibleStyle = "table-row-group";
			}
			else {
				visibleStyle = "block";
			}
		} else {
			alert("ElementId '" + elId + "' is null or not an object.");
		}
	}
	document.getElementById(elId).style.display = visibleStyle;
}

// Popup Windows
function strOpenWindowFeatures(iWindowWidth, iWindowHeight) {
	var iMouseX = 10;
	var iMouseY = 10;
	if ( window.event != null ) {
		iMouseX = window.event.screenX;
		iMouseY = window.event.screenY; }
	var iScreenX = window.screen.availWidth;
	var iScreenY = window.screen.availHeight;
	var iWindowLeft = iMouseX;
	if ( iWindowLeft + iWindowWidth > iScreenX ) { iWindowLeft = iMouseX - iWindowWidth - 10; }
	if ( iWindowLeft < 10 ) { iWindowLeft = 10; }
	var iWindowTop = iMouseY;
	if ( iWindowTop + iWindowHeight > iScreenY - 50 ) { iWindowTop = iMouseY - iWindowHeight - 60; }
	if ( iWindowTop < 10 ) { iWindowTop = 10; }
	return "width=" + iWindowWidth + ", height=" + iWindowHeight + ", left=" + iWindowLeft + ", top=" + iWindowTop + ", resizable=yes";
}
function fnOpenWindow(strWindowURL, strWindowName, iWindowWidth, iWindowHeight) {
	var objNewWindow = window.open(strWindowURL, strWindowName, strOpenWindowFeatures(iWindowWidth, iWindowHeight), false);
	if ( objNewWindow != null ) {
		objNewWindow.focus();
	}
}

if (document.images) {
	// sample_on = new Image(); sample_on.src="/_imgs/sample_on.gif";
	// sample = new Image(); sample.src="/_imgs/sample.gif";
}
function imgAct(imgName) { if (document.images) { document.images[imgName].src = eval(imgName + "_on.src"); } }
function imgInact(imgName) { if (document.images) { document.images[imgName].src = eval(imgName + ".src"); } }

// This function is also in the admin.js file,
//  and fully documented there...
function fnSimulateRepeaterCommand(strLinkButtonUniqueID, strHiddenFieldUniqueID, strHiddenFieldValue) {
	//alert("fnSimulateRepeaterCommand('" + strLinkButtonUniqueID + "', '" + strHiddenFieldUniqueID + "', '" + strHiddenFieldValue + "');");

	// Split and Join the UniqueID property of the LinkButton to get
	//  the DHTML ID and .NET __doPostBack ID for the server control.
	var aryLinkButtonID = strLinkButtonUniqueID.toString().split(":");
	var strLinkButtonClientID = aryLinkButtonID.join("_");
	var strLinkButtonPostBackID = aryLinkButtonID.join("$");

	// Split and Join the UniqueID property of the HtmlInputHidden
	//  to get the DHTML ID for the server control.
	var aryHiddenFieldID = strHiddenFieldUniqueID.toString().split(":");
	var strHiddenFieldClientID = aryHiddenFieldID.join("_");

	// Look for DHTML objects for the LinkButton and HtmlInputHidden.
	var objLinkButton = document.getElementById(strLinkButtonClientID);
	var objHiddenField = document.getElementById(strHiddenFieldClientID);

	// A variable to verify that everything will work...
	var blnOK = false;
	//alert("typeof __doPostback = '" + typeof __doPostBack + "'");
	if ( typeof __doPostBack == 'function' ) {
		if ( objLinkButton != null ) {
			if ( typeof objLinkButton == 'object' ) {
				if ( objHiddenField != null ) {
					if ( typeof objHiddenField == 'object' ) {
						if ( objHiddenField.value != null ) {
							if ( strHiddenFieldValue.toString().length > 0 ) {
								blnOK = true;
							} else { alert("ERROR! strHiddenFieldValue parameter is an empty string!"); }
						} else { alert("ERROR! DHTML element with id='" + strHiddenFieldClientID + "' has no 'value' attribute!"); }
					} else { alert("ERROR! DHTML element with id='" + strHiddenFieldClientID + "' is not an object!"); }
				} else { alert("ERROR! Could not find a DHTML element with id='" + strHiddenFieldClientID + "'"); }
			} else { alert("ERROR! DHTML element with id='" + strLinkButtonClientID + "' is not an object!"); }
		} else { alert("ERROR! Could not find a DHTML element with id='" + strLinkButtonClientID + "'"); }
	} else { alert("ERROR! Could not find a '__doPostBack' function!"); }

	if ( blnOK == true ) {
		objHiddenField.value = strHiddenFieldValue.toString();
		try {
			__doPostBack(strLinkButtonPostBackID,'');
		} catch (err) {
			alert("JavaScript error:\n" + err.description);
		}
	}
}

// Used for multiple window.onload events
// http://www.sitepoint.com/blogs/2004/05/26/closures-and-executing-javascript-on-page-load/
/*
addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
	// more code to run on page load 
});
*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
			window.onload = function() {
			oldonload();
			func();
		}
	}
}

/*
pullquote function by Roger Johansson, http://www.456bereastreet.com/
*/
var pullquote = function() {
// Check that the browser supports the methods used
	if (!document.getElementById || !document.createElement || !document.appendChild) return false;
	var oElement, oPullquote, oPullquoteP, oQuoteContent, i, j;
// Find all span elements with a class name of Pullquote
	var arrElements = document.getElementsByTagName('span');
	var oRegExp = new RegExp("(^|\\s)Pullquote(\\s|$)");
	for (i=0; i<arrElements.length; i++) {
// Save the current element
		oElement = arrElements[i];
		if (oRegExp.test(oElement.className)) {
// Create the blockquote and p elements
			oPullquote = document.createElement('blockquote');
			oPullquote.className = oElement.className
			oPullquoteP = document.createElement('p');
// Insert the pullquote text
			for(j=0;j<oElement.childNodes.length;j++) {
				oPullquoteP.appendChild(oElement.childNodes[j].cloneNode(true));
			}
			oPullquote.appendChild(oPullquoteP);
// Insert the blockquote element before the span elements parent element
			oElement.parentNode.parentNode.insertBefore(oPullquote,oElement.parentNode);
		}
	}
};
addLoadEvent(pullquote);

// NewWindow Script
function newWindow()
{
  //$(".NewWindow").after("<img src=\"/imgs/icons/new_window_icon.gif\" border=0 class=\"NewWindowIcon\">");
  $('a[target*=_blank]')
     .addClass('NewWindow')
	 .attr("title", "Link opens in new window")
     .append("<img src=\"/imgs/icons/new_window_icon.gif\" border=0 class=\"NewWindowIcon\">");
}
$(document).ready(function(){newWindow();});
