/* Global variables */
var inxDomain = 1;
var inxWhoIs = 2;
var inxYaType = 3;
var inxtCY = 4;
var inxYaTypeC = 5;
var inxtCYc = 6;
var inxYaIndex = 7;
var inxPR = 8;
//var inxPRfraud = 9;
//var inxwwwPR = 9;
//var inxwwwPRfraud = 11;
var inxGLinks = 9;
var inxGIndex = 10;
var inxGInfo = 11;
var inxYahooLinks = 12;
var inxWebArch = 13;
var inxDmoz = 14;
var inxAlexa = 15;
var inxRIndex = 16;
var inxMSNIndex = 17;
var inxYaLinks = 18;

var names = new Array(
    "",
    Labels.domain,
    "WhoIs",
    "YaTypet",
    "tCYt",
    "YaType",
    "tCY",
//    "YaLinksP",
//    "YaLinksS",
    "YaIndex",
    "PR",
//    "PRfraud",
//    "wwwPR",
//    "wwwPRfraud",
    "GLinks",
    "GIndex",
    "GInfo",
    "YahooLinks",
    "WebArch",
    "DMOZ",
    "AlexaRank",
    "RIndex",
    "MSNIndex",
    "YaLinks"
);
var inxMax = names.length;

/* Domains parse functions */
function getCleanDomain(domain) {
	if (domain.substr(0,4) == "www." && domain.substr(4).indexOf(".") != -1)
		return domain.substr(4);
	else
		return domain;
}

function getRHost(domain) {
	var lastPoint = domain.lastIndexOf(".");
	if (lastPoint != -1)
		return domain.substr(lastPoint + 1) + "." + getRHost(domain.substr(0, lastPoint));
	else
		return domain;
}

