// FrameChecker -- Remove if frames site.
if (window!=top) { top.location.replace(document.location.href); }

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;
	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);
		}
	}
}


// This function flips the server form element to target="_blank"
//  then perfoms a postback on a specified LinkButton, and finally
//  flipds the target attribute of the server form element back.
// 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.
function fnOpenPrintFormatWindow(strLinkButtonUniqueID) {
	//alert("fnOpenPrintFormatWindow('" + strLinkButtonUniqueID + "');");

	// 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("$");

	// Mimic .NET's client-side __doPostBack function to locate the server form element.
	// Because Avera.VitalSite.CmsPageBase.CreateAspx names the
	//  server form element "serverform" we can be certain that the
	//  hard-coded name of the form below will work OK.
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		theform = document.serverform;
	}
	else {
		theform = document.forms["serverform"];
	}

	// Look for DHTML object for the LinkButton.
	var objLinkButton = document.getElementById(strLinkButtonClientID);

	// A variable to store the current value of theform's target property...
	var strFormTarget;

	// A variable to verify that everything will work...
	var blnOK = false;
	if ( typeof __doPostBack == 'function' ) {
		if ( objLinkButton != null ) {
			if ( typeof objLinkButton == 'object' ) {
				if ( theform != null ) {
					if ( typeof theform == 'object' ) {
						if ( theform.target != null ) {
							//alert("theform.target = '" + theform.target + "'");
							strFormTarget = theform.target;
							if ( strFormTarget == "" ) { strFormTarget = "_self"; }
							blnOK = true;
						} else { alert("ERROR! HTML form element 'serverform' has no 'target' attribute!"); }
					} else { alert("ERROR! HTML form element 'serverform' is not an object!"); }
				} else { alert("ERROR! Could not find an HTML form element 'serverform'"); }
			} 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 ) {
		// Open a new window for the printer format page.
		// Do this to be able to set properties of the window,
		//  and to specify that no entry is made in the browser's history list.
		var objNewWindow = window.open("", "PrintFormat", "width=780, height=580, left=10, top=10, channelmode=no, directories=no, fullscreeen=no, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=no", false);
		if ( objNewWindow != null ) {
			theform.target = "PrintFormat";
			try {
				__doPostBack(strLinkButtonPostBackID,'');
			} catch (err) {
				alert("JavaScript error:\n" + err.description);
			}
			theform.target = strFormTarget;
			objNewWindow.focus();
		}
	}
}


// 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=yes, menubar=yes, 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);
}


// Opens a virtual tour.
function strOpenVirtualTourFeatures(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=no, scrollbars=no, status=no, titlebar=no, toolbar=no";
}
var objVirtualTourWindow;
function fnCloseVirtualTour() {
		//	alert("fnCloseVirtualTour()");
	if ( objVirtualTourWindow != null ) { objVirtualTourWindow.close(); }
}
function fnOpenVirtualTour(strWindowURL, iWindowWidth, iWindowHeight) {
		//	alert("strOpenVirtualTourFeatures(" + iWindowWidth + ", " + iWindowHeight + "): '" + strOpenWindowFeatures(iWindowWidth, iWindowHeight) + "'");
	objVirtualTourWindow = window.open(strWindowURL, "VirtualTour", strOpenVirtualTourFeatures(iWindowWidth, iWindowHeight), false);
	// Set focus on the window, so it will come to the top if already open.
	if ( objVirtualTourWindow != null ) {
		objVirtualTourWindow.focus();
	}
}

// Birthplace virtual tours.
function fnBirthsuiteTour() { fnOpenVirtualTour("/vrtour/birthplace/birthsuite1.htm", 400, 386); }
function fnBirthsuiteTourWithBath() { fnOpenVirtualTour("/vrtour/birthplace/birthsuite2.htm", 400, 386); }
function fnCSecTour() { fnOpenVirtualTour("/vrtour/birthplace/csec.htm", 400, 283); }
function fnNICUTour() { fnOpenVirtualTour("/vrtour/birthplace/nicu.htm", 400, 283); }

// Fitness Center virtual tours.
function fnAccelerationTour() { fnOpenVirtualTour("/vrtour/fitness/acceleration.htm", 400, 283); }
function fnGymTour1() { fnOpenVirtualTour("/vrtour/fitness/gym1.htm", 400, 283); }
function fnGymTour2() { fnOpenVirtualTour("/vrtour/fitness/gym2.htm", 400, 283); }

// Katz Cardiovascular Center virtual tours.
function fnCathLabTour() { fnOpenVirtualTour("/vrtour/katz/cathlab.htm", 400, 386); }
function fnCathControlTour() { fnOpenVirtualTour("/vrtour/katz/cathcontrol.htm", 400, 386); }
function fnEPLabTour() { fnOpenVirtualTour("/vrtour/katz/eplab.htm", 400, 283); }

// J. Edward Lundy Pavilion orthopaedics services virtual tours.
function fnOrthSuiteTour() { fnOpenVirtualTour("/vrtour/orthopaedics/suite.htm", 400, 386); }
function fnOrthWaitingRoomTour() { fnOpenVirtualTour("/vrtour/orthopaedics/waiting.htm", 400, 386); }

// Margaret and Howard Hall Radiation Center virtual tour.
function fnHallCenterTour() { fnOpenVirtualTour("/vrtour/radiation/hallcenter.htm", 400, 283); }



// Doctor Survey Psuedo-Popup
// 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();
}
function closeSurveyPopUp() {
	// Cookie setter
	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth() + 6);
	document.cookie = "hasClicked=True;expires=" + expireDate.toGMTString() + ";path=/;";
	document.getElementById("SurveyPopUp").style.display = "none";
}
// Cookie getter
function getCookieValue() {
	var cookieName = "hasClicked";
	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");
	if (cookieStartsAt == -1) {
		cookieStartsAt = cookieValue.indexOf(cookieName + "=");		
	}
	if (cookieStartsAt == -1) {
		cookieValue = null;	
	}
	else {	
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
		var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
		if (cookieEndsAt == -1) {
			cookieEndsAt = cookieValue.length;
		}
		cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt));
	}
	return cookieValue;
}
// Survey Psuedo-Popup
function showSurveyPopUp() {
	var hasClicked = getCookieValue();
	if (hasClicked == null) {		
		document.getElementById("SurveyPopUp").style.display = "block";
	}
}
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
			window.onload = function() {
			oldonload();
			func();
		}
	}
} 

// 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 {
			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;
}

