/*------------BAT DAU TIM KIEM DU AN------------*/
function txt_search_project_keydown(f,p_goto_url){
	key = event.keyCode;
	if (key==13){
		btn_search_project_onclick(f,p_goto_url);
	}	
}
function btn_search_project_onclick(f,p_goto_url)
{
	v_search_text = f.txt_search_project.value;
	if (v_search_text!="" && v_search_text.length>1)
	{
		go_url = p_goto_url  + "&txt_search_project=" + v_search_text;
		window.location =  go_url ;
	}	
}

/*----------KET THUC TIM KIEM DU AN----------------*/


/////////////////////////// Cac ham JS duoc su dung trong modul quan tri danh muc ////////////////////// 
// Ham nay duoc goi khi NSD nhan chuot vao ten file dinh kem
// Ham nay mo mot cua so moi va thuc thi dsp_file_content.php
function filename_onclick(p_table, p_file_id_column, p_file_name_column, p_file_content_column,p_file_type_column, p_file_id, p_file_url){
	url = "../dsp_file_content.asp";
	url = url + "?file_id=" + p_file_id;
	url = url + "&table=" + p_table;
	url = url + "&file_id_column=" + p_file_id_column;
	url = url + "&file_name_column=" + p_file_name_column;
	url = url + "&file_content_column=" + p_file_content_column;
	url = url + "&file_type_column=" + p_file_type_column;
	url = url + "&file_url=" + p_file_url;
	open(url);
}

//ham xay dung menu dung
function write_vertical_menu(p_object_id,p_top,p_left){
	var v_count = p_object_id.length;
	if (v_count>0){
		for (var i=0; i<v_count ;i++){ //Xay dung menu cap 2
			if ((p_object_id[i].have_child>0)&&(p_object_id[i].level == 1)){
				with(milonic=new menuname(p_object_id[i].parent)){
					top = p_top;
					left = p_left;
					style = menuStyle;
					for (var j=0; j<v_count ;j++){
						if ((p_object_id[i].menu == p_object_id[j].parent)&&(p_object_id[j].menu != p_object_id[j].parent)){
							aI("text=" + p_object_id[j].name + ";url=" + p_object_id[j].href + ";status="+p_object_id[j].name+";");
						}
					}
				}
			}
		}
	}
	drawMenus();
}
function see_article_from_date(f, p_index_of_from_date, p_menuid, p_parent_menuid, p_subject){
	v_date_value = eval("f.from_date_" + p_index_of_from_date + ".value");
	if (v_date_value!="")
	{
		window.location = "?menuid=" + p_menuid + "&parent_menuid=" + p_parent_menuid + "&fuseaction=" + p_subject + "&from_date=" + euro_us(v_date_value) + "&show_date=1" ;
	}
}
function check_keypress(f,p_fuseaction){
	if (event.keyCode==13){
		search_onclick_frame(f,p_fuseaction);
	} else {
		key = event.keyCode;
	}
}

function search_onclick(f,p_fuseaction)
{
	if (f.txt_search.value!="" && f.txt_search.value.length>1)
	{
		s = new String(window.parent.location);
		go_url = s.substring(0, s.lastIndexOf("index.asp")) + "?txt_search=" + f.txt_search.value + "&fuseaction=" + p_fuseaction;
		//alert(go_url);
		window.location= go_url;
	}	
}

function search_onclick_frame(f,p_fuseaction)
{
	if (f.txt_search.value!="" && f.txt_search.value.length>1)
	{
		s = new String(window.parent.location);
		go_url = s.substring(0, s.lastIndexOf("index.asp")) + "?txt_search=" + f.txt_search.value + "&fuseaction=" + p_fuseaction;
		//alert(go_url);
		window.location= go_url;
		
	}	
}

function advance_search_onclick(f,p_fuseaction)
{
	if (f.txt_search.value!="" && f.txt_search.value.length>1)
	{
		s = new String(window.parent.location);
		go_url = s.substring(0, s.lastIndexOf("index.asp")) + "?txt_search=" + f.txt_search.value + "&fuseaction=" + p_fuseaction;
		//alert(go_url);
		chk_check = '';
		for (i=0;i<f.chk_check.length;i++) {
				if (f.chk_check[i].checked) {
					chk_check = chk_check + f.chk_check[i].value + ',';
				}
		}
		window.top.location =  go_url + '&chk_check=' + chk_check;
		//submit();
		
	}	
}

