


var iFurnReg = {

	itcFields: $w('tx_ifurn_it_connect tx_ifurn_imoscustomername tx_ifurn_imoscity tx_ifurn_imosdonglefile-0 tx_ifurn_osdconnect1 tx_ifurn_twenty1 tx_ifurn_pinncalc1 tx_ifurn_pinncalc2'),

	itcVals: $w('imosCAD OSD 20-20 Pinncalc'),




	setLevel: function(el) {
		return this.getValue(el);

	},

	setLockedState: function() {
// 		console.log('setLockedState: ',el);
// 		console.log('lvl: ',this.lvl);
// 		var lvl = this.getValue(el);
		if (mode=='edit' && this.lvl == 2) {
			locked = true;
		} else {
			locked = false;
		}
// 		console.debug(this.locked);

// 		this.check_ifurnLvl();
		return locked;
	},

	/**
	 * wird vom radiobutton (onclick) und bei Laden aufgerufen
	 *
	 */
	check_ifurnLvl: function(el) {
//


			if (el) {
				this.lvl = this.getValue(el);
			}

	// 		console.log('check_ifurnLvl: ');
// 			console.log('lvl: ',this.lvl);
// 			console.log('el: ',el);
// 			console.log('locked: ',this.locked);


			if ($('ifurnLvlNormal')) $('ifurnLvlNormal').hide();
			if ($('ifurnLvlPro')) $('ifurnLvlPro').hide();


			if (this.lvl == 2) { // pro
				if ($('tx-srfeuserregister-pi1-tx_ifurn_it_connect')) {
					if (this.locked) {
						$('tx-srfeuserregister-pi1-tx_ifurn_it_connect').disable();
	// 					var theForm = $('tx-srfeuserregister-pi1-fe_users_form');
	// 					var lvlFieldObj = theForm['FE[fe_users][tx_ifurn_ifurn_level]'];
						$('tx-srfeuserregister-pi1-tx_ifurn_ifurn_level').disable();

// 						console.dir($('tx-srfeuserregister-pi1-tx_ifurn_ifurn_level'));

					} else {
						$('tx-srfeuserregister-pi1-tx_ifurn_it_connect').enable();
					}
				}
				if ($('ifurnLvlPro')) $('ifurnLvlPro').show();

				this.check_itconnect($('tx-srfeuserregister-pi1-tx_ifurn_it_connect'));


			} else {
				if ($('tx-srfeuserregister-pi1-tx_ifurn_it_connect')) {
					$('tx-srfeuserregister-pi1-tx_ifurn_it_connect').disable();
				}
				if ($('ifurnLvlNormal')) $('ifurnLvlNormal').show();

				this.itcVals.each(function(itcVal){
					if ($('itconnectFields'+itcVal)) {
						$('itconnectFields'+itcVal).hide();
					}
				});
			}


	},


	check_itconnect: function(el) {

		if($(el) && el.value) {
			theValue = el.value;
		} else {
			theValue = el;
		}

// 	console.log('check_itconnect: ',theValue);
		this.itcVals.each(function(itcVal){
			if ($('itconnectFields'+itcVal)) {
				if (theValue == itcVal) {
					$('itconnectFields'+itcVal).show();
				} else {
					$('itconnectFields'+itcVal).hide();
				}
			}
		});



	},

	check_itConnectEditFields: function(el)  {
		var theValue = this.getValue(el);
// 		console.log('check_itConnectEditFields: ');


		if (this.lvl == 2 && this.locked && mode=='edit') { // pro
// 			lvlField
			this.itcFields.each(function(s){
				if ($('tx-srfeuserregister-pi1-'+s)) {
					$('tx-srfeuserregister-pi1-'+s).disable();
				}
			});
		}

	},

	getValue: function(el) {

		var theValue;
		if($(el) && el.value) {
			// function wurde durch klick ausgelöst (radio element wird als 'this' übergeben)
			theValue = el.value;
		} else {
			// erstmaliges Laden des Formulars (Name der radio-group wird übergeben)
			var theForm = $('tx-srfeuserregister-pi1-fe_users_form');
			$A(theForm[el]).each(
				function(input) {
					if(input.checked) {
						theValue=input.value
					};
				}
			);
		}
		return theValue;
	},





	check_previewItConnect: function(elName) {
// 		if($('itconnectImosFields') && $('itconnectOSDFields')) {
			var theForm = $('tx-srfeuserregister-pi1-fe_users_form');
			var theField = theForm[elName];

			var theValue = $F(theField);

			this.itcVals.each(function(itcVal){
				if ($('itconnectFields'+itcVal)) {
					if (theValue == itcVal) {
						$('itconnectFields'+itcVal).show();
					} else {
						$('itconnectFields'+itcVal).hide();
					}
				}
			});
// 		}
	},

	setItcCreateFields: function() {
// 			console.log('setItcCreateFields: ');
// 		var lvl = this.getValue(el);

		if ($('ifurnLvlNormal')) $('ifurnLvlNormal').hide();
		if ($('ifurnLvlPro')) $('ifurnLvlPro').hide();


		if (this.lvl == 2) { // pro
			if ($('tx-srfeuserregister-pi1-tx_ifurn_it_connect')) $('tx-srfeuserregister-pi1-tx_ifurn_it_connect').enable();
			if ($('ifurnLvlPro')) $('ifurnLvlPro').show();

 			this.showItcFields($('tx-srfeuserregister-pi1-tx_ifurn_it_connect'));

		} else {
			if ($('tx-srfeuserregister-pi1-tx_ifurn_it_connect')) $('tx-srfeuserregister-pi1-tx_ifurn_it_connect').disable();
			if ($('ifurnLvlNormal')) $('ifurnLvlNormal').show();

			this.itcVals.each(function(itcVal){
				if ($('itconnectFields'+itcVal)) {
					$('itconnectFields'+itcVal).hide();
				}
			});


		}
	},

	showItcFields: function(el) {
// 			console.log('showItcFields: ');

		if($(el) && el.value) {
			theValue = el.value;
		} else {
			theValue = el;
		}


		this.itcVals.each(function(itcVal){
			if ($('itconnectFields'+itcVal)) {
				if (theValue == itcVal) {
					$('itconnectFields'+itcVal).show();
				} else {
					$('itconnectFields'+itcVal).hide();
				}
			}
		});



	},


	validateItc: function(form) {
		var OK = true;

		this.setLevel(lvlField);

// 		console.debug('lvl: ',this.lvl);

		if (this.lvl==2) {

			var itcField = form['FE[fe_users][tx_ifurn_it_connect]'];
			var itcVal = $F(itcField);


			var msg = '';

			switch (itcVal) {
				case 'imosCAD':
					checkFields = 'tx_ifurn_imoscustomername tx_ifurn_imoscity tx_ifurn_imosdonglefile-0';
				break;
				case '20-20':
					checkFields = 'tx_ifurn_twenty1';
				break;
				default:
					checkFields = false;
				break;
			}
			if (checkFields) {
				var cfArr = $w(checkFields);
				cfArr.each(function(f) {
					if ($('tx-srfeuserregister-pi1-'+f) && $('tx-srfeuserregister-pi1-'+f).value =='') {
						if (f=='tx_ifurn_imosdonglefile-0') f='tx_ifurn_imosdonglefile';
						msg = msg+'\n'+' '+window[f+'Lbl']+','
						OK = false;
					}
				});
			}

			if (!OK) {
				alert(FEHLERLbl+' \n'+msg);
			}
		}


		return OK;

	}

}

// 		console.debug('mode= ',mode);




var lvlField = 'FE[fe_users][tx_ifurn_ifurn_level]';


if (mode=='edit'  || mode=='create') {
	if (mode=='edit') {
		iFurnReg.lvl = iFurnReg.setLevel(lvlField);
		iFurnReg.locked = iFurnReg.setLockedState();
		iFurnReg.check_ifurnLvl();
		iFurnReg.check_itConnectEditFields();
	} else if (mode=='create') {
		iFurnReg.lvl = iFurnReg.setLevel(lvlField);
		iFurnReg.locked = false;
		iFurnReg.setItcCreateFields();
	}


} else {
	iFurnReg.check_previewItConnect('FE[fe_users][tx_ifurn_it_connect]');

}




