﻿<!--

var site_var_cookieid = "";
var site_var_cookie_domain = "";
var site_var_cookie_path   = "/";
var data_request_sent = 0;
var data_request_received = 0;
var site_submit_time = 1;
var data_request_time = 1;

function SITE_transfer(FROM, TO)
{
	document.getElementById( TO ).innerHTML = document.getElementById( FROM ).innerHTML;
}

function SITE_capnhatten(FROM, TO)
{
	document.getElementById( TO ).innerHTML = document.getElementById( FROM ).value;
}

function page_loading(type)
{
	if ( type == 1 )
	{
		document.getElementById( "SITE_loading" ).innerHTML = "<DIV style='width: 100%;' align='right'><div style='position:absolute; left: 0%; top: 0%; right: 40%; z-index:0; width: 20%; text-align: left; padding: 12px; border: solid #bebebe 1px; background: #EEEEEE;'> &nbsp; <font size='2' face='verdana' color='red'>K&#7871;t n&#7889;i b&#7883; l&#7895;i....</font></div></div>";
	}
	else if ( type == 2 )
	{
		document.getElementById( "SITE_loading" ).innerHTML = "";
	}
	else
	{
		document.getElementById( "SITE_loading" ).innerHTML = "<DIV style='width: 100%;' align='right'><div style='position:absolute; left: 0%; top: 0%; right: 40%; z-index:0; width: 20%; text-align: left; padding: 12px; border: solid #bebebe 1px; background: #EEEEEE;'> &nbsp; <font size='2' face='verdana'>&#272;ang g&#7917;i....</font></div></div>";
	}
	
}


function data_request(request, url, type, form_id, no_status)
{
	data_request_sent++;
	update_status(0);
	
	this.no_status = no_status;
	
	if ( no_status == 1 )
	{
		no_status = 1;
	}
	else
	{
		no_status = 0;
	}
	
	if ( ! type )
	{
		type = "GET";
	}
	else
	{
		type = "POST";
	}
	
	var fields_data = "";
	var lhl_data_got = "";

	if ( form_id )
	{
		if ( type == "GET" )
		{
			var fields_data = "?";
		}
		else if ( type == "POST" )
		{
			var fields_data = "";
		}

		var frm = document.forms[form_id];
		var numberElements = frm.elements.length;
		
		for( var i = 0; i < numberElements; i++)
		{
			if( i < numberElements-1 )
			{
				if ( ( frm.elements[i].type == "radio" ) || ( frm.elements[i].type == "checkbox" ))
				{					
					if (frm.elements[i].checked)
					{
						fields_data += frm.elements[i].name+"="+frm.elements[i].value+"&";
					}
				}
				else
				{
					fields_data += frm.elements[i].name+"="+frm.elements[i].value+"&";
				}
			}
			else
			{
				if (frm.elements[i].type == "radio")
				{					
					if (frm.elements[i].checked)
					{
						fields_data += frm.elements[i].name+"="+frm.elements[i].value;
					}
				}
				else
				{
					fields_data += frm.elements[i].name+"="+frm.elements[i].value;
				}
			}
		}
		
	}


	http_request = false;

	this.lhl_id_packet_send_to = request;
	
	if ( lhl_id_packet_send_to )
	{
		if ( no_status != 1 )
		{
			page_loading();
		}
	}
	
	if (window.XMLHttpRequest) // Mozilla, Safari,...
	{
		http_request = new XMLHttpRequest();
		
		if (http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/xml');
		}
	
	}
	else if (window.ActiveXObject) // IE
	{
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			
			}
		}
	}


	if ( ! http_request )
	{
		if ( lhl_id_packet_send_to )
		{
			page_loading(1);
		}

		return false;
	}
		
	http_request.onreadystatechange = contents;

	if ( type == "POST" )
	{
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		http_request.setRequestHeader("Content-length", fields_data.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(fields_data);
	}
	else if ( type == "GET" )
	{
		http_request.open('GET', url + fields_data, true);
		http_request.send(null);
	}
	
}


