function changePass()
{
	var s_old_password = document.getElementById('s_old_password').value;
	var s_password = document.getElementById('s_password').value;
	var s_password_confirm = document.getElementById('s_password_confirm').value;
	var pars = '&s_old_password=' + s_old_password + '&s_password=' + s_password + '&s_password_confirm=' + s_password_confirm;
	load_pages('index.php?do=change_pass&action=save' + pars,'divID');
	
}
function editUser(user_id)
{
	//document.getElementById('user_id').value = user_id;
	document.getElementById('div_add_user').style.display = 'block';
	document.getElementById('div_search').style.display = 'none';
	
	user_id = encodeURIComponent(user_id);
	//load_pages('index.php?do=permission&action=edit&draw=1&user_id=' + user_id,'codition_search');
	var url = 'index.php?do=permission&action=edit&user_id=' + user_id;

	ShowDivGeneral(url, '', 'div_add_user');
	
	var n_user_type_id = document.getElementById('n_user_type_id').value;
	if(n_user_type_id != 6)
	{
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				parameters: '', 
				onComplete: function(originalRequest)
				{
					//alert(originalRequest.responseText);
					load_pages('index.php?do=permission&action=edit&draw=1&user_id=' + user_id,'codition_search');
					load_pages('index.php?do=permission&action=edit&draw=1&user_type=3&user_id=' + user_id,'cod_class');
					if(n_user_type_id == 3)
					{						
						document.getElementById('tbl_display_class').style.display = 'block';	
					}
					else
					{
						document.getElementById('tbl_display_class').style.display = 'none';	
					}
	
				}
	
			});
			
			var myGlobalHandlers = {
			onCreate: function(){
				//Element.show(div);
			},
		
			onComplete: function() {
				if(Ajax.activeRequestCount == 0){				
					//Element.hide('div1');
				}
			}
		};
	
		Ajax.Responders.register(myGlobalHandlers);		
		
	}
	

	//load_pages('index.php?do=permission&action=edit&user_id=' + user_id,'div_add_user');	
	
}

function addUser(flag)
{
	if(flag == 1)
	{

		document.getElementById('div_add_user').style.display = 'block';
		document.getElementById('div_search').style.display = 'none';
		var n_user_type_id = document.getElementById('n_user_type_id').value;
		addGeneral("permission", "div_add_user", "add", "&n_user_type_id="+n_user_type_id);
	}		
	else
	{
		document.getElementById('div_add_user').innerHTML = '';
		document.getElementById('div_add_user').style.display = 'none';		
		document.getElementById('div_search').style.display = 'block';
		load_pages('index.php?do=permission&action=reset','div_add_user');
	}
		
}
function delUser()
{
	var n_speciality_id = document.getElementById('n_speciality_id').value;
	var n_user_type_id = document.getElementById('n_user_type_id').value;

	var codition = '&n_speciality_id=' + n_speciality_id + '&n_user_type_id=' + n_user_type_id;
	deleteGeneral('permission', 'show_user', codition);
}

