function PrepareURL(data, name, value)
{
	if (data != '') {data += '&';}
	data += name + '=' + urlencode(value);
	return data;
}

function GetFormItems(form) 
{ 
	if(!document.getElementById(form))
	{
		alert ("CHYBA: Nepodarilo se ziskat seznam poli formulare!");
		return '';
	} 	
	var f = document.getElementById (form); 
	var data = '';
	for (var i = 0; i < f.elements.length; i++) 
	{ 
		obj = f.elements[i];
		switch (obj.type)
		{
			case 'textarea':
			elemclass = obj.className;
			elemid = obj.getAttribute('id');
			if (elemclass != "textarea-general")	
			{								
				var elemvalue = tinyMCE.get(elemid).getContent();
				data = PrepareURL(data, obj.name, elemvalue);
				break;
			}			

			case 'text':
			case 'select-one':
			case 'password':
			case 'hidden':
			case 'file':
			if (obj.name != '')
			{
				data = PrepareURL (data, obj.name, obj.value);
			}
			break;
			
			case 'radio':
			if (obj.name != '')
			if (obj.checked)
			{
				if (data != '') {data += '&';}
				data = PrepareURL (data, obj.name, obj.value);
			}			
			break;

			case 'checkbox':
			if (obj.name != '')
			if (obj.checked)
			{				
				if (data != '') {data += '&';}
				data = PrepareURL (data, obj.name, obj.value);
			}			
			break;
		} 
	}
	for (var key in doubleTables)
	{
		if (key == "toJSONString") continue;
		obj = doubleTables[key];
		if (Object.isFunction(obj)) continue;
		exp = (obj.Export());
		if (data != '' && exp != '') {data += '&';}
		data += exp;
	}	
	
	//alert (data);
	return data;
}

function SetFormItems(form, input)
{
	if(!document.getElementById(form))
	{
		alert ("CHYBA: Nepodarilo se ziskat seznam poli formulare!");
		return false;
	} 	
	var f = document.getElementById (form); 
	for (var i = 0; i < f.elements.length; i++) 
	{ 
		var obj = f.elements[i];
		var name = obj.name;
		switch (obj.type)
		{
			case 'checkbox':			
			name = name.substr(0, name.length-2);

			case 'text':
			case 'radio':			
			case 'textarea':			
			case 'select-one':
			case 'password':
			case 'button':
			case 'file':
			if (document.getElementById(form+'_row_'+name) != null)
			{
				//alert (name);
				if (input.Errors[name] == 1)
				{
					//document.getElementById(form+'_row_'+name).setAttribute("class", "test");
					document.getElementById(form+'_row_'+name).className ="err";
					if (input.ErrorTexts[name] != '')
					{
						document.getElementById(form+'_errtr_'+name).className="visible";
						document.getElementById(form+'_errtd_'+name).innerHTML = input.ErrorTexts[name];
					}
					else
					document.getElementById(form+'_errtr_'+name).className="invisible";				
				}
				else
				{
					document.getElementById(form+'_row_'+name).className="ok";
					document.getElementById(form+'_errtr_'+name).className="invisible";
				}
			}
			break;
		}
	}
	return true;
}

function FillFormItems(form, input)
{
	for (var key in input.Answers)
	{
		if (key == "toJSONString") continue;
		if (key == "id") continue;
		if (Object.isFunction(input.Answers[key])) continue;
		
		var obj = form+'_'+key;
		if (document.getElementById(obj) != null)
		{
			if (document.getElementById(obj).type == 'checkbox')
			{
				document.getElementById(obj).checked = 
					(input.Answers[key] == '0' ? '' : 'checked');
			}
			else
			{
				document.getElementById(obj).value = input.Answers[key];
			}
		}		                    		                  
	}	
	return true;
}

// ----- LOGIN FORM ----- 
function LoginRequest ()
{
	document.getElementById('frmLogin_mysubmit').disabled = true;
	document.getElementById('frmLogin_errtr_coptel_password').className = "invisible";
	http = new HttpConnector();
	query = GetFormItems ('frmLogin');
	hash = http.getQuery("ajax_login.php?" + query, LoginResponse);
	resp['Login'] = hash;	
}

function LoginResponse (http, data)
{	
	//alert (data);
	
	if (resp['Login'] != http.hash) return 0;

	var inp = new Input(data);
	SetFormItems ('frmLogin', inp);

	document.getElementById('frmLogin_mysubmit').disabled = false;

	if (inp.Status)
	{
		window.location.reload();		
	}	
	
	//alert (inp.ToString());
}

// ----- LOGOUT FORM ----- 
function LogoutRequest ()
{
	document.getElementById('frmLogout_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmLogout');
	//hash = http.getQuery("ajax_logout.php", LogoutResponse);
	hash = http.postQuery("ajax_logout.php", query, LogoutResponse);
	resp['Logout'] = hash;	
}

function LogoutResponse (http, data)
{	
	//alert (data);
	
	if (resp['Logout'] != http.hash) return 0;
	document.getElementById('frmLogout_mysubmit').disabled = false;
	
	var inp = new Input(data);
	
	//alert (inp.ToString());
	
	if (inp.Data["Instance_all"] == 1)
		window.location.href = "index.php";
	else
		//window.location.href = "?instance=" + inp.Data["Instance_id"];
		window.location.href = "index.php";
}

// ----- DOC ADD FORM ----- 
function DocAddRequest (id_loading)
{
	document.getElementById('frmDocAdd_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmDocAdd');
	hash = http.postQuery("ajax_docAdd.php", query, DocAddResponse, id_loading);
	resp['DocAdd'] = hash;	
}

