///////////////////////////////////////////////////////////////////
// commonJS.js
// MIO Common Javascript Functions
///////////////////////////////////////////////////////////////////
var layerVisible = false;
var clearImage = "images/quiz_items/blank_unmarked.gif";
var rightImage = "images/quiz_items/yes.gif";
var wrongImage = "images/quiz_items/no.gif";
var dannysCrazyTimeout = 0;
var dannysCrazyListoffeedback = new Array();
var switchChecksIndex=0;
var can_go_next = true;
var hasFlashQuiz = false;
var cptFooter="CPT only &copy; Current Procedural Terminology, 2002, Professional Edition, American Medical Association. All rights reserved.";
var CPT_Footer=cptFooter; //way to be consistent, Danny.

var defaultFeedbackWindowHeight = 300;
var defaultAnitaWindowHeight = 300;
var defaultPopupWindowHeight = 585;

// override these in the template with a full img tag
var nowrap_left_img = '';
var nowrap_right_img = '';

// array of types that bigWrapper will deal with
var bigwrapperCheckedTypes = new Array();
bigwrapperCheckedTypes['radio'] = true
bigwrapperCheckedTypes['checkbox'] = true;
bigwrapperCheckedTypes['select-one'] = true;
bigwrapperCheckedTypes['text'] = true;

// function to be called onClick in "next" link
//  eg. <a href='next.html' onClick="return(checkGoNext)">
function checkGoNext(){
	if(! can_go_next || can_go_next == "false"){
		var text = "Are you sure that you want to continue";
		if(hasFlashQuiz){
			// flash question (no forms)
			text += " without completing this block?";
		}else if(document.forms && document.forms.length == 1){
			// one question (one form)
			text += " without answering this question?";
		}else if(document.forms && document.forms.length > 1){
			// more than one question (more than one form)
			text += " without answering these questions?";
		}else{
			// unknown type (maybe someone just wants to confirm?)
			text += "?";
		}
		can_go_next = confirm(text);
	}
	return can_go_next;
}

function writeChecks(whichBullet)
{
document.write('<a href="javascript:switchChecks(\''+whichBullet+'\');"><img name="'+whichBullet+'" border="0" src="images/objectives/phase_obj_check_box_on.gif" width="38" height="21"></a>');
}

// new feedback object
// usage:
//  new feedbackHolder(goodFeedback, badFeedback)
//  new feedbackHolder(goodFeedback, goodHeight, badFeedback, badHeight)
function feedbackHolder(){
    this.usage = 
	  'var feedback = new feedbackHolder()' + '\n' +
      'feedback.add("elemName", "feedback string", "window height")' + '\n' +
      'feedback.add("elemName", "feedback url")';
	this.goodUrl = false;
	this.badUrl = false;
	this.stuffAdded = false;
	this.add = _feedback_add;
	this.feedbackArray = new Array();
	if(arguments.length){
		alert("error in feedbackHolder creation:\n" + this.usage);
		return false;
	}
	return this;
}

// internal add_feedback function
// args:
//  URL - url to redirect to
// OR
//  feedbackString - string to put in popup window
//  windowHeight - integer height of popup window
function _feedback_add(){
	var newfeedback = false;
	if(arguments.length == 2){
		newfeedback = new _url_feedbackObj(arguments[1]);
	}else if(arguments.length == 3){
		newfeedback = new _window_feedbackObj(arguments[1], arguments[2]);
	}
	this.feedbackArray[arguments[0]] = newfeedback;
	this.stuffAdded = true;
}

// new popup feedback object
// args:
//  feedback - string represenattion of feedback text
//  windowHeight - integer height of feedback window
function _window_feedbackObj(){
	this.isURL = false;
	this.URL = '';
	this.feedback = arguments[0];
	this.windowHeight = arguments[1];
	this.delay = 1000;
	this.showGood = popCorrect;
	this.showGood = delayPopCorrect;
	this.showBad = popWrong;
	this.showBad = delayPopWrong;
	return this;
}

// new redirect feedback object
// args:
//  URL - URL to redirect to
function _url_feedbackObj(){
	this.isURL = true;
	this.URL = arguments[0];
	this.feedback = '';
	this.windowHeight = 0;
	this.delay = 1000;
	this.showGood = gotoPage;
	this.showGood = delayGotoPage;
	this.showBad = gotoPage;
	this.showBad = delayGotoPage;
	return this;
}

// delayed good feedback
function delayGood(){
	clearTimeout(dannysCrazyTimeout);
	//dannysCrazyTimeout = setTimeout(this.goodFunk, this.goodDelayTime);
	//dannysCrazyTimeout = setTimeout("this.goodFunk()", this.goodDelayTime);
	window.tempFeedbackObj = this;
	dannysCrazyTimeout = setTimeout("tempFeedbackObj.goodFunk()", this.goodDelayTime);
}
// delayed bad feedback
function delayBad(){
	clearTimeout(dannysCrazyTimeout);
//	dannysCrazyTimeout = setTimeout(this.badFunk, this.badDelayTime);
	window.tempFeedbackObj = this;
	dannysCrazyTimeout = setTimeout("tempFeedbackObj.badFunk()", this.badDelayTime);
}

// onClick check function
function clickCheck(daElem){
	clearTimeout(dannysCrazyTimeout);
	var daForm = daElem.form;
	if(eval("window." + daForm.name + "Feedback")){
		var feedbackObj = eval(daForm.name + "Feedback");
	}else{
		alert("Please define the feedback object for form "+ daForm.name +".");
		return false;
	}
	
	var feedbackName = daElem.name;
	if(daElem.type == 'radio'){
		feedbackName = daElem.name + '-' + daElem.value;
	}
	
	var rval = false;
	clearImages(daForm);
	can_go_next = true;
	var daImage = getImage(feedbackName);
	if(daElem.value == 0){
		// 0 = right
		daImage.src = rightImage;
		if(feedbackObj.feedbackArray[feedbackName]){
			feedbackObj.feedbackArray[feedbackName].showGood();
		}
		rval = true;
	}else{
		// non-zero = wrong
		daImage.src = wrongImage;
		if(feedbackObj.feedbackArray[feedbackName]){
			feedbackObj.feedbackArray[feedbackName].showBad();
		}
	}
	return rval;
}

function submitCheck(daForm){
	var checked = new Array();
	for(var i=0; i < daForm.elements.length; i++){
		var daElem = daForm.elements[i];
		if(daElem.type && !checked[daElem.type]){
			switch (daElem.type){
				case 'radio':
					checkRadio(daForm, false);
					break;
				case 'checkbox':
					checkCheck(daForm, false);
					break;
				default:
					break;
			}
		}
	}
}

