﻿var isIE = (navigator.userAgent.indexOf('MSIE') != -1);

function AboutVietAd()
{
	alert("mailto:" + "contact" + "@" + "vietad.vn");
}

function showDialog(url, width, height)
{
	return showWindow(url, false, false, false, false, false, false, false, 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;
	}
	
	var config = '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;
	
	open(url, '_blank', config);
}

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+"")
}

function writeTime()
{
	var mydate= new Date()
	
	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+"")
}

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 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 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 ParseKeyword(id)
{
    var txtKeyword = document.getElementById(id); 
	var q = Trim(txtKeyword.value);
		
	if (q == '')
		return true;
	
	if ((q.indexOf('AND') == -1) && (q.indexOf('OR') == -1) && (q.indexOf('"') == -1))
		q = '"' + q + '"';
	txtKeyword.value = q;
	
	return true;
}

function onCmdSearchClick()
{
	var q = Trim(document.SearchSubmit.SearchQuery.value);
	
	if (q == '')
		return false;
		
	if ((q.indexOf('AND') == -1) && (q.indexOf('OR') == -1) && (q.indexOf('"') == -1))
		q = '"' + q + '"';
	
	document.SearchSubmit.SearchQuery.value = q;
	
	return true;
}