//<?php
function $(id) { return document.getElementById(id); }
function createXMLHttpRequestObject(){
	var xmlHttp;
	if(window.ActiveXObject){
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlHttp = false;
		}
	} else {
		try {
			xmlHttp = new XMLHttpRequest();
		} catch (e){
			xmlHttp = false;
		}
	}
	if (!xmlHttp)
		return null;
	else
		return xmlHttp;
}
/*****************************************************************/

var fBrw=(navigator.userAgent.indexOf('MSIE')!= -1 && navigator.userAgent.indexOf('Windows')!= -1);
//Xu ly menu
function ENEWS_MENU(){
	var attribute_string = '';
	this.SetData = SetData;

	this.parent_channel_id = parent_channel_id;
	this.channel_id = channel_id;
	this.level = level;
	this.have_child = have_child;
	//this._get_attr_value=_get_attr_value;

	function SetData( str ){
        attribute_string = str;
    }


    /**
     * Lay parent_channel_id tu xau thuoc tinh
     */
	function parent_channel_id(){
		str =  attribute_string.match(/parent_channel_id:[0-9]+;/);
		if (str == null){return 0;}
		str = str.toString();
		str = str.match(/:[0-9]+;/);
		str = str.toString();
		str = str.replace(':','');
		str = str.replace(';','');
		return str;
	}

	/**
     * Lay channel_id tu xau thuoc tinh
     */
	function channel_id(){
		str =  attribute_string.match(/channel_id:[0-9]+;/);
		if (str == null){return 0;}
		str = str.toString();
		str = str.match(/:[0-9]+;/);
		str = str.toString();
		str = str.replace(':','');
		str = str.replace(';','');
		return str;
	}

	/**
     * Lay level tu xau thuoc tinh
     */
	function level(){
		str =  attribute_string.match(/level:[0-9]+;/);
		if (str == null){return 0;}
		str = str.toString();
		str = str.match(/:[0-9]+;/);
		str = str.toString();
		str = str.replace(':','');
		str = str.replace(';','');
		return str;
	}

	/**
     * Lay have_child tu xau thuoc tinh
     */
	function have_child(){
		str =  attribute_string.match(/have_child:[0-9]+;/);
		if (str == null){return 0;}
		str = str.toString();
		str = str.match(/:[0-9]+;/);
		str = str.toString();
		str = str.replace(':','');
		str = str.replace(';','');
		return str;
	}
}
/**************************************************/
//ham xay dung menu dung
function write_vertical_menu(p_object_id,p_top,p_left){

	if (p_object_id.length) {
		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].channel_id)){
						top = p_top;
						left = p_left;
						style = menuStyle;
						for (var j=0; j<v_count ;j++){
							if (p_object_id[j].parent_channel_id == p_object_id[i].channel_id){
								aI("text=" + p_object_id[j].name + ";url=" + p_object_id[j].href + ";");
							}
						}
					}
				}
			}
		}
	}
	drawMenus();
}

function write_vertical_menu_for_mozilla(p_type,p_top,p_left){
	var anchors = document.getElementsByTagName('A');
	if (anchors.length){
		for(i = 0; i < anchors.length; i++){
			if (anchors[i].type == p_type){
				str_attributes = anchors[i].id;

				var channel_obj = new ENEWS_MENU();
				channel_obj.SetData(str_attributes);

				v_parent_channel_id = channel_obj.parent_channel_id();
				v_channel_id 		= channel_obj.channel_id();
				v_level				= channel_obj.level();
				v_have_child		= channel_obj.have_child();
				if ((parseInt(v_have_child) > 0) && (parseInt(v_level) == 1)){
					with(milonic=new menuname(v_channel_id)){
						top = p_top;
						left = p_left;
						style = menuStyle;

						for (var j=i+1; j<anchors.length; j++){
							if (anchors[j].type == p_type){
								str_attributes2 = anchors[j].id;
								var level2_channel_obj = new ENEWS_MENU();
								level2_channel_obj.SetData(str_attributes2);

								v_parent_channel_id2 = level2_channel_obj.parent_channel_id();
								v_level2			 = level2_channel_obj.level();
								if ((parseInt(v_level2) == 2) && (parseInt(v_parent_channel_id2) == parseInt(v_channel_id))){
									aI("text=" + anchors[j].name + ";url=" + anchors[j].href + ";");
								}
								else {
									break;
								}
							}
						}
					}
				}
			}
		}
	}
	drawMenus();
}
//==============================================================================================================

