﻿// JScript File
//

var theSummaries = new Array();
	var theSiteLinks = new Array();

	// Ticker startup
	function startTicker()
	{
		// Define run time values
		theCurrentStory     = -1;
		theCurrentLength    = 0;
		// Locate base objects
		if (document.getElementById) {	
				theAnchorObject     = document.getElementById("hottext");
				runTheTicker();   	
			 }
	}
	// Ticker main run loop
	function runTheTicker()
	{
		var myTimeout;  
		// Go for the next story data block
		if(theCurrentLength == 0)
		{
			theCurrentStory++;
			theCurrentStory      = theCurrentStory % (theSummaries.length);
			theStorySummary   = theSummaries[theCurrentStory].replace(/&quot;/g,'"');
			theTargetLink        = theSiteLinks[theCurrentStory];
			theAnchorObject.href = theTargetLink;
		}
		// Stuff the current ticker text into the anchor
		theStartPosition = 0;
		if (theCurrentLength > theMaxLength)
		{
			theStartPosition = theCurrentLength - theMaxLength;
		}
		theAnchorObject.innerHTML = theStorySummary.substring(theStartPosition,theCurrentLength) + whatWidget();
		// Modify the length for the substring and define the timer
		if(theCurrentLength != theStorySummary.length)
		{
			theCurrentLength++;
			myTimeout = theCharacterTimeout;
		}
		else
		{
			theCurrentLength = 0;
			myTimeout = theStoryTimeout;
		}
		// Call up the next cycle of the ticker
		setTimeout("runTheTicker()", myTimeout);
	}
	// Widget generator
	function whatWidget()
	{
		if(theCurrentLength == theStorySummary.length)
		{
			return theWidgetNone;
		}
	
		if((theCurrentLength % 2) == 1)
		{
			return theWidgetOne;
		}
		else
		{
			return theWidgetTwo;
		}
	}
	
	var theCharacterTimeout = 100;
	var theStoryTimeout     = 600;
	var theWidgetOne        = "_";
	var theWidgetTwo        = "-";
	var theWidgetNone       = "";
	var theMaxLength		= 70;
	
	
	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 == "")
		ctrl.style.display = "none";
	else
		ctrl.style.display = "";
}

function AboutVega()
{
	alert("mailto:" + "Sales" + "@" + "vega.com.vn");
}




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 showImage(url)
{
	showDialog('ImageView.htm?' + url.substr(url.indexOf('?') + 1), 524, 524);
}



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].toString()+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute)
	document.write(dayarray[dayw].toString()+",  "+day+"/"+month+"/"+year)
}

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)
{
	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 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 = "";
}