function contents()
{
	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		{
			data_request_received++;
			update_status(1);
				
			if ( lhl_id_packet_send_to )
			{
				if ( no_status != 1 )
				{
						page_loading(2);
				}
			
				data_request_time = 1;
			
				document.getElementById( lhl_id_packet_send_to ).innerHTML = http_request.responseText;
			}
		}
		else
		{
			if ( lhl_id_packet_send_to )
			{
				if ( no_status != 1 )
				{
					page_loading(1);
				}
			}
		}
	}
}


function update_status(type)
{
	
	if ( document.getElementById( 'SITE_request_sent' ) )
	{
		if ( type == 1 )
		{
			status_received = data_request_received;
	
			document.getElementById( 'SITE_request_received' ).innerHTML = status_received;
		}
		else
		{
			status_sent = data_request_sent;
	
			document.getElementById( 'SITE_request_sent' ).innerHTML = status_sent;
		}
	}
}

function SITE_insert(request, url, type, form_id, no_status)
{
	updateRTE('content');
	
	if ( ! document.getElementById( form_id ).content.value || ! document.getElementById( "member_name" ).innerHTML )
	{ 
		return false;
	}
	
	if ( site_submit_time == 0 )
	{
		alert("Đợi 1 chút, tin trước đó đang được gửi đi ! Thử lại nhé.");
		
		return false;
	}
	
	var site_submit_time = 0;
	
	document.getElementById( "noidung" ).innerHTML = SITE_boxuly ( document.getElementById( "noidung" ).innerHTML ) + "<div><b>" + document.getElementById( "member_name" ).innerHTML + ":</b>&nbsp;" + SITE_xuly ( document.getElementById( form_id ).content.value ) + "</div>";
	
	SITE_scroll( "noidung" );
	
	data_request_sent++;
	update_status(0);
	
	this.no_status = no_status;
	
	if ( no_status == 1 )
	{
		no_status = 1;
	}
	else
	{
		no_status = 0;
	}
	
	if ( ! type )
	{
		type = "GET";
	}
	else
	{
		type = "POST";
	}
	
	var fields_data = "";
	var lhl_data_got = "";

	if ( form_id )
	{
		if ( type == "GET" )
		{
			var fields_data = "?";
		}
		else if ( type == "POST" )
		{
			var fields_data = "";
		}

		fields_data += "&content=" + document.dulieu.content.value;		
	}
	
	frames["content"].document.body.innerHTML = "";

	send_msg = false;

	this.lhl_id_packet_send_to = request;
	
	if ( lhl_id_packet_send_to )
	{
		if ( no_status != 1 )
		{
			page_loading();
		}
	}
	
	if (window.XMLHttpRequest) // Mozilla, Safari,...
	{
		send_msg = new XMLHttpRequest();
		
		if (send_msg.overrideMimeType)
		{
			send_msg.overrideMimeType('text/xml');
		}
	
	}
	else if (window.ActiveXObject) // IE
	{
		try
		{
			send_msg = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				send_msg = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			
			}
		}
	}


	if ( ! send_msg )
	{
		if ( lhl_id_packet_send_to )
		{
			page_loading(1);
		}

		return false;
	}
		
	send_msg.onreadystatechange = sent_msg;

	if ( type == "POST" )
	{
		send_msg.open('POST', url, true);
		send_msg.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		send_msg.setRequestHeader("Content-length", fields_data.length);
		send_msg.setRequestHeader("Connection", "close");
		send_msg.send(fields_data);
	}
	else if ( type == "GET" )
	{
		send_msg.open('GET', url + fields_data, true);
		send_msg.send(null);
	}
	
}


function sent_msg()
{
	if (send_msg.readyState == 4)
	{
		if (send_msg.status == 200)
		{
			data_request_received++;
			update_status(1);
				
			if ( lhl_id_packet_send_to )
			{				
				var site_submit_time = 1;
				
				if ( no_status != 1 )
				{
						page_loading(2);
				}
			
				document.getElementById( lhl_id_packet_send_to ).innerHTML = send_msg.responseText;
			}
		}
		else
		{
			if ( lhl_id_packet_send_to )
			{
				if ( no_status != 1 )
				{
					page_loading(1);
				}
			}
		}
	}
}

