function btn_save_idea_onclick(f){
	if (!verify(f)){
		return false;
	}
	f.submit();
}
function resizeImageWithLink(max_width, width, height, objImage) {
	if (width > max_width)	{
		objImage.onclick = function () { openImage (objImage.src, height, width) };
		objImage.className = "image_link";
	}
}

function resizeImageWithoutLink(max_width, objImage) {
	if (objImage.width > max_width)	{
		objImage.width = max_width;
	}
}

function openImage(vLink, vHeight, vWidth)
{
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;

	if (sLink == '')
	{
		return false;
	}

	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<title>B&#225;o H&#7843;i Ph&#242;ng</title><body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="', 'Dong lai', '" border=0></a>');
	newwin.document.writeln('</body>');

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}

function goto_url(p_url,p_open_new_win)
{
	if (p_open_new_win==1)
		open_me(p_url, 0, 1, 1, 1, 1, 0, 1, 1, 300, 450, 0, 0);
	else{
		window.parent.location = p_url;	
	}
}

//Xu ly khi NSD nhan vao nut anh cua don vi chua cac function.
//Trong man hinh danh sach nguoi su dung cua mot ung dung (goi tu file dsp_all_function.php va dsp_all_staff_for_application)
function show_menu_on_parent_menu(img_obj){
	var v_count;
	//Thay doi anh hien thi cua modul
	var v_img_path = img_obj.src.substring(0, img_obj.src.lastIndexOf('/') + 1);
	if (img_obj.status == "on"){
		img_obj.status = "off";
		eval('img_obj.src = v_img_path + "close.gif"');
	}else{
		img_obj.status = "on";
		eval('img_obj.src = v_img_path + "open.gif"');
	}
	try{	
		//dat che do hien thi cho cac tr_function thuoc modul
		v_count = document.all.tr_menu.length;
		if (v_count){
			for (var i=0; i<v_count; i++){
				if (img_obj.status == "on"){
					if (eval('document.all.tr_menu[i].parent_menu == img_obj.parent_menu')){
						eval('document.all.tr_menu[i].style.display = "block"');
					}
				}else{
					if (eval('document.all.tr_menu[i].parent_menu == img_obj.parent_menu')){
						eval('document.all.tr_menu[i].style.display = "none"');
					}
				}
			}
		}else{
			if (img_obj.status == "on"){
				if (eval('document.all.tr_menu.parent_menu == img_obj.parent_menu')){
					eval('document.all.tr_menu.style.display = "block"');
				}
			}else{
				if (eval('document.all.tr_menu.parent_menu == img_obj.parent_menu')){
					eval('document.all.tr_menu.style.display = "none"');
				}
			}
		}
	}catch(e){;}
}

//Xu ly khi NSD nhan vao ten loai danh muc
function show_list_on_listtype(p_listtype_obj,p_row_obj){
	var v_count;
	
	if (p_listtype_obj.status == "on"){
		p_listtype_obj.status = "off";
	}else{
		p_listtype_obj.status = "on";
	}
	try{	
		//dat che do hien thi cho cac tr_user thuoc unit
		v_count = p_row_obj.length;
		if (v_count){
			for (var i=0; i<v_count; i++){
				if (p_listtype_obj.status == "on"){
					if (eval('p_row_obj[i].listtype == p_listtype_obj.listtype')){
						eval('p_row_obj[i].style.display = "block"');
					}
				}else{
					if (eval('p_row_obj[i].listtype == p_listtype_obj.listtype')){
						eval('p_row_obj[i].style.display = "none"');
					}
				}
			}
		}else{
			if (p_listtype_obj.status == "on"){
				if (eval('p_row_obj.listtype == p_listtype_obj.listtype')){
					eval('p_row_obj.style.display = "block"');
				}
			}else{
				if (eval('p_row_obj.listtype == p_listtype_obj.listtype')){
					eval('p_row_obj.style.display = "none"');
				}
			}
		}
	}catch(e){;}
}


function see_article_from_date(p_from_date_obj, p_website_id,p_menu_id, p_parent_menu_id, p_fuseaction)
{

	var v_date_value = p_from_date_obj.value;
	
	if (v_date_value!="")
	{
		window.location = "index.asp?website_id=" + p_website_id + "&menu_id=" + p_menu_id + "&parent_menu_id=" + p_parent_menu_id + "&fuseaction=" + p_fuseaction + "&from_date=" + (v_date_value) + "&show_date=1" ;
	}
}

