/**
 * @author christian kapitzke
 */


function activateFormFields ( id ){

	switch (id) {
	case 'tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_no_membership':
		if ($('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_no_membership').checked) {
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_no_membership').checked = true;
			if ($('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').disabled != true){
				$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').checked = false;
				$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').disabled = true;
			}
			
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild').checked = false;
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').disabled = true;
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').style.backgroundColor = '#E2E8EA';
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').style.backgroundColor = '#E2E8EA';
		}
		break;
	case 'tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw':
		if ($('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').checked){
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_no_membership').checked = false;
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').disabled = false;
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').style.backgroundColor = '#FFFFFF';
		}
		break;
	case 'tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild':
		if ($('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild').checked){
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_no_membership').checked = false;
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').disabled = false;
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').style.backgroundColor = '#FFFFFF';
		}
		break;
	default:
		break;
	}
}

function lockElement( id ){
	switch (id) {
	case 'tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw':
		if (!$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').checked){
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').disabled = true;
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').style.backgroundColor = '#E2E8EA';
		}
		break;
	case 'tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild':
		if (!$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild').checked){
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').disabled = true;
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').style.backgroundColor = '#E2E8EA';
		}
		break;
	default:
		break;
	}
	
}

function checkboxReset(){
	if (!$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').checked && !$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild').checked){
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_no_membership').checked = true;
		if ($('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').disabled != true){
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').checked = false;
			$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').style.backgroundColor = '#E2E8EA';
		}
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild').checked = false;
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').style.backgroundColor = '#E2E8EA';
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').disabled = true;
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').disabled = true;
	}
	
	if (!$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').checked){
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').checked = false;		
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').disabled = true;
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_bsw').style.backgroundColor = '#E2E8EA';
	}
	
	if (!$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild').checked){
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild').checked = false;		
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').disabled = true;
		$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_account_electric_guild').style.backgroundColor = '#E2E8EA';
	}
}

function setactive(step){
	switch (step) {
	case '1':
		$('formHeaderBoxStep_' + step).style.backgroundImage = "url(fileadmin/img/icons/step_1_active.gif)";
		$('formHeaderBoxStep_2').style.backgroundImage = "url(fileadmin/img/icons/step_2_inactive.gif)";
		
		$('step_' + step).style.display = 'block';
		$('step_2').style.display  = 'none';
		break;
	case '2':
		$('formHeaderBoxStep_' + step).style.backgroundImage = "url(fileadmin/img/icons/step_2_active.gif)";
		$('formHeaderBoxStep_1').style.backgroundImage = "url(fileadmin/img/icons/step_1_inactive.gif)";
		$('step_' + step).style.display  = 'block';
		$('step_1').style.display  = 'none';
		break;

	default:
		//alert(step);
		break;
	}
	$('formHeaderBoxStep_' + step).className = 'active';
}


function disableCheckbox(){
	$('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw').disabled = true;
}

function respondToClick(event) {
  var element = event.element();
  activateFormFields(element.id);
}

function init(){
	makeItCount('tx-srfeuserregister-pi1-comments', 250);
}

function charCounter(id, maxlimit, limited){
	if (!$('counter-'+id)){
		$(id).insert({after: '<div id="counter-'+id+'"></div>'});
	}
	if($F(id).length >= maxlimit){
		if(limited){	$(id).value = $F(id).substring(0, maxlimit); }
		$('counter-'+id).addClassName('charcount-limit fieldText');
		$('counter-'+id).removeClassName('charcount-safe fieldText');
	} else {	
		$('counter-'+id).removeClassName('charcount-limit fieldText');
		$('counter-'+id).addClassName('charcount-safe fieldText');
	}
	$('counter-'+id).update( $F(id).length + '/' + maxlimit );	
		
}

function makeItCount(id, maxsize, limited){
	if(limited == null) limited = true;
	if ($(id)){
		Event.observe($(id), 'keyup', function(){charCounter(id, maxsize, limited);}, false);
		Event.observe($(id), 'keydown', function(){charCounter(id, maxsize, limited);}, false);
		charCounter(id,maxsize,limited);
	}
}

/**
 * 
 * Eventobserver
 */


Event.observe( window, 'load', function( event ){
	if($('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw'))
		Event.observe('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_bsw', 'click', respondToClick);
	if($('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild'))
		Event.observe('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_membership_electric_guild', 'click', respondToClick);
	if($('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_no_membership'))
		Event.observe('tx-srfeuserregister-pi1-tx_vtmbswextendsrfeuser_no_membership', 'click', respondToClick);
} );

Event.observe(window, 'load', init);