// wraps any "check" function that returns true if all right
//  and false if any wrong.  checkCheck, checkRadio, etc...
//  the function must accept the form name as the first arg
//  and true/false as a second arg (to alert on error)
// form follows function. :)
// daFunction can be an array of functions to apply multiple tests
//  whose results are ANDed together.  This should be an array of
//  functions - not string representations of function names...
// update: can be called with one arg - a form name
//  this requires that a check function be defined either as a
//  variable (form1 would require a variable called form1Checks)
//  that can be either a single function (form1Checks=checkRadio)
//  or an array of functions (form1Checks=new Array(checkRadio, checkCheck))
// updateAgain:
//  now works with object-oriented feedback by taking the first
//  correct element and the first incorrect element in the form
//  and using their feedback for allright and allwrong, respectively.
// further update:
//  now works with forms that have either all correct or all incorrect
function bigWrapper(daFunction, daForm){
	clearTimeout(dannysCrazyTimeout);
	if(arguments.length == 1){
		daForm = arguments[0];
		if(eval("window." + daForm.name + "Checks")){
			daFunction = eval(daForm.name + "Checks");
		}else{
			alert(form2Checks);
			alert('bad call to bigWrapper - define ' + daForm.name + 'Checks');
		}
	}
	var correctName = "correct" + daForm.name;
	var wrongName = "wrong" + daForm.name;
	if(typeof(daFunction) == 'function'){
		var allRight = daFunction(daForm, false);
	}else{
		var allRight = daFunction[0](daForm, false);
		for(var i=1; i<daFunction.length; i++){
			allRight = daFunction[i](daForm, false) ? allRight : false;
			// apperently, this next way doesn't work.  Sigh.
			// allRight = (allRight && daFunction[i](daForm, false));
		}
	}
	if(eval("window." + daForm.name + "Feedback")){
		var feedback = eval(daForm.name + "Feedback");
		can_go_next = true;
	}else{
		alert("you forgot to define the feedback object for form " + daForm.name + ".");
	}

	if(feedback.stuffAdded){
		// new style feedback
		// find the first correct and first incorrect feedback objects
		var firstCorrect = false;
		var firstIncorrect = false;
		var elemType = false;
		for(var i=0; i<daForm.elements.length; i++)
		{
			var daElem = daForm.elements[i];
			if(bigwrapperCheckedTypes[daElem.type]){
				var daVal = daElem.value;
				elemType = daElem.type;
				if(!firstCorrect && daVal == 0){
					firstCorrect = daElem.name;
					if(daElem.type == 'radio'){
						firstCorrect = daElem.name + '-' + daElem.value;
					}
				}else if(!firstIncorrect && daVal != 0){
					firstIncorrect = daElem.name;
					if(daElem.type == 'radio'){
						firstIncorrect = daElem.name + '-' + daElem.value;
					}
				}
			}
			if(firstCorrect && firstIncorrect){
				i=daForm.elements.length; // I distrust "break"... :)
			}
		}
		// use daForm.name in case there are no incorrect / no correct
		if(!firstCorrect){
			firstCorrect = daForm.name;
		}
		if(!firstIncorrect){
			firstIncorrect = daForm.name;
		}
		// do something with getSelected to show feedback for the
		//  currently selected object if the element types are "radio" or
		//  "select-one"
		// do something even more different if the object is type text...
		if(allRight && feedback.feedbackArray[firstCorrect]){
				feedback.feedbackArray[firstCorrect].showGood();
		}else if(feedback.feedbackArray[firstIncorrect]){
				feedback.feedbackArray[firstIncorrect].showBad();
		}
	}else{
		// old style feedback
		if(allRight){
			if(feedback.goodUrl){
				gotoPage(feedback.good);
			}else{
				popCorrect(feedback.good);
			}
		}else{
			if(feedback.badUrl){
				gotoPage(feedback.bad);
			}else{
				popWrong(feedback.bad);
			}
		}
	}

	return allRight;
}

function switchChecks(whichBullet)
{	
	var offImage="images/objectives/phase_obj_check_box_off.gif";
	var onImage="images/objectives/phase_obj_check_box_on.gif";
	var currentImage=getTheImage(whichBullet).src; 
	if(currentImage.match("off.gif"))
	{
		MM_swapImage(whichBullet,'',onImage,1);
		switchChecksIndex--;	
	}
	else
	{
		MM_swapImage(whichBullet,'',offImage,1);
		switchChecksIndex++;	
	}
	if(switchChecksIndex==switchChecksTotal)
	{
		gotoPage(switchChecksNextPage);
	}
	
}

// returns an image object with the given name
function getTheImage(daName){
	return eval("document.images['" + daName + "']");
}

function setLayerVisible(yup)
{
		layerVisible=yup;
}

function openWindowBigger(thisPage)
{
	biggerWindow = window.open(thisPage,'newWin','width=650, height=500, scrollbars=yes,toolbar=no,location=no,resizable=no');
	biggerWindow.focus();
}

function openWindow(thisPage, howHigh)
{
	if(!howHigh)
	{
		howHigh = 400; //default
	}
	newTom2 = window.open(thisPage,'newTom2','width=620,height='+howHigh+',scrollbars=yes,toolbar=no,location=no,resizable=yes');
	newTom2.focus();
}

//function openPages(whichStep) //not actual step number, just the index of this one for this phase.
//{
//	var fiber="pages_"+whichStep+".html";
//	horkinFiberChunks = window.open(fiber,'horkinFiberChunks','width=400,height=300,scrollbars=yes,toolbar=no,location=no,resizable=yes');
//}

function openPages(whichPhase, whichStep) //not actual step number, just the index of this one for this phase.
{
var fiber="pages_phs"+whichPhase+".html";
if(arguments.length > 1){
	fiber="pages_phs"+whichPhase+"_step"+whichStep+".html";
}
horkinFiberChunks =
window.open(fiber,'horkinFiberChunks','width=400,height=300,scrollbars=yes,toolbar=no,location=no,resizable=yes');
horkinFiberChunks.focus();
}

function openWord(thisPage)
{
	newTom3 = window.open(thisPage,'newWin2','width=405,height=300,scrollbars=yes,toolbar=no,location=no,resizable=no');
	newTom3.focus();
}

function delayGotoPage(thisPage){
	clearTimeout(dannysCrazyTimeout);
	dannysCrazyTimeout = setTimeout("gotoPage('"+this.URL+"')", this.delay);
}

