var site_var_cookieid = "";

var site_var_cookie_domain = "";

var site_var_cookie_path   = "/";

var site_login_click = 0;

var site_login_status = 1;

var data_request_sent = 0;

var data_request_received = 0;

var startday = new Date();

var clockStart = startday.getTime(); 

var site_tips = ""; 

var is_ie = 0;



function initStopwatch()   

{   

	var myTime = new Date();   

	var timeNow = myTime.getTime();    

	var timeDiff = timeNow - clockStart;   

	this.diffSecs = timeDiff/1000;   

	return(this.diffSecs);

}



if ( window.ActiveXObject )

{

	var is_ie = 1;

}



function logout()

{

	//ht = document.getElementsByTagName("html");

	//ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";

	

	if ( confirm("Ban co chac la muon thoat ra ?") )

	{

		logout_request();

		

		return false;

	}

	else

	{

		//ht[0].style.filter = "";

		return false;

	}

}



function delete_messages(theURL)

{

	if (confirm( "Ban co chac la muon xoa tin nhan nay ?" ))

	{

		window.location.href=theURL;

	}

	else

	{

		alert ( "Tin nhan khong duoc xoa!" );

	} 

}



function delete_script(theURL)

{

	if (confirm( "Ban co chac la muon xoa Script nay ?" ))

	{

		window.location.href=theURL;

	}

	else

	{

		alert ( "Script khong duoc xoa!" );

	} 

}



function alert_msg(theURL)

{

	if (confirm( "Are you sure to send this command ?" ))

	{

		window.location.href=theURL;

	}

	else

	{

		return false;	

	}

}



function check_login(the_form)

{

	var the_name    = the_form.name.value;

	var the_password    = the_form.password.value;



	if ( (the_name=='')||(the_password==''))

	{

		alert("Nhap day du thong tin yeu cau");

		the_form.name.focus();

		return false;

	}

}



function check_search(str)

{

	if (str.value=='')

	{

		alert("Ban hay nhap noi dung tim kiem vao");

		str.focus;

		return false;

	}

	return true;

}





function delete_topic(theURL)

{

	if (confirm( "Ban co chac la muon xoa bai viet nay ?" ))

	{

		window.location.href=theURL;

	}

	else

	{

		alert ( "Bai viet khong duoc xoa!" );

	} 

}





function fast_reply(isMsg)

{

	document.quick_reply.submit.disabled = true;

	return true;

}





function checkall(){

	for (var i = 0; i < document.POSTS.elements.length; i++) {

		if ( document.POSTS.all.checked==true ){

			document.POSTS.elements[i].checked = true;

		}

		else{

			document.POSTS.elements[i].checked = false;

		}

	}

}





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 page_loading_html( text )

{

	text = "<DIV style='width: 100%; padding-top: 7px; padding-bottom: 7px;' align='center'> &nbsp; " + text + " </div>";

	

	return text;

}





function page_loading(type)

{

	if ( type == 1 )

	{

		document.getElementById( this.clicked ).innerHTML = page_loading_html("<img align='absmiddle' src='" + site_root_domain + "/templates/images/warning.png'> <font size='2' face='verdana' color='red'>Connecting to server</font>");

	}

	else if ( type == 2 )

	{

		document.getElementById( this.clicked ).innerHTML = "";

	}

	else

	{

		document.getElementById( this.clicked ).innerHTML = page_loading_html("<font size='2' face='verdana'><img align='absmiddle' src='" + site_root_domain + "/templates/images/loading.gif'>");

	}

}





function data_request(request, url, type, form_id, no_status)

{

	this.clicked = request;

	

	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 == "select-one" )

				{

					fields_data += frm.elements[i].name+"="+frm.elements[i].value+"&";

				}

				else if ( frm.elements[i].type == "select-multiple" )

				{

					art_name = frm.elements[i].name;

					

					selmul = frm.elements[i];

	

					var seldt = new Array();

					var selcnt = 0;

					

					for ( var i = 0; i < selmul.length; i++ )

					{

						if ( selmul.options[i].selected == true )

						{

							seldt[selcnt] = selmul.options[i].value;

							selcnt++;

						}

					}

										

					fields_data += art_name+"="+seldt+"&";

				}

				else 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_menu()

