function ich_thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function ich_loadValues()
{
	var parameters = ich_thisMovie("ich_StampDuty").getParameters();
	var pArray = parameters.split("&&");

	document.forms['ich_MainForm'].elements['ich_vClientName'].value = pArray[0];
	document.forms['ich_MainForm'].elements['ich_vClientNum'].value = pArray[1];
	document.forms['ich_MainForm'].elements['ich_vCalc'].value = pArray[2];
	document.forms['ich_MainForm'].elements['ich_vDate'].value = pArray[3];
	document.forms['ich_MainForm'].elements['ich_vStateTerritory'].value = pArray[4];
	document.forms['ich_MainForm'].elements['ich_vPropertyValue'].value = pArray[5];
	document.forms['ich_MainForm'].elements['ich_vLoanAmount'].value = pArray[6];
	document.forms['ich_MainForm'].elements['ich_vPropertyIs'].value = pArray[7];
	document.forms['ich_MainForm'].elements['ich_vFirstHome'].value = pArray[8];
	document.forms['ich_MainForm'].elements['ich_vMortgageFee'].value = pArray[9];
	document.forms['ich_MainForm'].elements['ich_vTransferFee'].value = pArray[10];
	document.forms['ich_MainForm'].elements['ich_vStampDutyProp'].value = pArray[11];
	document.forms['ich_MainForm'].elements['ich_vStampDutyLoan'].value = pArray[12];
	document.forms['ich_MainForm'].elements['ich_vTotal'].value = pArray[13];
	
	document.forms['ich_MainForm'].elements['ich_dbPropertyValue'].value = pArray[14];
	document.forms['ich_MainForm'].elements['ich_dbLoanAmount'].value = pArray[15];
	document.forms['ich_MainForm'].elements['ich_dbMortgageFee'].value = pArray[16];
	document.forms['ich_MainForm'].elements['ich_dbTransferFee'].value = pArray[17];
	document.forms['ich_MainForm'].elements['ich_dbStampDutyProp'].value = pArray[18];
	document.forms['ich_MainForm'].elements['ich_dbStampDutyLoan'].value = pArray[19];
	document.forms['ich_MainForm'].elements['ich_dbTotal'].value = pArray[20];
	
	document.forms['ich_MainForm'].elements['ich_vfirstHomeGrant'].value = pArray[21];
	document.forms['ich_MainForm'].elements['ich_votherConcessions'].value = pArray[22];
	document.forms['ich_MainForm'].elements['ich_vtotalGrants'].value = pArray[23];
	
	document.forms['ich_FriendForm'].elements['ich_vCalc'].value = pArray[2];
	document.forms['ich_FriendForm'].elements['ich_vDate'].value = pArray[3];
	document.forms['ich_FriendForm'].elements['ich_vStateTerritory'].value = pArray[4];
	document.forms['ich_FriendForm'].elements['ich_vPropertyValue'].value = pArray[5];
	document.forms['ich_FriendForm'].elements['ich_vLoanAmount'].value = pArray[6];
	document.forms['ich_FriendForm'].elements['ich_vPropertyIs'].value = pArray[7];
	document.forms['ich_FriendForm'].elements['ich_vFirstHome'].value = pArray[8];
	document.forms['ich_FriendForm'].elements['ich_vMortgageFee'].value = pArray[9];
	document.forms['ich_FriendForm'].elements['ich_vTransferFee'].value = pArray[10];
	document.forms['ich_FriendForm'].elements['ich_vStampDutyProp'].value = pArray[11];
	document.forms['ich_FriendForm'].elements['ich_vStampDutyLoan'].value = pArray[12];
	document.forms['ich_FriendForm'].elements['ich_vTotal'].value = pArray[13];
	
	document.forms['ich_FriendForm'].elements['ich_vfirstHomeGrant'].value = pArray[21];
	document.forms['ich_FriendForm'].elements['ich_votherConcessions'].value = pArray[22];
	document.forms['ich_FriendForm'].elements['ich_vtotalGrants'].value = pArray[23];
}
	
function ich_saveCalc(stateTerritory,propertyValue,loanAmount,propertyIs,firstHome,mortgageFee,transferFee,stampDutyProp,stampDutyLoan,total,firstHomeGrant,otherConcessions,totalGrants)
{
	var winRef = window.open('','saveWindow','location=no,resizable=yes,scrollbars=yes,width=500,height=400,left=400,top=100');
	var s = ' ';
	s = ich_makeReport(stateTerritory,propertyValue,loanAmount,propertyIs,firstHome,mortgageFee,transferFee,stampDutyProp,stampDutyLoan,total,firstHomeGrant,otherConcessions,totalGrants);
	winRef.document.write(s);
	winRef.document.close();
}

