﻿function spm() {
    var o = $i("spm");

    if (o == null) return;
    o.innerHTML = g_spm;
}
var g_firstClick = true;
function searchClick(el) {
    if (g_firstClick) {
        el.style.color = 'black';
        el.value = '';
        g_firstClick = false;
    }
}
function setRateStats(obj) {
    $('divRateStats').style.display = 'block';
    obj.style.display = 'none';
}
function setRecommend(isRecommend) {
    var _isRec = (isRecommend) ? 1 : 0;
    new Ajax.Request(_recommendUrl, { method: 'post', postBody: 'hdnRecommend=' + _isRec + '&prdid=' + _prdid + '&usrid=' + _usrid, onSuccess: onRecommend });
}
function setRate(relVal, easVal, valVal) {
    var _delegate = onRate;
    if (arguments.length > 3)
        _delegate = arguments[3];
    new Ajax.Request(_rateUrl, { method: 'post', postBody: '&prdid=' + _prdid + '&usrid=' + _usrid + '&er=' + easVal + '&rr=' + relVal + '&vr=' + valVal, onSuccess: _delegate });
}
function onRecommend() {
    $('divRecommend').style.display = 'none';
    if ($('divRateStats') !== null)
        $('divRateStats').style.display = 'none';
    $('divRater').style.display = 'block';
    if ($('hProductTitle') === null) return;
    //$('hProductTitle').style.width = '450px';
}
function onRate(retValue) {
    eval('var returnedObj =' + retValue.responseText);
    if (returnedObj === null) return;
    $('divRater').style.display = 'none';
    $('divRateStats').style.display = 'block';
    $('divImgPie').innerHTML = returnedObj.img;
    $('spnYes').innerHTML = 'Yes: ' + returnedObj.yesRate + '%';
    $('spnNo').innerHTML = 'No: ' + returnedObj.noRate + '%';
    $('spnTotalVotes').innerHTML = returnedObj.totalVotes + ' votes';
    var mainArr = $$('div[class="right"] div[class="img"] div');
    for (var i = 0; i < 5; i++) {
        mainArr[i].className = returnedObj.relRateArr[i]
    }
    for (var i = 5; i < 10; i++) {
        mainArr[i].className = returnedObj.easeRateArr[i - 5];
    }
    for (var i = 10; i < 15; i++) {
        mainArr[i].className = returnedObj.valRateArr[i - 10];
    }
    $('divStatsTitleTx').style.display = 'block';
    if ($('hProductTitle') === null) return;
}
function initRaterBoxes() {
    if (_rtStat == 0) {
        setUnvisible($('divRateStats'));
        setUnvisible($('divRater'));
    }
    if (_rtStat == 1 || _rtStat == 2)
        setUnvisible($('divRateStats'));
}
function setUnvisible(obj, isShow) {
    if (obj !== null) obj.style.display = (isShow) ? 'block' : 'none';
}

function manSubmit() {
    var selectedValue = $F('txtSearchManual');
    if (selectedValue == null)
        return false;
    if (selectedValue.length < 2) {
        $('txtSearchManual').value = '';
        return false;
    }

    $('hdnManualssearch').value = selectedValue;
    if (selectedValue.indexOf('manual') == -1) {
        $('hdnManualssearch').value += ' manuals';
    }

    return true;
}

function findWarranty() {
    var url = $F("p_findWarranty_ctg");
    if (url != '') {
        if (url == 231) {
            if (pageCtgId != 231) {
                logEvent(5966);
                window.open(carChex_link, "_blank");
            }
        }
        else {
            //window.location.href = url;
            new Ajax.Request('/httphandlers/warranty/GetWarrantyCtrl.ashx?ctgid=' + url, { method: 'get', onSuccess: onWarrantySuccess });
        }
    }
}
function onWarrantySuccess(res) {
    if ($('divWarranty') == null)
        return;
    $('divWarranty').innerHTML = res.responseText;
}