{

	var nodes = document.getElementById("topmenu").getElementsByTagName("a");

	for( var i = 1 ; i < nodes.length; i++ )

	{

		nodes[i].onclick = function()

		{

			document.getElementById( "site_" + menuselect ).className = "";

			document.getElementById( menuselect ).style.display = "none";

			

			if(this.parentNode.current && this.parentNode.current != this)

			{

				document.getElementById(this.parentNode.current.getAttribute("menu")).style.display = "none";

				this.parentNode.current.className = "";

			}

			this.parentNode.current = this;

			if ( this.getAttribute("menu") )

			{

				document.getElementById(this.getAttribute("menu")).style.display = "block";

				this.className = "selected";

			}

		}

	}

	

	nodes[1].parentNode.current = nodes[1];

}



var renew = 0;



function login_request()

{

	data_request( "SITE_member", site_root_domain + "/?site=login&view=do&isa=1", "POST", "login", 0 );

}



function logout_request()

{

	site_login_click = 0;

	site_login_status = 1;

	

	data_request( "SITE_member", site_root_domain + "/?site=login&view=logout&isa=1", "GET", "", 0 );

}



function login_effect( type )

{

	lhl_Cron = initStopwatch();

	lhl_Cron_exe = ""+lhl_Cron;

	lhl_Cron_exe = lhl_Cron_exe.substring(0,lhl_Cron_exe.indexOf("."));

	

	login = '<form name="login" id="login" method="post">T&#234;n truy nh&#7853;p: <input class="input_text_white" type="text" name="name" size="20"> M&#7853;t kh&#7849;u: <input class="input_text_white" type="password" name="password" size="20"> <input type="checkbox" name="remember" value="1" checked> Ghi nh&#7899; ? <input class="input_submit" type="submit" name="submit" value="&#272;&#259;ng nh&#7853;p" onclick="login_request();"></form>';



	if ( ! type )

	{

		if ( is_ie == 1 )

		{

			document.getElementById("SITE_login").innerHTML = "<div style='background: #EEEEEE; position: absolute; left: 0px; top: 0px; width: 100%; border-bottom: solid #000000 1px; vertical-align: middle; height: 30px;'><div style='padding-left: 8px; padding-top: 4px;'><p class='align_right'><a onclick='javascript:SITE_login_effect();'><img src='" + site_root_domain + "/templates/images/icon_delete.gif'></a>&nbsp;</p>" + login + "</div></div>";

		}

		else

		{

			if ( site_login_status > 30 )

			{

				return false;	

			}

			

			window.setTimeout('login_effect()', 1);

			

			document.getElementById("SITE_login").innerHTML = "<div style='background: #EEEEEE; position: absolute; left: 0px; top: 0px; width: 100%; border-bottom: solid #000000 1px; vertical-align: middle; height: "+ site_login_status +"px;'><div style='padding-left: 8px; padding-top: 4px;'><p class='align_right'><a onclick='javascript:SITE_login_effect();'><img src='" + site_root_domain + "/templates/images/icon_delete.gif'></a>&nbsp;</p>" + login + "</div></div>";

		

			site_login_status += 1;

		}

	}

	else

	{

		if ( is_ie == 1 )

		{

			document.getElementById("SITE_login").innerHTML = "";

		}

		else

		{

			if ( site_login_status <= 0 )

			{

				document.getElementById("SITE_login").innerHTML = "";

				return false;

			}

			

			window.setTimeout('login_effect(1)', 1);

			

			document.getElementById("SITE_login").innerHTML = "<div style='background: #EEEEEE; position: absolute; left: 0px; top: 0px; width: 100%; border-bottom: solid #000000 1px; vertical-align: middle; height: "+ site_login_status +"px;'><div style='padding-left: 8px; padding-top: 4px;'><p class='align_right'><a onclick='javascript:SITE_login_effect();'><img src='" + site_root_domain + "/templates/images/icon_delete.gif'></a>&nbsp;</p>" + login + "</div></div>";

			

			//document.getElementById("SITE_login").innerHTML = "<div style='background: #EEEEEE; border-bottom: solid #000000 1px; vertical-align: middle; padding-top: 4px; padding-left: 8px; padding-right: 8px; height: "+ site_login_status +"px;'>" + login + "</div>";

			

			site_login_status -= 1;

		}

	}

}



function SITE_login_effect()

{

	if ( site_login_click == 0 )

	{	

		login_effect();

		site_login_click = 1;		

	}

	else

	{

		login_effect(1);

		site_login_click = 0;

	}

}



function SITE_change_tab( this_id )

{

	if ( this_id != menu_tab_selected )

	{

		document.getElementById( this_id ).className = "block_tab_selected"; 

		

		document.getElementById( menu_tab_selected ).className = "block_tab"; 

		

		menu_tab_selected = this_id;

	}

}