function ich_makeReport(stateTerritory,propertyValue,loanAmount,propertyIs,firstHome,mortgageFee,transferFee,stampDutyProp,stampDutyLoan,total,firstHomeGrant,otherConcessions,totalGrants)
{
	var browserSupported = false;
	var browser = navigator.appName;
	var temp,version;	
	if (browser=="Microsoft Internet Explorer") {
		if (navigator.appVersion.indexOf("MSIE")!=-1) {
			temp = navigator.appVersion.split("MSIE");
			version = parseFloat(temp[1]);
		}
		if(version >= 5) {
			browserSupported = true;
		}
	}
	
	// generate the html page for the save table frame.
	var saveFrameStr = ich_saveHeader() +
	"<body>"+
	"<div id=\\'brandingColor\\'></div>"+
	"<div id=\\'global_container\\'>"+
		"<h2>Calculator Summary</h2>"+
		"<div id=\\'column_container\\'>"+
			"<h3>Stamp Duty Details </h3>"+
				"<div class=\\'content_container\\'>"+
					"<p class=\\'column1\\'>"+
						"<strong>State/Territory :</strong> "+stateTerritory+"<br>"+
						"<strong>Value of property :</strong> $"+propertyValue+"</br>"+
						"<strong>Loan amount :</strong> $"+loanAmount+"</p>"+
					"<p class=\\'column2\\'>"+
						"<strong>Property is :</strong> "+propertyIs+"<br>"+
						"<strong>Are you a first home buyer? </strong> "+firstHome+"</p>"+	
				"</div>"+
		"</div>"+
		"<div id=\\'results_container\\'>"+
			"<h3>Results</h3>"+
				"<div class=\\'content_container\\'>"+
					"<p class=\\'column1\\'>"+
						"<strong>Mortgage registration fee :</strong> "+mortgageFee+"<br>"+
						"<strong>Transfer fee :</strong> "+transferFee+"<br>"+
						"<strong>Stamp duty on property :</strong> "+stampDutyProp+"<br>"+						
						"<strong>Total :</strong> "+total+"</br>"+	
						
						"<strong>First Home Owner Grant :</strong> "+firstHomeGrant+"<br>"+
						"<strong>Other Concessions :</strong> "+otherConcessions+"<br>"+					
						"<strong>Total Government Concessions:</strong> "+totalGrants+"</p>"+						
				"</div>"+
		"</div>" + 
	"</body>"+
	"</html>";

	// generate a html page consisting of the save button.
	var buttonFrameStr = ich_saveButtonPage();
	
	// generate a html page consisting of 2 frames: top frame contains save table.
	// bottom frame contains save button.
	var str = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"+
	"<html><head>"+ 
	"<title>Stamp Duty Calculator Information</title>"+
	"<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"+
	"<script type=\"text/javascript\">"+
	"function update() {"+
	    "window.saveFrame.document.open();"+
	    "window.saveFrame.document.write('"+saveFrameStr+"');"+
	    "window.saveFrame.document.close();"+
	    "window.buttonFrame.document.open();"+
	    "window.buttonFrame.document.write('"+buttonFrameStr+"');"+
	    "window.buttonFrame.document.close();"+
	"}"+
	
	"function doSaveAs() {"+
		"var browserSupported = false;"+
		"var browser = navigator.appName;"+
		"var temp,version;"+
		"if (browser==\"Microsoft Internet Explorer\") {"+
			"if (navigator.appVersion.indexOf(\"MSIE\")!=-1) {"+
				"temp = navigator.appVersion.split(\"MSIE\");"+
				"version = parseFloat(temp[1]);"+
				"if(version >= 5) {"+
					"browserSupported = true;"+
				"}"+
			"}"+
		"}"+
		"if(browserSupported) {	"+
			"window.saveFrame.document.execCommand('saveAs',false,'CalculatorResults.html');"+
		"} else {"+
			"var button = window.buttonFrame.document.getElementById('SaveForm');"+
			"button.parentNode.removeChild(button);"+
			"alert(\"Your browser does not support this save function. To save this page press ctrl-S.\");"+
		"}"+
	"}"+

	"document.write('<frameset rows=\"260,*\" onLoad=\"update()\" frameborder=no border=0>');"+
	"document.write('<frame src=\"\" name=saveFrame noresise=noresize>');"+
	"document.write('<frame src=\"\" name=buttonFrame noresise=noresize>');"+
	"document.write('</frameset>');"+
	"</script>"+
	"</head>"+	
	"</html>";
	
	return str;
}

