window.addEvent('domready', function() {


	var form = $('Formular');
	var total_overall = $('total_overall');

//	var div_credit_card = $('div_credit_card');
//	var div_transfer = $('div_transfer');
//	var div_bankers_cheque = $('div_bankers_cheque');


	var div_ifla_number = new Fx.Slide('div_ifla_number');

	var div_credit_card = new Fx.Slide('div_credit_card');
	var div_transfer = new Fx.Slide('div_transfer');
	var div_bankers_cheque = new Fx.Slide('div_bankers_cheque');


	var ifla_member_yes = $('ifla_member_yes');
	var ifla_member_no = $('ifla_member_no');

	var credit_card = $('credit_card');
	var transfer = $('transfer');
	var bankers_cheque = $('bankers_cheque');

	window.addEvent('load', function() {

			div_ifla_number.slideOut();

			div_credit_card.slideOut();
			div_transfer.slideOut();
			div_bankers_cheque.slideOut();

	});


	form.addEvent('keypress',function(e){
		var key;

		if(window.event)
		key = window.event.keyCode;     //IE
		else
		key = e.which;     //firefox

		if(key == 13)
		return false;
		else
		return true;
	});

	ifla_member_yes.addEvent('click',function(e){
		e = new Event(e);
		div_ifla_number.slideIn();
	});

	ifla_member_no.addEvent('click',function(e){
		e = new Event(e);
		div_ifla_number.slideOut();
	});


	credit_card.addEvent('click',function(e){
		e = new Event(e);
		div_credit_card.slideIn();
		div_transfer.slideOut();
		div_bankers_cheque.slideOut();
	});

	transfer.addEvent('click',function(e){
		e = new Event(e);
		div_credit_card.slideOut();
		div_transfer.slideIn();
		div_bankers_cheque.slideOut();

	});

	bankers_cheque.addEvent('click',function(e){
		e = new Event(e);
		div_credit_card.slideOut();
		div_transfer.slideOut();
		div_bankers_cheque.slideIn();
	});



/***********************************************************/
/********************** FEE ********************************/
/***********************************************************/

	var ifla = $('ifla');
	var ifla_after = $('ifla_after');
	var total_fee_ifla = $('total_fee_ifla');
	
	var non_ifla = $('non_ifla');
	var non_ifla_after = $('non_ifla_after');
	var total_fee_non_ifla = $('total_fee_non_ifla');

	var student = $('student');
	var student_after = $('student_after');
	var total_fee_student = $('total_fee_student');

	var acc_person = $('acc_person');
	var acc_person_after = $('acc_person_after');
	var total_fee_acc_person = $('total_fee_acc_person');

	var total_fee = $('total_fee');

	var factors = new Array();

/********** FEE ***********/

		factors["ifla"]=350;
		factors["ifla_after"]=400;
		factors["non_ifla"]=410;
		factors["non_ifla_after"]=460;
		factors["student"]=40;
		factors["student_after"]=50;
		factors["acc_person"]=130;
		factors["acc_person_after"]=150;


	ifla.addEvent('change', function(e){
		a = calval(ifla.value,'ifla','ifla');
		b = calval(ifla_after.value,'ifla_after','ifla');
		total_fee_ifla.value=a+b;
		setTotalFee();
		setTotalOverall();
		ifla.fade('0.8');
	});

	ifla.addEvent('focus', function(e){
		ifla.fade('1');
	});

	ifla_after.addEvent('change', function(e){
		a = calval(ifla.value,'ifla','ifla');
		b = calval(ifla_after.value,'ifla_after','ifla');
		total_fee_ifla.value=a+b;
		setTotalFee();
		setTotalOverall();
		ifla_after.fade('0.8');
	});

	ifla_after.addEvent('focus', function(e){
		ifla_after.fade('1');
	});


/***********************************************************/


	non_ifla.addEvent('change', function(e){
		a = calval(non_ifla.value,'non_ifla','non_ifla');
		b = calval(non_ifla_after.value,'non_ifla_after','non_ifla');
		total_fee_non_ifla.value=a+b;
		setTotalFee();
		setTotalOverall();
		non_ifla.fade('0.8');
	});

	non_ifla.addEvent('focus', function(e){
		non_ifla.fade('1');
	});

	non_ifla_after.addEvent('change', function(e){
		a = calval(non_ifla.value,'non_ifla','non_ifla');
		b = calval(non_ifla_after.value,'non_ifla_after','non_ifla');
		total_fee_non_ifla.value=a+b;
		setTotalFee();
		setTotalOverall();
		non_ifla_after.fade('0.8');
	});

	non_ifla_after.addEvent('focus', function(e){
		non_ifla_after.fade('1');
	});


/***********************************************************/


	student.addEvent('change', function(e){
		a = calval(student.value,'student','student');
		b = calval(student_after.value,'student_after','student');
		total_fee_student.value=a+b;
		setTotalFee();
		setTotalOverall();
		student.fade('0.8');
	});

	student.addEvent('focus', function(e){
		student.fade('1');
	});

	student_after.addEvent('change', function(e){
		a = calval(student.value,'student','student');
		b = calval(student_after.value,'student_after','student');
		total_fee_student.value=a+b;
		setTotalFee();
		setTotalOverall();
		student_after.fade('0.8');
	});

	student_after.addEvent('focus', function(e){
		student_after.fade('1');
	});


/***********************************************************/


	acc_person.addEvent('change', function(e){
		a = calval(acc_person.value,'acc_person','acc_person');
		b = calval(acc_person_after.value,'acc_person_after','acc_person');
		total_fee_acc_person.value=a+b;
		setTotalFee();
		setTotalOverall();
		acc_person.fade('0.8');
	});

	acc_person.addEvent('focus', function(e){
		acc_person.fade('1');
	});

	acc_person_after.addEvent('change', function(e){
		a = calval(acc_person.value,'acc_person','acc_person');
		b = calval(acc_person_after.value,'acc_person_after','acc_person');
		total_fee_acc_person.value=a+b;
		setTotalFee();
		setTotalOverall();
		acc_person_after.fade('0.8');
	});

	acc_person_after.addEvent('focus', function(e){
		acc_person_after.fade('1');
	});

/***********************************************************/

	function setTotalFee(){

		if(!total_fee_ifla.value)total_fee_ifla.value=0;
		if(!total_fee_non_ifla.value)total_fee_non_ifla.value=0;
		if(!total_fee_student.value)total_fee_student.value=0;
		if(!total_fee_acc_person.value)total_fee_acc_person.value=0;


		a=(total_fee_ifla.value).toInt();
		b=(total_fee_non_ifla.value).toInt();
		c=(total_fee_student.value).toInt();
		d=(total_fee_acc_person.value).toInt();

		total_fee.value = a+b+c+d;
	}


/***********************************************************/
/********************** Guided Tour ************************/
/***********************************************************/

	var hannover_city_tour_22_10_2009 = $('hannover_city_tour_22_10_2009');
	var hannover_city_tour_23_10_2009 = $('hannover_city_tour_23_10_2009');
	var lower_saxony_tour_23_10_2009 = $('lower_saxony_tour_23_10_2009');

	var total_hannover_city_tour_22_10_2009 = $('total_hannover_city_tour_22_10_2009');
	var total_hannover_city_tour_23_10_2009 = $('total_hannover_city_tour_23_10_2009');
	var total_lower_saxony_tour_23_10_2009 = $('total_lower_saxony_tour_23_10_2009');


	var total_guided_tours = $('total_guided_tours');

		factors["hannover_city_tour_22_10_2009"]=20;
		factors["hannover_city_tour_23_10_2009"]=20;
		factors["lower_saxony_tour_23_10_2009"]=70;


	hannover_city_tour_22_10_2009.addEvent('change', function(e){
		a = calval(hannover_city_tour_22_10_2009.value,'hannover_city_tour_22_10_2009','hannover_city_tour_22_10_2009');
		total_hannover_city_tour_22_10_2009.value=a;
		setTotalGuidedTours();
		setTotalOverall();
		hannover_city_tour_22_10_2009.fade('0.8');
	});

	hannover_city_tour_22_10_2009.addEvent('focus', function(e){
		hannover_city_tour_22_10_2009.fade('1');
	});

	hannover_city_tour_23_10_2009.addEvent('change', function(e){
		a = calval(hannover_city_tour_23_10_2009.value,'hannover_city_tour_23_10_2009','hannover_city_tour_23_10_2009');
		total_hannover_city_tour_23_10_2009.value=a;
		setTotalGuidedTours();
		setTotalOverall();
		hannover_city_tour_23_10_2009.fade('0.8');
	});

	hannover_city_tour_23_10_2009.addEvent('focus', function(e){
		hannover_city_tour_23_10_2009.fade('1');
	});

	lower_saxony_tour_23_10_2009.addEvent('change', function(e){
		a = calval(lower_saxony_tour_23_10_2009.value,'lower_saxony_tour_23_10_2009','lower_saxony_tour_23_10_2009');
		total_lower_saxony_tour_23_10_2009.value=a;
		setTotalGuidedTours();
		setTotalOverall();
		lower_saxony_tour_23_10_2009.fade('0.8');
	});

	lower_saxony_tour_23_10_2009.addEvent('focus', function(e){
		lower_saxony_tour_23_10_2009.fade('1');
	});



/***********************************************************/

	function setTotalGuidedTours(){

		if(!total_hannover_city_tour_22_10_2009.value)total_hannover_city_tour_22_10_2009.value=0;
		if(!total_hannover_city_tour_23_10_2009.value)total_hannover_city_tour_23_10_2009.value=0;
		if(!total_lower_saxony_tour_23_10_2009.value)total_lower_saxony_tour_23_10_2009.value=0;

		a=(total_hannover_city_tour_22_10_2009.value).toInt();
		b=(total_hannover_city_tour_23_10_2009.value).toInt();
		c=(total_lower_saxony_tour_23_10_2009.value).toInt();

		total_guided_tours.value = a+b+c;

		
	}



/***********************************************************/
/********************** Pre Tour ************************/
/***********************************************************/

	var pre_tour_single = $('pre_tour_single');
	var pre_tour_double = $('pre_tour_double');

	var total_pre_tour_single = $('total_pre_tour_single');
	var total_pre_tour_double = $('total_pre_tour_double');


	var total_pre_tour = $('total_pre_tour');

		factors["pre_tour_single"]=135;
		factors["pre_tour_double"]=155;



	pre_tour_single.addEvent('change', function(e){
		a = calval(pre_tour_single.value,'pre_tour_single','pre_tour_single');
		total_pre_tour_single.value=a;
		setTotalPreTour();
		setTotalOverall();
		pre_tour_single.fade('0.8');
	});

	pre_tour_single.addEvent('focus', function(e){
		pre_tour_single.fade('1');
	});

	pre_tour_double.addEvent('change', function(e){
		a = calval(pre_tour_double.value,'pre_tour_double','pre_tour_double');
		total_pre_tour_double.value=a;
		setTotalPreTour();
		setTotalOverall();
		pre_tour_double.fade('0.8');
	});

	pre_tour_double.addEvent('focus', function(e){
		pre_tour_double.fade('1');
	});




/***********************************************************/

	function setTotalPreTour(){

		if(!total_pre_tour_single.value)total_pre_tour_single.value=0;
		if(!total_pre_tour_double.value)total_pre_tour_double.value=0;

		a=(total_pre_tour_single.value).toInt();
		b=(total_pre_tour_double.value).toInt();

		total_pre_tour.value = a+b;
		
	}


/***********************************************************/
/********************** Post Tour ************************/
/***********************************************************/

	var post_tour_single_dorint = $('post_tour_single_dorint');
	var post_tour_double_dorint = $('post_tour_double_dorint');
	var post_tour_single_berolina = $('post_tour_single_berolina');
	var post_tour_double_berolina = $('post_tour_double_berolina');


	var total_post_tour_single_dorint = $('total_post_tour_single_dorint');
	var total_post_tour_double_dorint = $('total_post_tour_double_dorint');
	var total_post_tour_single_berolina = $('total_post_tour_single_berolina');
	var total_post_tour_double_berolina = $('total_post_tour_double_berolina');

	var total_post_tour = $('total_post_tour');

		factors["post_tour_single_dorint"]=81;
		factors["post_tour_double_dorint"]=103;
		factors["post_tour_single_berolina"]=59;
		factors["post_tour_double_berolina"]=69;



	post_tour_single_dorint.addEvent('change', function(e){
		a = calval(post_tour_single_dorint.value,'post_tour_single_dorint','post_tour_single_dorint');
		total_post_tour_single_dorint.value=a;
		setTotalPostTour();
		setTotalOverall();
		post_tour_single_dorint.fade('0.8');
	});

	post_tour_single_dorint.addEvent('focus', function(e){
		post_tour_single_dorint.fade('1');
	});

	post_tour_double_dorint.addEvent('change', function(e){
		a = calval(post_tour_double_dorint.value,'post_tour_double_dorint','post_tour_double_dorint');
		total_post_tour_double_dorint.value=a;
		setTotalPostTour();
		setTotalOverall();
		post_tour_double_dorint.fade('0.8');
	});

	post_tour_double_dorint.addEvent('focus', function(e){
		post_tour_double_dorint.fade('1');
	});


	post_tour_single_berolina.addEvent('change', function(e){
		a = calval(post_tour_single_berolina.value,'post_tour_single_berolina','post_tour_single_berolina');
		total_post_tour_single_berolina.value=a;
		setTotalPostTour();
		setTotalOverall();
		post_tour_single_berolina.fade('0.8');
	});

	post_tour_single_berolina.addEvent('focus', function(e){
		post_tour_single_berolina.fade('1');
	});

	post_tour_double_berolina.addEvent('change', function(e){
		a = calval(post_tour_double_berolina.value,'post_tour_double_berolina','post_tour_double_berolina');
		total_post_tour_double_berolina.value=a;
		setTotalPostTour();
		setTotalOverall();
		post_tour_double_berolina.fade('0.8');
	});

	post_tour_double_berolina.addEvent('focus', function(e){
		post_tour_double_berolina.fade('1');
	});





/***********************************************************/

	function setTotalPostTour(){

		if(!total_post_tour_single_dorint.value)total_post_tour_single_dorint.value=0;
		if(!total_post_tour_double_dorint.value)total_post_tour_double_dorint.value=0;
		if(!total_post_tour_single_berolina.value)total_post_tour_single_berolina.value=0;
		if(!total_post_tour_double_berolina.value)total_post_tour_double_berolina.value=0;


		a=(total_post_tour_single_dorint.value).toInt();
		b=(total_post_tour_double_dorint.value).toInt();
		c=(total_post_tour_single_berolina.value).toInt();
		d=(total_post_tour_double_berolina.value).toInt();

		total_post_tour.value = a+b+c+d;
	}

/***********************************************************/

	function setTotalOverall(){

		if(!total_fee.value)total_fee.value=0;
		if(!total_guided_tours.value)total_guided_tours.value=0;
		if(!total_pre_tour.value)total_pre_tour.value=0;
		if(!total_post_tour.value)total_post_tour.value=0;

		a=(total_fee.value).toInt();
		b=(total_guided_tours.value).toInt();
		c=(total_pre_tour.value).toInt();
		d=(total_post_tour.value).toInt();

		total_overall.value = a+b+c+d;
	}

/***********************************************************/

	function calval(a,factor,target){
		if(!a)a=0;
		a = (a).toInt();
		b=factors[factor];
		return a*b;
	}


});