// JavaScript Document
// VisualCalc, Inc. copyright 2005
// www.visualcalc.com

// JS to invoke apps from VisualCalc server

/* 
Name:		vcjsappgen.js
Author:		Rieger
Orig Date:	7/17/2003
Purpose:	To be able to send customers who want a hosted solution simple lines of html with javascript to allow them to use VisualCalc calculators. The code and the text files and the help files reside on a VisualCalc server, allowing VisualCalc to make fixes on the fly. Calculators appear in pop-up JavaScript windows, sized correctly, with each pop-up window containing a help file link and a powered by gif and a copyright line/gif.

The html/javascript sent to a customer is 
<script language="JavaScript" src="http://analytics.visualcalc.com/vchost/vcjsappgen.js" type="text/javascript">
</script>
<a href='javascript:getCalc("home2");'> Mortgage Calculator</a>

Functions:
getCalc(calcspec) takes the name of the calculator (calcspec resolves to, e.g., home2) and furnishes input to variables that are written out as parm values in an applet tag using the function
putInfo(calctxt,winwid,winhi,auxname,jarname,titlename,appwid,apphi,helphtml)  

The variables are self explanatory: 
calctxt is the template txt file that defines the calculator
winwid is the width of the host window that is created to contain the calculator
winhi is the height of the host window that is created to contain the calculator
auxname is the name of the auxiliary jar file
jarname is the name of the application-specific jar file
titlename is the title that is put into the browser title bar
appwid is the width of the application itself
apphi is the height of the application itself
helphtml is the name of the html help file for the specific app
vcjar is the name of the VisualCalc.jar file - we use different names, depending upon version

	

*/

	function getCalc(calcspec) {
	switch(calcspec)
	{
	// Home Suite
		case "home2":
			putInfo("homeloan2.txt",700,455,"VCAux2.jar","mortgage.jar","AMPLIFY Mortgage Calculator",650,350,"hlp_home2.html","VisualCalc.jar","1");
			break;
		
		case "rentbuy":
			putInfo("rentbuy.txt",700,605,"VCAux2.jar","rentbuy.jar","AMPLIFY Rent or Buy Calculator",650,500,"hlp_rentbuy.html","VisualCalc.jar","2");
			break;
			
		case "refinance":
			putInfo("refinance.txt",650,655,"VCAux1.jar","refinance.jar","AMPLIFY Refinance Calculator",600,550,"hlp_refinance.html","VisualCalc.jar","3");
			break;
			
		case "biweekly":
			putInfo("biweekly.txt",650,455,"VCAux2.jar","biweekly.jar","AMPLIFY Biweekly Mortgage Calculator",600,350,"hlp_biweekly.html","VisualCalc.jar","4");
			break;
			
		case "mortgpts":
			putInfo("mortgpts.txt",650,630,"VCAux1.jar","mortgpts.jar","AMPLIFY Mortgage Points Calculator",600,525,"hlp_mortgpts.html","VisualCalc.jar","5");
			break;
			
		case "affordability":
			putInfo("affordability.txt",650,455,"VCAux2.jar","affordability.jar","AMPLIFY Mortgage Affordability Calculator",600,350,"hlp_aff.html","VisualCalc.jar","6");
			break;
			
		case "adj2wide":
			putInfo("adj2wide.txt",650,605,"VCAux2.jar","adj2.jar","AMPLIFY Fixed vs. Adjustable Calculator",600,500,"hlp_adj2.html","VisualCalc.jar","7");
			break;
			
		case "downpmtcomp":
			putInfo("downpmtcomp.txt",650,605,"VCAux2.jar","downpmtcomp.jar","AMPLIFY Down Payment Calculator",600,500,"hlp_downpmtcomp.html","VisualCalc.jar","8");
			break;
			
		case "homeequity2":
			putInfo("homeequity2.txt",710,745,"VCAux2.jar","homeequity2.jar","AMPLIFY Home Equity Calculator",650,650,"hlp_homeequity2.html","VisualCalc.jar","9");
			break;
			
		// Auto Suite
		
		case "auto2":
			putInfo("autoloaninscu.txt",650,455,"VCAux2.jar","mortgageins.jar","AMPLIFY Auto Loan Calculator",600,350,"hlp_autoloanins.html","VisualCalc.jar","10");
			break;

		case "autobw":
			putInfo("autobw.txt",650,455,"VCAux2.jar","biweekly.jar","AMPLIFY Biweekly Auto Loan Calculator",600,350,"hlp_biweekly.html","VisualCalc.jar","11");
			break;

		case "leaseloan":
			putInfo("leaseloan.txt",650,655,"VCAux2.jar","leaseloan.jar","AMPLIFY Lease or Buy Calculator",600,550,"hlp_leaseloan.html","VisualCalc.jar","12");
			break;

		case "raterebate":
			putInfo("raterebate.txt",550,605,"VCAux2.jar","raterebate.jar","AMPLIFY Rate vs. Rebate Calculator",500,500,"hlp_raterebate.html","VisualCalc.jar","13");
			break;

		// Savings Suite
		
		case "savings":
			putInfo("savings.txt",650,555,"VCAux2.jar","savings.jar","AMPLIFY Saving for a Goal Calculator",600,450,"hlp_savings.html","VisualCalc.jar","14");
			break;

		case "college":
			putInfo("college.txt",650,505,"VCAux2.jar","college.jar","AMPLIFY College Planner Calculator",600,400,"hlp_college.html","VisualCalc.jar","15");
			break;

		case "lease":
			putInfo("lease.txt",475,605,"VCAux1.jar","lease.jar","AMPLIFY Lease Analysis Calculator",400,500,"hlp_lease.html","VisualCalc.jar","16");
			break;

		case "annuity":
			putInfo("annuity.txt",650,655,"VCAux3.jar","annuity.jar","AMPLIFY Annuity  Calculator",600,550,"hlp_annuity.html","VisualCalc.jar","17");
			break;

//		case "cdladder":
//			putInfo("cdladder.txt",585,700,"VCAux2.jar","ladder.jar","AMPLIFY CD Laddering Calculator",525,750,"hlp_cdladder.html","VisualCalc.jar","CDLaddering");
//			break;

//		case "blendrate":
//			putInfo("blendrate.txt",635,440,"VCAux2.jar","blendrate.jar","AMPLIFY Blended Rate Calculator",600,350,"hlp_blendrate.html","VisualCalc.jar");
//			break;

		// Retirement Suite
		
		case "withold":
			putInfo("withold.txt",700,505,"VCAux2.jar","withold.jar","AMPLIFY Income Witholding Calculator",650,400,"hlp_withold.html","VisualCalc.jar","18");
			break;

		case "retire":
			putInfo("retire.txt",550,605,"VCAux1.jar","retire.jar","AMPLIFY Retirement Planner Calculator",500,500,"hlp_retire.html","VisualCalc.jar","19");
			break;
	
		case "rdist":
			putInfo("rdist.txt",605,455,"VCAux1.jar","rdist.jar","AMPLIFY Retirement Distribution Calculator",550,350,"hlp_rdist.html","VisualCalc.jar","20");
			break;
	
		case "nestegg":
			putInfo("nestegg.txt",505,630,"VCAux1.jar","nestegg.jar","AMPLIFY Nest Egg Calculator",450,525,"hlp_nestegg.html","VisualCalc.jar","21");
			break;
	
		case "taxdefc":
			putInfo("taxdefc.txt",485,605,"VCAux1.jar","taxdefc.jar","AMPLIFY Tax-Deferred Savings Comparison Calculator",425,500,"hlp_taxdefc.html","VisualCalc.jar","22");
			break;

		case "iracomp":
			putInfo("iracomp.txt",475,605,"VCAux1.jar","iracomp.jar","AMPLIFY IRA Comparison Calculator",400,500,"hlp_iracomp.html","VisualCalc.jar","23");
			break;
	
		case "iraconv":
			putInfo("iraconv.txt",475,605,"VCAux1.jar","iraconv.jar","AMPLIFY ROTH IRA Conversion Calculator",400,500,"hlp_iraconv.html","VisualCalc.jar","24");
			break;

		// Income & Insurance Suite
		
		case "estatetax":
			putInfo("estatetax.txt",550,705,"VCAux2.jar","stdestatetax.jar","AMPLIFY Estate Tax Calculator",500,600,"hlp_estatetax.html","VisualCalc.jar","25");
			break;
	
		case "incomegrowth":
			putInfo("incomegrowth.txt",550,605,"VCAux2.jar","incomegrowth.jar","AMPLIFY Income Growth Calculator",500,500,"hlp_incomegrowth.html","VisualCalc.jar","26");
			break;
	
		case "raisingchildren":
			putInfo("raisingchildren.txt",550,705,"VCAux2.jar","stdraisingchildren.jar","AMPLIFY Cost of Raising Children Calculator",500,600,"hlp_raisingchildren.html","VisualCalc.jar","27");
			break;
				
		case "cashflow":
			putInfo("cashflow.txt",500,630,"VCAux2.jar","stdcashflow.jar","AMPLIFY Cash Flow Calculator",450,525,"hlp_cashflow.html","VisualCalc.jar","28");
			break;			
				
		case "networth":
			putInfo("networth.txt",550,655,"VCAux2.jar","stdnetworth.jar","AMPLIFY Net Worth Calculator",500,550,"hlp_networth.html","VisualCalc.jar","29");
			break;
				
		case "insurlife":
			putInfo("insurlife.txt",650,655,"VCAux2.jar","stdinsurance.jar","AMPLIFY Life Insurance Calculator",600,550,"hlp_insurlife.html","VisualCalc.jar","30");
			break;
				
		case "insurdisability":
			putInfo("insurdisability.txt",650,655,"VCAux2.jar","stdinsurance.jar","AMPLIFY Disability Insurance Calculator",600,550,"hlp_insurdisability.html","VisualCalc.jar","31");
			break;
				
		case "lifeexp":
			putInfo("lifeexp.txt",500,405,"VCAux2.jar","lifeexp.jar","AMPLIFY Life Expectancy Calculator",450,300,"hlp_lifeexp.html","VisualCalc.jar","32");
			break;

		// Business Analyzers
		
//		case "breakeven":
//			putInfo("breakeven.txt",585,440,"VCAux1_v2048b6.jar","breakeven_v2048b6.jar","AMPLIFY Break Even Analysis Calculator",550,350,"hlp_breakeven.html","VisualCalc_v2048b6.jar");
//			break;
//			
//		// Synergex ROI
//		
//		case "synergexroi":
//			putInfo("synergexroi.txt",675,590,"VCAux2_synergex.jar","SynergexROI.jar","AMPLIFY Synergex VisualSmart ROI Tool",640,500,"blank.html","VisualCalc_synergex.jar");
//			break;
			
	
		default:
		alert("Try another calculator");
	} 
	}

