var isIE = (navigator.userAgent.indexOf('MSIE') != -1);
if (window.parent!=window)
 { 
  alert('Trang web ban dang vao khong phai la website chinh thuc cua Tuoi Tre. Tuoi Tre khong chiu trach nhiem ve tinh chinh xac cua thong tin cung do an toan cua trang web nay.\r\nVui long nhan OK de quay lai trang chinh thuc www.tuoitre.com.vn');
  window.open(location.href, '_top', '');
 }
 
// channelSampleToday.ascx
function boldStr( srcStr,splitStr )
{
	var splitPosition = srcStr.indexOf(splitStr);
	
	if (splitPosition != -1)
	{		
		var lastIndex = srcStr.lastIndexOf(' ');				
		var stop = srcStr.charAt(lastIndex+1);
		while( stop != '' )
		{
			lastIndex++;
			stop = srcStr.charAt(lastIndex);
		}		
		
		var firstStr = srcStr.substring(0, splitPosition);		
		var lastStr = srcStr.substring(splitPosition, lastIndex);		
		srcStr = "<b>" + firstStr + "</b>" + lastStr;				
	}
	
	document.write(srcStr);			
}

//Media
//function changeSource( strSource )
//{
	//media = document.getElementById("winMediaPlayerID");
	//media.URL = strSource;
//}

function switchVisible(ctrl)
{
	if (ctrl.style.display == "inline")
		ctrl.style.display = "none";
	else
		ctrl.style.display = "inline";
}

function AboutVega()
{
	alert("mailto:" + "Sales" + "@" + "vega.com.vn");
}

function fixChannelVieclamUrl()
{
	var links = document.getElementsByTagName("a"); 
	var tagNum = links.length; 
	var hrefStr = "";
	
	for(i = 0; i < tagNum; i++)
	{                        
		hrefStr = links[i].href;		
		if ( hrefStr == 'http://www.tuoitre.com.vn/Tianyon/Index.aspx?ChannelID=269' )
		{
			links[i].href = 'http://vieclam.tuoitre.com.vn'; 
		} 
	} 
}

function fixChannelUrl(channelID, findwhat, replacewith)
{
	var links = document.getElementsByTagName("a"); 
	var tagNum = links.length; 
	var hrefStr = "";
	var index = -1; 
	
	var currentChannel = GetPostVariable("ChannelID", -1);
	var currentURL = window.location.href + "&";	
	currentURL = currentURL.toLowerCase(); 
	index = currentURL.indexOf("/tianyon/"); 
	if((currentChannel == channelID)  && (index != -1))
	{
		index = currentURL.indexOf("channelid="+channelID+"&", 0); 
		if (index != -1)
		{
			window.location.href = window.location.href.replace(findwhat, replacewith); 			
		} 
		return;
	}
	
	for(i = 0; i < tagNum; i++)
	{                        
		hrefStr = links[i].href + "&";
		
		hrefStr=hrefStr.toLowerCase(); 
		
		index = hrefStr.indexOf("channelid="+channelID+"&", 0); 
		if (index != -1)
		{
			links[i].href = links[i].href.replace(findwhat, replacewith); 
		} 
	} 
} 