function DocAddResponse (http, data)
{	
	if (resp['DocAdd'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmDocAdd', inp);

	//alert (inp.ToString());
	document.getElementById('frmDocAdd_mysubmit').disabled = false;

	if (inp.Status)
	{
		if (inp.Data["parentDoc_id"] != -1) 
		{
			FormDone('frmDocAdd_mysubmit', this.working, 
					'?action=2&doc=' + inp.Data["parentDoc_id"] + "&cmd=0" +
					'&instance=' + inp.Data["Instance_id"]);
		}
		else
		{
			FormDone('frmDocAdd_mysubmit', this.working,
					inp.Data["backlink"]);
		}
	}
	/*
	if (inp.Status)
	{
		if (document.getElementById('frmDocAdd_3_type').checked)
		{
			FormDone ('frmDocAdd_mysubmit', this.working, '?form=DocEdit&id=' + inp.Answers['id']);			
		}
		if (document.getElementById('frmDocAdd_4_type').checked)
		{
			FormDone ('frmDocAdd_mysubmit', this.working, '?');			
		}
		if (document.getElementById('frmDocAdd_5_type').checked)
		{
			FormDone ('frmDocAdd_mysubmit', this.working, '?form=DocEdit&id=' + inp.Answers['id']);			
		}
	}
	*/	
}

// ----- DOC EDIT FORM ----- 
function DocEditRequest (id_loading)
{
	document.getElementById('frmDocEdit_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems('frmDocEdit');	
	hash = http.postQuery("ajax_docEdit.php", query, DocEditResponse, id_loading);
	resp['DocEdit'] = hash;					
}

function DocEditResponse (http, data)
{	
	if (resp['DocEdit'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmDocEdit', inp);

	//alert (inp.ToString());
	document.getElementById('frmDocEdit_mysubmit').disabled = false;

	if (inp.Status)
	{
		if (inp.Data["parentDoc_id"] != -1) 
		{
			FormDone('frmDocEdit_mysubmit', this.working, 
					'?action=2&doc=' + inp.Data["parentDoc_id"] + "&cmd=0" +
					'&instance=' + inp.Data["Instance_id"]);
		}
		else
		{
			FormDone('frmDocEdit_mysubmit', this.working,
					inp.Data["backlink"]);
		}
	}	
}

// ----- DOC INLINE FORM ----- 
/*function DocInlineRequest (id_loading)
{
	document.getElementById('frmDocInline_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmDocInline');	
	hash = http.postQuery("ajax_docInline.php", query, DocInlineResponse, id_loading);
	resp['DocInline'] = hash;					
}

function DocInlineResponse (http, data)
{	
	if (resp['DocInline'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmDocInline', inp);

	//alert (inp.ToString());
	document.getElementById('frmDocInline_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmDocInline_mysubmit', this.working, '?');			
	}	
}*/

// ----- DOC PUBLISH FORM ----- 
function DocPublishRequest (id_loading)
{
	document.getElementById('frmDocPublish_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmDocPublish');	
	hash = http.postQuery("ajax_docPublish.php", query, DocPublishResponse, id_loading);
	resp['DocPublish'] = hash;					
}

function DocPublishResponse (http, data)
{	
	if (resp['DocPublish'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmDocPublish', inp);

	//alert (inp.ToString());
	document.getElementById('frmDocPublish_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmDocPublish_mysubmit', this.working, inp.Data["backlink"]);			
	}	
}

//----- USER REGISTRATION FORM ----- 
function UserRegistrationRequest (id_loading)
{
	document.getElementById('frmUserRegistration_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmUserRegistration');
	hash = http.postQuery("ajax_userRegistration.php", query, UserRegistrationResponse, id_loading);
	resp['UserRegistration'] = hash;				
}

function UserRegistrationResponse (http, data)
{	
	if (resp['UserRegistration'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems('frmUserRegistration', inp);

	//alert (inp.ToString());
	document.getElementById('frmUserRegistration_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone('frmUserRegistration_mysubmit', this.working, '?form=RegDone' +
				'&instance=' + inp.Data["Instance_id"]);			
	}	
}

// ----- PERSON ADD FORM ----- 
function PersonAddRequest (id_loading)
{
	document.getElementById('frmPersonAdd_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmPersonAdd');
	hash = http.postQuery("ajax_personAdd.php", query, PersonAddResponse, id_loading);
	resp['PersonAdd'] = hash;				
}

function PersonAddResponse (http, data)
{	
	if (resp['PersonAdd'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmPersonAdd', inp);

	//alert (inp.ToString());
	document.getElementById('frmPersonAdd_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmPersonAdd_mysubmit', this.working,
				'?form=PersonAdd&instance=' + inp.Data["Instance_id"]);
	}	
}

// ----- PERSON EDIT FORM ----- 
function PersonEditRequest (id_loading)
{
	document.getElementById('frmPersonEdit_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmPersonEdit');
	hash = http.postQuery("ajax_personEdit.php", query, PersonEditResponse, id_loading);
	resp['PersonEdit'] = hash;				
}

function PersonEditResponse (http, data)
{	
	if (resp['PersonEdit'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmPersonEdit', inp);

	//alert (inp.ToString());
	document.getElementById('frmPersonEdit_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmPersonEdit_mysubmit', this.working,
				'?form=PersonEdit&instance=' + inp.Data["Instance_id"]);			
	}	
}

function PersonEditChange (obj, id_loading)
{
	document.getElementById('frmPersonEdit_mysubmit').disabled = true;
	http = new HttpConnector();
	query = 'id='+obj.value;
	hash = http.postQuery("ajax_get_person.php", query, PersonEditChangeResponse, id_loading);	
	resp['PersonEditChange'] = hash;			
}

function PersonEditChangeResponse (http, data)
{	
	if (resp['PersonEditChange'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	FillFormItems ('frmPersonEdit', inp);
			
	//alert (inp.ToString());
	document.getElementById('frmPersonEdit_mysubmit').disabled = false;	
}

// ----- DOCGROUP ADD FORM ----- 
function DocGroupAddRequest (id_loading)
{
	document.getElementById('frmDocGroupAdd_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmDocGroupAdd');
	hash = http.postQuery("ajax_docGroupAdd.php", query, DocGroupAddResponse, id_loading);
	resp['DocGroupAdd'] = hash;			
}

function DocGroupAddResponse (http, data)
{
	if (resp['DocGroupAdd'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmDocGroupAdd', inp);

	//alert (inp.ToString());
	document.getElementById('frmDocGroupAdd_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmDocGroupAdd_mysubmit', this.working, inp.Data["backlink"]);			
	}	
}

// ----- DOCGROUP EDIT FORM ----- 
function DocGroupEditRequest (id_loading)
{
	document.getElementById('frmDocGroupEdit_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmDocGroupEdit');
	hash = http.postQuery("ajax_docGroupEdit.php", query, DocGroupEditResponse, id_loading);
	resp['DocGroupEdit'] = hash;			
}

function DocGroupEditResponse (http, data)
{	
	if (resp['DocGroupEdit'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmDocGroupEdit', inp);

	//alert (inp.ToString());
	document.getElementById('frmDocGroupEdit_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmDocGroupEdit_mysubmit', this.working, inp.Data["backlink"]);			
	}	
}

// ----- USERROLE EDIT FORM ----- 
function UserRoleEditRequest(id_loading)
{
	document.getElementById('frmUserRoleEdit_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmUserRoleEdit');
	hash = http.postQuery("ajax_userRoleEdit.php", query, UserRoleEditResponse, 
			id_loading);
	resp['UserRoleEdit'] = hash;			
}

function UserRoleEditResponse (http, data)
{	
	if (resp['UserRoleEdit'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmUserRoleEdit', inp);

	//alert (inp.ToString());
	document.getElementById('frmUserRoleEdit_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmUserRoleEdit_mysubmit', this.working,
				'?form=UserRoleEdit&cmd=3&instance=' + inp.Data["Instance_id"]);
	}	
}

// ----- USER EDIT FORM ----- 
function UserEditRequest (id_loading)
{
	document.getElementById('frmUserEdit_mysubmit').disabled = true;
	if (document.getElementById('frmUserEdit_delete_mysubmit') != null)
		document.getElementById('frmUserEdit_delete_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmUserEdit');
	hash = http.postQuery("ajax_userEdit.php", query, UserEditResponse, id_loading);
	resp['UserEdit'] = hash;			
}

function UserEditResponse (http, data)
{	
	if (resp['UserEdit'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmUserEdit', inp);

	//alert (inp.ToString());
	document.getElementById('frmUserEdit_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmUserEdit_mysubmit', this.working,
				'?form=UserEdit&cmd=3&instance=' + inp.Data["Instance_id"]);
	}	
}

function UserEditChange (obj, id_loading)
{
	document.getElementById('frmUserEdit_mysubmit').disabled = true;
	if (document.getElementById('frmUserEdit_delete_mysubmit') != null)
		document.getElementById('frmUserEdit_delete_mysubmit').disabled = true;
	http = new HttpConnector();
	query = 'id='+obj.value;
	/*if (obj.multiple){
		for (i=0; i<obj.children.length; i++)
		{
			var option = obj.children[i];
			//if (option.tagName == 'OPTION' && option.selected)
				alert(option.value);
		}
	}*/
	hash = http.postQuery("ajax_get_user_person.php", query, UserEditChangeResponse, id_loading);
	resp['UserEditChange'] = hash;
}

function UserEditChangeResponse (http, data)
{	
	if (resp['UserEditChange'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	FillFormItems ('frmUserEdit', inp);
	
	if (document.getElementById('frmUserEdit_personGroupsTxt') != null)
	{
		document.getElementById('frmUserEdit_personGroupsTxt').innerHTML = 
			inp.Answers['personGroupsTxt'];
	}
	else
	{
		UserPersonGroupsRequest(
			document.getElementById('frmUserEdit_select_id'), http.working);
	}
	//document.getElementById('frmUserEdit_informationTxt').innerHTML = 
	//	inp.Answers['informationTxt'];
	
	//alert (inp.ToString());
	document.getElementById('frmUserEdit_mysubmit').disabled = false;
	if (document.getElementById('frmUserEdit_delete_mysubmit') != null)
	{
		document.getElementById('frmUserEdit_delete_mysubmit').disabled = 
			(inp.Data['canBeDeleted'] == false);
	}
}

function UserPersonGroupsRequest(obj, id_loading)
{
	http = new HttpConnector();
	query = 'id='+obj.value;
	hash = http.postQuery("ajax_get_user_personGroups.php", query, UserPersonGroupsResponse, id_loading);
	resp['UserPersonGroups'] = hash;
}

function UserPersonGroupsResponse(http, data)
{
	if (resp['UserPersonGroups'] != http.hash) return 0;
	//alert (data);
	
	//var inp = new Input(data);
	AjaxListFillCheckboxes(data, 'frmUserEdit_', '_personGroups', 0, 99);
}

function UserDeleteRequest (id_loading)
{
	if (confirm('Skutečně chcete smazat tohoto uživatele?') == false)
	{
		return
	}
	
	document.getElementById('frmUserEdit_mysubmit').disabled = true;
	document.getElementById('frmUserEdit_delete_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems('frmUserEdit');
	hash = http.postQuery("ajax_userDelete.php", query, UserDeleteResponse, id_loading);
	resp['UserDelete'] = hash;
}

function UserDeleteResponse (http, data)
{	
	if (resp['UserDelete'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	FillFormItems ('frmUserEdit', inp);
	
	//alert (inp.ToString());
	document.getElementById('frmUserEdit_mysubmit').disabled = false;
	document.getElementById('frmUserEdit_delete_mysubmit').disabled = 
		(inp.Data['canBeDeleted'] == false);
	
	if (inp.Status)
	{
		FormDone ('frmUserEdit_delete_mysubmit', this.working,
				'?form=UserEdit&cmd=3&instance=' + inp.Data["Instance_id"]);
	}	
}

// ----- USER PASSWD FORM ----- 
function UserPasswdRequest (id_loading)
{
	document.getElementById('frmUserPasswd_mysubmit').disabled = true;	
	http = new HttpConnector();
	query = GetFormItems ('frmUserPasswd');
	hash = http.postQuery("ajax_userPasswd.php", query, UserPasswdResponse, id_loading);
	resp['UserPasswd'] = hash;	
}

function UserPasswdResponse (http, data)
{	
	if (resp['UserPasswd'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmUserPasswd', inp);

	//alert (inp.ToString());
	document.getElementById('frmUserPasswd_mysubmit').disabled = false;	

	if (inp.Status)
	{
		FormDone ('frmUserPasswd_mysubmit', this.working, inp.Data["backlink"]);
	}	
}

// ----- ----------------- ----- 
// ----- AJAX LIST: PERSON -----
function SearchPersonRequest(id, id_loading, query, limit, show, instance_id, media)
{
	http = new HttpConnector();
	http.id = id;
	var ajaxquery = "ajax_search_person.php?q=" + query + "&limit=" + limit + "&show=" + show;
	if (instance_id != null) ajaxquery = ajaxquery + "&Instance_id=" + instance_id;
	hash = http.getQuery(ajaxquery,
		SearchPersonResponse, id_loading);
	resp['SearchPerson'] = hash;
}

function SearchPersonResponse(http, data)
{
	if (resp['SearchPerson'] != http.hash) return 0;

	//alert(data);
	
	AjaxListFill(data, http.id);
}

// ----- AJAX LIST: USER -----
function SearchUserRequest(id, id_loading, query, limit, show, instance_id, media)
{
	http = new HttpConnector();
	http.id = id;
	var ajaxquery = "ajax_search_user.php?q=" + query + "&limit=" + limit + "&show=" + show;
	if (instance_id != null) ajaxquery = ajaxquery + "&Instance_id=" + instance_id;
	hash = http.getQuery(ajaxquery,
		SearchUserResponse, id_loading);
	resp['SearchUser'] = hash;
}

function SearchUserResponse(http, data)
{
	if (resp['SearchUser'] != http.hash) return 0;
	//alert(data);
	AjaxListFill(data, http.id);
	
	if (document.getElementById(http.id).options.length == 1 &&
			document.getElementById('frmUserEdit_mysubmit') != null)
	{
		document.getElementById(http.id).selectedIndex = 0;

		document.getElementById('frmUserEdit_mysubmit').disabled = true;
		if (document.getElementById('frmUserEdit_delete_mysubmit') != null)
			document.getElementById('frmUserEdit_delete_mysubmit').disabled = true;
		query = 'id='+document.getElementById(http.id).
			options[document.getElementById(http.id).selectedIndex].value;
		http = new HttpConnector();
		hash = http.postQuery("ajax_get_user_person.php", query, UserEditChangeResponse, 'SignalUserEdit');
		resp['UserEditChange'] = hash;
	}
}

function SearchUserExtendedRequest(id, id_loading, query, personGroup, docGroup,
	limit, show, instance_id, media)
{
	http = new HttpConnector();
	http.id = id;
	var ajaxquery = "ajax_search_user.php?q=" + query + "&limit=" + limit + "&show=" + show;
	if (instance_id != null) ajaxquery = ajaxquery + "&Instance_id=" + instance_id;
	ajaxquery = ajaxquery + "&personGroup=" + personGroup + "&docGroup=" + docGroup;
	hash = http.getQuery(ajaxquery,
		SearchUserResponse, id_loading);
	resp['SearchUser'] = hash;
}

// ----- AJAX LIST: DOCGROUP -----
function SearchDocGroupRequest(id, id_loading, query, limit, show, instance_id, media)
{
	http = new HttpConnector();
	http.id = id;
	var ajaxquery = "ajax_search_docGroup.php?q=" + query + "&limit=" + limit + "&show=" + show;
	if (instance_id != null) ajaxquery = ajaxquery + "&Instance_id=" + instance_id;
	hash = http.getQuery(ajaxquery,
		SearchDocGroupResponse, id_loading);
	resp['SearchDocGroup'] = hash;
}

function SearchDocGroupResponse(http, data)
{
	if (resp['SearchDocGroup'] != http.hash) return 0;

	AjaxListFill(data, http.id);
}

//----- AJAX LIST: INSTANCE DOCGROUPS FOR MOVE -----
function SearchDocGroupMoveRequest(id, id_loading, instance, secondary)
{
	document.getElementById('frmDocMove_mysubmit').disabled = true;
	document.getElementById('frmDocMove_parentGroup_id').disabled = true;
	http = new HttpConnector();
	http.id = id;
	hash = http.getQuery("ajax_search_docGroup_for_move.php?instance=" + 
		instance + "&secondary=" + secondary,
		SearchDocGroupMoveResponse, id_loading);
	resp['SearchDocGroupMove'] = hash;
}

function SearchDocGroupMoveResponse(http, data)
{
	if (resp['SearchDocGroupMove'] != http.hash) return 0;

	AjaxListFill(data, http.id);
	
	document.getElementById('frmDocMove_mysubmit').disabled = false;
	document.getElementById('frmDocMove_parentGroup_id').disabled = false;
}

// ----- ------------- -----
// ----- SELECTOR: DOC -----
function SearchDocRequest (id, id_loading, query, limit, show, instance_id, media)
{
	http = new HttpConnector();
	http.id = id;	
	var ajaxquery = "ajax_search_doc.php?q=" + query + "&limit=" + limit + "&show=" + show;
	if (instance_id != null) ajaxquery = ajaxquery + "&Instance_id=" + instance_id +
		"&media=" + media;
	hash = http.getQuery(ajaxquery,
		SearchDocResponse, id_loading);
	resp['SearchDoc'] = hash;
}

function SearchDocResponse (http, data)
{
	//alert(data);
	
	if (resp['SearchDoc'] != http.hash) return 0;
	
	SelectorFill(data, http.id);
}

// ----- ----------------- ----- 
// ----- AJAX DOUBLE: DOCPERSON-PERSON ----- 
function AddDocPersonPersonRequest (id, form, id_loading)
{
	http = new HttpConnector();
	http.id = id;
	query = GetFormItems (form);
	hash = http.postQuery("ajax_docPersonPerson.php", query,
		AddDocPersonPersonResponse, id_loading);
	resp['AddDocPersonPerson'] = hash;		
}

function AddDocPersonPersonResponse (http, data)
{	
	if (resp['AddDocPersonPerson'] != http.hash) return 0;

	var inp = new Input(data);
	form = GetFirstSubstring(http.id, "_");
	SetFormItems (form, inp);

	//alert (inp.ToString());

	if (inp.Status)
	{
		doubleTables[http.id].AddItem (
			inp.Data['roles_combo'],
			inp.Answers['roles_combo'],
			inp.Data['roles_ajaxlist'],
			inp.Answers['roles_ajaxlist']
		);
	}
}

// ----- AJAX DOUBLE: USERROLE-PERSON ----- 
function AddUserRolePersonRequest(id, form, id_loading)
{
	http = new HttpConnector();
	http.id = id;
	query = GetFormItems (form);
	hash = http.postQuery("ajax_userRolePerson.php", query,
		AddUserRolePersonResponse, id_loading);
	resp['AddUserRolePerson'] = hash;		
}

function AddUserRolePersonResponse(http, data)
{	
	if (resp['AddUserRolePerson'] != http.hash) return 0;

	var inp = new Input(data);
	form = GetFirstSubstring(http.id, "_");
	SetFormItems (form, inp);

	//alert (inp.ToString());

	if (inp.Status)
	{
		doubleTables[http.id].AddItem (
			inp.Data['rights_ajaxlist'],
			inp.Answers['rights_ajaxlist'],
			inp.Data['rights_combo'],
			inp.Answers['rights_combo']
		);
	}
}

// ----- AJAX DOUBLE: TAGS-TAG ----- 
function AddDocTagsTagRequest(id, form, id_loading)
{
	http = new HttpConnector();
	http.id = id;
	query = GetFormItems (form);
	hash = http.postQuery("ajax_tagsTag.php", query,
		AddDocTagsTagResponse, id_loading);
	resp['AddDocTagsTag'] = hash;
}

function AddDocTagsTagResponse (http, data)
{	
	if (resp['AddDocTagsTag'] != http.hash) return 0;

	var inp = new Input(data);
	form = GetFirstSubstring(http.id, "_");
	SetFormItems (form, inp);

	//alert (inp.ToString());

	if (inp.Status)
	{
		doubleTables[http.id].AddItem (
			inp.Data['tags_combo'],
			inp.Answers['tags_combo'],
			inp.Data['tags_input'],
			inp.Answers['tags_input']
		);
		document.getElementById(form + '_tags_input').value = '';
	}
}

// ----- SEARCH ----- 
function SystemSearch (instance_id)
{	
	data = document.getElementById('frmSystemSearch_search').value;	
	if (data != '')
	{
		data = "?search=" + urlencode(data) + '&instance=' + instance_id;
		//alert (data);
		window.location.href = data;
	}
}

//----- SEARCH -----
function SystemIllustrationSearch (illustration_group, instance_id)
{	
	data = document.getElementById('frmSystemSearch_search').value;	
	if (data != '')
	{
		data = "?search=" + urlencode(data) + "&docGroup=" + illustration_group +
			'&instance=' + instance_id;
		//alert (data);
		window.location.href = data;
	}
}

//----- REGISTRATION ----- 
function RegistrationRequest(instance_id)
{
	data = '?form=UserRegistration&instance=' + instance_id;
    window.location.href = data;
}

//----- FORUM ADD FORM ----- 
function ForumPostAddRequest(id_loading)
{
	document.getElementById('frmForumPostAdd_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmForumPostAdd');	
	hash = http.postQuery("ajax_forumPostAdd.php", query, ForumPostAddResponse, 
			id_loading);
	resp['ForumPostAdd'] = hash;					
}

function ForumPostAddResponse(http, data)
{	
	if (resp['ForumPostAdd'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmForumPostAdd', inp);

	//alert(inp.ToString());
	document.getElementById('frmForumPostAdd_mysubmit').disabled = false;

	if (inp.Status)
	{
		url = "?";
		
		if (inp.Data['forumDoc'] > -1)
		{
			url = '?forumDoc=' + inp.Data['forumDoc'] + '&cmd=0&instance=' +
				inp.Data["Instance_id"];			
		}
		else
		{
			url = inp.Data['backlink'];
		}
		
		FormDone ('frmForumPostAdd_mysubmit', this.working, url);			
	}	
}

// ----- TYPE ----- 
function TypeChange ()
{	
	data = document.getElementById('frmTypeChange_type').value;	
	data = "?type=" + urlencode(data);
	window.location.href = data;
}

//----- AJAX GET DOC GROUP USER ROLES ----- 
function GetDocGroupUserRolesRequest(id_loading)
{
	document.getElementById('frmUserRoleEdit_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmUserRoleEdit');	
	hash = http.postQuery("ajax_get_docGroupUserRole.php", query, 
			GetDocGroupUserRoleResponse, id_loading);
	resp['DocGroupUserRoles'] = hash;					
}

function GetDocGroupUserRoleResponse(http, data)
{	
	if (resp['DocGroupUserRoles'] != http.hash) return 0;
	//alert(data);
		
	AjaxListFillCheckboxes(data, 'frmUserRoleEdit_', '_userRoles', 0, 99);
	
	document.getElementById('frmUserRoleEdit_mysubmit').disabled = false;		
}


//----- DOC MOVE FORM ----- 
function DocMoveRequest(id_loading)
{
	document.getElementById('frmDocMove_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmDocMove');	
	hash = http.postQuery("ajax_docMove.php", query, DocMoveResponse, id_loading);
	resp['DocMove'] = hash;					
}

function DocMoveResponse(http, data)
{	
	if (resp['DocMove'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmDocMove', inp);

	//alert (inp.ToString());
	document.getElementById('frmDocMove_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmDocMove_mysubmit', this.working, inp.Data["backlink"]);			
	}	
}


//----- INSTANCE ADD FORM ----- 
function InstanceAddRequest (id_loading)
{
	document.getElementById('frmInstanceAdd_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmInstanceAdd');
	hash = http.postQuery("ajax_instanceAdd.php", query, InstanceAddResponse, id_loading);
	resp['InstanceAdd'] = hash;				
}

function InstanceAddResponse (http, data)
{	
	if (resp['InstanceAdd'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmInstanceAdd', inp);

	//alert (inp.ToString());
	document.getElementById('frmInstanceAdd_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmInstanceAdd_mysubmit', this.working,
				'?form=InstanceAdmin&instance=' + inp.Data["Instance_id"]);			
	}	
}

// ----- INSTANCE EDIT FORM ----- 
function InstanceEditRequest (id_loading)
{
	document.getElementById('frmInstanceEdit_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmInstanceEdit');
	hash = http.postQuery("ajax_instanceEdit.php", query, InstanceEditResponse, id_loading);
	resp['InstanceEdit'] = hash;				
}

function InstanceEditResponse (http, data)
{	
	if (resp['InstanceEdit'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmInstanceEdit', inp);

	//alert (inp.ToString());
	document.getElementById('frmInstanceEdit_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmInstanceEdit_mysubmit', this.working,
				'?form=InstanceAdmin&instance=' + inp.Data["Instance_id"]);			
	}	
}

//----- INSTANCE EDIT FORM ----- 
function InstanceConfEditRequest (id_loading)
{
	document.getElementById('frmInstanceConfEdit_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmInstanceConfEdit');
	hash = http.postQuery("ajax_confEdit.php", query, InstanceConfEditResponse, id_loading);
	resp['InstanceConfEdit'] = hash;
}

function InstanceConfEditResponse (http, data)
{	
	if (resp['InstanceConfEdit'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmInstanceConfEdit', inp);

	//alert (inp.ToString());
	document.getElementById('frmInstanceConfEdit_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmInstanceConfEdit_mysubmit', this.working,
				'?form=InstanceAdmin&instance=' + inp.Data["Instance_id"]);			
	}
}

function TestSubmitRequest(id_loading)
{
	document.getElementById('frmTestFill_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmTestFill');
	hash = http.postQuery("ajax_testFill.php", query, TestSubmitResponse, id_loading);
	resp['TestSubmit'] = hash;
}

function TestSubmitResponse(http, data)
{
	if (resp['TestSubmit'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmTestFill', inp);
	
	//alert (inp.ToString());
	//document.getElementById('frmTestFill_mysubmit').disabled = false;

	if (inp.Answers["testResult"] != null)
	{
		SetTestItems('frmTestFill', inp)
		alert (inp.Answers["testResult"]);
	}
	
	if (inp.Status)
	{
		
		//FormDone ('frmTestFill_mysubmit', this.working,
		//		'');			
	}
}

function SetTestItems(form, input)
{
	if(!document.getElementById(form))
	{
		return false;
	}
	var f = document.getElementById (form); 
	for (var i = 0; i < f.elements.length; i++) 
	{ 
		var obj = f.elements[i];
		var name = obj.name;
		switch (obj.type)
		{
			case 'checkbox':			
			name = name.substr(0, name.length-2);

			case 'text':
			case 'radio':			
			case 'textarea':			
			case 'select-one':
			case 'password':
			case 'button':
			case 'file':
			if (document.getElementById(form+'_row_'+obj.value+'_'+name) != null)
			{
				var className = "ok";
				//alert (name);
				if (input.Errors[obj.value+'_'+name] == 1)
				{
					//document.getElementById(form+'_row_'+name).setAttribute("class", "test");
					if (obj.checked)
					{
						className ="err2";
					}
					else
					{
						className ="err";
					}
					//if (input.ErrorTexts[name] != '')
					//{
						//document.getElementById(form+'_errtr_'+name).className="visible";
						//document.getElementById(form+'_errtd_'+name).innerHTML = input.ErrorTexts[name];
					//}
					//else
					//document.getElementById(form+'_errtr_'+name).className="invisible";				
				}
				else
				{
					if (obj.checked)
					{
						className="ok2";
					}
					else
					{
						className="ok";
					}
					//document.getElementById(form+'_errtr_'+name).className="invisible";
				}
				document.getElementById(form+'_row_'+obj.value+'_'+name).className = className;
			}
			break;
		}
	}
	return true;
}

//----- PERSON GROUP EDIT FORM ----- 
function PersonGroupEditRequest (id_loading)
{
	document.getElementById('frmPersonGroupEdit_mysubmit').disabled = true;
	document.getElementById('frmPersonGroupEdit_delete_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmPersonGroupEdit');
	hash = http.postQuery("ajax_personGroupEdit.php", query, PersonGroupEditResponse, id_loading);
	resp['PersonGroupEdit'] = hash;			
}

function PersonGroupEditResponse (http, data)
{	
	if (resp['PersonGroupEdit'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	SetFormItems ('frmPersonGroupEdit', inp);

	//alert (inp.ToString());
	document.getElementById('frmPersonGroupEdit_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmPersonGroupEdit_mysubmit', this.working,
				'?form=PersonGroupEdit&cmd=3&instance=' + inp.Data["Instance_id"]);
	}	
}

function PersonGroupEditChange (obj, id_loading)
{
	document.getElementById('frmPersonGroupEdit_mysubmit').disabled = true;
	if (document.getElementById('frmPersonGroupEdit_delete_mysubmit') != null)
		document.getElementById('frmPersonGroupEdit_delete_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmPersonGroupEdit');
	//query = 'id='+obj.value;
	hash = http.postQuery("ajax_get_personGroup.php", query, 
			PersonGroupEditChangeResponse, id_loading);
	resp['PersonGroupEditChange'] = hash;
}

function PersonGroupEditChangeResponse (http, data)
{	
	if (resp['PersonGroupEditChange'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	FillFormItems ('frmPersonGroupEdit', inp);
	
	//alert (inp.ToString());
	
	document.getElementById('frmPersonGroupEdit_membersCount').innerHTML = 
		inp.Answers['membersCount'];
	
	document.getElementById('frmPersonGroupEdit_members').innerHTML = 
		inp.Answers['members'];
	
	document.getElementById('frmPersonGroupEdit_mysubmit').disabled = false;
	if (document.getElementById('frmPersonGroupEdit_delete_mysubmit') != null)
	{
		document.getElementById('frmPersonGroupEdit_delete_mysubmit').disabled = 
			(inp.Data['canBeDeleted'] == false);
	}
}

//----- AJAX LIST: PERSON GROUP -----
function SearchPersonGroupRequest(id, id_loading, query, limit, show, instance_id, media)
{
	http = new HttpConnector();
	http.id = id;
	var ajaxquery = "ajax_search_personGroup.php?q=" + query + "&limit=" + limit + "&show=" + show;
	if (instance_id != null) ajaxquery = ajaxquery + "&Instance_id=" + instance_id;
	hash = http.getQuery(ajaxquery,
		SearchPersonGroupResponse, id_loading);
	resp['SearchPersonGroup'] = hash;
}

function SearchPersonGroupResponse(http, data)
{
	if (resp['SearchPersonGroup'] != http.hash) return 0;

	AjaxListFill(data, http.id);
	
	if (document.getElementById(http.id).options.length == 1)
	{
		document.getElementById(http.id).selectedIndex = 0;

		document.getElementById('frmPersonGroupEdit_mysubmit').disabled = true;
		if (document.getElementById('frmPersonGroupEdit_delete_mysubmit') != null)
			document.getElementById('frmPersonGroupEdit_delete_mysubmit').disabled = true;
		query = 'id='+document.getElementById(http.id).
			options[document.getElementById(http.id).selectedIndex].value;
		http = new HttpConnector();
		hash = http.postQuery("ajax_get_personGroup.php", query, 
			PersonGroupEditChangeResponse, 'SignalPersonGroupEdit');
		resp['PersonGroupEditChange'] = hash;
	}
}

function PersonGroupDeleteRequest (id_loading)
{
	var confirmText = 'Skutečně chcete smazat tuto skupinu?';
	if (document.getElementById('frmPersonGroupEdit_membersCount') != null &&
		document.getElementById('frmPersonGroupEdit_membersCount').innerHTML != "0")
	{
		confirmText = 'Skupina má ' + 
			document.getElementById('frmPersonGroupEdit_membersCount').innerHTML +
			' uživatelů. ' + confirmText;
	}
	if (confirm(confirmText) == false)
	{
		return;
	}
	
	document.getElementById('frmPersonGroupEdit_mysubmit').disabled = true;
	document.getElementById('frmPersonGroupEdit_delete_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems('frmPersonGroupEdit');
	hash = http.postQuery("ajax_personGroupDelete.php", query, 
			PersonGroupDeleteResponse, id_loading);
	resp['PersonGroupDelete'] = hash;
}

function PersonGroupDeleteResponse (http, data)
{	
	if (resp['PersonGroupDelete'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	FillFormItems ('frmPersonGroupEdit', inp);
	
	//alert (inp.ToString());
	document.getElementById('frmPersonGroupEdit_mysubmit').disabled = false;
	document.getElementById('frmPersonGroupEdit_delete_mysubmit').disabled = 
		(inp.Data['canBeDeleted'] == false);
	
	if (inp.Status)
	{
		FormDone ('frmPersonGroupEdit_delete_mysubmit', this.working,
				'?form=PersonGroupEdit&cmd=3&instance=' + inp.Data["Instance_id"]);
	}
}

function PersonGroupAddRequest (id_loading)
{
	document.getElementById('frmPersonGroupAdd_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmPersonGroupAdd');
	hash = http.postQuery("ajax_personGroupAdd.php", query, PersonGroupAddResponse, id_loading);
	resp['PersonGroupAdd'] = hash;			
}

function PersonGroupAddResponse (http, data)
{
	if (resp['PersonGroupAdd'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmPersonGroupAdd', inp);

	//alert (inp.ToString());
	document.getElementById('frmPersonGroupAdd_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone ('frmPersonGroupAdd_mysubmit', this.working, 
				'?form=PersonGroupEdit&cmd=3&instance=' + inp.Data["Instance_id"]);			
	}
}

//----- ASSIGNMENT SOLUTION ADD FORM ----- 
function AssignmentSolutionAddRequest (id_loading)
{
	document.getElementById('frmAssignmentSolutionAdd_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmAssignmentSolutionAdd');
	hash = http.postQuery("ajax_assignmentSolutionAdd.php", query,
			AssignmentSolutionAddResponse, id_loading);
	resp['AssignmentSolutionAdd'] = hash;	
}

function AssignmentSolutionAddResponse (http, data)
{	
	if (resp['AssignmentSolutionAdd'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmAssignmentSolutionAdd', inp);

	//alert (inp.ToString());
	document.getElementById('frmAssignmentSolutionAdd_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone('frmAssignmentSolutionAdd_mysubmit', this.working,
				//inp.Data["backlink"]);
				'?doc=' + inp.Data["assignment_id"] + '&cmd=0&instance=' + 
				inp.Data["Instance_id"]);
	}
}

//----- ASSIGNMENT TEACHER FORM ----- 
function AssignmentPersonGroupChange (id_loading)
{
	document.getElementById('frmAssignmentTeacher_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmAssignmentTeacher');
	hash = http.postQuery("ajax_get_assignments.php", query,
			AssignmentPersonGroupChangeResponse, id_loading);
	resp['AssignmentPersonGroupChange'] = hash;	
}

function AssignmentPersonGroupChangeResponse (http, data)
{
	if (resp['AssignmentPersonGroupChange'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmAssignmentTeacher', inp);

	//alert (inp.ToString());
	document.getElementById('frmAssignmentTeacher_mysubmit').disabled = false;

	if (document.getElementById('frmAssignmentTeacher_assignments') != null)
	{
		document.getElementById('frmAssignmentTeacher_assignments').innerHTML = 
			inp.Answers['assignments'];
	}
}

function AssignmentTeacherRequest (id_loading)
{
	document.getElementById('frmAssignmentTeacher_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmAssignmentTeacher');
	//var obj = document.getElementById('frmAssignmentTeacher_select_id');
	//if ((obj != null) && (obj.multiple)){
		/*for (i=0; i<obj.children.length; i++)
		{
			var option = obj.children[i];
			if (option.tagName == 'OPTION' && option.selected)
				query = query + '&id[]=' + (option.value);
		}*/
	//}
	//alert(query);
	hash = http.postQuery("ajax_assignmentEvaluate.php", query,
			AssignmentTeacherResponse, id_loading);
	resp['AssignmentTeacher'] = hash;	
}

function AssignmentTeacherResponse(http, data)
{
	if (resp['AssignmentTeacher'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmAssignmentTeacher', inp);

	//alert (inp.ToString());
	document.getElementById('frmAssignmentTeacher_mysubmit').disabled = false;

	if (inp.Status)
	{
		FormDone('frmAssignmentTeacher_mysubmit', this.working,
				//inp.Data["backlink"]);
				'?doc=' + inp.Data["assignment_id"] + '&cmd=0&instance=' + 
				inp.Data["Instance_id"]);
	}
}

function AssignmentTeacherAddRequest (id_loading)
{
	document.getElementById('frmAssignmentTeacherAdd_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmAssignmentTeacherAdd');
	var obj = document.getElementById('frmAssignmentTeacherAdd_select_id');
	//if ((obj != null) && (obj.multiple)){
		for (i=0; i<obj.children.length; i++)
		{
			var option = obj.children[i];
			if (option.tagName == 'OPTION' && option.selected)
				query = query + '&id[]=' + (option.value);
		}
	//}
	//alert(query);
	hash = http.postQuery("ajax_assignmentsAdd.php", query,
			AssignmentTeacherAddResponse, id_loading);
	resp['AssignmentTeacherAdd'] = hash;	
}

function AssignmentTeacherAddResponse(http, data)
{
	if (resp['AssignmentTeacherAdd'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmAssignmentTeacherAdd', inp);

	//alert (inp.ToString());
	document.getElementById('frmAssignmentTeacherAdd_mysubmit').disabled = false;

	if (inp.Answers["existing"] != null)
		alert (inp.Answers["existing"]);
	
	if (inp.Status)
	{
		FormDone('frmAssignmentTeacherAdd_mysubmit', this.working,
				//inp.Data["backlink"]);
				'?doc=' + inp.Data["assignment_id"] + '&cmd=0&instance=' + 
				inp.Data["Instance_id"]);
	}
}

function MessageUserEditChange (obj, id_loading)
{
	document.getElementById('frmMessageNew_mysubmit').disabled = true;
	http = new HttpConnector();
	//query = 'id='+obj.value;
	query = '';
	
	var form = document.getElementById('frmMessageNew');
	var oldreceivers = new Array();
	for(i=0; i<form.children.length; i++)
	{
		var elem = form.children[i];
		if (elem.name == 'recipients[]')
			oldreceivers[oldreceivers.length] = elem;
	}
	for(i=0; i<oldreceivers.length; i++)
	{
		form.removeChild(oldreceivers[i]);
	}
	
	for (i=0; i<obj.children.length; i++)
	{
		var option = obj.children[i];
		if (option.tagName == 'OPTION' && option.selected)
		{
			query = query + '&ids[]=' + (option.value);
			
			receiver = document.createElement('input');
			receiver.type = 'hidden';
			receiver.name = 'recipients[]';
			receiver.value = option.value;
			receiver.id = 'receiver_' + option.value;
			document.getElementById('frmMessageNew').appendChild(receiver);
		}
	}
	hash = http.postQuery("ajax_get_user_names.php", query, MessageUserEditChangeResponse, id_loading);
	resp['MessageUserEditChange'] = hash;
}

function MessageUserEditChangeResponse (http, data)
{	
	if (resp['MessageUserEditChange'] != http.hash) return 0;
	//alert (data);
	
	var inp = new Input(data);
	
	document.getElementById('frmMessageNew_recipients').innerHTML = inp.Answers['Names'];
	
	if (inp.Answers['Names'].length > 0)
		document.getElementById('frmMessageNew_mysubmit').disabled = false;
	/*FillFormItems ('frmUserEdit', inp);
	
	if (document.getElementById('frmUserEdit_personGroupsTxt') != null)
	{
		document.getElementById('frmUserEdit_personGroupsTxt').innerHTML = 
			inp.Answers['personGroupsTxt'];
	}
	else
	{
		UserPersonGroupsRequest(
			document.getElementById('frmUserEdit_select_id'), http.working);
	}*/
	//document.getElementById('frmUserEdit_informationTxt').innerHTML = 
	//	inp.Answers['informationTxt'];
	
	//alert (inp.ToString());
	/*document.getElementById('frmUserEdit_mysubmit').disabled = false;
	if (document.getElementById('frmUserEdit_delete_mysubmit') != null)
	{
		document.getElementById('frmUserEdit_delete_mysubmit').disabled = 
			(inp.Data['canBeDeleted'] == false);
	}*/
}

function MessageSendRequest (id_loading)
{
	document.getElementById('frmMessageNew_mysubmit').disabled = true;
	http = new HttpConnector();
	query = GetFormItems ('frmMessageNew');
	
	hash = http.postQuery("ajax_messageSend.php", query,
			MessageSendResponse, id_loading);
	resp['MessageSend'] = hash;	
}

function MessageSendResponse(http, data)
{
	if (resp['MessageSend'] != http.hash) return 0;
	//alert(data);
	
	var inp = new Input(data);
	SetFormItems ('frmMessageNew', inp);

	//alert (inp.ToString());
	document.getElementById('frmMessageNew_mysubmit').disabled = false;
	
	if (inp.Status)
	{
		FormDone('frmMessageNew_mysubmit', this.working,
				//inp.Data["backlink"]);
				'?form=Messages&cmd=3&instance=' + 
				inp.Data["Instance_id"]);
	}
}