function counter(f,p_fuseaction)
{
	selected=0;
	for (i=0;i<f.opt_answer.length;i++)
	{
		if (f.opt_answer(i).checked)
		{
			selected=1;
			break;
		}	
	}
	if (selected==1)
	{
		go_url = "?type=COUNTER&fuseaction=" + p_fuseaction + "&answer_id=" + f.opt_answer(i).value;
		window.location =  go_url ;
	}	
}

function display_result(p_question_id)
{
	go_url = "Counter/dsp_counter_result.asp?question_id=" + p_question_id
	window.open(go_url,null,"top=10,left=10,height=370,width=680,status=no,toolbar=no,scrollbars=yes,menubar=yes,location=no,directories=0,fullscreen:yes;");
}

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, 0, 0, 0, 0, 0);
	else{
		window.parent.location = p_url;	
	}
}

function goto_url_frame(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;	
}

function onchange_link(f)
{
	if (f.sele_link.value=="-2")
		return;
	for (i=0; i<f.sele_link.length; i++) 
	{
		if (f.sele_link.options[i].selected) 
		{
			if (f.sele_link.options[i].new_win=="1")
				open_me(f.sele_link.options[i].goto_url, 0, 1, 1, 1, 1, 0, 1, 1, 300, 450, 0, 0);
			else
				window.parent.location = f.sele_link.options[i].goto_url;
			return;
		}		
	}
}	
function onchange_eservice(f)
{
	if (f.sele_eservice.value=="")
		return;
	for (i=0; i<f.sele_eservice.length; i++) 
	{
		if (f.sele_eservice.options[i].selected) 
		{
			if (f.sele_eservice.options[i].new_win=="1")
				open_me(f.sele_eservice.options[i].goto_url, 0, 1, 1, 1, 1, 0, 1, 1, 300, 450, 0, 0);
			else
				window.parent.location = f.sele_eservice.options[i].goto_url;
			return;
		}		
	}
}
// open new window with some value
function open_me(url, vStatus, vResizeable, vScrollbars, vToolbar, 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('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);
}

/*function to read doc of the article */
function read_doc(doc_id){
	/* Neu chay tren Internet or Intranet
	var url="cw-yenbai/vn/article/dsp_file_content.asp?id=" + doc_id;
	*/
	var url="article/dsp_file_content.asp?id=" + doc_id;
	var the_window;
	the_window=window.open(url,null,"");
	the_window.focus();
}

function btn_save_idea_onclick(f,fuse){
	if (!verify(f)){
		return false;
	}
	if(Trim(document.all.area_content.value)=="" ){
		alert("Ban phai nhap noi dung cau hoi");
		return;
	}
	f.action = "?type=QA&fuseaction=" + fuse ;
	f.submit();
}
function btn_save_news_onclick(f,fuse){
	if (!verify(f))
	return false;
	f.action = "?type=SENDNEWS&fuseaction= " + fuse ;
	f.submit();
}
//	Function set_selected set the i option to be checked if its value equals p_value
function set_selected(p_obj,p_value)
{
	for (i=0;i<p_obj.options.length;i++)
	{
		if (p_obj.options[i].value==p_value)
		{
			p_obj.options[i].selected = true;
			break;
		}	
	}
}
function DoCal(elTarget){
  if (showModalDialog)
  {
    var sRtn;
    sRtn = showModalDialog("../lib/calendar.htm","","dialogWidth=210pt;dialogHeight=180pt;status=no;scroll=no");
    if (sRtn!="")
      elTarget.value = sRtn;
  }
}  
function euro_us(theDate){
	strSeparator = ""
	if (theDate.indexOf("/")!=-1) strSeparator = "/";
	if (theDate.indexOf("-")!=-1) strSeparator = "-";
	if (theDate.indexOf(".")!=-1) strSeparator = ".";
	if (strSeparator == "")
		return "";
	parts=theDate.split(strSeparator);
	day=parts[0];
	month=parts[1];
	year=parts[2];
	return month + strSeparator + day + strSeparator + year.substr(0,4);
}

function resizeImageWithLink(max_width, width, height, objImage) {
	if (width > max_width)	{
		//alert (objImage.width + "||" + objImage.height);
		//objImage.realHeight = objImage.height;
		//objImage.realWidth = objImage.width;
		objImage.onclick = function () { openImage (objImage.src, height, width) };
		//objImage.width = max_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>Hinh anh</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 doShowOrHide (id) {
	obj = document.getElementById(id);
	//alert (obj.style.display);
	if (obj.style.display=='') {
		obj.style.display = "none";
	} else {
		obj.style.display = "";
	}
}