function allow(flag)
{	
	if (flag == true)
	{
		document.admin_form.edit.disabled = true;
	}
	else
	{
		document.admin_form.edit.disabled = false;
	}
}

function doSubmitFCK(form_name, hidden_field, actionId)
{
	var oForm = document.getElementById(form_name);	

	var oEditor = FCKeditorAPI.GetInstance('FCKeditor1');	
	var content_home = oEditor.EditorDocument.body.innerHTML;

	oForm.edit_content.value = content_home;
		
	document.getElementById(hidden_field).value = actionId;	

	oForm.submit();	

}

function deleteGeneral(do_action, div, codition)
{	
	var oForm = document.admin_form;
	var arr_id = oForm.chk_delete;
	var pars = '&action=delete';
	pars += stringSearch();
	if(codition != null)
		pars += codition;
	var url = "index.php?do=" + do_action;

	if(arr_id != null)
	{
		var length = arr_id.length;

		if(length == null && arr_id.checked)
		{
			pars += '&n_id[]=' + arr_id.value;

			if(confirm('Bạn chắc chắn sẽ xóa?\nĐiều này sẽ xóa hết những thông tin có sử dụng đến dữ liệu này.'))
				ShowDivGeneral(url, pars, div);					
		}
		else
		{
			var flag_check = false;
			for(var i = 0; i < length; i++)
			{
				if(arr_id[i].checked)
				{
					pars += '&n_id[]=' + arr_id[i].value;
					flag_check = true;
				}
			}


			if(flag_check)
			{
				if(confirm('Bạn chắc chắn sẽ xóa?\nĐiều này sẽ xóa hết những thông tin có sử dụng đến dữ liệu này.'))
					ShowDivGeneral(url, pars, div);			
			}
			else
				alert('Xin hãy chọn dữ liệu trước khi xóa');
		}
	}
	else
		alert('Chưa có dữ liệu');
}
function updateGeneral(do_action)
{
		var edit_n_id = $('id_update').value;
		var pars = '&action=edit&edit_n_id='+edit_n_id;
		var url = "index.php?do=" + do_action;
		ShowDivGeneral(url, pars, 'list_array');		
}
function addGeneral(do_action, div, action, codition)
{
	var pars = '&action=' + action;
	if(codition != null)
		pars += codition;
	var url = "index.php?do=" + do_action;
	ShowDivGeneral(url, pars, div);
	return url;
}

