	//Weekly Leak Amount
	var wLeak = 0; var wTmpLeak;
	//Monthly Leak Amount
	var mLeak = 0; var mTmpLeak;
	//Weekly Alternate Amount
	var wAlt = 0; var wTmpAlt;
	//Monthly Alternate Amount
	var mAlt = 0; var mTmpAlt;
	
	var spendWeekTitle = new Array();
	var AltWeekTitle = new Array();
	
	var tmpCcost;
	
	function spendLeaks() {
		tmp = stringFilter($('cCost').value);
		tmpCcost = tmp
		
		if(tmp > 1000) {
			toBig('cCost')
		} else {
			wLeak = Math.round(parseFloat(tmp * 5)*100)/100;
			mLeak = Math.round(parseFloat((tmp * 5)* 4.3333)*100)/100;
		
			wTmpLeak = wLeak.toFixed(2);
			mTmpLeak = mLeak.toFixed(2);
		
			$('cWeekCost').setHTML('$' + commaFormatted(wTmpLeak));		
			$('cMonthCost').setHTML('$'+ commaFormatted(mTmpLeak));
		
			$('altApproach').setStyle('display', 'block');
		}
	}
	function toBig(arg) {
		alert("You have provided a figure that is greater than $1,000 a day. This calculator is designed to look at your daily spending habits so please adjust this figure to a smaller amount.")
		$(arg).focus()
	}
	function resetStates() {
		//Reset the info Input Field
		$('cItem').value = '';
		$('aItem').value = '';
		
		//Reset the Cost Input Field
		$('cCost').value = 0;
		$('aCost').value = 0;
		
		$$(['cWeekCost', 'cMonthCost'], ['aWeekCost','aMonthCost'], ['compWeek','compMonth']).setHTML('$0');
		$$(['resetLink', 'saveDataLink']).setStyle('display', 'none'); 
		
	}
	
	function alternate() {
		tmp = stringFilter($('aCost').value).toFloat();
		
		tmp2 = stringFilter($('cCost').value).toFloat()
		

		if(tmp > 1000) {
			toBig('aCost')	
		} else {
			if(tmp < tmp2) {
				wAlt = Math.round(parseFloat(tmp * 5)*100)/100;
				mAlt = Math.round(parseFloat((tmp * 5)* 4.3333)*100)/100;

				wTmpAlt = wAlt.toFixed(2);
				mTmpAlt = mAlt.toFixed(2);

				$('aWeekCost').setHTML('$' + commaFormatted(wTmpAlt));	
				$('aMonthCost').setHTML('$' + commaFormatted(mTmpAlt));

				costComparison();
			
			} else {
				alert('Your Alternate value is greater than your Current Spending. Adjust your price to be less than $' + tmp2)
			}
			
		}
		
	}	
	
	function costComparison() {
		
		sWeekTotal = Math.round((wLeak - wAlt)*100)/100;
		sMonthTotal = Math.round((mLeak - mAlt)*100)/100;
		
		$('compWeek').setHTML('$'+commaFormatted(sWeekTotal.toFixed(2)));
		$('compMonth').setHTML('$'+commaFormatted(sMonthTotal.toFixed(2)));
		
		$('grandTotal').setStyle('display', 'block');
		$$(['resetLink', 'saveDataLink']).setStyle('display', 'block'); 
		
	}
	
	var leakAlert = false;
	var altAlert = false;
	
	function saveData() {

		leakAlert = false;
		altAlert = false;

		if(spendWeekTitle.contains($('cItem').value)) leakAlert = true;

		if(AltWeekTitle.contains($('aItem').value))  altAlert = true;

		if(altAlert == false && leakAlert == false)	{
			addLeakList(); addAltList();
		} else showAlert();
	}

	var ld = 0;

	
	function addLeakList() {
	  	var ni = $('savedLeakData');
		
		leakAlert = false;			
		//Set to show the Leak Data List
		$('leakData').setStyle('display', 'block');
		
		//Show the Leak Totals
		leakTotals(wTmpLeak);
		
		spendWeekTitle[ld] = $('cItem').value;

	  	var newPara = document.createElement('p');

	  	newPara.setAttribute('id', 'leak' + ld);
	  	newPara.innerHTML = '<span class="description">' + $('cItem').value.capitalize() + '</span> <span>Weekly Cost: <strong>$'+ commaFormatted(wTmpLeak) +'</strong> | Monthly Cost: <strong>$'+ commaFormatted(mTmpLeak) +'</strong></span>';
	  	ni.appendChild(newPara);
		ld++;
	}
	
	var lTotal = 0;
	
	function leakTotals(num) {
		
		lTotal = lTotal + num.toFloat();
		
		$$('#leakData h3').setStyle('display', 'block');

		$('leakWeekTotal').setHTML('$'+commaFormatted(lTotal.toFixed(2)));
		$('leakMonthTotal').setHTML('$'+commaFormatted((lTotal*4.3333).toFixed(2)));

		grandTotals();
	}
	
	var ad = 0;

	
	function addAltList() {
	  	var ni = $('saveAltData');

		altAlert = false;
		AltWeekTitle[ad] = $('aItem').value;
		
		$('altData').setStyle('display', 'block');

		//Show the Leak Totals
		altTotals(wTmpAlt);

	  	var newPara = document.createElement('p');

	  	newPara.setAttribute('id', 'alt' + ad);
	  	newPara.innerHTML = '<span class="description">' + $('aItem').value.capitalize() + '</span> <span>Weekly Cost: <strong>$'+ commaFormatted(wTmpAlt) +'</strong> | Monthly Cost: <strong>$'+ commaFormatted(mTmpAlt) +'</strong></span>';
	  	ni.appendChild(newPara);
		ad++;

	}
	
	function showAlert() {
		//Leak List Alert
		if(altAlert == true && leakAlert == true) alert('You have already added the spending leak "' + $('cItem').value + '" to your list.  Please use a different title for the spending leak and try again.\n\n' + 'You have already added the alternative approach "' + $('aItem').value + '" to your list.  Please use a different title for the alternative approach and try again.');
		else if(leakAlert == true) alert('You have already added the spending leak "' + $('cItem').value + '" to your list.  Please use a different title for the spending leak and try again.');
		else if(altAlert == true) alert('You have already added the alternative approach "' + $('aItem').value + '" to your list.  Please use a different title for the alternative approach and try again.');
	}
	
	var aTotal = 0;
	
	function altTotals(num) {
		
		aTotal = aTotal + num.toFloat();

		$$('#altData h3').setStyle('display', 'block');
		$('altWeekTotal').setHTML('$'+commaFormatted(aTotal.toFixed(2)));
		$('altMonthTotal').setHTML('$'+commaFormatted((aTotal*4.3333).toFixed(2)));

		grandTotals();
	}
	
	function grandTotals(){
		$$('#grandTotals h3').setStyle('display', 'block');
		$('grandWeekTotal').setHTML('$'+commaFormatted((lTotal - aTotal).toFixed(2)));
		$('grandMonthTotal').setHTML('$'+commaFormatted(((lTotal - aTotal)*4.3333).toFixed(2)));
	}

	function commaFormatted(amount) {
		var delimiter = ","; // replace comma if desired
		var a = amount.split('.',2)
		var d = a[1];
		var i = parseInt(a[0]);
		if(isNaN(i)) { return ''; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		var n = new String(i);
		var a = [];
		while(n.length > 3) {
			var nn = n.substr(n.length-3);
			a.unshift(nn);
			n = n.substr(0,n.length-3);
		}
		if(n.length > 0) { a.unshift(n); }
		n = a.join(delimiter);
		if(d.length < 1) { amount = n; }
		else { amount = n + '.' + d; }
		amount = minus + amount;
		return amount;
	}
	function stringFilter(input) {
	    s = input;
	    filteredValues = "$,<>(){}[]'!@#$%^&*-_+=| \\:;\"/?`~";
		filteredValues += "abcdefghijklmnopqrstuvwxyz"
	    // Characters stripped out
	    var i;
	    var returnString = "";
	    for (i = 0; i < s.length; i++) {
	        // Search through string and append to unfiltered values to returnString.
	        var c = s.charAt(i);
	        if (filteredValues.indexOf(c) == -1) returnString += c;
	    }
	    return returnString;
	}
	
	window.addEvent('domready', function(){
		new SmoothScroll();
	});