//global Object
var GRAlObj     = new CalculateRiskAnalyser();
var GRAlConstObj   = new CalcRiskAnalyserConstants();
/*************************Main Object that holds all function and data related to the Module**************************/
function CalculateRiskAnalyser(){
 try{
//[Common Variable Starts]	
		 this.asset_Cap_Eqt_per = 0;
		 this.asset_Tol_Eqt_per = 0;
		 this.risk_Cap_Per=0	;
		 this.risk_Tol_Per=0	;
//[Common Variable Ends]	

//[Main Variable Starts]	
		this.v_main_age=0;
		this.v_main_dep_age10=0;
		this.v_main_dep_age11_18=0;
		this.v_main_dep_age19_25=0;
		this.v_main_handicap_dep=0;
		this.v_main_aged_dep=0;		
		this.v_main_month_save=0;
		this.v_main_sust_month=0;
		this.v_main_sec_income=2;
		this.v_main_reinv_income=0;
		this.v_main_fin_goals=0;

		this.v_main_inhr_wealth=0;
		this.v_main_inc_cover=0;		
		this.v_main_fin_supp=1;

		this.v_main_quiz_game=1;
		this.v_main_start_buss=1;
		this.v_main_play_card=1;
		this.v_main_play_bet=1;
		this.v_main_compensation=1;
		this.v_main_risk=1;		
		this.v_main_Short_term=1;
		this.v_main_portfolio=1;
		this.v_main_inv_venture=1;
		this.v_main_offer=1;		

		this.v_main_newInvestor=1;
		this.v_main_trade_or_invest=1;
		this.v_main_retail_highvol=1;		
		this.v_main_monthly_fee=1;
//[Main Variable Ends]	

		this.populateAll = function (p_type){
			if(p_type == 'main'){
				if(populateRiskAnalyser(p_type)){//returns TRUE if validation succeeds 
					return false;
				}else{
					return true;
				}
			}
		}	

		this.resetAll = function (p_type,resetType){//resetType:both(fields and object) & resetType:fields(fields only) & & resetType:object(object only)
				if(p_type == 'main'){
					if(resetType == 'both'){
						resetRiskAnalyser(p_type,resetType)																	
					}
				}
			}


		this.calculateRiskTakCapacity = function(){
			var temp_score_age=0;
			var temp_score_dep_age10=0;
			var temp_score_dep_age11_18=0;
			var temp_score_dep_age19_25=0;
			var temp_score_handicap_dep=0;
			var temp_score_aged_dep=0;		
			var temp_score_month_save=0;
			var temp_score_sust_month=0;
			var temp_score_sec_income=0;
			var temp_score_reinv_income=0;
			var temp_score_fin_goals=0;
			var temp_score_inhr_wealth=0;
			var temp_score_inc_cover=0;		
			var temp_score_fin_supp=0;
	
			var tot_RespRiskCapScore=0;
			var tot_MaxRiskCapScore=0;
			var riskCap_Per=0;
			if(this.v_main_age >= 0 && this.v_main_age <= 25){
				temp_score_age = GRAlConstObj.maxscore_age
			}else if(this.v_main_age >= 26 && this.v_main_age <= 30){
				temp_score_age = (GRAlConstObj.maxscore_age*85/100)
			}else if(this.v_main_age >= 31&& this.v_main_age <= 40){
				temp_score_age = (GRAlConstObj.maxscore_age*70/100)
			}else if(this.v_main_age >= 41 && this.v_main_age <= 55){
				temp_score_age = (GRAlConstObj.maxscore_age*60/100)
			}else if(this.v_main_age >= 56 && this.v_main_age <= 65){
				temp_score_age = (GRAlConstObj.maxscore_age*50/100)
			}else{
				temp_score_age = 0
			}

//			alert('temp_score_age  '+temp_score_age)

			if(this.v_main_dep_age10 == 0){
				temp_score_dep_age10=GRAlConstObj.maxscore_dep_age10 
			}else if(this.v_main_dep_age10 == 1){
				temp_score_dep_age10=(GRAlConstObj.maxscore_dep_age10 *67/100)
			}else if(this.v_main_dep_age10 == 2){
				temp_score_dep_age10=(GRAlConstObj.maxscore_dep_age10 * 33/100)
			}else{
				temp_score_dep_age10=0
			}
//			alert('temp_score_dep_age10'+temp_score_dep_age10)

			if(this.v_main_dep_age11_18 == 0){
				temp_score_dep_age11_18=GRAlConstObj.maxscore_dep_age11_18;
			}else if (this.v_main_dep_age11_18 == 1){
				temp_score_dep_age11_18=(GRAlConstObj.maxscore_dep_age11_18*50/100);
			}else{
				temp_score_dep_age11_18=0;
			}
//			alert('temp_score_dep_age11_18  '+temp_score_dep_age11_18)

			if(this.v_main_dep_age19_25 == 0){
				temp_score_dep_age19_25=GRAlConstObj.maxscore_dep_age19_25;
			}else if (this.v_main_dep_age19_25 == 1){
				temp_score_dep_age19_25=(GRAlConstObj.maxscore_dep_age19_25*50/100);
			}else{
				temp_score_dep_age19_25=0;
			}
//			alert('temp_score_dep_age19_25  '+temp_score_dep_age19_25)

			if(this.v_main_handicap_dep == 0){
				temp_score_handicap_dep=GRAlConstObj.maxscore_handicap_dep
			}else if(this.v_main_handicap_dep == 1){
				temp_score_handicap_dep=(GRAlConstObj.maxscore_handicap_dep*75/100)
			}else if(this.v_main_handicap_dep == 2){
				temp_score_handicap_dep=(GRAlConstObj.maxscore_handicap_dep* 50/100)
			}else{
				temp_score_handicap_dep=0
			}
//			alert('temp_score_handicap_dep '+temp_score_handicap_dep)

			if(this.v_main_aged_dep == 0){
				temp_score_aged_dep=GRAlConstObj.maxscore_aged_dep
			}else if(this.v_main_aged_dep == 1){
				temp_score_aged_dep=(GRAlConstObj.maxscore_aged_dep*75/100)
			}else if(this.v_main_aged_dep == 2){
				temp_score_aged_dep=(GRAlConstObj.maxscore_aged_dep* 50/100)
			}else{
				temp_score_aged_dep=0
			}
//			alert('temp_score_aged_dep  '+temp_score_aged_dep)

			if (this.v_main_month_save >= (0/100) && this.v_main_month_save <= (15/100)){
				 temp_score_month_save = (GRAlConstObj.maxscore_month_save*25/100)
			}else if (this.v_main_month_save >= (16/100) && this.v_main_month_save <= (30/100)){
				 temp_score_month_save = (GRAlConstObj.maxscore_month_save*40/100)
			}else if (this.v_main_month_save >= (31/100) && this.v_main_month_save <= (45/100) ){
				 temp_score_month_save = (GRAlConstObj.maxscore_month_save*50/100)
			}else if (this.v_main_month_save >= (46/100) && this.v_main_month_save <= (60/100)){
				 temp_score_month_save = (GRAlConstObj.maxscore_month_save*60/100)
			}else if (this.v_main_month_save >= (61/100) && this.v_main_month_save <= (75/100)){
				 temp_score_month_save = (GRAlConstObj.maxscore_month_save*75/100)
			}else if (this.v_main_month_save >= (76/100) && this.v_main_month_save <= (90/100)){
				 temp_score_month_save = (GRAlConstObj.maxscore_month_save*90/100)
			}else{
				 temp_score_month_save = GRAlConstObj.maxscore_month_save
			}
//			alert('temp_score_month_save   '+temp_score_month_save )


		if (this.v_main_sust_month >= 0 && this.v_main_sust_month <= 1){
			temp_score_sust_month=0
		}else if  (this.v_main_sust_month >= 2 && this.v_main_sust_month <= 3){
			temp_score_sust_month=(GRAlConstObj.maxscore_sust_month*30/100)
		}else if  (this.v_main_sust_month >= 4 && this.v_main_sust_month <= 6){
			temp_score_sust_month=(GRAlConstObj.maxscore_sust_month*50/100)
		}else if  (this.v_main_sust_month >= 7 && this.v_main_sust_month <= 9){
			temp_score_sust_month=(GRAlConstObj.maxscore_sust_month*60/100)
		}else if  (this.v_main_sust_month >= 10 && this.v_main_sust_month  <= 12){
			temp_score_sust_month=(GRAlConstObj.maxscore_sust_month*90/100)
		}else {
			temp_score_sust_month=GRAlConstObj.maxscore_sust_month
		}
//		alert('temp_score_sust_month '+temp_score_sust_month)

		if(this.v_main_sec_income == 1){
			temp_score_sec_income=GRAlConstObj.maxscore_sec_income;
		}else if (this.v_main_sec_income == 2){
			temp_score_sec_income=(GRAlConstObj.maxscore_sec_income*57/100);
		}else{
			temp_score_sec_income=0;
		}
//		alert('temp_score_sec_income  '+temp_score_sec_income)

		if(this.v_main_reinv_income == 1){
			temp_score_reinv_income=GRAlConstObj.maxscore_reinv_income;
		}else {
			temp_score_reinv_income=0;
		}
//		alert('temp_score_reinv_income  '+temp_score_reinv_income)

		if (this.v_main_fin_goals >= 0/100 && this.v_main_fin_goals <= 10/100){
			temp_score_fin_goals=GRAlConstObj.maxscore_fin_goals
		}else if (this.v_main_fin_goals >= 11/100 && this.v_main_fin_goals <= 25/100){
			temp_score_fin_goals=(GRAlConstObj.maxscore_fin_goals*80/100)
		}else if (this.v_main_fin_goals >= 26/100 && this.v_main_fin_goals <= 35/100){
			temp_score_fin_goals=(GRAlConstObj.maxscore_fin_goals*60/100)
		}else if (this.v_main_fin_goals >= 36/100 && this.v_main_fin_goals <= 45/100){
			temp_score_fin_goals=(GRAlConstObj.maxscore_fin_goals*40/100)
		}else if (this.v_main_fin_goals >= 46/100 && this.v_main_fin_goals <= 75/100){
			temp_score_fin_goals=(GRAlConstObj.maxscore_fin_goals*20/100)
		}else if (this.v_main_fin_goals >= 76/100 && this.v_main_fin_goals <= 95/100){
			temp_score_fin_goals=(GRAlConstObj.maxscore_fin_goals*7/100)
		}else{
			temp_score_fin_goals=0
		}
//		alert('temp_score_fin_goals  '+temp_score_fin_goals)

		if (this.v_main_inhr_wealth >= 0/100,this.v_main_inhr_wealth <= 15/100){
			temp_score_inhr_wealth=0
		}else if(this.v_main_inhr_wealth >= 16/100,this.v_main_inhr_wealth <= 35/100){
			temp_score_inhr_wealth=(GRAlConstObj.maxscore_inhr_wealth*29/100)
		}else if(this.v_main_inhr_wealth >= 36/100,this.v_main_inhr_wealth <= 45/100){
			temp_score_inhr_wealth=(GRAlConstObj.maxscore_inhr_wealth*57/100)
		}else if(this.v_main_inhr_wealth >= 46/100,this.v_main_inhr_wealth <= 75/100){
			temp_score_inhr_wealth=(GRAlConstObj.maxscore_inhr_wealth*71/100)
		}else if(this.v_main_inhr_wealth >= 76/100,this.v_main_inhr_wealth <= 85/100){
			temp_score_inhr_wealth=(GRAlConstObj.maxscore_inhr_wealth*86/100)
		}else {	
			temp_score_inhr_wealth=GRAlConstObj.maxscore_inhr_wealth
		}
//		alert('temp_score_inhr_wealth  '+temp_score_inhr_wealth)

		if (this.v_main_inc_cover >= 0 && this.v_main_inc_cover <= 2){
			temp_score_inc_cover=0
		}else if(this.v_main_inc_cover >= 3 && this.v_main_inc_cover <= 8){
			temp_score_inc_cover=(GRAlConstObj.maxscore_inc_cover*67/100)
		}else{
			temp_score_inc_cover=GRAlConstObj.maxscore_inc_cover
		}
//		alert('temp_score_inc_cover  '+temp_score_inc_cover)

		if(this.v_main_fin_supp == 1){
			temp_score_fin_supp=GRAlConstObj.maxscore_fin_supp;
		}else {
			temp_score_fin_supp=0;
		}
//		alert('temp_score_fin_supp  '+temp_score_fin_supp )

		tot_RespRiskCapScore=	temp_score_age+temp_score_dep_age10+temp_score_dep_age11_18+temp_score_dep_age19_25+
														temp_score_handicap_dep+temp_score_aged_dep+temp_score_month_save+
														temp_score_sust_month+temp_score_sec_income+temp_score_reinv_income+
														temp_score_fin_goals+temp_score_inhr_wealth+temp_score_inc_cover+temp_score_fin_supp
		tot_MaxRiskCapScore =	GRAlConstObj.maxscore_age+GRAlConstObj.maxscore_dep_age10+GRAlConstObj.maxscore_dep_age11_18+GRAlConstObj.maxscore_dep_age19_25+
														GRAlConstObj.maxscore_handicap_dep+GRAlConstObj.maxscore_aged_dep+GRAlConstObj.maxscore_month_save+
														GRAlConstObj.maxscore_sust_month+GRAlConstObj.maxscore_sec_income+GRAlConstObj.maxscore_reinv_income+
														GRAlConstObj.maxscore_fin_goals+GRAlConstObj.maxscore_inhr_wealth+GRAlConstObj.maxscore_inc_cover+GRAlConstObj.maxscore_fin_supp
		riskCap_Per=Math.round(tot_RespRiskCapScore/tot_MaxRiskCapScore*100)
		 this.risk_Cap_Per=riskCap_Per;
/*
		alert('temp_score_age  '+temp_score_age+'\n'
					+'temp_score_dep_age10'+temp_score_dep_age10+'\n'
					+'temp_score_dep_age11_18  '+temp_score_dep_age11_18+'\n'
					+'temp_score_dep_age19_25  '+temp_score_dep_age19_25+'\n'
					+'temp_score_handicap_dep '+temp_score_handicap_dep+'\n'
					+'temp_score_aged_dep  '+temp_score_aged_dep+'\n'
					+'temp_score_month_save   '+temp_score_month_save +'\n'
					+'temp_score_sust_month '+temp_score_sust_month+'\n'
					+'temp_score_sec_income  '+temp_score_sec_income+'\n'
					+'temp_score_fin_goals  '+temp_score_fin_goals+'\n'
					+'temp_score_inhr_wealth  '+temp_score_inhr_wealth+'\n'
					+'temp_score_inc_cover  '+temp_score_inc_cover+'\n'
					+'temp_score_fin_supp  '+temp_score_fin_supp +'\n'
		)
*/
//		alert('tot_RespRiskCapScore  '+tot_RespRiskCapScore);
//		alert('tot_MaxRiskCapScore  '+tot_MaxRiskCapScore );
		//alert('riskCap_Per '+riskCap_Per);

		var assetAlloDebt_per=0
		var assetAlloEqt_per=0
		var temp_riskTakingCapStr='';
		
		if (riskCap_Per >= 0 && riskCap_Per <= 25){
			temp_riskTakingCapStr="Kotak Flat"
		}else if (riskCap_Per >= 26 && riskCap_Per <= 45.99){
			temp_riskTakingCapStr="Low-Medium"
		}else if (riskCap_Per >= 46 && riskCap_Per <= 60.99){
			temp_riskTakingCapStr="Medium"
		}else if (riskCap_Per >= 61 && riskCap_Per <= 75.99){
			temp_riskTakingCapStr="Medium-High"
		}else if (riskCap_Per >= 76 && riskCap_Per <= 90.99){
			temp_riskTakingCapStr="High"
		}else {
			temp_riskTakingCapStr="Very High"
		}

		var assetAllo_Cap_Eqt_per =new Number(getRiskCap_Tol_Per(riskCap_Per).split('~')[0]);
		var assetAllo_Cap_Debt_per =new Number(getRiskCap_Tol_Per(riskCap_Per).split('~')[1]);
		 this.asset_Cap_Eqt_per = assetAllo_Cap_Eqt_per ;
		//alert('this.asset_Cap_Eqt_per   '+this.asset_Cap_Eqt_per);

		//alert('temp_riskTakingCapStr  '+temp_riskTakingCapStr);
		//alert('assetAllo_Cap_Eqt_per  == '+assetAllo_Cap_Eqt_per+'   assetAllo_Cap_Debt_per='+assetAllo_Cap_Debt_per);
	}

	this.calculateRiskTolerance= function(){
		var temp_score_quiz_game=0;
		var temp_score_start_buss=0;
		var temp_score_play_card=0;
		var temp_score_play_bet=0;
		var temp_score_compensation=0;
		var temp_score_risk=0;		
		var temp_score_Short_term=0;
		var temp_score_portfolio=0;
		var temp_score_inv_venture=0;
		var temp_score_offer=0;		

		if(this.v_main_quiz_game == 1){
			temp_score_quiz_game=0
		}else{
			temp_score_quiz_game=GRAlConstObj.maxscore_quiz_game
		}
	
		if(this.v_main_start_buss== 1){
			temp_score_start_buss=GRAlConstObj.maxscore_start_buss
		}else{
			temp_score_start_buss=0
		}

		if(this.v_main_play_card== 1){
			temp_score_play_card=GRAlConstObj.maxscore_play_card
		}else{
			temp_score_play_card=0
		}

		if(this.v_main_play_bet== 1){
			temp_score_play_bet=GRAlConstObj.maxscore_play_bet
		}else if(this.v_main_play_bet== 2){
			temp_score_play_bet=GRAlConstObj.maxscore_play_bet * (50/100)
		}else{
			temp_score_play_bet=0
		}

		if(this.v_main_compensation== 1){
			temp_score_compensation=0
		}else{
			temp_score_compensation=GRAlConstObj.maxscore_compensation
		}
	
		if(this.v_main_risk== 1){
			temp_score_risk=0
		}else if(this.v_main_risk== 2){
			temp_score_risk=GRAlConstObj.maxscore_risk * (20/100)
		}else if(this.v_main_risk== 3){
			temp_score_risk=GRAlConstObj.maxscore_risk * (60/100)
		}else{
			temp_score_risk=GRAlConstObj.maxscore_risk
		}

		if(this.v_main_Short_term== 1){
			temp_score_Short_term=GRAlConstObj.maxscore_Short_term * (80/100)
		}else if(this.v_main_Short_term== 2){
			temp_score_Short_term=GRAlConstObj.maxscore_Short_term 
		}else if(this.v_main_Short_term== 3){
			temp_score_Short_term=GRAlConstObj.maxscore_Short_term * (5/100)
		}else{
			temp_score_Short_term=0
		}

		if(this.v_main_portfolio== 1){
			temp_score_portfolio=GRAlConstObj.maxscore_portfolio
		}else if(this.v_main_portfolio== 2){
			temp_score_portfolio=GRAlConstObj.maxscore_portfolio * (50/100)
		}else{
			temp_score_portfolio=0
		}

		if(this.v_main_inv_venture== 1){
			temp_score_inv_venture=GRAlConstObj.maxscore_inv_venture * (80/100)
		}else if(this.v_main_inv_venture== 2){
			temp_score_inv_venture=GRAlConstObj.maxscore_inv_venture 
		}else if(this.v_main_inv_venture== 3){
			temp_score_inv_venture=GRAlConstObj.maxscore_inv_venture * (5/100)
		}else{
			temp_score_inv_venture=0
		}

		if(this.v_main_offer== 1){
			temp_score_offer=GRAlConstObj.maxscore_offer * (80/100)
		}else if(this.v_main_offer== 2){
			temp_score_offer=GRAlConstObj.maxscore_offer 
		}else if(this.v_main_offer== 3){
			temp_score_offer=GRAlConstObj.maxscore_offer * (5/100)
		}else{
			temp_score_offer=0
		}

/*	alert(
				temp_score_quiz_game+'        '+temp_score_start_buss+'        '+temp_score_play_card+'        '
				+temp_score_play_bet+'        '+temp_score_compensation+'        '+temp_score_risk+'        '
				+temp_score_Short_term+'        '+temp_score_portfolio+'        '+temp_score_inv_venture+'        '
				+temp_score_offer
	)
*/		var tot_RespRiskTolScore=0
		var tot_MaxRiskTolScore =0
		var riskTol_Per=0
		var temp_riskTakingTolStr;
		tot_RespRiskTolScore=temp_score_quiz_game+temp_score_start_buss+temp_score_play_card+
													 temp_score_play_bet+temp_score_compensation+temp_score_risk+		
													 temp_score_Short_term+temp_score_portfolio+temp_score_inv_venture+temp_score_offer		
		tot_MaxRiskTolScore =GRAlConstObj.maxscore_quiz_game+GRAlConstObj.maxscore_start_buss+GRAlConstObj.maxscore_play_card+
													GRAlConstObj.maxscore_play_bet+GRAlConstObj.maxscore_compensation+GRAlConstObj.maxscore_risk+		
													GRAlConstObj.maxscore_Short_term+GRAlConstObj.maxscore_portfolio+GRAlConstObj.maxscore_inv_venture+GRAlConstObj.maxscore_offer		
		riskTol_Per=Math.round(tot_RespRiskTolScore/tot_MaxRiskTolScore*100)
		 this.risk_Tol_Per=riskTol_Per;

		//alert('riskTol_Per  '+riskTol_Per);
		var assetAllo_Tol_Eqt_per =new Number(getRiskCap_Tol_Per(riskTol_Per).split('~')[0]);
		var assetAllo_Tol_Debt_per  =new Number(getRiskCap_Tol_Per(riskTol_Per).split('~')[1]);
		 this.asset_Tol_Eqt_per = assetAllo_Tol_Eqt_per ;
		
		//alert('this.asset_Tol_Eqt_per    '+this.asset_Tol_Eqt_per );

		if (riskTol_Per >= 0 && riskTol_Per <= 25.99){
			temp_riskTakingTolStr="Low"
		}else if (riskTol_Per >= 26 && riskTol_Per <= 45.99){
			temp_riskTakingTolStr="Low-Medium"
		}else if (riskTol_Per >= 46 && riskTol_Per <= 60.99){
			temp_riskTakingTolStr="Medium"
		}else if (riskTol_Per >= 61 && riskTol_Per <= 75.99){
			temp_riskTakingTolStr="Medium-High"
		}else if (riskTol_Per >= 76 && riskTol_Per <= 90.99){
			temp_riskTakingTolStr="High"
		}else {
			temp_riskTakingTolStr="Very High"
		}
		$('resultCap').value= temp_riskTakingTolStr;
		//alert('temp_riskTakingTolStr  '+temp_riskTakingTolStr);
		//alert('assetAllo_Tol_Eqt_per  == '+assetAllo_Tol_Eqt_per +'   assetAllo_Tol_Debt_per='+assetAllo_Tol_Debt_per);
	}


	this.CalculateMod_Cap_Tol=function(){
		 var temp_RiskTolCapStr='';
		 var temp_RiskTolCapStr_PortFol='';
		 var avgRiskCap=0;
		 var avgRiskTol=0;
		 var finalTotScore=0;
		 if( parseInt(this.asset_Tol_Eqt_per) > parseInt(this.asset_Cap_Eqt_per) ){
			 temp_RiskTolCapStr="Your risk tolerance is higher than your risk-taking capacity."
		 }else if(parseInt(this.asset_Tol_Eqt_per) ==  parseInt(this.asset_Cap_Eqt_per) ){
			 temp_RiskTolCapStr="Your risk tolerance is in equilibrium with your risk-taking capacity."
		}else{
			temp_RiskTolCapStr="Your risk tolerance is lower than your risk-taking capacity."
		}
	
		if(parseInt(this.asset_Tol_Eqt_per) > parseInt(this.asset_Cap_Eqt_per) ){
			temp_RiskTolCapStr_PortFol = "Your risk tolerance is higher than the risk inherent in your present portfolio"
		}else if(parseInt(this.asset_Tol_Eqt_per) == parseInt(this.asset_Cap_Eqt_per)) {
			temp_RiskTolCapStr_PortFol = "Your risk tolerance is in equilibrium with the risk inherent in your present portfolio"
		}else{
			temp_RiskTolCapStr_PortFol = "Your risk tolerance is lower than the risk inherent in your present portfolio"	
		}

		avgRiskCap=( GRAlConstObj.wgt_AvgRiskCap * this.risk_Cap_Per )/100;
		avgRiskTol=( GRAlConstObj.wgt_AvgRiskTol     * this.risk_Tol_Per )/100;
		finalTotScore=avgRiskCap+avgRiskTol
		var final_asset_Eqt_per =new Number(getRiskFinalPer(finalTotScore).split('~')[0]);
		var final_asset_Debt_per  =100-final_asset_Eqt_per;
		$('pieCanvas').innerHTML=''; 
		var p = new pie();
		 p.add("Equity",final_asset_Eqt_per);
		 p.add("Debt",final_asset_Debt_per);
		 p.render("pieCanvas", "Pie Graph")
		 p=null;	
 /*
		alert('temp_RiskTolCapStr					'+temp_RiskTolCapStr);
		alert('temp_RiskTolCapStr_PortFol   '+temp_RiskTolCapStr_PortFol);
		alert('avgRiskCap   '+avgRiskCap);
		alert('avgRiskTol  '+avgRiskTol);
		alert('finalTotScore  '+finalTotScore);
		alert('final_asset_Eqt_per   '+final_asset_Eqt_per );
		alert('final_asset_Debt_per   '+final_asset_Debt_per);
*/	 }

	 this.CalculateSuitableAcct = function(){
		var suiAcctStr='';
		if( isHidden('ques2') && isHidden('ques3') && isHidden('ques4') ){
//				suiAcctStr="The Kotak Gateway Account is suitable for you";
				suiAcctStr='The Kotak Securities <A href="#" onClick="autoinvest();">AutoInvest</a> Account is suitable for you.';
		 }else if( !isHidden('ques2') && isHidden('ques3') && isHidden('ques4') ){
//				suiAcctStr="The Kotak Value account is suitable for you";
				suiAcctStr='The Kotak Securities <A href="#" onClick="Gateway();">Gateway</a> Account is suitable for you.';
		 }else if( !isHidden('ques2') && !isHidden('ques3') && isHidden('ques4') ){
					suiAcctStr='The Kotak Securities <A href="#" onClick="Privilage();">Privilage</a> Account is Suitable for You.';
		 }else if( !isHidden('ques2') && !isHidden('ques3') && !isHidden('ques4') ){
					suiAcctStr='Kotak Securities <A href="#" onClick="Flat();">Flat</a> Brokerage Scheme without Monthly Charges is suitable for you.';
		 }else {
				suiAcctStr="Kotak Flat without Monthly Charges is suitable for you.";		 
		 }
		$('accSuitabStr').innerHTML= suiAcctStr;
//		alert(suiAcctStr)
	 }
		/**************Business logic calculations for getting Risk Analyser Details******************/
}catch(err){
		alert("err in KStreetCalcRisk.html.RiskAnalyser.js.CalculateRiskAnalyser() "+err.description)
	}
}
function autoinvest()
{
window.open("http://www.kotaksecurities.com/accountsection/Autoinvest.html");
}

