
<!--
//********************************************************
//* Created for Orion Systems by Scott A. Caldwell
//* 2005-10-04
//* persfinc.js
//* page specific functions to match the behavior of
//* the persfinc.xls spreadsheet calculations and formulas
//********************************************************
//********************************************************
//* Variables for the popup window
//********************************************************
var popupwdw;					//  popup wizard window object
var usewizard=false;			//	popup wizard is open flag
window.onload = wonload;
function wonload() {
	// no wizard
}
//********************************************************
//* wonunload executes when the window is unloaded
//********************************************************
function wonunload() {
	closewizard();
}

//********************************************************
//* showwizard will load the popup wizard window and display it
//*		s = name of the wizard page to display
//********************************************************
function showwizard(s) {
	var features='toolbar=no,status=yes,height=50,width=50';
	var name='wizard';
	var url= s+'.htm';
	usewizard=true;
	popupwdw=window.open(url,name,features);
}

//
// closewizard will unload the popup wizard window if it is loaded
//
function closewizard() {
	document.persfinc.cbusewizard.checked = false;
	if (usewizard == true) {
		usewizard=false;
		popupwdw.close();
	}
}
//********************************************************
//* computesum
//* 	compare the excel named cells to the argument
//*		and performs the appropriate formula
//*		for dependent section, c is reassigned
//********************************************************
function computesum(f) {
	
	f.D3.value=gendiff(2,f.C2.value,f.C3.value);
	f.D8.value=xsum(f,'D1:7');

	f.D10.value=gendiff(2,f.C9.value,f.C10.value);
	f.D12.value=gendiff(2,f.C11.value,f.C12.value);
	f.D14.value=gendiff(2,f.C13.value,f.C14.value);
	f.D16.value=gendiff(2,f.C15.value,f.C16.value);
	f.D19.value=xsum(f,'D10:18');

	f.D25.value=xsum(f,'C21:24');
	f.D30.value=gendiff(2,f.C26.value,f.C27.value);
	f.D30.value=genprod(f.D30,f.C28,1);
	f.D30.value=genprod(f.D30,f.C29,1);
	f.D31.value=xsum(f,'D20:30');
	f.D32.value=gensum(3,f.D8.value,f.D19.value,f.D31.value);

	f.D41.value=xsum(f,'D33:40');
	f.D45.value=xsum(f,'C42:44');

	f.D48.value=xsum(f,'C46:47');
	f.D49.value=gensum(3,f.D41.value,f.D45.value,f.D48.value);

	f.D52.value=gendiff(2,f.C50.value,f.C51.value);

	f.D54.value=gendiff(2,f.D52.value,f.C53.value);

	f.E55.value=gendiff(2,f.D32.value,f.D49.value);

	f.H55.value=dividenum(f.D54,f.F55,100);
	f.H55.value=dividenum(f.H55,f.C55,100);
	f.H56.value=dividenum(f.D54,f.G55,100);
	f.H57.value=dividenum(f.E55,f.G55,100);

	f.D56.value=xsum(f,'H55:57');
	f.D57.value=genprod(f.D54,f.A55,1);
	f.D57.value=dividenum(f.D57,f.D56,100);

	return;
}
function dividenum(s1,s2,w) {
	var p,x,y,r,s;
	s=0;
	x=parseFloat(s1.value);
	y=parseFloat(s2.value);
	if (isNaN(x) || isNaN(y)) {
		r=0;
	} else {
		if (y==0) {
			r=0;
		} else {
			r=(x/y)*w;
			r=Math.round(r)/w;
		}
	}
	s = formatdollar(r);
	return s;
}
//********************************************************
//* cellchange
//*		generic function added to all excel type input boxes
//* 	calls the appropriate sum function based on
//*		which cell changed.
//********************************************************
function cellchange(c) {
	var f=c.form;
	if (isInRange(c,'C1:7')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'D1:7')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'C9:16')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'D17:18')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'C20:29')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'D20:20')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'D33:40')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'C42:44')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'C46:47')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'C50:51')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'C53:53')) { c.value = gensum(1,c.value);computesum(f); return; }
	if (isInRange(c,'C55:55')) { c.value = gensum(1,c.value);computesum(f); return; }
	return;
}
//********************************************************
//* sheetformat
//*		generic function for setting the global
//* 	format of the displayed page in dollars
//*		with or without cents.
//*		called as the onclick event of a checkbox control
//********************************************************
function sheetformat(c) {
	var f=c.form;
	whdol = true;
//	reformat(f.B6);
	return;
}
//********************************************************
//* shiftfocus
//*		generic function for moving focus from a
//* 	computed cell to the next input cell
//********************************************************
function shiftfocus(c) {
	var f=c.form;
	if (c==f.D3) { f.D4.focus(); return; }
	if (c==f.D10) { f.C11.focus(); return; }
	if (c==f.D12) { f.C13.focus(); return; }
	if (c==f.D14) { f.C15.focus(); return; }
	if (c==f.D16) { f.D17.focus(); return; }
	if (c==f.D25) { f.C26.focus(); return; }
	if (c==f.D45) { f.C46.focus(); return; }
	if (c==f.D52) { f.C53.focus(); return; }
	if (c==f.D54) { f.C55.focus(); return; }
	return;
}
//********************************************************
//* divexpand
//*		generic function added to all line input boxes
//* 	checks to see if the next line is visible
//********************************************************
function divexpand(id) {
	var s,x;
	s='currentassets'; x=(id==s)?1:0; display(s,x);
	s='fixedassets'; x=(id==s)?1:0; display(s,x);
	s='otherassets'; x=(id==s)?1:0; display(s,x);
	s='currentliabilities'; x=(id==s)?1:0; display(s,x);
	s='longtermliabilities'; x=(id==s)?1:0; display(s,x);
	s='peroi'; x=(id==s)?1:0; display(s,x);
	x=(shiding.length==-1)?-1:shiding.length-1;
	if (x!=-1) shiding[x]=id;
	return;
}
function divexpandall(x) {
	var s,t;
	t='';
	s='currentassets'; t=(divcheck(s)==1)?s:t; display(s,x);
	s='fixedassets'; t=(divcheck(s)==1)?s:t; display(s,x);
	s='otherassets'; t=(divcheck(s)==1)?s:t; display(s,x);
	s='printspacer'; t=(divcheck(s)==1)?s:t; display(s,x);
	s='currentliabilities'; t=(divcheck(s)==1)?s:t; display(s,x);
	s='longtermliabilities'; t=(divcheck(s)==1)?s:t; display(s,x);
	s='peroi'; t=(divcheck(s)==1)?s:t; display(s,x);
	return t;
}
function printmealldivs(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19) {
	var i,x;
	shiding=new Array();
	for (i=0; i < 20; i++) {
		eval("x=(s"+i+"==undefined)?0:1;");
		if (x == 0) break;
		eval("shiding["+i+"]=s"+i+";");
	}
	for (i=0; i < shiding.length; i++) {
		display(shiding[i],0);
	}
	shiding[shiding.length]=divexpandall(1);
	setTimeout('autoprint()',100);
}
function autoprint() {
	if (window.focus != undefined) oldwindowfocus=window.focus;
	window.onfocus = printunhidediv;
	window.print();
}
function printunhidediv() {
	var i;
	var s=divexpandall(0);
	for (i=0; i < shiding.length; i++) {
		display(shiding[i],1);
	}	
	if (oldwindowfocus != undefined) window.focus=oldwindowfocus;
	oldwindowfocus=undefined;
}
//********************************************************
//* divcheck(id)
//* 	checks element visibility based on browser version
//********************************************************
function divcheck(id) {
	if (ie5 || ns6) {
		return (document.getElementById(id).style.display=="block")?1:0;
	} else {
		if (document.layers) return (document.layers[id].visibility == "show") ? 1 : 0;
		if (document.all) return (document.all[id].style.visibility == "visible") ? 1 : 0;
		return 0;
	}
}
function displaytab(idx) {
	for (var i=1; i<7; i++) {
		var k=(i==idx)?1:0;
		var id='menutabs'+i;
		display(id,k);
	}
}
//-->
