function loadEditor(div) {
		if (div.getAttribute('dis') || window.underEdit) {
			return;
		}
        var form_name = div.getAttribute('form');
        var input_name = div.getAttribute('var');
       // alert(form_name + ' ' + input_name);
        if (!input_name || !form_name) return;
        //alert('1');
        var id = document.getElementById('obj_id');
        var content = {
		page: 'editor', 
		form: form_name, 
		input: input_name, 
		obj_id: id.value 
        }
        var bparams = {
		evalDiv: div,
		_eval: true,
		evalFunc: function (data) {
			div.setAttribute('dis', 'true');
			window.underEdit = true;
		}
		
        };
        mutasdbe.bind(content, bparams);
        /*dojo.io.bind({
                transport: 'XMLHTTPTransport',
                url: 'index.php',
                preventCache: true,
                encoding: 'utf-8',
                content: { page: 'editor',  form: form_name, input: input_name, obj_id: id.value},
                load: function(type, evaledObj) {
                	//alert(evaledObj);
                        div.innerHTML = evaledObj;
                        evalscripts(div);
                        div.setAttribute('dis', 'true');
                        window.underEdit = true;
                //      obj.handleValidationResult(evaledObj);
                }
                // load: function(type, evaledObj) { alert(evaledObj); }
        });*/
}

function saveEditorField(formname, varname, obj_id, input, value) {
	var div = lookupDiv(formname, varname);
	var val = '';
	if (!input) {
		var _input = dojo.byId(new String('in_' + formname + '_' + varname));
		if (_input) {
			val = _input.value;
			
		}
		else if (value) {
			val = value;
		}
	}
	else {
		val = input.value;
	}
	var content = {
		page: 'editor', 
		save: '1', 
		form: formname, 
		input: varname, 
		obj_id: obj_id, 
		newval: val
	};
	var bparams = {
		evalDiv: div,
		evalFunc: function (data) {
			div.setAttribute('form', formname);
			div.setAttribute('var', varname);
			div.removeAttribute('dis');
			window.underEdit = false;
		}
	};
	mutasdbe.bind(content, bparams);
	/*
	dojo.io.bind({
		transport: 'XMLHTTPTransport',
		url: 'index.php',
		preventCache: true,
		encoding: 'utf-8',
		content: { page: 'editor', save: '1', form: formname, input: varname, obj_id: obj_id, newval: val},
		load: function(type, evaledObj) {
			//alert(evaledObj);
			
			if (div) {
				
				div.setAttribute('form', formname);
				div.setAttribute('var', varname);
			//	alert('formname: ' + div.getAttribute('form'));
				div.innerHTML = evaledObj;
				div.removeAttribute('dis');
				window.underEdit = false;
				/*div.onclick = function () {
					loadEditor(input);
				}* /
			}
		}
	});*/
}

function saveEditorMissingField(formname, varname, obj_id, input, value) {
	var val = '';
	if (!input) {
		var _input = dojo.byId(new String('in_' + formname + '_' + varname));
		if (_input) {
			val = _input.value;
			
		}
		else if (value) {
			val = value;
		}
	}
	else {
		val = input.value;
	}
	if (varname == 'birth') {
		var year = dojo.byId('birthday_Year').value;
		var month = dojo.byId('birthday_Month').value;
		var day = (dojo.byId('birthday_Day').value < 10) ? '0' + dojo.byId('birthday_Day').value : dojo.byId('birthday_Day').value;
		val =  year + '-' + month + '-' +  day;
	}

	content = { page: 'editor', save: '1', form: formname, input: varname, obj_id: obj_id, newval: val};

	var bparams = {
		url: 'index.php',
		preventCache: true,
		encoding: 'utf-8',
		content: content,
		evalFunc: function(data) {
//			alert(data);return;
			dojo.byId('formdiv').style.display = 'none';
			dojo.byId('thnx').style.display = 'block';
		}
	};
	mutasdbe.bind(content, bparams);
}

function saveUserStatus(obj_id, input) {
	var val = '';
	if (!input) {
		var _input = dojo.byId(new String(obj_id));
		if (_input) {
			val = _input.value;
			
		}
		else if (value) {
			val = value;
		}
	}
	else {
		val = input.value;
	}

	content = { saveStatus: '1', newval: val};

	var bparams = {
		url: 'myprofile',
		preventCache: true,
		encoding: 'utf-8',
		content: content,
		evalFunc: function(data) {
			if (dojo.byId('status_input')) {
				dojo.byId('status_input').style.display = 'none';
				dojo.byId('status_txt').innerHTML = (content.newval) ? content.newval : 'írd be ide mit csinálsz, mire gondolsz';
				dojo.byId('status_txt').style.display = 'inline';
			}
			else if (dojo.byId('status_set')) {
				mutasdbe.showAlert('status_set', { left: 'center', top: 200 });
			}
			mutasdbe.decreaseFontSize('status_txt', 20);
		}
	};
	mutasdbe.bind(content, bparams);
}