/* Check SEO parameter functions */
function getHttpReq(domain, pars, ignoreLoading, url, callback) {
    if (!(domain in base))
        return;

    var used = false;
    for (var i=0; i<pars.length; i++)
        if (use[pars[i]]) {
            used = true;
            break;
        }
    if (!used)
        return;
    if (!ignoreLoading) {
        var load = true;
        for (var i=0; i<pars.length; i++)
            if (base[domain][pars[i]] != loading) {
                load = false;
                break;
            }
        if (load)
            return;
    }

    totalCountChange(1);
    for (var i=0; i<pars.length; i++)
        setVal(domain, pars[i], loading);

    var httpReq;
    try {httpReq = new XMLHttpRequest();} catch(e) {}
    try {httpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");} catch(e) {}
    if (!httpReq)
      return;
    try {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} catch(e) {}
    httpReq.open("GET", url, true);
    httpReq.onreadystatechange = function() {
      if (httpReq.readyState == 4) {
        totalCountChange(-1);
        callback(httpReq);
      }
    };
    httpReq.send(null);

    return httpReq;
}

function checkWhoIs(domain) {
    getHttpReq(domain, [inxWhoIs], false, "https://www.nic.ru/whois/?query="+domain, function(httpReq) {
        if (httpReq.responseText.indexOf("Ошибка: сервис временно недоступен (50") != -1 && !stopped && domain in base) {
            base[domain][inxWhoIs] = undefined;
            setTimeout("checkWhoIs('"+domain+"')", 10);
            return;
        }
        var res, arr;
        if (httpReq.responseText.indexOf('Домен занят') != -1) {
            if (arr = httpReq.responseText.match(/created:.*?(\d\d\d\d)\.(\d\d)\.(\d\d)/))
              res = arr[3] + '.' + arr[2] + '.' + arr[1];
            else if (arr = httpReq.responseText.match(/(?:Creation Date|Created On): ?(\d\d)-([a-zA-Z]{3})-(\d\d\d\d)/)) {
              var d = new Date(Date.parse(arr[2] + ' ' + arr[1] + ', ' + arr[3]));
              var day = d.getDate();
              var month = d.getMonth() + 1;
              var year = d.getFullYear();
              res = (day < 10 ? '0' : '') + day + '.' + (month < 10 ? '0' : '') + month + '.' + year;
            }
            else
              res = '<font color="#ff0000">N/A</font>';
        } else if (httpReq.responseText.indexOf("Доменное имя свободно!") != -1) {
            res = '<font color="#009900">Free</font>';
        } else if (httpReq.responseText.indexOf("Доменное имя недоступно") != -1) {
            res = 'Bad name';
        } else if (httpReq.responseText.search(/Информация по доменам в зоне \S+ не предоставляется/m) != -1) {
            res = 'Unknown zone';
        }

        setVal(domain, inxWhoIs, res);

        doAD(domain);
    });
}

function checkCYc(domain) {
    getHttpReq(domain, [inxYaTypeC, inxtCYc], false, "http://search.yaca.yandex.ru/yca/cy/ch/"+domain+"/", function(httpReq) {
        if (httpReq.responseText.length == 0 && !stopped && domain in base) {
            base[domain][inxYaTypeC] = undefined;
            base[domain][inxtCYc] = undefined;
            setTimeout("checkCYc('"+domain+"')", 10);
            return;
        }
        var arr, err, yca, mirror, tcy;
        if (arr = httpReq.responseText.match(/индекс цитирования (.+?)\s+<\/TITLE>/im)) {
            var realDomain = arr[1];
            var trueDomain = getCleanDomain(realDomain);

            if (httpReq.responseText.indexOf('ресурс не описан в Яндекс.Каталоге') != -1)
                yca = false;
            else
                yca = true;

            if (trueDomain != domain)
                mirror = true;
            else
                mirror = false;

            if (yca) {
                realDomain = realDomain.replace(/\./gm, "\\.");
                trueDomain = trueDomain.replace(/\./gm, "\\.");
                if (arr = httpReq.responseText.match(new RegExp("<a href=\"http://"+realDomain+"/\".+?</a>\\s*<div>.+?</div>\\s*</td>\\s*<td align=\"right\">(\\d+)</td>", "im")))
                    tcy = parseInt(arr[1], 10);
                else if (arr = httpReq.responseText.match(new RegExp("<a href=\"http://www\."+trueDomain+"/\".+?</a>\\s*<div>.+?</div>\\s*</td>\\s*<td align=\"right\">(\\d+)</td>", "im")))
                    tcy = parseInt(arr[1], 10);
                else if (arr = httpReq.responseText.match(new RegExp("<a href=\"http://"+trueDomain+"/\".+?</a>\\s*<div>.+?</div>\\s*</td>\\s*<td align=\"right\">(\\d+)</td>", "im")))
                    tcy = parseInt(arr[1], 10);
            } else {
                if (httpReq.responseText.search(/Индекс цитирования \(тИЦ\) ресурса\s+меньше 10\./im) != -1)
                    tcy = 0;
                else if (arr = httpReq.responseText.match(/Индекс цитирования \(тИЦ\) ресурса(?:&nbsp;| )(?:&#151;|&mdash;|—)(?:&nbsp;| )(\d+)/))
                    tcy = parseInt(arr[1], 10);
            }
        }

        var yaType;
        if (mirror)
            yaType = '<font color="#ff0000">Mirror</font>';
        else if (yca)
            yaType = '<font color="#009900">YaCatalog</font>';
        else if (mirror === false && yca === false)
            yaType = '';

        setVal(domain, inxYaTypeC, yaType);
        setVal(domain, inxtCYc, tcy);

        doAD(domain);
    });
}

/* Fast, but not accurate */
function checkCY(domain) {
    var httpReq = getHttpReq(domain, [inxYaType, inxtCY], false, "http://bar-navig.yandex.ru/u?ver=2&show=32&url=http://" + domain, function(httpReq) {
            if (httpReq.responseText.length == 0 && !stopped && domain in base) {
                base[domain][inxYaType] = undefined;
                base[domain][inxtCY] = undefined;
                setTimeout("checkCY('"+domain+"')", 10);
                return;
            }
            try {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} catch(e) {}

            var arr, yca, mirror, tcy;
            var trueDomain = getCleanDomain(httpReq.responseXML.getElementsByTagName("url")[0].getAttribute("domain"));
            if (trueDomain == domain)
                mirror = false;
            else
                mirror = true;

            if (httpReq.responseXML.getElementsByTagName("topics")[0].getElementsByTagName("topic").length > 0)
                yca = true;
            else
                yca = false;

            tcy = httpReq.responseXML.getElementsByTagName("tcy")[0].getAttribute("value");
            if (tcy.length == 0)
                tcy = -1;
            else
                tcy = parseInt(tcy, 10);

            var yaType;
            if (mirror)
                yaType = '<font color="#ff0000">Mirror</font>';
            else if (yca)
                yaType = '<font color="#009900">YaCatalog</font>';
            else if (mirror === false && yca === false)
                yaType = '';

            setVal(domain, inxYaType, yaType);
            setVal(domain, inxtCY, tcy);

            doAD(domain);
    });
//    checkwwwCY(domain);
}

/*function checkwwwCY(domain) {
    var httpReq = getHttpReq(domain, [inxYaType, inxtCY], true);
    if (!httpReq)
        return;

    var url = "http://bar-navig.yandex.ru/u?ver=2&show=32&url=http://www." + domain;
    try {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} catch(e) {}
    httpReq.open("GET", url, true);
    httpReq.onreadystatechange = function() {
        if (httpReq.readyState == 4) {
            totalCountChange(-1);
            if (httpReq.responseText.length == 0 && !stopped && domain in base) {
                base[domain][inxYaType] = undefined;
                base[domain][inxtCY] = undefined;
                setTimeout("checkCY('"+domain+"')", 10);
                return;
            }
            try {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} catch(e) {}

            var arr, yca, mirror, tcy;
            var trueDomain = getCleanDomain(httpReq.responseXML.getElementsByTagName("url")[0].getAttribute("domain"));
            if (trueDomain == domain)
                mirror = false;
            else
                mirror = true;

            if (httpReq.responseXML.getElementsByTagName("topics")[0].getElementsByTagName("topic").length > 0)
                yca = true;
            else
                yca = false;

            tcy = httpReq.responseXML.getElementsByTagName("tcy")[0].getAttribute("value");
            if (tcy.length == 0)
                tcy = -1;
            else
                tcy = parseInt(tcy, 10);

            var yaType;
            if (mirror)
                yaType = '<font color="#ff0000">Mirror</font>';
            else if (yca)
                yaType = '<font color="#009900">YaCatalog</font>';
            else if (mirror === false && yca === false)
                yaType = '';

            base[domain].wwwyaType = yaType;
            base[domain].wwwtcy = tcy;
            showTCY(domain);
        }
    }
    httpReq.send(null);
}

function showTCY(domain) {
    if ("tcy" in base[domain] && "wwwtcy" in base[domain]) {
        if (base[domain].tcy < base[domain].wwwtcy) {
//            base[domain].wwwyatcy = true;
//            if (base[domain].tr)
//                base[domain].tr.cells[inxtCY].innerHTML = getTDHTML(inxtCY, domain);
            setVal(domain, inxtCY, base[domain].wwwtcy);
        } else {
            setVal(domain, inxtCY, base[domain].tcy);
        }
        delete base[domain].tcy;
        delete base[domain].wwwtcy;

        if (base[domain].yaType.length > 0)
            setVal(domain, inxYaType, base[domain].yaType);
        else
            setVal(domain, inxYaType, base[domain].wwwyaType);
        delete base[domain].yaType;
        delete base[domain].wwwyaType;

        doAD(domain);
    }
}*/

/*function checkYaLinks(domain) {
    var httpReq = getHttpReq(domain, [inxYaLinksP, inxYaLinksS]);
    if (!httpReq)
        return;

    var fullDomain = "www." + domain + "," + domain;
    var url = "http://www.yandex.ru/yandsearch/?Link="+fullDomain+"&iserverurl="+fullDomain;
    try {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} catch(e) {}
    httpReq.open("GET", url, true);
    httpReq.onreadystatechange = function() {
        if (httpReq.readyState == 4) {
            totalCountChange(-1);
            var arr, linksP, linksS;
            if (arr = httpReq.responseText.match(/Результат поиска: страниц&nbsp;&mdash; <b>((?:\d+(?:&nbsp;)?)+)<\/b>, сайтов&nbsp;&mdash; не менее <b>((?:\d+(?:&nbsp;)?)+)<\/b>/im)) {
                linksP = parseInt(arr[1].replace(/&nbsp;/igm, ""), 10);
                linksS = parseInt(arr[2].replace(/&nbsp;/igm, ""), 10);
            } else if (httpReq.responseText.indexOf("Искомая комбинация слов нигде не встречается") != -1) {
                linksP = 0;
                linksS = 0;
            }

            setVal(domain, inxYaLinksP, linksP);
            setVal(domain, inxYaLinksS, linksS);

            doAD(domain);
        }
    }
    httpReq.send(null);
}*/

function getYaCount(text) {
            var arr, yaIndex;
            if (text.indexOf("Искомая комбинация слов нигде не встречается") != -1) {
                yaIndex = 0;
            } else if (arr = text.match(/(?:ашёлся|ашлось)(?:<br\/>)?\s*(\d+)(?:&nbsp;)?\s*ответ/im)) {
                yaIndex = parseInt(arr[1].replace(/&nbsp;/igm, ""), 10);
            } else if (arr = text.match(/ашлось(?:<br\/>)?\s*(\d+)(?:&nbsp;)?\s*тыс\.(?:&nbsp;)?\s*ответов/im)) {
                yaIndex = parseInt(arr[1].replace(/&nbsp;/igm, ""), 10)*1000;
            } else if (arr = text.match(/ашлось(?:<br\/>)?\s*(\d+)(?:&nbsp;)?\s*млн\.(?:&nbsp;)?\s*ответов/im)) {
                yaIndex = parseInt(arr[1].replace(/&nbsp;/igm, ""), 10)*1000000;
            }
            return yaIndex;
}

function checkYaIndex(domain, surl) {
    var url;
    if (surl) {
        url = "http://yandex.ru/yandsearch?rstr=&to_day=13&linkto=&zone=all&date=&spcctx=notfar&from_month=&numdoc=10&text=&Link=&lang=all&from_year=&within=0&site="+domain+"&wordforms=all&to_year=2007&from_day=&to_month=8&ds=&rd=0&mime=all&lr=225";
    } else {
        var rhost = getRHost(domain);
        url = "http://yandex.ru/yandsearch?text=rhost%3A"+rhost+"%20|%20rhost%3A"+rhost+".*&lr=225";
    }

    getHttpReq(domain, [inxYaIndex], surl, url, function(httpReq) {
            var yaIndex = getYaCount(httpReq.responseText);

            if (surl) base[domain].yaIndexsurl = yaIndex;
            else base[domain].yaIndex = yaIndex;
            showYaIndex(domain);
    });
    if (!surl) checkYaIndex(domain, true);
}

function checkYaLinks(domain) {
  getHttpReq(domain, [inxYaLinks], false, 'http://yandex.ru/yandsearch?text=%22*.' + domain + '%22&lr=225', function(httpReq) {
    var links = getYaCount(httpReq.responseText);
    setVal(domain, inxYaLinks, links);
    doAD(domain);
  });
}

function showYaIndex(domain) {
    if ("yaIndex" in base[domain] && "yaIndexsurl" in base[domain]) {
        if (base[domain].yaIndex < base[domain].yaIndexsurl) {
            base[domain].yaisurl = true;
            if (base[domain].tr)
                base[domain].tr.cells[inxYaIndex].innerHTML = getTDHTML(inxYaIndex, domain);
            setVal(domain, inxYaIndex, base[domain].yaIndexsurl);
        } else {
            setVal(domain, inxYaIndex, base[domain].yaIndex == 0 ? '<span style="color: red">0</span>' : base[domain].yaIndex);
        }
        delete base[domain].yaIndex;
        delete base[domain].yaIndexsurl;

        doAD(domain);
    }
}

/*function checkPR(domain) {
    var httpReq = getHttpReq(domain, [inxPR, inxwwwPR]);
    if (!httpReq)
        return;

    var url = "http://www.checkpagerank.net/index.php?name="+domain;
    try {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} catch(e) {}
    httpReq.open("GET", url, true);
    httpReq.onreadystatechange = function() {
        if (httpReq.readyState == 4) {
            totalCountChange(-1);
            var arr, pr, wwwPr;
            var reDomain = domain.replace(/\./gm, "\\.");

            if (arr = httpReq.responseText.match(new RegExp('<b>Google Pagerank for:&nbsp;<font color="#000099">'+reDomain+'</font>&nbsp;\\s+<font color="red">(\\d\\d?)/10</font></b>', "im")))
                pr = parseInt(arr[1], 10);

            if (arr = httpReq.responseText.match(new RegExp('<b>Google Pagerank for:&nbsp;<font color="#000099">www.'+reDomain+'</font>&nbsp;\\s+<font color="red">(\\d\\d?)/10</font></b>', "im")))
                wwwPr = parseInt(arr[1], 10);

            setVal(domain, inxPR, pr);
            setVal(domain, inxwwwPR, wwwPr);

            doAD(domain);
        }
    }
    httpReq.send(null);
}*/

function checkPR(domain) {
    var q = "info:"+domain;
    var url = "http://www.google.com/search?client=navclient-auto&ch=6" + GCH(q) + "&ie=UTF-8&oe=UTF-8&features=Rank&q="+q;
    getHttpReq(domain, [inxPR], false, url, function(httpReq) {
            var arr, pr;

            if (httpReq.responseText.length == 0 && !stopped && domain in base)
                pr = -1;
            else if (arr = httpReq.responseText.match(/Rank_(?:\d+):(?:\d+):(\d+)/im))
                pr = parseInt(arr[1], 10);

            base[domain].pr = pr;
            showPR(domain);
    });
    checkwwwPR(domain);
}

function checkwwwPR(domain) {
    var q = "info:www."+domain;
    var url = "http://www.google.com/search?client=navclient-auto&ch=6" + GCH(q) + "&ie=UTF-8&oe=UTF-8&features=Rank&q="+q;
    var httpReq = getHttpReq(domain, [inxPR], true, url, function(httpReq) {
            var arr, wwwPr;

            if (httpReq.responseText.length == 0 && !stopped && domain in base)
                wwwPr = -1;
            else if (arr = httpReq.responseText.match(/Rank_(?:\d+):(?:\d+):(\d+)/im))
                wwwPr = parseInt(arr[1], 10);

            base[domain].wwwPr = wwwPr;
            showPR(domain);
    });
}

function showPR(domain) {
    if ("pr" in base[domain] && "wwwPr" in base[domain]) {
        if (base[domain].pr < base[domain].wwwPr) {
//            base[domain].wwwgpr = true;
//            if (base[domain].tr)
//                base[domain].tr.cells[inxPR].innerHTML = getTDHTML(inxPR, domain);
            setVal(domain, inxPR, base[domain].wwwPr);
        } else {
            setVal(domain, inxPR, base[domain].pr);
        }
        delete base[domain].pr;
        delete base[domain].wwwPr;

        doAD(domain);
    }
}

/*function checkPRFraud(domain) {
    var httpReq = getHttpReq(domain, [inxPRfraud]);
    if (!httpReq)
        return;

    var url = "http://www.checkpagerank.net/cgi-bin/ccpr.pl?name="+domain+"&num=1";
    try {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} catch(e) {}
    httpReq.open("GET", url, true);
    httpReq.onreadystatechange = function() {
        if (httpReq.readyState == 4) {
            totalCountChange(-1);
            var prFraud;
            if (httpReq.responseText.indexOf("parent.showResult(1, true,") != -1)
                prFraud = '<font color="#009900">Valid</font>';
            if (httpReq.responseText.indexOf("parent.showResult(1, false,") != -1)
                prFraud = '<font color="#ff0000">Mirror</font>';
            if (httpReq.responseText.indexOf("parent.showResult(1, null,") != -1)
                prFraud = '';

            setVal(domain, inxPRfraud, prFraud);

            doAD(domain);
        }
    }
    httpReq.send(null);
}

function checkwwwPRFraud(domain) {
    var httpReq = getHttpReq(domain, [inxwwwPRfraud]);
    if (!httpReq)
        return;

    var url = "http://www.checkpagerank.net/cgi-bin/ccpr.pl?name=www."+domain+"&num=1";
    try {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");} catch(e) {}
    httpReq.open("GET", url, true);
    httpReq.onreadystatechange = function() {
        if (httpReq.readyState == 4) {
            totalCountChange(-1);
            var prFraud;
            if (httpReq.responseText.indexOf("parent.showResult(1, true,") != -1)
                prFraud = '<font color="#009900">Valid</font>';
            if (httpReq.responseText.indexOf("parent.showResult(1, false,") != -1)
                prFraud = '<font color="#ff0000">Mirror</font>';
            if (httpReq.responseText.indexOf("parent.showResult(1, null,") != -1)
                prFraud = '';

            setVal(domain, inxwwwPRfraud, prFraud);

            doAD(domain);
        }
    }
    httpReq.send(null);
}*/

function checkGlinks(domain) {
    getHttpReq(domain, [inxGLinks], false, "http://www.google.com/search?hl=en&filter=0&q=link%3A"+domain, function(httpReq) {
            var arr, gLinks;
            if (arr = httpReq.responseText.match(/of (?:about\s)?<b>((?:\d+,?)+)<\/b> linking to/im))
                gLinks = arr[1].replace(/,/igm, "");
            else if (httpReq.responseText.indexOf("did not match any documents") != -1)
                gLinks = 0;

            base[domain].gLinks = gLinks;
            showGlinks(domain);
    });
    checkwwwGlinks(domain);
}

function checkwwwGlinks(domain) {
    var httpReq = getHttpReq(domain, [inxGLinks], true, "http://www.google.com/search?hl=en&filter=0&q=link%3Awww."+domain, function(httpReq) {
            var arr, wwwGLinks;
            if (arr = httpReq.responseText.match(/of (?:about\s)?<b>((?:\d+,?)+)<\/b> linking to/im))
                wwwGLinks = arr[1].replace(/,/igm, "");
            else if (httpReq.responseText.indexOf("did not match any documents") != -1)
                wwwGLinks = 0;

            base[domain].wwwGLinks = wwwGLinks;
            showGlinks(domain);
    });
}

function showGlinks(domain) {
    if ("gLinks" in base[domain] && "wwwGLinks" in base[domain]) {
        if (base[domain].gLinks < base[domain].wwwGLinks) {
            base[domain].wwwgl = true;
            if (base[domain].tr)
                base[domain].tr.cells[inxGLinks].innerHTML = getTDHTML(inxGLinks, domain);

            setVal(domain, inxGLinks, base[domain].wwwGLinks);
        } else {
            setVal(domain, inxGLinks, base[domain].gLinks);
        }
        delete base[domain].gLinks;
        delete base[domain].wwwGLinks;

        doAD(domain);
    }
}

function checkGIndex(domain) {
    getHttpReq(domain, [inxGIndex], false, "http://www.google.com/search?hl=en&filter=0&q=site%3A"+domain, function(httpReq) {
            var arr, gIndex;
            if (arr = httpReq.responseText.match(/of (?:about\s)?<b>((?:\d+,?)+)<\/b> from/im))
                gIndex = parseInt(arr[1].replace(/,/igm, ""), 10);
            else if (httpReq.responseText.indexOf("did not match any documents") != -1)
                gIndex = 0;

            setVal(domain, inxGIndex, gIndex || '<span style="color: red;">0</span>');

            doAD(domain);
    });
}

function checkGInfo(domain) {
    getHttpReq(domain, [inxGInfo], false, "http://www.google.com/search?hl=en&filter=0&q=info%3A"+domain, function(httpReq) {
            var arr, res;
            var reDomain = domain.replace(/\./gm, "\\.");
            if (httpReq.responseText.search(new RegExp("<cite>(www\\.)?"+reDomain+"/.*?</cite>", "im")) != -1
                || httpReq.responseText.search(new RegExp('<a href="http://(www\\.)?'+reDomain+'/.*?" class=l( onmousedown=".*?")?>.*?</a>', 'im')) != -1)
                res = '<font color="#009900">OK</font>';
            else if ((arr = httpReq.responseText.match(/<span class=a>(.*?)<\/span>/im))
                || (arr = httpReq.responseText.match(/<a href="http:\/\/(.*?)" class=l>\1<\/a>/im)))
                res = '<font color="#ff0000">'+arr[1]+'</font>';
            else if (httpReq.responseText.indexOf("Sorry, no information is available for the URL") != -1) {
                base[domain].wwwgi = true;
                if (base[domain].tr)
                    base[domain].tr.cells[inxGInfo].innerHTML = getTDHTML(inxGInfo, domain);

                base[domain][inxGInfo] = undefined;
                setTimeout("checkwwwGInfo('"+domain+"')", 10);
                return;
            }

            setVal(domain, inxGInfo, res);

            doAD(domain);
    });
}

function checkwwwGInfo(domain) {
    getHttpReq(domain, [inxGInfo], false, "http://www.google.com/search?hl=en&filter=0&q=info%3Awww."+domain, function(httpReq) {
            var arr, res;
            var reDomain = domain.replace(/\./gm, "\\.");
            if (httpReq.responseText.search(new RegExp("<span class=a>(www.)?"+reDomain+"/.*?</span>", "im")) != -1
                || httpReq.responseText.search(new RegExp('<a href="http://(www.)?'+reDomain+'/.*?" class=l>(www.)?'+reDomain+'/.*?</a>', 'im')) != -1)
                res = '<font color="#009900">OK</font>';
            else if (arr = httpReq.responseText.match(/<span class=a>(.*?)<\/span>/im))
                res = '<font color="#ff0000">'+arr[1]+'</font>';
            else if (httpReq.responseText.indexOf("Sorry, no information is available for the URL") != -1)
                res = 'No info';

            setVal(domain, inxGInfo, res);

            doAD(domain);
    });
}

function checkYahooLinks(domain) {
    getHttpReq(domain, [inxYahooLinks], false, "http://siteexplorer.search.yahoo.com/search?ei=UTF-8&p=http%3A%2F%2F"+domain+"&bwm=i&bwmf=s&bwmo=d", function(httpReq) {
            var arr, yahooLinks;
            if (arr = httpReq.responseText.match(/<strong>Inlinks \(<span style="white-space: nowrap">((?:\d+,?)+)<\/span>\)<\/strong>/im))
                yahooLinks = parseInt(arr[1].replace(/,/igm, ""), 10);
            else if (httpReq.responseText.indexOf("We were unable to find any results for the given URL in our index") != -1)
                yahooLinks = 0;
            else if (httpReq.responseText.indexOf("No Inlinks") != -1)
                yahooLinks = 0;
            else if (httpReq.responseText.indexOf(">Inlinks</a>") != -1)
                yahooLinks = 0;

            setVal(domain, inxYahooLinks, yahooLinks);

            doAD(domain);
    });
}

function checkWebArch(domain) {
    getHttpReq(domain, [inxWebArch], false, "http://web.archive.org/web/*/"+domain, function(httpReq) {
            var arr, res;
            if (arr = httpReq.responseText.match(/<p align="right"><b>(\d+)<\/b> Results<\/p>/im))
                res = parseInt(arr[1], 10);
            else if (httpReq.responseText.indexOf("<b>0 pages found for</b>") != -1)
                res = 0;

            setVal(domain, inxWebArch, res);

            doAD(domain);
    });
}

function checkDmoz(domain) {
  getHttpReq(domain, [inxDmoz], false, 'http://search.dmoz.org/cgi-bin/search?search=u:' + domain, function(httpReq) {
	     if (httpReq.responseText.length == 0 && !stopped && domain in base) {
            base[domain][inxDmoz] = undefined;
            setTimeout("checkDmoz('"+domain+"')", 10);
            return;
        }
            var arr, res = '';
            if (httpReq.responseText.indexOf('No <b><a href="http://dmoz.org/">Open Directory Project</a></b> results found') == -1)
                res = '<span style="color: green;">DMOZ</span>';

            setVal(domain, inxDmoz, res);

            doAD(domain);
    });
}

function checkRIndex(domain) {
  getHttpReq(domain, [inxRIndex], false, 'http://search.rambler.ru/srch?sort=0&oe=1251&limit=50&filter=' + domain, function(httpReq) {
    var arr, index = 0;
    if (arr = httpReq.responseText.match(/class="find">.*?<b>(\d+)<\/b>/))
      index = arr[1];
    setVal(domain, inxRIndex, index);
    doAD(domain);
  })
}

function checkAlexa(domain, callback) {
  if (callback) {
    var domainParts = domain.split('.');
    domain = domainParts.slice(domainParts.length - 2).join('.');
  }
  getHttpReq(domain, [inxAlexa], arguments[2], 'http://www.alexa.com/data/details/traffic_details/' + domain, function(httpReq) {
            var arr, res;
            if (arr = httpReq.responseText.match(/the Alexa Web Information Service\.-->(.*?)<!-- google_ad_section/)) {
                var hideClasses = {c11e:1,c125:1,c12d:1,c130:1,c145:1,c14d:1,c15f:1,c163:1,c169:1,c17f:1,c182:1,c187:1,c197:1,c1a5:1,c1ae:1,c1b0:1,c1c0:1,c1cc:1,c1e1:1,c20c:1,c227:1,c232:1,c235:1,c25a:1,c261:1,c290:1,c293:1,c29d:1,c2be:1,c2ec:1,c306:1,c311:1,c34f:1,c350:1,c386:1,c39e:1,c3a0:1,c3a7:1,c3b2:1,c3e0:1,c3ec:1,c400:1,c401:1,c405:1,c44e:1,c477:1,c4ba:1,c4bb:1,c4d4:1,c4d6:1,c4e0:1,c4e5:1,c4ef:1,c4f6:1,c4f8:1,c4fb:1,c501:1,c510:1,c514:1,c515:1,c52a:1,c52c:1,c533:1,c53b:1,c54a:1,c55a:1,c560:1,c584:1,c5a7:1,c5bc:1,c5be:1,c5de:1,c60c:1,c629:1,c64f:1,c656:1,c678:1,c695:1,c69a:1,c6bf:1,c6c9:1,c6da:1,c6e4:1,c6ee:1,c6ef:1,c6fd:1,c712:1,c744:1,c745:1,c747:1,c7ad:1,c7b6:1,c7b8:1,c7dc:1,c80f:1,c820:1,c84e:1,c85d:1,c862:1,c88e:1,c8a7:1,c8ad:1,c8e3:1,c8e9:1,c8f3:1,c8f6:1,c8ff:1,c92f:1,c932:1,c946:1,c94e:1,c95f:1,c963:1,c994:1,c9b3:1,c9b5:1,c9c7:1,c9d0:1,c9eb:1,ca07:1,ca0b:1,ca15:1,ca17:1,ca33:1,ca53:1,ca57:1,ca58:1,cabd:1,cae7:1,cb09:1,cb10:1,cb59:1,cb74:1,cb79:1,cb82:1,cb91:1,cb9b:1,cbae:1,cbb6:1,cbbb:1,cbc6:1,cbc8:1,cbcd:1,cbea:1,cbed:1,cbf1:1,cbf8:1,cc04:1,cc0b:1,cc75:1,cc77:1,cc9c:1,cca6:1,ccb3:1,ccc5:1,ccee:1,cd33:1,cda3:1,cdcf:1,cdd1:1,cde4:1,cde5:1,cded:1,ce12:1,ce1b:1,ce1e:1,ce32:1,ce3c:1,ce45:1,ce52:1,ce55:1,ce78:1,ce82:1,ce83:1,ce87:1,ce9b:1,ceba:1,cec3:1,ced0:1,cf15:1,cf6b:1,cf9d:1,cfa2:1,cfa8:1,cfb5:1,cfbe:1,cfc1:1,cfdb:1,cfe9:1};
                res = arr[1].replace(/<span class="(....)">.*?<\/span>/g, function(tag, className) {
                  return hideClasses[className] ? '' : tag;
                }).replace(/(<.*?>|,)/g, '');
            } else
                res = '<span style="color: blue;">No Data</span>';

            if (callback) {
              callback(res);
              return;
            }

            var domainLevel = domain.split('.').length;
            if (domainLevel >= 3) {
              checkAlexa(domain, function(subRes) {
                if (res == subRes)
                  res = '<span style="color: blue;">No Data</span>';
                else
                  res = subRes;
                setVal(domain, inxAlexa, res);
              }, true);
            } else
			  setVal(domain, inxAlexa, res);

			doAD(domain);
	});
}


function checkMSNIndex(domain) {
	getHttpReq(domain, [inxMSNIndex], false, "http://search.msn.com/results.aspx?q=site%3A"+domain, function(httpReq) {
			var arr, MSNIndex = 0;
			if (arr = httpReq.responseText.match(/id="count">.*?из ([^<]+)/i)) {
				MSNIndex = parseInt(arr[1].replace(/[^\d]/g, ''));
	        }
			setVal(domain, inxMSNIndex, MSNIndex);
			doAD(domain);
	});
}


