$(document).ready(function(){
	$('.US-ROI-Calculator').click(function(){
		
		var formstr = '<div class="formBoxTitle">Innovation Property ROI Calculator<\/div>'+
			'<div class="formBox" style="border:none; padding:0;"><p>In working with our insurance company customers, we developed a quick tool to assist property claims executives to calculate the potential cost savings that Innovation Property can provide by leveraging our managed network in lieu of utilizing your appraisers on certain claim types.</p>'+
			'<p>Please enter the following parameters to calculate a potential annual savings by outsourcing your claim to Innovation property. Do not utilize commas, dollar signs or days in your answers when completing the data.  All fields are required.</p>'+
			
			'<table cellspacing="5">'+
				'<tr>'+
					'<th align="left"><label for="annualadjustercost">What is your annual "fully loaded" cost for each property Adjuster?<\/label><em style="font-weight:normal;">("fully loaded" includes salary, car and benefits.)<\/em><\/th>'+
					'<td align="right" style="white-space:nowrap;">$<input type="text" name="annualadjustercost" id="annualadjustercost" value="0" \/><\/td>'+
				'<\/tr>'+
				'<tr>'+
					'<th align="left"><label for="fteadjusters">How many full-time-equivalent (FTE) Property Adjusters do you have?<\/label><\/th>'+
					'<td align="right"><input type="text" name="fteadjusters" id="fteadjusters" value="0" \/><\/td>'+
				'<\/tr>'+
				'<tr>'+
					'<th align="left"><label for="adjusterpersuper">Indicate the number of Property Adjusters you have per supervisor?<\/label><\/th>'+
					'<td align="right"><input type="text" name="adjusterpersuper" id="adjusterpersuper" value="0" \/><\/td>'+
				'<\/tr>'+
				'<tr>'+
					'<th align="left"><label for="adjustertrain">How many days does it take to train a new Property Adjuster?<\/label><\/th>'+
					'<td align="right"><input type="text" name="adjustertrain" id="adjustertrain" value="0" \/><\/td>'+
				'<\/tr>'+
				'<tr>'+
					'<th align="left"><label for="adjusterclaimspermonth">What is the average number of claims a Property Adjuster handles per month?<\/label><\/th>'+
					'<td align="right"><input type="text" name="adjusterclaimspermonth" id="adjusterclaimspermonth" value="0" \/><\/td>'+
				'<\/tr>'+
				'<tr>'+
					'<th align="left"><label for="IAclaimhandlingtime">What is the average number of days it takes for a Property Adjuster to close a file?<\/label><\/th>'+
					'<td align="right"><input type="text" name="IAclaimhandlingtime" id="IAclaimhandlingtime" value="0" \/><\/td>'+
				'<\/tr>'+				
				'<tr>'+
					'<th align="left"><label for="IAcostperclaim">What is the fully loaded Property Independent Adjuster cost per claim (include time & materials if applicable)?<\/label><\/th>'+
					'<td align="right">$<input type="text" name="IAcostperclaim" id="IAcostperclaim" value="0" \/><\/td>'+
				'<\/tr>'+
				'<tr>'+
					'<th align="left"><label for="IAclaimspermonth">Indicate the average number of monthly claims that are sent to Property Independant Adjusters?<\/label><\/th>'+
					'<td align="right"><input type="text" name="IAclaimspermonth" id="IAclaimspermonth" value="0" \/><\/td>'+
				'<\/tr>'+
				'<tr>'+
					'<th align="left"><label for="severityperIA">What is your average severity per Property Independent Adjuster<\/label><\/th>'+
					'<td align="right"><input type="text" name="severityperIA" id="severityperIA" value="0" \/><\/td>'+
				'<\/tr>'+
				'<tr>'+
					'<th align="left"><label for="severityperadjuster">What is your average severity per Property Adjuster<\/label><\/th>'+
					'<td align="right"><input type="text" name="severityperadjuster" id="severityperadjuster" value="0" \/><\/td>'+
				'<\/tr>'+
			'<\/table>'+
			'<\/div>'
		
	
		var resultstr = '<div class="formBoxTitle">Estimated Annual Cost Savings<\/div>'+
						'<table cellspacing="5">'+
							'<tr>'+
								'<th align="left"><span style="font-weight:bold">Adjuster Costs:</span></span><\/th>'+
								'<td align="left">$<span id="adjustercosts"><\/td>'+
							'<\/tr>'+
							'<tr>'+
								'<th align="left"><span style="font-weight:bold">Supervisory Costs:</span><\/th>'+
								'<td align="left">$<span id="supervisorycosts"></span> (Note: Factored 1.25% based on Adjuster salary)<\/td>'+
							'<\/tr>'+
							'<tr>'+
								'<th align="left"><span style="font-weight:bold">Independant Adjuster Costs:</span><\/th>'+
								'<td align="left">$<span id="iacosts"></span><\/td>'+
							'<\/tr>'+
						'<\/table>'+
						'<table cellspacing="5">'+
							'<tr>'+
								'<th align="left"><span style="font-weight:bold; color:#0076B4;">Total Costs:</span><\/th>'+
								'<td align="left">$<span id="totalcosts"></span><\/td>'+
							'<\/tr>'+
						'<\/table>'+
						'<table cellspacing="5">'+
							'<tr>'+
								'<th align="left"><span style="font-weight:bold">Total number of property calims per year:</span><\/th>'+
								'<td align="left"><span id="totalannualclaims"></span><\/td>'+
							'<\/tr>'+
							'<tr>'+
								'<th align="left"><span style="font-weight:bold">Your current estimated average cost per claim:</span><\/th>'+
								'<td align="left">$<span id="approxcostperclaim"></span><\/td>'+
							'<\/tr>'+
							'<tr>'+
								'<th align="left"><span style="font-weight:bold">Innovation Property average cost per claim:</span><\/th>'+
								'<td align="left">$<span id="ipavecostperclaim"></span><\/td>'+
							'<\/tr>'+
						'<\/table>'+
						'<table cellspacing="5">'+
							'<tr>'+
								'<th align="left"><span style="font-weight:bold; color:#138C9A;">Estimated potential annual cost savings:</span><\/th>'+
								'<td align="left">$<span style="color:#138C9A;" id="annualcostsavings"></span><\/td>'+
							'<\/tr>'+
						'<\/table>'
			
		jqistates = {
			state0: {
				html: formstr,
				focus: 1,
				top:5,
				buttons: { Cancel: false, Calculate: true },
				submit: function(v, m, f){
					var e = "";
					m.find('.errorBlock').slideUp('slow',function(){ jQuery(this).remove(); });
					
					if (v) {
						
						if(isNaN(f.annualadjustercost))
							e += "Please enter a numeric 'fully loaded' cost for each property Adjuster<br />";
						if(isNaN(f.fteadjusters))
							e += "Please enter a numeric value for the fte adjusters you have<br />";
						if(isNaN(f.adjusterpersuper))
							e += "Please enter a numeric value for the number of Adjusters per supervisor<br />";
						if(isNaN(f.adjustertrain))
							e += "Please enter a numeric value for the number of days it takes to train an Adjuster<br />";
						if(isNaN(f.adjusterclaimspermonth))
							e += "Please enter a numeric value for the number of claims your Adjusters have per month<br />";
						if(isNaN(f.IAclaimhandlingtime))
							e += "Please enter a numeric value for the average handling time of a claim<br />";
						if(isNaN(f.IAcostperclaim))
							e += "Please enter a numeric value for the average I.A. cost per claim<br />";
						if(isNaN(f.IAclaimspermonth))
							e += "Please enter a numeric value for the number of claims your I.A. handles per month<br />";
						if(isNaN(f.severityperIA))
							e += "Please enter a numeric value for your average severity per I.A.<br />";
						if(isNaN(f.severityperadjuster))
							e += "Please enter a numeric value for your average severity per Adjuster<br />";
							
						
						if (e == "") {	
							var adjusterCosts = Math.round(f.annualadjustercost*f.fteadjusters);
							var supervisoryCosts = Math.round((f.fteadjusters/f.adjusterpersuper)*(f.annualadjustercost*1.25));
							var iaCosts = Math.round(f.IAclaimspermonth*f.IAcostperclaim*12);
							
							var totalCosts = Math.round(adjusterCosts + supervisoryCosts + iaCosts);
							var totalAnnualClaims = Math.round(f.adjusterclaimspermonth*f.fteadjusters*12+f.IAclaimspermonth*12);
							var approxCostPerClaim = Math.round(totalCosts / totalAnnualClaims);
							
							var IPAverageCostPerClaim = 190;
							var annualCostSavings = Math.round((approxCostPerClaim - IPAverageCostPerClaim)*totalAnnualClaims);
							
							jQuery.prompt.getStateContent('state1').find('#adjustercosts').text(adjusterCosts);
							jQuery.prompt.getStateContent('state1').find('#supervisorycosts').text(supervisoryCosts);
							jQuery.prompt.getStateContent('state1').find('#iacosts').text(iaCosts);
							
							jQuery.prompt.getStateContent('state1').find('#totalcosts').text(totalCosts);
							jQuery.prompt.getStateContent('state1').find('#totalannualclaims').text(totalAnnualClaims);
							jQuery.prompt.getStateContent('state1').find('#approxcostperclaim').text(approxCostPerClaim);
	
							jQuery.prompt.getStateContent('state1').find('#ipavecostperclaim').text(IPAverageCostPerClaim);
							jQuery.prompt.getStateContent('state1').find('#annualcostsavings').text(annualCostSavings);
							
							jQuery.prompt.goToState('state1');
						}
						else{
							jQuery('<div class="errorBlock errors" style="display: none;">'+ e +'</div>').appendTo('.preError').slideDown('slow');
						}
						return false;
					}
					else return true;
				}
			},
			state1: {
				html: resultstr,
				focus: 1,
				top: 5,
				buttons: { Back: false, Done: true },
				submit: function(v,m,f){
					if(v)
						return true;
						
					jQuery.prompt.goToState('state0');
					return false;
				}
			}
		};
		
		$.prompt(jqistates);
		
		$('.jqi').css('top','50px');
	});
});