function gotoPage(thisPage)
{
	if(arguments.length == 0){
		// method call
		window.location = this.URL;
	}else{
		// regular call
		window.location = thisPage;
	}
}

// wide (585px) popup window with text
function popWideWindow(displayText, howHigh){
	return popWindow(displayText, howHigh, 585);
}

function popClinic()
{
	largeClinic = window.open("floorplan.html",'largeClinic','width=600,height=500,scrollbars=yes,toolbar=no,location=no,resizable=yes');		
	largeClinic.focus();
}

function popLifecycle(whichOne) //will probably have to change
{
	if(!whichOne)
	{
		largeCycle = window.open("lifecycle.html",'largeCycle','width=600,height=599,scrollbars=yes,toolbar=no,location=no,resizable=yes');		
	}
	else
	{
		whichOne=whichOne.toLowerCase();
		whichOne=whichOne+".html";
		largeCycle = window.open(whichOne,'largeCycle','width=600,height=599,scrollbars=yes,toolbar=no,location=no,resizable=yes');			
	}
	largeCycle.focus();
}


function popGlossary(whichFile)
{
	if(!whichFile) //no word, display all.			
	{
		largeGlossary = window.open("macrogloss/mio_glossary.html",'largeGlossary','width=600,height=400,scrollbars=yes,toolbar=no,location=no,resizable=yes');		
		largeGlossary.focus();
	}
	else
	{
		howWide=380;
		whichFile = whichFile.replace(/ /g, '_');
		//display "whichFile" file
		glossary_file="mio_glossary/"+whichFile+".html";
		smallGlossary=window.open(glossary_file,'smallGlossary','width=400,height=400,scrollbars=yes,toolbar=no,location=no,resizable=yes');		
		smallGlossary.focus();
	}	 	
}
function popAnita(displayText,howHigh,wrap) //anita's advice
{
	if(!howHigh)			
	  var howHigh = defaultAnitaWindowHeight;
	
	var anitaText='<html><head><title>Anita\'s Advice</title><link href="mio.css" rel="stylesheet" type="text/css">\n';
    anitaText+='<script>\n';
    anitaText+='function MM_swapImage() { //v3.0\n';
    anitaText+='  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)\n';
    anitaText+='   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}\n';
    anitaText+='}\n';
    anitaText+='function MM_swapImgRestore() { //v3.0\n';
    anitaText+='  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;\n';
    anitaText+='}\n';
    anitaText+='function MM_findObj(n, d) { //v4.0\n';
    anitaText+='var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {\n';
    anitaText+='d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}\n';
    anitaText+='  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];\n';
    anitaText+='  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);\n';
    anitaText+=' if(!x && document.getElementById) x=document.getElementById(n); return x;\n';
	anitaText+='}\n';
    anitaText+='</script></head>\n';
	anitaText+='<body>\n';
	anitaText+='<center><table width="360" border="0" cellspacing="0" cellpadding="0">\n';
	anitaText+='<tr valign="top"><td rowspan="2" height="216" width="56"><img src="images/popUp/advice/pop_hdr_advice_col1.jpg" width="56" height="216"></td>\n';
    anitaText+='<td width="285" height="42"><img src="images/popUp/advice/pop_hdr_advice_col2.jpg" width="285" height="42"></td>\n';
    anitaText+='<td width="109" height="42"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'mrCloseButton\',\'\',\'images/popUp/advice/pop_hdr_advice_close_mo.jpg\',1)"><img name="mrCloseButton" border="0" src="images/popUp/advice/pop_hdr_advice_close.jpg" width="109" height="42"></a></td></tr>\n';
    if(!wrap){
	  anitaText+='<tr><td valign="top"><br><div class="anita">'+displayText+'</div></td>\n';
      anitaText+='<td width="109" height="174" valign="top"><img src="images/popUp/advice/pop_hdr_advice_col3_anita1.jpg" width="109" height="174"></td></tr><tr><td colspan="3" align="center"><br><img src="images/framework/divider_fullwidth_360.gif" width="430" height="7"><br><div class="footer">Copyright &copy 2004, Elsevier (USA). All rights reserved.</div></td></tr></table></center></body></html>\n';
	}else{
      anitaText+='<tr><td valign="top" colspan=2><br><img src="images/popUp/advice/pop_hdr_advice_col3_anita1.jpg" width="109" height="174" align=right><div class="anita">'+displayText+'</div>\n';
      anitaText+='</td></tr><tr><td colspan="3" align="center"><br><img src="images/framework/divider_fullwidth_360.gif" width="430" height="7"><br><div class="footer">Copyright &copy 2004, Elsevier (USA). All rights reserved.</div></td></tr></table></center></body></html>\n';  	
	} 
    
    anitaBath = window.open("",'anitaBath','width=490,height='+howHigh+',scrollbars=yes,toolbar=no,location=no,resizable=yes');
    anitaBath.document.write(anitaText);
    anitaBath.document.close();
    anitaBath.focus();
}