function permissionUser()
{
	var oForm = document.admin_form;

	var n_speciality_id = "";
	if(document.getElementById('n_speciality_id'))
	{
		n_speciality_id = document.getElementById('n_speciality_id').value;							
	}		
	
	var n_user_type_id = document.getElementById('n_user_type_id').value;
	if(n_user_type_id != 6)
	{
		document.getElementById('div_search').style.display = 'block';
	}
	var arr_user_id_status = oForm.chk_status;

	var pars = 'n_user_type_id=' + n_user_type_id + '&action=update_permission';
	if(n_speciality_id != null)
	{
		pars += '&n_speciality_id=' + n_speciality_id;
	}
	var j = 0;
	var url = "index.php?do=permission";
	if(arr_user_id_status != null)
	{
		var length = arr_user_id_status.length;

		if(length == null)
		{
			pars += '&user_id_' + j + '=' + arr_user_id_status.value;

			if(arr_user_id_status.checked)
			{
				pars += '&status_' + j + '=true';
			}
			else
			{
				pars += '&status_' + j + '=false';
			}
			
			pars += '&count=1';
			
			ShowDivGeneral(url, pars, 'show_user');					
		}
		else
		{
			for(var i=0; i<length; i++)
			{
				pars += '&user_id_' + j + '=' + arr_user_id_status[i].value;

				if(arr_user_id_status[i].checked)
				{
					pars += '&status_' + j + '=true';
				}
				else
				{
					pars += '&status_' + j + '=false';
				}
				
				
				j++;
			}
			pars += '&count=' + length;
			ShowDivGeneral(url, pars, 'show_user');			
		}
	}
	else
		alert('Chưa có dữ liệu');
	
	document.getElementById('div_add_user').innerHTML = '';
	document.getElementById('div_add_user').style.display = 'none';
		
}
function getListUser(flag, action)
{
	var arr_const_user_type = getUserTypeConstant();
	
	var n_user_type_id = document.getElementById('n_user_type_id').value;
	
	if(n_user_type_id == arr_const_user_type["office"] || n_user_type_id == arr_const_user_type["subject"])
	{
		if(flag == 0)
		{			
			setFocus('btn_focus');			

			document.getElementById('tbl_display_class').style.display = 'none';
			document.getElementById('div_add_user').innerHTML = '';	

		}
			
		var url = "index.php?do=permission";	
		var pars = 'n_user_type_id=' + n_user_type_id + '&action=search&index_paging=1';
		ShowDivGeneral(url, pars, 'show_user');
		document.getElementById('codition_search').style.display = 'none';
		document.getElementById('div_search').style.display = 'none';
				
	}
	else
	{
		document.getElementById('div_search').style.display = 'block';
		
		if(flag == 0)
		{
			document.getElementById('div_add_user').innerHTML = '';
			//document.getElementById('div_search').style.display == 'block'
			setFocus('n_system_id');
			
			if(n_user_type_id == "3")
			{
				document.getElementById('tbl_display_class').style.display = 'block';	
			}
			else
			{
				document.getElementById('tbl_display_class').style.display = 'none';	
			}
			
		}
		
		if(flag == 1)
		{
			
			var pars = '&n_user_type_id=' + n_user_type_id;
			
			searchAll('permission','show_user','search',pars);
			//document.getElementById('div_search').style.display == 'block'
			//ShowDivGeneral(url, pars, 'show_user');
			
		}
		document.getElementById('codition_search').style.display = 'block';
		
		var lenght_request = document.getElementById('div_add_user').innerHTML;

		if(lenght_request.length > 50)
		{
			document.getElementById('div_search').style.display = 'none';
		}

		
		
	}
	if(action == "search")
	{
		document.getElementById('div_add_user').innerHTML = '';
		document.getElementById('div_add_user').style.display = 'none';
	}
		
}

function showLesson()
{
	var n_speciality_id = document.getElementById('n_speciality_id').value;
	var url = "index.php?do=admin_programe_study";	
	var pars = 'n_speciality_id=' + n_speciality_id + '&action=search&index_paging=1';
	ShowDivGeneral(url, pars, 'show_lesson');
}

function getUserTypeConstant()
{
	var arr_const_user_type = new Array();
	arr_const_user_type["admin"] = document.getElementById("const_user_type_admin").value;
	arr_const_user_type["teacher"] = document.getElementById("const_user_type_teacher").value;
	arr_const_user_type["student"] = document.getElementById("const_user_type_student").value;
	arr_const_user_type["father"] = document.getElementById("const_user_type_father").value;
	arr_const_user_type["office"] = document.getElementById("const_user_type_office").value;
	arr_const_user_type["subject"] = document.getElementById("const_user_type_subject").value;	
	return arr_const_user_type;
}