function checkSelectedOptionAndEnableDisableElement(fromSelectTagId, value, elementTagId){
	$('#'+fromSelectTagId+'>option:selected').each(function(){
		if ($(this).val()==value) $('#'+elementTagId).removeAttr('disabled');
		else $('#'+elementTagId).attr('disabled','disabled'); 
	})
}

function checkTextField(id, acceptChars, maxLength) {
	var value = $('#' + id).val();
	var newValue = "";
	var changed = false;

	for (i=0; i<value.length; i++) {
		append = true;
		char = value.charAt(i);

		// AcceptChars
		if (acceptChars.length > 0) {
			if (acceptChars.indexOf(char) == -1) {
				append = false;
			}
		}

		// MaxLength
		if (maxLength > 0) {
			if (maxLength <= newValue.length) {
				append = false;
			}
		}
		
		if (append) {
			newValue += char;
		} else {
			changed = true;
		}
	}

	if (changed) {
		$('#' + id).val(newValue);
	}
}

function sendParentForm(node, ajax) {
	if (ajax) {
		var form = $(node).parents('form:first');

		$.ajax({
			url: form.attr('action'),
			data: form.serialize(),
			dataType: "json",
			beforeSend: function() {
				$('body').css('cursor', 'wait'); 
		   	},
		   	complete: function() {
		   		$('body').css('cursor', 'default');
		   	},
		   	success: function(data) {
				processAjaxMessage(data);
			}
		});
	} else {
		$(node).parents('form:first').submit();
	}
}

function processAjaxMessage(data) {
	for (i=0; i<data.commands.length; i++) {
		var command = data.commands[i];

		if (command.command == 'render') {
			// ez a megoldas nem hajtja vegre a javascript-et, mig a kikommentezett igen
			// a home oldalon othergroup eseten okoz problemat hogy a reklam olyan javascriptet ad vissza, amiben van document.write,
			// ez pedig kitorli a teljes oldalt
			document.getElementById(command.container).innerHTML = command.content;
			// $('#' + command.container).html(command.content);
			
			// Popup feldolgozasa
			processPopups(document.getElementById(command.container));
		} else if (command.command == 'jump') {
			if (command.place == 'top')
				window.scroll(0,0);
		} else if (command.command == 'setvalue') {
			$('*[name=' + command.name + ']').val(command.value);
		} else {
			console.log("illegal command: " + command.command);
		}
	}
}
