
function WIZ_onFocus(input) {
	input.hasFocus = true;
	
	var focusCount = 0;
	var inputs = document.getElementById('wizardIntro').getElementsByTagName('input');
	for (var i=0; inputs.length>i; i++) {
		if (inputs[i].hasFocus) {
			focusCount++;
		}
	}
	
	if (focusCount > 1) {
		input.hasFocus = false;
		input.blur();
	} else {
		if (input.value == 0) {
			input.value = '';
		}
		WIZ_switchChecker(input);
	}
}

function WIZ_onBlur(input) {
	input.hasFocus = false;
	input.value = isNaN(parseInt(input.value)) ? 0 : parseInt(input.value);
	if (input.value < 0) {
		input.value = 0;
	}
	WIZ_checkFields(input);
	WIZ_switchChecker(input);
}

function WIZ_switchChecker(input) {
	// zruseni checkeru
	// 2. 7. 2010 byly odebrany img tagy z templatu
	return;
	var imgs = input.parentNode.getElementsByTagName('img');
	for (var i=0; imgs.length>i; i++) {
		if (imgs[i].className == 'check') {
			imgs[i].style.visibility = input.hasFocus ? 'visible' : 'hidden';
		}
	}
}

function WIZ_checkFields(input, doNotAlert) {
	var inputs = document.getElementById('wizardIntro').getElementsByTagName('input');
	var error = false;
	var newValue = false;
	
	// pocty jednotlivych portu
	var ANALOG = parseInt(document.getElementById('analog').value);
	var ISDN2 = parseInt(document.getElementById('isdn2').value);
	var ASL = parseInt(document.getElementById('asl').value);
	var DSL = parseInt(document.getElementById('dsl').value);
	var ISDN30 = parseInt(document.getElementById('isdn30').value);
	var GSM = parseInt(document.getElementById('gsm').value);
	var UMTS = parseInt(document.getElementById('umts').value);
	var UMTS_VOICE = parseInt(document.getElementById('umtsVoice').value);
	var VOIP_CH = parseInt(document.getElementById('voip_ch').value);
	
	// potrebne ASL upravime podle zadanych ANALOG (analog karta ma v sobe 4 ASL, 4 ANALOG)
	if (ANALOG > 0) {
		ASL -= Math.ceil(ANALOG);
		if (ASL < 0) {
			ASL = 0;
		}
	}
	
	
	// kontrola pri aktivovanem UMTS -> bude pouze mozna Omega
	if (UMTS > 0) {
		var oMax = new Array();
		oMax['analog'] = 48;
		oMax['isdn2'] = 24;
		oMax['asl'] = 48;
		oMax['dsl'] = 48;
		oMax['gsm'] = 48;
		for (var i=0; inputs.length>i; i++) {
			if (inputs[i].name) {
				if (oMax[inputs[i].name] < inputs[i].value) {
//					error = error ? error : AX_postRequest('translate', 'word=AC_ERROR_TOO_MANY_'+inputs[i].name.toUpperCase());
				}
			}
		}
		
		var count = 0;
		count += Math.ceil(ANALOG / 2);
		count += Math.ceil(ISDN2);
		count += Math.ceil(ASL / 2);
		count += Math.ceil(DSL / 2);
		count += Math.ceil(GSM / 2);
		count += Math.ceil(UMTS);
		if (count > 24) {
			error = error ? error : AX_postRequest('translate', 'word=AC_ERROR_CONFIGURATION_NOT_POSSIBLE');
		}
	
	// kontrola pro netstar
	} else {
		var count = 0;
		count += Math.ceil(ANALOG / 4);
		count += Math.ceil(ISDN2 / 8);
		count += Math.ceil(ASL / 8);
		count += Math.ceil(DSL / 8);
		count += Math.ceil(GSM / 4);
		if (count > 53) {
			error = error ? error : AX_postRequest('translate', 'word=AC_ERROR_CONFIGURATION_NOT_POSSIBLE');
		}
	}

	for (var i=0; inputs.length>i; i++) {
		if (inputs[i].name) {
			if (max[inputs[i].name] < inputs[i].value) {
				newValue = max[inputs[i].name];
				error = error ? error : AX_postRequest('translate', 'word=AC_ERROR_TOO_MANY_'+inputs[i].name.toUpperCase());
			}
		}
	}
	
	var count = 0;
	count += ASL;
	count += DSL;
	count += ISDN2;
	count += GSM;
	count += ANALOG;
	if (count > max['ASL_DSL_ISDN2_GSM_ANALOG']) {
		error = error ? error : AX_postRequest('translate', 'word=AC_ERROR_TOO_MANY_ASL_DSL_ISDN2_GSM_ANALOG');
	}

	var count = 0;
	count += ISDN2;
	count += DSL;
	if (count > max['ISDN2_DSL']) {
		error = error ? error : AX_postRequest('translate', 'word=AC_ERROR_TOO_MANY_ISDN2_DSL');
	}
	
	// PRI a UMTS nesmi byt najednou zadany
	if (ISDN30>0 && UMTS>0) {
		error = error ? error : AX_postRequest('translate', 'word=AC_ERROR_PRI_AND_UMTS');
	}
	
	// PRI a UMTS nesmi byt najednou zadany
	if (UMTS>0 && UMTS_VOICE>0) {
		error = error ? error : AX_postRequest('translate', 'word=AC_ERROR_UMTS_DATA_AND_UMTS_VOICE');
	}
	
	// tenke sloty u netstaru
	if (ISDN30>0 && VOIP_CH>0) {
		var countVOIP = Math.ceil(VOIP_CH / 32);
		var countISDN = Math.ceil((ISDN30 - 1) / 4);
		if (countVOIP+countISDN > 3) {
			error = error ? error : AX_postRequest('translate', 'word=AC_ERROR_TOO_MANY_VOIP_ISDN30');
		}
	}
	
	if (error) {
		if (!doNotAlert) {
			alert(error);
		}
		WIZ_focusInput(input.name, newValue ? newValue : '');
		if (newValue) {
			WIZ_checkFields(input, true);
		}
	}
}

function WIZ_focusInput(name, newValue) {
	var inputs = document.getElementById('wizardIntro').getElementsByTagName('input');
	for (var i=0; inputs.length>i; i++) {
		if (inputs[i].name == name) {
			inputs[i].value = newValue;
			globalVar = inputs[i];
			
			// tahle kravina je tu kvuli FF a jeho nefunkcnimu focusu
			setTimeout('globalVar.focus()', 50);
		}
	}
}

function WIZ_openEmailBox() {
	document.getElementById('sendEmail').style.display='block';
	document.getElementById('summaryDiscount').style.display='none';
}
function WIZ_closeEmailBox() {
	document.getElementById('sendEmail').style.display='none';
	document.getElementById('summaryDiscount').style.display='block';
	document.getElementById('senderSummaryForm').reset();
	
}