function popStory(displayText,howHigh) //The Rest of the Story
{
	if(!howHigh)			
	  var howHigh = defaultAnitaWindowHeight+50;
	
	var returnToTop='<tr><td colspan="3"><table width="541" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top"><a href="javascript:window.scroll(0,0);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'ToTop\',\'\',\'images/framework/btn_btm_return_top_sm_mo.gif\',1)"><img name="ToTop" border="0" src="images/framework/btn_btm_return_top_sm.gif" width="93" height="15"></a></td>';
    returnToTop+='<td valign="top" align="right"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'mrCloseUm\',\'\',\'images/popUp/btn_btm_close_mo.gif\',1)"><img name="mrCloseUm" border="0" src="images/popUp/btn_btm_close.gif" width="72" height="15"></a></td></tr></table></td></tr>';
    var divider= '<tr align="center" valign="top"><td colspan="3"><img src="images/framework/divider_fullwidth_560.gif" width="560" height="7"><br><div class="footer">Copyright &copy 2004, Elsevier (USA). All rights reserved.</div></td></tr>';
		
	
	var storyText='<html><head><title>The Rest of the Story</title><link href="mio.css" rel="stylesheet" type="text/css">\n';
    storyText+='<script>\n';
    storyText+='function MM_swapImage() { //v3.0\n';
    storyText+='  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)\n';
    storyText+='   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}\n';
    storyText+='}\n';
    storyText+='function MM_swapImgRestore() { //v3.0\n';
    storyText+='  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;\n';
    storyText+='}\n';
    storyText+='function MM_findObj(n, d) { //v4.0\n';
    storyText+='var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {\n';
    storyText+='d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}\n';
    storyText+='  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];\n';
    storyText+='  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);\n';
    storyText+=' if(!x && document.getElementById) x=document.getElementById(n); return x;\n';
	storyText+='}\n';
    storyText+='</script></head>\n';
	storyText+='<body>\n';
	storyText+='<center><table width="360" border="0" cellspacing="0" cellpadding="0">\n';
	storyText+='<tr valign="top"><td height="24" width="91"><img src="images/pop_hdr_reststory_c1r1.gif" width="91" height="24"></td><td width="392" height="12"><img src="images/pop_hdr_reststory_c2r1.gif" width="392" height="24"></td>\n';
	storyText+='<td width="77" height="12"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'mrCloseButton\',\'\',\'images/pop_btn_reststory_close_mo.gif\',1)"><img name="mrCloseButton" border="0" src="images/pop_btn_reststory_close.gif" width="77" height="24"></a></td></tr>\n';
	storyText+='<tr valign="top"><td height="54" width="91"><img src="images/pop_hdr_reststory_c1r2.gif" width="91" height="54"></td><td colspan="2" height="54"><img src="images/pop_hdr_reststory_c2r2.gif" width="469" height="54"></td></tr>\n';
	storyText+='<tr><td valign="top" height="174" width="56">&nbsp;</td><td valign="top"><br>\n';
	storyText+='<div class="anita">'+displayText+'</div></td><td height="174" valign="top">&nbsp;</td></tr>\n';
    storyText+=returnToTop;
    storyText+=divider;
    storyText+='</table></center></body></html>';
	//storyText+='<td height="174" valign="top">&nbsp;</td></tr><tr><td colspan="3" align="center"><br><img src="images/framework/divider_fullwidth_360.gif" width="430" height="7"><br>\n';
	//storyText+='<div class="footer">Copyright &copy 2004, Elsevier (USA). All rights reserved.</div></td></tr></table></center></body></html>\n';
    
    storyWindow = window.open("",'storyWindow','width=600,height='+howHigh+',scrollbars=yes,toolbar=no,location=no,resizable=yes');
    storyWindow.document.write(storyText);
    storyWindow.document.close();
    storyWindow.focus();
}

function popInsurance(displayText,howHigh) 
{
	var returnToTop='<tr><td colspan="2"><table width="450" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top"><a href="javascript:window.scroll(0,0);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'ToTop\',\'\',\'images/framework/btn_btm_return_top_sm_mo.gif\',1)"><img name="ToTop" border="0" src="images/framework/btn_btm_return_top_sm.gif" width="93" height="15"></a></td>';
    returnToTop+='<td valign="top" align="right"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'mrCloseUm\',\'\',\'images/popUp/btn_btm_close_mo.gif\',1)"><img name="mrCloseUm" border="0" src="images/popUp/btn_btm_close.gif" width="72" height="15"></a></td></tr></table></td></tr>';
            
	if(!howHigh)			
	  var howHigh =300;
var insureText='<html><head><title>Experience Files</title>';
	insureText+='<link href="mio.css" rel="stylesheet" type="text/css">\n';
    insureText+='<script>\n';
    insureText+='function MM_swapImage() { //v3.0\n';
    insureText+='  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)\n';
    insureText+='   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}\n';
    insureText+='}\n';
    insureText+='function MM_swapImgRestore() { //v3.0\n';
    insureText+='  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;\n';
    insureText+='}\n';
    insureText+='function MM_findObj(n, d) { //v4.0\n';
    insureText+='var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {\n';
    insureText+='d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}\n';
    insureText+='  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];\n';
    insureText+='  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);\n';
    insureText+=' if(!x && document.getElementById) x=document.getElementById(n); return x;\n';
	insureText+='}\n';
    insureText+='</script>';
    insureText+='</head>';
    insureText+='<body bgcolor="#FFFFFF" text="#000000"><Center><table width="450" border="0" cellspacing="0" cellpadding="0">';
    insureText+='<tr valign="top"><td height="57" width="373"><img src="images/lounge/pop_hdr_exp_files.jpg" width="373" height="57"></td>';
    insureText+='<td width="77" height="57"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'closeUm\',\'\',\'images/lounge/pop_hdr_exp_files_close_mo.jpg\',1)"><img name="closeUm" border="0" src="images/lounge/pop_hdr_exp_files_close.jpg" width="77" height="57"></a></td></tr>';
    insureText+='<tr><td colspan="2" align="center"><table width="450" border="0" cellspacing="0" cellpadding="0">';
    insureText+='<tr><td width="13"><p><img src="images/spacer.gif" width="13" height="1"></p></td>';
    insureText+='<td><div class="anita"><!-- Glossary text -->';
    insureText+=displayText; 
    insureText+='<!-- End Glossary text --><br><br></div></td></tr>'+returnToTop+'<tr><td colspan="2"><img src="images/framework/divider_fullwidth_360.gif" width="450" height="7"><br>';
    insureText+='<div class="footer">Copyright &copy 2004, Elsevier (USA). All rights reserved.</div></td></tr></table></td></tr></table></center></body></html>';
    
    insureWindow = window.open("",'insureWindow','width=500,height='+howHigh+',scrollbars=yes,toolbar=no,location=no,resizable=yes');
    //insureText="<html><head><title>ZIggy</title><Script></script></head><body>Help</body></html>";
    insureWindow.document.write(insureText);
    insureWindow.document.close();
    insureWindow.focus();
}

