var Event = {};
/*
 * ajax(url, params, oncomplete);
 * url: controller, action (ex. /user/index/parameters/optional)
 * params: key, value pairs seperated by ? (ex. 'petId=1?petColor=red')
 * onCompleted: the function that's called when ajax is done.
 */
Event.checkDna = function() {
	var fn = $('#adopter_fn').val();
	var ln = $('#adopter_ln').val();
	if (fn != '' && ln != '')
		ajax('/dna/check/ajax/true/fn/' + fn + '/ln/' + ln, null, Event.displayResult);
	else {
		$('#alertdna').html('*Please enter a first and last name');
		$('#alertdna').css('color', 'red');
		$('#alertdna').css('display', 'block');
	}
}
Event.profileCheckDna = function() {
	var fn = $('#adopter_fn').val();
	var ln = $('#adopter_ln').val();
	if (fn != '' && ln != '')
		ajax('/dna/check/ajax/true/fn/' + fn + '/ln/' + ln, null, Event.profileDisplayResult);
	else {
		$('#alertdna').html('*Please enter a first and last name');
		$('#alertdna').css('color', 'red');
		$('#alertdna').css('display', 'block');
	}
}

Event.displayResult = function (obj) {
	try {
		if (obj) {	
			if (obj == '1') {
				$('#alertdna').html('*This person is on the DNA list');
				$('#alertdna').css('color', 'red');
				$('#alertdna').css('display', 'block');
			}
			else {
				$('#alertdna').html('*This person is NOT on the DNA list');
				$('#alertdna').css('color', '#666666');
				$('#alertdna').css('display', 'block');
			}
		}
		else {
			alert('hi');
			$('#alertdna').html();
		}
	}
	catch(e) {
		alert(e.message);
	}
}

Event.profileDisplayResult = function (obj) {
	try {
		if (obj) {	
			if (obj == '1') {
				$('#alertdna').html('*This person is on the DNA list');
				$('#alertdna').css('color', 'red');
				$('#alertdna').css('display', 'block');
			}
			else {
				$('#alertdna').html('*This person is NOT on the DNA list');
				$('#alertdna').css('color', '#666666');
				$('#alertdna').css('display', 'block');
			}
		}
		else {
			alert('hi');
			$('#alertdna').html();
		}
	}
	catch(e) {
		alert(e.message);
	}
}

Event.updateTotal = function (cost) {
	donationElt = $('#donation');
	feeElt = $('#fee');
	totalCostElt = $('#total_paid');
		totalCostElt.val((parseFloat(donationElt.val()) + parseFloat(feeElt.val())));
}


