function editLesson(lesson_id, edit)
{
	var oForm = document.admin_form;
	oForm.lesson_id.value = lesson_id;
	oForm.edit.value = edit; 
	oForm.submit();					
}
function delLesson()
{
	var n_speciality_id = document.getElementById('n_speciality_id').value;

	var codition = '&n_speciality_id=' + n_speciality_id;
	deleteGeneral('admin_programe_study', 'show_lesson', codition);
}

function show_teacher_question_lesson_list()
{
	var n_speciality_id = document.getElementById('n_speciality_id').value;
	var url = "index.php?do=teacher_question_lesson_list";	
	var pars = 'n_speciality_id=' + n_speciality_id + '&action=change_url&index_paging=1';
	ShowDivGeneral(url, pars, 'show_lesson');
}

function show_lesson_test()
{
	var n_speciality_id = document.getElementById('n_speciality_id').value;
	var url = "index.php?do=test_lesson_list";	
	var pars = 'n_speciality_id=' + n_speciality_id + '&action=change_url&index_paging=1';
	ShowDivGeneral(url, pars, 'show_lesson');
}

function showAdminDocumentList()
{
	var n_speciality_id = document.getElementById('n_speciality_id').value;
	var url = "index.php?do=admin_document";	
	var pars = 'n_speciality_id=' + n_speciality_id + '&action=search&index_paging=1';
	ShowDivGeneral(url, pars, 'show_lesson');
}
function showDocumentOnline()
{
	var n_speciality_id = document.getElementById('n_speciality_id').value;
	var url = "index.php?do=admin_document_online";	
	var pars = 'n_speciality_id=' + n_speciality_id + '&action=search_documnet_online&index_paging=1';
	ShowDivGeneral(url, pars, 'show_lesson');
}	
function showDocumentList()
{
	var n_speciality_id = document.getElementById('n_speciality_id').value;
	var url = "index.php?do=document_list";	
	var pars = 'n_speciality_id=' + n_speciality_id + '&action=search&index_paging=1';
	ShowDivGeneral(url, pars, 'show_lesson');
}
function showLessonList()
{
	var n_speciality_id = document.getElementById('n_speciality_id').value;

	var url = "index.php?do=lesson_list";	
	var pars = 'n_speciality_id=' + n_speciality_id + '&action=search&index_paging=1';
	ShowDivGeneral(url, pars, 'show_lesson');
}
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 edit_lesson_tpl(case_kind,kind,lesson_id)
{
	var error = 0;
	var ulr="";
	
	if(case_kind == '0')//show new
	{
		//var n_speciality_id = document.getElementById('n_speciality_id').value;
		url = "index.php?do=admin_programe_study&action=case_tpl&kind="+kind;
		var	n_system_id = document.getElementById('n_system_id').value;
		var	n_course_id = document.getElementById('n_course_id').value;
		var	n_m_subject_id = document.getElementById('n_m_subject_id').value;
		var	n_speciality_id = document.getElementById('n_speciality_id').value;
		url = url + '&n_system_id=' + n_system_id;
		url = url +'&n_course_id=' + n_course_id ; 
		url = url +'&n_m_subject_id=' + n_m_subject_id ;
		url = url + '&n_speciality_id=' + n_speciality_id;
		
	}
	else
	if(case_kind == '1')//show edit
	{
		
		url = "index.php?do=admin_programe_study&action=case_tpl&kind="+kind+"&lesson_id="+lesson_id;
	}
	else
	if(case_kind == '2')//update
	{
		
		var name = $('s_lesson_name').value;
		var s_short_name = $('s_short_name').value;
		//var fee = $('fee').value;
		var credit_number = $('n_credit_number').value;
		var hour_number = $('n_hour_number').value;
		var n_speciality_id = document.getElementById('n_speciality_id').value;
		
		if(n_speciality_id == "" || n_speciality_id == null) n_speciality_id = 0;
		 url = "index.php?do=admin_programe_study&action=case_tpl&kind=" + kind;
		 url = url + "&name=" + encodeURIComponent(name);
		 url = url + "&s_short_name=" + encodeURIComponent(s_short_name);
		 //url = url + "&fee=" + encodeURIComponent(fee);
		 url = url + "&credit=" + encodeURIComponent(credit_number);
		 url = url + "&hour=" + encodeURIComponent(hour_number);
		 url = url + "&spec_id=" + n_speciality_id;
		 url = url + "&hidden_lesson=" + $('hidden_lesson_id').value;
		if(name =="" || credit_number=="" || hour_number == "" || s_short_name == "")
		{
			$('show_error_n_speciality_id').style.display = 'none';
			if(name == "")
			{
				$('show_error_s_lesson_name').style.display = 'block';
			}
			else
			{
				$('show_error_s_lesson_name').style.display = 'none';		
			}
			
			if(s_short_name == "")
			{
				$('show_error_s_short_name').style.display = 'block';
			}
			else
			{
				$('show_error_s_short_name').style.display = 'none';		
			}
			
			if(credit_number == "")
			{
				$('show_error_n_credit_number').style.display = 'block';
			}
			else
			{
				$('show_error_n_credit_number').style.display = 'none';		
			}
			
			if(hour_number == "")
			{
				$('show_error_n_hour_number').style.display = 'block';
			}
			else
			{
				$('show_error_n_hour_number').style.display = 'none';		
			}						
			//$('hidden_error').innerHTML = "Ph&#7843;i nh&#7853;p &#273;&#7847;y &#273;&#7911;";
			//alert($('hidden_error').innerHTML);
			error = 1;
			
		}
		else
		{
			if((credit_number < ini_min_tin_chi) || (credit_number > ini_max_tin_chi))
			{
				$('show_error_n_credit_number_invalid').style.display = 'block';	
				error = 1;
			}
			else
			{
				$('show_error_n_credit_number_invalid').style.display = 'none';		
			}

			if((hour_number < ini_min_so_tiet) || (hour_number > ini_max_so_tiet))
			{
				$('show_error_n_hour_number_invalid').style.display = 'block';
				error = 1;
			}
			else
			{
				$('show_error_n_hour_number_invalid').style.display = 'none';		
			}
			
		}
	}
	if(case_kind == '3')//insert
	{
		var name=$('s_lesson_name').value;
		var s_short_name=$('s_short_name').value;
		//var fee=$('fee').value;
		var credit_number=$('n_credit_number').value;
		var hour_number=$('n_hour_number').value;
		var n_speciality_id = document.getElementById('n_speciality_id').value;
		
		if(n_speciality_id == "") n_speciality_id = 0;
		 url = "index.php?do=admin_programe_study&action=case_tpl&kind="+kind;
		 url = url + "&name=" + encodeURIComponent(name);
		 url = url + "&s_short_name=" + encodeURIComponent(s_short_name);
		// url = url + "&fee=" + encodeURIComponent(fee);
		 url = url + "&credit=" + encodeURIComponent(credit_number);
		 url = url + "&hour=" + encodeURIComponent(hour_number);
		 url = url + "&spec_id=" + n_speciality_id;
		if(n_speciality_id == 0)
		{
			//$('hidden_error').innerHTML = "Ph&#7843;i Ch&#7885;n Khoa";
			//alert($('hidden_error').innerHTML);
			$('show_error_n_speciality_id').style.display = 'block';
			
			error = 1;
		}
		else if(name =="" || credit_number=="" || hour_number == "" || s_short_name == "")
		{
			$('show_error_n_speciality_id').style.display = 'none';
			if(name == "")
			{
				$('show_error_s_lesson_name').style.display = 'block';
			}
			else
			{
				$('show_error_s_lesson_name').style.display = 'none';		
			}
			
			if(s_short_name == "")
			{
				$('show_error_s_short_name').style.display = 'block';
			}
			else
			{
				$('show_error_s_short_name').style.display = 'none';		
			}
			
			
			if(credit_number == "")
			{
				$('show_error_n_credit_number').style.display = 'block';
			}
			else
			{
				$('show_error_n_credit_number').style.display = 'none';		
			}
			
			if(hour_number == "")
			{
				$('show_error_n_hour_number').style.display = 'block';
			}
			else
			{
				$('show_error_n_hour_number').style.display = 'none';		
			}			
			
			//$('hidden_error').innerHTML = "Ph&#7843;i nh&#7853;p &#273;&#7847;y &#273;&#7911;";
			//alert($('hidden_error').innerHTML);
			error = 1;
		
		}
		else
		{
			if((credit_number < ini_min_tin_chi) || (credit_number > ini_max_tin_chi))
			{
				$('show_error_n_credit_number_invalid').style.display = 'block';	
				error = 1;
			}
			else
			{
				$('show_error_n_credit_number_invalid').style.display = 'none';		
			}

			if((hour_number < ini_min_so_tiet) || (hour_number > ini_max_so_tiet))
			{
				$('show_error_n_hour_number_invalid').style.display = 'block';
				error = 1;
			}
			else
			{
				$('show_error_n_hour_number_invalid').style.display = 'none';		
			}

		}		
	}
	else
	if(case_kind == '4')
	{
		url = "index.php?do=admin_programe_study&action=case_tpl&kind="+kind;
		var spec_hidden = $('id_spec_hidden').value;
		url=url+"&spec_hidden="+spec_hidden;
	}
	//alert(url);
	
	
	if(error == 0)
	{
		if(case_kind == 0 || case_kind == 1)
		{
			
			ShowDivGeneral(url,"", 'divID');
		
		}
		else
		if(case_kind == 2 || case_kind == 3 || case_kind == 4)
		{
			
			back_lesson_tpl(url);
		}
	}
}
function handleEventKeyNumber(event,id)
{
	 
	 $(id).value=$(id).value.replace(/[^0-9]*/g,'');
}
function back_lesson_tpl(text)
{

	var b=0;
	if(b==0)
	{
					$('divID').innerHTML='&#272;ang l&#7845;y d&#7919; li&#7879;u....';
					var url=text; 
					
			  	
			  		try
					{
						
						new Ajax.Request(url, {
				    	method: 'Post',
				    	onSuccess: function(transport) {
						if (200 == transport.status)
						{
							
							var x = transport.responseText;
							$('divID').innerHTML=x;
							b=1;
							searchAll('admin_programe_study','show_lesson','search', '', true);
						}
						
				    }
					} );
					}catch(e)
					{
						b=2;
					}
		//load_pages('index.php?do=admin_programe_study','case_tpl');
	}
	/*while(b<3)
	{
		if(b==1)
		{
				searchAll('admin_programe_study','show_lesson','search');
				break;
		}
		if(b==2) break;	
	}*/
}
function resetFieldOpenData()
{
	document.getElementById('s_name').value = '';	
	document.getElementById('s_file').value = '';
	document.getElementById('id_update').value = '';	
}

