﻿
function inspectionPendingClick() {
    __doPostBack('inspectionPendingTrigger', '');
}
function pepClick() {
    __doPostBack('pepInspectionTrigger', '');
}
function carFaxClick() {
    __doPostBack('carFaxTrigger', '');
}
function condQaClick() {
    __doPostBack('conditionQaTrigger', '');
}
function mechQaClick() {
    __doPostBack('mechanicalQaTrigger', '');
}
function maintainQaClick() {
    __doPostBack('maintainQaTrigger', '');
}
function noCarFactsClick() {
    __doPostBack('carFactsTrigger', '');
}
function requestVinClick() {
    __doPostBack('vinRequestTrigger', '');
}




function switchImage(thumbImage, mainImage) {
    document.getElementById(mainImage).src = document.getElementById(thumbImage).src;
}


function autoTab(input, len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0, 8, 9] : [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 46];
    if (input.value.length >= len && !containsElement(filter, keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input) + 1) % input.form.length].focus();
    }

    function containsElement(arr, ele) {
        var found = false, index = 0;
        while (!found && index < arr.length)
            if (arr[index] == ele)
            found = true;
        else
            index++;
        return found;
    }

    function getIndex(input) {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
            if (input.form[i] == input) index = i;
        else i++;
        return index;
    }
    return true;
}
function showToolTip() {
    document.getElementById('contactTooltip').style.display = "block";
}
function hideToolTip() {
    document.getElementById('contactTooltip').style.display = 'none';
}
function kbbTooltip() {
    $(this).find("em").animate({ opacity: "show" }, "fast");
}
function myFunc() {
    $('#test-button').click();
}
function hideModal() {
    $find("MPE").hide();
}
function csClick() {
    //          window.location.hash = "TOP";
    __doPostBack('ContactSellerTrigger', '');
}

function myFunc() {
    alert(document.getElementById('BuyerOfferTextBox').value);
}

