function HandleCheckTIC()
{
    header("Content-type: text/html; charset=windows-1251");
    require_once "YandexTICGrabber.php";
    $json = new Services_JSON();
    $result = array("rowNum" => (int) $_REQUEST["rowNum"], "url" => $_REQUEST["url"]);
    $proxyService = new ProxiesService("yandex", SERVER_IP);
    $res = $proxyService->getProxyData();
    if (PEAR::isError($res)) {
        $result["error"] = $res->getMessage();
        print $json->encode($result);
        exit;
    }
    if (isset($_REQUEST["delay"]) && $_REQUEST["delay"] == "true") {
        if (isset($_REQUEST["delayValue"])) {
            sleep((int) $_REQUEST["delayValue"]);
        } else {
            sleep(DELAY_BEFORE_REQUEST);
        }
    }
    $_REQUEST["url"] = trim($_REQUEST["url"]);
    $parser =& new YandexTICGrabber();
    $parser->showInfo = false;
    $cy = $parser->parseForDomen(removeWWW($_REQUEST["url"]));
    $proxyService->increase();
    $cyNoWww = $parser->parseForDomen("www." . removeWWW($_REQUEST["url"]));
    $proxyService->increase();
    $cy = max($cy["num"], $cyNoWWW["num"]);
    if ($cy < 0) {
        $result["error"] = "Wrong CY";
        print $json->encode($result);
        exit;
    }
    $result["num"] = $cy;
    print $json->encode($result);
}
function HandleCheckPriceLink()
{
    header("Content-type: text/html; charset=windows-1251");
    require_once "YandexTICGrabber.php";
    require_once "CheckPageRankGrabber.php";
    $json = new Services_JSON();
    $result = array("url" => $_REQUEST["url"], "rowNum" => (int) $_REQUEST["rowNum"]);
    $proxyService = new ProxiesService("yandex", SERVER_IP);
    $res = $proxyService->getProxyData();
    if (PEAR::isError($res)) {
        $result["error"] = $res->getMessage();
        print $json->encode($result);
        exit;
    }
    if (isset($_REQUEST["delay"]) && $_REQUEST["delay"] == "true") {
        if (isset($_REQUEST["delayValue"])) {
            sleep((int) $_REQUEST["delayValue"]);
        } else {
            sleep(DELAY_BEFORE_REQUEST);
        }
    }
    $_REQUEST["url"] = trim($_REQUEST["url"]);
    $parserTic =& new YandexTICGrabber();
    $parserTic->showInfo = false;
    $resultTic = $parserTic->parseForDomen(removeWWW($_REQUEST["url"]));
    $proxyService->increase();
    $resultTicNoWww = $parserTic->parseForDomen("www." . removeWWW($_REQUEST["url"]));
    $resultTic = max($resultTic["num"], $resultTicNoWww["num"]);
    if ($resultTic < 0) {
        $result["error"] = "Wrong CY";
        print $json->encode($result);
        exit;
    }
    $proxyService->increase();
    $parserRank =& new CheckPageRankGrabber();
    $parserRank->showInfo = false;
    $resultRank = $parserRank->parseForDomen($_REQUEST["url"]);
    $pageRank = max($resultRank["www"], $resultRank["nowww"]);
    if ($pageRank < 0) {
        $result["error"] = "Wrong Page Rank";
        print $json->encode($result);
        exit;
    }
    if (strpos($_REQUEST["url"], "http://") === false || strpos($_REQUEST["url"], "http://") > 0) {
        $_REQUEST["url"] = "http://" . $_REQUEST["url"];
    }
    $res = getLinksForUrlDOM($_REQUEST["url"]);
    if (PEAR::isError($res)) {
        $result["error"] = $res->getMessage();
        print $json->encode($result);
        exit;
    }
    list($linksCount, $linksCountNoIndex, $linksCountIn, $linksCountOut, $linkCountOur) = $res;
    $lCount = $linksCountOut + $linkCountOur;
    switch ((int) $_REQUEST["linktype"]) {
        case 1:
            $result["num1"] = get_face_value($pageRank, $resultTic, -1);
            $result["num"] = get_face_value($pageRank, $resultTic, $linksCountOut + $linkCountOur);
            break;
        case 2:
            $result["num1"] = get_inner_value($pageRank, $resultTic, -1);
            $result["num"] = get_inner_value($pageRank, $resultTic, $linksCountOut + $linkCountOur);
            break;
    }
    $result["linksCountOut"] = $lCount;
    $result["pr"] = $pageRank;
    $result["cy"] = $resultTic;
    print $json->encode($result);
}
function HandleGetSearchResults()
{
    set_time_limit(0);
    header("Content-type: text/html; charset=windows-1251");
    // NOTE Без этого почемуто оне выводит нифига
    print " ";
    require_once "YandexResultsGrabber.php";
    require_once "YandexResultsAddGrabber.php";
    $json = new Services_JSON();
    $result = array("rowNum" => (int) $_REQUEST["rowNum"], "linkType" => (int) $_REQUEST["linkType"]);
    $parser =& new YandexResultsGrabber();
    $parser->showInfo = false;
    $parserAdd =& new YandexResultsAddGrabber();
    $parserAdd->showInfo = false;
    if (isset($_REQUEST["withoutOur"]) && $_REQUEST["withoutOur"] == "true") {
        $parserAdd->withoutOur = true;
    } else {
        $parserAdd->withoutOur = false;
    }
    if (isset($_REQUEST["delay"]) && $_REQUEST["delay"] == "true") {
        $parser->waitBeforRequest = isset($_REQUEST["delayValue"]) ? (int) $_REQUEST["delayValue"] : DELAY_BEFORE_REQUEST;
        $parserAdd->waitBeforRequest = isset($_REQUEST["delayValue"]) ? (int) $_REQUEST["delayValue"] : DELAY_BEFORE_REQUEST;
    }
    // указываем имя сервиса и ip-сервера откуда скрипт запускается
    $proxyService = new ProxiesService("yandex", SERVER_IP);
    $res = $proxyService->getProxyData();
    if (PEAR::isError($res)) {
        $result["error"] = $res->getMessage();
        print $json->encode($result);
        exit;
    }
    $parser->setProxyData($res);
    $parserAdd->proxyService = $proxyService;
    $parserAdd->setProxyData($res);
    $_REQUEST["url"] = trim($_REQUEST["url"]);
    switch ((int) $_REQUEST["linkType"]) {
        // Все
        case 0:
            $res1 = $parser->parseForDomen($_REQUEST["url"]);
            $proxyService->increase();
            $res2 = $parser->parseForDomen("www." . $_REQUEST["url"]);
            $proxyService->increase();
            $result["res1"] = $res1;
            $result["res2"] = $res2;
            if (isset($_REQUEST["mainAndRest"]) && $_REQUEST["mainAndRest"] == "true" || isset($_REQUEST["withoutOur"]) && $_REQUEST["withoutOur"] == "true") {
                $resAdd1 = $parserAdd->parseForDomen($_REQUEST["url"]);
                $resAdd2 = $parserAdd->parseForDomen("www." . $_REQUEST["url"]);
                if (PEAR::isError($resAdd1) && PEAR::isError($resAdd2)) {
                    $result["error"] = $resAdd1->getMessage();
                    print $json->encode($result);
                    exit;
                }
                $result["resAdd1"] = $resAdd1;
                $result["resAdd2"] = $resAdd2;
            }
            break;
            // С www
        // С www
        case 1:
            $res = $parser->parseForDomen("www." . $_REQUEST["url"]);
            $proxyService->increase();
            $result["res"] = $res;
            if (isset($_REQUEST["mainAndRest"]) && $_REQUEST["mainAndRest"] == "true" || isset($_REQUEST["withoutOur"]) && $_REQUEST["withoutOur"] == "true") {
                $resAdd = $parserAdd->parseForDomen("www." . $_REQUEST["url"]);
                if (PEAR::isError($resAdd)) {
                    $result["error"] = $resAdd->getMessage();
                    print $json->encode($result);
                    exit;
                }
                $result["resAdd"] = $resAdd;
            }
            break;
            // Без www
        // Без www
        case 2:
            $res = $parser->parseForDomen($_REQUEST["url"]);
            $proxyService->increase();
            $result["res"] = $res;
            if (isset($_REQUEST["mainAndRest"]) && $_REQUEST["mainAndRest"] == "true" || isset($_REQUEST["withoutOur"]) && $_REQUEST["withoutOur"] == "true") {
                $resAdd = $parserAdd->parseForDomen($_REQUEST["url"]);
                if (PEAR::isError($resAdd)) {
                    $result["error"] = $resAdd->getMessage();
                    print $json->encode($result);
                    exit;
                }
                $result["resAdd"] = $resAdd;
            }
            break;
    }
    print $json->encode($result);
}