function txt_search_keydown(form,p_goto_url){
	key = event.keyCode;
	if (key==13 && form.txt_search.value!="" && form.txt_search.value.length>1){
		btn_search_onclick(form,p_goto_url);
	}	
}
function btn_search_onclick(form,p_goto_url){

	if (form.txt_search.value!="" && form.txt_search.value.length>1){
		if (form.rad_search[0].checked){
			//Tim tren bao HP
			go_url = p_goto_url + "&txt_search=" + form.txt_search.value;
			window.location =  go_url ;			
		}
		else{
			//Tim tren Google
			form.action = "http://www.google.com/custom";
			form.method = "get";
			form.target = "_top"
			form.q.value = form.txt_search.value;
			form.submit();
		}
	}		
}


function txt_advance_search_keydown(form,p_goto_url){
	key = event.keyCode;
	if (key==13){
		btn_advance_search_onclick(form,p_goto_url);
	}	
}

function btn_advance_search_onclick(form,p_goto_url)
{
	if (form.txt_search.value!="" && form.txt_search.value.length>1){
		var v_menu_id_list;
		v_menu_id_list = checkbox_value_to_list(form.chk_menu_id,",");
		go_url = p_goto_url + "&txt_search=" + form.txt_search.value;
		go_url = go_url + "&menu_id_list=" + v_menu_id_list;
		window.location =  go_url ;
	}
}

function submit_vote(p_form_name,p_action)
{
	//p_action: 0: Vote or 1: View result;
	
	var frm = p_form_name;	
	if (p_action == 0){
		if (frm.hdn_vote_id.value == ""){
			alert('Hay chon mot trong cac muc truoc khi bieu quyet!');
			return;
		}
	}
	var j = 0;
	for (i=0; i < frm.elements.length - 2; i++){
		if(frm.elements[i].type=='radio'){
			j = j + 1; //options
		}
	}	
	var v_height = (j * 40) + 50;
	if (v_height < 250){
		v_height = 250;
	}
	var url = "poll/index.asp?poll_id=" + frm.hdn_poll_id.value;
		url += "&vote_id=" + frm.hdn_vote_id.value;
		url += "&fuseaction=" + p_action;
	window.open(url,'','scrollbars=yes,resizeable=no,locationbar=no,width=500,height='+v_height+',left='.concat((screen.width - 500)/2).concat(',top=').concat((screen.height - 250)/2));
}


function select_link_onchange(form){
	if (form.sel_link.value=="-1")
		return;
	for (i=0; i<form.sel_link.length; i++) 
	{
		if (form.sel_link.options[i].selected) 
		{
			if (form.sel_link.options[i].new_win=="1")
				open_me(form.sel_link.options[i].goto_url, 0, 1, 1, 1, 1, 0, 1, 1, 300, 450, 0, 0);
			else
				window.parent.location = form.sel_link.options[i].goto_url;
			return;
		}		
	}
}	
/*************************************************
*	Mo mot window popup va ghi noi dung ra cua so popup
**************************************************/

function print_alert(title,height, width, css_file_name,style, title_alert, content_alert,imageURL){
	content_alert = content_alert.replace('&#39;',"'");
	content_alert = content_alert.replace("&#34;",'"');
		
	winDef = 'status=no,resizable=yes,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(height).concat(',').concat('width=').concat(width).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - height)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - width)/2);
	newwin = open('', '_blank', winDef);
	newwin.document.writeln('<html>');
	newwin.document.writeln('<head>');
	newwin.document.writeln('<title>'+title+'</title>');
	newwin.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
	newwin.document.writeln('<link rel="stylesheet" href="' + css_file_name + '" type="text/css">');
	newwin.document.writeln('</head>');
	newwin.document.writeln('<body topmargin=3 leftmargin=0 marginheight=0 marginwidth=0 class=body_alert>');
	newwin.document.writeln('<table class="table_alert" align="center">');
	if(style==0){
		newwin.document.writeln('<tr>');
		newwin.document.writeln('<td class=alert_title>');
		newwin.document.writeln(title_alert);
		newwin.document.writeln('</td>');
		newwin.document.writeln('</tr>');
		
		newwin.document.writeln('<tr>');
		newwin.document.writeln('<td class=alert_content>');
		newwin.document.writeln(content_alert);
		newwin.document.writeln('</td>');
		newwin.document.writeln('</tr>');
	}else{	
			newwin.document.writeln('<tr>');
			newwin.document.writeln('<td class=alert_image>');
			arr_temp = imageURL.split(".");	
			file_type = arr_temp[arr_temp.length -1].toUpperCase();	
			if(file_type!="SWF"){
				newwin.document.writeln('<img src="', imageURL, '" alt="','" border=0>');
			}else{
				newwin.document.writeln('<object id="swf" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" >');
				newwin.document.writeln('<param name="movie" value="'+imageURL+'">');
				newwin.document.writeln('<param name="quality" value="high">');
				newwin.document.writeln('<embed name="swf" src="'+imageURL+'"');
				newwin.document.writeln('quality="high"');
				newwin.document.writeln('pluginspage="http://www.macromedia.com/go/getflashplayer"');
				newwin.document.writeln('type="application/x-shockwave-flash" >');
				newwin.document.writeln('</embed>');
				newwin.document.writeln('</object>');
			}			
			newwin.document.writeln('</td>');
			newwin.document.writeln('</tr>');
		}
	newwin.document.writeln('</table>');
	newwin.document.writeln('</body>');
	newwin.document.writeln('</html>');
	return false;
}