$(document).ready(function() {


    var urlIdShowInspection = $.url.param('showinspection');

    $("#divLoadingListing").animate({ opacity: 'hide' }, 'slow');
    $('#vehicle-details').tabs();
    $('#features-options').tabs();
    $('.tabs-nav').tabs();

    if (urlIdShowInspection == 1) {
        $('#listingContentDiv.tabs-nav').tabs('select', 1);
    }

    $('#car-facts').removeClass('hide');

    $('#makeOfferButton').click(function() {
        var val = $('#tbYourOffer').val();
        document.cookie = "csMakeAnOfferAmount =" + val;
    });

    $('.inspection-nav a').click(function() {
        var linkClicked = $(this).attr('id');
        var targetPanel = $(this).attr('href');
        var currentUrl = $('.inspection-nav a[href$=' + 'javascript:void(0);' + ']');
        var linkId = $(currentUrl).attr('id');
        var replaceUrl = '#' + linkId + 'Panel';

        $(currentUrl).attr('href', replaceUrl);
        $('div.inspection-panel').addClass('hide');
        $(targetPanel).removeClass('hide');
        $(this).attr('href', 'javascript:void(0);');
    });



    $('#inspectionTabs a').click(function() {
        var linkClicked = $(this).attr('id');
        var targetPanel = $(this).attr('href');
        $(this).attr('href', 'javascript:void(0);')
        $('#inspectionTabs').addClass('hide');
        $('#hasInspectionBanner2Div.hasInspectionBanner').addClass('hide');
        $('#viewPbInspectionLink').addClass('hide');
        $('div.inspection-panel').addClass('hide');
        $(targetPanel).removeClass('hide');
    });

    $('a.close-link').click(function() {
        $('div.inspection-panel').addClass('hide');
        $('#hasInspectionBanner2Div.hasInspectionBanner').removeClass('hide');
        $('#viewPbInspectionLink').removeClass('hide');

        $('#inspectionTabs').removeClass('hide');
        var currentUrl = $('#inspectionTabs a[href$=' + 'javascript:void(0);' + ']');
        var linkId = $(currentUrl).attr('id');
        var replaceUrl = '#' + linkId + 'Panel';
        $(currentUrl).attr('href', replaceUrl);
    });

    $('#ValetInspectionLink').click(function(e) {
        if ($("#HasInspectionDfs").length) {
            $('#listingContentDiv.tabs-nav').tabs('select', 1);
            $("#HasInspectionDfs").attr("src", insSrc); //reload iframe on click event
            e.preventDefault();
        }
    });

    $("#VehicleReportLink a.close-link").click(function(e) {
        if ($("#HasInspectionDfs").length) {
            $("#HasInspectionDfs").attr("src", insSrc); //reload iframe on click event
            e.preventDefault();
        }
    });

    $('#inspectionTabs a').hover(function() {
        $(this).find('img').addClass('hover-filter');
    }, function() {
        $(this).find('img').removeClass('hover-filter');
    });
    $('.inspection-panel .right-column td:nth-child(2)').addClass('inspectionResultsText');

    $('.inspection-panel tr').each(function() {
        var rowName = $(this).attr('id');
        var inspectionResult = '#' + rowName + 'ResultLabel';
        var inspectionResultDiv = '#' + rowName + 'ResultDiv';
        var commentsAvailable = '#' + rowName + 'SeeMoreLabel';
        var commentsDiv = '#' + rowName + 'CommentsDiv';
        if ($(commentsAvailable).length > 0) {
            $(commentsAvailable).addClass('hide');
            $(commentsDiv).removeClass('hide');
        }
    });
    $('#hasInspectionBannerDiv').click(function() {
        $('#listingContentDiv.tabs-nav').tabs('select', 1);
    });
    $('.inspection-panel tr:contains(REPAIR)').each(function() {
        //here now
        $(this).addClass('fail');
        var rowName = $(this).attr('id');
        var commentsAvailable = '#' + rowName + 'SeeMoreLabel';
        var summaryLineItem = '#' + rowName;
        var item = $(summaryLineItem).clone();
        $('#repairsSummaryTable').append(item);
        $('#repairsSummaryTable span:contains(*)').each(function() {
            $(this).addClass('hide');
        });
    });

    $('.inspection-panel tr:contains(FAIL)').each(function() {
        $(this).addClass('fail');
    });

    $('.inspection-panel tr span:contains(PASS)').each(function() {
        $(this).addClass('pass');
    });
    $('.inspection-panel tr span:contains(N/A)').each(function() {
        $(this).addClass('pass');
    });

    $('#carPhotostrip.scrollable').scrollable({
        size: 4
    });
    $('#SimilarListingsPhotoStrip.scrollable').scrollable({
        size: 5,
        clickable: false
    });

    $('#vehicle-specs tr:even').addClass('table-stripes');

    $('#car-facts div:odd').addClass('alt-color');
    $('#car-facts a').tooltip();
    $('h15').append('<em></em>');
    $('#LongDesc').click(function(e) {
        $('#SmallDescriptionLabel').addClass('hide');
        $('#LongDesc').addClass('hide');
        $('#ThirdPartyDescPanel').removeClass('hide');
    });

    $('#InspectionAvailableBannerDiv a').click(function(e) {
        e.preventDefault();
        $('#InspectionAvailableBannerDiv').animate({ opacity: 'hide' }, 'fast');
    });
    $('#kbbClose').click(function() {
        $('#kbbToolTip, #kbbClose, #kbbMoreLink, #kbbLessLink').addClass('hide');
        $('#kbbMore').removeClass('hide');
        $('.tp-kbb a').hover(function() {
            $('#kbbToolTip').animate({ opacity: 'show' }, 'fast');
        }, function() {
            $('#kbbToolTip').animate({ opacity: 'hide' }, 'fast');
        });
    });
    $('#kbbMoreLink').click(function() {
        $('#kbbMoreLink').addClass('hide');
        $('#kbbLessLink').removeClass('hide');
        $('#kbbMore').removeClass('hide');
    });
    $('#kbbLessLink').click(function() {
        $('#kbbMoreLink').removeClass('hide');
        $('#kbbLessLink').addClass('hide');
        $('#kbbMore').addClass('hide');
    });

    $("#fraudModTrigger").click(function(e) {
        e.preventDefault();
        if (!$(this).hasClass("disabled")) {
            $("#reportFraudModal").modal({
                minHeight: 135
            });
        }
    });



    $("#ListingContentContainer").animate({ opacity: 'show' }, 'slow');
    $('#Panel1').removeClass('hide');
    $('#SendEmail').removeClass('hide');

    setTimeout(sellQuestionsLoadEffect, 2000);
    if ($("#HasInspectionDfs").length) {
        $("#HasInspectionDfs").attr("src", insSrc); //load inspection report last (reloads on every click event too.)
    }
});


function sellQuestionsLoadEffect() {
    $("#loadingEffect").hide();
    $("#sellQuestionsWrapper").fadeIn("slow");
    
}

//Facebook connect
function facebook_onlogin() {
    window.location.reload();
}

//Google Analytics

//var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
//document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

//try {
//    var pageTracker = _gat._getTracker("UA-5897660-1");
//    pageTracker._trackPageview();
//} catch (err) { }