// FrameChecker -- Remove if frames site.
if (window!=top) { top.location.replace(document.location.href); }


// ** fnSimulateRepeaterCommand **
//
// This function is commonly used to simulate an "ItemCommand" event for
//  a DataBound WebControls.Repeater object with EnableViewState = False.
//
// "fnSimulateRepeaterCommand" works around what is essentially a chicken-and-egg problem...
// The "ItemCommand" event cannot fire until the Repeater is bound,
//  but DataBinding does not take place unless the event fires.
//
// (In Avera, this situation arises when an "Approve" button
//   is displayed on the list of CmsPages or CmsPanels.)
//
// To use this function, write server-side codebehind to handle
//  a "Click" event on a WebControls.LinkButton control outside
//  the Repeater or other templated DataBound control, and look
//  for the value in an HtmlControls.HtmlInputHidden control.
// Generally, the LinkButton will have a "Text" property
//  of empty string, but it MUST be visible on the Page
//  to be a valid postback target.
//
// The JavaScript places the strHiddenFieldValue parameter
//  into the HtmlInputHidden control, then causes a postback
//  to fire on the LinkButton control.
//
// Use the strLinkButtonUniqueID and strHiddenFieldUniqueID
//  parameters to identify the LinkButton and HtmlInputHidden
//  controls with the "UniqueID" property.
//
// Note how join and split are used to create the appropriate strings
//  understood by the .NET aspnet_client system_web v1.1.4322.
//
// -- KRopa, April 15 2004

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);
		}
	}
}


// ** fnConfirmCheckboxes **
//
// This function returns true or false, and is commonly used to
//  verify that at least one checkbox is checked in a list of
//  DHTML checkboxes with the same "name" attribute.
// <input type="submit" onclick="return fnConfirmCheckboxes('[value of "name" attribute]');" />

function fnConfirmCheckboxes(strCheckboxesName, strErrorMessage, strConfirmMessage) {
	var blnOK = false;

	var strAlertMessage = "Please check at least one item.";
	if ( strErrorMessage != null ) {
		if ( strErrorMessage.toString().length > 0 ) {
			strAlertMessage = strErrorMessage.toString();
		}
	}

	var strConfirmQuestion = "Are you sure?";
	if ( strConfirmMessage != null ) {
		if ( strConfirmMessage.toString().length > 0 ) {
			strConfirmQuestion = strConfirmMessage.toString();
		}
	}

	var i = 0;
	var objCheckbox;
	var objCheckboxes = document.getElementsByName(strCheckboxesName.toString());
	if ( objCheckboxes != null ) {
		if ( typeof objCheckboxes == 'object' ) {

			if ( objCheckboxes.length > 0 ) {
				for (i = 0; i < objCheckboxes.length; i++) {
					objCheckbox = objCheckboxes.item(i);
					if ( objCheckbox.checked != null ) {
						if ( objCheckbox.checked == true ) { blnOK = true; }
					} else { alert("ERROR! Element at index " + i.toString() + " of '" + strCheckboxesName.toString() + "' collection has no 'checked' attribute!"); }
				}
				if ( blnOK ) {
					blnOK = confirm(strConfirmQuestion);
				} else { alert(strAlertMessage); }
			}

			else {
				objCheckbox = objCheckboxes.item(0);
				if ( objCheckbox.checked != null ) {
					if ( objCheckbox.checked == true ) {
						blnOK = confirm(strConfirmQuestion);
					} else { alert(strAlertMessage); }
				} else { alert("ERROR! The one '" + strCheckboxesName.toString() + "' element has no 'checked' attribute!"); }
			}

		} else { alert("ERROR! DHTML element named '" + strCheckboxesName.toString() + "' is not an object!"); }
	} else { alert("ERROR! Could not find a DHTML element named '" + strCheckboxesName.toString() + "'"); }

	return blnOK;
}


// ** fnOpenWindow **
//
// Opens a modeless dialog.

function strOpenWindowFeatures(iWindowWidth, iWindowHeight) {
	//var iWindowHeight = 630;
	//var iWindowWidth = 640;
	var iMouseX = 10;
	var iMouseY = 10;
	if ( window.event != null ) {
		//	alert("SRC ELEMENT: " + window.event.srcElement.tagName);
		//	alert("mouse X, Y relative to window: " + window.event.clientX + ", " + window.event.clientY);
		//	alert("mouse X, Y relative to screen: " + window.event.screenX + ", " + window.event.screenY);
		iMouseX = window.event.screenX;
		iMouseY = window.event.screenY; }
		//	alert("iMouseX, iMouseY: " + iMouseX + ", " + iMouseY);
	var iScreenX = window.screen.availWidth;
	var iScreenY = window.screen.availHeight;
		//	alert("iScreenX, iScreenY: " + iScreenX + ", " + iScreenY);
	var iWindowLeft = iMouseX;
	if ( iWindowLeft + iWindowWidth > iScreenX ) { iWindowLeft = iMouseX - iWindowWidth - 10; }
	if ( iWindowLeft < 10 ) { iWindowLeft = 10; }
		//	alert("iWindowLeft: " + iWindowLeft);
	var iWindowTop = iMouseY;
	if ( iWindowTop + iWindowHeight > iScreenY - 50 ) { iWindowTop = iMouseY - iWindowHeight - 60; }
	if ( iWindowTop < 10 ) { iWindowTop = 10; }
		//	alert("iWindowTop: " + iWindowTop);
	return "width=" + iWindowWidth + ", height=" + iWindowHeight + ", left=" + iWindowLeft + ", top=" + iWindowTop + ", channelmode=no, directories=no, fullscreeen=no, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=no";
}

function fnOpenWindow(strWindowURL, strWindowName, iWindowWidth, iWindowHeight) {
		//	alert("strWindowName: '" + strWindowName + "'");
		//	alert("strOpenWindowFeatures(" + iWindowWidth + ", " + iWindowHeight + "): '" + strOpenWindowFeatures(iWindowWidth, iWindowHeight) + "'");
	var objNewWindow = window.open(strWindowURL, strWindowName, strOpenWindowFeatures(iWindowWidth, iWindowHeight), false);
}

// toggles the display of an item
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 {
			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;
	return false;
}	