function updateOpenData(n_id)
{
	var n_id_value = document.getElementById(n_id).value;
		
	//var s_name = encodeURIComponent(document.getElementById('s_name').value);
	//var s_file = document.getElementById('s_file').value;
	//var codition = '&s_name=' + s_name + '&s_file=' + s_file;
	var codition = "";
	var action = 'save';
	var div = "divID";
	
	if(n_id_value != "")
	{		
		var s_name = encodeURIComponent(document.getElementById('s_name').value);
		codition += '&s_name=' + s_name;
		codition += "&" + n_id + "=" + n_id_value;
		action = 'edit';
		div = "divID";
	}
	else
	{
		var arr_s_name = document.getElementsByName("s_name");
		for(var i=0; i<4; i++)
		{
			codition += '&s_name[]=' + encodeURIComponent(arr_s_name[i].value);
		}
		
		codition += '&index_paging=1';
	}
	
	addGeneral('admin_open_data',div, action, codition);

}
function updateOpenAccount(div, str_do, n_id)
{
	var s_first_name = encodeURIComponent(document.getElementById('s_first_name').value);
	var s_middle_name = encodeURIComponent(document.getElementById('s_middle_name').value);
	var s_last_name = encodeURIComponent(document.getElementById('s_last_name').value);
	var s_user_id = encodeURIComponent(document.getElementById('s_user_id_assign').value);
	var s_password = encodeURIComponent(document.getElementById('s_password_assign').value);
	var s_password_confirm = encodeURIComponent(document.getElementById('s_password_confirm').value);
	var s_sex = encodeURIComponent(document.getElementById('s_sex').value);
	var dt_birthday = encodeURIComponent(document.getElementById('dt_birthday').value);
	var s_address = encodeURIComponent(document.getElementById('s_address').value);
	var s_email = encodeURIComponent(document.getElementById('s_email').value);
	var security_code = "";
	if(document.getElementById('security_code') != null)
		security_code = encodeURIComponent(document.getElementById('security_code').value);
	var n_user_type_id = "";
	if(document.getElementById('n_user_type_id') != null)
	{
		n_user_type_id = document.getElementById('n_user_type_id').value;
	}
		
		
	var n_speciality_id = "";
	if(document.getElementById('n_speciality_id') != null)
		n_speciality_id = document.getElementById('n_speciality_id').value;
			
	var n_class_id = "";
	if(n_user_type_id == "")
	{
		n_class_id = document.getElementById('n_class_id').value;
	}
	else
	{
		var arr_const_user_type = getUserTypeConstant();		
		if(n_user_type_id == arr_const_user_type["student"] && document.getElementById('n_class_id') != null)
		{
			n_class_id = document.getElementById('n_class_id').value;
		}
	}

	var entry_date = "";
	if(document.getElementById('entry_date'))
		entry_date = encodeURIComponent(document.getElementById('entry_date').value);
	
	var n_type_id = "";
	if(document.getElementById('n_type_id') != null)
	{
		n_type_id = document.getElementById('n_type_id').value;
		
	}

	var codition = '&s_first_name=' + s_first_name 
					+ '&s_middle_name=' + s_middle_name
					+ '&s_last_name=' + s_last_name
					+ '&s_user_id=' + s_user_id
					+ '&s_password=' + s_password
					+ '&s_password_confirm=' + s_password_confirm
					+ '&s_sex=' + s_sex
					+ '&dt_birthday=' + dt_birthday
					+ '&s_address=' + s_address
					+ '&s_email=' + s_email
					+ '&security_code=' + security_code
					+ '&n_user_type_id=' + n_user_type_id
					+ '&n_speciality_id=' + n_speciality_id
					+ '&n_class_id=' + n_class_id
					+ '&entry_date=' + entry_date 
					+ '&n_type_id=' + n_type_id ;
	var action = 'save';

	if(n_id == null)
		n_id = "";
	if(n_id != "")
	{		
		var n_id_value = document.getElementById(n_id).value;
		codition += "&" + n_id + "=" + n_id_value;
		action = 'save';
	}
	else
	{
		codition += '&index_paging=1';
	}
	//var url = addGeneral(str_do, div, action, codition);
	var url = searchAll(str_do, div, action, codition);
	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: '', 
			onComplete: function(originalRequest)
			{
				//alert(originalRequest.responseText);
				if(str_do != "remote_assign")
				{
					getListUser(1);
				}
				
			}

		});
		
		var myGlobalHandlers = {
		onCreate: function(){
			//Element.show(div);
		},
	
		onComplete: function() {
			if(Ajax.activeRequestCount == 0){				
				//Element.hide('div1');
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);	
	
/*	
	if(str_do != "remote_assign")
	{
		getListUser(1);		
	}
*/
}
function missAssign(mod, n_id)
{
	
	var s_name = encodeURIComponent(document.getElementById('s_name').value);
	var dt_birthday = encodeURIComponent(document.getElementById('dt_birthday').value);
	var s_chool_name = encodeURIComponent(document.getElementById('s_chool_name').value);
	var s_address = encodeURIComponent(document.getElementById('s_address').value);
	var s_email = encodeURIComponent(document.getElementById('s_email').value);
	var n_phone = encodeURIComponent(document.getElementById('n_phone').value);
	var s_aptitude = encodeURIComponent(document.getElementById('s_aptitude').value);
	var s_dream = encodeURIComponent(document.getElementById('s_dream').value);
	var s_interest = encodeURIComponent(document.getElementById('s_interest').value);
	var s_describe = encodeURIComponent(document.getElementById('s_describe').value);
	var s_to_speak = encodeURIComponent(document.getElementById('s_to_speak').value);
	
	
	var codition = '&s_name=' + s_name 
					+ '&dt_birthday=' + dt_birthday
					+ '&s_chool_name=' + s_chool_name
					+ '&s_address=' + s_address
					+ '&s_email=' + s_email
					+ '&n_phone=' + n_phone
					+ '&s_aptitude=' + s_aptitude
					+ '&s_dream=' + s_dream
					+ '&s_interest=' + s_interest
					+ '&s_describe=' + s_describe
					+ '&s_to_speak=' + s_to_speak;
					
	var action = 'save';
	var div = "divID";
	var n_id_value = "";
	var str_do = "miss_assign";

	if(mod != "")
	{
		n_id_value = document.getElementById(n_id).value;
		codition += "&" + n_id + "=" + n_id_value;
		
		str_do = "miss_list";
		var s_code = encodeURIComponent(document.getElementById('s_code').value);
		var file0 = encodeURIComponent(document.getElementById('file0').value);
		var file1 = encodeURIComponent(document.getElementById('file1').value);
		var file2 = encodeURIComponent(document.getElementById('file2').value);
		var file3 = encodeURIComponent(document.getElementById('file3').value);
		var file4 = encodeURIComponent(document.getElementById('file4').value);
		codition += '&s_code=' + s_code
					+ '&file0=' + file0
					+ '&file1=' + file1
					+ '&file2=' + file2
					+ '&file3=' + file3
					+ '&file4=' + file4; 
	}
	else
	{
		var s_image = document.getElementById('s_image').value;
		var s_zip = document.getElementById('s_zip').value;
		codition += '&s_image=' + s_image + '&s_zip=' + s_zip;
		
	}
	if(n_id_value == "")
	{
		codition += '&index_paging=1';
	}
	//alert(codition);
	addGeneral(str_do, div, action, codition);

}
function sendInform()
{	
	//var arr_email = document.getElementById('arr_email').value;	
	var textSubject = encodeURIComponent(document.getElementById('textSubject').value);
	var textContent = encodeURIComponent(document.getElementById('textContent').value);
	
	var codition = '&textSubject=' + textSubject + '&textContent=' + textContent;
	
	
	var oForm = document.admin_form;
	var arr_email = oForm.arr_email;

	if(arr_email != null)
	{
		var length = arr_email.length;		
		if(length == null && arr_email.selected)
		{
			codition += '&arr_email[]=' + arr_email.value;
		}
		else
		{
			for(var i = 0; i < length; i++)
			{				
				if(arr_email[i].selected)
				{
					codition += '&arr_email[]=' + arr_email[i].value;
				}
			}
		}
	}	
	
	var action = 'send';
	var div = "divID";
	
	addGeneral('send_inform',div, action, codition);

}
function resetFieldGallery()
{
	document.getElementById('s_name').value = '';	
	document.getElementById('s_file').value = '';
	document.getElementById('id_update').value = '';
}
function updateGallery(n_id)
{
	var n_id_value = document.getElementById(n_id).value;
	
/*	var s_name = encodeURIComponent(document.getElementById('s_name').value);
	var s_file = document.getElementById('s_file').value;
	var codition = '&s_name=' + s_name + '&s_file=' + s_file;
*/	
	var codition = "";
	var action = 'save';
	var div = "divID";
	
	if(n_id_value != "")
	{
		var s_name = encodeURIComponent(document.getElementById('s_name').value);
		codition += '&s_name=' + s_name;
		
		codition += "&" + n_id + "=" + n_id_value;
		action = 'edit';
		div = "divID";
	}
	else
	{
		var arr_s_name = document.getElementsByName("s_name");
		for(var i=0; i<4; i++)
		{
			codition += '&s_name[]=' + encodeURIComponent(arr_s_name[i].value);
		}
		
		codition += '&index_paging=1';
	}
	
	addGeneral('admin_gallery',div, action, codition);

}

function doConvertPoint()
{
	var s_term_name = encodeURIComponent(document.getElementById('s_term_name').value);
	var s_school_year = encodeURIComponent(document.getElementById('s_school_year').value);
	var s_point_file_name = document.getElementById('s_point_file_name').value;
	var codition = '&s_term_name=' + s_term_name + '&s_school_year=' + s_school_year + '&s_point_file_name=' + s_point_file_name;
//	var action = 'save';
	var action = 'convert_point';
	var div = "divID";
	
	var errmsg = "";
	
	//check data input
	if (s_term_name=='')
	{
		errmsg += "Xin chon hoc ky.<br>";
	}
	
	//check data input
	if (s_school_year=='')
	{
		errmsg += "Xin chon nam hoc.<br>";
	}
	
	//check data input
	if (s_point_file_name=='')
	{
		errmsg += "Xin chon tap tin chuyen.<br>";
	}
	
	
	//check and display error
	$('warning').innerHTML  = "";
	
	if (errmsg!="")
	{
		$('warning').innerHTML = errmsg;
		return;
	}
	else
	{
		addGeneral('convert_data',div, action, codition);
	}
}

function doConvertStudent()
{
	var s_student_file_name = document.getElementById('s_student_file_name').value;
	var codition = '&s_student_file_name=' + s_student_file_name;
	var action = 'convert_student';
	var div = "divID";
	
	var errmsg = "";
	
	//check data input
	if (s_student_file_name=='')
	{
		errmsg += "Xin chon tap tin chuyen.<br>";
	}
	
	
	//check and display error
	$('warning').innerHTML  = "";
	
	if (errmsg!="")
	{
		$('warning').innerHTML = errmsg;
		return;
	}
	else
	{
		addGeneral('convert_data',div, action, codition);
	}
}

function doConvertMaster()
{
	var s_master_file_name = document.getElementById('s_master_file_name').value;
	var codition = '&s_master_file_name=' + s_master_file_name;
	var action = 'convert_master';
	var div = "divID";
	
	var errmsg = "";
	
	//check data input
	if (s_master_file_name=='')
	{
		errmsg += "Xin chon tap tin chuyen.<br>";
	}
	
	
	//check and display error
	$('warning').innerHTML  = "";
	
	if (errmsg!="")
	{
		$('warning').innerHTML = errmsg;
		return;
	}
	else
	{
		addGeneral('convert_data',div, action, codition);
	}
}

function resetFieldDocument()
{
	document.getElementById('s_document_name').value = "";	
	document.getElementById('s_user_id').value = "";	
	document.getElementById('s_file_name').value = "";
	document.getElementById('n_document_id').value = "";
}
function updateDocument(n_id, flag)
{
	var n_id_value = document.getElementById(n_id).value;	
	var n_lesson_id = document.getElementById('n_lesson_id').value;
						
	var codition = "";
	var action = 'them';
	var div = "divID";
	
	if(n_id_value != "")
	{		
		var s_document_name = encodeURIComponent(document.getElementById('s_document_name').value);		
		var s_document_short_name = encodeURIComponent(document.getElementById('s_document_short_name').value);		
		var s_user_id = document.getElementById('s_user_id').value;
		var s_file_name = document.getElementById('s_file_name').value;
		
		codition += '&s_document_name=' + s_document_name
						+ '&s_document_short_name=' + s_document_short_name 
						+ '&s_user_id=' + s_user_id
						+ '&s_file_name=' + s_file_name
						+ '&n_lesson_id=' + n_lesson_id;
		
	
		codition += "&" + n_id + "=" + n_id_value;
		action = 'capnhat';
		div = "div_edit_document";
	}
	else
	{
		var arr_s_document_name = document.getElementsByName("s_document_name");
		var arr_s_document_short_name = document.getElementsByName("s_document_short_name");
		var arr_s_user_id = document.getElementsByName("s_user_id");
		//var s_file_name = "";
		codition += '&n_lesson_id=' + n_lesson_id;
		for(var i=0; i<4; i++)
		{
			codition += '&arr_s_document_name[]=' + encodeURIComponent(arr_s_document_name[i].value);
			codition += '&arr_s_document_short_name[]=' + encodeURIComponent(arr_s_document_short_name[i].value);
			codition += '&arr_s_user_id[]=' + encodeURIComponent(arr_s_user_id[i].value);
			//s_file_name = document.getElementById("s_file_name_"+i).value;
			//codition += '&s_file_name_'+i+'=' + s_file_name;
		}
		
		codition += '&index_paging=1';
	}
	
	var str_do = "admin_document_detail";
	if(flag != null)
		str_do = "admin_document_online_detail";

	//var url = searchAll(str_do,div, action, codition, true);
	var url = 'index.php?do=' + str_do + '&action=' + action;
	//document.getElementById(div).innerHTML="&#272;ang t&#7843;i d&#7919; li&#7879;u...";	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: codition, 
			onComplete: function(originalRequest)
			{	
				var result = originalRequest.responseText;
				
				//alert(originalRequest.responseText);
								
				if(result.length > 50)
				{
					document.getElementById(div).innerHTML = result;
					if(document.getElementById("hdd_update_success"))
					{
						var hdd_update_success = document.getElementById("hdd_update_success").value;
						
						if(hdd_update_success == "update_success")
						{
							searchAll(str_do,'divID', '', '', true);
						}
						
					}

				}
				else
				{
					document.getElementById('err_duplicate').innerHTML = result;	
				}
				
				
				
			}

		});
		
		var myGlobalHandlers = {
		onCreate: function(){
			//Element.show(div);
		},
	
		onComplete: function() {
			if(Ajax.activeRequestCount == 0){				
				//Element.hide('div1');
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);				
}
function updateTimeTable(n_id)
{
	var dt_start_date = document.getElementById('dt_start_date').value;
	var dt_end_date = document.getElementById('dt_end_date').value;
	
	var codition = '&dt_start_date=' + dt_start_date + '&dt_end_date=' + dt_end_date;
	var action = 'save';
	var div = "divID";
	if(n_id != "")
	{
		codition += "&n_time_table_id=" + n_id;
	}
	else
	{
		codition += '&index_paging=1';
	}
	
	searchAll('admin_time_table',div, action, codition, true);

}

function editTimeTableDetail(action, n_id)
{
	var s_user_id = encodeURIComponent(document.getElementById('s_user_id').value);
	var n_date = document.getElementById('n_date').value;
	var n_location_id='';
	if(document.getElementById('n_location_id') != null)
		n_location_id = document.getElementById('n_location_id').value;
	var n_time_table_id = document.getElementById('n_time_table_id').value;

	
	var codition = '&s_user_id=' + s_user_id
					+ '&n_date=' + n_date
					+ '&n_time_table_id=' + n_time_table_id
					+ '&n_location_id=' + n_location_id;

	var from_h='', from_m='', to_h='', to_m='';
	if(document.getElementById('from_h') != null)
	{
		from_h = document.getElementById('from_h').value;
		from_m = document.getElementById('from_m').value;
		to_h = document.getElementById('to_h').value;
		to_m = document.getElementById('to_m').value;
		codition += '&from_h=' + from_h 
					+ '&from_m=' + from_m 
					+ '&to_h=' + to_h 
					+ '&to_m=' + to_m;
	}

	var div = "divID";
	if(action != "back")
	{
	if(n_id != null)
	{
		codition += "&n_time_table_detail_id=" + n_id;
	}
	else
	{
		codition += '&index_paging=1';
		}
	}
	addGeneral('admin_time_table_detail',div, action, codition);

}

function updateCalendar(n_id)
{
	//var n_time_table_id = document.getElementById('n_time_table_id').value;

	var n_location_id='';
	if(document.getElementById('n_location_id') != null)
		n_location_id = document.getElementById('n_location_id').value;
	
	var dt_start_date = document.getElementById('dt_start_date').value;
	var dt_end_date = document.getElementById('dt_end_date').value;
	var n_exam_type_id = document.getElementById('n_exam_type_id').value;
	
	var codition = '&n_location_id=' + n_location_id
					+ '&dt_start_date=' + dt_start_date
					+ '&dt_end_date=' + dt_end_date 
					+ '&n_exam_type_id=' + n_exam_type_id;
					
	var action = 'save';
	var div = "divID";
	if(n_id != "")
	{
		codition += "&n_calendar_id=" + n_id;
	}
	else
	{
		codition += '&index_paging=1';
	}
	
	searchAll('admin_calendar',div, action, codition, true);
	
}
function editCalendar(action, codition)
{
	var url = searchAll('admin_calendar', 'divID', action,codition);
	
}
function updateTimetableInfo(n_id)
{
	//var n_time_table_id = document.getElementById('n_time_table_id').value;
	//var hdd_time_table_info = encodeURIComponent(document.getElementById('hdd_time_table_info').value);

	var s_user_id = encodeURIComponent(document.getElementById('s_user_id').value);
	var n_branch_id = document.getElementById('n_branch_id').value;
	
	var n_location_id='';
	if(document.getElementById('n_location_id') != null)
		n_location_id = document.getElementById('n_location_id').value;
	
	var dt_start_date = document.getElementById('dt_start_date').value;
	var dt_end_date = document.getElementById('dt_end_date').value;
	var n_time_table_detail_id = document.getElementById('n_time_table_detail_id').value;
	
	var start_date = document.getElementById('start_date').value;
	var end_date = document.getElementById('end_date').value;	
	
	
	var codition = '&s_user_id=' + s_user_id
					+ '&n_branch_id=' + n_branch_id
					+ '&n_location_id=' + n_location_id
					+ '&dt_start_date=' + dt_start_date
					+ '&dt_end_date=' + dt_end_date 
					+ '&start_date=' + start_date + '&end_date=' + end_date
					//+ '&hdd_time_table_info=' + hdd_time_table_info
					+ '&n_time_table_detail_id=' + n_time_table_detail_id;
					
					
	var action = 'save';
	var div = "divID";
	if(n_id != "")
	{
		codition += "&n_time_table_detail_info_id=" + n_id;
	}
	else
	{
		codition += '&index_paging=1';
	}
	
	addGeneral('admin_time_table_detail_info',div, action, codition);
	
}
function editTimeTableDetailInfo(action, n_id)
{
	var start_date = document.getElementById('start_date').value;
	var end_date = document.getElementById('end_date').value;
	
	var codition = '&start_date=' + start_date + '&end_date=' + end_date;

	var div = "divID";
	if(n_id != "")
	{
		codition += "&n_time_table_detail_info_id=" + n_id;

	}
	else
	{
		codition += '&index_paging=1';
	}
	
	searchAll('admin_time_table_detail_info',div, action, codition, true);

}
function sendAContact()
{
	var textName = encodeURIComponent(document.getElementById('textName').value);
	var textEmail = encodeURIComponent(document.getElementById('textEmail').value);
	var textSubject = encodeURIComponent(document.getElementById('textSubject').value);
	var textContent = encodeURIComponent(document.getElementById('textContent').value);
		
	var codition = '&textName=' + textName 
					+ '&textEmail=' + textEmail
					+ '&textSubject=' + textSubject
					+ '&textContent=' + textContent;
	var action = 'send';
	var div = "divID";
	addGeneral('contact',div, action, codition);

}
function selectLocationForTimeTable()
{
	
	var n_date = document.getElementById('n_date').value;
	var from_h = document.getElementById('from_h').value;
	var from_m = document.getElementById('from_m').value;
	var to_h = document.getElementById('to_h').value;
	var to_m = document.getElementById('to_m').value;
	var n_time_table_id = document.getElementById('n_time_table_id').value;
	var n_time_table_detail_id = document.getElementById('n_time_table_detail_id').value;

	if(n_date != '')
	{
		$('show_error_n_date').style.display = 'none';	
		var url = "index.php?do=admin_time_table_detail";
		url += "&n_date=" + n_date 
				+ "&from_h=" + from_h 
				+ "&from_m=" + from_m 
				+ "&to_h=" + to_h 
				+ "&to_m=" + to_m 		
				+ "&n_time_table_id=" + n_time_table_id 		
				+ "&n_time_table_detail_id=" + n_time_table_detail_id 		
				+ "&action=select_location";	
	
		//load_pages(url, 'div_location_id');
		ShowDivGeneral(url, '', 'div_location_id');
		
	}
	else
	{
		$('show_error_n_date').style.display = 'block';	
	}
}

function updateClass(n_id)
{
	var s_class_name = document.getElementById('s_class_name').value;
	var s_short_name = document.getElementById('s_short_name').value;
	var codition = '&s_class_name=' + s_class_name + '&s_class_short_name=' + s_short_name;
	var action = 'save';
	var div = "divID";
	if(n_id != "")
	{
		codition += "&n_class_id=" + n_id;
	}
	else
	{
		codition += '&index_paging=1';
	}
	
	//searchAll('admin_class',div, action, codition, true);
	var url = "index.php?do=admin_class&action=" + action + stringSearch();

	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: codition, 
			onComplete: function(originalRequest)
			{
				//alert(originalRequest.responseText);
				var result = originalRequest.responseText;
				//alert(result.length);
				if(result.length > 500)
				{
					document.getElementById(div).innerHTML = result;	
				}
				else
				{
					document.getElementById('err_duplicate').innerHTML = result;	
				}
			}

		});
		
		var myGlobalHandlers = {
		onCreate: function(){
			//Element.show(div);
		},
	
		onComplete: function() {
			if(Ajax.activeRequestCount == 0){				
				//Element.hide('div1');
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);		
	
	
	
}
function searchReportLocation()
{
	var n_branch_id = $F('n_branch_id');
	var n_location_id = $F('n_location_id');
	var n_from_number = $F('n_from_number');	
	var n_to_number = $F('n_to_number');	
	var b_status_empty = $F('b_status_empty');
	var b_status_used = $F('b_status_used');
	var dt_datetime = $F('dt_datetime');	
	
	var url = "index.php?do=admin_report_location";	
	var pars = 'n_branch_id=' + n_branch_id 
				+ '&n_location_id=' + n_location_id 
				+ '&n_from_number=' + n_from_number 
				+ '&n_to_number=' + n_to_number 
				+ '&b_status_empty=' + b_status_empty 
				+ '&b_status_used=' + b_status_used 
				+ '&dt_datetime=' + dt_datetime 
				
				+ '&action=search&index_paging=1';

	ShowDivGeneral(url, pars, 'show_report_location');
}
function ShowLocationReport()
{
	if($('n_location_id'))
		setFocus('n_location_id');
	var n_branch_id = document.getElementById('n_branch_id').value;

	var url = "index.php?do=admin_report_location";	
	url += '&n_branch_id=' + n_branch_id + '&action=select_location';
	load_pages(url, 'div_location_id');
}
function arisePeriod(n_time_table_id)
{

	var url = "index.php?do=admin_time_table_detail_info";	
	var codition = 'n_time_table_id=' + n_time_table_id + '&action=arise_period';
	disablePage();
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: codition, 
			onComplete: function(originalRequest)
			{
				//document.getElementById('div_temp').innerHTML = originalRequest.responseText;
				//alert(originalRequest.responseText);				
				alert('Xong');
				enablePage();
			}

		});
		
		var myGlobalHandlers = {
		onCreate: function(){
			//Element.show(div);
		},
	
		onComplete: function() {
			if(Ajax.activeRequestCount == 0){				
				//Element.hide('div1');
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);				
}
function selectSearchAttendance()
{
	if(document.getElementById('btnEnter') != null)
		document.getElementById('btnEnter').disabled = 'disabled';
	var url = "index.php?do=search_attendance";
	openChild(url, 'win2');

}
function selectedFromSearchAttendance(n_time_table_detail_info_id, s_lesson_name, s_term_name, s_location_name, s_first_name, s_middle_name, s_last_name, n_date, dt_start_date, dt_end_date, n_speciality_id)
{
	var oForm = opener.document.admin_form;
	
	if(oForm.n_time_table_id)
		oForm.n_time_table_id.value = n_time_table_detail_info_id;

	if(oForm.n_speciality_id)
		oForm.n_speciality_id.value = n_speciality_id;

	if(oForm.dt_input)
		oForm.dt_input.value = dt_start_date;

	var n_date_format = (n_date==8)?"CN":n_date;

	opener.document.getElementById('div_time_table_detail_info').innerHTML = "Môn: " + s_lesson_name + " - Học kỳ: " + s_term_name + " - Phòng: " + s_location_name + " - Giáo viên: " + s_first_name + " " + s_middle_name + " " + s_last_name + " " + " - Thứ: " + n_date_format + " - Từ: " + dt_start_date + " - Đến: " + dt_end_date + "<br/><br/><br/>";
	
	if(opener.document.getElementById('hdd_time_table_info') != null)
		opener.document.getElementById('hdd_time_table_info').value = opener.document.getElementById('div_time_table_detail_info').innerHTML;
	
	self.close();
	if(oForm.btnEnter)
		oForm.btnEnter.disabled = false;
	
	//oForm.hdd_action.value = "search";

	//oForm.submit();					
	
	//showPointAdmin();
	
    
}

function updatePermissiionScreen()
{
	var n_user_type_id = encodeURIComponent(document.getElementById('n_user_type_id').value);
	var n_type_id = encodeURIComponent(document.getElementById('n_type_id').value);

	var url = "index.php?do=admin_permission_screen";	
	var pars = 'action=save';
	pars += '&n_user_type_id=' + n_user_type_id;
	pars += '&n_type_id=' + n_type_id;
	
	
	var formRadios = document.getElementsByTagName("input");				
	
	for(var i = 0; i< formRadios.length; i++)
	{

		if(formRadios[i].type == 'radio')
		{			
			if(formRadios[i].checked == true)
			{
				pars += '&' + formRadios[i].name + '=' + formRadios[i].value;
			}
		}
	}
	
	ShowDivGeneral(url,pars,'divID');
	
}

function grantPermissiionScreen()
{
	var n_user_type_id = encodeURIComponent(document.getElementById('n_user_type_id').value);
	var n_type_id = encodeURIComponent(document.getElementById('n_type_id').value);

	var url = "index.php?do=admin_permission_screen";	
	url += '&n_user_type_id=' + n_user_type_id + '&n_type_id=' + n_type_id + '&action=edit';
	load_pages(url, 'divID');
	
}

function getPermissionTypeId()
{
	document.getElementById('btn_grant').disabled = true;	
	var n_user_type_id = encodeURIComponent(document.getElementById('n_user_type_id').value);	
	if(n_user_type_id != "")
	{
		var url = "index.php?do=admin_permission_screen";	
		url += '&n_user_type_id=' + n_user_type_id + '&action=get_type';
	
		//load_pages(url, 'show_permission_type');		
		document.getElementById('show_permission_type').innerHTML = "Đang tải dữ liệu...";
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				parameters: '', 
				onComplete: function(originalRequest)
				{
					document.getElementById('show_permission_type').innerHTML = originalRequest.responseText;
					document.getElementById('btn_grant').disabled = false;	
				}
	
			});
			
			var myGlobalHandlers = {
			onCreate: function(){
				//Element.show(div);
			},
		
			onComplete: function() {
				if(Ajax.activeRequestCount == 0){				
					//Element.hide('div1');
				}
			}
		};
	
		Ajax.Responders.register(myGlobalHandlers);				
	}
}

function loginHongbang()
{

	var url = "index.php?do=login&action=login";
	var s_user_id = encodeURIComponent(document.getElementById('s_user_id').value);
	var s_password = encodeURIComponent(document.getElementById('s_password').value);
	var codition = "&s_user_id=" + s_user_id;
	codition += "&s_password=" + s_password;

	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: codition, 
			onComplete: function(originalRequest)
			{
				var result = originalRequest.responseText;
				if(result.length < 200)
				{
					document.getElementById("err_login").innerHTML = result;
				}
				else
				{
					document.getElementById("div_general").innerHTML = result;
					load_pages('index.php?do=admin_time_table','divID')	
				}
				
				
			}

		});
		
		var myGlobalHandlers = {
		onCreate: function(){
			//Element.show(div);
		},
	
		onComplete: function() {
			if(Ajax.activeRequestCount == 0){				
				//Element.hide('div1');
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);			
	
}

