// Ham select_unit_checkbox_treeuser() cho phep danh dau cac staff cua mot phong ban dung cho khai bao xml
// Tham so:
// node: ten object cua doi doi tuong phong ban
function btn_save_record_onclick(){	
	if (check_value_in_form()) 
		return false;
	_save_checkbox_value_to_textbox_obj(document.forms[0].chk_unit_id,',');
	_save_checkbox_value_to_textbox_obj(document.forms[0].chk_staff_id,',');
	save_hidden_multiple_list(document.forms(0).chk_item_id,',');
	save_list_onclick(document.forms(0),document.forms(0).hdn_list_xml_tag,document.forms(0).hdn_list_xml_value);
	test_status_show_hide_record();
	return;
}


function display_childselectbox_by_parent_id(parent_id,child_obj){
	var k = 0;
	var len = child_obj.arr_parent_id.length;
	child_obj.length=0;		
	for (i=0; i<len; i++) 
	{	
		if (child_obj.arr_parent_id[i] == parent_id || parent_id == "")
			{
				child_obj.options[k] = new Option(child_obj.arr_text[i]);
				child_obj.options[k].value = child_obj.arr_id[i];
				k=k+1;
			}		
		//if (k>0) child_obj.options[0].selected;
	}
}
//Ham thay hien thi danh sach nguoi soan theo phong ban lua chon
function onchange_select_child_staff_selectbox(p_obj_sel){
	var v_selected = "";	
	try{		
		v_selected = document.forms(0).can_bo_soan_thao.value;		
		display_childselectbox_by_parent_id(p_obj_sel.value,document.forms(0).can_bo_soan_thao);
		set_selected(document.forms(0).can_bo_soan_thao,v_selected);
	}catch(e){;}
}
/*
	chuc nang: Ham dung de lay gia tri tu mot the tag_name
	vi du: Muon lay gia tri tu the doc_another
*/
function get_value_from_tag(tag_name){
	var f = document.forms(0);
	var v_value = "";
	for (i=0;i<f.length;i++){
		var e=f.elements[i];
		var v_element = e.xml_tag_in_db;
		if(v_element != "undefined"){			
			if(v_element == tag_name){
				v_value = e.value;
				break;
			}
		}
	}
	return v_value;
}
//----------------------------
function show_row(p_row_id){
	var v_length = eval('document.all.' + p_row_id + '.length');
	if (v_length){
		for (var i=0;i<v_length;i++){
			eval('document.all.' + p_row_id + '[i].style.display="block"');
		}
	}else{
		eval('document.all.' + p_row_id + '.style.display="block"');
	}
}
function hide_row(p_row_id){
	var v_length = eval('document.all.' + p_row_id + '.length');
	if (v_length){
		for (var i=0;i<v_length;i++){
			eval('document.all.' + p_row_id + '[i].style.display="none"');
		}
	}else{
		eval('document.all.' + p_row_id + '.style.display="none"');
	}
}
//Ham nay dung de kiem tra xem co ton tai the xxx khong???
function test_tag(name_tag){
	var v_test_tag = false;
	var f = document.forms(0);
	for (i=0;i<f.length;i++){
		var e=f.elements[i];
		var v_element = e.xml_tag_in_db;
		if(v_element != "undefined"){
			if(v_element == name_tag){
				v_test_tag = true;
				break;
			}
		}
	}
	return v_test_tag;
}
/*
	Chuc nang: Ham nay dung de an/hien khi NSD cho vao muc tai lieu khac tren list tai lieu kem theo
	Vi du: Khi NSD chon vao "Tai lieu khac" tren danh sach tai lieu kem theo
*/
function show_hide_content_doc_another(){
	if(test_tag('doc_another')){
		var v_count = 0;
		var v_len_checkbox = document.all.chk_item_id.length;
		for(var v_index = 0;v_index<v_len_checkbox;v_index++){
			var v_value = document.all.chk_item_id[v_index].value;
			if((v_value == 'TAI_LIEU_KHAC') && (document.all.chk_item_id[v_index].checked)){
				v_count++;
				document.forms(0).hdn_doc_another.value = 1;
				show_row('doc_another');
				break;
			}
		}
		//alert(v_count);
		if(v_count <= 0){
			document.forms(0).hdn_doc_another.value = 0;
			hide_row('doc_another');
		}
	}
}
//Ham nay dung de kiem tra xem la phan tu "name_element" co ton tai khong?
//Vi du: Kiem tra phan tu co ten la txt_code co ton tai tren form khong?
function test_form_element(name_element){
	var v_test_form_element = false;
	var f = document.forms(0);
	for (i=0;i<f.length;i++){
		var e=f.elements[i];
		var v_element = e.name;
		if(v_element != "undefined"){
			if(v_element == name_element){
				v_test_form_element = true;
				break;
			}
		}
	}
	return v_test_form_element;
}
function select_unit_checkbox_treeuser(node){
	var checked = 0;
	var v_count = document.all.chk_staff_id.length;
	if(node.checked){
		for(i=0; i < v_count; i++){
			if(checked > 0 && document.all.chk_staff_id[i].parent_id != node.value && document.all.chk_staff_id[i].xml_tag_in_db_name==node.xml_tag_in_db_name){
				return;
			}			
			if(document.all.chk_staff_id[i].parent_id == node.value && document.all.chk_staff_id[i].xml_tag_in_db_name==node.xml_tag_in_db_name){
				document.all.chk_staff_id[i].checked = "checked";
				checked ++;
			}
		}
	}else{
		for(i=0; i < v_count; i++){
			if(checked >0 && document.all.chk_staff_id[i].parent_id != node.value && document.all.chk_staff_id[i].xml_tag_in_db_name==node.xml_tag_in_db_name){
				return;
			}						
			if(document.all.chk_staff_id[i].parent_id == node.value && document.all.chk_staff_id[i].xml_tag_in_db_name==node.xml_tag_in_db_name){
				document.all.chk_staff_id[i].checked = "";
				checked ++;
			}
		}		
	}
}
function select_readonly(sel_obj){
	if (sel_obj.readonly=="true")	return;	
}
function show_modal_dialog_all_record_onclick(p_goto_url,p_fuseaction,p_recordtype_filter,p_txt_obj,p_hdn_obj,p_fuseaction_back){
	v_url = _DSP_MODAL_DIALOG_URL_PATH;	
	v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_recordtype_filter_list=" + p_recordtype_filter);
	v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
	v_url = v_url+ "&" + randomizeNumber();
	sRtn = showModalDialog(v_url,"","dialogWidth=550pt;dialogHeight=360pt;dialogTop=80pt;status=no;scroll=no;");
	//alert(sRtn);
	if (!sRtn) return;
	arr_value = sRtn.split(_LIST_DELIMITOR);
	p_hdn_obj.value = arr_value[1];
	p_txt_obj.value = arr_value[1];	
	if (p_fuseaction_back!=""){
		document.forms(0).fuseaction.value = p_fuseaction_back;
		document.forms(0).submit();
	}
}
function show_modal_dialog_record_onclick(p_goto_url,p_fuseaction,p_recordtype_filter,p_txt_obj,p_hdn_obj,p_fuseaction_back){
	v_url = _DSP_MODAL_DIALOG_URL_PATH;	
	v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_recordtype_filter_list=" + p_recordtype_filter);
	v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
	v_url = v_url+ "&" + randomizeNumber();
	sRtn = showModalDialog(v_url,"","dialogWidth=550pt;dialogHeight=360pt;dialogTop=80pt;status=no;scroll=no;");
	//alert(sRtn);
	if (!sRtn) return;
	arr_value = sRtn.split(_LIST_DELIMITOR);
	p_hdn_obj.value = arr_value[1];
	//p_txt_obj.value = arr_value[1];	
	if (p_fuseaction_back!=""){
		document.forms(0).fuseaction.value = p_fuseaction_back;
		document.forms(0).submit();
	}
}
///Luu lai danh sach cac the va cac gia tri co trong form
function save_list_onclick(f,hdn_obj_tag,hdn_obj_value){
	var list_tag = "";
	var list_value = "";
	var v_temp = "";
	var v_value = "";
	for (i=0;i<f.length;i++){
		var e=f.elements[i];
		if (e.value==""||e.value==null){
			v_value=" ";
		}else{
			v_value=e.value;
		}
		if (e.xml_tag_in_db &&(e.type!='radio' && e.type!='checkbox')){
			list_tag = list_append(list_tag,e.xml_tag_in_db,_SUB_LIST_DELIMITOR);
			list_value = list_append(list_value,v_value,_SUB_LIST_DELIMITOR);
		}
		if (e.xml_tag_in_db &&(e.type=='radio' || e.type=='checkbox')){
			list_tag = list_append(list_tag,e.xml_tag_in_db,_SUB_LIST_DELIMITOR);
			if (e.checked==true){
				v_temp="true";
			}else{
				v_temp="false";
			}
			list_value = list_append(list_value,v_temp,_SUB_LIST_DELIMITOR);
		}
	}
	if (hdn_obj_tag.value!=null && hdn_obj_value.value!=null){
		hdn_obj_tag.value = list_tag;
		hdn_obj_value.value = list_value;
	}
	//alert(list_tag);
	//alert(list_value);return;
}
function save_hidden_multiple_list(p_chk_obj,the_separator){
	var ret = "";
	try{
		if (!p_chk_obj.length){
			if (p_chk_obj.checked){
				ret=p_chk_obj.value;
				eval('document.forms(0).'+p_chk_obj.xml_tag_in_db_name+'.value="'+ret+'"');
			}
		}else{	
			current_chk_obj = p_chk_obj[0].xml_tag_in_db_name;
			for(i=0;i<p_chk_obj.length;i++){
				next_chk_obj = p_chk_obj[i].xml_tag_in_db_name;	
				if (current_chk_obj != next_chk_obj){  //Neu het danh sach thi gan vao gia tri cua danh sach
					eval('document.forms(0).'+current_chk_obj+'.value="'+ret+'"');
					ret = "";
				}
				if (p_chk_obj[i].checked){
					ret=list_append(ret,p_chk_obj[i].value,the_separator);					
				}
				if (i==p_chk_obj.length-1){ //Cuoi gan gia tri vao danh sach
					eval('document.forms(0).'+current_chk_obj+'.value="'+ret+'"');
					ret = "";
				}
				current_chk_obj = next_chk_obj;
			}
		}	
	}catch(e){;}
}
/////Begin/////Cac ham phuc vui cho checkbox multiple
function show_row_selected(rad_id,tr_name){
	//Thay doi selected cua radio button
	eval('document.all.' + rad_id + '(0).checked=false');
	eval('document.all.' + rad_id + '(1).checked=true');
	//hide cac dong chua modul neu tr_name='tr_function' va gia tri cua checked=""
	if (tr_name == 'tr_function'){
		v_count=eval('document.all.tr_modul.length');
		if (v_count){
			for(var i=0;i<v_count;i++){
				if (eval('document.all.tr_modul[i].checked == ""')){
					eval('document.all.tr_modul[i].style.display="none"');
				}else{
					eval('document.all.tr_modul[i].style.display="block"');
				}
			}
		}else{
			if (eval('document.all.tr_modul.checked == ""')){
				eval('document.all.tr_modul.style.display="none"');
			}else{
				eval('document.all.tr_modul.style.display="block"');
			}
		}
	}
	//hide cac dong tr_name neu gia tri checked=""
	v_count=eval('document.all.' + tr_name + '.length');
	var v_odd_class="";
	if(v_count){
		for(var i=0;i<v_count;i++){
			if (eval('document.all.' + tr_name + '[i].checked == ""')){
				eval('document.all.' + tr_name + '[i].style.display="none"');
			}else{
				if (v_odd_class == "odd_row"){
					eval('document.all.'+ tr_name + '[i].className="round_row"');
					v_odd_class = "round_row"
				}else{
					eval('document.all.'+ tr_name + '[i].className="odd_row"');
					v_odd_class = "odd_row"
				}
			}
		}
	}else{
		if (eval('document.all.' + tr_name + '.checked == ""')){
			eval('document.all.' + tr_name + '.style.display="none"');
		}else{
			if (v_odd_class == "odd_row"){
				eval('document.all.'+ tr_name + '.className="round_row"');
				v_odd_class = "round_row"
			}else{
				eval('document.all.'+ tr_name + '.className="odd_row"');
				v_odd_class = "odd_row"
			}
		}
	}
}
//Ham show_all_row co chuc nang hien thi tat ca doi tuong (ke ca khong thuoc nhom)
function show_row_all(rad_id,tr_name){
	//Thay doi selected cua radio button
	eval('document.all.' + rad_id + '(0).checked=true');
	eval('document.all.' + rad_id + '(1).checked=false');
	//show tat ca cac tr_modul neu tr_name='tr_function'
	if (tr_name == 'tr_function'){
		v_count=eval('document.all.tr_modul.length');
		if(v_count){
			for(var i=0;i<v_count;i++){
				var v_img_path = getImgDirectory(eval('document.all.img_modul[i].src'));
				eval('document.all.img_modul[i].src = v_img_path + "open.gif"');
				eval('document.all.tr_modul[i].style.display="block"');
			}
		}else{
			eval('document.all.tr_modul.style.display="block"');
		}
	}
	//show tat ca cac tr_name
	v_count=eval('document.all.' + tr_name + '.length');
	var v_odd_class="";
	if(v_count){
		for(var i=0;i<v_count;i++){
			eval('document.all.' + tr_name + '[i].style.display="block"');
			if (v_odd_class == "odd_row"){
				eval('document.all.'+ tr_name + '[i].className="round_row"');
				v_odd_class = "round_row"
			}else{
				eval('document.all.'+ tr_name + '[i].className="odd_row"');
				v_odd_class = "odd_row"
			}
		}
	}else{
		eval('document.all.' + tr_name + '.style.display="block"');
		if (v_odd_class == "odd_row"){
			eval('document.all.'+ tr_name + '.className="round_row"');
			v_odd_class = "round_row"
		}else{
			eval('document.all.'+ tr_name + '.className="odd_row"');
			v_odd_class = "odd_row"
		}
	}
}
/*Ham change_item_checked
Chuc nang: Xu ly khi NSD click mouse vao checkbox cua EndUser hoac cua Function
	-Tim tr_name chua checkbox duoc click va thay doi trang thai cua attribute checked ("" hoac "checked")
	-Kiem tra cac trang thai checked cua cac function trong modul de xac dinh trang thai checked cua modul
	(Neu khong co function nao duoc chon thi checked=""; neu co thi checked="checked")
	-Kiem tra che do hien thi (qua radio button) de refresh lai man hinh
Tham so:
	-chk_obj: doi tuong checkbox duoc click
	-tr_name: ten id cua row chua checkbox (tr_function hoac tr_enduser)
	-rad_id:  ten id cua radio button xac dinh che do hien thi cua moi loai (rad_group_enduser hoac rad_group_function)
*/
function change_item_checked(chk_obj,tr_name,rad_id){
	var v_count;
	var i;
	var v_modul_checked=false;
	//Tim row chua checkbox va thay doi gia tri cua tr_name.checked
	v_count = eval('document.all.' + tr_name +'.length');
	i=0;
	if (v_count){
		while (i<v_count){
			if (eval('document.all.' + tr_name + '[i].value == chk_obj.value')){
				if (eval('document.all.' + tr_name + '[i].checked == "checked"')){
					eval('document.all.' + tr_name + '[i].checked = ""');
				}else{
					eval('document.all.' + tr_name + '[i].checked = "checked"');
				}
				//break;
			}
			//Kiem tra xem trong mo dul co chuc nang nao duoc chon khong
			if (tr_name == 'tr_function'){
				if (eval('document.all.' + tr_name + '[i].modul == chk_obj.modul')){
					if (eval('document.all.' + tr_name + '[i].checked == "checked"')){
						v_modul_checked=true;
					}
				}
			}
			i++;
		}
	}else{
		if (eval('document.all.' + tr_name + '.value == chk_obj.value')){
			if (eval('document.all.' + tr_name + '.checked == "checked"')){
				eval('document.all.' + tr_name + '.checked = ""');
			}else{
				eval('document.all.' + tr_name + '.checked = "checked"');
			}
		}
		if (tr_name == 'tr_function'){
			if (eval('document.all.' + tr_name + '.modul == chk_obj.modul')){
				if (eval('document.all.' + tr_name + '.checked == "checked"')){
					v_modul_checked=true;
				}
			}
		}
	}
	//thay doi gia tri cua checked trong tr_modul va chk_modul_id theo v_modul_checked=True or False
	if (tr_name == 'tr_function'){
		v_count = eval('document.all.tr_modul.length');
		if (v_count){
			i=0;
			while (i<v_count){
				if (eval('document.all.tr_modul[i].value == chk_obj.modul')){
					if (v_modul_checked == true){
						eval('document.all.tr_modul[i].checked = "checked"');
						eval('document.all.chk_modul_id[i].checked = "checked"');
					}else{
						eval('document.all.tr_modul[i].checked = ""');
						eval('document.all.chk_modul_id[i].checked = ""');
					}
					break;
				}
				i++;
			}
		}else{
			if (eval('document.all.tr_modul.value == chk_obj.modul')){
				if (v_modul_checked == true){
					eval('document.all.tr_modul.checked = "checked"');
				}else{
					eval('document.all.tr_modul.checked = ""');
				}
			}
		}
	}
	//Kiem tra che do hien thi de refresh man hinh
	if (eval('document.all.' + rad_id + '(1).checked')){
		show_row_selected(rad_id,tr_name);
	}
}
function save_hidden_list_item_id(p_hdn_list,p_chk_obj){
	if (checkbox_value_to_list(p_chk_obj,",")!=""){
		p_hdn_list.value = checkbox_value_to_list(p_chk_obj,",");
	}
}
/////End/////Cac ham phuc vui cho checkbox multiple
function onchange_submit(obj_sel_type,obj_hdn_type,p_fuseaction){		
	obj_hdn_type.value = obj_sel_type.value;
	btn_save_onclick(p_fuseaction);
}
function show_window_to_print(p_goto_url,p_checkbox_obj,p_type,p_fuseaction) {
	var list = checkbox_value_to_list(p_checkbox_obj,",");
	if (list) {   //Kiem tra xem co cau hoi nao duoc chon hay khong?
		if(list_count_element(list,",")==1)	{ //Kiem tra xem co phai chon 1 cau hoi hay khong?
			v_url = p_goto_url + "?hdn_record_id_list=" + list+ "&hdn_record_id=" + list + "&hdn_recordtype_filter=" + p_type +"&fuseaction="+p_fuseaction +"&modal_dialog_mode=1";
			v_url = v_url+ "&" + randomizeNumber();
			//sRtn = showModalDialog(v_url,"","dialogWidth=420pt;dialogHeight=200pt;dialogTop=80pt;status=no;scroll=no;");
			goto_url(v_url,3);
		}else{
			alert("Chi duoc chon mot HO SO de in");
		}
	}else {
		alert("Chua co HO SO nao duoc chon");
		return;		
	}
}
function list_count_element(the_list,the_separator)
{	
	if (the_list=="") return -1;
	arr_value = the_list.split(the_separator);
	if (arr_value.length > 0){
			return arr_value.length;
	}
	return -1;
}	
//Chuyen toi url
function goto_url(p_url,p_open_new_win)
{
	if (p_open_new_win==3)
		open_me(p_url, 1, 1, 1, 1, 1, 0, 0, 0, 0, 450, 650, 0, 0);
	else{
		//document.parentWindow.location = p_url;	
		//alert (document.location);
		if (p_open_new_win==2)
			window.top.location = p_url;
		else{
			window.parent.location = p_url;
		}
	}
}
//==============================================================================================================
// open new window with some value
function open_me(url, vStatus, vResizeable, vScrollbars, vToolbar,vMenubar, vLocation, vFullscreen, vTitlebar, vCentered, vHeight, vWidth, vTop, vLeft)	 
{
	winDef = '';
	winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('menubar=').concat((vMenubar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('height=').concat(vHeight).concat(',');
	winDef = winDef.concat('width=').concat(vWidth).concat(',');

	if (vCentered)	{
		winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
		winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	}
	else	{
		winDef = winDef.concat('top=').concat(vTop).concat(',');
		winDef = winDef.concat('left=').concat(vLeft);
	}
	open(url, '_blank', winDef);
}
//Ham de cap nhat cong viec (handle)
function btn_save_record_work_onclick(p_worktype_checkbox_obj,p_hdn_worktype_checkbox_obj, p_fuseaction){
	p_hdn_worktype_checkbox_obj.value = checkbox_value_to_list(p_worktype_checkbox_obj,",");
	btn_save_onclick(p_fuseaction);
}
function btn_add_record_work_onclick(p_obj, p_fuseaction, p_goto_url){
	if (_MODAL_DIALOG_MODE==1){
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + p_goto_url + "&hdn_item_id=0" + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" + "&" + randomizeNumber();
		sRtn = showModalDialog(v_url,"","dialogWidth=470pt;dialogHeight=210pt;status=no;scroll=no;");
		alert(sRtn);
		document.forms(0).fuseaction.value = "";
		document.forms(0).submit();
	}else{
		document.forms(0).fuseaction.value = p_fuseaction;
		document.forms(0).submit();
	}	
}
function show_modal_dialog_update_onclick(p_goto_url,p_fuseaction,p_fuseaction_ret, p_checkbox_item, p_hdn_item,hdn_type,hdn_date){
	var v_id_list = checkbox_value_to_list(p_checkbox_item,",");
	if (v_id_list) {  
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_record_id_list=" + v_id_list + "&hdn_recordtype_filter=" + hdn_type.value+ "&hdn_received_date=" + hdn_date.value);
		v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
		v_url = v_url+ "&" + randomizeNumber();
		sRtn = showModalDialog(v_url,"","dialogWidth=420pt;dialogHeight=150pt;dialogTop=100pt;status=no;scroll=no;");
		if (!sRtn){ 
			return;
		}else{
			p_hdn_item.value = v_id_list;
			document.forms(0).fuseaction.value = p_fuseaction_ret;
			document.forms(0).submit();
		}
	}else{
		alert("Chua co HO SO nao duoc chon");
		return;		
	}
	
}
function btn_update_handover_onclick(p_hdn_obj){
	window.returnValue = p_hdn_obj.value;
	window.close();
}
//Lay ngay tiep theo cua ngay trong elTerget.value
function Next_Date(p_date) {
	if(isdate(p_date)){
		var theDate,strSeparator,arr,day,month,year;
		strSeparator = "";
		theDate = p_date;
		if (theDate.indexOf("/")!=-1) strSeparator = "/";
		if (theDate.indexOf("-")!=-1) strSeparator = "-";
		if (theDate.indexOf(".")!=-1) strSeparator = ".";
		if (strSeparator != "") {
		arr=theDate.split(strSeparator);
		day=new Number(arr[0])+1;
		month=new Number(arr[1]);
		year=new Number(arr[2]);
		if(day > 28) {
			if (((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && (day > 31))
			|| ((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30))||(month == 2 && year % 4 !=0)||(month == 2 && year % 4 ==0 && day > 29)) 
			{
				day = 1;
				month = month+1;
			}
			if (month > 12 ){
				year = year +1;
				month = 1;
			}
			
		}	
		return day + strSeparator + month + strSeparator + year;
	}
   }		
	
}
function list_have_date(the_list,the_element, the_separator)
{	
	if (the_list=="") return 0;
	arr_value = the_list.split(the_separator);
	for(i=0;i<arr_value.length;i++){
		if (date_compare(arr_value[i],the_element)==0){
			return 1;
		}
	}
	return 0;
}
function get_appoint_date(obj_date_input,count,obj_date_output,p_year){
	var v_list_day_off_of_year = _LIST_DAY_OFF_OF_YEAR.split(",");
	var v_list_day = _LIST_WORK_DAY_OF_WEEK;
	var v_increase_and_decrease_day = parseInt(_INCREASE_AND_DECREASE_DAY);
	var v_list_luner_date="";
	var v_date,v_temp_date;
	var v_input_date = obj_date_input.value;
	var v_next_date = "";	
	if (!isdate(obj_date_input.value)){
		return;
	}
	for (var i=0;i<v_list_day_off_of_year.length;i++){
		v_date = v_list_day_off_of_year[i].split("/");
		if (v_date[0]=="-"){
			v_list_luner_date = list_append(v_list_luner_date,v_date[1]+"/" + v_date[2] + "/" + p_year,",");
		}else{
			v_temp_date = Solar2Lunar(v_date[1]+ "/" + v_date[2] + "/" + p_year);
			v_list_luner_date = list_append(v_list_luner_date,v_temp_date,",");
		}
	}
	
	var i=0;
	v_next_date = v_input_date;
	while ((i<count - v_increase_and_decrease_day)){ //Tinh du tong so ngay tru ngay duoc nghi ra
		if ((list_have_date(v_list_luner_date,Solar2Lunar(v_next_date),",")!=1)&&(Solar2DayofWeek(v_next_date)!=7)&&(Solar2DayofWeek(v_next_date)!=8)){
			i++;
			v_next_date = Next_Date(v_next_date);	
		}else{
			v_next_date = Next_Date(v_next_date);	
		}		
	}//Neu den han duoc lay roi ma gap ngay khong tiep thi phai cho 
	//alert(v_next_date);
	if(count==0){	
		obj_date_output.value = v_next_date;
	}else{	
		while ((list_have_element(v_list_day,Solar2DayofWeek(v_next_date),",")<0)){
			v_next_date = Next_Date(v_next_date);		
		}		
		obj_date_output.value = v_next_date;
	}
}
function btn_result_handle_onclick(p_checkbox_obj, p_hidden_obj, p_fuseaction){	
	if (!checkbox_value_to_list(p_checkbox_obj,",")){
		alert("Chua co HO SO nao duoc chon!");
		return;
	}
	document.forms(0).fuseaction.value = p_fuseaction;		
	p_hidden_obj.value = checkbox_value_to_list(p_checkbox_obj,",");		
	document.forms(0).submit(); 
}
function sending_email(p_fuseaction){
		document.forms(0).fuseaction.value = p_fuseaction;
		document.forms(0).submit();
}
function re_display_list_handler_transfer(){
	v_obj = document.all.tr_handler_name;
	v_check_obj = document.all.chk_handler_list_id;
	primary_handler_id = document.forms(0).hdn_primary_handler_id.value;
	if (v_obj.length>1){
		for(i=0;i<v_obj.length;i++){		
			if (v_obj[i].value == primary_handler_id){
				v_check_obj[i].checked=false;
				v_obj[i].style.display = 'none';
			}
			else
				v_obj[i].style.display = 'block';
		}
	}else{
		if (v_obj.value == primary_handler_id){
			v_check_obj.checked=false;
			v_obj.style.display = 'none';
		}
	}
}
///////////////////////////////////////
function re_display_unit_list(){
	v_obj = document.all.tr_unit_name;
	v_check_obj = document.all.chk_unit_list_id;
	primary_handler_unit_id = document.forms(0).hdn_handle_unit_id.value;
	if (v_obj.length>1){
		for(i=0;i<v_obj.length;i++){		
			if (v_obj[i].value == primary_handler_unit_id){
				v_check_obj[i].checked=false;
				v_obj[i].style.display = 'none';
			}
			else
				v_obj[i].style.display = 'block';
		}
	}else{
		if (v_obj.value == primary_handler_unit_id){
			v_check_obj.checked=false;
			v_obj.style.display = 'none';
		}
	}
}
//////////////////////////////////////////
function unit_onchange(p_select_obj,p_hidden_obj) {	
	p_hidden_obj.value = p_select_obj.value ;
}
//////////////////////////////////////////////////
function show_modal_dialog_transition_onclick(p_goto_url,p_fuseaction,p_fuseaction_ret, p_checkbox_item, p_hdn_item,hdn_type,hdn_date){
	var v_id_list = checkbox_value_to_list(p_checkbox_item,",");
	if (v_id_list) {  
		v_url = _DSP_MODAL_DIALOG_URL_PATH;
		v_url = v_url + "?goto_url=" + escape(p_goto_url +  "?hdn_record_id_list=" + v_id_list + "&hdn_recordtype_filter=" + hdn_type.value+ "&hdn_received_date=" + hdn_date.value);
		v_url = v_url + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" 
		v_url = v_url+ "&" + randomizeNumber();
		var v_top = (screen.heigth - 450)/2;
		var v_left = (screen.width - 450)/2;
		sRtn = showModalDialog(v_url,"","dialogWidth=600pt;dialogHeight=300pt;dialogTop="+v_top+"pt;status=no;scroll=no");
		if(sRtn){
			document.forms(0).fuseaction.value = p_fuseaction_ret;
			document.forms(0).submit();
		}
	
	}else{
		alert("Chua co HO SO nao duoc chon");
		return;		
	}
	
	
}
function show_dialog_all_item_onclick(p_goto_url,p_fuseaction, p_text_name_obj, p_text_code_obj, p_hdn_obj, p_hdn_unit_id,p_hdn_handler_id_list){
	try{
		if (p_hdn_unit_id == '' || p_hdn_handler_id_list == ''){
			return;
		}
		v_url =  p_goto_url + "?hdn_handle_agency_id="+p_hdn_unit_id +"&hdn_handler_id_list="+p_hdn_handler_id_list + "&fuseaction=" + p_fuseaction + "&modal_dialog_mode=1" + "&" + randomizeNumber();
		sRtn = showModalDialog(v_url,"","dialogWidth=420pt;dialogHeight=280pt;dialogTop=80pt;status=no;scroll=no;");
		if (!sRtn) return;
		arr_value = sRtn.split(_LIST_DELIMITOR);
		p_hdn_obj.value = arr_value[0];
		p_text_code_obj.value = arr_value[1];		
		p_text_name_obj.value = arr_value[2];
	}catch(e){;}	
}
function transition_onclick(){

		var v_handler_list_id = '';
		try{
			if(document.forms(0).chk_handler_list_id.length){
				for(i=0;i<document.forms(0).chk_handler_list_id.length;i++){
					if(document.all.tr_handler_name[i].style.display != 'none' && document.forms(0).chk_handler_list_id[i].checked){
						if(v_handler_list_id != ''){
							v_handler_list_id = v_handler_list_id + ',' + document.forms(0).chk_handler_list_id[i].value;
						}else{
							v_handler_list_id = document.forms(0).chk_handler_list_id[i].value;
						}
					}
				}
			}
		}catch(e){;}						
		if (document.forms(0).hdn_transition_by.value == 0){
			if(document.forms(0).hdn_handle_unit_id.value <= 0 && document.forms(0).sel_handler_unit.value ==''){
				alert('Phai chon phong thu ly chinh!');
				return;
			}	
		}
		if (document.forms(0).hdn_transition_by.value == 1){
			if(document.forms(0).sel_transition_receive.value == ''){
				alert('Phai chon don vi nhan chuyen tiep!');
				return;
			}	
		}
		if (document.forms(0).hdn_transition_by.value == 2){
			if(document.forms(0).hdn_primary_handler_id.value == ''){
				alert('Phai chon can bo thu ly chinh!');
				return;
			}	
		}
		if(document.forms(0).txt_petition_period_date.value != ''){
			if (isdate(document.forms(0).txt_petition_period_date.value)==false){
				alert('Ngay xu ly phai co dang ngay/thang/nam!');
				document.forms(0).txt_petition_period_date.focus();
				return;
			}
		}
		if(document.forms(0).txt_date_limit.value != ''){
			if (isnum(document.forms(0).txt_date_limit.value)==false){
				alert('Thoi han xu ly phai la so nguyen!');
				document.forms(0).txt_date_limit.focus();
				return;
			}
		}
		document.forms(0).hdn_handler_id_list.value = v_handler_list_id;
		document.forms(0).fuseaction.value = 'TRANSITION_RECORD';
		document.forms(0).submit();
	//}
}
function transition_or_handle_onclick(p_choise,p_hdn_value){	
	if(p_choise == 1){
		document.all.td_transition_label.style.display = 'block';
		document.all.td_transition_sel.style.display = 'block';
		document.forms(0).hdn_transition_by.value = 1;
		document.all.tr_handle.style.display = 'none';		
	}
	if(p_choise == 0){
		document.all.td_transition_label.style.display = 'none';
		document.all.td_transition_sel.style.display = 'none';
		document.all.tr_handle.style.display = 'block';
		document.forms(0).hdn_transition_by.value = 0;
		
	}
	if(p_choise == 2){
		try{
		if(p_hdn_value==0  && p_hdn_value !=''){	
			document.forms(0).sel_handler_unit.value=document.forms(0).sel_handler_unit(1).value;
			document.all.tr_combine_handler_unit.style.display = 'none';
		}else{
			document.all.tr_combine_handler_unit.style.display = 'block';
		}
		}catch(e){;}
		document.all.tr_room_handle.style.display = 'block';
		document.all.tr_staff_handle.style.display = 'none';
		document.forms(0).hdn_transition_by.value = 0;
		
	}
	if(p_choise == 3){
		document.all.tr_room_handle.style.display = 'none';
		document.all.tr_combine_handler_unit.style.display = 'none';
		document.all.tr_staff_handle.style.display = 'block';
		document.forms(0).hdn_transition_by.value = 2;	
		
		}
		
}

function get_num_date_from_date(obj_date_input,obj_date_num,obj_date_output,obj_current_year){
	var v_list_day_off_of_year = _LIST_DAY_OFF_OF_YEAR.split(",");
	var v_list_day = _LIST_WORK_DAY_OF_WEEK;
	var dem = 0;
	var v_list_luner_date="";
	var v_date,v_temp_date;
	var p_year = obj_current_year.value;
	var v_next_date = p_date_begin;
	var p_date_end = obj_date_output.value;
	var p_date_begin = obj_date_input.value;
	var v_next_date = p_date_begin;
	
	for (var i=0;i<v_list_day_off_of_year.length;i++){
		v_date = v_list_day_off_of_year[i].split("/");
		if (v_date[0]=="-"){
			v_list_luner_date = list_append(v_list_luner_date,v_date[1]+"/" + v_date[2] + "/" + p_year,",");
		}else{
			v_temp_date = Solar2Lunar(v_date[1]+ "/" + v_date[2] + "/" + p_year);
			v_list_luner_date = list_append(v_list_luner_date,v_temp_date,",");
		}
	}
	if (!isdate(p_date_end)){
		return;
	}
	if(date_compare(p_date_begin,p_date_end)<0){
		alert('Khong duoc nho hon ngay hien tai');
		obj_date_output.value = "";
		obj_date_num.value = "";
		obj_date_output.focus();
		return;
	}
	while (v_next_date!=p_date_end){
		v_next_date = Next_Date(v_next_date);
		if((list_have_date(v_list_luner_date,Solar2Lunar(v_next_date),",")!=1)&&(Solar2DayofWeek(v_next_date)!=7)&&(Solar2DayofWeek(v_next_date)!=8)){
			dem ++;
		}
	}
	obj_date_num.value = dem;
}

function check_date(p_date, p_receiver_date){
	if (p_date != ''){
		if(date_compare(p_date.value,p_receiver_date)>0){
			alert('Ngay ra quyet dinh khong duoc nho hon ngay tiep nhan: ' + p_receiver_date + '!');
			p_date.focus();
			return 0;
		}
	}
	btn_save_onclick('UPDATE_LICENSE');
}


//Ham nay thuc thi khi NSD nhan vao mot trang tren danh sach
function page_onchange(sel_obj,p_fuseaction){
	document.forms(0).hdn_page.value = sel_obj.value;	
	document.forms(0).fuseaction.value = p_fuseaction;
	document.forms(0).submit();
}
//Ham thay thuc thi khi NSD muon thay doi so dong quy dinh tren mot trang
function page_record_number_onchange(sel_obj,p_fuseaction){		
	document.forms(0).hdn_page.value = 1;
	document.forms(0).hdn_record_number_page.value = sel_obj.value;	
	document.forms(0).fuseaction.value = p_fuseaction;
	document.forms(0).submit();
}

/*
	Nguoi tao: Vu Manh Hung
	Ngay tao: 10/06/2007
	Y nghia: Ham nay xu ly viec an/hien cua left menu
*/
function show_hide_leftmenu(){	
	if(document.all.hdn_showhide_leftmenu.value == 0){
		hide_row('id_leftmenu');
		//Cho hien thi img arrow right
		document.all.id_img_show_hide.src = _WEB_PATH_IMAGE + "show_leftmenu.jpg";
	}else{
		show_row('id_leftmenu');
		document.all.id_img_show_hide.src = _WEB_PATH_IMAGE + "hide_leftmenu.jpg";
	}
	//Neu dang an thi dat lai flag cho an
	if(document.all.hdn_showhide_leftmenu.value == 0){
		document.all.hdn_showhide_leftmenu.value = 1;
	}else{
		document.all.hdn_showhide_leftmenu.value = 0;
	}
	//alert(document.all.hdn_showhide_leftmenu.value);
}
function process_hot_key(p_f12, p_insert, p_delete, p_esc, p_enter){
	var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
	// Phim ESC
	if(keyCode == 27 && p_esc){
		window.close();
		return;
	}	
}
function set_input(){
	show_hide_leftmenu();	
}
//Gan gia tri vao mot bien an obj.value
function set_value_hidden(obj,obj_value){
	obj.value = obj_value;	
}
/*
Chuc nang: Lay ngay/thang/nam hien tai theo he thong
Ten ham: return_current_date
*/
function return_current_date(){
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
return day + "/" + month + "/" + year
} 
/*	
	Nguoi tao: HungVM
	Ngay tao: 10/80/2007
	Chuc nang: Tra lai so ngay hen cong viec kiem tra tinh hop le cua ho so
*/
function calculation_date_period_num_change(){
	var currentTime = new Date();
	var count = document.forms(0).so_ngay_kiem_tra_hs_hop_le.value;
	//Year
	var p_year = currentTime.getFullYear();
	var v_list_day_off_of_year = _LIST_DAY_OFF_OF_YEAR.split(",");
	var v_list_day = _LIST_WORK_DAY_OF_WEEK;
	var v_increase_and_decrease_day = parseInt(_INCREASE_AND_DECREASE_DAY);
	var v_list_luner_date="";
	var v_date,v_temp_date;
	//Viec tinh ngay hen giai quyet bat dau tu ngay tiep nhan
	var v_input_date = document.forms(0).txt_received_date.value;	
	if(v_input_date == "" || !isdate(v_input_date)){
		v_input_date = return_current_date();
	}
	var v_next_date = "";
	if (!isdate(v_input_date)){
		return;
	}else{	
		var arr_input_date = v_input_date.split("/");
		v_input_date = arr_input_date[0]*1 + "/" + arr_input_date[1]*1 + "/" + arr_input_date[2]*1; 
	}
	for (var i=0;i<v_list_day_off_of_year.length;i++){
		v_date = v_list_day_off_of_year[i].split("/");
		if (v_date[0]=="-"){
			v_list_luner_date = list_append(v_list_luner_date,v_date[1]+"/" + v_date[2] + "/" + p_year,",");
		}else{
			v_temp_date = Solar2Lunar(v_date[1]+ "/" + v_date[2] + "/" + p_year);
			v_list_luner_date = list_append(v_list_luner_date,v_temp_date,",");
		}
	}
	var i=0;
	v_next_date = v_input_date;
	while ((i<count - v_increase_and_decrease_day)){ //Tinh du tong so ngay tru ngay duoc nghi ra
		if ((list_have_date(v_list_luner_date,Solar2Lunar(v_next_date),",")!=1)&&(Solar2DayofWeek(v_next_date)!=7)&&(Solar2DayofWeek(v_next_date)!=8)){
			i++;
			v_next_date = Next_Date(v_next_date);	
		}else{			
			v_next_date = Next_Date(v_next_date);	
		}
	}//Neu den han duoc lay roi ma gap ngay khong tiep thi phai cho 
	while ((list_have_element(v_list_day,Solar2DayofWeek(v_next_date),",")<0)){
		v_next_date = Next_Date(v_next_date);	
	}
	document.forms(0).ngay_ket_thuc_kiem_tra.value = v_next_date;
}
function petition_period_num_change(obj_date_input,obj_date_num,obj_date_output,obj_current_year){
	var count = obj_date_num.value;
	var p_year = obj_current_year.value;
	var v_list_day_off_of_year = _LIST_DAY_OFF_OF_YEAR.split(",");
	var v_list_day = _LIST_WORK_DAY_OF_WEEK;
	var v_list_luner_date="";
	var v_increase_and_decrease_day = parseInt(_INCREASE_AND_DECREASE_DAY);
	var v_date,v_temp_date;
	var v_input_date = obj_date_input.value;
	var v_next_date = "";
	if (!isdate(obj_date_input.value)){
		return;
	}else{	
		var arr_input_date = v_input_date.split("/");
		v_input_date = arr_input_date[0]*1 + "/" + arr_input_date[1]*1 + "/" + arr_input_date[2]*1; 
		
	}
	
	for (var i=0;i<v_list_day_off_of_year.length;i++){
		v_date = v_list_day_off_of_year[i].split("/");
		if (v_date[0]=="-"){
			v_list_luner_date = list_append(v_list_luner_date,v_date[1]+"/" + v_date[2] + "/" + p_year,",");
		}else{
			v_temp_date = Solar2Lunar(v_date[1]+ "/" + v_date[2] + "/" + p_year);
			v_list_luner_date = list_append(v_list_luner_date,v_temp_date,",");
		}
	}
	var i=0;
	v_next_date = v_input_date;
	while ((i<count-v_increase_and_decrease_day)){ //Tinh du tong so ngay tru ngay duoc nghi ra
		if ((list_have_date(v_list_luner_date,Solar2Lunar(v_next_date),",")!=1)&&(Solar2DayofWeek(v_next_date)!=7)&&(Solar2DayofWeek(v_next_date)!=8)){
			i++;
			v_next_date = Next_Date(v_next_date);	
		}else{
			v_next_date = Next_Date(v_next_date);	
		}
	}//Neu den han duoc lay roi ma gap ngay khong tiep thi phai cho 
	while ((list_have_element(v_list_day,Solar2DayofWeek(v_next_date),",")<0)){
		v_next_date = Next_Date(v_next_date);	
	}
	obj_date_output.value = v_next_date;
}

/* Display options of the selectbox object by a foreign key value
   Parameters:	
	   parent_id: the key value to fillter
	   child_obj: is a name of selectbox object that will be displayed it's options by parent_id
*/
function display_childselectbox_by_fk(parent_id,child_obj){
	var k = 0;
	var len = child_obj.arr_parent_id.length;
	child_obj.length=0;
	child_obj.options[k] = new Option("--Chọn Phường/xã--");
	child_obj.options[k].value = '';
	for (i=0; i<len; i++) 
	{			
		if (child_obj.arr_parent_id[i] == parent_id || parent_id == "")
		{
			child_obj.options[k+1] = new Option(child_obj.arr_text[i]);
			child_obj.options[k+1].value = child_obj.arr_id[i];
			k=k+1;
			
		}		
		//if (k>0) child_obj.options[0].selected;\		
	}
	
}
function display_childselectbox_by_fk1(parent_id,child_obj){
	var k = 0;
	var len = child_obj.arr_parent_id.length;
	child_obj.length=0;
	child_obj.options[k] = new Option("--Chọn Đường/phố--");
	child_obj.options[k].value = '';
	for (i=0; i<len; i++) 
	{			
		if (child_obj.arr_parent_id[i] == parent_id || parent_id == "")
		{
			child_obj.options[k+1] = new Option(child_obj.arr_text[i]);
			child_obj.options[k+1].value = child_obj.arr_id[i];
			k=k+1;			
		}		
		//if (k>0) child_obj.options[0].selected;\		
	}	
}
function onchange_land_district_selectbox_ajax(obj_parent){
	//try{		
		var v_land_district = document.forms(0).phuong_xa.value;
		var v_duong_pho = document.forms(0).thuoc_duong.value;	
		
		display_childselectbox_by_fk(obj_parent.value,document.forms(0).phuong_xa);
		set_selected(document.forms(0).phuong_xa,v_land_district);	
		
		display_childselectbox_by_fk1(obj_parent.value,document.forms(0).thuoc_duong);
		set_selected(document.forms(0).thuoc_duong,v_duong_pho);					
	//}catch(e){;}
} 

// Ham  get_appointed_change_date
	// Y nghia tu dong tinh ngay hen tra ket qua ung voi gia tri cua v_record_form
	// Tham so: v_record_form la hinh thuc cua ho so
	function  get_appointed_change_date(p_change_date){
 
		var     v_process_date = document.forms(0).hdn_process_date.value;	
 		var		date_now = new Date();
		var     yy = date_now.getYear();		 	
		if (p_change_date != ""){	 
  				get_appoint_date(document.forms(0).txt_received_date,p_change_date,document.forms(0).txt_appointed_date,yy);
				document.forms(0).hdn_change_date.value = p_change_date;
		}else{
  				get_appoint_date(document.forms(0).txt_received_date,v_process_date,document.forms(0).txt_appointed_date,yy);
				document.forms(0).hdn_change_date.value = "";
		}			
 	}

