var mris_window;
var saveWidth=400;
var saveHeight=300;
// $cmasset
	var saveUrl = "http://www.mris.com/utilities/save.cfm";
// $/cmasset
/***********
* Opens a printer friendly window
* myform is the form object to submit - should contain all form variables supplied to the page
* url is the url to display the printer friendly content for
*/
function openPrinterFriendlyWin(myform, url) {
	closeWindow();
	updatedFieldsForPrinterFriendly = true;
	mris_window = window.open('',"mris_window",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=840,height=600');
	myform.action = url;
	myform.target = 'mris_window';
	myform.method = 'GET'; //use get rather than post - known bug posting to flashpaper and swf files in IE
	
		addField(myform, 'hidden', 'printer_friendly', 'yes'); // add to form, since it is a get, the form field will resolve to the url
		// extract the url args and convert to hidden fields
		var args = new Object();
		var queryIdx = url.indexOf("?");
		if (queryIdx > 0) {	
			// we found the query string
			var queryStr = url.substring(queryIdx+1, url.length);
			var pairs = queryStr.split("&");
			for (var i = 0; i < pairs.length; i++) {
				var pos = pairs[i].indexOf("=");
				if (pos == -1) continue;
				var argname = pairs[i].substring(0,pos);
				var value = pairs[i].substring(pos+1);
				addField(myform, 'hidden', argname, value);
			}
		} 
	
	myform.submit();
	mris_window.focus();
}		

/***********
* Opens a printer friendly window
* url is the url to display the printer friendly content for
*/
function openPrinterFriendlyWinNoForm(url) {
	closeWindow();
	updatedFieldsForPrinterFriendly = true;
	mris_window = window.open('',"mris_window",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=840,height=600');
	mris_window.focus();
}		

function addField (form, fieldType, fieldName, fieldValue) {
  if (document.getElementById) {
    var input = document.createElement('INPUT');
      if (document.all) { // what follows should work 
                          // with NN6 but doesn't in M14
        input.type = fieldType;
        input.name = fieldName;
        input.value = fieldValue;
      }
      else if (document.getElementById) { // so here is the
                                          // NN6 workaround
        input.setAttribute('type', fieldType);
        input.setAttribute('name', fieldName);
        input.setAttribute('value', fieldValue);
      }
    form.appendChild(input);
  }
}



/***********
* Opens the save window
* myform is the form object to submit - should contain all form variables supplied to the page
* url is the url to display the printer friendly content for
*/
function savePage(url,title) {
	closeWindow();
	if (title == null || title.length == 0 || title == '') {
		title = 'MRIS';
	}
	mris_window = window.open(saveUrl + '?save_url='+escape(url)+'&title='+escape(title),"printwindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width='+saveWidth+',height='+saveHeight);
	mris_window.focus();	
}		

/***********
* Opens the save window
* myform is the form object to submit - should contain all form variables supplied to the page
* url is the url to display the printer friendly content for
*/
function openSaveWin() {
	closeWindow();
	mris_window = window.open(saveUrl,"mris_window",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width='+saveWidth+',height='+saveHeight);
	mris_window.focus();
}		

/***********
* Opens the save help window
* myform is the form object to submit - should contain all form variables supplied to the page
* url is the url to display the printer friendly content for
*/
function openSaveHelpWin() {
	closeWindow();
	mris_window = window.open(saveUrl + '?displayhelp=yes',"mris_window",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width='+saveWidth+',height='+saveHeight);
	mris_window.focus();
}	

function closeWindow() {
if (mris_window && !mris_window.closed) mris_window.close();
}