function Gateway()
{
window.open("http://www.kotaksecurities.com/accountsection/kotakgateway.html");
}
function Privilage()
{
window.open("http://www.kotaksecurities.com/accountsection/kotakprivilegecircle.html");
}
function Flat()
{
window.open("http://www.kotaksecurities.com/accountsection/Kotakflatversiona.html");
}
/*************************All variable Population for calculating Risk Analyser Details done here**************************/
function populateRiskAnalyser(p_type){
	try{
			if(p_type == 'main'){
				if(validateRiskAnalyser(p_type)){
				   return true;				  
				}else {			
						GRAlObj.v_main_age=$$('main_age');
						GRAlObj.v_main_dep_age10=$$('main_dep_age10');
						GRAlObj.v_main_dep_age11_18=$$('main_dep_age11_18');
						GRAlObj.v_main_dep_age19_25=$$('main_dep_age19_25');
						GRAlObj.v_main_handicap_dep=$$('main_handicap_dep');
						GRAlObj.v_main_aged_dep=$$('main_aged_dep');		
						GRAlObj.v_main_month_save=($$('main_month_save')/100);
						GRAlObj.v_main_sust_month=$$('main_sust_month');
						GRAlObj.v_main_sec_income=$$('main_sec_income');
						GRAlObj.v_main_reinv_income=$$('main_reinv_income');
						GRAlObj.v_main_fin_goals=($$('main_fin_goals')/100);
						GRAlObj.v_main_inhr_wealth=($$('main_inhr_wealth')/100);
						GRAlObj.v_main_inc_cover=$$('main_inc_cover');		
						GRAlObj.v_main_fin_supp=$$('main_fin_supp');

						GRAlObj.v_main_quiz_game=$$('main_quiz_game');
						GRAlObj.v_main_start_buss=$$('main_start_buss');
						GRAlObj.v_main_play_card=$$('main_play_card');
						GRAlObj.v_main_play_bet=$$('main_play_bet');
						GRAlObj.v_main_compensation=$$('main_compensation');
						GRAlObj.v_main_risk=$$('main_risk');		
						GRAlObj.v_main_Short_term=$$('main_Short_term');
						GRAlObj.v_main_portfolio=$$('main_portfolio');
						GRAlObj.v_main_inv_venture=$$('main_inv_venture');
						GRAlObj.v_main_offer=$$('main_offer');		

						GRAlObj.v_main_newInvestor=$$('main_newInvestor');
						GRAlObj.v_main_trade_or_invest=$$('main_trade_or_invest');
						GRAlObj.v_main_retail_highvol=$$('main_retail_highvol');		
						GRAlObj.v_main_monthly_fee=$$('main_monthly_fee');
				}					
			}
	}catch(err){
		alert("err in KStreetCalcRisk.html.RiskAnalyser.js.populateRiskAnalyser() "+err.description)
	}
}

