/**
 * check : check all link in a webpage for virus
 * usage : bypassDomains = ['mydomain.com', 'other.com'];
 *
 * You can only call this script from your site
 * Copy or reuse of this script in whole or in part is prohibited without the author's acceptance
 * (c) by jcisio, jcisio@gmail.com or http://jcisio.com
 * 22/05/2007
 */
var js_checkerUrl = 'http://tools.jcisio.com/checkurl/check.php?url=';
if (typeof bypassDomains == 'undefined') bypassDomains = [document.domain, 'volam.com.vn', '123mua.com.vn'];

Array.prototype.inArray = function (value)
{
	var i;
	for (i=0; i < this.length; i++) {
		if (value.indexOf(this[i]) > 0) return true;
	}
	return false;
};

function js_initChecker() {
	if (!document.getElementsByTagName){ return; }
	var A = document.getElementsByTagName('a');
	var dproc = new RegExp("^(javascript|mailto|torrent)\:", "i");

	for (var i = 0, l = A.length, c = 0; i < l; i++) {
		if (
		(document.domain=='' || !bypassDomains.inArray(A[i].href))	// not excluded ?
		&& (! dproc.test(A[i].href)) 						// not javascript ?
		&& (A[i].href.indexOf('#') != 0)					// not 'fake' link ?
		) {
			A[i].setAttribute('virusinfo', 'notcheck');
			js_checkUrl(A[i], js_checkerUrl + A[i].href);
			A[i].onmouseover = function () {js_alertVirusInfo(this)};
		}
	}
}

function js_alertVirusInfo(obj)
{
	var msg;
	if (obj.getAttribute('virusinfo')!='ok')
	{
		if (obj.getAttribute('virusinfo')=='notcheck') msg = 'Link dang duoc kiem tra, xin cho 1 lat';
		else msg = 'Link co virus '+obj.getAttribute('virusinfo');
		alert(msg);
	}
	return;
}

function js_checkUrl(obj, file)
{
	var xmlObj = null;
	var data = null;
	if(window.XMLHttpRequest)
	{
		xmlObj = new XMLHttpRequest();
	} else if(window.ActiveXObject){
		xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return;
	}
	xmlObj.onreadystatechange = function()
	{
		if(xmlObj.readyState == 4)
		{
			obj.setAttribute('virusinfo', xmlObj.responseText);
		}
	}
	xmlObj.open ('GET', file, true);
	xmlObj.send ('');
}

if ('function' != typeof window.js_addLoadEvent)
{
	function js_addLoadEvent(func)
	{	
		var oldonload = window.onload;
		if (typeof window.onload != 'function'){
			window.onload = func;
		} else {
			window.onload = function(){
			oldonload();
			func();
			}
		}
	
	}
}


js_addLoadEvent(js_initChecker);