var IE = document.all?true:false

	

if ( ! IE )

{

	document.captureEvents( Event.MOUSEMOVE );

}



document.onmousemove = getMouseXY;



function ietruebody()

{

	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;

}



var tempX = 0;

var tempY = 0;



function getMouseXY(e)

{

	if ( IE )

	{

		tempX = event.clientX + ietruebody().scrollLeft;

		tempY = event.clientY + ietruebody().scrollTop;

	}

	else

	{

	    tempX = e.pageX;

	    tempY = e.pageY;

	}

	

	if ( tempX < 0 )

	{

		tempX = 0

	}

	

	if ( tempY < 0 )

	{

		tempY = 0

	}

		

	return true;

}



var post_respond_id = 0;



function news_post_request( topic_id )

{

	post_respond_id += 1;

	

	document.getElementById("post_respond").id = "lhl_dattenginhi_" + post_respond_id;

	document.getElementById( "lhl_dattenginhi_" + post_respond_id ).innerHTML = document.getElementById( "lhl_dattenginhi_" + post_respond_id ).innerHTML + "<div id='post_respond'></div>";

	

	data_request( "post_respond", site_root_domain + "/?site=news&view=post&act=reply&id=" + topic_id + "&isa=1", "POST", "news_post", 0 );

}



function is_login()

{

	return true;

	

	if ( my_getcookie('member_id') && my_getcookie('member_id') != 0 &&  my_getcookie('pass_hash') != 0 )

	{

		return true;	

	}

	else

	{

		alert("Xin vui long su dung chuc nang dang nhap nhanh de dang nhap truoc khi vao trang can vao.");

		javascript:SITE_login_effect();

		window.scrollTo(0,0);

		return false;

	}

}



function site_url()

{

	base_url = window.location.href;

	base_url = base_url.split("#");

	real_url = base_url[0];

	id_url = base_url[1];

	base_url = real_url + id_url;

	

	return base_url;

}



function site_url_check()

{

	base_url = window.location.href;

	base_url = base_url.split("#");

	real_url = base_url[0];

	id_url = base_url[1];



	if ( id_url )

	{

		return true;

	}

	else

	{

		return false;

	}

}



function showfaq( text, faqid )

{

	showtip(text, 180);

	document.getElementById( faqid ).src= site_img_url +'/icon_notice_active.gif';

}



function hidefaq( faqid )

{

	hidetip();

	document.getElementById( faqid ).src= site_img_url + '/icon_notice.gif';

}



function href_close()

{

	base_url = window.location.href;

	base_url = base_url.split("#");

	window.location.href = base_url[0] + "#";

}



function href_click( data )

{

	//base_url = window.location.href;

	//base_url = base_url.split("#");

	//window.location.href = base_url[0] + "#" + data;

	

	window.location.href = data;

}



function rating_over( num )

{

	var numelse = 10 - num;

		

	for ( i = 1; i <= num; i ++ )

	{

		document.getElementById( "star_" + i ).style.opacity = 1;

		document.getElementById( "star_" + i ).style.filter = "alpha(opacity=100)";

	}

	

	for ( i = num+1; i <= numelse; i ++ )

	{

		document.getElementById( "star_" + i ).style.opacity = 0.4;

		document.getElementById( "star_" + i ).style.filter = "alpha(opacity=60)";

	}

	

	document.getElementById("rating_star").innerHTML = num;

}



function rating_out()

{

	for ( i = 1; i <= 10; i ++ )

	{

		document.getElementById( "star_" + i ).style.opacity = 0.4;

		document.getElementById( "star_" + i ).style.filter = "alpha(opacity=60)";

	}

}



function rating_click( target_to, target_id )

{	

	var star_select = document.getElementById("rating_star").innerHTML;

	

	if ( star_select > 0 )

	{

		data_request( target_id, target_to + star_select + "/", "GET", "", 0 );

	

		return false;

	}

}



function add_favourite( name, URL )

{

	if (window.sidebar)

	{

		window.sidebar.addPanel(name, url,"");

	}

	else if( window.external )

	{

		window.external.AddFavorite( url, name);

	}

	else if  (window.opera && window.print)

	{

		return true;

	}

}



function check_form( form_id )

{

	var frm = document.forms[form_id];

	var numberElements = frm.elements.length;



		for( var i = 0; i < numberElements; i++ )

		{

			test = frm.elements[i];



			if ( ! document.getElementById(frm.elements[i].name).value && test.getAttribute('emsg') )

			{

				alert( test.getAttribute('emsg')  );

				document.getElementById(frm.elements[i].name).focus();

				

				return false;

			}

		}

}