function popBrick(displayText,howHigh) 
{
	var returnToTop='<tr><td colspan="2"><table width="450" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top"><a href="javascript:window.scroll(0,0);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'ToTop\',\'\',\'images/framework/btn_btm_return_top_sm_mo.gif\',1)"><img name="ToTop" border="0" src="images/framework/btn_btm_return_top_sm.gif" width="93" height="15"></a></td>';
        returnToTop+='<td valign="top" align="right"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'mrCloseUm\',\'\',\'images/popUp/btn_btm_close_mo.gif\',1)"><img name="mrCloseUm" border="0" src="images/popUp/btn_btm_close.gif" width="72" height="15"></a></td></tr></table></td></tr>';
            
	if(!howHigh)			
	  var howHigh =300;
    var insureText='<html><head><title>Experience Files</title>';
	insureText+='<link href="mio.css" rel="stylesheet" type="text/css">\n';
    insureText+='<script>\n';
    insureText+='function MM_swapImage() { //v3.0\n';
    insureText+='  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)\n';
    insureText+='   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}\n';
    insureText+='}\n';
    insureText+='function MM_swapImgRestore() { //v3.0\n';
    insureText+='  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;\n';
    insureText+='}\n';
    insureText+='function MM_findObj(n, d) { //v4.0\n';
    insureText+='var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {\n';
    insureText+='d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}\n';
    insureText+='  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];\n';
    insureText+='  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);\n';
    insureText+=' if(!x && document.getElementById) x=document.getElementById(n); return x;\n';
	insureText+='}\n';
    insureText+='</script>';
    insureText+='</head>';
    insureText+='<body bgcolor="#FFFFFF" text="#000000"><Center><table width="450" border="0" cellspacing="0" cellpadding="0">';
    insureText+='<tr valign="top"><td height="57" width="373"><img src="images/lounge/pop_hdr_exp_files.jpg" width="373" height="57"></td>';
    insureText+='<td width="77" height="57"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'closeUm\',\'\',\'images/lounge/pop_hdr_exp_files_close_mo.jpg\',1)"><img name="closeUm" border="0" src="images/lounge/pop_hdr_exp_files_close.jpg" width="77" height="57"></a></td></tr>';
    insureText+='<tr><td colspan="2" align="center"><table width="450" border="0" cellspacing="0" cellpadding="0">';    
    insureText+='<td><div class="anita"><!-- Glossary text -->';
    insureText+=displayText; 
    insureText+='<!-- End Glossary text --><br><br></div></td></tr>'+returnToTop+'<tr><td colspan="2"><img src="images/framework/divider_fullwidth_360.gif" width="450" height="7"><br>';
    insureText+='<div class="footer">Copyright &copy 2004, Elsevier (USA). All rights reserved.</div></td></tr></table></td></tr></table></center></body></html>';
    
    insureWindow = window.open("",'insureWindow','width=500,height='+howHigh+',scrollbars=yes,toolbar=no,location=no,resizable=yes');
    //insureText="<html><head><title>ZIggy</title><Script></script></head><body>Help</body></html>";
    insureWindow.document.write(insureText);
    insureWindow.document.close();
    insureWindow.focus();
}

