function delCourseAdmin()
{
	var n_system_id = document.getElementById('n_system_id').value;
	
	var codition = '&n_system_id=' + n_system_id;
	deleteGeneral('admin_course', 'show_course', codition);

}
function showListCourse(flag_search)
{
	var n_system_id = document.getElementById('n_system_id').value;
	var n_entry_year = document.getElementById('n_entryYear').value;
	var n_to_year = document.getElementById('n_toYear').value;
	var url = "index.php?do=admin_course";	
	var pars = 'n_system_id=' + n_system_id + '&n_entry_year=' + n_entry_year + '&n_to_year=' + n_to_year + '&action=search';
	if(flag_search)
		pars += "&index_paging=1";

	ShowDivGeneral(url, pars, 'show_course');
}

function checkForSaveCourse()
{
	var s_course_name = document.getElementById('s_course_name').value;
	var n_entry_year = document.getElementById('n_entry_year').value;
	//var s_to_year = document.getElementById('s_to_year').value;
	if(s_course_name == '' || n_entry_year == '')	
		return false;
	return true;
}
function editAdminCourse(n_course_id, edit)
{
	var oForm = document.admin_form;
	oForm.id_update.value = n_course_id;
	oForm.edit.value = edit; 
	oForm.submit();					
}
function edit_course_tpl(case_kind,kind,course_id)
{
	var error = 0;
	var url="";
	var from_year = $('n_entryYear').value;
	//var to_year = $('s_toYear').value;
	var n_system_id = document.getElementById('n_system_id').value;
	if( n_system_id == null || n_system_id  == '' ) n_system_id = 0;
	if(course_id == null || course_id == '') course_id = 0;
	if(case_kind == '0')//show new
	{		
		url = "index.php?do=admin_course&action=case_tpl&kind=" + kind;
	}
	else
	if(case_kind == '1')//show edit
	{
		
		url = "index.php?do=admin_course&action=case_tpl&kind=" + kind ;
		
	
	}
	else
	if(case_kind == '2')//update
	{
		url = "index.php?do=admin_course&action=case_tpl&kind=" + kind;
		url = url +"&s_course_name="+ encodeURIComponent($('s_course_name').value);
		url = url +"&s_short_name="+ encodeURIComponent($('s_short_name').value);

		course_id = $('id_update').value;
		$('id_sys_hidden').value = n_system_id;
	    //$('id_to_hidden').value = to_year;
		$('id_from_hidden').value = from_year;
	}
	if(case_kind == '3')//insert
	{
		
		url = "index.php?do=admin_course&action=case_tpl&kind="+kind;
		url = url +"&s_course_name=" + encodeURIComponent($('s_course_name').value);
		url = url +"&s_short_name="+ encodeURIComponent($('s_short_name').value);
		$('id_sys_hidden').value = n_system_id;
	    //$('id_to_hidden').value = to_year;
		$('id_from_hidden').value = from_year;
		
	}
	else
	if(case_kind == '4')
	{
		url = "index.php?do=admin_course&action=case_tpl&kind="+kind;
		n_system_id = $('id_sys_hidden').value;
		//to_year = $('id_to_hidden').value;
		from_year = $('id_from_hidden').value;
		
		
	}
	
	url = url + "&n_entry_year=" + encodeURIComponent(from_year);
	//url = url + "&s_to_year=" + encodeURIComponent(to_year);
	url = url + "&n_system_id=" + encodeURIComponent(n_system_id);
	url = url +"&course_id=" + encodeURIComponent(course_id);
	//alert(url);
	if(case_kind == '3' || case_kind == '2' )
	{
		if(n_system_id == 0)
		{
			$('show_error_n_system_id').style.display = 'block';			
			//$('error_hidden').innerHTML = "Ph&#7843;i nh&#7853;p h&#7879;";
			//alert($('error_hidden').innerHTML);
			error = 1 ;
		}
		else
		{
			$('show_error_n_system_id').style.display = 'none';
			if(from_year == '' || $('s_course_name').value =='' || $('s_short_name').value =='')
			{
/*				if(to_year == "")
				{
					$('show_error_s_toYear').style.display = 'block';
				}
				else
				{
					$('show_error_s_toYear').style.display = 'none';		
				}
*/				
				if(from_year == "")
				{
					$('show_error_n_fromYear').style.display = 'block';
				}
				else
				{
					$('show_error_n_fromYear').style.display = 'none';		
				}

				if($('s_course_name').value == "")
				{
					$('show_error_s_course_name').style.display = 'block';
				}
				else
				{
					$('show_error_s_course_name').style.display = 'none';		
				}

				if($('s_short_name').value == "")
				{
					$('show_error_s_short_name').style.display = 'block';
				}
				else
				{
					$('show_error_s_short_name').style.display = 'none';		
				}

				error = 1 ;
			}
		}
		
	}
	if(error == 0)
	{ 
		if(case_kind == 0 || case_kind == 1)
		{
			
			ShowDivGeneral(url,"", 'case_tpl');
		
		}
		else
		if(case_kind == 2 || case_kind == 3 || case_kind == 4)
		{
			//alert('vu');
			back_course_tpl('case_tpl',url);
		}
	}
}
function back_course_tpl(id_div,text)
{
	var b=0;
	if(b==0)
	{
		//$(id_div).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;
				
				if(x.length > 500)
				{
					$(id_div).innerHTML=x;
					b=1;
					//searchAll('admin_course','show_lesson','search');
					showListCourse();
				}
				else
				{					
					document.getElementById('err_duplicate').innerHTML = x;	
				}
				
			}
			
		}
		} );
		}catch(e)
		{
			b=2;
		}
		//load_pages('index.php?do=admin_course','case_tpl');
	}
	
}