/*************************All validations for calculating Risk Analyser Details done here**************************/
function validateRiskAnalyser(p_type){
	try{
		if(p_type == 'main'){
			var checkMainEmptStr=	'main_age#Age~'+
															'main_dep_age10#Nos of Dependent below 10 yrs~'+
															'main_dep_age11_18#Nos of Dependent between 11-18 yrs~'+
															'main_dep_age19_25#Nos of Dependent between 19-25 yrs~'+
															'main_handicap_dep#Nos of Handicap Dependent~'+
															'main_aged_dep#Nos of Aged Dependent~'+		
															'main_month_save#Monthly saving~'+
															'main_sust_month#Nos of months you can sustain~'+
															'main_fin_goals#Finance~'+
															'main_inhr_wealth#Inheritance Wealth~'+
															'main_inc_cover#Insurance Cover';		

			var mainNumStr= 	'main_age~main_dep_age10~main_dep_age11_18~main_dep_age19_25~'+
												'main_handicap_dep~main_aged_dep~main_month_save~main_sust_month~'+
												'main_sec_income~main_reinv_income~main_fin_goals~main_inhr_wealth~'+
												'main_inc_cover~main_fin_supp';

			var checkMainNumStr =checkNumericAll(mainNumStr);                 
			
		    if(checkEmptyAll(checkMainEmptStr)){
			   return true;
			}else if(checkMainNumStr != ""){
				$(checkMainNumStr).select();
				$(checkMainNumStr).focus();
				alert('Please Enter Numeric Value !')
			   return true;
			}
			else{						
				return false;				
			}
		}
	}catch(err){
		alert("err in KStreetCalcRisk.html.RiskAnalyser.js.validateRiskAnalyser() "+err.description)
	}
}