// lyhuuloi foundation date 23/1/2008



function password_change( data )

{

	var point = 0;

	var value = data.value;

	var simple = new Array("123456", "1234567", "12345678", "123456789", "321654", "654987", "321654987", "654321", "987654321");

	

	if ( value.length > 0 )

	{

		document.getElementById("password_checker").style.display = "inline";

		

		// step 1

		point += value.length;



		// step 2

		var check1 = 0;

		

		for ( var i = 0; i < simple.length-1; i++ )

		{

			if ( simple[i] == value )

			{

				check1 = 1;

			}

		}

		

		if ( check1 == 0 && value.length >= 6 )

		{

			point += 5;	

		}

		

		// step 3

		/*var check2 = 0;

		

		if ( value.length >= 6 )

		{

			for ( var i = 1; i <= 3; i++ )

			{

				var data2 = value;

				result = data2.replace( data2.substr(0,i), "" );

				

				alert( data2.substr(0,i) + " = " + result);

				

				if ( result == "" )

				{

					check2 = 1;

				}

			}

		}

		*/



		

	}

	else

	{

		document.getElementById("password_checker").style.display = "none";

	}



	if ( point >= 5 )

	{

		document.getElementById("pwd1").innerHTML = '<span class="password_2">&nbsp;</span>';

	}

	else

	{

		document.getElementById("pwd1").innerHTML = '<span class="password_1">&nbsp;</span>';

	}

	

	if ( point >= 10 )

	{

		document.getElementById("pwd2").innerHTML = '<span class="password_2">&nbsp;</span>';

	}

	else

	{

		document.getElementById("pwd2").innerHTML = '<span class="password_1">&nbsp;</span>';

	}

	

	if ( point >= 15 )

	{

		document.getElementById("pwd3").innerHTML = '<span class="password_2">&nbsp;</span>';

	}

	else

	{

		document.getElementById("pwd3").innerHTML = '<span class="password_1">&nbsp;</span>';

	}

	

	if ( point >= 20 )

	{

		document.getElementById("pwd4").innerHTML = '<span class="password_2">&nbsp;</span>';

	}

	else

	{

		document.getElementById("pwd4").innerHTML = '<span class="password_1">&nbsp;</span>';

	}

	

	if ( point >= 25 )

	{

		document.getElementById("pwd5").innerHTML = '<span class="password_2">&nbsp;</span>';

	}

	else

	{

		document.getElementById("pwd5").innerHTML = '<span class="password_1">&nbsp;</span>';

	}



}





function order(id,name)

{

	

	alert("Báº¡n Ä'Ã£ thÃªm sáº£n pháº©m "+name+" vÃ o giá» hÃ ng");

	data_request('mycart', root_domain+'/?site=product&act=order&action=add&item='+id,'');	

	}

function paymentz(id,hide)

{

	if(id==1)

	{

	document.getElementById("payment_1").style.display="block";

	document.getElementById("payment_2").style.display="none";

	}

	else if(hide==2)

	{

		document.getElementById("payment_1").style.display="none";

		document.getElementById("payment_2").style.display="block";

		}

	else{

		return true;

		}	

	}

	

function dosubmit(id)

{

	window.location=id;

}



function sorturl(url,id){

	window.location=url+'&order='+id;

	}

function selectid(id)

{

	if(id)

	{

		document.getElementById(""+id).selected="selected";

		}

	else{

		return true;

		}

	}

	

function changepage(url,id)

{

	window.location=url+'&id='+id;

	}

function show(id,total)
{

	for(i=1;i<=total;i++)

	{

		if(id==i){

		document.getElementById("calenda_"+i).style.display='block';	

		document.getElementById("a_"+i).className	='calendaactive';

		}

		else

		{

			document.getElementById("calenda_"+i).style.display='none';	

			document.getElementById("a_"+i).className	='';

			}

		}

	

	}

	

function search_index()

{

	if(document.formsearch.keyword.value=='')

	{

		alert("Vui lÃ²ng nháº­p tá»« khÃ³a tÃ¬m kiáº¿m");

		document.formsearch.keyword.focus();

		return false;

		}

	if(document.formsearch.keyword.value.length<6)

	{

		alert("Tá»« khÃ³a tÃ¬m kiáº¿m pháº£i lá»›n hÆ¡n hoáº·c báº±ng 6 kÃ½ tá»±");

		document.formsearch.keyword.focus();

		return false;

		}

	

			

	}
