// JavaScript Document

var discount = new Array();

function $get(el) {

	var obj = document.getElementById(el);
	if (obj) {
		return obj;		
	} else {
		return null;
	}
} 

function doVouchers() {
	var a1 = $get('calcFRM_argos_one');
	var a5 = $get('calcFRM_argos_five');
	var a10 = $get('calcFRM_argos_ten');
	var a20 = $get('calcFRM_argos_twenty');
	var a25 = $get('calcFRM_argos_twentyfive');
	var h1 = $get('calcFRM_homebase_one');
	var h5 = $get('calcFRM_homebase_five');
	var h10 = $get('calcFRM_homebase_ten');
	var h20 = $get('calcFRM_homebase_twenty');
	// var h25 = $get('calcFRM_homebase_twentyfive');
	var displayTotal = $get('calcTotalResult');
	var displaySaveTotal = $get('calcSaveResult');
	var argosPercentage = 0;
	var homebasePercentage = 0;
	var total = 0;
	var savetotal = 0;
	
	var argosTotal = ((a1.value*1) + (a5.value*5) + (a10.value*10) + (a20.value*20) + (a25.value*25));
	// var homebaseTotal = ((h1.value*1) + (h5.value*5) + (h10.value*10) + (h20.value*20) + (h25.value*25));
	var homebaseTotal = ((h1.value*1) + (h5.value*5) + (h10.value*10) + (h20.value*20));
	
	
	for (i=0;i<discount.length;i++) {
		
		if (argosTotal>=discount[i].lower&&argosTotal<=discount[i].upper) {
			argosPercentage = (discount[i].argos_percentage/100);
		}
		if (argosTotal>=discount[i].lower) {
			argosCall = discount[i].call_us		
		}
		if (homebaseTotal>=discount[i].lower&&homebaseTotal<=discount[i].upper) {
			homebasePercentage = (discount[i].homebase_percentage/100);
		}
		if (homebaseTotal>=discount[i].lower) {
			homebaseCall = discount[i].call_us		
		}
	}
	
	total = (argosTotal + homebaseTotal);
	savetotal = ((argosTotal-(argosTotal*(argosPercentage))) + (homebaseTotal-(homebaseTotal*(homebasePercentage))));
	
	displaySaveTotal.innerHTML = '&pound;' + savetotal.toFixed(2);
	if (argosCall||homebaseCall) {
		displaySaveTotal.innerHTML = '<div style="font-weight:bold;color:red;text-align:left;margin-left:1em;"><div>Call us</div><div>to find out</div></div>';		
	}
	
	displayTotal.innerHTML = total.toFixed(2);
	
}