function onBodyLoad() 
{
	fixChannelUrl(142, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	fixChannelUrl(224, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	fixChannelUrl(230, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	fixChannelUrl(101, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	fixChannelUrl(222, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	fixChannelUrl(183, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	fixChannelUrl(225, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	fixChannelUrl(227, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	fixChannelUrl(228, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	fixChannelUrl(229, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Tuyensinh");
	
	//fixChannelUrl(150, /Tianyon/gi, "thethao");
	fixChannelUrl(14,  /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(4,   /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(248, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(249, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");	
	fixChannelUrl(251, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(146, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(247, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(246, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(5,   /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");	
	fixChannelUrl(254, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(252, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(260, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(267, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	fixChannelUrl(250, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/thethao");
	
	fixChannelVieclamUrl();
	fixChannelUrl(269, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Vieclam");		
	fixChannelUrl(270, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Vieclam");
	fixChannelUrl(271, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Vieclam");
	fixChannelUrl(272, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Vieclam");
	fixChannelUrl(273, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Vieclam");
	fixChannelUrl(274, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Vieclam");
	fixChannelUrl(275, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Vieclam");
	fixChannelUrl(276, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Vieclam");
	
	fixChannelUrl(279, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Seagames23");
	fixChannelUrl(281, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Seagames23");
	fixChannelUrl(282, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Seagames23");
	fixChannelUrl(283, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Seagames23");
	fixChannelUrl(284, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Seagames23");
	fixChannelUrl(285, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Seagames23");
	fixChannelUrl(286, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/Seagames23");
	
	fixChannelUrl(212, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TetOnline");
	fixChannelUrl(338, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TetOnline");
	fixChannelUrl(207, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TetOnline");	
	
	fixChannelUrl(352, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/worldcup2006");
	fixChannelUrl(353, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/worldcup2006");
	fixChannelUrl(354, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/worldcup2006");
	fixChannelUrl(355, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/worldcup2006");
	fixChannelUrl(356, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/worldcup2006");
	fixChannelUrl(357, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/worldcup2006");
	fixChannelUrl(358, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/worldcup2006");
	fixChannelUrl(359, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/worldcup2006");

	fixChannelUrl(103, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
	fixChannelUrl(372, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
	fixChannelUrl(373, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
	fixChannelUrl(374, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
	fixChannelUrl(375, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
	fixChannelUrl(376, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
	fixChannelUrl(377, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
	fixChannelUrl(378, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
	fixChannelUrl(380, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
	fixChannelUrl(117, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");	
	fixChannelUrl(116, /www.tuoitre.com.vn\/Tianyon/gi, "www3.tuoitre.com.vn/TTC");
		
	fixChannelUrl(278, /www.tuoitre.com.vn/gi, "media.tuoitre.com.vn?");
		
	fixChannelUrl(371, /www.tuoitre.com.vn\/Tianyon\/Index.aspx\?ChannelID=371/gi, "www3.tuoitre.com.vn/Tusach");	
	fixChannelUrl(371, /www.tuoitre.com.vn\/Tianyon\/Index.aspx/gi, "www3.tuoitre.com.vn/Tusach/Book/ArticleView.aspx");

	fixChannelUrl(401, "www.tuoitre.com.vn/Tianyon/Index.aspx?ChannelID=401", "www3.tuoitre.com.vn/TetOnline/");	
	fixChannelUrl(401, /www.tuoitre.com.vn\/Tianyon\/Index.aspx/gi, "www3.tuoitre.com.vn/TetOnline/Index.aspx");

 	//setTimeout("location.reload()", timeoutMinute * 60000);
 	//if (location.search=='') showWindow('/Advertisement/thongbao.htm', false, false, false, false, false, false, true, false, 215, 202, 50, 575);
 	
 	setTimeout("ReloadPage()", 600000);
 }
 
 function ReloadPage()
{
	setTimeout("ReloadPage()", 600000);
	if((GetPostVariable("ArticleID", "-1")!="-1")||(GetPostVariable("ContactID", "-1")!="-1"))
	{
		return;
	}
	else
	{
		location.reload();
	}
}

function utf8(wide) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}

function buildURL(fld)
{
	if (typeof encodeURIComponent == "function")
	{
		// Use JavaScript built-in function
		// IE 5.5+ and Netscape 6+ and Mozilla
		return encodeURIComponent(fld);
	}
	else 
	{
		// Need to mimic the JavaScript version
		// Netscape 4 and IE 4 and IE 5.0
		return encodeURIComponentNew(fld);
	}
}

function destroyURL(fld)
{
	if (typeof decodeURIComponent == "function")
	{
		// Use JavaScript built-in function
		// IE 5.5+ and Netscape 6+ and Mozilla
		return decodeURIComponent(fld);
	}
	else 
	{
		// Need to mimic the JavaScript version
		// Netscape 4 and IE 4 and IE 5.0
		return "";
	}
}

function moveCalendar(offset)
{
	var currentDate = new Date();

	var dateString = GetPostVariable('Date', '');
	if (dateString != '')
	{
		var dateElements = dateString.split('-');
		var t = dateElements[0];
		dateElements[0] = dateElements[1];
		dateElements[1] = t;
		currentDate = new Date(dateElements.join('-'));
		
	}
	currentDate = new Date(currentDate.setDate(currentDate.getDate() + offset));
	dateString = currentDate.getDate() + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getYear();
	
	location.search = 'ChannelID=' + GetPostVariable('ChannelID', 1) + '&Date=' + dateString;
}

function showImage(url)
{
	showDialog('ImageView.htm?' + url.substr(url.indexOf('?') + 1), 524, 524);
}

function showDialog(url, width, height)
{
	return showWindow(url, false, false, false, false, false, false, true, true, width, height, 0, 0);
}

function showWindow(url, isStatus, isResizeable, isScrollbars, isToolbar, isLocation, isFullscreen, isTitlebar, isCentered, width, height, top, left)
{
	if (isCentered)
	{
		top = (screen.height - height) / 2;
		left = (screen.width - width) / 2;
	}

	open(url, '_blank', 'status=' + (isStatus ? 'yes' : 'no') + ','
	+ 'resizable=' + (isResizeable ? 'yes' : 'no') + ','
	+ 'scrollbars=' + (isScrollbars ? 'yes' : 'no') + ','
	+ 'toolbar=' + (isToolbar ? 'yes' : 'no') + ','
	+ 'location=' + (isLocation ? 'yes' : 'no') + ','
	+ 'fullscreen=' + (isFullscreen ? 'yes' : 'no') + ','
	+ 'titlebar=' + (isTitlebar ? 'yes' : 'no') + ','
	+ 'height=' + height + ',' + 'width=' + width + ','
	+ 'top=' + top + ',' + 'left=' + left);
}

function writeTime(s)
{
	var mydate=new Date(s)
	
	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 getTimeString(s)
{
	document.write("<span class=LargeTime2>");
	writeTime(s);
	document.write("</span>")
}

function Trim(s)
{
var i = 0;
while ((i < s.length) && (s.charCodeAt(i) == 32))
	i++;

var j = s.length - 1;
while ((j > i) && (s.charCodeAt(j) == 32))
	j--;

return s.substr(i, j - i + 1);
}

function GetPostVariable(param, defval)
{
	param = param.toLowerCase();  

	var	s = '&' + location.search.substr(1).toLowerCase(); 
	
	//var	s = '&' + location.search.substr(1);
	
	var	i = s.indexOf('&' + param + '=');
	if (i == -1) return defval;

	s = s.substr(i + param.length + 2);
	i = s.indexOf('&');
	if (i == -1) return s;

	return s.substr(0, i);
}

function DisplaySearchPage(PageCount)
{
document.write('Trang ');
j = GetPostVariable('SearchPage', 1);
for (i = 1; i <= PageCount; i++)
	if (i != j)
		document.write('<a class="SearchPage" href=index.aspx?SearchQuery=' + GetPostVariable('SearchQuery', 'Error') + '&SearchPage=' + i + '>' + i + '&nbsp;</a>');
	else
		document.write('[' + i + ']&nbsp;');
i = parseInt(j) + 1;
if (j < PageCount)
	document.write('&nbsp;<a class="SearchPage" href=index.aspx?SearchQuery=' + GetPostVariable('SearchQuery', 'Error') + '&SearchPage=' + i + '>Xem ti&#7871;p&nbsp;</a>');
}

function onLinkClick(link)
{
if (isIE)	//Mozilla and FireFox don't support non-standard attribute
{	
	window.open(link.href, '', 
	'toolbar='+link.toolbar+
	',location='+link.location+
	',status='+link.statusbar+
	',menubar='+link.menubar+
	',scrollbars='+link.scrollbars+
	',resizable='+link.resizable+
	',width='+link.width+
	',height='+link.height+
	',top='+link.top+
	',left='+link.left);
	return false;
}
else{
	window.open(link.href, 'name', 'height=800, width=1200, left=0, top=0, resizable=yes, scrollbars=yes, toolbar=yes, status=yes');
	return false;
}
}


function onLinkClickFull(link)
{
if (isIE)	//Mozilla and FireFox don't support non-standard attribute
{	
	window.open(link.href, '', 
	'toolbar='+link.toolbar+
	',location='+link.location+
	',status='+link.statusbar+
	',menubar='+link.menubar+
	',scrollbars= yes'+
	',resizable= yes'+
	',width= 770' +
	',height= 1000' +
	',top='+link.top+
	',left='+link.left);
	return false;
}
}


function displayInfo(info)
{
	if (info == 'weather')
		showDialog('http://www3.tuoitre.com.vn/transweb/rams.htm', 492, 659);
	if (info == 'forex')
		showDialog('http://www3.tuoitre.com.vn/transweb/tygia.htm', 460, 432);
	if (info == 'gold')
		showDialog('http://www3.tuoitre.com.vn/transweb/giavang.htm', 450, 220);
	if (info == 'tvguide')
		showWindow('http://www3.tuoitre.com.vn/transweb/truyenhinh.htm', false, false, true, false, false, false, true, true, 450, 354, 0, 0);
	if (info == 'lottery')
		showWindow('http://www3.tuoitre.com.vn/Transweb/XoSo.html', false, false, true, false, false, false, true, true, 450, 600, 0, 0);
		//showDialog('http://www3.tuoitre.com.vn/transweb/xoso.htm', 600, 346);
		//showDialog('http://www.xsktcantho.com.vn/xsktcantho.asp', 1024, 1350);
	if (info == 'stock')
		showDialog('http://www3.tuoitre.com.vn/transweb/chungkhoan.htm', 770, 750);
}

function setHomePage(ctrl)
{
	ctrl.style.behavior='url(#default#homepage)';
	ctrl.setHomePage(location.host);
}
function switchDisplay(id)
{
	ctrl = document.getElementById(id);
	if (ctrl.style.display == "")
		ctrl.style.display = "none";
	else
		ctrl.style.display = "";
}

function onCmdSearchClick(SearchQuery)
{
	//var q = Trim(document.SearchSubmit.SearchQuery.value);
	
	var q = Trim(SearchQuery.value);
	
	if (q == '')
		return false;
		
	if ((q.indexOf('AND') == -1) && (q.indexOf('OR') == -1) && (q.indexOf('"') == -1))
		q = '"' + q + '"';
	
	
	SearchQuery.value = q;
	
	//document.SearchSubmit.SearchQuery.value = q;
	
	return true;
}


function DisplayBrowserTitle(){
	var oContent = document.getElementById("divContent");
	
	var arrayTag = oContent.getElementsByTagName("P");
	
	for (var i = 0; i < arrayTag.length; i++)
	{
		if (arrayTag[i].className == "pTitle")
		{
			var sTitle = arrayTag[i].innerHTML;
			
			// Remove all tag			
			while(true)
			{
				if (sTitle.indexOf("<") == -1 || sTitle.indexOf(">") == -1)
				{
					break;
				}
				var startIndex = sTitle.indexOf("<");
				var endIndex = sTitle.indexOf(">");
				var sRemoval = sTitle.substring(startIndex, endIndex + 1);
				sTitle = sTitle.replace(sRemoval, "");
			}
			break;
		}
	}
	
	document.title = document.title + " - " + sTitle;
}

/***********************************
            String Cut
************************************/
function cutStrExper( head, length )
{
    if(head == "?")
    {
        document.write("");
		return;
    }
        
   	var strLen = head.length;
	if (strLen > length)
	{
		head = head.substr(0, length+5) ;
		
		var lastIndexOfSpace = head.lastIndexOf(' ');
		
		if (lastIndexOfSpace > 0)
        {
            head = head.substr(0, lastIndexOfSpace) ;
        }
        else 
        {
            head = head.substr(0, length) ;
        }
		
		document.write(head + " ...");
		return;
	}
	else
	{
		document.write(head);		
	}		
}

/*
function hidestatus(){
window.status=''
return true
}

if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)

document.onmouseover=hidestatus
document.onmouseout=hidestatus
*/