function ShowDivGeneral(url, pars, div)
{
	document.getElementById(div).innerHTML="&#272;ang t&#7843;i d&#7919; li&#7879;u...";
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onComplete: function(originalRequest)
			{
				//alert(originalRequest.responseText);
				document.getElementById(div).innerHTML = originalRequest.responseText;
			}

		});
		
		var myGlobalHandlers = {
		onCreate: function(){
			//Element.show(div);
		},
	
		onComplete: function() {
			if(Ajax.activeRequestCount == 0){				
				//Element.hide('div1');
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);
}


function ShowDivGeneralOpener(url, pars, div)
{
	//opener.
	opener.document.getElementById(div).innerHTML="&#272;ang t&#7843;i d&#7919; li&#7879;u...";
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onComplete: function(originalRequest)
			{
				//alert(originalRequest.responseText);
				opener.document.getElementById(div).innerHTML = originalRequest.responseText;
			}

		});
		
		var myGlobalHandlers = {
		onCreate: function(){
			//Element.show(div);
		},
	
		onComplete: function() {
			if(Ajax.activeRequestCount == 0){				
				//Element.hide('div1');
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);
}
function showEditGeneral(n_id, do_action, div)
{
	//flag=false;
	$('id_update').value=n_id;
	var pars = '&action=show&n_id='+n_id;
	var url = "index.php?do=" + do_action;
	ShowDivGeneral(url, pars, div);		
}
function showEditGeneralSubmit(id_update, edit)
{
	var oForm = document.admin_form;
	oForm.n_id.value = id_update;
	oForm.hdd_action.value = edit; 
	oForm.submit();					
}
function searchAll(url_do, div, action, codition, flag_paging)
{
	var n_system_id="", n_course_id="", n_m_subject_id="", n_speciality_id="";	
	if(document.getElementById('n_system_id') != null  
		&& document.getElementById('n_course_id') != null
		&& document.getElementById('n_m_subject_id') != null
		&& document.getElementById('n_speciality_id') != null
	)	
	{

		n_system_id = document.getElementById('n_system_id').value;
		n_course_id = document.getElementById('n_course_id').value;
		n_m_subject_id = document.getElementById('n_m_subject_id').value;
		n_speciality_id = document.getElementById('n_speciality_id').value;
	}
	var str = "";
	if(document.getElementById('n_lesson_id') != null)
	{
		var n_lesson_id = document.getElementById('n_lesson_id').value;
		str += '&n_lesson_id=' + n_lesson_id;
	}
	
	if(document.getElementById('n_term_id') != null)
	{
		var n_term_id = document.getElementById('n_term_id').value;
		str += '&n_term_id=' + n_term_id;
	}

	if(document.getElementById('n_class_id') != null)
	{
		var n_class_id = document.getElementById('n_class_id').value;
		str += '&n_class_id=' + n_class_id;
	}


	var url = "index.php?do=" + url_do;	
	var pars = 'n_system_id=' + n_system_id + '&n_course_id=' + n_course_id + '&n_m_subject_id=' + n_m_subject_id + '&n_speciality_id=' + n_speciality_id + str;
	pars += '&action=' + action;
	if(flag_paging == null)
	{
		pars += '&index_paging=1';
	}
	if(codition != null)
	{
		pars += codition;	
	}
	ShowDivGeneral(url, pars, div);
	return url;
}
function stringSearch()
{
	var n_system_id="", n_course_id="", n_m_subject_id="", n_speciality_id="";	
	if(document.getElementById('n_system_id') != null  
		&& document.getElementById('n_course_id') != null
		&& document.getElementById('n_m_subject_id') != null
		&& document.getElementById('n_speciality_id') != null
	)	
	{

		n_system_id = document.getElementById('n_system_id').value;
		n_course_id = document.getElementById('n_course_id').value;
		n_m_subject_id = document.getElementById('n_m_subject_id').value;
		n_speciality_id = document.getElementById('n_speciality_id').value;
	}
	var str = "";
	if(document.getElementById('n_lesson_id') != null)
	{
		var n_lesson_id = document.getElementById('n_lesson_id').value;
		if(n_lesson_id != "")
			str += '&n_lesson_id=' + n_lesson_id;
	}
	
	if(document.getElementById('n_term_id') != null)
	{
		var n_term_id = document.getElementById('n_term_id').value;
		if(n_term_id != "")
			str += '&n_term_id=' + n_term_id;
	}

	if(document.getElementById('n_class_id') != null)
	{
		var n_class_id = document.getElementById('n_class_id').value;
		if(n_class_id != "")
			str += '&n_class_id=' + n_class_id;
	}

	var pars = str;
	if(n_system_id != "")
		pars += '&n_system_id=' + n_system_id;
	if(n_course_id != "")
		pars += '&n_course_id=' + n_course_id; 
	if(n_m_subject_id != "")
		pars += '&n_m_subject_id=' + n_m_subject_id; 
	if(n_speciality_id != "")
		pars += '&n_speciality_id=' + n_speciality_id; 

	return pars;
}
function validateNameAndFile(id_update)
{
	var n_id = document.getElementById(id_update).value;
	var result = true;
	
	if(n_id == "")
	{
		var arr_s_name = document.getElementsByName("s_name");
		
		var flag_pass = false;
		for(var i=0; i<4; i++)	
		{
			var divErrorS_name = document.getElementById("divErrorS_name_"+i);
			var divErrorS_file = document.getElementById("divErrorS_file_"+i);			
			var s_file = document.getElementById('s_file_'+i).value;
			
			if(trim(arr_s_name[i].value) != "" || trim(s_file) != "")
			{
				flag_pass = true;
				if (trim(arr_s_name[i].value) == "")
				{
					divErrorS_name.innerHTML = showError("B&#7855;t bu&#7897;c nh&#7853;p t&#234;n");
					result = false;
				}
				else
				{
					divErrorS_name.innerHTML = "";
				}
				
				if (trim(s_file) == "")
				{
					divErrorS_file.innerHTML = showError("B&#7855;t bu&#7897;c nh&#7853;p file");
					result = false;
				}
				else
				{
					if(!isFile('s_file_'+i))
					{
						divErrorS_file.innerHTML = showError("Xin h&#227;y ch&#7885;n &#273;&#250;ng file");
						result = false;
						
					}
					else
					{
						divErrorS_file.innerHTML = "";				
					}
				}
			}
		}
		if(!flag_pass)
		{
			var divErrorS_name = document.getElementById("divErrorS_name_0");
			var divErrorS_file = document.getElementById("divErrorS_file_0");			
			divErrorS_name.innerHTML = showError("B&#7855;t bu&#7897;c nh&#7853;p t&#234;n");
			divErrorS_file.innerHTML = showError("B&#7855;t bu&#7897;c nh&#7853;p file");
			result = false;				
		}
	}
	else
	{
		var divErrorS_name = document.getElementById("divErrorS_name");
		var divErrorS_file = document.getElementById("divErrorS_file");			
		var s_name = document.getElementById('s_name').value;
		var s_file = document.getElementById('s_file').value;
		
		if (trim(s_name) == "")
		{
			divErrorS_name.innerHTML = showError("B&#7855;t bu&#7897;c nh&#7853;p t&#234;n");
			result = false;
		}
		else
		{
			divErrorS_name.innerHTML = "";
		}
		if(trim(s_file) != "" && !isFile('s_file'))
		{
			divErrorS_file.innerHTML = showError("Xin h&#227;y ch&#7885;n &#273;&#250;ng file");
			result = false;
			
		}
		else
		{
			divErrorS_file.innerHTML = "";				
		}
		
		
	}

	return result;
}