function saveCheckboxOtherValue(checkbox_id, chk_id, chk_type_id, maskval, obj_id, user_id) {
	var val = '';
	var _input = dojo.byId(obj_id);
	var _checkbox = dojo.byId(checkbox_id);

	content = { profilChkSetOther: 1, type_id: chk_type_id, chk_id: chk_id, value: _input.value, checked: _checkbox.selected, maskval: maskval };

	var bparams = {
		url: '/myprofile',
		_eval: false,
		evalFunc: function(data) {
		}
	};
	mutasdbe.bind(content, bparams);
}

function lookupDiv(formname, varname) {
	var node_lst = document.getElementsByTagName('div');
	for (var i = 0; i < node_lst.length; i++) {
		var cur = node_lst[i];
		//alert(cur.getAttribute('form'));
		if (cur && cur.getAttribute('form') == formname && cur.getAttribute('var') == varname) {
			return cur;
		}
	}
	return null;
}

function disableEditors() {
	var div = document.getElementById('layProfilUserDetail');
	var node_lst = div.getElementsByTagName('div');
	var cur = null;
	for (var i = 0; i < node_lst.length; i++) {
		alert(node_lst[i]);
		if (node_lst[i]) {
			var form_name = node_lst[i].getAttribute('form');
			var input_name = node_lst[i].getAttribute('var');
			if (!input_name || !form_name) continue;
			
			var id = document.getElementById('obj_id');
			var content = {
		        		page: 'editor', 
		        		cancel: '1', 
		        		form: form_name, 
        				input: input_name, 
        				obj_id: id.value
        			};
        	
        			var bparams = {
        				evalDiv: div,
        				evalFunc: function (data) {
        					if (node_lst[i]) {
        						node_lst[i].setAttribute('form', form_name);
        						node_lst[i].setAttribute('var', input_name);
        						node_lst[i].removeAttribute('dis');
        					}
        				}
        			};
        			mutasdbe.bind(content, bparams);
        	/*
			dojo.io.bind({
				transport: 'XMLHTTPTransport',
				url: 'index.php',
				preventCache: true,
				encoding: 'utf-8',
				content: { page: 'editor', cancel: '1', form: form_name, input: input_name, obj_id: id.value},
				load: function(type, evaledObj) {
				//alert(evaledObj);
				
					if (node_lst[i]) {
					
						node_lst[i].setAttribute('form', form_name);
						node_lst[i].setAttribute('var', input_name);
					//	alert('formname: ' + div.getAttribute('form'));
						node_lst[i].innerHTML = evaledObj;
						
						node_lst[i].removeAttribute('dis');
						/*div.onclick = function () {
							loadEditor(input);
						}* /
					}
				}
			});*/
		}
	}
}


function ajaxEditor(read_obj) {
	var read_id = read_obj.getAttribute('id');
	var name = read_id.substr(9);
	
	var edit_id = new String('ajaxedit_' + name);
	var edit_obj = dojo.byId(edit_id);
	
	mutasdbe.setShowing(read_obj, false);
	mutasdbe.setShowing(edit_obj, true);
	dojo.query("[name=" + name + "]", edit_obj).forEach(function (item) {
		item.focus();
	});
}

function saveAjaxEditor(name, bparams) {
	var edit_id = new String('ajaxedit_' + name);
	var edit_obj = dojo.byId(edit_id);
	var content = mutasdbe.getFormContent(edit_obj);
	var orig_id = new String('ajaxorig_' + name);
	var orig_obj = dojo.byId(orig_id);
	
	var read_id = new String('ajaxread_' + name);
	var read_obj = dojo.byId(read_id);
	
	var content_obj = null;
	dojo.query("[name=" + name + "]", edit_obj).forEach(function (item) {
		content_obj = item;
	});
	
	
	var current_val = content[name];
	var nval = '';
	
	var nodetype = content_obj.nodeName.toLowerCase();
	if (nodetype == 'select') {
		dojo.query("[value=" + current_val + "]", content_obj).forEach(function (item) {
			nval = item.text;
		});
	}
	else nval = current_val;
	if (current_val != orig_obj.value) {
		bp = {
			url: 'myprofile/update',
			evalFunc: function (data) {
				
			}
		};
		
		if (typeof(bparams) != 'undefined') {
			for (var b in bparams) {
				bp[b] = bparams[b];
			}
		}
		
		var ncontent = {};
		ncontent[name.substr(2)] = current_val;
		mutasdbe.bind(ncontent, bp);
	}
	
	read_obj.innerHTML = nval;
	mutasdbe.setShowing(edit_obj, false);
	mutasdbe.setShowing(read_obj, true);
	orig_obj.value = current_val;
}

