//doc file rss
// Valid number 
function isnum(passedVal)
{
	if (passedVal == "")
	{
		return false;
	}
	for (i=0; i<passedVal.length; i++)
	{
		if(passedVal.charAt(i)< "0")
		{
			return false;
		}
		if (passedVal.charAt(i)> "9")
		{
			return false;
		}
	}
	return true;
}
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();
}
function rss_article_onclick(p_url){
	var the_window;
	the_window=window.open(p_url,null,"");
	the_window.focus();
}
function rss_file_attach_onclick(p_go_url,p_web_url,p_item_order){
	var the_window;
	var v_url;
	v_url = p_go_url+ "?web_url="+p_web_url+"&item_order="+p_item_order;
	the_window=window.open(v_url,null,"");
	the_window.focus();
}

//-----
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 = "index.asp?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){
	key = event.keyCode;
	if (key==13){
		search_onclick(f,p_fuseaction);
	}	
}
function search_onclick(f,p_fuseaction)
{
	if (f.txt_search.value!="" && f.txt_search.value.length>1)
	{
		go_url = "index.asp?text=" + f.txt_search.value + "&fuseaction=" + p_fuseaction;
		window.location =  go_url ;
	}	
}
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 = "index.asp?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, 1, 300, 450, 0, 0);
	else
		window.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.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.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){
	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;
	f.action = "index.asp?type=QA&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);
}