			var msday = 24 * 60 * 60 * 1000;
			
			function setDate()
			{
				var thisDate = new Date()
				var thisDay = thisDate.getDate();
				var thisMonth = thisDate.getMonth()+ 1;
				var thisYear = thisDate.getFullYear();
				
				return thisDay + "/" + thisMonth + "/" + thisYear;
			}
		
		
			function numericInput(val,frmElement)
			{
				var validInput = "0123456789";
				var tmpString ="";
				var replace = false;
				
				
				for(i=0; i<val.length; i++)
				{
					if(validInput.indexOf(val.charAt(i))>-1)
					{
						tmpString += String(val.charAt(i));
					}else{
						replace = true;
					}
					
				}
				
				if(replace)
				{
					frmElement.value = tmpString;
				}
				
					
			}
			
			function padDecimal(strNumber,numplaces)
			{
				var m = numplaces + 1
				strNumber = parseFloat(strNumber);
							
				strNumber = strNumber * Math.pow(10,numplaces);
				strNumber = Math.round(strNumber)/Math.pow(10,numplaces);
				strNumber = String(strNumber);
				if(strNumber.indexOf(".")<0)
				{
					strNumber = strNumber+".";
				}
				
				var dec = strNumber.substring(strNumber.indexOf("."));
				if(dec.length<m)
				{
					for(i=0; i<(m-dec.length); i++)
					{
						strNumber += "0"; 
					}
				}
				
				return strNumber;
			}
			
			function addCommas(strNumber)
			{
				var strDec;
				var strInt;
				var ret;
				
				
				strNumber = new String(strNumber);
								
				if(strNumber.indexOf(".")>-1)
				{
					strInt = strNumber.substring(0,strNumber.indexOf("."));
					strDec = strNumber.substring(strNumber.indexOf("."));
				}else{
					strDec = -1;
					strInt = strNumber;
				}
								
				/*strInt = String(strInt);
				strDec = String(strDec);*/
				
				if(strInt.length > 3)
				{
					 for (var i = 0; i < Math.floor((strInt.length-(1+i))/3); i++)
					 {
						strInt = strInt.substring(0,strInt.length-(4*i+3)) + "," + strInt.substring(strInt.length-(4*i+3));
					 }
				}
				
				if(strDec == -1)
				{  
					
					return strInt+'.00';
				}else{
				
					if(strDec.length > 2)
					{	
						ret = strInt + strDec;
					}else{
						ret = strInt + strDec+"0";
					}
				  	return String(ret);
				}
				
			}
			
			function calcSecVal()
			{
				var dolVal = document.getElementById("txtSecValDol").value;
				var cntVal = document.getElementById("txtSecValCnt").value;
				var dvError = document.getElementById("dvSecValError");
				
				
				
				strCnt = String(cntVal);
				strDol = String(dolVal);
				
				if(strCnt.length==0)
				{
					cntVal = "000";
				}
				
				if(strDol.length==0)
				{
					dolVal = "0";
				}
				
				
				if(String(strCnt).length == 2)
				{
					cntVal = cntVal* 10;
				}else if(String(strCnt).length == 1){
					cntVal = cntVal * 100;
				}
				
						
				//var secVal = parseFloat(parseInt(dolVal)*1000 + parseFloat(cntVal))/1000;
				var secVal = parseFloat(parseInt(dolVal)*1000 + parseFloat(cntVal))/1000;

				if(secVal<.1 && document.getElementById("FeeType").value == "application")
				{
					secVal = 0.1;
					dvError.className = "showBlock";
				}else{
					dvError.className = "hideBlock";
				}
				secVal = String(secVal);
				//secVal = addCommas(secVal);  //problem with values greater than 1000
				
				secVal = padDecimal(secVal,3);
				
				return secVal;
			}
			
			function getQuoteDate()
			{
				var arrDate = document.getElementById("txtDate").value.split("/");
				var quoteDate = new Date();
				quoteDate.setFullYear(arrDate[2],arrDate[1]-1,arrDate[0]);
				quoteDate.setHours(0,0,0,0);
				return quoteDate;
			}
			
			function getFinYearEnd(currDate)
			{
				var finYearEnd = new Date();
															
				if(currDate.getMonth() > 5)
				{
					finYearEnd.setFullYear(currDate.getFullYear()+1,6,1);
				}else{
					finYearEnd.setFullYear(currDate.getFullYear(),6,1);
				}
				
				finYearEnd.setHours(0,0,0,0);
				finYearEnd.setMilliseconds(finYearEnd.getMilliseconds()-1);
				return finYearEnd;
			}
			
			function getFinYearStart(currDate)
			{
				var finYearEnd = new Date();
															
				if(currDate.getMonth() > 5)
				{
					finYearEnd.setFullYear(currDate.getFullYear(),6,1);
				}else{
					finYearEnd.setFullYear(currDate.getFullYear()-1,6,1);
				}
				
				finYearEnd.setHours(0,0,0,0);
				return finYearEnd;
			}
			
			
			function feeTypeSelect(feeType)
			{
				var NumSecField = document.getElementById("dvNumSecurities");
				var numSecurities = parseFloat(document.getElementById("txtNumSecurities").value);
				
				if(isNaN(numSecurities))
				{
					numSecurities = 0;
				}
			
				
				var SecValField = document.getElementById("dvSecValue");
				var secVal = calcSecVal();
				SecValField.innerHTML = "$"+secVal;
				var secValue = parseFloat(calcSecVal());
				var totalValue = parseInt(numSecurities) * secValue;
				var strTotalValue = String(totalValue);
				
				numSecurities = addCommas(numSecurities);
				NumSecField.innerHTML = numSecurities; 	
								
				switch(feeType)
				{
					case "application":
						document.getElementById("dvAnnualVariation").className = "hideBlock";
						document.getElementById("dvQuotationDate").className = "hideBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Application Fee";
						feePayable = regCalc(totalValue,appFees);
						chessFee = 1650;
						GrandTotal = feePayable + chessFee;
						GrandTotalGST = GrandTotal * 1.1;

			
					break
					
					case "annual":
						document.getElementById("dvAnnualVariation").className = "showBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Annual Fee";
						feePayable = regCalc(totalValue,annualFees);
						
						if(!document.getElementById("cbListed").checked)
						{
							if(document.getElementById("txtDate").value.length == 0)
							{
								document.getElementById("txtDate").value = setDate();
								
							}
							document.getElementById("dvQuotationDate").className = "showBlock";
							var cDate = new Date();
							cDate = getQuoteDate();
							daysPayable = ((getFinYearEnd(cDate).getTime()-cDate.getTime())/msday);
							feePayable = feePayable * (Math.round(daysPayable-1)/365.25);
							document.getElementById("dvFeePayHeader").innerHTML= "Annual Fee";
	
						}
						
						chessFee = 825;
						GrandTotal = feePayable + chessFee;
						GrandTotalGST = GrandTotal * 1.1;
					break
					
					case "subsequent":
						document.getElementById("dvAnnualVariation").className = "hideBlock";
						document.getElementById("dvQuotationDate").className = "hideBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Additional Fee";
						feePayable = regCalc(totalValue,subsequentFees);
						chessFee = 0;
						GrandTotal = feePayable + chessFee;
						GrandTotalGST = GrandTotal * 1.1;

					break
					
				}
				
				
				var feeField = document.getElementById("dvPayableAmount");
				feePayable = Math.round(feePayable*100)/100;
				feePayable = addCommas(feePayable);
				feeField.innerHTML = "$" + feePayable;
	
				var feeChess = document.getElementById("dvChessFee");
				chessFee = Math.round(chessFee*100)/100;
				chessFee = addCommas(chessFee );
				feeChess.innerHTML = "$" + chessFee 
								
				var feeGT = document.getElementById("dvGrandTotal");
				GrandTotal = Math.round(GrandTotal*100)/100;
				GrandTotal = addCommas(GrandTotal);
				feeGT.innerHTML = "$" + GrandTotal;
				
				var feeGTG = document.getElementById("dvGrandTotalGST");
				GrandTotalGST= Math.round(GrandTotalGST*100)/100;
				GrandTotalGST= addCommas(GrandTotalGST);
				feeGTG.innerHTML = "$" + GrandTotalGST;
				
				
			}
			
			function securityListed(cbx)
			{
				var dateDiv = document.getElementById("dvQuotationDate");
				if(cbx.checked)
				{
				   dateDiv.className = "hideBlock";
				}else{
				   dateDiv.className = "showBlock";
				   
				}
			}
			
			
			function doFeeCalc()
			{
				var NumSecField = document.getElementById("dvNumSecurities");
				var numSecurities = parseFloat(document.getElementById("txtNumSecurities").value);
				if(isNaN(numSecurities))
				{
					numSecurities = 0;
				}
				NumSecField.innerHTML = addCommas(numSecurities); 				
				
				var SecValField = document.getElementById("dvSecValue");
				SecValField.innerHTML = "$"+calcSecVal();
				
				var secValue = parseFloat(calcSecVal());
				
				secValue = Math.round(secValue*1000)/1000;
												
				var totalValue = parseFloat(numSecurities) * secValue;
				totalValue = Math.round(totalValue*1000)/1000;
				var strTotalValue = String(totalValue);
				
				strTotalValue = padDecimal(strTotalValue,2);
				strTotalValue = addCommas(strTotalValue);
				
				
				var SecTotalField = document.getElementById("dvValue");
				SecTotalField.innerHTML = "$" + strTotalValue;
				
				var feeField = document.getElementById("dvPayableAmount");
				var feeType = document.getElementById("FeeType").value;
				var feePayable;
				var feeChess = document.getElementById("dvChessFee");
				var feeGT = document.getElementById("dvGrandTotal");
				var feeGTG = document.getElementById("dvGrandTotalGST");
				
				switch(feeType)
				{
					case "application":
						document.getElementById("dvAnnualVariation").className = "hideBlock";
						document.getElementById("dvQuotationDate").className = "hideBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Application Fee";
						feePayable = regCalc(totalValue,appFees);
						chessFee = 1650;
						GrandTotal = feePayable + chessFee;
						GrandTotalGST = GrandTotal * 1.1;
					break
					
					case "annual":
						document.getElementById("dvAnnualVariation").className = "showBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Annual Fee";
						feePayable = regCalc(totalValue,annualFees);
						if(!document.getElementById("cbListed").checked)
						{
							if(document.getElementById("txtDate").value.length == 0)
							{
								document.getElementById("txtDate").value = setDate();
							}
							document.getElementById("dvQuotationDate").className = "showBlock";
							var cDate = new Date();
							cDate = getQuoteDate();
							daysPayable = ((getFinYearEnd(cDate).getTime()-cDate.getTime())/msday);
							feePayable = feePayable * (Math.round(daysPayable)/ Math.round((getFinYearEnd(cDate).getTime()-getFinYearStart(cDate))/msday)/*365.25*/);
									
						}
						chessFee = 825;
						GrandTotal = feePayable + chessFee;
						GrandTotalGST = GrandTotal * 1.1;

					break
					
					case "subsequent":
						document.getElementById("dvAnnualVariation").className = "hideBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Additional Fee";
						document.getElementById("dvQuotationDate").className = "hideBlock";
						feePayable = regCalc(totalValue,subsequentFees);
						chessFee = 0;
						GrandTotal = feePayable + chessFee;
						GrandTotalGST = GrandTotal * 1.1;

					break
				
				}
								
				feePayable = Math.round(feePayable*100)/100;
				feePayable = addCommas(feePayable);
				feeField.innerHTML = "$" + feePayable;
				
				var feeChess = document.getElementById("dvChessFee");
				chessFee = Math.round(chessFee*100)/100;
				chessFee = addCommas(chessFee);
				feeChess.innerHTML = "$" + chessFee 
								
				var feeGT = document.getElementById("dvGrandTotal");
				GrandTotal = Math.round(GrandTotal*100)/100;
				GrandTotal = addCommas(GrandTotal);
				feeGT.innerHTML = "$" + GrandTotal;
				
				var feeGTG = document.getElementById("dvGrandTotalGST");
				GrandTotalGST= Math.round(GrandTotalGST*100)/100;
				GrandTotalGST= addCommas(GrandTotalGST);
				feeGTG.innerHTML = "$" + GrandTotalGST;

			}
			
			
			function feecalc(val,frmElement)
			{
				numericInput(val,frmElement);
				
				doFeeCalc();
				
			}
		

			function feeSchedule(lower,upper,base,rate)
			{
				this.lower = lower;
				this.upper = upper;
				this.base  = base;
				this.rate  = rate;
			}
			
			var annualFees = new Array();
			annualFees[0] = new feeSchedule(0,2000000,5500,0);
			annualFees[1] = new feeSchedule(2000001,10000000,5500,0.035)
			annualFees[2] = new feeSchedule(10000001,100000000,8300,0.0066)
			annualFees[3] = new feeSchedule(100000001,1000000000,14240,0.0012)
			annualFees[4] = new feeSchedule(1000000001,5600000000,25040,0.0011)
			annualFees[5] = new feeSchedule(5600000001,Infinity,75000,0)
						
			var appFees = new Array();
			appFees[0] = new feeSchedule(0,2000000,5500,0);
			appFees[1] = new feeSchedule(2000001,10000000,5500,0.11)
			appFees[2] = new feeSchedule(10000001,100000000,14300,0.033)
			appFees[3] = new feeSchedule(100000001,1000000000,44000,0.016)
			appFees[4] = new feeSchedule(1000000000,Infinity,188000,.0055)
			
			var subsequentFees = new Array();
			subsequentFees[0] = new feeSchedule(0,100000,550,0);
			subsequentFees[1] = new feeSchedule(100001,500000,550,0.1375)
			subsequentFees[2] = new feeSchedule(500001,2500000,1100,0.048)
			subsequentFees[3] = new feeSchedule(2500001,10000000,2060,0.02754)
			subsequentFees[4] = new feeSchedule(10000001,100000000,4125,0.0055)
			subsequentFees[5] = new feeSchedule(100000001,Infinity,9075,0.0022)
			
			
			function quarterDetail(startDay,startMonth,endDay,endMonth)
			{
				this.startDay   = startDay;
				this.startMonth = startMonth;
				this.endDay     = endDay;
				this.endMoth    = endMonth;
			}
			
			var finQuaters =new Array();
			finQuaters[0] = new quarterDetail(1,1,31,3)
			finQuaters[1] = new quarterDetail(1,1,31,3)
			finQuaters[2] = new quarterDetail(1,1,31,3)
			finQuaters[3] = new quarterDetail(1,6,30,6)
			finQuaters[4] = new quarterDetail(1,4,30,6)
			finQuaters[5] = new quarterDetail(1,4,30,6)
			finQuaters[6] = new quarterDetail(1,7,30,9)
			finQuaters[7] = new quarterDetail(1,7,30,9)
			finQuaters[8] = new quarterDetail(1,7,31,9)
			finQuaters[9] = new quarterDetail(1,10,31,12)
			finQuaters[10] = new quarterDetail(1,10,31,12)
			finQuaters[11] = new quarterDetail(1,10,31,12)
			
			
			function regCalc(totalValue,arrSched)
			{
				var baseFee;
				var threshold;
				var rate;
				var fee;
				
				for(i=0; i<arrSched.length; i++)
				{
					
					if(totalValue >= arrSched[i].lower && totalValue <= arrSched[i].upper)
					{
						baseFee   = arrSched[i].base;
						rate      = arrSched[i].rate;
						threshold = arrSched[i].lower-1;
						break;
					}
				}
				
				fee = baseFee + ((totalValue-threshold)*(rate/100));
				return fee;
			}
