	//Global Definitons for data usage.
	var block     = 10;    //KB
	
	//Monthly fee, [$] "Dollars"
	var mEDDatac  = 0;    //Every Day Casual Data
	// var mEDData50 = 39;   //Every Day Data 50
	// var mEDData1000 = 149;   //Every Day Data 1000
	var mBSData200Term = 29.95; 	// Broadband Starter 200 24mth term
	var mBSData200NoTerm = 39.95;	// Broadband Starter 200 no term
	var mBEData1000Term = 49.95;		// Broadband Everyday 1000 24mth term
	var mBEData1000NoTerm = 59.95;		// Broadband Everyday 1000 no term
	
	//Included Data per plan, Mb "Mega bites"
	var iEDDatac  = 0;       //Every Day Casual Data
	// var iEDData50 = 50000;   //Every Day Data 50
	// var iEDData1000 = 1000000;   //Every Day Data 1000
	var iBSData200Term = 200000; 	// Broadband Starter 200 24mth term
	var iBSData200NoTerm = 200000;	// Broadband Starter 200 no term
	var iBEData1000Term = 1000000;		// Broadband Everyday 1000 24mth term
	var iBEData1000NoTerm = 1000000;	// Broadband Everyday 1000 no term	
	
	//Excess usage Price / Block [$] "Dollars"
	var eEDDatac  = 0.1125;  //Every Day Casual Data
	// var eEDData50 = 0.01; //Every Day Data 50
	// var eEDData1000 = 0.00; //Every Day Data 1000
	var eBSData200Term = 0.5; 	// Broadband Starter 200 24mth term
	var eBSData200NoTerm = 0.5;	// Broadband Starter 200 no term
	var eBEData1000Term = 0.5;		// Broadband Everyday 1000 24mth term
	var eBEData1000NoTerm = 0.5;	// Broadband Everyday 1000 no term
	
	//For choosing recomended plan
	var recmPlan = "EDDc";
	var recmValue = 0;
	
	function init(){
		clearEstValues();
		estPlan();
	}
	
	YAHOO.util.Event.on(window,'load',init);
	
	function estPlan(){
		/**/
		if(document.getElementById("txtMonthlyUsage").value != ""){
			var usage = document.getElementById("txtMonthlyUsage").value * 1000; //Kb
			document.frmPlanEst.txtPlanUsage.value = document.getElementById("txtMonthlyUsage").value;
			
			estDDatac(usage);
			// estDData50(usage);
			// estDData1000(usage);
			estBSData200Term(usage);
			estBSData200NoTerm(usage);
			estBEData1000Term(usage);
			estBEData1000NoTerm(usage);
			
			clearTicks();
			markRecmPlan();
			
			document.getElementById("txtMonthlyUsage").value = "";
		}
		else 
		if(document.frmPlanEst.txtPlanUsage.value != ""){
			var usage = document.frmPlanEst.txtPlanUsage.value * 1000; //Kb
	
			estDDatac(usage);
			// estDData50(usage);
			// estDData1000(usage);
			estBSData200Term(usage);
			estBSData200NoTerm(usage);
			estBEData1000Term(usage);
			estBEData1000NoTerm(usage);
			
			clearTicks();
			markRecmPlan();
		}else{
			clearTicks();
			clearEstValues();
		}
	}
	
	function estDDatac(usage){
		var result = mEDDatac + (eEDDatac * (usage / block));
		document.frmPlanEst.txtEDDatac.value = "$ " + round(result,2);
		recmValue = result;
		recmPlan = "EDDc";
	}
	
	/*
	function estDData50(usage){
		var result, excess;
		
		if(usage > iEDData50) excess = usage - iEDData50;
		else excess = 0;
		
		result = mEDData50 + ((excess / block) * eEDData50);
		document.frmPlanEst.txtEDData50.value = "$ " + round(result,2);
		
		if(result < recmValue){
			recmValue = result;
			recmPlan = "EDD50";
		}		
	}
	
	function estDData1000(usage){
		var result, excess;
		
		if(usage > iEDData1000) excess = usage - iEDData1000;
		else excess = 0;
		
		result = mEDData1000 + ((excess / block) * eEDData1000);
		document.frmPlanEst.txtEDData1000.value = "$ " + round(result,2);
		
		if(result < recmValue){
			recmValue = result;
			recmPlan = "EDD1000";
		}		
	}
	*/
	
	function estBSData200Term(usage){
		var result, excess;
		
		if (usage > (iBSData200Term * 2)) excess = usage - (iBSData200Term * 2);
		else excess = 0;

		if (usage <= iBSData200Term) {
			result = mBSData200Term;
		} else if (usage > iBSData200Term && usage <= (iBSData200Term * 2)) {
			result = mBSData200Term + 10;
		} else {
			result = (mBSData200Term + 10) + ((excess / (block*100)) * eBSData200Term);
		}
		document.frmPlanEst.txtBSD200T.value = "$ " + round(result,2);
		
		if(result < recmValue){
			recmValue = result;
			recmPlan = "BSD200T";
		}
	}
	
	function estBSData200NoTerm(usage){
		var result, excess;
		
		if (usage > (iBSData200NoTerm * 2)) excess = usage - (iBSData200NoTerm * 2);
		else excess = 0;

		if (usage <= iBSData200NoTerm) {
			result = mBSData200NoTerm;
		} else if (usage > iBSData200NoTerm && usage <= (iBSData200NoTerm * 2)) {
			result = mBSData200NoTerm + 10;
		} else {
			result = (mBSData200NoTerm + 10) + ((excess / (block*100)) * eBSData200NoTerm);
		}
		document.frmPlanEst.txtBSD200NT.value = "$ " + round(result,2);
		
		if(result < recmValue){
			recmValue = result;
			recmPlan = "BSD200NT";
		}
	}
	
	function estBEData1000Term(usage){
		var result, excess;
		
		if (usage > (iBEData1000Term * 2)) excess = usage - (iBEData1000Term * 2);
		else excess = 0;

		if (usage <= iBEData1000Term) {
			result = mBEData1000Term;
		} else if (usage > iBEData1000Term && usage <= (iBEData1000Term * 2)) {
			result = mBEData1000Term + 10;
		} else {
			result = (mBEData1000Term + 10) + ((excess / (block*100)) * eBEData1000Term);
		}
		document.frmPlanEst.txtBED1000T.value = "$ " + round(result,2);
		
		if(result < recmValue){
			recmValue = result;
			recmPlan = "BED1000T";
		}
	}
	
	function estBEData1000NoTerm(usage){
		var result, excess;
		
		if (usage > (iBEData1000NoTerm * 2)) excess = usage - (iBEData1000NoTerm * 2);
		else excess = 0;

		if (usage <= iBEData1000NoTerm) {
			result = mBEData1000NoTerm;
		} else if (usage > iBEData1000NoTerm && usage <= (iBEData1000NoTerm * 2)) {
			result = mBEData1000NoTerm + 10;
		} else {
			result = (mBEData1000NoTerm + 10) + ((excess / (block*100)) * eBEData1000NoTerm);
		}
		document.frmPlanEst.txtBED1000NT.value = "$ " + round(result,2);
		
		if(result < recmValue){
			recmValue = result;
			recmPlan = "BED1000NT";
		}
	}
	
	function markRecmPlan(){
		if(document.getElementById("txtPlanUsage").value == "" || document.getElementById("txtPlanUsage").value == " "){
			return;
		}
		if(recmPlan == "EDDc"){
			YAHOO.util.Dom.addClass('trEDDatac','tickbg');
		}
		else if(recmPlan == "BSD200T"){
			YAHOO.util.Dom.addClass('trBSD200T','tickbg');
		}	
		else if(recmPlan == "BSD200NT"){
			YAHOO.util.Dom.addClass('trBSD200NT','tickbg');
		} 
		else if(recmPlan == "BED1000T"){
			YAHOO.util.Dom.addClass('trBED1000T','tickbg');
		}	
		else if(recmPlan == "BED1000NT"){
			YAHOO.util.Dom.addClass('trBED1000NT','tickbg');
		}
	}
	
	// Round a value to 2 decimal places
	function round(number,X) {
	// rounds number to X decimal places, defaults to 2
		X = (!X ? 2 : X);
		return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
	}
	
	// function to highlight data plan row
	function change(id, newClass) {
		identity=document.getElementById(id);
		identity.className=newClass;
	}
	
	function clearEstValues(){
		var alltxtfields = YAHOO.util.Dom.get(['txtEDDatac','txtBSD200T','txtBSD200NT','txtBED1000T','txtBED1000NT']);
		for (var i=0;i<alltxtfields.length;i++) {
			alltxtfields[i].setAttribute('value','');
		}
	}
	
	function clearTicks(){
		var alltrs = YAHOO.util.Dom.get(['trEDDatac','trBSD200T','trBSD200NT','trBED1000T','trBED1000NT']);
		for (var i=0;i<alltrs.length;i++) {
			YAHOO.util.Dom.removeClass(alltrs[i],'tickbg');
		}
	}
	
	function getElementsByTagNames(list,obj) {
		if (!obj) var obj = document;
		var tagNames = list.split(',');
		var resultArray = new Array();
		for (var i=0;i<tagNames.length;i++) {
			var tags = obj.getElementsByTagName(tagNames[i]);
			for (var j=0;j<tags.length;j++) {
				resultArray.push(tags[j]);
			}
		}
		var testNode = resultArray[0];
		if (!testNode) return [];
		if (testNode.sourceIndex) {
			resultArray.sort(function (a,b) {
					return a.sourceIndex - b.sourceIndex;
			});
		}
		else if (testNode.compareDocumentPosition) {
			resultArray.sort(function (a,b) {
					return 3 - (a.compareDocumentPosition(b) & 6);
			});
		}
		return resultArray;
	}
