			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 alertDate(field)
			{
				field.value = "Please Use Calendar Provided"
			}
		
			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;
				}else{
					ret = strInt + strDec;
					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;
				if(secVal<.2 && document.getElementById("FeeType").value == "initial")
				{
					secVal = 0.2;
					dvError.className = "showBlock";
				}else{
					dvError.className = "hideBlock";
				}
				secVal = String(secVal);
				secVal = addCommas(secVal);
				
				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 "initial":
						document.getElementById("dvAnnualVariation").className = "hideBlock";
						document.getElementById("dvQuotationDate").className = "hideBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Initial Fee Payable $";
						feePayable = regCalc(totalValue,initialFees);
						ds_hi();
					break
					
					case "annual":
						document.getElementById("dvAnnualVariation").className = "showBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Annual Fee Payable $";
						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);
							
						}
					break
					
					case "subsequent":
						document.getElementById("dvAnnualVariation").className = "hideBlock";
						document.getElementById("dvQuotationDate").className = "hideBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Subsequent Fee Payable $";
						feePayable = regCalc(totalValue,subsequentFees);
						ds_hi();
					break
					
				}
				
				
				var feeField = document.getElementById("dvPayableAmount");
				feePayable = Math.round(feePayable);
				feePayable = addCommas(feePayable);
				
				feeField.innerHTML = "$" + feePayable;
			}
			
			function securityListed(cbx)
			{
				var dateDiv = document.getElementById("dvQuotationDate");
				if(cbx.checked)
				{
				   dateDiv.className = "hideBlock";
				   ds_hi();
				}else{
				   dateDiv.className = "showBlock";
				}
			}
			
			
			function doCalc()
			{
				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;
				
				switch(feeType)
				{
					case "initial":
						document.getElementById("dvAnnualVariation").className = "hideBlock";
						document.getElementById("dvQuotationDate").className = "hideBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Initial Fee Payable $";
						feePayable = regCalc(totalValue,initialFees);
					break
					
					case "annual":
						document.getElementById("dvAnnualVariation").className = "showBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Annual Fee Payable $";
						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*/);
									
						}
					break
					
					case "subsequent":
						document.getElementById("dvAnnualVariation").className = "hideBlock";
						document.getElementById("dvFeePayHeader").innerHTML= "Subsequent Fee Payable $";
						document.getElementById("dvQuotationDate").className = "hideBlock";
						feePayable = regCalc(totalValue,subsequentFees);
					break
				
				}
								
				feePayable = Math.round(feePayable);
				feePayable = addCommas(feePayable);
				feeField.innerHTML = "$" + feePayable;
			}
			
			
			function calcResults(val,frmElement)
			{
				numericInput(val,frmElement);
				
				doCalc();
				
			}
		

			function feeSchedule(lower,upper,base,rate)
			{
				this.lower = lower;
				this.upper = upper;
				this.base  = base;
				this.rate  = rate;
			}

                        var initialFees = new Array();
                        initialFees[0] = new feeSchedule(          0,    3000000,  25000, 0);
                        initialFees[1] = new feeSchedule(    3000000,   10000000,  25000, 0.2671429)
                        initialFees[2] = new feeSchedule(   10000000,   50000000,  43700, 0.07975)
                        initialFees[3] = new feeSchedule(   50000000,  100000000,  75600, 0.04004)
                        initialFees[4] = new feeSchedule(  100000000,  500000000,  95620, 0.03)
                        initialFees[5] = new feeSchedule(  500000000, 1000000000, 215620, 0.025)
                        initialFees[6] = new feeSchedule( 1000000000,   Infinity, 340620, 0.018)

			var annualFees = new Array();
			annualFees[0] = new feeSchedule(           0,     3000000,   9990, 0);
			annualFees[1] = new feeSchedule(     3000000,    10000000,   9990, 0.1425)
			annualFees[2] = new feeSchedule(    10000000,   100000000,  19970, 0.0154)
			annualFees[3] = new feeSchedule(   100000000,  1000000000,  33800, 0.002865)
			annualFees[4] = new feeSchedule(  1000000000, 10000000000,  59590, 0.00088)
			annualFees[5] = new feeSchedule( 10000000000,   Infinity,  138790, 0.00009)

                        var subsequentFees = new Array();
                        subsequentFees[0] = new feeSchedule(         0,    100000,   1500, 0);
                        subsequentFees[1] = new feeSchedule(    100000,    500000,   1500, 0.425)
                        subsequentFees[2] = new feeSchedule(    500000,   2500000,   3200, 0.25)
                        subsequentFees[3] = new feeSchedule(   2500000,  10000000,   8200, 0.13)
                        subsequentFees[4] = new feeSchedule(  10000000,  20000000,  17950, 0.05)
                        subsequentFees[5] = new feeSchedule(  20000000,  50000000,  22950, 0.04)
                        subsequentFees[6] = new feeSchedule(  50000000, 100000000,  34950, 0.03)
                        subsequentFees[7] = new feeSchedule( 100000000, 500000000,  49950, 0.025)
                        subsequentFees[8] = new feeSchedule( 500000000,  Infinity, 149950, 0.02)

			
			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[0] = new quarterDetail(1,10,31,12)
			finQuaters[0] = 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;
						break;
					}
				}
				fee = baseFee + ((totalValue-threshold)*(rate/100));
				return fee;
			}