function discounts(ap,hp,l,u,c) {
	this.argos_percentage = ap;
	this.homebase_percentage = hp;
	this.lower = l;
	this.upper = u;
	this.call_us = c;
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function calcTotal(obj) {
	if (obj) {
		if (obj.value=='') {
			obj.value = 0;	
		}
	}
	var a1 = $get('accountOrderFRM_argos_one');
	var a5 = $get('accountOrderFRM_argos_five');
	var a10 = $get('accountOrderFRM_argos_ten');
	var a20 = $get('accountOrderFRM_argos_twenty');
	var a25 = $get('accountOrderFRM_argos_twentyfive');
	var a1v = $get('accountOrderFRM_argos_one_value');
	var a5v = $get('accountOrderFRM_argos_five_value');
	var a10v = $get('accountOrderFRM_argos_ten_value');
	var a20v = $get('accountOrderFRM_argos_twenty_value');
	var a25v = $get('accountOrderFRM_argos_twentyfive_value');
	var at = $get('accountOrderFRM_argos_total');
	var ad = $get('accountOrderFRM_argos_discount');
	var ap = $get('accountOrderFRM_argos_payable');
	var h1 = $get('accountOrderFRM_homebase_one');
	var h5 = $get('accountOrderFRM_homebase_five');
	var h10 = $get('accountOrderFRM_homebase_ten');
	var h20 = $get('accountOrderFRM_homebase_twenty');
	var h1v = $get('accountOrderFRM_homebase_one_value');
	var h5v = $get('accountOrderFRM_homebase_five_value');
	var h10v = $get('accountOrderFRM_homebase_ten_value');
	var h20v = $get('accountOrderFRM_homebase_twenty_value');
	var ht = $get('accountOrderFRM_homebase_total');
	var hd = $get('accountOrderFRM_homebase_discount');
	var hp = $get('accountOrderFRM_homebase_payable');
	
	a1v.value = '£' + (a1.value*1).toFixed(2);
	a5v.value = '£' + (a5.value*5).toFixed(2);
	a10v.value = '£' + (a10.value*10).toFixed(2);
	a20v.value = '£' + (a20.value*20).toFixed(2);
	a25v.value = '£' + (a25.value*25).toFixed(2);
	h1v.value = '£' + (h1.value*1).toFixed(2);
	h5v.value = '£' + (h5.value*5).toFixed(2);
	h10v.value = '£' + (h10.value*10).toFixed(2);
	h20v.value = '£' + (h20.value*20).toFixed(2);
	
	if (obj!=false) {
		var argosTotal = ((a1.value*1) + (a5.value*5) + (a10.value*10) + (a20.value*20) + (a25.value*25));
		// var homebaseTotal = ((h1.value*1) + (h5.value*5) + (h10.value*10) + (h20.value*20) + (h25.value*25));
		var homebaseTotal = ((h1.value*1) + (h5.value*5) + (h10.value*10) + (h20.value*20));
		
		at.value = argosTotal.toFixed(2);
		ap.value = (argosTotal-(argosTotal*(ad.value/100))).toFixed(2);
		ht.value = homebaseTotal.toFixed(2);
		hp.value = (homebaseTotal-(homebaseTotal*(hd.value/100))).toFixed(2);
	}
	//total = (Number(tt.value) + result);
	
	//tt.value = total.toFixed(2);
}
function reCalcTotal(obj) {
	if (obj) {
		if (obj.value=='') {
			obj.value = 0;	
		}
	}
	var a1 = $get('quoteOrderFRM_argos_one');
	var a5 = $get('quoteOrderFRM_argos_five');
	var a10 = $get('quoteOrderFRM_argos_ten');
	var a20 = $get('quoteOrderFRM_argos_twenty');
	var a25 = $get('quoteOrderFRM_argos_twentyfive');
	var a1v = $get('quoteOrderFRM_argos_one_value');
	var a5v = $get('quoteOrderFRM_argos_five_value');
	var a10v = $get('quoteOrderFRM_argos_ten_value');
	var a20v = $get('quoteOrderFRM_argos_twenty_value');
	var a25v = $get('quoteOrderFRM_argos_twentyfive_value');
	var at = $get('quoteOrderFRM_argos_total');
	var ad = $get('quoteOrderFRM_argos_discount');
	var ap = $get('quoteOrderFRM_argos_payable');
	var h1 = $get('quoteOrderFRM_homebase_one');
	var h5 = $get('quoteOrderFRM_homebase_five');
	var h10 = $get('quoteOrderFRM_homebase_ten');
	var h20 = $get('quoteOrderFRM_homebase_twenty');
	var h1v = $get('quoteOrderFRM_homebase_one_value');
	var h5v = $get('quoteOrderFRM_homebase_five_value');
	var h10v = $get('quoteOrderFRM_homebase_ten_value');
	var h20v = $get('quoteOrderFRM_homebase_twenty_value');
	var ht = $get('quoteOrderFRM_homebase_total');
	var hd = $get('quoteOrderFRM_homebase_discount');
	var hp = $get('quoteOrderFRM_homebase_payable');
	var postage = $get('quoteOrderFRM_postage');
	var argosPercentage = 0;
	var homebasePercentage = 0;
	
	a1v.value = '£' + (a1.value*1).toFixed(2);
	a5v.value = '£' + (a5.value*5).toFixed(2);
	a10v.value = '£' + (a10.value*10).toFixed(2);
	a20v.value = '£' + (a20.value*20).toFixed(2);
	a25v.value = '£' + (a25.value*25).toFixed(2);
	h1v.value = '£' + (h1.value*1).toFixed(2);
	h5v.value = '£' + (h5.value*5).toFixed(2);
	h10v.value = '£' + (h10.value*10).toFixed(2);
	h20v.value = '£' + (h20.value*20).toFixed(2);
	
		var argosTotal = ((a1.value*1) + (a5.value*5) + (a10.value*10) + (a20.value*20) + (a25.value*25));
		// var homebaseTotal = ((h1.value*1) + (h5.value*5) + (h10.value*10) + (h20.value*20) + (h25.value*25));
		var homebaseTotal = ((h1.value*1) + (h5.value*5) + (h10.value*10) + (h20.value*20));
	
		for (i=0;i<discount.length;i++) {
			
			if (argosTotal>=discount[i].lower&&argosTotal<=discount[i].upper) {
				argosPercentage = (discount[i].argos_percentage/100);
			}
			if (argosTotal>=discount[i].lower) {
				argosCall = discount[i].call_us		
			}
			if (homebaseTotal>=discount[i].lower&&homebaseTotal<=discount[i].upper) {
				homebasePercentage = (discount[i].homebase_percentage/100);
			}
			if (homebaseTotal>=discount[i].lower) {
				homebaseCall = discount[i].call_us		
			}
		}
	/*
		total = (argosTotal + homebaseTotal);
		savetotal = ((argosTotal-(argosTotal*(argosPercentage))) + (homebaseTotal-(homebaseTotal*(homebasePercentage))));
		*/
		at.value = '£' + argosTotal.toFixed(2);
		ad.value = '£' + (argosTotal*(argosPercentage));
		ap.value = '£' + (argosTotal-(argosTotal*(argosPercentage)));
											
		ht.value = '£' + homebaseTotal.toFixed(2);
		hd.value = '£' + (homebaseTotal*(homebasePercentage));
		hp.value = '£' + (homebaseTotal-(homebaseTotal*(homebasePercentage)));
/*		
		postage.value = '£39.26';	
		
		if ((argosTotal+homebaseTotal)<20000) {
			postage.value = '£19.63';	
		} 
		if ((argosTotal+homebaseTotal)<5000) {
			postage.value = '£10.80';	
		} 
		if ((argosTotal+homebaseTotal)<2499) {
			postage.value = '£5.40';	
		} 
		if ((argosTotal+homebaseTotal)<999) {
			postage.value = '£4.50';	
		} 
		if ((argosTotal+homebaseTotal)<250) {
			postage.value = '£4.05';	
		} 
		if ((argosTotal+homebaseTotal)<100) {
			postage.value = '£1.00';	
		} 
		if ((argosTotal+homebaseTotal)<50) {
			postage.value = '£0.32';	
		} 
*/	
		if ((argosTotal+homebaseTotal)>=500) {
			postage.value = '£0.00';	
		} 
		else {
						postage.value = '£4.95';	

		}
//total = (Number(tt.value) + result);
	
	//tt.value = total.toFixed(2);
}

function reCalcTotalNew(obj) {
	if (obj) {
		if (obj.value=='') {
			obj.value = 0;	
		}
	}
	var a1 = $get('quoteOrderFRM_argos_one');
	var a5 = $get('quoteOrderFRM_argos_five');
	var a10 = $get('quoteOrderFRM_argos_ten');
	var a20 = $get('quoteOrderFRM_argos_twenty');
	var a25 = $get('quoteOrderFRM_argos_twentyfive');
	var a1v = $get('quoteOrderFRM_argos_one_value');
	var a5v = $get('quoteOrderFRM_argos_five_value');
	var a10v = $get('quoteOrderFRM_argos_ten_value');
	var a20v = $get('quoteOrderFRM_argos_twenty_value');
	var a25v = $get('quoteOrderFRM_argos_twentyfive_value');
	var at = $get('quoteOrderFRM_argos_total');
	var ad = $get('quoteOrderFRM_argos_discount');
	var ap = $get('quoteOrderFRM_argos_payable');
	var apostage = $get('quoteOrderFRM_argos_postage');
	var argos_postage = $get('quoteOrderFRM_argos_postage_hidden');

	var h1 = $get('quoteOrderFRM_homebase_one');
	var h5 = $get('quoteOrderFRM_homebase_five');
	var h10 = $get('quoteOrderFRM_homebase_ten');
	var h20 = $get('quoteOrderFRM_homebase_twenty');
	var h1v = $get('quoteOrderFRM_homebase_one_value');
	var h5v = $get('quoteOrderFRM_homebase_five_value');
	var h10v = $get('quoteOrderFRM_homebase_ten_value');
	var h20v = $get('quoteOrderFRM_homebase_twenty_value');
	var ht = $get('quoteOrderFRM_homebase_total');
	var hd = $get('quoteOrderFRM_homebase_discount');
	var hp = $get('quoteOrderFRM_homebase_payable');
	var hpostage = $get('quoteOrderFRM_homebase_postage');
	var homebase_postage = $get('quoteOrderFRM_homebase_postage_hidden');
	var argosPercentage = 0;
	var homebasePercentage = 0;
	
	a1v.value = '£' + (a1.value*1).toFixed(2);
	a5v.value = '£' + (a5.value*5).toFixed(2);
	a10v.value = '£' + (a10.value*10).toFixed(2);
	a20v.value = '£' + (a20.value*20).toFixed(2);
	a25v.value = '£' + (a25.value*25).toFixed(2);
	h1v.value = '£' + (h1.value*1).toFixed(2);
	h5v.value = '£' + (h5.value*5).toFixed(2);
	h10v.value = '£' + (h10.value*10).toFixed(2);
	h20v.value = '£' + (h20.value*20).toFixed(2);
	
		var argosTotal = ((a1.value*1) + (a5.value*5) + (a10.value*10) + (a20.value*20) + (a25.value*25));
		// var homebaseTotal = ((h1.value*1) + (h5.value*5) + (h10.value*10) + (h20.value*20) + (h25.value*25));
		var homebaseTotal = ((h1.value*1) + (h5.value*5) + (h10.value*10) + (h20.value*20));
	
		for (i=0;i<discount.length;i++) {
			
			if (argosTotal>=discount[i].lower&&argosTotal<=discount[i].upper) {
				argosPercentage = (discount[i].argos_percentage/100);
			}
			if (argosTotal>=discount[i].lower) {
				argosCall = discount[i].call_us		
			}
			if (homebaseTotal>=discount[i].lower&&homebaseTotal<=discount[i].upper) {
				homebasePercentage = (discount[i].homebase_percentage/100);
			}
			if (homebaseTotal>=discount[i].lower) {
				homebaseCall = discount[i].call_us		
			}
		}
	
		var hpv = 45.15;	
		var apv = 45.15;	
		
		if ((argosTotal)<=20000) {		apv = 22.57;			} 
		if ((argosTotal)<=5000) {		apv = 16.68;			} 
		if ((argosTotal)<=2500) {		apv = 8.34;			} 
		if ((argosTotal)<=1000) {			apv = 6.50;			} 
		if ((argosTotal)<=500) {			apv = 5.52;			} 
		if ((argosTotal)<250) {			apv = 0.00;			}    /* Delivery not available for orders less than 250 */

		if ((argosTotal)<=20000) {		hpv = 22.57;			} 
		if ((argosTotal)<=5000) {		hpv = 16.68;			} 
		if ((argosTotal)<=2500) {		hpv = 8.34;			} 
		if ((argosTotal)<=1000) {			hpv = 6.50;			} 
		if ((argosTotal)<=500) {			hpv = 5.52;			} 		
		if ((homebaseTotal)<250) {			hpv = 0.00;			} /* Delivery not available for orders less than 250 */

		if (hpv == 0.00) {
			hpostage.value = 'Minimum order value £250';
		} else {
			hpostage.value = '£'+hpv.toFixed(2);
		}
		
		if (apv == 0.00) {
			apostage.value = 'Minimum order value £250';
		} else {
			apostage.value = '£'+apv.toFixed(2);
		}

		homebase_postage.value = hpv;
		argos_postage.value = apv;

	/*
		total = (argosTotal + homebaseTotal);
		savetotal = ((argosTotal-(argosTotal*(argosPercentage))) + (homebaseTotal-(homebaseTotal*(homebasePercentage))));
		*/
		at.value = '£' + argosTotal.toFixed(2);
		ad.value = '£' + (argosTotal*(argosPercentage)).toFixed(2);
		ap.value = '£' + (argosTotal-(argosTotal*(argosPercentage))+apv).toFixed(2);
											
		ht.value = '£' + homebaseTotal.toFixed(2);
		hd.value = '£' + (homebaseTotal*(homebasePercentage)).toFixed(2);
		hp.value = '£' + (homebaseTotal-(homebaseTotal*(homebasePercentage))+hpv).toFixed(2);

//total = (Number(tt.value) + result);
	
	//tt.value = total.toFixed(2);
}