/*--------BAT DAU PHAN GUI TIN PHAN HOI-----*/
function btn_save_article_reply_onclick(form,p_fuseaction){
	if (!verify(form)){
		return false;
	}
	// Luu cac anh duoc Upload
	//if(remember_list()) {
		form.fuseaction.value = p_fuseaction;
		form.submit();
	//}
}

/* get file name from the full path */
function get_filename(strPath){
	i=strPath.lastIndexOf('\\') +1;
	return strPath.substring(i,strPath.length);
}

/*to get image and asign to list*/
function assign_filename(file_element,index){
	try{
		document.all.hdn_file_attach_location[index].value=get_filename(file_element.value);
	}catch(e){;}
}
/* to remember list of document & image inserted */
function remember_list(){
	var strList="";
	// file dinh kem
	for(i=0;i<document.all.hdn_file_attach_location.length;i++){
		if(document.all.hdn_file_attach_location[i].value!=""){
			// Kiem tra dinh dang file Upload co duoc phep khong
			if (!is_valid_upload_file_type(document.all.hdn_file_attach_location[i].value,_CONST_ATTACH_FILE_TYPE_UPLOAD,"","File đính kèm không đúng định dạng")){
				return false;
			}
			
			if (strList=="")
				strList=document.all.hdn_file_attach_location[i].value;
			else
				strList= strList + "," + document.all.hdn_file_attach_location[i].value;
		}
	}
	document.all.hdn_file_attach_list.value=strList;
	return true;
}


/*--------KET THUC PHAN GUI TIN PHAN HOI-----*/


/*--------BAT DAU XUAT BAN TIN BAI RA RSS-----*/
function rss_row_onclick(p_url,p_menu_id,p_hdn_obj,p_day_obj){
	var the_window;
	var time_type = p_hdn_obj.value;
	if (time_type=="OTHER"){
		if(!(isnum(p_day_obj.value))){
			alert('Ngay nhap vao phai la so nguyen duong!');
			return;
		}
		time_type = p_day_obj.value;
	}
	var v_url = p_url + "&menu_id=" + p_menu_id + "&time_type="+time_type;  
	the_window=window.open(v_url,null,"");
	the_window.focus();
}
function rad_time_type_onclick(p_rad_obj,p_day_obj,p_hdn_obj){
	if(p_rad_obj.value=="OTHER"){
		p_day_obj.style.display= "block";
	}else{
		p_day_obj.style.display= "none";		
	}
	p_hdn_obj.value =p_rad_obj.value;
}
function menu_onclick(p_url){
	var the_window;
	the_window=window.open(p_url,null,"");
	the_window.focus();
}
/*--------KET THUC XUAT BAN TIN BAI RA RSS-----*/


function showDialog(vLink, vWidth, vHeight)
{
return showWindow(vLink, false, true, true, false, false, false, true, true, vWidth, vHeight, 0, 0);
}

function showModalDialog(vLink, vWidth, vHeight)
{
return showWindow(vLink, false, false, false, false, false, false, true, true, vWidth, vHeight, 0, 0);
}

function showWindow(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vWidth, vHeight, vTop, vLeft)
{
var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;

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('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(sLink, '_blank', winDef);

if (typeof(vLink.href) != 'undefined')
{
	return false;
}
}

function show_hide_menu(p_tr_menu_obj){
	try{	
		var v_count = p_tr_menu_obj.length*1;
		if (v_count>0){
			for (var i=0; i<v_count; i++){
				p_tr_menu_obj[i].style.display = "block";
			}
		}else{
			p_tr_menu_obj.style.display = "block";
		}
	}catch(e){;}
}