﻿onStartUp();
 
 
 function onStartUp() {
 	if (GetPostVariable("Contact", null) != null)
 			return;
 
 	var timeoutMinute = 60;
 	if (GetPostVariable("ArticleID", null) != null)
 		timeoutMinute = 30;
 	else if (GetPostVariable("ChannelID", null) != null)
 		timeoutMinute = 10;
 	
 	setTimeout("location.reload()", timeoutMinute * 60000);
 }

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(s);
	}
	else 
	{
		// Need to mimic the JavaScript version
		// Netscape 4 and IE 4 and IE 5.0
		return encodeURIComponentNew(s);
	}
}

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)
{
	showWindow('ImageView.htm?' + url.substr(url.indexOf('?') + 1), false, false, true, false, false, false, true, true, 525, 525, 0, 0);
	return false;
}

function showDialog(vLink, vWidth, vHeight)
{
	return showWindow(vLink, false, false, false, false, false, false, true, true, vWidth, vHeight, 0, 0);
}

function showWindow(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vWidth, vHeight, vTop, vLeft)
{
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;

	winDef = '';
	winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
	winDef = winDef.concat('height=').concat(vHeight).concat(',');
	winDef = winDef.concat('width=').concat(vWidth).concat(',');

	if (vCentered)
	{
		winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
		winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	}
	else
	{
		winDef = winDef.concat('top=').concat(vTop).concat(',');
		winDef = winDef.concat('left=').concat(vLeft);
	}

	open(sLink, '_blank', winDef);

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}

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ủ Nhật","Thứ Hai","Thứ Ba","Thứ Tư","Thứ Năm","Thứ Sáu","Thứ Bả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 EncodeUrl(iStr)
{
	var	r1=/&/g;
	var	r2=/ /g;
	var	r3=/"/g;

	iStr	=iStr.replace(r1, '%26');
	iStr	=iStr.replace(r2, '%20');
	iStr	=iStr.replace(r3, '%22');

	return iStr;
}

function Trim(iStr)
{
	while (iStr.charCodeAt(0) <= 32)
	{
		iStr=iStr.substr(1);
	}

	while (iStr.charCodeAt(iStr.length - 1) <= 32)
	{
		iStr=iStr.substr(0, iStr.length - 1);
	}

	return iStr;
}

function GetPostVariable(vName, vDef)
{
	var	str=location.href;
	var	pos=str.indexOf('?'.concat(vName).concat('='));

	if (pos==-1)
	{
		pos=str.indexOf('&'.concat(vName).concat('='));
		if (pos==-1) return vDef;
	}
	
	str=str.substring(pos + vName.length + 2);
	pos=str.indexOf('&');

	if (pos==-1)
	{
		pos=str.length;
	}	

	if (pos > 0)
	{
		str=str.substring(0, pos);
	}

	return str;
}

function DisplaySearchPage(PageCount)
{
document.write('Trang ');
j = GetPostVariable('SearchPage', 1);
for (i = 1; i <= PageCount; i++)
	if (i != j)
		document.write('<a href=index.aspx?SearchQuery=' + GetPostVariable('SearchQuery', 'Error') + '&SearchPage=' + i + '>[' + i + ']&nbsp;</a>');
	else
		document.write('[' + i + ']&nbsp;');
}
	function onLinkClick(link)
	{
		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;
	}
function showImage(url)
{
	showDialog('ImageView.htm?' + url.substr(url.indexOf('?') + 1), 524, 524);
}