	function caption_edit(this_id,this_width,this_class) {document.location.href='caption_edit.cfm?id='+this_id+'&width='+this_width+'&class='+this_class+'&from='+document.location.href;}

	function content_edit(this_id, this_field, this_caption) {document.location.href='content_edit.cfm?id='+this_id+'&field='+this_field+'&caption='+this_caption+'&from='+document.location.href;}

	function io_edit(this_address) {document.location.href='io_edit.cfm?address='+this_address+'&from='+document.location.href;}


	function isAlien(a) {
	   return isObject(a) && typeof a.constructor != 'function';
	}
	function isArray(a) {
	    return isObject(a) && a.constructor == Array;
	}
	function isBoolean(a) {
	    return typeof a == 'boolean';
	}
	function isEmpty(o) {
	    var i, v;
	    if (isObject(o)) {
	        for (i in o) {
	            v = o[i];
	            if (isUndefined(v) && isFunction(v)) {
	                return false;
	            }
	        }
	    }
	    return true;
	}
	function isFunction(a) {
	    return typeof a == 'function';
	}
	function isNull(a) {
	    return typeof a == 'object' && !a;
	}
	function isNumber(a) {
	    return typeof a == 'number' && isFinite(a);
	}
	function isObject(a) {
	    return (a && typeof a == 'object') || isFunction(a);
	}
	function isString(a) {
	    return typeof a == 'string';
	}
	function isUndefined(a) {
	    return typeof a == 'undefined';
	}

function ISNUMBER(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
	if (sText==null) return(false);
   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return (IsNumber && (sText.length != 0));
   }

   	function SET(name,value)
		{
		   o = document.getElementById('output');
		   if (parent != undefined)
			{
			   if (parent.calculations != undefined)
				{
			      if (parent.calculations.SET != undefined)
			      {
					   parent.calculations.SET(name,value);
		            return true;
			      }
					//else o.innerHTML = 'SET in _header (parent.calculations.SET not defined).<br>'+o.innerHTML;
				} //else o.innerHTML = 'SET in _header (parent.calculations not defined).<br>'+o.innerHTML;
			} //else o.innerHTML = 'SET in _header (parent not defined).<br>'+o.innerHTML;
			return false;
		}

   		function GET(name,type) 
		{
		   o = document.getElementById('output');
		   if (parent != undefined)
			{
			   if (parent.calculations != undefined)
				{
			      if (parent.calculations.GET != undefined)
			      {
						return(parent.calculations.GET(name,type));
			      }
					//else o.innerHTML = 'GET-_header.cfm (parent.calculations.GET not defined).<br>'+o.innerHTML;
				} //else o.innerHTML = 'GET-_header.cfm (parent.calculations not defined).<br>'+o.innerHTML;
			} //else o.innerHTML = 'GET-_header.cfm (parent not defined).<br>'+o.innerHTML;
			return (null);
		}
		
		function load_scenario(scenarioID)
		{
			if (parent != undefined) 
			{
				if (parent.calculations != undefined)
				{
					if (parent.calculations.load_scenario != undefined)
			      	{
						return(parent.calculations.load_scenario(scenarioID));
			      	}
				} 
			} 
			alert('Unable to execute load_scenario('+snapshotID+')');
			return(false);
		}
		
		function update_input(this_control, update_now)
		{
			//if (c = MM_findObj('outputx')) c.innerHTML = 'update_input:'+this_control.name;
			frame_value = new String(GET(this_control.name,'input'));
			control_value = new String(this_control.value);

			control_value = control_value.replace(/\$/g,'').replace(/,/g,'').replace(/\%/g,'').replace(/\)/g,'').replace(/\(/g,'');

			if ((this_control.datatype=='PERCENTAGE') && (ISNUMBER(control_value)==true))
			   control_value = control_value / 100;

			if (ISNUMBER(control_value)) control_value = control_value/1;

			//if (c = MM_findObj('outputx')) c.innerHTML += '<BR>a:'+frame_value+':'+control_value;
			//if (c = MM_findObj('outputx')) c.innerHTML += '<BR>-'+this_control.mirror;

			if ((String(frame_value) != String(control_value)) || (this_control.mirror != this_control.name))
			{
			    //if (c = MM_findObj('outputx')) c.innerHTML += '<BR>b';
				SET(this_control.mirror, control_value);
				if (update_now)
				{
				   //if (c = MM_findObj('outputx')) c.innerHTML += '<BR>c';
				   store_input(this_control.mirror, control_value);
				   SET('to_be_updated', true);
				}
			}
			format_control(this_control, control_value);
		}

		function store_input(address,value)
		{
		   if (parent == undefined) return(false);
			if (parent.updates == undefined) return(false);
			parent.updates.location.href='calculations_updates.cfm?address='+address+'&value='+value;
			return true;
		}


		function format_control(this_control, this_value)
		{
			if ((this_control.datatype=='TEXT') || (this_control.datatype=='BOOLEAN') || (this_control.datatype=='DATE'))
			{
			   if (this_control.usage == 'INPUT') this_control.value = this_value
			   else this_control.innerHTML = this_value;
				return;
			}
			if (isNaN(this_value))
			{
			   this_control.innerHTML = new String('(na)');
				return;
			}
			if (!ISNUMBER(this_value)) return(new String(this_value));

			number_value = this_value;
			if (this_control.datatype=='PERCENTAGE') number_value *= 100;
			this_precision = this_control.precision;
			if (this_control.datatype=='INTEGER') this_precision = 0;
			number_value = Math.round(Math.pow(10,this_precision)*number_value);
			if (is_negative = (number_value < 0)) number_value *= (-1);

			characters = new String(number_value).split('');

			result = '';
			if (this_precision > 0) {
			   for(i=0; i<this_precision; i++)
				{
				   if (characters.length) result = (characters.pop() + result)
					else result = ('0' + result);
				}
				result = '.' + result;
			}
			while(characters.length)
			{
			   result = (characters.pop() + result); if (!characters.length) break;
				result = (characters.pop() + result); if (!characters.length) break;
				result = (characters.pop() + result); if (!characters.length) break;
				result = ',' + result;
			}
			if (this_control.datatype=='PERCENTAGE') result += '%';
			if (this_control.datatype=='CURRENCY') result = '$'+result;
			if (result.charAt(0) == '.') result = '0'+result;
			if (is_negative) {
			   // this_control.style.color = 'red';
			   result = '('+result+')';
			}
			else if (this_control.usage == 'INPUT') this_control.style.color = 0;
			else this_control.style.color = '#555555';

			if (this_control.usage == 'INPUT') this_control.value = result
			else this_control.innerHTML = result;
		}

		function echo(name,message) {e = MM_findObj(name); if (e != undefined) e.innerHTML = message + '<br>'+ e.innerHTML;}

		function MM_swapImgRestore() { //v3.0
		  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
		}

		function MM_preloadImages() { //v3.0
		  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		    if (a[i].indexOf('#')!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
		}

		function MM_findObj(n, d) { //v4.01
		  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		  if(!x && d.getElementById) x=d.getElementById(n); return x;
		}

		function MM_swapImage() { //v3.0
		  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
		   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
		}
		//-->

