$(document).ready(function(){
	var branche = {
					'Einzelhandel':		{
											'MasterCard': 		'2,950%',
											'Visa':				'2,950%',
											'Maestro':			'0,950%',
											'VisaElectron':		'2,950%',
											'VPay':				'0,950%',
											'ChinaUnionPay':	'2,950%',
											'JCB':				'2,950%',
											'intervall':		'14-tägig'
					},
					'Gastronomie':		{
											'MasterCard':	 	'2,750%',
											'Visa':				'2,750%',
											'Maestro':			'0,950%',
											'VisaElectron':		'2,750%',
											'VPay':				'0,950%',
											'ChinaUnionPay':	'2,750%',
											'intervall':		'14-tägig'
					},
					'Hotellerie':		{
											'MasterCard':	 	'2,750%',
											'Visa':				'2,750%',
											'Maestro':			'0,950%',
											'VisaElectron':		'2,750%',
											'VPay':				'0,950%',
											'ChinaUnionPay':	'2,750%',
											'JCB':				'2,750%',
											'intervall':		'14-tägig'
					},
					'E-Commerce':		{
											'MasterCard':	 	'3,390%',
											'Visa':				'3,390%',
											'Maestro':			'3,390%',
											'VisaElectron':		'3,390%',
											'VPay':				'nicht möglich',
											'ChinaUnionPay':	'nicht möglich',
											'JCB':				'nicht möglich',
											'intervall':		'monatlich'
					},
					'Versandhandel':	{
											'MasterCard':	 	'3,390%',
											'Visa':				'3,390%',
											'Maestro':			'nicht möglich',
											'VisaElectron':		'3,390%',
											'VPay':				'nicht möglich',
											'ChinaUnionPay':	'nicht möglich',
											'JCB':				'nicht möglich',
											'intervall':		'monatlich'
					}
	};

	if( $("select#branche" ).length ){
		if ($("select#branche").attr('value')) {
			$('.prozentsatz').empty();

			for ( card in branche[$("select#branche").attr('value')] ) {
				$('div[rel="' + card + '"]').append(branche[$("select#branche").attr('value')][card]);
				$('input[rel="' + card + '"]').attr('value', branche[$("select#branche").attr('value')][card]);
			}

			if( ($('#branche').attr('value') == "E-Commerce") || ($('#branche').attr('value') == "Versandhandel") ){
				$('tr.neuebranche').removeClass('neuebranche').addClass('neuebrancheact');

				if (jQuery.browser.msie ) {
					$('tr.neuebrancheact td').css('display', 'block');
				}

				$('a.altebranche').hide();
			} else {
				$('tr.neuebranche').hide();

				if (jQuery.browser.msie ) {
					$('tr.neuebranche td').css('display', 'none');
				}

				$('a.altebranche').show();
			}
		} else {
			$('.prozentsatz').empty();
			$('input.cardwert').attr('value', '');
			$('tr.neuebranche').hide();

			if (jQuery.browser.msie ) {
				$('tr.neuebranche td').css('display', 'none');
			}

			$('a.altebranche').show();
		}

		$('table.terminaltable').css('display', 'block');
	}

	$('select#branche').change(function (){
		if ($("select#branche").attr('value')) {
			$('.prozentsatz').empty();

			for ( card in branche[$("select#branche").attr('value')] ) {
				$('div[rel="' + card + '"]').append(branche[$("select#branche").attr('value')][card]);
				$('input[rel="' + card + '"]').attr('value', branche[$("select#branche").attr('value')][card]);
			}

			if( ($('#branche').attr('value') == "E-Commerce") || ($('#branche').attr('value') == "Versandhandel") ){
				$('tr.neuebranche').removeClass('neuebranche').addClass('neuebrancheact').css("display","");

				if (jQuery.browser.msie ) {
					$('tr.neuebrancheact td').css('display', 'block');
				}

				$('a.altebranche').hide();
			} else {
				$('tr.neuebrancheact').removeClass('neuebrancheact').addClass('neuebranche');

				if (jQuery.browser.msie ) {
					$('tr.neuebranche td').css('display', 'none');
				}

				$('a.altebranche').show();
			}
		} else {
			$('.prozentsatz').empty();
			$('input.cardwert').attr('value', '');
			$('tr.neuebrancheact').removeClass('neuebrancheact').addClass('neuebranche');

			if (jQuery.browser.msie ) {
				$('tr.neuebranche td').css('display', 'none');
			}

			$('a.altebranche').show();
		}

		$('table.terminaltable').css('display', 'block');
	});

	if( ($('#branche').attr('value') == "E-Commerce") || ($('#branche').attr('value') == "Versandhandel") ){
	    $('fieldset#question').show();
		$('div#agbakzeptanz').hide();
		$('div#agbfernabsatz').show();
		$('tr.neuebranche').show();
		$('a.altebranche').hide();
	} else {
		$('div#agbakzeptanz').show();
		$('div#agbfernabsatz').hide();
		$('tr.neuebranche').hide();
		$('a.altebranche').show();
	    $('div.question').hide();
	    $('div.fernterminal').hide();
	}

	if ( $('select#rechtsform').length ) {
		if ( ( $('select#rechtsform').attr('value') == 'Einzelfirma' ) || ( $('select#rechtsform').attr('value') == 'GbR' ) ) {
			$('fieldset#privat').show();
			$('div.geschaeftsfuehrer').hide();
			$('div.privat').show();

			if ( $('input[name="kontrollperson"]').length ) {
				if ( $('input[name=kontrollperson]:checked').val() == "Ja" ) {
					$('fieldset#economicallyentitled').show();
				} else {
					$('fieldset#economicallyentitled').hide();
				}
			}
		} else {
			$('fieldset#privat').hide();
			$('div.geschaeftsfuehrer').show();
			$('div.privat').hide();
			$('fieldset#economicallyentitled').hide();
		}

		if ( ( $('select#rechtsform').attr('value') == 'GmbH' ) || ( $('select#rechtsform').attr('value') == 'AG' ) ) {
			$('div.inhaber').hide();
		} else {
			$('div.inhaber').show();
		}
	}

	$('select#rechtsform').change(function () {
		if ( ( $(this).attr('value') == 'Einzelfirma' ) || ( $(this).attr('value') == 'GbR' ) ) {
			$('fieldset#privat').show();
			$('div.geschaeftsfuehrer').hide();

			if ( $('input[name="kontrollperson"]').length ) {
				if ( $('input[name=kontrollperson]:checked').val() == "Ja" ) {
					$('fieldset#economicallyentitled').show();
				} else {
					$('fieldset#economicallyentitled').hide();
				}
			}
		} else {
			$('fieldset#privat').hide();
			$('fieldset#economicallyentitled').hide();
			$('div.geschaeftsfuehrer').show();
		}

		if ( ( $(this).attr('value') == 'GmbH' ) || ( $(this).attr('value') == 'AG' ) ) {
			$('div.inhaber').hide();
		} else {
			$('div.inhaber').show();
		}
	});

	$('input[name=kontrollperson]').click(function () {
		if ( $('input[name=kontrollperson]:checked').val() == "Ja" ) {
			$('fieldset#economicallyentitled').show();
			$('form input#isee').attr('value', 'is');
		}
		else {
			$('fieldset#economicallyentitled').hide();
			$('form input#isee').attr('value', '');
		}
	});

	if ( $('#iseetwo').length ) {
		if ( $('form input#iseetwo').attr('value') == 'is'){
			$('div#economicallyentitledtwo').show();
			$('#eeedit').attr('value', 'wirtschaftlich Berechtigten löschen');
			$('#eeedit').attr('title', 'Möchten Sie den wirtschaftlich Berechtigten löschen?');
		} else {
			$('div#economicallyentitledtwo').hide();
			$('#eeedit').attr('value', 'wirtschaftlich Berechtigten hinzufügen');
			$('#eeedit').attr('title', 'Möchten Sie den wirtschaftlich Berechtigten hinzufügen?');
			$('div.iseetwo').hide();
		}
	}

	$('#eeedit').click(function () {
		if ( $('form input#iseetwo').attr('value') == 'is'){
			$('div#economicallyentitledtwo').hide();
			$('form input#iseetwo').attr('value', '');
			$('#eeedit').attr('value', 'wirtschaftlich Berechtigten hinzufügen');
			$('#eeedit').attr('title', 'Möchten Sie den wirtschaftlich Berechtigten hinzufügen?');
		} else {
			$('div#economicallyentitledtwo').show();
			$('form input#iseetwo').attr('value', 'is');
//console.debug($('#iseetwo').attr('value'));
			$('#eeedit').attr('value', 'wirtschaftlich Berechtigten löschen');
			$('#eeedit').attr('title', 'Möchten Sie den wirtschaftlich Berechtigten löschen?');
		}
	});

	if ( $('#isee').length ) {
		if ( $('form input#isee').attr('value') == 'is'){
 			$('div.isee').show();
		} else {
			$('div.isee').hide();
		}
	}
});