function setinputfocus(e)
{
	e.getElementsByTagName('input')[0].focus();
}

function check_numeric(e, obj)
{
	 var charCode = (e.which) ? e.which : event.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	
	 return true;
}

var RequestMade = function(t) {
	if(t.responseText == 'SUCCESS')
	{
		alert("Thank you for your order!\r\nOne of our staff will be in touch");
	} else {
		alert("There was an error requesting the materials you specified.\r\nPlease contact us on 0800 590 517 and we will be happy to help you.")
	}
}

var RequestFailed = function(t) {
	alert("There was an error requesting the materials you specified.\r\nPlease contact us on 0800 590 517 and we will be happy to help you.");
}

function updatetally()
{
	var cost;
	cost = 0;
	cost+=$('largeboxes').value * 2.3
	cost+=$('smallboxes').value * 1.8
	cost+=$('archiveboxes').value * 1.8
	cost+=$('bubblewrap').value * 1.2
	cost+=$('wardrobecartons').value * 8
	cost+=$('doublemattress').value * 2.3
	cost+=$('singlemattress').value * 2.3
	cost+=$('sealingtape').value * 1.2
	cost+=$('fullwrapping').value * 5.5
	cost+=$('paperblanket').value * 15
	cost+=$('blackmarker').value * 1.2
	cost+=$('redmarker').value * 1.2
	if($('delivery_deliver').checked == true)
		cost += 12.5;
		
	$('totalvalue').innerHTML = '£' + cost.toFixed(2);
	
	if(cost == 0)
		$('Request_js').disabled = true;
	else
		$('Request_js').disabled = false;
}

function RequestItems()
{
	var cost;
	cost = 0;
	cost+=$('largeboxes').value * 2.3
	cost+=$('smallboxes').value * 1.8
	cost+=$('archiveboxes').value * 1.8
	cost+=$('bubblewrap').value * 1.2
	cost+=$('wardrobecartons').value * 8
	cost+=$('doublemattress').value * 2.3
	cost+=$('singlemattress').value * 2.3
	cost+=$('sealingtape').value * 1.2
	cost+=$('fullwrapping').value * 5.5
	cost+=$('paperblanket').value * 15
	cost+=$('blackmarker').value * 1.2
	cost+=$('redmarker').value * 1.2
	if($('delivery_deliver').checked == true)
		cost += 12.5;
		
	lb=$('largeboxes').value
	sb=$('smallboxes').value
	ab=$('archiveboxes').value
	bw=$('bubblewrap').value
	wc=$('wardrobecartons').value
	dm=$('doublemattress').value
	sm=$('singlemattress').value
	st=$('sealingtape').value
	fw=$('fullwrapping').value
	pb=$('paperblanket').value
	bm=$('blackmarker').value
	rm=$('redmarker').value
	if($('delivery_deliver').checked == true)
		deliver='deliver';
	if($('delivery_collect').checked == true)
		deliver='collect';
	n=$('name').value.replace('=', '%3D').replace('&', '%26')
	t=$('telephone').value.replace('=', '%3D').replace('&', '%26')
	a=$('address').value.replace('=', '%3D').replace('&', '%26')
	
	new Ajax.Request('material_request.php', {method:'post',asynchronous:true,postBody:'price='+cost.toFixed(2)+'&ab='+ab+'&lb='+lb+'&sb='+sb+'&bw='+bw+'&wc='+wc+'&dm='+dm+'&sm='+sm+'&st='+st+'&fw='+fw+'&pb='+pb+'&bm='+bm+'&rm='+rm+'&deliver='+deliver+'&n='+n+'&t='+t+'&a='+a,onSuccess:RequestMade,onFailure:RequestFailed});
}

function init()
{
	$('Request').style.display = "none";
	$('Request_js').style.display = "";
	updatetally();
}

window.onload = init;
