﻿
function Search(r,k) {
	document.form1.action="/region"+r+"/search/key"+k+"/index.html";
	document.form1.secondtime.value="start_search";
	document.form1.submit();
}
var bool=true;
function ShowHide()
{
	var obj=document.getElementById("tbCretia");
	obj.style.display=(bool ? "none" : "");
	var src=event.srcElement;
	src.src=(bool ? "http://www.nhagiare.com/images/plus.gif" : "http://www.nhagiare.com/images/minus.gif");
	bool=!bool;
}


function setTabActiveSimple(idxActive) {
	for(var iTab = 0; iTab <= 5; iTab++) {
		eval("tbList"+iTab).style.display = "none";
		eval("ctrl_tab00"+iTab).className = "";
	} 
	eval("tbList"+idxActive).style.display = "block";
	eval("ctrl_tab00"+idxActive).className = "current";
	
	GetLoai("http://www.nhagiare.com/loadpage.aspx?region=0&loai=" + idxActive,eval("tbList"+idxActive));
}

function setTabActive(val) {
	var arr = new Array("tbBrowserEasy", "tbContents", "tbFindDetails", "tbFindCategory");
	for(var i = 0; i< arr.length; i++) {
		eval(arr[i]).style.display = "none";
		eval("tab00"+i).className = "";
	}
	eval("tab00"+val).className = "current";
	eval(arr[val]).style.display = "block";
}

function expanderList(objCheckTag, numOfItem) {


}
function checkfile(filename) {
	return isExistExtend(filename)||trim(filename)=="";
}
function isExistExtend(str) {
	var t=str.toString().toLowerCase();
	var m=t.split('.');
	if (m.length>=2 && (m[m.length-1]=="jpeg" || 
											m[m.length-1]=="jpg" || 
											m[m.length-1]=="jpe" || 
											m[m.length-1]=="gif" || 
											m[m.length-1]=="png" ||
											m[m.length-1]=="tif" ||
											m[m.length-1]=="tiff")) {
			return true;
	}
	return false;
}
function showMoneyRate(){
	window.open("http://www2.thanhnien.com.vn/news/LiveInfo/MoneyRateP.aspx","_blank","width=135,height=275,resizable=no,toolbars=mo,scrollbar=no");
}
function showGoldPrice() {
	window.open("http://www2.thanhnien.com.vn/news/LiveInfo/GoldPricePage.aspx","_blank","width=155,height=200,resizable=no,toolbars=mo,scrollbar=no");
}
function showStock(){
	window.open("http://www.bsc.com.vn/OP/OP.htm","_blank","width=790,height=650,resizable=no,toolbars=mo,scrollbar=no");
}
function showBigInfo(str){
	window.open("http://www2.thanhnien.com.vn/news/LiveInfo/LotteryPage.aspx?ZURL="+str,"_blank","width=450,height=400,resizable=no,toolbars=mo,scrollbar=yes");
}
function showSouthLottery(){
}
function Login() {
	document.form1.secondtime.value="submit";
	document.form1.submit();
}
/*
function: Trim(string)
- Cut all space at the end and the begining of the string
*/
function trim(str) {
	while (str.indexOf(" ")>=0) str = str.replace(" ","");
	return str;
}
/*
function newCMS()
*/
function newCMS(str) {
	while (str.indexOf(">")>=0) str=str.replace(">","]");
	while (str.indexOf("<")>=0) str=str.replace("<","[");
	while (str.indexOf("'")>=0) str=str.replace("'","~1");
	while (str.indexOf("\"")>=0) str=str.replace("\"","~2");
	return str;
}
/*
function unescapeCMS
*/
function new_unCMS(str) {
	while (str.indexOf("]")>=0) str=str.replace("]",">");
	while (str.indexOf("[")>=0) str=str.replace("[","<");
	while (str.indexOf("~1")>=0) str=str.replace("~1","'");
	while (str.indexOf("~2")>=0) str=str.replace("~2","\"");
	return str;
}
/*
Lofout
*/
function Logout() {
	document.body.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (!confirm("Do you really want to logout ?")) {
		document.body.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=0)";
	}
	else
	{
	    document.form1.secondtime.value="logout";
		document.form1.submit();
		//location = "/region9/index.html";
	}
}
/*
function EndWiths(filename,string)
- Check if filename exist "string" at the and string return true otherwise
*/
function EndWiths(filename, extension){
	filename=filename.toString().toLowerCase();
	extension=extension.toString().toLowerCase();
	var spl=extension.replace("*.");
	for(var j=0;j<spl.length;j++)
		if (filename.charAt(filename.length-1-j)!=spl.charAt(spl.length-1-j)) return false;
	return filename.charAt(filename.length-j-1)=="." ? true : false;
}

/** AJAX **/

var xmlHttp;

function GetLoai(url, obj) {
	xmlHttp=GetMSXmlHttp();
	if (xmlHttp==null)  {
		alert("Trình duyệt không hỗ trợ AJAX !")
	}        
	
	xmlHttp.onreadystatechange = function()
	{
	    if (xmlHttp.readyState==4)   { 
		    var tx = xmlHttp.responseText;
			obj.rows[1].cells[0].innerHTML="<table cellspacing='0' cellpadding='0'>" + tx + "</table>";
        }
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

//===============
function GetMSXmlHttp()
{
	var xmlHttp2 = null;
	if (!window.XMLHttpRequest) {
		var s="";
		var clsids = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0",
								"Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0", 
								"Msxml2.XMLHTTP.2.6","Microsoft.XMLHTTP.1.0", 
								"Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"];
		for(var i=0; i<clsids.length && xmlHttp2 == null; i++) {
				xmlHttp2 = CreateXmlHttp(clsids[i]);
		}
	}
	else { //Firefox;nextscape/opera
		xmlHttp2 = new XMLHttpRequest();
	}
	return xmlHttp2;
}
//=================
function CreateXmlHttp(clsid) {
	var xmlHttp1 = null;
	try {
			xmlHttp1 = new ActiveXObject(clsid);
			lastclsid = clsid;
			return xmlHttp1;
	}
	catch(e) {}
}