// method call only - PITA to make work both ways :(
function delayPopCorrect(){
	
	clearTimeout(dannysCrazyTimeout);
	dannysCrazyTimeout = setTimeout("popCorrect('"+
	                     this.feedback.replace(/'/g, "\\'")+
						 "', " + this.windowHeight + 
						 ", " + this.delay + 
						 ")", this.delay);
}

// method call only - PITA to make work both ways :(
function delayPopWrong(){
	
	clearTimeout(dannysCrazyTimeout);
	dannysCrazyTimeout = setTimeout("popWrong('"+
	                     this.feedback.replace(/'/g, "\\'")+
						 "', " + this.windowHeight + 
						 ", " + this.delay + 
						 ")", this.delay);
}

function popCorrect(displayText,howHigh) //anita's advice
{
	var delay = 0;
	if(arguments.length == 0){
		// method call
		var howHigh = this.windowHeight;
		var displayText = this.feedback;
		delay = this.delay;
	}
	if(arguments.length < 3){
		delay = arguments[2];
	}
	if(!howHigh){
		// called w/ one arg
		var howHigh = defaultFeedbackWindowHeight;
	}
	
	var anitaText='<html><head><title>Yes!</title><link href="mio.css" rel="stylesheet" type="text/css">\n';
    anitaText+='<script>\n';
    anitaText+='MM_preloadImages = opener.MM_preloadImages;\n';
    anitaText+='function MM_swapImage() { //v3.0\n';
    anitaText+='  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)\n';
    anitaText+='   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}\n';
    anitaText+='}\n';
    anitaText+='function MM_swapImgRestore() { //v3.0\n';
    anitaText+='  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;\n';
    anitaText+='}\n';
    anitaText+='function MM_findObj(n, d) { //v4.0\n';
    anitaText+='var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {\n';
    anitaText+='d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}\n';
    anitaText+='  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];\n';
    anitaText+='  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);\n';
    anitaText+=' if(!x && document.getElementById) x=document.getElementById(n); return x;\n';
	anitaText+='}\n';
    anitaText+='</script></head>\n';
	anitaText+='<body onLoad="MM_preloadImages(\'images/popUp/advice/pop_hdr_advice_close_mo.jpg\')"><center>\n';
	anitaText+='<table width="360" border="0" cellspacing="0" cellpadding="0"><tr> \n';
	anitaText+='<td width="33" height="50"><img src="images/popUp/feedback/pop_hdr_pos_col1_icon.jpg" width="33" height="50"></td>\n';
	anitaText+='<td width="254" height="50"><img src="images/popUp/feedback/pop_hdr_pos_col2_title.jpg" width="254" height="50"></td>\n';
	anitaText+='<td width="73" height="50"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'closeIt\',\'\',\'images/popUp/feedback/pop_hdr_pos_col3_close_mo.jpg\',1)"><img name="closeIt" border="0" src="images/popUp/feedback/pop_hdr_pos_col3_close.jpg" width="73" height="50"></a></td></tr>\n';
	anitaText+='<tr><td>&nbsp;</td><td colspan="2"><div class="feedback_yes"><!-- feedback text start -->\n';
	anitaText+=displayText;
	anitaText+='<!-- feedback text end --></div></td></tr></table></center></body></html>\n';
    
    anitaBath = window.open('','feedBath','width=385,height='+howHigh+',scrollbars=no,toolbar=no,location=no,resizable=yes');
    anitaBath.document.write(anitaText);
    anitaBath.document.close();
    anitaBath.focus();
}

function popWrong(displayText,howHigh) //anita's advice
{	
	if(arguments.length == 0){
		// method call
		var howHigh = this.windowHeight;
		var displayText = this.feedback;
	}
	if(!howHigh){
		// called w/ one arg
		var howHigh = defaultFeedbackWindowHeight;
	}
	
	var anitaText='<html><head><title>No.</title><link href="mio.css" rel="stylesheet" type="text/css">\n';
    anitaText+='<script>\n';
    anitaText+='MM_preloadImages = opener.MM_preloadImages;\n';
    anitaText+='function MM_swapImage() { //v3.0\n';
    anitaText+='  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)\n';
    anitaText+='   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}\n';
    anitaText+='}\n';
    anitaText+='function MM_swapImgRestore() { //v3.0\n';
    anitaText+='  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;\n';
    anitaText+='}\n';
    anitaText+='function MM_findObj(n, d) { //v4.0\n';
    anitaText+='var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {\n';
    anitaText+='d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}\n';
    anitaText+='  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];\n';
    anitaText+='  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);\n';
    anitaText+=' if(!x && document.getElementById) x=document.getElementById(n); return x;\n';
	anitaText+='}\n';
    anitaText+='</script></head>\n';
	anitaText+='<body onLoad="MM_preloadImages(\'images/popUp/advice/pop_hdr_advice_close_mo.jpg\')"><center>\n';
	anitaText+='<table width="360" border="0" cellspacing="0" cellpadding="0"><tr> \n';
	anitaText+='<td width="33" height="50"><img src="images/popUp/feedback/pop_hdr_neg_col1_icon.jpg" width="33" height="50"></td>\n';
	anitaText+='<td width="254" height="50"><img src="images/popUp/feedback/pop_hdr_neg_col2_title.jpg" width="254" height="50"></td>\n';
	anitaText+='<td width="73" height="50"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'closeIt\',\'\',\'images/popUp/feedback/pop_hdr_neg_col3_close_mo.jpg\',1)"><img name="closeIt" border="0" src="images/popUp/feedback/pop_hdr_neg_col3_close.jpg" width="73" height="50"></a></td></tr>\n';
	anitaText+='<tr><td>&nbsp;</td><td colspan="2"><div class="feedback_no"><!-- feedback text start -->\n';
	anitaText+=displayText;
	anitaText+='<!-- feedback text end --></div></td></tr></table></center></body></html>\n';
    
    anitaBath = window.open("",'feedBath','width=385,height='+howHigh+',scrollbars=no,toolbar=no,location=no,resizable=yes');
    anitaBath.document.write(anitaText);
    anitaBath.document.close();
    anitaBath.focus();
}

// narrow (385px) popup window with text
var popUseScrollbars = false;
var popCPTFooter = false;

function popWindow(displayText,howWide,howHigh,collapse)
{

		var scroll = popUseScrollbars ? 'yes' : 'no';
		var showTheCPTFooter = popCPTFooter ? "<br>"+cptFooter : '';
		
		
		
		var some_random_number = Math.floor(Math.random()*1000);        
	   // if(window.snapCrackle && !snapCrackle.closed)                         
       //       window.snapCrackle.close();
		
		if(!collapse)
		{
			leftMargin='<td>&nbsp;</td><td colspan="2">';
			tomCenterThingy="";
		}
		else if(collapse==true)
		{
			leftMargin='<td colspan="3">';
			tomCenterThingy=' align="center"';
		}
		                  
		  
		if(!howWide)
		{
		  if(!howHigh)
  		  {
  		  	howHigh = 300; 
  		  }
		  howWide =385
		}
		else
		{
			if(howWide=="wide")
			{
				howWide=585;
				if(!howHigh)
				{
  		  			howHigh = 530; 
  		  		}
  		  	}
			else
			{
				howWide=385;
				if(!howHigh)
				{
  		  			howHigh = 300; 
  		  		}				
			}
		}
	
		if(popUseScrollbars)
		{
				howWide += 25;
		}

		if(howHigh > 450)
		{
			topWindow='top="0",';	
		}
		else
		{
			topWindow='';	
		}

		if(howWide <= 410){			
		    var header = '<table width="360" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td width="19" height="49"><img src="images/popUp/360/pop_hdr_360_col1.gif" width="19" height="49"></td><td width="264" height="49"><img src="images/popUp/360/pop_hdr_360_col2.gif" width="264" height="49"></td>';
			var header_right = 'images/popUp/360/pop_hdr_360_close.gif';
			var header_right_mo = 'images/popUp/360/pop_hdr_360_close_mo.gif';
			snapCrackle = window.open("",'snapCrackle','width='+howWide+',height='+howHigh+',scrollbars='+scroll+',toolbar=no,location=no,resizable=yes');
			var returnToTop='';
            var divider= '<tr align="center" valign="top"><td colspan="3"><img src="images/framework/divider_fullwidth_360.gif" width="360" height="7"><br><div class="footer">Copyright &copy 2004, Elsevier (USA). All rights reserved.</div></td></tr>';
		}else if(howWide >= 585){
		    var header = '<table width="560" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td width="19" height="49"><img src="images/popUp/560/pop_hdr_560_col1.gif" width="19" height="49"></td><td width="464" height="49"><img src="images/popUp/560/pop_hdr_560_col2.gif" width="464" height="49"></td>';
			var header_right = 'images/popUp/560/pop_hdr_560_close.gif';
			var header_right_mo = 'images/popUp/560/pop_hdr_560_close_mo.gif';
			snapCrackle = window.open("",'snapCrackle'+some_random_number,'width='+howWide+',height='+howHigh+','+topWindow+'scrollbars='+scroll+',toolbar=no,location=no,resizable=yes');
			var returnToTop='<tr><td colspan="3"><table width="560" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top"><a href="javascript:window.scroll(0,0);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'ToTop\',\'\',\'images/framework/btn_btm_return_top_sm_mo.gif\',1)"><img name="ToTop" border="0" src="images/framework/btn_btm_return_top_sm.gif" width="93" height="15"></a></td>';
            returnToTop+='<td valign="top" align="right"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'mrCloseUm\',\'\',\'images/popUp/btn_btm_close_mo.gif\',1)"><img name="mrCloseUm" border="0" src="images/popUp/btn_btm_close.gif" width="72" height="15"></a></td></tr></table></td></tr>';
            var divider= '<tr align="center" valign="top"><td colspan="3"><img src="images/framework/divider_fullwidth_560.gif" width="560" height="7"><br><div class="footer">Copyright &copy 2004, Elsevier (USA). All rights reserved.'+showTheCPTFooter+'</div></td></tr>';
		}
		else if(howWide > 385 && howWide < 585){
			var header = '<table width="561" border="0"><tr><td colspan="2" width="560"><table border="0" width="560" cellpadding="0" cellspacing="0"><tr valign="top"><td><img src="images/popup_560p_hdr.jpg" width="486" height="40"></td>';
			var header_right = 'images/popup_560p_close_btn.jpg';
			var header_right_mo = 'images/popup_560p_close_mo.jpg';
			snapCrackle = window.open("",'snapCrackle','width='+howWide+',height='+howHigh+',scrollbars='+scroll+',toolbar=no,location=no,resizable=yes');
            var divider= '<img src="images/Divider_multicolor_550x8.gif">';
		}
		//var dividerSpace =
		//    (displayText.indexOf(toTopTable) == -1) ? '<br><br>' : '';      	
	
        with(snapCrackle.document){
        clear();
        write('<html><head><title>Popup</title>');
        write('<link href="mio.css" rel="stylesheet" type="text/css">\n');
        write('<script>\n');
        write('function MM_swapImage() { //v3.0\n');
        write('  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)\n');
        write('   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}\n');
        write('}\n');
        write('function MM_swapImgRestore() { //v3.0\n');
        write('  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;\n');
        write('}\n');
        write('function MM_findObj(n, d) { //v4.0\n');
        write('var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {\n');
        write('d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}\n');
        write('  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];\n');
        write('  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);\n');
        write(' if(!x && document.getElementById) x=document.getElementById(n); return x;\n');
		write('}\n');
        write('</script>\n');
        write('</head>');
        write('<body><center>');
        write(header);
        write('<td><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'mrCloseButton\',\'\',\''+header_right_mo+'\',1)">');
        write('<img name="mrCloseButton" border="0" src="'+header_right+'" width="77" height="49"></a></td>');
        write('</tr><tr>'+leftMargin+'<div class="text_area"'+tomCenterThingy+'>');
        write(displayText);
        write('</div><br></td></tr>');
        write(returnToTop);
        write(divider);
        write('</table></center></body></html>');
        close();
		}	
	snapCrackle.focus();
}

function popForm(whichForm)
{
		var form1_1Image="form_pif_blank.gif"; //phase#_form#
		var form1_2Image="form_b_idcard_blank.gif";
		var form1_3Image="form_ledger_blank.gif";
		var form1_4Image="form_encounter_blank.gif";
		var form1_5Image="form_e_medchart_blank.gif";
		var form1_1_AImage="form_pif_mpw_mod9a2.gif"; //phase#_form#
		var form1_2_AImage="form_inscard_mpw_mod9b2.gif";
		var form1_3_AImage="form_ledger_mod9c2.gif";
		var form1_4_AImage="form_encounter_mpw_mod9d2.gif";
		var form1_5_AImage="form_e_medchart_mod9e2.gif";
		var form1_1_BImage="form_pif_nbf_mod9a3.gif"; //phase#_form#
		var form1_2_BImage="form_inscard_nbf_mod9b3.gif";
		var form1_3_BImage="form_ledger_mod9c3.gif";
		var form1_4_BImage="form_encounter_nbf_mod9d3.gif";
		var form1_5_BImage="form_e_medchart_mod9e3.gif";
		
		var form2_1Image="form_pif_blank.gif"; //phase#_form#
		var form2_2Image="form_b_idcard_blank.gif";
		var form2_3Image="form_ledger_blank.gif";
		var form2_4Image="form_encounter_blank.gif";
		var form2_5Image="form_e_medchart_blank.gif";
		var form2_1_AImage="form_pif_jcw_mod9a4.gif"; //phase#_form#
		var form2_2_AImage="form_inscard_jcw_mod9b4.gif";
		var form2_3_AImage="form_ledger_mod9c4.gif";
		var form2_4_AImage="form_encounter_jcw_mod9d4.gif";
		var form2_5_AImage="form_e_medchart_mod9e4.gif";
		
		var form3_1Image="form_pif_blank.gif"; //phase#_form#
		var form3_2Image="form_b_idcard_blank.gif";
		var form3_3Image="form_ledger_blank.gif";
		var form3_4Image="form_encounter_blank.gif";
		var form3_5Image="form_e_medchart_blank.gif";
		var form3_1_AImage="form_pif_jad_mod9a5.gif"; //phase#_form#
		var form3_2_AImage="form_inscard_jad_mod9b5.gif";
		var form3_3_AImage="form_ledger_mod9c5.gif";
		var form3_4_AImage="form_encounter_jad_mod9d5.gif";
		var form3_5_AImage="form_e_medchart_mod9e5.html";
		var form3_1_BImage="form_pif_pkh_mod9a6.gif"; //phase#_form#
		var form3_2_BImage="form_inscard_pkh_mod9b6.html";
		var form3_3_BImage="form_ledger_mod9c6.gif";
		var form3_4_BImage="form_encounter_pmk_mod9d6.gif";
		var form3_5_BImage="form_e_medchart_mod9e6.html";
		
		var form0_1Image=form1_1Image;
		var form0_2Image=form1_2Image;
		var form0_3Image=form1_3Image;
		var form0_4Image=form1_4Image;
		var form0_5Image=form1_5Image;
		
		var pdf1="images/form_a_pif_blank.pdf";
		var pdf2="images/form_b_inscard_jenna.pdf";
		var pdf3="images/ledger_card.pdf";
		var pdf4="images/form_encounter_blank.pdf";
		var pdf5="images/form_e_medchart_blank.pdf";
		
		whichPhase = whichForm.charAt(0);
		whichPDF = whichForm.charAt(2);
		whichForm = whichForm.replace(/\./gi, '_');
		
		
		pdfLink="<Br><Br><a href=\""+eval("pdf"+whichPDF)+"\" target=\"_blank\">Download a blank PDF version of this form.</a>";
		
		if(whichPDF == 2)
		{
			pdfLink="";	
		}
		if(whichPDF == 4 || whichPDF == 5)
		{
			copyrightLine='<br>'+cptFooter;
		}
		else
		{
			copyrightLine="";	
		}
		
		var scroll = 'yes';
		        
		var howWide=605;
		var howHigh=400;
		testNum=eval("form"+whichForm+"Image.indexOf('.html')");
		if(testNum<0){
		var displayForm="<center><img src='images/medrecords/"+eval("form"+whichForm+"Image")+"'>"+pdfLink+"<Br><Br></center>";
			
		var header = '<table width="560" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td width="483" height="49"><img src="images/popUp/form/pop_hdr_medrec.jpg" width="483" height="49"></td>';
		var header_right = 'images/popUp/form/pop_hdr_medrec_close.jpg';
		var header_right_mo = 'images/popUp/form/pop_hdr_medrec_close_mo.jpg';
		snapCrackle = window.open("",'snapCrackle','width='+howWide+',height='+howHigh+',scrollbars='+scroll+',toolbar=yes,location=no,resizable=yes');
		var returnToTop='<tr><td colspan="2"><table width="541" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top"><a href="javascript:window.scroll(0,0);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'ToTop\',\'\',\'images/framework/btn_btm_return_top_sm_mo.gif\',1)"><img name="ToTop" border="0" src="images/framework/btn_btm_return_top_sm.gif" width="93" height="15"></a></td>';
        returnToTop+='<td valign="top" align="right"><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'mrCloseUm\',\'\',\'images/popUp/btn_btm_close_mo.gif\',1)"><img name="mrCloseUm" border="0" src="images/popUp/btn_btm_close.gif" width="72" height="15"></a></td></tr></table></td></tr>';
        var divider= '<tr align="center" valign="top"><td colspan="3"><img src="images/framework/divider_fullwidth_560.gif" width="560" height="7"><br><div class="footer">Copyright &copy 2004, Elsevier (USA). All rights reserved.'+copyrightLine+'</div></td></tr>';
		

        with(snapCrackle.document){
        clear();
        write('<html><head><title>Popup</title>');
        write('<link href="mio.css" rel="stylesheet" type="text/css">');
        write('<script>\n');
        write('function MM_swapImage() { //v3.0\n');
        write('  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)\n');
        write('   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}\n');
        write('}\n');
        write('function MM_swapImgRestore() { //v3.0\n');
        write('  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;\n');
        write('}\n');
        write('function MM_findObj(n, d) { //v4.0\n');
        write('var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {\n');
        write('d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}\n');
        write('  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];\n');
        write('  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);\n');
        write(' if(!x && document.getElementById) x=document.getElementById(n); return x;\n');
		write('}\n');
        write('</script>\n');
        write('</head>');
        write('<body><center>');
        write(header);
        write('<td><a href="javascript:window.close();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'mrCloseButton\',\'\',\''+header_right_mo+'\',1)">');
        write('<img name="mrCloseButton" border="0" src="'+header_right+'" width="77" height="49"></a></td>');
        write('</tr><tr><td colspan="2"><div class="text_area">');
        write(displayForm);
        write('</div></td></tr>');
        write(returnToTop);
        write(divider);
        write('</table></center></body></html>');
        close();
		}	
	snapCrackle.focus();
	}else{
	  popSimplified(eval("form"+whichForm+"Image"));
	}
}

// function that does the same thing as using a reset button or calling
//  form.reset() and doing <form onReset="clearImages(this)"> :)
function resetForm(resetMe)
{
	resetMe.reset();
	clearImages(resetMe);
}

// function called by flash objects to set can_go_next
function setIdiot(toWhat)
{
	can_go_next=toWhat;
	hasFlashQuiz = true;
}

function popSimplified(whichPage, howHigh, howWide)
{
	if(!howHigh)
		howHigh=400;
        if(!howWide)
		howWide=600;	
			
	aPage= window.open(whichPage,'aPage','height='+howHigh+',width='+howWide+',scrollbars=yes,toolbar=yes,location=no,resizable=yes');
	aPage.focus();
}

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
function cms1500_DoFSCommand(command, args) {
  var cms1500Obj = InternetExplorer ? cms1500 : document.cms1500;
  //
  //alert(args);
  setIdiot(args);
  //
}
// Hook for Internet Explorer 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub cms1500_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call cms1500_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}

images_changed=new Array();

//wrapper to check text box questions
tom_tries=new Array();
tom_passed_through=0;
function textBoxWrap(tomForm)
{
	can_go_next = true;
	if(!window.feedback_correct || tom_passed_through)
	{
		feedback_correct=eval('feedback_correct_'+tomForm.name);
		feedback_incorrect=new Array();
		feedback_incorrect=eval('feedback_incorrect_'+tomForm.name);
		tom_passed_through++;
	}
	
	tomCorrect=new Array();
	for(i=0;i<20;i++)
	{
		tomCorrect[i]=false;
	}
	tomWrong=false;
	for(i=0;i<tomForm.length;i++)
	{
		tom_image_name="yesno"+i+"_"+tomForm.name;
		images_changed[tomForm.name].push(tom_image_name);
		for(k=0;k<eval('answers_'+tomForm.name)[i].length;k++) //correct answers
		{
			if(tomForm["textfield"+i+"_"+tomForm.name].value == eval("answers_"+tomForm.name)[i][k])
			{
				tomCorrect[i]=true;
			}
		}
			
		if(tomCorrect[i]==true) //Correct! change image, and pop up form
		{			
			MM_swapImage(tom_image_name,'',rightImage,1);

		}
		else //Wrong! change image, and pop up form
		{
			MM_swapImage(tom_image_name,'',wrongImage,1);

		}	
		for(l=0;l<tomForm.length;l++)
		{
			if(tomCorrect[i]==false)
			{
				tomWrong=true;	
			}
		}
	
	}	
	if(tomWrong)
	{
		clearTimeout(dannysCrazyTimeout);
		dannysCrazyTimeout = setTimeout("popWrong('"+feedback_incorrect[tom_tries[tomForm.name]]+"', 300)", "1000");
		if(tom_tries[tomForm.name]<1)
			tom_tries[tomForm.name]++;
		else
			tom_tries[tomForm.name]=1;
	}
	else
	{	
		clearTimeout(dannysCrazyTimeout);
		dannysCrazyTimeout = setTimeout("popCorrect('"+feedback_correct+"', 300)", "1000");
	}
	
}
//clear text boxes
function textBoxClear(tomForm)
{
	tomForm.reset();
	tom_tries[tomForm.name]=0;
	for(i=0;i<images_changed[tomForm.name].length;i++)
	{
		MM_swapImage(images_changed[tomForm.name][i],'',clearImage,1);
	}
}
function writeTomTextBox(questionText,formName,numBoxes,boxText)
{	
	if(!formName)
	{
		formName='form1';	
	}
	if(!numBoxes)
	{
		numBoxes=1;	
	}
	if(!boxText)
	{
		boxText="";	
	}
	
	var displayBoxText=boxText.split("~");

	tom_tries[formName]=0;
	images_changed[formName]=new Array();
	document.write('<form name="'+formName+'" method="post" action="" onSubmit="textBoxWrap(this);return false">');
    document.write(questionText+'<br><br>');
    for(i=0;i<numBoxes;i++)
    {
    	document.write('<img src="images/quiz_items/blank_unmarked.gif" width="27" height="12" name="yesno'+i+'_'+formName+'">');
   		document.write(" "+displayBoxText[i]);
    	document.write(' <input type="text" name="textfield'+i+'_'+formName+'"><br><br>');
    }
    document.write('<a href="#" onClick="javascript:textBoxWrap(');
    document.write(formName);
    document.write(');return false;" onMouseUp="MM_swapImgRestore()" onMouseDown="MM_swapImage(\'Submit\',\'\',\'images/quiz_items/btn_submit_mo.gif\',1)"><img name="Submit" border="0" src="images/quiz_items/btn_submit.gif" width="51" height="22"></a>&nbsp;');
    document.write('<a href="#" onClick="textBoxClear('+formName+');return false;" onMouseUp="MM_swapImgRestore()" onMouseDown="MM_swapImage(\'Reset\',\'\',\'images/quiz_items/btn_reset_mo.gif\',1)"><img name="Reset" border="0" src="images/quiz_items/btn_reset.gif" width="51" height="22"></a>');
	document.write('</form>');
	
}
