$(function(){$("select[id*=TaxStatusDropDownList]").change(function(){if($(this).children("[selected]").text()=="Non-Resident Withholding Tax"){$(".countryoforigin").show();enableValidator($(".countryoforigin").next("span[id*=Validator]")[0].id,true)}else{$(".countryoforigin").hide();enableValidator($(".countryoforigin").next("span[id*=Validator]")[0].id,false)}});$("select[id*=AnyLargeExpensesDropDownList]").each(function(){$(this).change(function(){if($(this).val()=="Yes"){$(this).parent().parent().next().show();$("#howMuchNeedToSetAsideRow span[id*=Validator]").each(function(){enableValidator(this.id,true)})}else{$(this).parent().parent().next().hide();$("#howMuchNeedToSetAsideRow span[id*=Validator]").each(function(){enableValidator(this.id,false);$(this).hide()})}$("#howMuchNeedToSetAsideRow input").restoreDefaults("")})});var g=$("select[id*=TaxStatusDropDownList]");$(g).children("[selected]").text()=="Non-Resident Withholding Tax"&&$(".countryoforigin").show();var d=$("select[id*=AnyLargeExpensesDropDownList]");$(d).val()=="Yes"&&$(d).parent().parent().next().show();var e=$("select[id*=AnnualIncomeTypeDropDownList]").val();(e=="Gross"||e=="Net")&&GetGAIwithAjaxCall();$("select.TypeOfInvestment").each(function(){$(this).val()=="1"&&$(this).parent().next().find("input").show();$(this).change(function(){if($(this).val()=="1")$(this).parent().next().find("input").show().focus();else $(this).parent().next().find("input").hide().restoreDefaults("")})});$("#AnnualIncomeRow select,#AnnualIncomeRow input").change(function(){GetGAIwithAjaxCall()});$(".CallOptionsRow, td .FixedOptionsRow").hide();$(".CallOptionsRow:first, td .FixedOptionsRow:first").show().find("a.RemoveInvestmentLink").hide();$(".IndivativeFixedInvestmentPart, .IndivativeFixedInvestmentRow").hide();$("#numberOfInvestments").val("0");$("#numberOfCallOptions, #numberOfFixedOptions").val("1");$(".InvestmentsRow, #howMuchNeedToSetAsideRow").find("span[id*=Validator]").each(function(){enableValidator(this.id,false)});$(".countryoforigin").next("span[id*=Validator]").each(function(){enableValidator(this.id,false)});$(".FixedOptionsRow .dropdowncolumn select").change(function(){if($(this).val()=="termFund"){$(this).parent().parent().find(".termcolumn select[id*=TermDepsitDropDownList]").hide();$(this).parent().parent().find(".termcolumn select[id*=TermFundDropDownList]").show()}else if($(this).val()=="termDeposit"){$(this).parent().parent().find(".termcolumn select[id*=TermDepsitDropDownList]").show();$(this).parent().parent().find(".termcolumn select[id*=TermFundDropDownList]").hide()}DisplayRate($(this).attr("id"));var a=$(this).parent().parent().prevAll().length;$(".IndivativeFixedInvestmentRow:visible").eq(a).find(".productNamefield").text($(this).find("option:selected").text());GetIncomeforFixedTermInvestment(a)}).change();$(".FixedOptionsRow .amountcolumn input, .FixedOptionsRow .termcolumn select").change(function(){if($(this).parent().parent().find("[id*='CurrencyValidator']")[0].isvalid){var b=$(this).parent().parent().prevAll().length;$(".IndivativeFixedInvestmentPart").show();for(var a=0;a<=b;a++)if($.browser.msie)$(".IndivativeFixedInvestmentRow").eq(a).css("display","block");else $(".IndivativeFixedInvestmentRow").eq(a).css("display","table-row");GetIncomeforFixedTermInvestment(b);$(".IndivativeFixedInvestmentRow:visible").eq(b).find(".productNamefield").text($(this).parent().parent().find("select[id*='FixedInvestmentDropDownList'] option:selected").text())}});$("input[id*=AmountAvailableToInvestTextBox]").change(function(){ShowPrivateBankingInformation($(this).val())});$("input[id*='Amount'],input[id*='Expense']").change(function(){var a="";if($(this).next("span").length>0)a=$(this).next("span")[0].id;else if($(this).next("div").find("span").length>0)a=$(this).next("div").find("span")[0].id;else if($(this).parent("div").next("div").next("div").find("span").length>0)a=$(this).parent("div").next("div").next("div").find("span")[0].id;else if($(this).parent("div").parent("div").find("span").length>0)a=$(this).parent("div").parent("div").find("span")[0].id;a!=""&&formatCurrency($(this)[0],a)});var a=$("select[id*=FundsAvailableToInvestInFutureDropDownList]").val()==="Yes";if(a){var c=false,b=$("#numberOfInvestments").val();$("#ExistingInvestments .InvestmentsRow").each(function(){var d=0;$(this).find("select, input").each(function(){if($(this).val()!==""&&$(this).val()!=="0")d++});if(a&&d>0){c=true;$(this).show().find("span[id*=Validator]").each(function(){enableValidator(this.id,true)});b++}});$("#numberOfInvestments").val(b);HideRemoveWhenOnlyOne("Investments",1);var f=5;b>=f&&$("#LinkAddInvestments").hide();a&&c&&$("#ExistingInvestments").show();a&&c==false&&addRow("Investments")}$("select[id*=FundsAvailableToInvestInFutureDropDownList]").each(function(){$(this).change(function(){if($(this).val()==="Yes")addRow("Investments",this);else{removeAllInvestmentsRows();$("#ExistingInvestments").hide();$("#numberOfInvestments").val("0")}})});$(".CallOptionsRow .amountcolumn input").each(function(){var a=$(this).val();a!=""&&$(this).parents(".CallOptionsRow").show()});$("#numberOfCallOptions").val($(".CallOptionsRow:visible").length);HideRemoveWhenOnlyOne("CallOptions",1);$(".FixedOptionsRow .amountcolumn input").each(function(a){var b=$(this).val();if(b!==""){$(".IndivativeFixedInvestmentPart").show();$(this).parents(".FixedOptionsRow").show();$(".IndivativeFixedInvestmentRow").eq(a).show().find(".productNamefield").text($(this).parent().parent().find("select[id*='FixedInvestmentDropDownList'] option:selected").text());GetIncomeforFixedTermInvestment(a)}});$("#numberOfFixedOptions").val($(".FixedOptionsRow:visible").length-1);HideRemoveWhenOnlyOne("FixedOptions",1);$("input[id*=AmountAvailableToInvestTextBox]").length>0&&ShowPrivateBankingInformation($("input[id*=AmountAvailableToInvestTextBox]").val());SetDefaultButton("ctl00_MainContentPanel")});function addRow(b,e){var d=5,a=$("#numberOf"+b).val();if(b==="Investments")a==0&&$("#ExistingInvestments").show();if(a<d){a++;var c=$("div."+b+"Row:hidden:eq(0)");c.slideDown();rowNumber=a-1;c.find("span[id*=Validator]").each(function(){enableValidator(this.id,true)});c.find("input").restoreDefaults("");$("#numberOf"+b).val(a)}a>=d&&$("#LinkAdd"+b).hide();HideRemoveWhenOnlyOne(b,1);e&&e!==null&&OmnitureTrackingCode.CaptureButtonEventForButtonUsed(true,"calculator:cashinvestmentplanner:addinvestment")}function removeRow(a,b,g){var e=$(a).prevAll().length;$(a).find("input").restoreDefaults("").removeClass("errorhighlight");$(a).find("select").restoreSelectDefaults("");b==="Investments"&&$(a).find("input[id*='MaturityDate']").hide();var d=$("#numberOf"+b).val();(e!=4||d!=5)&&$(a).insertAfter("div."+b+"Row:last");$(a).slideUp();$("#LinkAdd"+b).show();$("#numberOf"+b).val(d-1);if(b=="FixedOptions"){var c=$(".IndivativeFixedInvestmentRow:visible").eq(e);$(c).find(".productNamefield").text("National Bank Term Deposit");$(c).find(".GrossIncome, .LessTax, .NetIncome").text("$0.00");(e!=4||d!=5)&&$(c).insertAfter(".IndivativeFixedInvestmentRow:last");$(c).hide();var f=0;$(".IndivativeFixedInvestmentRow").each(function(){f+=1;$(this).find(".number").text(f)});CalculateTotalIncomeAfterTax()}$(a).find("span[id*=Validator]").each(function(){enableValidator(this.id,false);$(this).hide()});HideRemoveWhenOnlyOne(b,2);g&&g!==null&&OmnitureTrackingCode.CaptureButtonEventForButtonUsed(true,"calculator:cashinvestmentplanner:remove")}function removeAllInvestmentsRows(){$(".InvestmentsRow input").restoreDefaults("");$(".InvestmentsRow select").restoreSelectDefaults("");$(".InvestmentsRow input[id*='MaturityDate']").hide();$(".InvestmentsRow").slideUp();$("#LinkAddInvestments").show();$(".InvestmentsRow span[id*=Validator]").each(function(){enableValidator(this.id,false);$(this).hide()})}function HideRemoveWhenOnlyOne(a,b){if($("div."+a+"Row:visible").length==b)$("div."+a+"Row:visible").find("a.RemoveInvestmentLink").hide();else $("div."+a+"Row:visible").find("a.RemoveInvestmentLink").show()}$.fn.restoreDefaults=function(){return this.each(function(){$(this).val("").removeClass("errorhighlight")})};$.fn.restoreSelectDefaults=function(){return this.each(function(){if($.browser.msie)$(this).val($(this).find("option:first").val());else $(this).val($(this).find("option[selected='selected']").val())})};function GetGAIwithAjaxCall(){if($("[id*='AnnualIncomeAmountTextBoxCurrencyValidator']")[0].isvalid){var c=$("select[id*=AnnualIncomeTypeDropDownList]").val(),a=$("select[id*=AnnualIncomeFrequencyDropDownList]").val(),b=$("input[id*=AnnualIncomeAmountTextBox]").val();if(c==""||a==""||b=="")return;var d="{'annualIncomeType': '"+c+"', 'annualIncomeFrequency': '"+a+"', 'incomeAmountText': '"+b+"'}";$.ajax({url:"cashinvestmentplanner.aspx/GetGrossAnnualIncome",data:d,success:function(a){$("span[id*=GrossAnnualIncomeLabel]").html(a.Message)}})}}function DisplayRate(a){$("#"+a).parent().parent().find(".rate span span").hide();var b=$("#"+a).parent().parent().find(".dropdowncolumn select").val(),c=$("#"+a).parent().parent().find(".termcolumn select").val();$("#"+a).parent().parent().find(".rate span[id*="+b+"] span[id="+c+"]").show()}function GetIncomeforFixedTermInvestment(a){var b=$("td .FixedOptionsRow").eq(a);if($(b).find("[id*='CurrencyValidator']")[0].isvalid){var f=$(b).find(".dropdowncolumn select").val(),c=$(b).find(".amountcolumn input").val();if(c==null)c=0;var i=$(b).find(".termcolumn select:visible").val(),g=$("[id$=TaxRateHiddenField]").val(),d=$("[id$=PrescribedInvestorRateHiddenField]").val(),e=$("[id$=CountryCodeHiddenField]").val(),h="{'product': '"+f+"','amount': '"+c+"','term': '"+i+"','taxRate': '"+g+"','countryCode': '"+e+"','prescribedInvestorRate': '"+d+"'}";$.ajax({url:"cashinvestmentplanner.aspx/GetIndicativeFixedInvestmentDepositIncome",data:h,success:function(b){$(".IndivativeFixedInvestmentRow .GrossIncome").eq(a).html(b.grossIncome);$(".IndivativeFixedInvestmentRow .LessTax").eq(a).html(b.lessTax);$(".IndivativeFixedInvestmentRow .NetIncome").eq(a).html(b.netIncome);$(".FixedOptionsRow .rate").eq(a).html("@ "+b.interestRate);CalculateTotalIncomeAfterTax()}})}else{$(".IndivativeFixedInvestmentRow .GrossIncome").eq(a).html("$0.00");$(".IndivativeFixedInvestmentRow .LessTax").eq(a).html("$0.00");$(".IndivativeFixedInvestmentRow .NetIncome").eq(a).html("$0.00")}}function CalculateTotalIncomeAfterTax(){var a=0;$(".IndivativeFixedInvestmentRow .NetIncome").each(function(){var b=$(this).html().replace(/\,/g,"");if(!isNaN(b.substring(1)))a+=eval(b.substring(1))});a=ThousandSeparator(a.toFixed(2));$("#TotalIncomeAfterTax").html("$"+a)}function ThousandSeparator(c){var b=new RegExp("(-?[0-9]+)([0-9]{3})"),a=c+"";while(b.test(a))a=a.replace(b,"$1,$2");return a}function ShowPrivateBankingInformation(c){var a=1e6,d=c.replace(/\,/g,""),b=d-0;if(b>=a&&$("[id*='AmountAvailableToInvestTextBoxCurrencyValidator']")[0].isvalid)$("#CIPinformation").slideDown();else $("#CIPinformation").slideUp()}function ValidateMinimumFixedTermDeposit(c,d){var a=5e3,b=$("#"+c.id).parents("div[class$='OptionsRow']").find(".amountcolumn input").val();d.IsValid=!(b.replace(/\,/g,"")<a)}$(function(){$("div.FixedOptionsRow").each(function(){var b=$(this).find(".dropdowncolumn select")[0].id,c=$(this).find(".amountcolumn input")[0].id,a=$(this).find("span[id*='MinimumFixedTermDepositValidator']")[0].id;ValidatorHookupControlID(b,document.getElementById(a))})});$(function(){$('[name$="hideshow"]').click(function(){if($(this).val()=="Yes")$("#current_customer_Yes_ToShow").show();else $(this).val()=="No"&&$("#current_customer_Yes_ToShow").hide()});$("#clear").click(function(){$("[id$='ToShow']").hide();for(i=0;i<Page_Validators.length;i++){Page_Validators[i].isvalid=true;ClearValidatorCallouts();$(Page_Validators[i]).css("display","none")}})});