// the putInfo function is used by the getCalc function, above. It populates variables with real data
	function putInfo(calctxt,winwid,winhi,auxname,jarname,titlename,appwid,apphi,helphtml,vcjar,calctype){
		//closechild ();
		//open a smallwindow with the size and specs provided
		smallwindow = window.open ( "../../../vcapps/calc.cfm", "smallwindow", "toolbar=no,status=no,menubar=no,location=no,resizable=yes,scrollbars=yes" );
		smallwindow.opener = this;
		window.calctxt = calctxt;
		window.winwid = winwid;
		window.winhi = winhi;
		window.auxname = auxname;
		window.jarname = jarname;
		window.titlename = titlename;
		window.appwid = appwid;
		window.apphi = apphi;
		window.helphtml = helphtml;
		window.vcjar = vcjar;
		window.calctype = calctype;

		smallwindow.resizeTo ( winwid+5,winhi+35 );
		smallwindow.focus();  // bring smallwindow to the front
	 }

// the closechild function closes a window without complaining about JavaScript not having opened the window.
	function closechild () {
		if ( window.smallwindow && !smallwindow.closed )
			smallwindow.close ();
	}

	function writecontent () {
		document.open(); // open a document in the smallwindow and stuff it full of html and applet tag
		document.write ( '<head>\n <title>\n'+window.opener.titlename+'</title>\n 	<LINK rel="stylesheet" type="text/css" href="styles/vcstyle.css">\n</head>\n<body>\n' );
// write table for calculator applet	
		document.write ( '<table cellspacing="0" cellpadding="3" border="0">\n' );
// write table row and cells for help, print and close.
		document.write ( '<TR>\n<TD>\n');
		writehelp ();
		document.write ('</TD>\n<TD>&nbsp;</TD>\n<TD align="right">\n');
		printit ();
		document.write ('</TD></TR>');
		document.write ('<tr>\n<td colspan="3">\n ' );
		document.write ( '<applet name="vcapp" code="vc.VisualCalc.class" codebase="https://www.goamplify.com/vcapps/vcclient" archive="' + window.opener.vcjar + ',' + window.opener.auxname + ',' + window.opener.jarname + '"' + ' width=' + window.opener.appwid + ' height=' + window.opener.apphi + '>\n' );
		document.write ( '<param name="copyrite" value="Copyright 1996-2005, VisualCalc, Inc. All rights reserved.">' );
		document.write ( '<param name="initstr" value="https://www.goamplify.com/vcapps/' + window.opener.calctxt + '">' );
		document.write ( '<param name="imgloc" value="https://www.goamplify.com/vcapps/images">' );
		document.write ( '<param name="vcpfn" value="https://www.goamplify.com/vcapps/vcclient/vcp.vcp">' );  
		document.write ( '<h2>VisualCalc applications require that your browser be Java-enabled. This VisualCalc application will not run because Java is NOT enabled in your browser. Please enable Java in your browser. If you do not know how to enable Java in your browser, please contact your system administrator. To download and install a Java Virtual Machine so Java applications can run on your computer, go to <a href="http://www.visualcalc.com/jvmsunredirect/jvmsunredirect.html">Sun Microsystems</a>.</h2>\n' );    
		document.write ( '</applet>\n' );
		document.write ( '</td>\n</tr>\n<tr>\n<td>\n' );
		writecopyright ();
		document.write ( '</td>\n<td>&nbsp;</td>\n<td align="right" nowrap="nowrap">\n' );
		writecontact ();
		document.write ('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
		writeapply ();
		document.write ( '</td>\n</tr>\n</table>\n</body>\n' );
		document.close();
	}

// the writehead function writes out the variable calc title name - used by calc.html	
	function writehead () {	
		document.open(); // open a document in the smallwindow and stuff it full of html and applet tag
		document.write ( '<head><title>'+window.opener.titlename+'</title></head>' );
		document.close();
}	


// the writecontact function writes out the URL for the contact form and includes calc type
	function writecontact () {	
		document.open(); 
		document.write ( '<a href="https://www.goamplify.com/contact/contact.cfm?calc='+ window.opener.calctype +'" target="_blank" class="cubuttons" onclick="window.open(\'https://www.goamplify.com/contact/contact.cfm?calc=' + window.opener.calctype +'\',\'Contact\',\'toolbar=yes, location=yes, status=yes, menubar=no, scrollbars=auto, resizable=yes, width=680, height=700\'); return false;">Contact AMPLIFY</a>' );
		document.close();
}	

// the writeapply function writes out the variable for the app center link
	function writeapply () {	
		document.open(); 
		document.write ( '<a href="http://www.goamplify.com/app_center/index.cfm" target="_blank" class="cubuttons">Apply Online</a>' );
		document.close();
}	

// the closehelp function closes the help window 
	function closehelp () {
		help = window.open ("calc.html", "help", "toolbar=no, location=no, status=yes, menubar=no, scrollbars=auto, resizable=yes, width=600, height=700");
		help.opener = this;	
		if ( window.help && !help.closed )
			help.close ();
	}

// the writehelp function writes out the variable calc help file - used by calc.html	
	function writehelp () {
		//closehelp ();
		document.open ();
		document.write   ( '<a href="http://www.goamplify.com/vcapps/help/' + window.opener.helphtml + '" target="help" class="sidelink" onclick="window.open(\'http://www.goamplify.com/vcapps/help/' + window.opener.helphtml +'\', \'help\', \'toolbar=no, location=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=600, height=700\'); return false;"><span class="sidelink">Help For This Calculator</span></a>\n' );  
		document.close (); 
		//help.focus;	
	}


function printit () {
	document.open();
//	document.write('<a href="http://www.goamplify.com/rates/LoanRates.cfm?type=HEL" target="_blank" class="cubuttons">Check Home Equity Rates</a>&nbsp;&nbsp;');
	document.write('<button type="button" style="width:40px;height:15pt;font-size:8pt;" onClick="window.print ();"><span style="font-family:Arial,Helvetica,Verdana,sans-serif;font-size:8pt;" >Print</span></button>&nbsp;&nbsp;<button type="button" style="width:40px;height:15pt;font-size:8pt;" onClick="window.close ();"><span style="font-family:Arial,Helvetica,Verdana,sans-serif;font-size:8pt;" >Close</span></button>');
	document.close();//-->
}	

function writecopyright () {
	document.open();
	document.write('<a href="http://www.visualcalc.com/" target="_blank"><img src="https://www.goamplify.com/vcapps/images/vcpower.gif" border="0"></a><br /><span style="font-family:Arial,Verdana,Helvetica,sans-serif;font-size:7pt;">Copyright&copy; 2005, VisualCalc, Inc.</span>');
	document.close();//-->
}	