startday = new Date();  
clockStart = startday.getTime();  

function initStopwatch()   
{   
	var myTime = new Date();   
	var timeNow = myTime.getTime();    
	var timeDiff = timeNow - clockStart;   
	this.diffSecs = timeDiff/1000;   
	return(this.diffSecs);
}

function lhl_my_cron()
{
	lhl_Cron = initStopwatch();
	lhl_Cron_exe = ""+lhl_Cron;
	lhl_Cron_exe = lhl_Cron_exe.substring(0,lhl_Cron_exe.indexOf("."));
	
	window.setTimeout('lhl_my_cron()', 3000);

	if ( ! document.getElementById( 'thanhvien' ) )
	{
		return false;
	}

	msg_id = document.getElementById( 'received_id' ).innerHTML;

	if ( msg_id )
	{
		if ( data_request_time == 0 )
		{
			return false;
		}
		
		data_request_time = 0;
			
		data_request('received_bk', document.getElementById( 'SITE_domain' ).innerHTML + '/?site=chat&view=msg&id=' + msg_id, 'GET', '', 1);
	}
}

function lhl_update()
{
	lhl_Cron = initStopwatch();
	lhl_Cron_exe = ""+lhl_Cron;
	lhl_Cron_exe = lhl_Cron_exe.substring(0,lhl_Cron_exe.indexOf("."));
	
	window.setTimeout('lhl_update()', 500);
	
	if ( ! document.getElementById( 'thanhvien' ) )
	{
		return false;
	}
		
	dulieu = document.getElementById( "received_bk" ).innerHTML;
		
	dulieu_one = dulieu.split("|||");

	if ( dulieu_one[0] )
	{
		document.getElementById( 'received_id' ).innerHTML = dulieu_one[0];

		if ( dulieu_one[2] )
		{
			dulieu_ct = dulieu_one[2].split("||");
		}
		
		document.getElementById( 'thanhvien' ).innerHTML = dulieu_one[1];
	}

	if ( document.getElementById( "received_id_bk" ).innerHTML != document.getElementById( "received_id" ).innerHTML )
	{
		if ( dulieu_one[2] )
		{		
			for ( i = 0; i < (dulieu_ct.length-1); i++ )
			{
				chitiet = dulieu_ct[i].split("|");
				
				chitiet[3] = SITE_xuly( chitiet[3] );
				
				dulieumoi = "<a id='msg_" + chitiet[0] + "' href='" + chitiet[1] + "'><b>" + chitiet[2] + ":</b></a>&nbsp;" + chitiet[3] + "<br>";
				
				document.getElementById( 'noidung' ).innerHTML = SITE_boxuly ( document.getElementById( 'noidung' ).innerHTML ) + dulieumoi;
			}
		}
		
		document.getElementById( "received_bk" ).innerHTML = "";
		
		document.getElementById( "received_id_bk" ).innerHTML = document.getElementById( "received_id" ).innerHTML;
	}
	
	SITE_scroll( "noidung" );
	
	SITE_khungnhaplieu();
}

lhl_my_cron();
lhl_update();

function my_getcookie( name )
{
	cname = site_var_cookieid + name + '=';
	cpos  = document.cookie.indexOf( cname );
	
	if ( cpos != -1 )
	{
		cstart = cpos + cname.length;
		cend   = document.cookie.indexOf(";", cstart);
		
		if (cend == -1)
		{
			cend = document.cookie.length;
		}
		
		return unescape( document.cookie.substring(cstart, cend) );
	}
	
	return null;
}


function my_setcookie( name, value, sticky )
{
	expire = "";
	domain = "";
	path   = "/";
	
	if ( sticky )
	{
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	}
	
	if ( site_var_cookie_domain != "" )
	{
		domain = '; domain=' + site_var_cookie_domain;
	}
	
	if ( site_var_cookie_path != "" )
	{
		path = site_var_cookie_path;
	}
	
	document.cookie = site_var_cookieid + name + "=" + value + "; path=" + path + expire + domain + ';';
}


