﻿// JScript File


    // --- Begin Sort Functions --- //
    var sortorder = [];
            sortorder[0] = true;
            sortorder[1] = true;
            sortorder[2] = true;
            sortorder[3] = true;
            sortorder[4] = true;
            sortorder[5] = true;
    var currentsorttype = 0;
    
    function loadData2(sorttype,zip) {
    flipArrow(sorttype);
    if (sorttype) {}
        else {
        sorttype = 0;
        }
    var sortby = 0;
        if (sorttype == 0) {sortby = 0};
        if (sorttype == 1) {sortby = 1};
        if (sorttype == 2) {sortby = 3};
        if (sorttype == 3) {sortby = 4};
        if (sorttype == 4) {sortby = 5};
        if (sorttype == 5) {sortby = 8};
        
      if (sortorder[sortby]) {
      sortorder[sortby] = false;
      }
      else {
      sortorder[sortby] = true;
      } 
    currentsorttype = sortby;
    Inventory.sort(sorting);
    loadSimilarList(zip);
    }
    
    function sorting(a, b) {
    if (currentsorttype != 1 && currentsorttype != 3) {
        var x = a[currentsorttype];
        var y = b[currentsorttype];
    if (sortorder[currentsorttype]) {
        return y - x;
        }
    else {
        return x - y;
        }
    }
    else {
    var x = a[currentsorttype].toLowerCase();
    var y = b[currentsorttype].toLowerCase();
    if (sortorder[currentsorttype]) {
        return ((x < y) ? 1 : ((x > y) ? -1 : 0));
        }
    else {
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
            }
        }
    }
    // --- End Sort Functions --- //


// --- Begin Load Similar Cars --- //

    function loadSimilarList(zip) {
        myCompareList = new Array();
        var list = '';
        list += '<div id="SimilarCars" style="width: 523px; margin:auto; height: 200px; overflow: auto; padding:0px;">';
        list += '<table width="502" border="0" align="center" cellpadding="2" cellspacing="3" class="pretty-table">';
        for(var i = 0; i <= Inventory.length - 1; i++) {
            //-- Class Name Calculation -- //
            var clsName;
            if( i % 2 ) { clsName = 'tblRow1'; } else { clsName = 'tblRow2'; }
            list += '<tr onclick=\'window.location = "/certified-used/inventory-vehicle-details.aspx?zip=' + zip + '&vin=' + Inventory[i][7] + '";\' class="' + clsName + '">'
            list += '<td width="35">' + Inventory[i][0] + '</td>';
            list += '<td width="163"><b>' + Inventory[i][1] + '</b><br /><span style="font-size:10px;">' + Inventory[i][2] + ' -</span>' + "<a href='/certified-used/inventory-vehicle-details.aspx?Zip="+ zip + '&VIN=' + Inventory[i][7] + "'>View Details</a>" + '</td>';
            list += '<td width="46">' + Inventory[i][3] + '</td>';
            list += '<td width="54">' + Inventory[i][4] + '</td>';
            list += '<td width="56">' + Inventory[i][5] + '</td>';
            list += '<td width="54">' + Inventory[i][8] + ' miles</td>';
            list += '</tr>';
        }
        list += '</table></div>'
        document.getElementById('simCarsListContainer').innerHTML = list;
    }
    
    function flipArrow(id) {
        
        var flip1 = '/images/certified-used/inventory-search/uparrow.jpg';
        var flip2 = '/images/certified-used/inventory-search/downarrow.jpg';
        var imgHeight = document.getElementById("simImgArrow" + id).height;
        
        for(var i= 0; i<=5;i++) {
            document.getElementById("simImgArrow" + i).src = flip1; 
            document.getElementById("simImgArrow" + i).height = '4';
        }
        if (imgHeight == '4') { 
            document.getElementById("simImgArrow" + id).src = flip2; 
            document.getElementById("simImgArrow" + id).height = '5';
        }
        else {
            document.getElementById("simImgArrow" + id).src = flip1; 
            document.getElementById("simImgArrow" + id).height = '4';
        }
    }

// --- end Similar Cars --- //

