//////////////////////
// reusablePopup.js //
//////////////////////

// This template contains a reusable popup window function.

// Sample usage: 
//  <!--- include popup code --->
//	<script language="JavaScript" src="/fca_scripts/reusablePopup.js"></script>
//	<a href="javascript: reusablePopup('winPopup','page.html','height=410,width=530,top=80,left=80,resizable,scrollable')">Link</a>
var winPopup // store "link" to popup window
var bitDoubleOpenFail = 0;

function reusablePopup(strWindowName,strPageName,strOptions) {
	var objChild;                           // Window
	var reWork = new RegExp('object','gi');	// Regular expression

	if (!bitDoubleOpenFail){
		try {
			objChild = window.open('','child','width=50,height=50,status=no,resizable=yes'); 
		
			objChild.close();
		}
		catch(e) { }
	}

	if(!reWork.test(String(objChild)) && !bitDoubleOpenFail) {
		alert('Warning: This machine has a pop-up blocker enabled for this site.  Please disable\nit for this site (training.fca.org). This application requires pop-ups to function.\nIf disabling your popup blocker is insuffient, try accessing from another computer.');
		return false
	} else {
		if (winPopup && !winPopup.closed) {
			winPopup.location.href = strPageName
		}
		// open new window
		winPopup = window.open(strPageName,strWindowName,strOptions);
		/* apparently opening 2 popups in a row is not allowed.  If the test window works,
			but the actual window fails, on the second click, bitDoubleOpenFail skips the 
			test and opens the actual window directly */
		if(!reWork.test(String(winPopup))) {
			bitDoubleOpenFail = 1
		} else {
			winPopup.focus();
		}
	}
}