
$(function(){
	$('#item1').click(function(){
			
			this.value="";
			$('#item1').css('color','#000000');
		});	
	
	$('#item2').click(function(){
			this.value="";
			$('#item2').css('color','#000000');
		});
	
	$('#item3').click(function(){
			this.value="";
			$('#item3').css('color','#000000');
		});
	
	$('#item4').click(function(){
			this.value="";
			$('#item4').css('color','#000000');
		});
	
	$('#item5').click(function(){
			this.value="";
			$('#item5').css('color','#000000');
		});
	
	$('#item6').click(function(){
			this.value="";
			$('#item6').css('color','#000000');
		});
	
	$('#item7').click(function(){
			this.value="";
			$('#item7').css('color','#000000');
		});
	
	$('#item8').click(function(){
			this.value="";
			$('#item8').css('color','#000000');
		});
	
	$('#amount1').click(function(){
			this.value="";
			$('#amount1').css('color','#000000');
		});	
	
	$('#amount2').click(function(){
			this.value="";
			$('#amount2').css('color','#000000');
		});
	
	$('#amount3').click(function(){
			this.value="";
			$('#amount3').css('color','#000000');
		});
	
	$('#amount4').click(function(){
			this.value="";
			$('#amount4').css('color','#000000');
		});
	
	$('#amount5').click(function(){
			this.value="";
			$('#amount5').css('color','#000000');
		});
	
	$('#amount6').click(function(){
			this.value="";
			$('#amount6').css('color','#000000');
		});
	
	$('#amount7').click(function(){
			this.value="";
			$('#amount7').css('color','#000000');
		});
	
	$('#amount8').click(function(){
			this.value="";
			$('#amount8').css('color','#000000');
		});
});

/*--------------------------------- Cashback ---------------------------*/
function format(ele){
	//strip out $ symbol
	re = /\$|,/g;
	var ele=ele.replace(re,"");
	
	//determine if ele is number and format number if true
	if(Number(ele)){
		var vAmount2=new Number(ele);
		var vAmount3=vAmount2.toFixed(2);
		return vAmount3;
	}else{
		return '0.00';
	}
}

function calc(){
	var aFreq=Array(12,52,24,26,1);
	
	var vYear_Total=0;
	var vCashback_Total=0;
	
	//Loop through to calculate
	for(i=1;i<9;i++){
		
		var vAmount=document.getElementById("amount" + i).value;
		var vAmount2=format(vAmount);
		document.getElementById("amount" + i).value=vAmount2;
		
		var vFreq=document.getElementById("frequency" + i).selectedIndex;
		var vTotal=vAmount2 * aFreq[vFreq];
		var vTotal2=vTotal.toFixed(2); 
		document.getElementById("total" + i).firstChild.nodeValue=vTotal2;
		
		var vCashback=vTotal2 * .01;
		var vCashback2=vCashback.toFixed(2);
		document.getElementById("cashback" + i).firstChild.nodeValue=vCashback2;
		
		var vYear_Total = parseFloat(vYear_Total) + parseFloat(vTotal2);
		var vCashback_Total = parseFloat(vCashback_Total) + parseFloat(vCashback2);
		
	}
	
	var vYear_Total2=vYear_Total.toFixed(2);
	document.getElementById("totalG").firstChild.nodeValue=vYear_Total2;
	
	var vCashback_Total2=vCashback_Total.toFixed(2);
	document.getElementById("cashbackG").firstChild.nodeValue="$"+vCashback_Total2;
	
	
	return false;
}


function resetForm(){
	//Loop through to reset
	for(i=1;i<9;i++){
		document.getElementById("item" + i).value="";
		document.getElementById("frequency" + i).options[0].selected=true;
		document.getElementById("amount" + i).value="";
		document.getElementById("total" + i).firstChild.nodeValue="";
		document.getElementById("cashback" + i).firstChild.nodeValue="";
	}
	
	document.getElementById("totalG").firstChild.nodeValue="";
	document.getElementById("cashbackG").firstChild.nodeValue="";
	
	
	return false;
}

function preLoad(){
	var aItems=new Array('','Food','Pharmacy, sundries','Utilities, misc. households','Gas, oil, auto maintenance','Personal care','Travel, entertainment','Newspapers, magazines','');
	
	var aFreq=new Array(0,1,0,0,0,0,4,4,0);
	var aAmount=new Array('0','165.00','175.00','150.00','180.00','125.00','4750.00','500.00','');
	
	for(i=1;i<=8;i++){
			document.getElementById("item" + i).value=aItems[i];
			document.getElementById("item" + i).style.color="#999999";
			document.getElementById("frequency" + i).options[aFreq[i]].selected=true;
			document.getElementById("amount" + i).value=aAmount[i];
			document.getElementById("amount" + i).style.color="#999999";
		}
	
	
	calc();
	
	return false;
	}
	
	
	//----------------------------------- FAQ ---------------------------->
	function show(shID) {
	if (document.getElementById(shID)) {
		if (document.getElementById(shID+'-show').style.display != 'none') {
			//document.getElementById(shID+'-show').style.display = 'none';
			document.getElementById(shID).style.display = 'block';
		}
		else {
			document.getElementById(shID+'-show').style.display = 'inline';
			document.getElementById(shID).style.display = 'none';
		}
	}
}

function hide(shID) {
	
			document.getElementById(shID+'-show').style.display = 'inline';
			document.getElementById(shID).style.display = 'none';
	
}