

var g_no_check = true
function check_fundraiser(e){
	if ( e.value.length == 8 && g_no_check ){
		g_no_check = false;
		var url='http://www.carboncatchers.com.au/fundtree/ajax/check_fundraiser.php';
		url    += '?code=' + e.value;
		var target='fundraiser_name';
		var pars='';
		var myAjax=new Ajax.Updater(
				target,
				url,
				{
					method: 'get',
					parameters: pars,
					onComplete: set_name
				}
		);
	}
}
/*
function check_fundraiser () {

	e = $('inp_fundraiser_code');

	if (e.value.length == 8){
		$('main_form').action = '?id=home&action=fundtree2ui&handle=check_fundraiser_submit';
		$('main_form').submit();
	}
}
*/
function set_name (req){
	g_no_check = false;
	discount_price_per_tree = 6.60;

	$('inp_fundraiser_name').value='Fundraiser: ' + req.responseText; 
	$('fundraiser_name').innerHTML ='Fundraiser: ' + req.responseText; 

	if (req.responseText != 'no fundraiser matches this code') {
		g_amount = g_tree_count * discount_price_per_tree;	
		$('inp_price').value = g_amount;
		$('sp_price').innerHTML = g_amount;
	}

}

function validate_fields() {
	e = $('rad_purchase_fundraiser');
	if (e.checked == true) {
		e = $('inp_fundraiser_code');
		if (e.value.length != 8 ){
			alert ('The fundraiser code should contain 8 letters');
			return false;
		}			
	}

	if ($('inp_firstname').value == ''
	|| $('inp_surname').value    == ''
	|| $('inp_email').value      == ''){
		alert ('firstname, surnmame and email address are required fields');
		return false;
	}

	return true;
}

function set_fundraiser(b_on){
	document.getElementById('fundit').style.display = (b_on?'block':'none');
}