function ShowHide(id1, id2)
{
	if (id1 != '') toggleview(id1);
	if (id2 != '') toggleview(id2);
}

	
function my_getbyid(id)
{
	itm = null;
	
	if (document.getElementById)
	{
		itm = document.getElementById(id);
	}
	else if (document.all)
	{
		itm = document.all[id];
	}
	else if (document.layers)
	{
		itm = document.layers[id];
	}
	
	return itm;
}


function toggleview(id)
{
	if ( ! id ) return;
	
	if ( itm = my_getbyid(id) )
	{
		if (itm.style.display == "none")
		{
			my_show_div(itm);
		}
		else
		{
			my_hide_div(itm);
		}
	}
}


function my_hide_div(itm)
{
	if ( ! itm ) return;
	
	itm.style.display = "none";
}


function my_show_div(itm)
{
	if ( ! itm ) return;
	
	itm.style.display = "";
}


function toggle( fid, add )
{
	saved = new Array();
	clean = new Array();


	if ( tmp = my_getcookie('site_collapseprefs') )
	{
		saved = tmp.split(",");
	}
	
	for( i = 0 ; i < saved.length; i++ )
	{
		if ( saved[i] != fid && saved[i] != "" )
		{
			clean[clean.length] = saved[i];
		}
	}


	if ( add )
	{
		clean[ clean.length ] = fid;
		my_show_div( my_getbyid( 'fc_'+fid  ) );
		my_hide_div( my_getbyid( 'fo_'+fid  ) );
	}
	else
	{
		my_show_div( my_getbyid( 'fo_'+fid  ) );
		my_hide_div( my_getbyid( 'fc_'+fid  ) );
	}
	
	
	my_setcookie( 'site_collapseprefs', clean.join(','), 1 );
}


function SITE_scroll( name )
{
	data = document.getElementById( name );
	data.scrollTop = data.scrollHeight;
}


function media( name )
{
	data = '';
	
	data += '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" standby="Loading Microsoft Windows Media Player components..." type="application/x-mplayer2" height="0" width="0">';
	data += '<param name="FileName" value="' + name + '">';
	data += '<param name="ShowControls" value="1">';
	data += '<param name="ShowDisplay" value="0">';
	data += '<param name="ShowStatusBar" value="1">';
	data += '<param name="AutoSize" value="1">';
	data += '<param name="loop" value="false">';
	data += '<embed autostart="1" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer" src="' + name + '" height="0" width="0"></object><font color="red"><b>BUZZ !!!</b></font>';

	return data;
}


function unmedia( name )
{
	data = '';
	
	data += '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" standby="Loading Microsoft Windows Media Player components..." type="application/x-mplayer2" height="0" width="0">';
	data += '<param name="FileName" value="' + name + '">';
	data += '<param name="ShowControls" value="1">';
	data += '<param name="ShowDisplay" value="0">';
	data += '<param name="ShowStatusBar" value="1">';
	data += '<param name="AutoSize" value="1">';
	data += '<param name="loop" value="false">';
	data += '<embed autostart="1" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer" src="' + name + '" height="0" width="0"></object>';

	return data;
}


function SITE_xuly( data )
{
	if ( datamoi.match("{new}") )
	{
		datamoi += media( document.getElementById( "SITE_domain" ).innerHTML + "/modules/chat/media/new.wav");
	}
	
	datamoi = data.replace("{buzz}", media( document.getElementById( "SITE_domain" ).innerHTML + "/modules/chat/media/buzz.wav"));

	return datamoi;
}

function SITE_boxuly( data )
{
	datamoi = data.replace( unmedia( document.getElementById( "SITE_domain" ).innerHTML + "/modules/chat/media/buzz.wav"), "" );
	datamoi = datamoi.replace( unmedia( document.getElementById( "SITE_domain" ).innerHTML + "/modules/chat/media/new.wav"), "" );

	return datamoi;
}


function SITE_khungnhaplieu()
{
	if ( document.getElementById( "khungnhaplieu" ).innerHTML )
	{
		return false;
	}
	
	writeRichText('content', '', 700, 40, true, false, "dulieu");
}