//ham xay dung menu ngang
function write_horizontal_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 1
			if ((p_object_id[i].have_child>0)&&(p_object_id[i].level == 0)){
				with(milonic=new menuname(p_object_id[i].parent_channel_id)){
					top = p_top;
					left = p_left;
					alwaysvisible=0;
					style = menuStyle;
					for (var j=0;j<v_count;j++){
						if (p_object_id[j].parent_channel_id == p_object_id[i].channel_id){
							if (p_object_id[j].have_child>0){
								aI("text=" + p_object_id[j].name + ";showmenu="+ p_object_id[j].parent_channel_id +";url="+ p_object_id[j].href +";status="+p_object_id[j].name+";");
							}else{
								aI("text=" + p_object_id[j].name + ";url=" + p_object_id[j].href + ";status="+p_object_id[j].name+";");
							}
						} //end if
					}//end for
				}//end with
			}
		}//end for
		for (var j=0;j<v_count;j++){ //Xay dung menu cap 2
			if ((p_object_id[j].have_child>0) && (p_object_id[j].level == 1)){
				with(milonic=new menuname(p_object_id[j].parent_channel_id)){
					style = menuStyle;
					for (var k=0;k<v_count;k++){
						if ((p_object_id[k].parent_channel_id == p_object_id[j].channel_id) && (p_object_id[k].level == 2)){
							aI("text=" + p_object_id[k].name + ";url=" + p_object_id[k].href + ";");
						} //end if
					}//end for
				}//end with
			}
		}//end for
	}
	drawMenus();
}
//==============================================================================================================
//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, 1, 0, 1, 1, 350, 550, 0, 0);
	else{
		//document.parentWindow.location = p_url;
		//alert (document.location);
		if (p_open_new_win==2)
			window.top.location = p_url;
		else{
			window.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 thuc hien khi goi Website lien ket
function sel_web_link_onchange(p_sel){
	var v_position = p_sel(p_sel.selectedIndex).position;
	var v_link = p_sel(p_sel.selectedIndex).value;
	goto_url(format_url(v_link),v_position);
}
//==============================================================================================================
//Ham dinh dang lai dia chi url
function format_url(p_str){
	if (p_str!=""){
		var s = p_str.split("://");
		if (s[0]=="http"){
			return 	p_str;
		}else{
			return "http://" + p_str;
		}
	}
}
//==============================================================================================================
//Ham xem anh
function openImage(vLink, vHeight, vWidth,vlink_css)
{
	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('<html>');
	newwin.document.writeln('<head>');
	newwin.document.writeln('<link rel="stylesheet" type="text/css" media="all" href="',vlink_css,'">');
	newwin.document.writeln('<title>ISA-ENEWS</title>');
	newwin.document.writeln('</head>');
	newwin.document.writeln('<body style="margin:0px">');
	newwin.document.writeln('<table cellpadding="0" cellspacing="0" class="detail_image_article" border="0"> ');
	newwin.document.writeln('<tr><td class="td_top_center_image_article" colspan = "3">&nbsp;</td></tr>');
	newwin.document.writeln('<tr><td class="td_left_image_article">&nbsp;</td><td class="image_article"> ');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="Dong lai" border="0" id="isa_image" class="image_article_logo"></a>');

	newwin.document.writeln('</td><td class="td_right_image_article">&nbsp;</td></tr>');
	newwin.document.writeln('<tr><td class="td_bottom_left_image_article">&nbsp;</td><td class="td_bottom_center_image_article">&nbsp;</td><td class="td_bottom_right_image_article">&nbsp;</td></tr>');
	newwin.document.writeln('</table>');
	newwin.document.writeln('</body></html>');

	var v_script = '<scr' + 'ipt language="javascript">';
	v_script += 'var w = document.getElementById("isa_image").width;';
	v_script += 'var h = document.getElementById("isa_image").height;';
	v_script += 'w += 20;';
	v_script += 'h += 85;';
	v_script += 'window.resizeTo(w,h);';
	v_script += '</scr' + 'ipt>';
	newwin.document.writeln(v_script);

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}
function resizeImageWithLink(max_width, width, height, objImage) {
	if (width > max_width)	{
		objImage.onclick = function () { openImage (objImage.src, height, width) };
		objImage.className = "image_link";
	}
}
//==================================================================================
function show_window_to_print(p_goto_url,p_fuseaction,p_article_id)
{
	v_url = p_goto_url + "?hdn_article_id=" +  p_article_id + "&fuseaction=" +  p_fuseaction + "&modal_dialog_mode=1" ;
	sRtn = window.open(v_url,"","");
	if (!sRtn) return;
}
//==================================================================================
function show_window_to_send_email(p_goto_url,p_fuseaction,p_article_id,p_width,p_height)
{
	v_url = p_goto_url + "?fuseaction=" +  p_fuseaction + "&hdn_article_id=" + p_article_id + "&modal_dialog_mode=1" ;
	sRtn = window.open(v_url,"","dialogWidth="+p_width+";dialogHeight="+p_height+";dialogTop=80pt;status=no;scroll=no;");
	if (!sRtn) return;
}
// ===================================================================================
function btn_send_email_onclick(p_form_name){
	if (verify(p_form_name)){
		p_form_name.submit();
	}
}

function btn_send_reply_onclick(p_form_name){
	if (verify(p_form_name)){
		p_form_name.submit();
	}
}

function btn_send_select_onclick(p_form_name){
    var v_article_id    = p_form_name.hdn_article_id.value;
    var v_mark          = p_form_name.sel_select_mark.value;
    var v_url = 'article/act_rate_article.php?article_id='+v_article_id+'&mark='+v_mark;

	var req = createXMLHttpRequestObject();
	var d = (new Date());

	if (req){
        req.onreadystatechange = function( ) {
			if ((req.readyState==4) && (req.status==200)) {
				xmlDoc = req.responseXML;
			    xmlObj = xmlDoc.getElementsByTagName("count");
                document.getElementById("rate_count").innerHTML = xmlObj[0].firstChild.nodeValue;

                xmlObj = xmlDoc.getElementsByTagName("mark");
                document.getElementById("rate_mark").innerHTML = xmlObj[0].firstChild.nodeValue;
			} 
		}
		req.open("GET", v_url, true);
		req.send(null);
	}
}

function btn_send_article_onclick(p_form_name){
	if (verify(p_form_name)){
		p_form_name.submit();
	}
}


function btn_send_question_onclick(p_form_name,p_hdn_tag_obj,p_hdn_value_obj){
	_save_xml_tag_and_value_list(p_form_name, p_hdn_tag_obj, p_hdn_value_obj, true);
	if (verify(p_form_name)){
		p_form_name.submit();
	}
}

// Xu ly su kien gui dang ky nhan tin nong qua email
function btn_send_mail_register_onclick(p_form_name,p_hdn_tag_obj,p_hdn_value_obj,p_checkbox_obj){
	if (verify(p_form_name)){
		_save_xml_tag_and_value_list(p_form_name, p_hdn_tag_obj, p_hdn_value_obj, true);
		if (!checkbox_value_to_list(p_checkbox_obj,",")){
			alert("Ban phai chon chuyen muc dang ky nhan tin");
			return;
		}
		// lay danh sach chuyen muc va chuyen trang
		var v_channel_id_list = "";
		var v_website_id_list = "";
		var v_old_website_id =0;
		try{
			if (!p_checkbox_obj.length){
				if (p_checkbox_obj.checked)	{
					v_website_id_list = p_checkbox_obj.website_id
					v_channel_id_list = p_checkbox_obj.value;
				}
			}else{
				for(i=0;i<p_checkbox_obj.length;i++){
					if (p_checkbox_obj[i].checked){
						if(p_checkbox_obj[i].website_id !=v_old_website_id ){ // cac chuyen muc cua chuyen trang khac chuyen trang hien tai
							v_old_website_id = p_checkbox_obj[i].website_id;
							if(v_website_id_list==""){
								v_website_id_list = p_checkbox_obj[i].website_id;
							}else{
								v_website_id_list = list_append(v_website_id_list,p_checkbox_obj[i].website_id,",");
							}
							v_channel_id_list = list_append(v_channel_id_list,p_checkbox_obj[i].value,_LIST_DELIMITOR);
						}else{  // cac chuyen muc cua cung mot chuyen trang
							v_channel_id_list = list_append(v_channel_id_list,p_checkbox_obj[i].value,",");
						}
					}
				}
			}
		}catch(e){;}
		p_form_name.hdn_website_id_list.value = v_website_id_list;
		p_form_name.hdn_channel_id_list.value = v_channel_id_list;
		p_form_name.submit();
	}
}

//**********************************************************************************************************************
function show_modal_dialog_qa_cate_onclick(p_goto_url,p_fuseaction, p_text_name_obj, p_hdn_obj, p_hdn_owner_id,p_height,p_width,p_position){
if (!p_height) p_height = "280pt";
	if (!p_width) p_width = "450pt";
	v_url = _DSP_MODAL_DIALOG_URL_PATH;
	v_url = v_url + "?goto_url=" + p_goto_url + "&fuseaction=" + p_fuseaction + "&hdn_position_id=" + p_position + "&modal_dialog_mode=1"
	v_url = v_url+ "&" + randomizeNumber();
	sRtn = showModalDialog(v_url,"","dialogWidth="+p_width+";dialogHeight="+p_height+";dialogTop=80pt;status=no;scroll=no;");
	if (!sRtn) return;
	arr_value = sRtn.split(_LIST_DELIMITOR);
	p_hdn_obj.value = arr_value[0];
	p_text_name_obj.value = arr_value[2];
}
//=========================================================================================================
function btn_send_onclick(p_fuseaction,p_type,p_menu_id){
	if (_MODAL_DIALOG_MODE==1)
		document.forms(0).action = "index.php?modal_dialog_mode=1";
	else
		document.forms(0).action = "index.php?menu_id="+ p_menu_id;

	if (verify(document.forms(0))){
		document.forms(0).hdn_type.value = p_type;
		document.forms(0).fuseaction.value = p_fuseaction;
		document.forms(0).submit();
	}
}
function counter_onclick(p_type_back,p_fuseaction_back,p_menu_id,p_fuseaction,rad_obj){
	var selected=0;
	var go_url = "";
	var v_count = rad_obj.length;
	if (v_count>0){
		for (i=0;i<rad_obj.length;i++){
			if (rad_obj(i).checked){
				selected = rad_obj(i).value;
				break;
			}
		}
	}else{
		if (rad_obj.checked){
			selected = rad_obj.value;
		}
	}
	if (selected>0){
		go_url = "index.php?hdn_type=VOTE&fuseaction=" + p_fuseaction + "&hdn_vote_answer_id=" + selected + "&menu_id=" + p_menu_id+ "&hdn_type_back=" + p_type_back + "&hdn_fuseaction_back=" + p_fuseaction_back;
		//alert(go_url);
		window.location =  go_url ;
	}else{
		alert("Ban phai chon cau tra loi tuong ung voi cau hoi");
		return;
	}
}
function display_result(p_fuseaction,p_vote_question_id)
{
	go_url = "index.php?hdn_type=VOTE&fuseaction="+p_fuseaction + "&hdn_vote_question_id=" + p_vote_question_id + "&modal_dialog_mode=1";
	sRtn = showModalDialog(go_url,"","dialogWidth=450pt;dialogHeight=340pt;dialogTop=80pt;status=no;scroll=no;");
	if (!sRtn) return;
}
//==============================================================================================================
// Ham thuc hien khi nhan nut chuyen den chu de thao luan nao do trong dien dan
function btn_goto_onclick(p_sel,p_type,p_fuseaction,p_menu_id,p_no_menu){
	var v_id = p_sel(p_sel.selectedIndex).value;
	p_url = "index.php?hdn_type=" + p_type + "&fuseaction=" + p_fuseaction+ "&hdn_discussion_topic_id=" + v_id + "&menu_id=" + p_menu_id + "&no_menu=" + p_no_menu;
	goto_url(p_url,0);
}
//=============================================================================================================
//Ham thuc hien khi nhan nut chuyen sang chuyen muc khac
function sel_channel_link_onchange(p_sel){
	var v_position = p_sel(p_sel.selectedIndex).position;
	var v_link = p_sel(p_sel.selectedIndex).value;
	var v_menu_id = p_sel(p_sel.selectedIndex).id;
	v_link = v_link + "&menu_id=" + v_menu_id;
	goto_url(format_url(v_link),v_position);
}
//==============================================================================================================
// Ham thuc hien khi nhan nut chuyen den chu de thao luan nao do trong dien dan
function btn_search_onclick(f,p_website_id,p_search_type,p_search_website_id,p_search_channel_id){
	if (f.txt_search.value!="" && f.txt_search.value.length>1){
		go_url = "index.php?type=SEARCH&txt_search=" + f.txt_search.value + "&website_id=" + p_website_id ;
		go_url = go_url + "&search_type=" + p_search_type +  "&search_website_id=" + p_search_website_id +  "&search_channel_id=" + p_search_channel_id;
		window.location =  go_url ;
	}
}
//=================================================================================================================
function txt_search_keypress(f,p_website_id,p_search_type,p_search_website_id,p_search_channel_id){
	key = event.keyCode;
	if (key==13){
		btn_search_onclick(f,p_website_id,p_search_type,p_search_website_id,p_search_channel_id);
	}
}



//================================================================================================================
function goto_page_onclick(p_type,p_fuseaction,p_searchtext,p_direction){
	var	go_url = "index.php?txt_searchtext=" + p_searchtext + "&fuseaction=" + p_fuseaction + "&hdn_type="+p_type;
	if (p_direction=="NEXT"){
		go_url = go_url + "&hdn_article_id="+document.all.hdn_buttom_id.value + "&hdn_direction=NEXT";
		window.location =  go_url ;
	}
	if (p_direction=="PREVIOUS"){
		go_url = go_url + "&hdn_article_id="+document.all.hdn_top_id.value + "&hdn_direction=PREVIOUS";
		window.location =  go_url ;
	}
	//alert(document.all.hdn_top_id.value);
}
function node_name_onclick(node,select_parent){
	if ((select_parent=='false') & (_MODAL_DIALOG_MODE==1)){
		if(node.level==0){return;}
	}
	if (_MODAL_DIALOG_MODE==1){
		return_value = node.id + _LIST_DELIMITOR + node.value + _LIST_DELIMITOR + node.innerText;
		window.returnValue = return_value;
		window.close();
	}
	document.forms(0).hdn_item_id.value=node.id;
	document.forms(0).submit();
}


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 btn_view_article_from_date_onclick(p_from_date_obj, p_website_id,p_channel_id, p_parent_channel_id, p_fuseaction){
	var v_date_value = p_from_date_obj.value;

	if (v_date_value!=""){
		window.location = "index.php?website_id=" + p_website_id + "&channel_id=" + p_channel_id + "&parent_channel_id=" + p_parent_channel_id + "&fuseaction=" + p_fuseaction + "&from_date=" + (v_date_value);
	}
}

/////////////////////////// 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_id, p_file_url){
	url = _DSP_FILE_CONTENT_URL_PATH;
	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_url=" + p_file_url;
	open(url);
}

/*
Tao object XmlHttpRequest. Vi trinh duyet IE va Mozilla ap dung ky thuat nay theo 2 cach khac nhau,
de dam bao tinh tuong thich, chung ta se can phai kiem tra xem nguoi dung dang su dung trinh duyet nao
va tao doi tuong XmlHttpRequest theo phuong thuc ho tro boi trinh duyet do.
*/
var req;
function retrieveURL(url)
{
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}

/*
Ham (function) processReqChange la ham chiu trach nhiem chinh xu ly viec goi du lieu va nhan du lieu.
Cac buoc ma ham nay thuc hien:
1. Doi cho den khi may chu gui phan hoi thong bao la no da xu ly xong
2. Doc thong bao tu may chu (may chu se gui status=200 nen xu ly thanh cong, 404 neu file khong tim thay,...).
Neu may chu noi la xu ly thanh cong, tiep tuc buoc tiep theo
3. Nhan du lieu ve duoi dang XML. Su dung DOM de phan tich du lieu XML.
File XML nhan ve se cung cap cac thong tin:
	a) Ten ham goi ban dau (giua 2 the <method> va </method>)
	b) Gia tri thong bao ket qua thuc hien ham do (giua 2 the <result> va </result>)
Biet duoc 2 thong tin tren, goi lai ham do (eval) voi gia tri tra ve de cap nhap giao dien
Vi du, ham checkName() goi thong tin len may chu hoi, may chu tra ve ten ham la checkName va ket qua la 1. Ta se goi:
	checkName('',1);
*/
function processReqChange()
{
	if (req.readyState == 4) { // Complete
	  if (req.status == 200) { // OK response
		document.getElementById("selectbox_search_in_channel").innerHTML = req.responseText;
	  } else {
		alert("Problem: " + req.statusText);
	  }
	}
}

function sel_website_onchange(p_goto_url,p_search_website_id,p_search_channel_id) {
	url  = p_goto_url + '?search_website_id=' + p_search_website_id + '&search_channel_id=' + p_search_channel_id;
	var Html = retrieveURL(url);
	/*if(p_search_website_id ==0){
		document.getElementById("tr_search_in_channel").style.display = 'none';
	}else{
		document.getElementById("tr_search_in_channel").style.display = 'block';
	}*/
	// we would return false if the Browser wasn't supported. This has been ommitted from the
	// sample article.
	return true;
}

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 rss_row_onclick(p_url,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 + "&time_type="+time_type;
	the_window=window.open(v_url,null,"");
	the_window.focus();
}

/*
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('<html><head><title>ISA-ENEWS</title></head><body style="margin:0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="ISA-ENEWS', '" border="0" id="image_article"></a>');
	newwin.document.writeln('</body></html>');

	var v_script = '<scr' + 'ipt language="javascript">';
	v_script += 'var w = document.getElementById("image_article").width;';
	v_script += 'var h = document.getElementById("image_article").height;';
	//if (fBrw){
		v_script += 'h += 20;';
	//}
	v_script += 'window.resizeTo(w,h);';
	v_script += '</scr' + 'ipt>';
	newwin.document.writeln(v_script);

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}
*/

function writeTime(s)
{
	var mydate;
	if (s)
		mydate = new Date(s);
	else
		mydate = new Date();

	var year = mydate.getYear()
	if (year < 1000)
		year += 1900
	var month = mydate.getMonth() + 1
	if (month < 10)
		month = "0" + month
	var day = mydate.getDate()
	if (day < 10)
		day = "0" + day

	var dayw = mydate.getDay()

	var hour = mydate.getHours()
	if (hour < 10)
		hour = "0" + hour

	var minute=mydate.getMinutes()
	if (minute < 10)
		minute = "0" + minute
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y")
	document.write(dayarray[dayw]+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute + " GMT+7")
}

function show_hide_menu(p_parent_id,p_chanel_id){

		eval("document.getElementById("+p_parent_id+").className='level1_selected'");
		eval("document.getElementById("+p_parent_id+").status='active'");
		eval("document.getElementById("+p_parent_id+").onmouseout.className='level1_selected'");
		eval("document.getElementById("+p_parent_id+").onmouseover.className='level1_selected'");

		if(eval("document.getElementById("+p_parent_id+").have_child")>0){
			var v_length = eval("document.all.tr_"+p_parent_id+".length");
			if(v_length > 1){
				for(i=0;i<v_length;i++){
					eval("document.all.tr_"+p_parent_id+"["+i+"].style.display='block'");
					if(eval("document.all.tr_"+p_parent_id+"["+i+"].chanel_id=="+p_chanel_id)){
						eval("document.all.tr_"+p_parent_id+"["+i+"].status_level2='active'");
						eval("document.all.tr_"+p_parent_id+"["+i+"].className='level2_selected'");
						eval("document.all.tr_"+p_parent_id+"["+i+"].onmouseout.className='level2_selected'");
						eval("document.all.tr_"+p_parent_id+"["+i+"].onmouseover.className='level2_over'");
					}

				}
			}else{
				eval("document.all.tr_"+p_parent_id+".style.display='block'");
			}
		}

	}

function onclick_next_image(p_image_id,p_image_count){
	var next_image_id=p_image_id+1;
	eval("document.all.image_id_"+p_image_id+".style.display='none'");
	eval("document.all.image_id_"+next_image_id+".style.display='block'");
	if(parseInt(next_image_id)==parseInt(p_image_count)){
			eval("document.all.next_image_"+next_image_id+".style.display='none'");
		}
	}

function onclick_previous_image(p_image_id){
	var previous_image_id=p_image_id-1;
	eval("document.all.image_id_"+p_image_id+".style.display='none'");
	eval("document.all.image_id_"+previous_image_id+".style.display='block'");
}
function btn_vote_left(p_position,p_fuseaction,toltal_answer){
	var v_height = 140 + toltal_answer * 28;
	var v_width = 512;
	var v_top = (screen.height - v_height)/2;
	var v_left = (screen.width - v_width)/2;
	if(eval('document.frm_vote_left_name.rad_vote_'+p_position+'.length')){
		var v_rad_vote_length = eval('document.frm_vote_left_name.rad_vote_'+p_position+'.length');
		var flags = false;
		for(i=0;i<v_rad_vote_length;i++){
			if(eval('document.frm_vote_left_name.rad_vote_'+p_position+'['+i+'].checked')){
				var answer_id = eval('document.frm_vote_left_name.rad_vote_'+p_position+'['+i+'].value');
				flags = true;
			}
		}
	}
	if(!flags && p_fuseaction != 'DISPLAY_RESULT_VOTE'){
		alert('Ban phai chon mot phuong an!');
	}
	else{
		p_url = 'index.php?type=VOTES&modal_dialog_mode=1&fuseaction='+p_fuseaction+'&hdn_question_id='+p_position+'&hdn_answer_id='+answer_id;
		open(p_url, '_blank', 'status=no,toolbar=no,resizable=yes,scrollbars=no,height='+v_height+',width='+v_width+',top='+v_top+',left='+v_left);
	}
}
function btn_vote_right(p_position,p_fuseaction, toltal_answer){
	var v_height = 140 + toltal_answer * 28;
	var v_width = 512;
	var v_top = (screen.height - v_height)/2;
	var v_left = (screen.width - v_width)/2;
	if(eval('document.frm_vote_right_name.rad_vote_'+p_position+'.length')){
		var v_rad_vote_length = eval('document.frm_vote_right_name.rad_vote_'+p_position+'.length');
		var flags = false;
		for(i=0;i<v_rad_vote_length;i++){
			if(eval('document.frm_vote_right_name.rad_vote_'+p_position+'['+i+'].checked')){
				var answer_id = eval('document.frm_vote_right_name.rad_vote_'+p_position+'['+i+'].value');
				flags = true;
			}
		}
	}
	if(!flags && p_fuseaction != 'DISPLAY_RESULT_VOTE'){
		alert('Ban phai chon mot phuong an!');
	}
	else{
		p_url = 'index.php?type=VOTES&modal_dialog_mode=1&fuseaction='+p_fuseaction+'&hdn_question_id='+p_position+'&hdn_answer_id='+answer_id;
		open(p_url, '_blank', 'status=no,toolbar=no,resizable=yes,scrollbars=no,height='+v_height+',width='+v_width+',top='+v_top+',left='+v_left);
	}
}

// Cac ham cua chuc nang Rao vat
function image_change(obj, order){
	eval('obj.form.classifield_ads_image'+order+'.src = obj.value');
	eval('obj.form.hdn_file_image'+order+'.value = 1');
	eval('document.all.rid_classified_ads_file'+order+'.style.display = "none"');
	eval('document.all.rid_classified_ads_file1_label.style.display = "none"');
}
function image_change_choose(obj){
	for(i=1;i<=3;i++){
		eval('document.all.rid_classified_ads_file'+i+'.style.display = "none"');
	}
	eval('document.all.rid_classified_ads_file1_label.style.display = "block"');
	eval('document.all.rid_classified_ads_file'+obj.name+'.style.display = "block"');
}
function delete_image(obj){
	eval('obj.form.classifield_ads_image'+obj.name+'.src = "../images/blank.gif"');
	eval('obj.form.hdn_file_image'+obj.name+'.value = 0');
}
function btn_send_classifeid_ads(obj){
	if(check_value_inform(obj.form)){eval('obj.form.submit()');}
}
function check_value_inform(form_name){
	if (form_name.sel_cate.value == '')
	{
		alert('Ban phai xac dinh linh vuc rao vat!');
		form_name.sel_cate.focus();
		return false;
	}
	if (form_name.txt_title.value == '')
	{
		alert('Ban phai xac dinh tieu de tin rao vat!');
		form_name.txt_title.focus();
		return false;
	}
	if (form_name.txta_content.value == '')
	{
		alert('Ban phai xac dinh noi dung tin rao vat!');
		form_name.txta_content.focus();
		return false;
	}
	if (form_name.sel_classifield_type.value == '')
	{
		alert('Ban phai xac dinh loai rao vat!');
		form_name.sel_classifield_type.focus();
		return false;
	}

	if (form_name.txt_sender_name.value == '')
	{
		alert('Ban phai xac dinh ten nguoi dang ki rao vat!');
		form_name.txt_sender_name.focus();
		return false;
	}
	if (form_name.txt_sender_email.value == '')
	{
		alert('Ban phai xac dinh email cua nguoi dang ki rao vat!');
		form_name.txt_sender_email.focus();
		return false;
	}
	if(!isemail(form_name.txt_sender_email.value)){
		alert('Dia chi email khong hop le, vui long nhap lai email!');
		form_name.txt_sender_email.focus();
		return false;
	}
	return true;
}
function btn_classified_ads_cacel_onclick(obj,form_action){
	obj.form.action = form_action;
	obj.form.submit();
}
function sel_cate_onchange(obj,form_action){
	obj.form.action = form_action;
	obj.form.submit();
}


function txt_search_btn_search_clasified_ads_keypress(f,p_website_id,p_search_type,p_search_website_id,p_search_channel_id){
	key = event.keyCode;
	if (key==13){
		btn_search_clasified_ads_onclick(f,p_website_id,p_search_type,p_search_website_id,p_search_channel_id);
	}
}

function btn_search_clasified_ads_onclick(f,p_website_id,p_search_type,p_search_website_id,p_search_channel_id){
	if (f.txt_classified_ads_search.value!="" && f.txt_classified_ads_search.value.length>1){
		go_url = "index.php?type="+p_search_type+"&fuseaction=SEARCH_CLS_ADS&txt_classified_ads_search=" + f.txt_classified_ads_search.value + "&website_id=" + p_website_id ;
		go_url = go_url + "&search_type=" + p_search_type +  "&search_website_id=" + p_search_website_id +  "&search_channel_id=" + p_search_channel_id;
		window.location =  go_url ;
	}
}
function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(null);
}

function updatepage(str){
    document.getElementById("sel_classified_ads_type").innerHTML = str;
}
function txt_submit(url, obj){
	var goto_url = url + '&cate_id='+obj.value+'&modal_dialog_mode=1';
	xmlhttpPost(goto_url);
}
function show_other_info(p_url, number_row){
	var v_height = 32 + number_row*25;
	var v_width = 250;
	var v_top = (screen.height - v_height)/2;
	var v_left = (screen.width - v_width)/2;
	open(p_url, '_blank', 'status=no,toolbar=no,resizable=no,scrollbars=no,height='+v_height+'px,width='+v_width+'px,top='+v_top+',left='+v_left);
}