/*************************All Transaction  for calculating Risk Analyser Details done here**************************/
function transRiskAnalyser(p_type ,p_action){
	try{	
		if(p_type == 'main') {
			if(p_action == 'trans') {
				if(GRAlObj.populateAll('main')) {	//redirection to a particular module				
					hideUnhideFields('','resultDiv');
					GRAlObj.calculateRiskTakCapacity()
					GRAlObj.calculateRiskTolerance();					
					GRAlObj.CalculateMod_Cap_Tol();
					GRAlObj.CalculateSuitableAcct();
					$('resetButBottom').focus();
				} 
			} else if(p_action == 'reset'){
				GRAlObj.resetAll('main','both')
			}
		} 
	}catch(err){
		alert("err in KStreetCalcRisk.html.RiskAnalyser.js.transRiskAnalyser() "+err.description);
	 }
} 

/*************************All Resets for calculating Risk Analyser Details done here**************************/
function resetRiskAnalyser(p_type,resetType){
	try{
			if(p_type == 'main'){
				if(resetType == 'both'){
					GRAlObj     = new CalculateRiskAnalyser();
					var hidDivNames='ques2~ques3~ques4';
					var defStr_0='main_age~main_dep_age10~main_dep_age11_18~main_dep_age19_25~'+
											 'main_handicap_dep~main_aged_dep~main_month_save~'+
											 'main_sust_month~main_fin_goals~main_inhr_wealth~main_inc_cover';	
					var defStr_Select = 'main_reinv_income~main_fin_supp~main_start_buss~main_play_card~main_compensation~'+
														'main_trade_or_invest~main_retail_highvol~main_monthly_fee~'+
														'main_play_bet~main_portfolio~'+
														'main_Short_term~main_inv_venture~main_offer~main_risk~main_newInvestor';
					setDefaultValueAll(defStr_0,'0')
					setDefaultValueAll(defStr_Select ,'1')
					hideUnhideFields('',hidDivNames)
					$('main_age').focus();					
					hideUnhideFields('ques2~ques3~ques4~resultDiv','')
					$('main_trade_or_invest_val').value='1'
					$('main_monthly_fee').value='2'
					$('main_monthly_fee').value='1'
				}
			}
	}catch(err){
		alert("err in KStreetCalcRisk.html.RiskAnalyser.js.resetRiskAnalyser() "+err.description)
	}
}


