// We will list out the functions used to call JQuery to make the magic of this page :)
// Declare and setup our variables - This will help send them over to the DB
	   // Numbers to tally the savings KB offers
		var kbs_et = 0.09; // Used to get the Employee Turnover Savings total
		var kbs_cs = 0.0146; // Used to get the Customer Satisfaction Savings total
		var kbs_ep = 0.05; // Used to get the Employee Productivity Savings total
		
		// For running total lets set our results to 0
		var EmpTurnTotal = 0;
		var CusSatTotal = 0;
		var EmpProdTotal = 0;
		
		// Now we establish vars for Employee Turnover
		var empT_ne; // Number of Employees
		var empT_cr; // Current Turnover Rate
		var empT_as; // Average Salary
		
		// Now we establish vars for Cusotmer Satisfaction
		var cusS_dr; // Desired Satisfaction Rate
		var cusS_cr; // Current Satisfaction Rate
		var cusS_as; // Annual Sales
		
		// Now we establish vars for Employee Productivity
		var empP_dr; // Desired Producivity Rate
		var empP_cr; // Current Productivity Rate
		var empP_as; // Annual Sales
		
		// Now for the Result Page
		var KBTotal; // Total savings KB offers
		var cdnTotal; // Total Cost of Doing nothing
		var kbs_ett; // Savings in Employee Turnover
		var kbs_cst; // Savings in customer Satisfaction
		var kbs_ept; // Savings in Employee Productivity
		
		// Create a var to hold our current report ID
		var currReportID;
		
	$(document).ready(function(){
	   // First we need to hide all of our hidden sections
	  // $("#calcHIW").toggle(); // Hide the HOW IT WORKS div
	   //$(".tooltip").stop(true,true).hide();
	   $("#pdfRequest").hide();
	   $(".pdfForm").hide();
	   $(".stepCalc input[type='text']").keyup(calcUpdate);
	   $("#graphDisplay .rightBar").hide();
	   $("#graphDisplay .leftBar").hide();
	   $("#results .prev").show();
	   $("#results .startOverBtn").hide();
	   $("#pdfRequest input").focus(function () {
			 if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});

	   
	   
	   // Reset the next buttons
	   $("#s1_next").fadeTo("fast", 0.45);
	   $("#s1_next").click(function() {});
	   $("#s2_next").fadeTo("fast", 0.45);
	   $("#s2_next").click(function() {});
	   $("#s3_next").fadeTo("fast", 0.45);
	   $("#s3_next").click(function() {});
	   
	   // Reset Header Paragraphs
	   $("#hp_step1").hide();
	   $("#hp_step2").hide();
	   $("#hp_step3").hide();
	   $("#hp_results").hide();
	   
	   var $panels = $('#cdnCalculator .slideContent > div');
	   var $container = $('#cdnCalculator .slideContent');
		
		// if false, we'll float all the panels left and fix the width 
		// of the container
	   var horizontal = true;
		
		// float the panels left if we're going horizontal
		if (horizontal) {
		  $panels.css({
			'float' : 'left',
			'position' : 'relative' // IE fix to ensure overflow is hidden
		  });
		  
		  // calculate a new width for the container (so it holds all panels)
		  $container.css('width', $panels[0].offsetWidth * $panels.length);
		}
		
		// collect the scroll object, at the same time apply the hidden overflow
		// to remove the default scrollbars that will appear
		var $scroll = $('#cdnCalculator .calcContent').css('overflow', 'hidden');
		
		// handle nav selection
		var currStep = 0;
		//$('#cdnCalculator .breadCrumb').find('a').click(selectNav);
		
		// go find the navigation link that has this target and select the nav
		function trigger(data) {

			$("#pdfRequest").stop(true,true).fadeOut("fast", function() {$("#totalCost").stop(true,true).fadeIn("fast")});
			$(".pdfForm").stop(true,true).slideUp();
			$("#graphDisplay .rightBar").hide();
	   		$("#graphDisplay .leftBar").hide();
			$("#results .prev").show();
		 	$("#results .startOverBtn").hide();
		  	// Here is where we setup the styles for the breadcrumb trail
			switch(data.id){
				case "starter":
					//alert("Start");
					break;
				case "stepOne":
					// Do this
					$(".bc_s1").css({"background-position" : "0px -31px", "color" : "#f9f4d9"})
					$(".bc_s1 .bc_cap").css("background-position","0px -62px")
					$(".bc_s2").css({"background-position" : "0px -62px", "color" : "#46463b"})
					$(".bc_s2 .bc_cap").css("background-position","0px -93px")
					$(".bc_s3").css({"background-position" : "0px -62px", "color" : "#46463b"})
					$(".bc_s3 .bc_cap").css("background-position","0px -93px")
					$(".bc_re").css({"background-position" : "0px -62px", "color" : "#46463b"})
					$("#hp_start").hide();
					$("#hp_step1").show();
					$("#hp_step2").hide();
				   	$("#hp_step3").hide();
					$("#hp_results").hide();
					selectiveTabbing("#stepOne")
					try {
					pageTracker._trackPageview("/management_training_programs/cost_of_doing_nothing_calculator/step_1"); 
					} catch(err) {}
					break;
				case "stepTwo":
					// Do this
					$(".bc_s1").css({"background-position" : "0px 0px", "color" : "#d6d4bc"})
					$(".bc_s1 .bc_cap").css("background-position","0px -31px")
					$(".bc_s2").css({"background-position" : "0px -31px", "color" : "#f9f4d9"})
					$(".bc_s2 .bc_cap").css("background-position","0px -62px")
					$(".bc_s3").css({"background-position" : "0px -62px", "color" : "#46463b"})
					$(".bc_s3 .bc_cap").css("background-position","0px -93px")
					$(".bc_re").css({"background-position" : "0px -62px", "color" : "#46463b"})
					$("#hp_start").stop(true,true).hide();
					$("#hp_step1").stop(true,true).hide();
					$("#hp_step2").stop(true,true).show();
					$("#hp_step3").stop(true,true).hide();
					$("#hp_results").stop(true,true).hide();
					selectiveTabbing("#stepTwo")
					try {
					pageTracker._trackPageview("/management_training_programs/cost_of_doing_nothing_calculator/step_2"); 
					} catch(err) {}

					break;
				case "stepThree":
					// Do this
					$(".bc_s1").css({"background-position" : "0px 0px", "color" : "#d6d4bc"})
					$(".bc_s1 .bc_cap").css("background-position","0px 0px")
					$(".bc_s2").css({"background-position" : "0px 0px", "color" : "#d6d4bc"})
					$(".bc_s2 .bc_cap").css("background-position","0px -31px")
					$(".bc_s3").css({"background-position" : "0px -31px", "color" : "#f9f4d9"})
					$(".bc_s3 .bc_cap").css("background-position","0px -62px")
					$(".bc_re").css({"background-position" : "0px -62px", "color" : "#46463b"})
					$("#hp_start").stop(true,true).hide();
					$("#hp_step1").stop(true,true).hide();
					$("#hp_step2").stop(true,true).hide();
					$("#hp_step3").stop(true,true).show();
					$("#hp_results").stop(true,true).hide()
					selectiveTabbing("#stepThree")
					try {
					pageTracker._trackPageview("/management_training_programs/cost_of_doing_nothing_calculator/step_3"); 
					} catch(err) {}

					break;
				case "results":
					// Do this
					$(".bc_s1").css({"background-position" : "0px 0px", "color" : "#d6d4bc"})
					$(".bc_s1 .bc_cap").css("background-position","0px 0px")
					$(".bc_s2").css({"background-position" : "0px 0px", "color" : "#d6d4bc"})
					$(".bc_s2 .bc_cap").css("background-position","0px 0px")
					$(".bc_s3").css({"background-position" : "0px 0px", "color" : "#d6d4bc"})
					$(".bc_s3 .bc_cap").css("background-position","0px -31px")
					$(".bc_re").css({"background-position" : "0px -31px", "color" : "#f9f4d9"})
					$("#hp_start").stop(true,true).hide();
					$("#hp_step1").stop(true,true).hide();
					$("#hp_step2").stop(true,true).hide();
					$("#hp_step3").stop(true,true).hide();
					$("#hp_results").stop(true,true).show();
					
					$("#totalCost").stop(true,true).fadeOut("fast", function() {$("#pdfRequest").stop(true,true).fadeIn("fast")});
					
					// Animate Graph
					$("#graphDisplay .leftBar").slideDown("slow", function(){$("#graphDisplay .rightBar").slideDown("slow");});
					
					selectiveTabbing("#results")
					try {
					pageTracker._trackPageview("/management_training_programs/cost_of_doing_nothing_calculator/step_4_results"); 
					} catch(err) {}

					break;
			}
		}
		
		if (window.location.hash) {
		  trigger({ id : window.location.hash.substr(1) });
		} else {
		  //$('ul.breadCrumb a:first').click();
		}
		
		// offset is used to move to *exactly* the right place, since I'm using
		// padding on my example, I need to subtract the amount of padding to
		// the offset.  Try removing this to get a good idea of the effect
		var offset = parseInt((horizontal ? 
		  $container.css('paddingTop') : 
		  $container.css('paddingLeft')) 
		  || 0) * -1;
		
		
		var scrollOptions = {
		  target: $scroll, // the element that has the overflow
		  
		  // can be a selector which will be relative to the target
		  items: $panels,
		  
		  navigation: '',
		  force: true,
		  
		  // selectors are NOT relative to document, i.e. make sure they're unique
		  prev: '.prev', 
		  next: '.startBtn',
		  
		  // allow the scroll effect to run both directions
		  axis: 'x',
		  
		  onAfter: trigger, // our final callback
		  
		  offset: offset,
		  
		  // duration of the sliding effect
		  duration: 500,
		  
		  // easing - can be used with the easing plugin: 
		  // http://gsgd.co.uk/sandbox/jquery/easing/
		  easing: 'swing'
		};
		
		// apply serialScroll to the slider - we chose this plugin because it 
		// supports// the indexed next and previous scroll along with hooking 
		// in to our navigation.
		$('#cdnCalculator').serialScroll(scrollOptions);
		
		// now apply localScroll to hook any other arbitrary links to trigger 
		// the effect
		//$.localScroll(scrollOptions);
		
		// finally, if the URL has a hash, move the slider in to position, 
		// setting the duration to 1 because I don't want it to scroll in the
		// very first page load.  We don't always need this, but it ensures
		// the positioning is absolutely spot on when the pages loads.
		scrollOptions.duration = 1;
		//$.localScroll.hash(scrollOptions);
		
		
		// Tooltip functionality
		//Select all anchor tag with rel set to tooltip
		$('.fieldHelp').mouseover(function(e) {
		
			//Grab the title attribute's value and assign it to a variable
			var tip = $(this).next('span').text();	
			
			//Append the tooltip template and its value
			$('body').append('<div id="tooltip"><div class="tipBody">' + tip + '</div></div>');		
			
			//Set the X and Y axis of the tooltip
			// Get tooltip's hiehgt so we can center it on the hover
			var ttCenter = parseInt($('#tooltip').height());
			var ttWCenter = parseInt($('#tooltip').width());
			$('#tooltip').css('top', e.pageY - (ttCenter+20) );
			$('#tooltip').css('left', e.pageX - (ttWCenter/2) );
			
			//Show the tooltip with fadeIn effect
			$('#tooltip').hide();
			$('#tooltip').fadeIn('500');
		
		}).mousemove(function(e) {
	
			//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
			var ttCenter = parseInt($('#tooltip').height());
			var ttWCenter = parseInt($('#tooltip').width());
			$('#tooltip').css('top', e.pageY - (ttCenter+20) );
			$('#tooltip').css('left', e.pageX - (ttWCenter/2) );
		
		}).mouseout(function() {
	
			//Remove the appended tooltip template
			$('body').children('div#tooltip').remove();
		
		});

	 });
	
	function getStarted(){
		// Start the Cost of Doing Nothing Process by fading out the entrance screen
		
		$('#startScreen').fadeOut('slow',function () {
        	
			
			
     	});
		$('#cdnCalculator .slideContent').trigger( 'goto', [0] );
		
	  	//$('#cdnCalculator .slideContent').trigger('prev');
	}
	
	// We have this function to prevent tabbing from destroying my beautiful work
	function selectiveTabbing(whichStep) {
			// Enable The currents steps tabs
			// Disable all each time for easy logic
			$("#stepOne :input").attr("disabled", true);
			$("#stepTwo :input").attr("disabled", true);
			$("#stepThree :input").attr("disabled", true);
			$("#results :input").attr("disabled", true);
					
			// Enable
			$(whichStep+" :input").removeAttr("disabled");
	}
	
	function resetCalculator(){
		// iterate over all of the inputs for the form
		// element that was passed in
		$(':input').each(function() {
		
		var type = this.type;
		var tag = this.tagName.toLowerCase(); // normalize case
		// it's ok to reset the value attr of text inputs,
		// password inputs, and textareas
		if (type == 'text' || type == 'password' || tag == 'textarea')
			switch(this.name){
				// Reset the inital percentage values
				case "empT_current_turnover":
					this.value = "20";
					break;
				case "cusS_current_rate":
					this.value = "75";
					break;
				case "empP_current_rate":
					this.value = "70";
					break;
				// Reset the Personal Info form
				case "firstName":
					this.value = "First Name";
					break;
				case "lastName":
					this.value = "Last Name";
					break;
				case "title":
					this.value = "Title";
					break;
				case "organization":
					this.value = "Organization";
					break;
				case "email":
					this.value = "Email";
					break;
				case "country":
					this.value = "Country";
					break;
				case "zip":
					this.value = "Postal Code";
					break;
				case "phone":
					this.value = "Phone (optional)";
					break;
				// Everything else goes blank
				default:
					this.value = "";
					break;
			}
		// checkboxes and radios need to have their checked state cleared
		// but should *not* have their 'value' changed
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		// select elements need to have their 'selectedIndex' property set to -1
		// (this works for both single and multiple select elements)
	 	else if (tag == 'select')
			this.selectedIndex = -1;
		});
		// Now we also want to result all of our total fields back to th intial values to start over
		$("#empT_total").text("$0");
		$("#cusS_total").text("$0");
		$("#empP_total").text("$0");
		$("#runTally").text("$0"); // Running Tally on bottom
		$(".resultP").text("$0"); // Total display on results page
		$(".currentCost .tally").text("$0"); // Total display on results graph
		$(".projectedSavings .tally").text("$0"); // Total display on results graph
		$("#runTally").text("$0"); // Total display on results graph
		$("#graphKey .iet .saveTotal").text("$0");
		$("#graphKey .ics .saveTotal").text("$0");
		$("#graphKey .iep .saveTotal").text("$0");
		
		// Result the next buttons to not be active
		$("#s1_next").fadeTo("fast", 0.45);
		$("#s1_next").click(function() {});
	   	$("#s2_next").fadeTo("fast", 0.45);
		$("#s2_next").click(function() {});
	   	$("#s3_next").fadeTo("fast", 0.45);
		$("#s3_next").click(function() {});
		$("#hp_results span").text(" ");
	}
	
	function referAFriend(){
		var refEmail = $("#pdfRequest input[name=email]");
		//alert(refEmail);
		if(refEmail.val().length>2 && refEmail.val() != "Email" && checkEmail(refEmail.val())){
			window.open("http://www.kenblanchard.com/Management_Training_Programs/Cost_of_Doing_Nothing_Calculator/Forward.asp?refEmail="+refEmail.val());
		} else {
			window.open("http://www.kenblanchard.com/Management_Training_Programs/Cost_of_Doing_Nothing_Calculator/Forward.asp");

		}
	}
	
	function alterREBtns() {
		 $("#results .prev").hide();
		 $("#results .startOverBtn").show();
	}
	
	// This will take all the info and send it to ASP for processing (DG)
	function requestPDF(){
		var passInfo = $("#cdnCalculator input[type=text]");
		var ckBoxes = $("form :checkbox");
		// I'm keeping all this in here for reference
		//var persInfo = [passInfo[9].value, passInfo[10].value, passInfo[11].value, passInfo[12].value, passInfo[13].value, passInfo[14].value, passInfo[15].value, ckBoxes[0].checked, ckBoxes[1].checked];
		//var userInfo = persInfo.join("|"); // For DG
		//var calcTotals = [passInfo[0].value, passInfo[1].value, passInfo[2].value, passInfo[3].value, passInfo[4].value, passInfo[5].value, passInfo[6].value, passInfo[7].value, passInfo[8].value, cdnTotal, KBTotal, kbs_ett, kbs_cst, kbs_ept];
		//var userTotals = calcTotals.join("|"); // For DG
		//alert(persInfo+"< br/>"+calcTotals)
		$.post("calculator.asp", { FirstName: passInfo[9].value, LastName: passInfo[10].value, Title: passInfo[11].value, Organization: passInfo[12].value, Email: passInfo[13].value, Country: passInfo[14].value, Zip: passInfo[15].value,  Phone: passInfo[16].value, ReceiveNewsletter: ckBoxes[0].checked, ContactNow: ckBoxes[1].checked, etNumEmployees: passInfo[0].value, etAvgSalary: "$"+passInfo[1].value, etCurrTurnRate: passInfo[2].value+"%", csAppAnnualSales: "$"+passInfo[3].value, csCurrSatRate: passInfo[4].value+"%", csDesrSatRate: passInfo[5].value+"%", epAppAnnualSales: "$"+passInfo[6].value, epCurrProdRate: passInfo[7].value+"%", epDesrProdRate: passInfo[8].value+"%", reTCODN: cdnTotal, reTKBSavings: ("$"+addCommas(KBTotal)), reEpmTurnSave: kbs_ett, reCustSatSave: kbs_cst, reEmpProdSave: kbs_ept, reEpmTurnCost: ("$"+addCommas(EmpTurnTotal)), reCustSatCost: ("$"+addCommas(CusSatTotal)), reEmpProdCost: ("$"+addCommas(EmpProdTotal))},
		  function(data){
			switch(data){
				case "0":
					// Form did not go through correctly so lets tell them.
					// Need to make this somehow show the user what is wrong.
					break;
				default:
					// Went through ok so clear form and instruct them it was succesfull. Also place the link to correspond with the Current Reports ID
					currReportID = data;
					$('.pdfForm').html("<h3 style='padding-top:25px;'>Your personalized report has been created and sent to the email address you have provided.</h3><p>Please check your email filter if you have not received it within 10 minutes.</p><p><span class='viewReportLink' onclick='javascript: viewReportNow();'>You may also access a copy of your report here.</span></p><p>Click the Refer a Colleague button above to send the calculator to a friend, or click the Start Over button to start the calculator over again.</p>");
					window.status = data;
			    try {
          pageTracker._trackPageview("/management_training_programs/cost_of_doing_nothing_calculator/completed_report_form"); 
          } catch(err) {}

					break;
			}
		  });

		
	}
	
	// Function: show/hide a content DIV (up/down accordian style)
	function showHideDiv(theElement){
		$(theElement).slideToggle();
	}
	
	function showInfoForm(){
    try {
    pageTracker._trackPageview("/management_training_programs/cost_of_doing_nothing_calculator/show_report_form"); 
    } catch(err) {}
    showHideDiv('.pdfForm');	
  }
	
	// Function: show/hide a steps tool tip (Fade in/out)
	function showTT(theElement){
		$(theElement).next("span").stop(true,true).fadeIn();
		//$(""+theElement+" + span").stop(true,true).fadeIn();
		
	}
	function hideTT(theElement){
		$(theElement).next("span").stop(true,true).fadeOut();
	}
	
	function addCommas(nStr)
	{
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
	
  function removeCommas(nStr)
  {
    var ReplacedNumber = nStr.replace(/\,/g,'');
    return ReplacedNumber;
  }

	
	function calcUpdate(){
	
		// Running checks for field entries
		var ETC;
		($("input[name='empT_number_emp']").val().length>=1 && $("input[name='empT_avg_salary']").val().length >=1 && $("input[name='empT_current_turnover']").val().length >=1) ? ETC = true : ETC = false;
		var CSC;
		($("input[name='cusS_desired_rate']").val().length>=1 && $("input[name='cusS_current_rate']").val().length >=1 && $("input[name='cusS_annual_sales']").val().length >=1) ? CSC = true : CSC = false;
		var EPC;
		($("input[name='empP_desired_rate']").val().length>=1 && $("input[name='empP_current_rate']").val().length >=1 && $("input[name='empP_annual_sales']").val().length >=1) ? EPC = true : EPC = false;
		
		// For ease we will duplicate the Approximate Annual Sales across steps 2 and 3
		$("input[name='empP_annual_sales']").val($("input[name='cusS_annual_sales']").val());
		$("input[name='cusS_annual_sales']").val($("input[name='empP_annual_sales']").val());
		
		
		//------------------------------------------//
		/*----- Employee Turnover Calculations -----*/
		//------------------------------------------//
		// First we Check to make sure all the fields have values
		if(ETC){
			// All fields have values so lets turn on the next button
			
			// Number of current employees
			//empT_ne = parseInt($("input[name='empT_number_emp']").val()); //old version
			empT_ne = parseInt(removeCommas($("input[name='empT_number_emp']").val()));
			// Current Employee Turnover Rate (Default corporate average is 15%)
			empT_cr = parseInt($("input[name='empT_current_turnover']").val())*0.01;
			// Get the Average Salary - because this may or may not contain commas we should strip them out
			empT_as = $("input[name='empT_avg_salary']").val();
			empT_as = empT_as.replace(/,/g, "");
			empT_as = parseInt(empT_as);
			// Do the calculation
			EmpTurnTotal = Math.ceil(((empT_ne*empT_cr)*empT_as)/2);
			// Spit out the result
			$("#empT_total").text("$"+addCommas(EmpTurnTotal)+"*");
			$("#s1_next").fadeTo("slow", 1);
			$("#s1_next").click(function() {$('#cdnCalculator .slideContent').trigger('next' );});
		}
		//------------------------------------------//
		
		//------------------------------------------//
		/*--- Customer Satisfaction Calculations ---*/
		//------------------------------------------//
		// First we Check to make sure all the fields have values
		if(CSC){
			// Desired Customer Satisfaction Rate (50-100%)  
			cusS_dr = parseInt($("input[name='cusS_desired_rate']").val());
			// Current Customer Satisfaction Rate (50-100%) (Default corporate average is 75%)
			cusS_cr = parseInt($("input[name='cusS_current_rate']").val());
			// Get the Annual Sales - because this may or may not contain commas we should strip them out
			cusS_as = $("input[name='cusS_annual_sales']").val();
			cusS_as = cusS_as.replace(/,/g, "");
			cusS_as = parseInt(cusS_as);
			// Step 1: Determine a vlue for our first hidden variable 
			var cs_hv_1 = cusS_dr-cusS_cr;
			// Step 2: Find the value for our second hidden variable
			var cs_hv_2 = (cs_hv_1*0.01)*0.384615384615;
			// Step 3: Find the final cost
			CusSatTotal = Math.floor(cusS_as*cs_hv_2);
			// Spit out the result
			$("#cusS_total").text("$"+addCommas(CusSatTotal)+"*");
			$("#s2_next").fadeTo("slow", 1);
			$("#s2_next").click(function() {$('#cdnCalculator .slideContent').trigger('next' );});
		}
		//------------------------------------------//
		
		//------------------------------------------//
		/*--- Employee Productivity Calculations ---*/
		//------------------------------------------//
		// First we Check to make sure all the fields have values
		if(EPC){
			// Get the percentages
			empP_dr = parseInt($("input[name='empP_desired_rate']").val())*0.01;
			empP_cr = parseInt($("input[name='empP_current_rate']").val())*0.01;
			// Get the Annual Sales - because this may or may not contain commas we should strip them out
			empP_as = $("input[name='empP_annual_sales']").val();
			empP_as = empP_as.replace(/,/g, "");
			empP_as = parseInt(empP_as);
			// Do the calculation
			EmpProdTotal = Math.ceil((empP_dr-empP_cr)*empP_as);
			// Spit out the result
			$("#empP_total").text("$"+addCommas(EmpProdTotal)+"*");
			$("#s3_next").fadeTo("slow", 1);
			$("#s3_next").click(function() {$('#cdnCalculator .slideContent').trigger('next' );});
		}
		//------------------------------------------//
		
		//------------------------------------------//
		/*--- Cost of Doing Nothing Results Disp ---*/
		//------------------------------------------//
		// Running Total on bottom of calculator. We can use the same condition to fill in the total for the results, twice :)
		if(ETC || CSC || EPC){
			cdnTotal = "$"+addCommas(Math.floor(EmpTurnTotal+CusSatTotal+EmpProdTotal));
			$("#runTally").text(cdnTotal+"*"); // Running Tally on bottom
			$(".resultP").text(cdnTotal); // Total display on results page
			$(".currentCost .tally").text(cdnTotal); // Total display on results graph
			KBTotal = Math.floor(EmpTurnTotal*kbs_et)+Math.floor(cusS_as*kbs_cs)+Math.floor(cusS_as*kbs_ep);
			$(".projectedSavings .tally").text("$"+addCommas(Math.floor(KBTotal))); // Total display on results graph
			$("#runTally").text(cdnTotal); // Total display on results graph
			
			// Total Savings from KB Services
			// Employee Turnover Savings
			kbs_ett = "$"+addCommas(Math.floor(EmpTurnTotal*kbs_et));
			$("#graphKey .iet .saveTotal").text(kbs_ett);
			// Customer Satifaction Savings
			kbs_cst = "$"+addCommas(Math.floor(cusS_as*kbs_cs));
			$("#graphKey .ics .saveTotal").text(kbs_cst);
			// Employee Productivity Savings
			kbs_ept = "$"+addCommas(Math.floor(cusS_as*kbs_ep));
			$("#graphKey .iep .saveTotal").text(kbs_ept);
			
			// The header paragraph
			$("#hp_results span.showSavings").text("$"+addCommas(Math.floor(KBTotal))+" ")
			// Total KB Savings Offered
			/*
			KBTotal = Math.floor(EmpTurnTotal*kbs_et)+Math.floor(cusS_as*kbs_cs)+Math.floor(cusS_as*kbs_ep);
			$("#kbtsDisplay").text("$"+addCommas(Math.floor(KBTotal)));
			*/
			
		}
		//------------------------------------------//
		
	}
	
	// This will open a new window with the name KBCalcReport that will contain the users report in HTML form
	function viewReportNow() {
		window.open("display.asp?id="+currReportID+"", "KBCalcReport");
	}
	
	// A function that helps us determine if a Email address is a valid email address
	function checkEmail(strng) {
		var error=true;
		if (strng == "") {
		   error = false;
		}
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) { 
			error = false;
		}	else {
		//test email for illegal characters
			var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			if (strng.match(illegalChars)) {
				error = false;
			}
		}
		return error;    
	}
	
	// Finally we need to constantly check for validation when the next button is clicked
	// Fields not required  are: Phone (input), Newsletter sign up (checkbox) and Please Contact Me (checkbox)
	function validateRequestFields(){
			// Check for valid fields - if something is not valid let the user know before sending info
			var invalid = false
			$(':input').each(function() {
				;
				var type = this.type;
				var tag = this.tagName.toLowerCase(); // normalize case
				// it's ok to reset the value attr of text inputs,
				// password inputs, and textareas
				if (type == 'text'){
					switch(this.name){
						// Reset the Personal Info form
						case "firstName":
							if(this.value.length<2 || this.value == "First Name" || this.value.indexOf("http://")>=0){
								// turn the BG Color Red then fade to white and add Message
								alert("Please enter your First Name, this is a required field");
								invalid = true;
							}
							break;
						case "lastName":
							if(this.value.length<2 || this.value == "Last Name" || this.value.indexOf("http://")>=0){
								// turn the BG Color Red then fade to white and add Message
								alert("Please enter your Last Name, this is a required field");
								invalid = true;
							}
							break;
						case "title":
							if(this.value.length<2 || this.value == "Title" || this.value.indexOf("http://")>=0){
								// turn the BG Color Red then fade to white and add Message
								alert("Please enter your Title, this is a required field");
								invalid = true;
							}
							break;
						case "organization":
							if(this.value.length<2 || this.value == "Organization" || this.value.indexOf("http://")>=0){
								// turn the BG Color Red then fade to white and add Message
								alert("Please enter your Organization, this is a required field");
								invalid = true;
							}
							break;
						case "email":
							if(this.value.length<2 || this.value == "Email" || this.value.indexOf("http://")>=0){
								// turn the BG Color Red then fade to white and add Message
								if(checkEmail(this.value)){
									// email is fine so lets move on
								} else {
									// email bad , bad email, no.
									alert("Please enter a valid Email address, this is a required field");
									invalid = true;
								}
							}
							break;
						case "country":
							if(this.value.length<2 || this.value == "Country" || this.value.indexOf("http://")>=0){
								// turn the BG Color Red then fade to white and add Message
								alert("Please enter your Country, this is a required field");
								invalid = true;
							}
							break;
						case "zip":
							if(this.value.length<5 || this.value == "Postal Code" || this.value.indexOf("http://")>=0){
								// turn the BG Color Red then fade to white and add Message
								alert("Please enter your Postal Code, this is a required field");
								invalid = true;
							}
							break;
					}
				}
			});
			if(!invalid){
				alterREBtns();
				requestPDF();
			}
	}