
function pupulateDeductibleRadios()
{
	 var errorMsg = "";
	 
	//clear all
 	 document.getElementById('deductible_1000').disabled=true;
  	 document.getElementById('deductible_2500').disabled=true;	 
 	 document.getElementById('deductible_5000').disabled=true;
     document.getElementById('deductible_7500').disabled=true;     
     document.getElementById('deductible_10000').disabled=true;            
     checkall('indicatorForm','deductible',false);      
     checkall('indicatorForm','covLevel',false);    
     checkall('indicatorForm','mutualFunds',false); 
     checkall('indicatorForm','financeProds',false);                         
	 loadinfo("");
	 DWRUtil.setValue("errorMsg", errorMsg); 	
	     
			    
	var policyType = DWRUtil.getValue("policyType");    
	var income = trim(DWRUtil.getValue("income"));
	DWRUtil.setValue("incomeHidden", income);
	var incomeHidden = DWRUtil.getValue("incomeHidden");
	var state = DWRUtil.getValue("state");   
	
	if( state=="TX" || state=="LA")
	{
     document.getElementById('covLevel2').disabled=true; 	
	}
	else
	{
     document.getElementById('covLevel2').disabled=false; 	
	}

 	if(policyType.length > 0 && income.length > 0 )    
	{
		// [JIRA] NAIFA-1 Don't restrict the user to an integer during input.		
		//if( !isInteger(income, true))
	  //{
	 	//	alert("Please enter income as number.  ex. 50000 ");
	  //	document.getElementById('income').focus();
	  // return;
	  //}	
		//	

 		// Discard any dollar sign or comma, then save the altered
		// value back to the HIDDEN input box for the subsequent calculation.
	  //var incomeValue = Number(income);
	  var incomeValue = Number(Math.round(incomeHidden.replace(/\$|,/g, "")));
		if( isNaN(incomeValue, true) )
	  {
	   	alert("Please enter income as a number or dollar figure.  ex. 50000 or 5,0000.00");
	  	document.getElementById('income').focus();
	  	return;
	  }	
		 DWRUtil.setValue("incomeHidden", incomeValue);
	   if( policyType=="agency")
	   {
	   		if(incomeValue >0)
	   		{
		   		if(incomeValue <= 2000000)
	 	   		{
			  	  document.getElementById('deductible_5000').disabled=false;				    
					}	
					else
					{
				  	errorMsg = "Your total gross commission income is outside the standard range for which we can provide a coverage option. Therefore, we are unable to process a website rate indication for you. Please contact us by calling our toll-free number, 1-800-247-3448, or via the <a href='/custserv/contactus.jsp' style='color:red;'>contact us</a> link, to discuss the coverage options that are available to you.";
						DWRUtil.setValue("errorMsg", errorMsg); 
				   	return;
					}		  
				}  		    		
	   }	   
	   else if( policyType=="individual")
	   {
	   		if(incomeValue >0)
	   		{  
	   		  if(incomeValue < 50000)
					{ 
			  		document.getElementById('deductible_1000').disabled=false;
					}
					else if(incomeValue < 150000)
					{ 
				    document.getElementById('deductible_1000').disabled=false;
				    document.getElementById('deductible_2500').disabled=false;
					}
					else if(incomeValue < 300000)
					{ 
				    document.getElementById('deductible_2500').disabled=false;
				    if(state!='FL')
				    {
					    document.getElementById('deductible_5000').disabled=false;
					    document.getElementById('deductible_7500').disabled=false;	
				    }	    
					}
					else if(incomeValue < 500000 && state!='FL')
					{ 
				    document.getElementById('deductible_5000').disabled=false;
				    document.getElementById('deductible_7500').disabled=false;
			   		if(state=='NY')
				    {
					    document.getElementById('deductible_10000').disabled=false;
						}
				}	
				else
				{
					errorMsg = "Your total gross commission income is outside the standard range for which we can provide a coverage option. Therefore, we are unable to process a website rate indication for you. Please contact us by calling our toll-free number, 1-800-247-3448, or via the <a href='/custserv/contactus.jsp' style='color:red;'>contact us</a> link, to discuss the coverage options that are available to you.";
					DWRUtil.setValue("errorMsg", errorMsg); 
			   	return;
				}			
			}	
		}		
	}  
}



function count() {

    var policyType = DWRUtil.getValue("policyType");
  	var state = DWRUtil.getValue("state");
		var income = trim(DWRUtil.getValue("incomeHidden"));
  	var deductible = DWRUtil.getValue("deductible");
  	var covLevel = DWRUtil.getValue("covLevel");
  	var mutualFunds = DWRUtil.getValue("mutualFunds");
  	var financeProds = DWRUtil.getValue("financeProds");  
   	var coverage = 0;	  	  
   	if(	"Y"!=mutualFunds)
   	mutualFunds = "N";
   	
   	if(	"Y"!=financeProds)
   	financeProds = "N";
   	   	
  	if(policyType.length >0 && state.length >0 && Number(income)>0 && Number(deductible)>0 && covLevel.length >0)
  	{
  	 	coverage = RateIndicator.estimateCoverate(policyType,state,income,deductible,covLevel,mutualFunds,financeProds, loadinfo);  	 
  	}
  	else
  	{
  		loadinfo("");
  	}
}

function loadinfo(data) {
	if(data !='')
	{ 
		data = "<div style='font:bold 20px Verdana, Arial, Helvetica, sans-serif; color:#fff; background:#30679F; padding:10px; text-align:center'>"+data + "</div><br><br><font style='font-size:120%'>Based on an evaluation of your completed application it may be determined that you qualify for additional rate reductions on your premium.</font>";
		data = data + "<br><br><a href='/application/applynow.jsp'><font style='font-size:120%;font-weight: 800'>To submit an application for evaluation, click here if you would like to complete an online application or to download an application for submission.</font></a>"; 	
		data = data + "<br><br><font style='font-size:120%;font-weight: 800; font-style:italic; text-decoration:underline'>The NAIFA Professional Liability Insurance Program is administered by Affinity Insurance Services, Inc.; in CA, MN and OK, AIS Affinity Insurance Agency, Inc. (CA license #0795465) and in NY, AIS Affinity Insurance Agency.</font>"; 
		data = data + "<br><br><center><input type='Submit' name='submit' value='Print Quote'></</center>"; 
		
	}

  	DWRUtil.setValue("RateIndicatorReply", data );

}

function trim(string) 
{
	while (string.substring(0,1) == ' ')
	{
	string = string.substring(1, string.length);
	}
	while (string.substring(string.length-1, string.length) == ' ')
	{
	string = string.substring(0,string.length-1);
	}
	return string; 
}


//thestate=true, check all; 
//thestate=false, uncheck all; 
function checkall(formname,checkname,thestate){
	var el_collection=eval("document.forms."+formname+"."+checkname)
	for (c=0;c<el_collection.length;c++)
	el_collection[c].checked=thestate
}