//Xtra functions [START]

		function setUnsetquestionList(obj,quesNo){
			// Question 1
			try{
				if(quesNo=='1'){
					if(obj.value==1 ){	
						hideUnhideFields('ques2','');
						hideUnhideFields('ques3','');
						hideUnhideFields('ques4','');
						$('main_trade_or_invest').value='2'
						$('main_retail_highvol').value='2'
					}else if(obj.value==2 ){	
						hideUnhideFields('','ques2');
						hideUnhideFields('ques3','');
						hideUnhideFields('ques4','');
						$('main_trade_or_invest').value='2'
						$('main_retail_highvol').value='2'
					}
				}	
				// Question 2
				if(quesNo=='2'){
					if(obj.value=='1' ){
						hideUnhideFields('','ques3');
						hideUnhideFields('ques4','');
						$('main_retail_highvol').value='2'
					}else if(obj.value=='2' ){	
						hideUnhideFields('ques3','');
						hideUnhideFields('ques4','');
						$('main_retail_highvol').value='2'
					}	
				}
				
				// Question 3
				if(quesNo=='3'){
					if(obj.value=='1' ){	
							hideUnhideFields('','ques4');
					}else if(obj.value=='2'){					
							hideUnhideFields('ques4','');
					}	
				}
				$('goButton').focus();
			}catch (err){
				alert("err in KStreetCalcRisk.html.RiskAnalyser.js.resetRiskAnalyser() "+err.description)
			}
		}

	function getRiskCap_Tol_Per(p_risk_Per ){
		try{
			var assetEqt_per=0;
			var assetDebt_per	=0;
			if(p_risk_Per >= 0 && p_risk_Per <= 25.99){
				assetEqt_per=GRAlConstObj.ast_alo_eq_low
				assetDebt_per=GRAlConstObj.ast_alo_debt_low
			}else if(p_risk_Per >= 26 && p_risk_Per <= 45.99){
				assetEqt_per=GRAlConstObj.ast_alo_eq_low_med
				assetDebt_per=GRAlConstObj.ast_alo_debt_low_med
			}else if(p_risk_Per >= 46 && p_risk_Per <= 60.99){
				assetEqt_per=GRAlConstObj.ast_alo_eq_med
				assetDebt_per=GRAlConstObj.ast_alo_debt_med
			}else if(p_risk_Per >= 61 && p_risk_Per <= 75.99){
				assetEqt_per=GRAlConstObj.ast_alo_eq_med_hi
				assetDebt_per=GRAlConstObj.ast_alo_debt_med_hi
			}else if(p_risk_Per >= 76 && p_risk_Per <= 90.99){
				assetEqt_per=GRAlConstObj.ast_alo_eq_hi
				assetDebt_per=GRAlConstObj.ast_alo_debt_hi
			}else {
				assetEqt_per=GRAlConstObj.ast_alo_eq_ver_hi
				assetDebt_per=GRAlConstObj.ast_alo_debt_ver_hi
			}
			return assetEqt_per+'~'+assetDebt_per;
		}catch (err){
			alert("err in KStreetCalcRisk.html.RiskAnalyser.js.getRiskCap_Tol_Per() "+err.description)
		}
	}

	function getRiskFinalPer(p_risk_Per ){
		try{
			var assetEqt_per=0;
			var assetDebt_per	=0;
			if(p_risk_Per >= 0 && p_risk_Per <= 25){
				assetEqt_per=GRAlConstObj.ast_alo_eq_low
				assetDebt_per=GRAlConstObj.ast_alo_debt_low
			}else if(p_risk_Per >= 26 && p_risk_Per <= 45){
				assetEqt_per=GRAlConstObj.ast_alo_eq_low_med
				assetDebt_per=GRAlConstObj.ast_alo_debt_low_med
			}else if(p_risk_Per >= 46 && p_risk_Per <= 60){
				assetEqt_per=GRAlConstObj.ast_alo_eq_med
				assetDebt_per=GRAlConstObj.ast_alo_debt_med
			}else if(p_risk_Per >= 61 && p_risk_Per <= 75){
				assetEqt_per=GRAlConstObj.ast_alo_eq_med_hi
				assetDebt_per=GRAlConstObj.ast_alo_debt_med_hi
			}else if(p_risk_Per >= 76 && p_risk_Per <= 90){
				assetEqt_per=GRAlConstObj.ast_alo_eq_hi
				assetDebt_per=GRAlConstObj.ast_alo_debt_hi
			}else {
				assetEqt_per=GRAlConstObj.ast_alo_eq_ver_hi
				assetDebt_per=GRAlConstObj.ast_alo_debt_ver_hi
			}
			return assetEqt_per+'~'+assetDebt_per;
		}catch (err){
			alert("err in KStreetCalcRisk.html.RiskAnalyser.js.getRiskFinalPer() "+err.description)
		}
	}




//Xtra functions [END]

