//	Hi all !
// JavaScript code by Dao Quoc Dai
// E-mail: itvn9online@yahoo.com
// Phone: 0984 533 228
// Free copy ^^!

var xmlhttp;
var resultAlert = "Đang tải dữ liệu...";
function getxmlhttpobject()
{
	var xmlhttp = null;
	try
	{
		//dành cho trình duyệt  Firefox, Opera 8.0+, Safari
		xmlhttp = new XMLHttpRequest();
	}    
	catch(e)
	{
		try
		{
			//dành cho trình duyệt internet explore
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{                        
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");                            
		}
	}
	return xmlhttp;
}

function Upthread()
{
	if(xmlhttp.readyState == 4)
	{
		document.getElementById('result_Advertise').innerHTML = xmlhttp.responseText;
		document.getElementById('result_Popup').innerHTML = "";
	}
	else
	{
		LoadingComponent('Đang tải dữ liệu...');
	}
	return;
}

function Advertise()
{
	if(xmlhttp.readyState == 4)
	{
		document.getElementById('result_Advertise').innerHTML = xmlhttp.responseText;
		document.getElementById('result_Waiting').innerHTML = "";
	}
	else
	{
		document.getElementById('result_Waiting').innerHTML = "<div class='dang_tai'>Đang tải dữ liệu...</div>";
	}
	return;
}

function Threadlist()
{
	if(xmlhttp.readyState == 4)
	{
		document.getElementById('result_Threadlist').innerHTML = xmlhttp.responseText;
		document.getElementById('result_Waiting').innerHTML = "";
	}
	else
	{
		document.getElementById('result_Waiting').innerHTML = "<div class='dang_tai'>Đang tải dữ liệu...</div>";
	}
	return;
}

function Popup()
{
	if(xmlhttp.readyState == 4)
	{
		document.getElementById('result_Popup').innerHTML = xmlhttp.responseText;
		document.getElementById('result_Waiting').innerHTML = "";
	}
	else
	{
		document.getElementById('result_Waiting').innerHTML = "<div class='dang_tai'>Đang tải dữ liệu...</div>";
	}
	return;
}

function City()
{
	if(xmlhttp.readyState == 4)
	{
		document.getElementById('result_City').innerHTML = xmlhttp.responseText;
	}
	return;
}

function resultOne()
{
	if(xmlhttp.readyState == 3)
	{
		document.getElementById('resultOne').innerHTML = resultAlert;
	}
	if(xmlhttp.readyState == 4)
	{
		document.getElementById('resultOne').innerHTML = xmlhttp.responseText;
	}
	return;
}

function resultTwo()
{
	if(xmlhttp.readyState == 3)
	{
		document.getElementById('resultTwo').innerHTML = resultAlert;
	}
	if(xmlhttp.readyState == 4)
	{
		document.getElementById('resultTwo').innerHTML = xmlhttp.responseText;
	}
	return;
}

function resultThree()
{
	if(xmlhttp.readyState == 3)
	{
		document.getElementById('resultThree').innerHTML = resultAlert;
	}
	if(xmlhttp.readyState == 4)
	{
		document.getElementById('resultThree').innerHTML = xmlhttp.responseText;
	}
	return;
}

function inputAjax(url, str, result)
{
	xmlhttp=getxmlhttpobject();
	if(xmlhttp==null)
	{
		alert("<center>Trình duyệt của bạn không hỗ trợ ajax...</center>");
		return false;
	}
	url += "&reid="+str;
	xmlhttp.onreadystatechange = result;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	return;
}

function showThread(return_value)
{
	var show = "";
	show += "<div align='center' id='popup_picture' title='Đóng cửa sổ này' onClick=\"inputNull('result_Galery');\">";
	show += "<img onClick=\"inputNull('result_Galery');\" class='mouse_thunho' src='" + return_value + "' border='0' style='max-height: 528px; max-width: 886px' />";
	show += "</div>";
	document.getElementById('result_Galery').innerHTML = show;
	return;
}

function ShowPopupAlert(title, msg, alink, mlink)
{
	// alink: name link
	// mlink: move link
	var show = "";
	show += "<div class='popup_border'>";
	show += "<table width='428' align='center' border='0' cellspacing='0' cellpadding='6' bgcolor='#FFFFFF'>";
	show += "<tr class='popup_menu'>";
	show += "<td>&nbsp; " + title + "</td>";
	show += "<td align='right'><img title='Đóng cửa sổ này' border='1' style='cursor: pointer' onclick=\"inputNull('result_Popup');\" src='./images/close_2.png' />&nbsp;</td>";
	show += "</tr>";
	show += "<tr>";
	show += "<td colspan='2'>";
	show += "<div style='padding: 6px; background: #CFEBFF'>";
	show += "<div align='center' style='min-height: 68px; padding-top: 28px; font-weight: bold; color: #E21919; font-size: 14px'>" + msg + "</div>";
	show += "<div align='right'>";
	if(alink != "" && mlink != "") show += "<a href='"+ mlink +"'>" + alink + "</a> | ";
	show += "<a onclick=\"inputNull('result_Popup');\" href='javascript:void(0);'>Đóng cửa sổ này [x]</a></div>";
	show += "<div>";
	show += "</td>";
	show += "</tr>";
	show += "</table>";
	show += "</div>";
	document.getElementById('result_Popup').innerHTML = show;
	return;
}

function LoadingComponent(msg)
{
	// alink: name link
	// mlink: move link
	var show = "";
	show += "<div class='popup_border'>";
	show += "<table width='428' align='center' border='0' cellspacing='0' cellpadding='6' bgcolor='#FFFFFF'>";
	show += "<tr>";
	show += "<td>";
	show += "<div style='padding: 6px; background: #CFEBFF'>";
	show += "<div align='center' style='min-height: 68px; padding-top: 28px; font-weight: bold; color: #E21919; font-size: 14px'>" + msg + "</div>";
	show += "</td>";
	show += "</tr>";
	show += "</table>";
	show += "</div>";
	document.getElementById('result_Popup').innerHTML = show;
	return;
}

function OnChange(page)
{
	window.location.href = page;
	return;
}

function inputNull(return_id)
{
	document.getElementById(return_id).innerHTML = "";
	return;
}

function CheckfrmSendMessenger()
{
	with(document.frmSendMessenger)
	{
		if(tTieude.value == "")
		{
			alert("Bạn chưa nhập tiêu đề tin nhắn");
			tTieude.focus();
			return false;
		}
		if(tTieude.value.length < 10 )
		{
			alert("Tiêu đề quá ngắn");
			tTieude.focus();
			return false;
		}
		if(tNoidung.value == "")
		{
			alert("Bạn chưa nhập nội dung tin nhắn");
			tNoidung.focus();
			return false;
		}
		if(tNoidung.value.length > 100)
		{
			alert("Mỗi tin nhắn tối đa chi được 100 ký tự");
			tNoidung.focus();
			return false;
		}
		if(tCaptcha.value.length < 4)
		{
			alert("Nhập mã xác nhận");
			tCaptcha.focus();
			return false;
		}
	}
	return true;
}

/* inc_phongthuy */
function PhongThuy(nam, gioitinh, huong)
{
	var url;
	url = 'http://www.vietaa.com/Tools/Battrach/venha.aspx?namsinh=' + nam + '&gioitinh=' + gioitinh + '&huongnha=' + huong + '&goclaban=0';
	showThread(url);
	return;
}

/* menu_member */
function CheckQuickLogin()
{
	 with(document.frmQuickLogin)
	 {
		email = tEmail.value;
		re=/^\w+([\-\.]?\w+)*@\w+(\.\w+){1,3}$/;
		if( re.test(email) == false)
		{
			alert("Địa chỉ email không chính xác");
			tEmail.focus();
			return false;
		}

		pass = tMatkhau.value;
		if( pass.length < 6 )
		{
			alert("Mật khẩu quá ngắn");
			tMatkhau.focus();
			return false;
		}
	}
	return true;
}

function CheckQuickRegister()
{
	 with(document.frmQuickRegister)
	 {
		email = tEmail.value;
		re=/^\w+([\-\.]?\w+)*@\w+(\.\w+){1,3}$/;
		if( re.test(email) == false)
		{
			alert("Email không đúng định dạng");
			tEmail.focus();
			return false;
		}

		pass = tMatkhau.value;
		if( pass.length < 6 )
		{
			alert("Mật khẩu quá ngắn");
			tMatkhau.focus();
			return false;
		}

		pass2 = tMatkhau2.value;
		if( pass2 != pass )
		{
			alert("Mật khẩu xác nhận không chính xác");
			tMatkhau2.focus();
			return false;
		}
	}
	return true;
}

function quick_login_register(type)
{
	var ShowMenuMember = '';

	if( type == 1 )
	{
		ShowMenuMember += '<div class="l_f_menu"><a onclick="quick_login_register(1);" href="javascript:void(0);">Đăng nhập</a> | <a onclick="quick_login_register(2);" href="javascript:void(0);" class="active">Đăng ký nhanh</a></div>';
		ShowMenuMember += '<div class="border_menu" title="Hỗ trợ đăng nhập bằng tài khoản Yahoo và Google (Gmail)" style="padding: 1px 16px 16px 16px;">';
		ShowMenuMember += '<form name="frmQuickLogin" id="frmQuickLogin" method="post" action="dangnhap.htm" onsubmit="return CheckQuickLogin();">';
		ShowMenuMember += '<p>';
		ShowMenuMember += '<div align="center"><img src="images/gmail.png" /><img src="images/yahoo.png" /></div>';
		ShowMenuMember += '<input type="text" name="tEmail" value="Email" id="tEmail" style="PADDING-LEFT: 17px; boder: solid 1px #8accff; width: 210px; height: 20px; color: #666666; background: #FFFFFF url(images/input_name.gif) no-repeat;"  onblur="if (this.value==\'\'){this.value=\'Email\';}" onfocus="if (this.value==\'Email\') {this.value = \'\';}" maxlength="57" />';
		ShowMenuMember += '</p>';
		ShowMenuMember += '<p>';
		ShowMenuMember += '<input type="password" name="tMatkhau" value="matkhau" id="tMatkhau" style="PADDING-LEFT: 17px; boder: solid 1px #8accff; width: 118px; height: 20px; color: #666666; background:url(images/input_pass.gif) no-repeat;" onblur="if (this.value==\'\'){this.value=\'matkhau\';}" onfocus="if (this.value==\'matkhau\') {this.value = \'\';}" maxlength="32" /> ';
		ShowMenuMember += '<input type="submit" name="btnSubmit" id="btnSubmit" value="Đăng nhập" style="height: 26px; width: 86px" />';
		ShowMenuMember += '</p>';
		ShowMenuMember += '<div>';
		ShowMenuMember += '<input type="checkbox" name="remember_password" id="remember_password" value="1" onclick="return confirm(\'Chỉ lưu mật khẩu khi bạn đang dùng máy tính cá nhân\');" /> ';
		ShowMenuMember += '<label style="cursor: pointer" for="remember_password">Tự động đăng nhâp lần sau</label>';
		ShowMenuMember += '</div>';
		ShowMenuMember += '</form>';
		ShowMenuMember += '<p><img src="images/bullet_arrow.gif" /> <a href="quenmatkhau.html"><strong>Bạn quên mật khẩu ?</strong></a></p>';
		ShowMenuMember += '<div><img src="images/bullet_arrow.gif" /> <a href="dangky.html"><strong>Đăng ký tài khoản mới . . .</strong></a></div>';
		ShowMenuMember += '</div>';
	}
	else
	{
		ShowMenuMember += '<div class="l_f_menu"><a onclick="quick_login_register(1);" href="javascript:void(0);" class="active">Đăng nhập</a> | <a href="javascript:void(0);">Đăng ký nhanh</a></div>';
		ShowMenuMember += '<div class="border_menu" style="padding: 16px">';
		ShowMenuMember += '<form name="frmQuickRegister" id="frmQuickRegister" method="post" action="dangkynhanh.htm" onsubmit="return CheckQuickRegister();">';
		ShowMenuMember += '<div>E-mail đăng nhập<br /><input type="text" name="tEmail" id="tEmail" style="boder: solid 1px #8accff; width: 100%; height: 20px; color: #666666;" maxlength="32" /></div>';
		ShowMenuMember += '<div>Mật khẩu<br /><input type="password" name="tMatkhau" id="tMatkhau" style="boder: solid 1px #8accff; width: 100%; height: 20px; color: #666666;" maxlength="32" /></div>';
		ShowMenuMember += '<div>Xác nhận mật khẩu<br /><input type="password" name="tMatkhau2" id="tMatkhau2" style="boder: solid 1px #8accff; width: 100%; height: 20px; color: #666666;" maxlength="32" /></div>';
		ShowMenuMember += '<p><input type="submit" name="btnSubmit" id="btnSubmit" value="Đăng ký nhanh" style="height: 26px; width: 116px; font-weight: bold" /></p>';
		ShowMenuMember += '<div>';
		ShowMenuMember += 'Hoặc <a onclick="quick_login_register(1);" href="javascript:void(0);">Đăng nhập</a> bằng tài khoản:';
		ShowMenuMember += '<div align="center" title="Hỗ trợ đăng nhập trự tiếp bằng tài khoản Yahoo và Gmail (Google)"><img src="images/gmail.png" /><img src="images/yahoo.png" /></div>';
		ShowMenuMember += '</div>';
		ShowMenuMember += '</form>';
		ShowMenuMember += '</div>';
	}

	return(document.getElementById('quick_login_register').innerHTML = ShowMenuMember);
}


/* tooltip */
var offsetfromcursorX = 12;
var offsetfromcursorY = 10;
var offsetdivfrompointerX = 10;
var offsetdivfrompointerY = 13;

document.write('<div id="dhtmltooltip"></div>');
document.write('<img id="dhtmlpointer" src="css_style/images/arrow_tooltip.gif">');

var ie = document.all;
var ns6 = document.getElementById && ! document.all;
var enabletip = false;
var  tipobj = document.getElementById("dhtmltooltip");
var pointerobj = document.getElementById("dhtmlpointer");
function ietruebody()
{
	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

String.prototype.trim = function ()
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function showtip(thetext, thewidth, thecolor)
{
	if (ns6 || ie)
	{
		if (typeof thewidth != "undefined")
			tipobj.style.width = thewidth + "px";
		if (typeof thecolor != "undefined" && thecolor != "")
			tipobj.style.backgroundColor = thecolor;
		thetext = thetext.trim();
		var arr = thetext.split(" ");
		for(i=0;i<arr.length;i++)
			if(arr[i].length>=40)
				thetext=thetext.replace(arr[i],arr[i].substr(0,40)+"...");
		tipobj.innerHTML = thetext;		
		enabletip = true;
		return false;
	}
}

function positiontip(e)
{
	if (enabletip)
	{
		var nondefaultpos = false;
		var curX = (ns6) ? e.pageX : event.clientX + ietruebody().scrollLeft;
		var curY = (ns6) ? e.pageY : event.clientY + ietruebody().scrollTop;
		
		var winwidth = ie && ! window.opera ? ietruebody().clientWidth : window.innerWidth - 20;
		var winheight = ie && ! window.opera ? ietruebody().clientHeight : window.innerHeight - 20;

		var rightedge = ie && ! window.opera ? winwidth - event.clientX - offsetfromcursorX : winwidth - e.clientX - offsetfromcursorX;
		var bottomedge = ie && ! window.opera ? winheight - event.clientY - offsetfromcursorY : winheight - e.clientY - offsetfromcursorY;

		var leftedge = (offsetfromcursorX < 0) ? offsetfromcursorX * (- 1) : - 1000;

		if (rightedge < tipobj.offsetWidth)
		{
			tipobj.style.left = curX - tipobj.offsetWidth + "px";
			nondefaultpos = true;
		}
		else if (curX < leftedge)
			tipobj.style.left = "5px";
		else
		{
			tipobj.style.left = curX + offsetfromcursorX - offsetdivfrompointerX + "px";
			pointerobj.style.left = curX + offsetfromcursorX + "px";
		}

		if (bottomedge < tipobj.offsetHeight)
		{
			tipobj.style.top = curY - tipobj.offsetHeight - offsetfromcursorY + "px";
			nondefaultpos = true;
		}
		else
		{
			tipobj.style.top = curY + offsetfromcursorY + offsetdivfrompointerY + "px";
			pointerobj.style.top = curY + offsetfromcursorY + "px";
		}

		tipobj.style.visibility = "visible";

		if (! nondefaultpos)
			pointerobj.style.visibility = "visible";
		else
			pointerobj.style.visibility = "hidden";
	}
	
	return;
}

function hidetip()
{
	if (ns6 || ie)
	{
		enabletip = false;
		tipobj.style.visibility = "hidden";
		pointerobj.style.visibility = "hidden";
		tipobj.style.left = "-1000px";
		tipobj.style.backgroundColor = '';
		tipobj.style.width = '';
	}
	
	return;
}

document.onmousemove = positiontip;

function SearchTop(SearchValue)
{
	if( SearchValue == null )
	{
		alert('Nhập từ khóa tìm kiếm');
		return false;
	}
	else
	{
		SearchValue.replace(' ', '+')

		window.open('http://www.google.com/search?output=googleabout&sitesearch=www.nhadat.info&q=' + SearchValue + '&submit=Site+Search', 'popup', 'width=986%, height=600, location=1, resizable=1, scrollbars=1, status=1');
	}
	return;
}

