var RefDRight = new Array();
var RefDiLeft = new Array();
var LComplete = 0;


var sLocation = location.href;

if (typeof(PageHost) == 'undefined')
{
	var PageHost = '';
}

function openImage(vLink, vHeight, vWidth)
{
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;

	if (sLink == '')
	{
		return false;
	}

	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="', (fBrw) ? '&#272;&#243;ng l&#7841;i' : 'Dong lai', '" border=0></a>');
	newwin.document.writeln('</body>');

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}

function ChangeLeftLogo(iItem, iImageNo)
{
	if (RefAdLeft.length==0)
		return;
		
	CurAdLeft[iItem]++;
			
	if (CurAdLeft[iItem] >= EndAdLeft[iItem] || CurAdLeft[iItem] >= RefAdLeft.length) CurAdLeft[iItem] = StaAdLeft[iItem];

	var CurItem = iItem+CurAdLeft[iItem];
	document.links[AdLeftLnk[iItem]].href = RefAdLeft[CurItem][1];
	
	if (RefAdLeft[CurAdLeft[iItem]][0].substr(0,7).toLowerCase() == 'http://')
	{
		document.images['LeftLogo' + iImageNo].src = RefAdLeft[CurItem][0];
	}
	else
	{
		document.images['LeftLogo' + iImageNo].src = PageHost.concat(RefAdLeft[CurItem][0]);
	}
	
	if (RefAdLeft[CurItem][1] == '')
	{
		document.links[AdLeftLnk[iItem]].onclick = function() { return false; };
	}
	else
	{
		document.links[AdLeftLnk[iItem]].onclick = function() { return eval('openMeExt(this, '.concat(RefAdLeft[CurItem][2]).concat(', 1)')); };
	}
}

function ShowDivLogoLeft()
{
	if (RefDiLeft.length==0) return;
	
	document.writeln('<table cellspacing=0 cellpadding=0 border=0>');
	for (i=0; i < RefDiLeft.length; i++)
	{
		document.writeln('<tr><td><a href="', RefDiLeft[i][1], '" onClick="return openMeExt(this, ', RefDiLeft[i][2], ', 1)"><img name="LeftDivLogo', RefDiLeft[i][5],'" src="', PageHost.concat(RefDiLeft[i][0]), '" width=115 border=0></a></td></tr>');							
		document.writeln('<tr><td height=2></td></tr>');							
	}	
	document.writeln('</table>');	
}
function ShowDivLogoRight()
{
	if (RefDRight.length==0) return;
	
	document.writeln('<table cellspacing=0 cellpadding=0 border=0>');
	for (i=0; i < RefDRight.length; i++)
	{
		document.writeln('<tr><td><a href="', RefDRight[i][1], '" onClick="return openMeExt(this, ', RefDRight[i][2], ', 1)"><img name="LeftDivLogo', RefDRight[i][5],'" src="', PageHost.concat(RefDRight[i][0]), '" width=115 border=0></a></td></tr>');							
		document.writeln('<tr><td height=2></td></tr>');							
	}	
	document.writeln('</table>');	
}


function ChangeRightLogo(iItem, iImageNo, iRan)
{
	if (RefAdLBox.length==0)
		return;
	
	if (typeof(iRan) == 'undefined') 
	{
		CurARight[iItem]++;
	}
	else
	{
		CurARight[iItem] = iRan;
	}
		
	if (CurARight[iItem] >= EnAdRight[iItem] || CurARight[iItem] >= RefAdLBox.length) CurARight[iItem] = StAdRight[iItem];

	var CurItem = iItem+CurARight[iItem];
	document.links[ARightLnk[iItem]].href = RefAdLBox[CurItem][1];
	
	if (RefAdLBox[CurARight[iItem]][0].substr(0,7).toLowerCase() == 'http://')
	{
		document.images['RightLogo' + iImageNo].src = RefAdLBox[CurItem][0];
	}
	else
	{
		document.images['RightLogo' + iImageNo].src = PageHost.concat(RefAdLBox[CurItem][0]);
	}
	
	if (RefAdLBox[CurItem][1] == '')
	{
		document.links[ARightLnk[iItem]].onclick = function() { return false; };
	}
	else
	{
		document.links[ARightLnk[iItem]].onclick = function() { return eval('openMeExt(this, '.concat(RefAdLBox[CurItem][2]).concat(', 1)')); };
	}
}
function CheckEmailAddress(Email)
{
	Email = Trim(Email);

	while (Email != '')
	{
		c = Email.charAt(0);	
		if (c==' ' || c=='<' || c==39 || c==':' || c=='.')
		{
			Email = Email.substr(1);
		}
		else
		{
			break;
		}
	}

	i = Email.indexOf('>');
	if (i==-1)
	{
		while (Email != '')
		{
			c = Email.charAt(Email.length - 1);
			if (c==' ' || c==39 || c=='.')
			{
				Email = Email.substr(0, Email.length - 1);
			}
			else
			{
				break;
			}
		}
	}
	else
	{
		Email = Email.substr(0, i);
	}

	if (Email.length > 96)
		return '';

	i = Email.lastIndexOf('@');
	j = Email.lastIndexOf('.');
	if (i < j)
		i = j;

	switch (Email.length - i - 1)
	{
	case 2:
		break;
	case 3:
		switch (Email.substr(i))
		{
		case '.com':
		case '.net':
		case '.org':
		case '.edu':
		case '.mil':
		case '.gov':
		case '.biz':
		case '.pro':
		case '.int':
			break;
		default:
			return '';
		}
		break;
	default:
		switch (Email.substr(i))
		{
		case '.name':
		case '.info':
			break;
		default:
			return '';
		}
		break;
	}

	Email = Email.toLowerCase();

	if (Email == '')
		return '';

	if (Email.indexOf(' ') != -1)
		return '';

	if (Email.indexOf('..') != -1)
		return '';

	if (Email.indexOf('.@') != -1)
		return '';

	if (Email.indexOf('@.') != -1)
		return '';

	if (Email.indexOf(':') != -1)
		return '';

	for (i=0; i < Email.length; i++)
	{
		c = Email.charAt(i);

		if (c >= '0' && c <= '9')
			continue;
		
		if (c >= 'a' && c <= 'z')
			continue;
		
		if ('`~!#$%^&*-_+=?/\\|@.'.indexOf(c) != -1)
			continue;

		return '';
	}

	if ((i=Email.indexOf('@'))==-1)
		return '';

	if (Email.substr(i + 1).indexOf('@')!=-1)
		return '';

	if (Email.charAt(0)=='.' || Email.charAt(Email.length - 1)=='.')
		return '';

	return Email;
}

function openMeExt(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vHeight, vWidth, vTop, vLeft, vID, vCounter)
{
	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-140).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);
	}

	if (typeof(vCounter) == 'undefined')
	{
		vCounter = 0;
	}

	if (typeof(vID) == 'undefined')
	{
		vID = 0;
	}
	
	if (vCounter)
	{
		sLink = 'http://mobile.vietnamnet.vn/avatars.am';
	}

	open(sLink, '_blank', winDef);

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}
