﻿YAHOO.namespace("CSSearch");
YAHOO.CSSearch.AdvSearch = function () {
    /*********************** Private Properties ***********************/
    var m_oUtils = YAHOO.CSUtils.Utils,
        m_oYEVNT = YAHOO.util.Event,
        m_oYDOM = YAHOO.util.Dom,
        g_oRespSchema = { resultsList: "d.Results" },
        g_HaveCarList = false,              //True indicates the carlist is available       
        g_IsInitiatedByPaginator = false,   //True=> Webservice hit is initialized by paginator buttons, avoids recreating the paginator
        g_BlockPaginationHndlr = false,     //True=>The pagination buttons are changed by clicking back or forward buttons, avoids the execution of hndlrHandlePagination
        g_IsSliderInitialized = false,      //True=>Slider is initialized for the first time and avoids rebinding the datatable
        g_IsQuickSearch = false,            //Avoids executing the code related to datatable
        g_AvoidBackPreviousHndlr = false,   //True =>One of the search buttons are clicked, avoids the execution of BackPreviousPage function
        g_SliderBtnsCreated = false,        //True indicates that the slider buttons are created
        g_SliderValuesSet = false,          //True indicates that the sliders max and min values are set
        g_IsTableFilteredBySlider = false,
        g_SetLabels4Btns = false,
        g_oDataTable = null,
        g_sCarListQryParamFromQryStr = null,
        g_oCarList = null,
        g_iTotalCount = null,
        g_oPaginator = null,
        g_iPageNum = null,
        g_oCarListDSCallback = null,
        g_onButtonsAvailable = null,
        g_iStockType = null,
        g_IsStockTypeRestricted = false,     //Avoids creating radio buttons in quick search
        g_sBookmarkedSection = null,
        g_sSortItem = null,
        g_sSortType = null,
        g_sUsedText = null,
        g_onDataTblCreated = null,
        g_onDataTblFiltered = null,
        g_IsLt = false,
        g_IgnoreQS = false,
        D_MAXLIST = 250000,  //Matches LLU.Constants.D_MAXLIST
        ROWS_PER_PG = 30,
        SLDR_RANGE = 150;

    var g_oColumnDefs = [],
        g_SortFlags = [{ key: "Year", value: false },
        { key: "Make", value: false },
        { key: "Model", value: false },
        { key: "SubModel", value: false },
        { key: "DFList", value: false}];

    var g_oSiteSearchCols = [
        { key: "DeptTypeID" },
        { key: "HeaderText" },
        { key: "Fields" },
        { key: "FormatString" }
    ];

    var g_sCarListDataSource = "/Services/Inventory.asmx/SearchCars",
        g_sSiteSearchColsDataSource = "/Services/Inventory.asmx/GetSiteSearchCols";

    var g_oCarListResponseSchema = {
        resultsList: "d.Results",
        fields: [
            { key: "CarID" }, { key: "CustomerID" }, { key: "SiteDefID" }, { key: "DealerStockID" }, { key: "VIN" }, { key: "StockType" }
            , { key: "Year" }, { key: "Make" }, { key: "Model" }, { key: "SubModel" }
            , { key: "DFList" }, { key: "DisplayDFList" }, { key: "DisplayListPrice" }, { key: "DisplayMSRP" }, { key: "DisplayInternetPrice" }, { key: "DisplayXoutPrice" }
            , { key: "ExtColor" }, { key: "IntColor" }, { key: "Mileage" }
            , { key: "First80w60h" }, { key: "Certified" }, { key: "IsSpecial" }, { key: "SiteDetailURL" }, { key: "SiteURL" }
            , { key: "Engine" }, { key: "EngineSize" }, { key: "ModelNum" }, { key: "Body" }, { key: "YMMS" }
            , { key: "SuperFormURL" }, { key: "ExtBBURL" }, { key: "FirstVideoURL" }, { key: "CarFaxOneOwner" }, { key: "FirstVidAsLink" }, { key: "MktClass" }
            , { key: "First160w120h" }, { key: "Drivetrain" }
        ],
        metaFields: { totalCount: "d.TotalCount", iMinPrice: "d.iMinPrice", iMaxPrice: "d.iMaxPrice", PageNum: "d.PageNum", CarsPerPage: "d.CarsPerPage" }
    },

      g_oSiteSearchColsResponseSchema = {
          resultsList: "d.Results",
          fields: g_oSiteSearchCols
      };

    /*         
    * Called from MasterInit and CBProcessGrdConfigData functions which sends a request
    *       to fetch data
    *  
    *  @param {object} oCallback - Contains the functions to be executed on success and failure of data request
    *  @param {string} sParameter - A parameter which will be sent along with the request
    *  @param {string} sDataSource - Contains the web service method which acts as a data source for requests
    *  @param {object} oResponseSchema - Holds the response schema fields 
    */
    var RequestData = function (oCallback, sParameter, sDataSource, oResponseSchema) {
        var oDataSource = new YAHOO.util.DataSource(sDataSource);
        oDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; //  set the content-type to JSON

        //This line is required to establish JSON Communincation between YUI Datasource and Asp.net WebService
        oDataSource.connMgr.initHeader("Content-Type", "application/json; charset=utf-8", true);
        oDataSource.responseSchema = oResponseSchema;
        oDataSource.sendRequest(sParameter, oCallback, null);
        oDataSource = null;
    },

    /*         
    * It creates querystring for datasource call to get MenuItems based on Button Menu Type
    */
    CreateReqParam4MenuDSQuery = function (sButton) {
        var sMenuRequestParams = "?stockType=" + g_iStockType + "&year=null&make=null&model=null&subModel=null&minDFList=null&maxDFList=null&minMileage=null&maxMileage=null&";
        for (sBtnIndex in g_oButtonList) {
            if (sButton == sBtnIndex) {
                sMenuRequestParams = sMenuRequestParams.replace(g_oButtonList[sBtnIndex].DSKey + "=null&", "");
                continue;
            }
            if (g_oButtonList[sBtnIndex].SelectedValue != null) {
                if (YAHOO.lang.isNumber(g_oButtonList[sBtnIndex].SelectedValue))
                    sMenuRequestParams = sMenuRequestParams.replace(g_oButtonList[sBtnIndex].DSKey + "=null", g_oButtonList[sBtnIndex].DSKey + "=" + g_oButtonList[sBtnIndex].SelectedValue);
                else
                    sMenuRequestParams = sMenuRequestParams.replace(g_oButtonList[sBtnIndex].DSKey + "=null", g_oButtonList[sBtnIndex].DSKey + "=\"" + m_oUtils.EncodeString(g_oButtonList[sBtnIndex].SelectedValue) + "\"");
            }
        }
        return sMenuRequestParams;
    },

    /*         
    * It creates querystring for Datasource call to get Carlist data
    */
    CreateReqParam4CarListFromBtns = function (pageNum, logSearch) {
        var sRepl = null, sWith = null, sTemp = null;
        var sMenuRequestParams = CreateReqParam4CarListFromQueryString(logSearch, true),
            oQS = new Querystring(sMenuRequestParams);

        //Ignore QS should be set once reset is clicked
        if (!YAHOO.lang.isUndefined(g_oButtonList)) {
            for (var sBtnIndex in g_oButtonList) {
                sRepl = g_oButtonList[sBtnIndex].DSKey + "=null";
                sWith = g_oButtonList[sBtnIndex].DSKey + "=";

                if (g_oButtonList[sBtnIndex].SelectedValue != null) {
                    if (YAHOO.lang.isNumber(g_oButtonList[sBtnIndex].SelectedValue))
                        sWith += g_oButtonList[sBtnIndex].SelectedValue;
                    else
                        sWith += "\"" + m_oUtils.EncodeString(g_oButtonList[sBtnIndex].SelectedValue.replace(/["]/g, "")) + "\"";

                    sMenuRequestParams = sMenuRequestParams.replace(sRepl, sWith);
                }
            }
        }

        //handle stock type in the quick search
        if (g_IsQuickSearch) {
            sMenuRequestParams = sMenuRequestParams.replace("stockType=null", "stockType=" + g_iStockType);
        }

        if (g_sSortItem != null) {
            sTemp = m_oUtils.QSVal(oQS, "sortCol", "sortCol", false, false);
            sTemp = sTemp.indexOf("null") > -1 ? null : sTemp; //value of null returns as ""null"".
            sMenuRequestParams = sMenuRequestParams.replace("sortCol=" + sTemp, "sortCol=\"" + g_sSortItem + "\"");
        }
        if (g_sSortType != null) {
            sTemp = m_oUtils.QSVal(oQS, "sortType", "sortType", false, false);
            sTemp = sTemp.indexOf("null") > -1 ? null : sTemp; //value of null returns as ""null"".
            sMenuRequestParams = sMenuRequestParams.replace("sortType=" + sTemp, "sortType=\"" + g_sSortType + "\"");
        }
        sMenuRequestParams = sMenuRequestParams.replace("pageNum=1", "pageNum=" + pageNum); //CreateReqParam4CarListFromQueryString always returns pageNum=1

        try {
            YAHOO.util.History.navigate("QryString", sMenuRequestParams);
        } catch (e) {
            var i = 1;
        };

        return sMenuRequestParams;
    },

    /*         
    * Called by the functions BackPreviousPage, MasterInit. Creates datasource request parameter by decoding the querystring
    *   parameters.  
    *  
    *  @param {bool} logSearch - Value to ve appended to querystring
    *  @param {bool} doNotSetBtns - Sets buttons only when value is null or false
    */
    CreateReqParam4CarListFromQueryString = function (logSearch, doNotSetBtns) {
        var oQS = null;

        //If they've reset the page, we pass an empty QS so that we can build a request parameter
        //  with a fresh search (seed it with the stock type though, so we don't mix the results)
        if (g_IgnoreQS) oQS = new Querystring("dpt=" + g_iStockType.toString());
        else oQS = new Querystring();

        var sParams = "?logSearch=" + logSearch + "&";
        sParams += m_oUtils.GetParam(oQS, "sortCol", "sortCol", false, false);
        sParams += m_oUtils.GetParam(oQS, "sortType", "sortType", false, false);
        sParams += m_oUtils.GetParam(oQS, "VIN", "vin", false, false);
        sParams += m_oUtils.GetParam(oQS, "dealerStockID", "stk", false, false);
        sParams += m_oUtils.GetParam(oQS, "stockType", "dpt", true, true);
        sParams += m_oUtils.GetParam(oQS, "year", "yr", true, true);
        sParams += m_oUtils.GetParam(oQS, "make", "mk", false, false);
        sParams += m_oUtils.GetParam(oQS, "model", "mdl", false, false);
        sParams += m_oUtils.GetParam(oQS, "subModel", "smdl", false, false);
        sParams += m_oUtils.GetParam(oQS, "minMileage", "miMn", true, true);
        sParams += m_oUtils.GetParam(oQS, "maxMileage", "miMx", true, true);
        sParams += m_oUtils.GetParam(oQS, "numOfDoors", "nmDrs", true, true);
        sParams += m_oUtils.GetParam(oQS, "certified", "cert", false, false);
        sParams += m_oUtils.GetParam(oQS, "minDFList", "lsMn", true, true);
        sParams += m_oUtils.GetParam(oQS, "maxDFList", "lsMx", true, true);
        sParams += m_oUtils.GetParam(oQS, "onLotAfter", "dtAft", false, false);
        sParams += m_oUtils.GetParam(oQS, "onLotBefore", "dtBef", false, false);
        sParams += "pageNum=1&carsPerPage=" + ROWS_PER_PG + "&";
        sParams += m_oUtils.GetParam(oQS, "fullText", "q", false, false) + "&";
        sParams += m_oUtils.GetParam(oQS, "mpghmn", "mpghmn", true, true) + "&";
        sParams += m_oUtils.GetParam(oQS, "lotID", "lot", false, false);
        sParams += m_oUtils.GetParam(oQS, "daysOnLotMin", "mndys", true, true);
        sParams += "&output=json\"";

        //May as well use this moment to setup the buttons lists
        if (!YAHOO.lang.isUndefined(g_oButtonList) && (YAHOO.lang.isUndefined(doNotSetBtns) || !doNotSetBtns)) {
            if (g_oButtonList["Year"] != null)
                g_oButtonList["Year"].SelectedValue = m_oUtils.QSVal(oQS, "yr", true, true);
            if (g_oButtonList["Make"] != null)
                g_oButtonList["Make"].SelectedValue = m_oUtils.QSVal(oQS, "mk", false, true);
            if (g_oButtonList["Model"] != null)
                g_oButtonList["Model"].SelectedValue = m_oUtils.QSVal(oQS, "mdl", false, true);
            g_oButtonList["MinDFList"].SelectedValue = m_oUtils.QSVal(oQS, "lsMn", true, true);
            g_oButtonList["MaxDFList"].SelectedValue = m_oUtils.QSVal(oQS, "lsMx", true, true);
        }

        return sParams;
    },

    /*         
    * Sets the selected values for the buttons from the query string.
    */
    SetBtnValuesFromQryString = function (sQry) {
        var sParams = null, oQS = new Querystring(),
            sValue = null, sParm = null, sKVP = null, sKeyVals = [];

        if (sQry) {
            //sQry contains the previous search parameters list
            sParams = sQry.split("&");
            for (var i in sParams) {
                //Split the key value pair
                sKVP = sParams[i].split("=");
                sParm = sKVP[0].replace(/[?]/g, "").toLowerCase();
                sValue = sKVP[1];
                if (sValue == undefined || sValue == "null") sValue = null;
                if (sValue) sValue = unescape(sValue).replace(/["]/g, "");

                //Cache the value
                sKeyVals[sParm] = sValue;

                //Set the repeated globals
                if (sParm == "pagenum") {
                    g_iPageNum = Number(sValue);
                }
                else if (sParm == "sortcol") {
                    g_sSortItem = sValue;
                }
                else if (sParm == "sorttype") {
                    g_sSortType = sValue;
                }
            }
        }

        //VIN
        sValue = m_oUtils.QSVal(oQS, "VIN", false, true);
        if (sValue && sValue != "null")
            m_oYDOM.get("txtVin").value = sValue;

        //Stk #
        sValue = m_oUtils.QSVal(oQS, "dealerStockID", false, true);
        if (sValue && sValue != "null")
            m_oYDOM.get("txtStockID").value = sValue;

        for (sBtnType in g_oButtonList) {
            if (!sQry || sQry == "") {
                //Try to fetch the value from querystring
                if (!g_IsQuickSearch)
                    sValue = m_oUtils.QSVal(oQS, g_oButtonList[sBtnType].QSKey, false, true);
            }
            else sValue = sKeyVals[sBtnType.toLowerCase()];

            //make sure we have something in sValue
            if (sValue == undefined) sValue = null;

            //Full text is a little different, since they're not actually buttons
            if (sBtnType == "FullText") {
                try {
                    g_oButtonList[sBtnType].SelectedValue = sValue;

                    if (sValue) m_oYDOM.get("txtFullTxt").value = sValue;
                    else m_oYDOM.get("txtFullTxt").value = "";
                }
                catch (e) { }
            }
            else {
                //If we have value, select it
                oBtn = YAHOO.widget.Button.getButton('Btn' + sBtnType);
                if (sValue) {
                    if (g_SetLabels4Btns)
                        oBtn.set("label", sValue);

                    if (g_oButtonList[sBtnType].Type == 'SliderButton')
                        g_oButtonList[sBtnType].SelectedValue = Number(sValue);
                    else
                        g_oButtonList[sBtnType].SelectedValue = sValue;
                }
                else {
                    //Otherwise, just restore the default label and clear out the value
                    g_oButtonList[sBtnType].SelectedValue = null;
                    if (g_SetLabels4Btns)
                        oBtn.set("label", g_oButtonList[sBtnType].Label);
                }
            }

            //reset the value holder
            sValue = null;
        }
    },

    InitializeHistory = function () {
        try {
            //See if we already have a qry string search bookmarked (default: "N/A")
            g_sBookmarkedSection = YAHOO.util.History.getBookmarkedState("QryString");

            var sInitSection = g_sBookmarkedSection || "N/A";

            // Initialize the browser history management library.
            YAHOO.util.History.register("QryString", sInitSection, BackPreviousPage);
            YAHOO.util.History.initialize("yui-history-field", "yui-history-iframe");
        } catch (e) {
            var i = 1;
        };
    },

    BackPreviousPage = function (sQry) {
        if (!g_AvoidBackPreviousHndlr) {
            g_BlockPaginationHndlr = true;
            g_IsInitiatedByPaginator = false;

            if (sQry.indexOf("N/A") > -1) {
                sQry = CreateReqParam4CarListFromQueryString(false);
            }

            g_SetLabels4Btns = true;
            SetBtnValuesFromQryString(sQry);
            RequestData(g_oCarListDSCallback, sQry, g_sCarListDataSource, g_oCarListResponseSchema);
        }
        g_AvoidBackPreviousHndlr = false;
    },

    /*         
    * Called by the function CreateCustomColumns and creates a hyperlink using the data and fields that
    *   are passed as parameters.
    *  
    *  @param {object} Data - Contains the Car record  
    *  @param {object} Fields - Contains the Fields  
    *  @param {string} FormatString - Contains the format of the link  
    */
    CreateLink = function (Data, Fields, FormatString) {
        var cols = Fields.split(",");
        //Do not try FormatString.replace(new RegExp(sRegExp, "g"), Data[cols[i]]) for it always say Invalid quanititier;
        // It is expensive to use sRegExp =eval("/\\{"+i+''+ "\\}/g");FormatString = FormatString.replace(sRegExp, Data[cols[i]] ? Data[cols[i]] : "")
        for (var i in cols) {
            FormatString = FormatString.replace('{' + i + '}', Data[cols[i]] ? Data[cols[i]] : "").replace('{' + i + '}', Data[cols[i]] ? Data[cols[i]] : "");
        }
        return FormatString;
    },

     CreateCustomColumns = function () {
         var sField,
             iCarCnt = g_oCarList.length,
             iColCnt = g_oColumnDefs.length;

         for (var i = 0; i < iCarCnt; i++) {
             for (var j = 0; j < iColCnt; j++) {
                 sField = g_oColumnDefs[j]["key"];
                 g_oCarList[i][sField] = CreateLink(g_oCarList[i], g_oSiteSearchColsData[j].Fields, g_oSiteSearchColsData[j].FormatString);
             }
         }
     },

     CreateMenu = function (btn, menuItems) {
         if (YAHOO.lang.isNumber(menuItems[0])) {
             for (var idx in menuItems)
                 menuItems[idx] = String(menuItems[idx]);
         }
         var oMenu = btn.getMenu();

         //Work around for scrollbars not working after repopulating with ClearContent()       
         oMenu.cfg.setProperty("maxheight", 0);

         oMenu.clearContent();
         oMenu.addItems(menuItems);
         oMenu.render(btn);
     },

    /*         
    * Sends request to get filtered car data   
    */
     GetFilteredCarList = function (pageNum) {
         //Reset the sort globals
         g_sSortType = null;
         g_sSortItem = null;

         //Newly filtered car lists are always set to first page and logged
         var sReqParam = CreateReqParam4CarListFromBtns(1, true);

         g_AvoidBackPreviousHndlr = true;
         g_HaveCarList = false;

         //Hit webservice to get car records
         RequestData(g_oCarListDSCallback, sReqParam, g_sCarListDataSource, g_oCarListResponseSchema);
     },

    /*         
    * Called by the functions CBProcessGrdConfigData,CBProcessCarData.
    *    Destroys the existing datatable and creates a new table with passed data records.   
    */
     CreateDataTable = function () {
         if (g_oDataTable != null)
             g_oDataTable.destroy();

         var oDsRecords = new YAHOO.util.DataSource(g_oCarList);
         oDsRecords.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
         oDsRecords.responseSchema = {
             fields: g_oColumnDefs
         };
         g_oDataTable = new YAHOO.widget.DataTable("CSData", g_oColumnDefs, oDsRecords);
         g_oDataTable.subscribe("cellClickEvent", hndlrRegisterHistoryForCellClick);

         //Do not recreate the paginator when the datatable is being created by paginator buttons
         if (!g_IsInitiatedByPaginator) {
             if (g_oPaginator != null)
                 g_oPaginator.destroy();
             g_oPaginator = new YAHOO.widget.Paginator({
                 rowsPerPage: ROWS_PER_PG,
                 totalRecords: g_iTotalCount,
                 template: "{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}",
                 alwaysVisible: true,
                 updateOnChange: true,
                 pageLinks: 5,
                 containers: ["CSPagingTop", "CSPagingBtm"]
             });
             g_oPaginator.subscribe("pageChange", hndlrHandlePagination);
             g_oPaginator.render();
         }

         g_oPaginator.setPage(g_iPageNum, false);

         if (g_onDataTblCreated)
             g_onDataTblCreated.fire(g_oDataTable);

         if (g_onDataTblFiltered)
             g_onDataTblFiltered.fire();
     },

    /*         
    *  Creates Menu Buttons and adds event handlers to them
    */
    CreateMenuBtns = function (type, args) {
        for (var sBtnIndex in g_oButtonList) {
            if ((g_IsQuickSearch && g_oButtonList[sBtnIndex].Visible == false)
                || g_oButtonList[sBtnIndex].Type != "MenuButton") continue;

            //Create Button
            oButton = new YAHOO.widget.Button("Btn" + sBtnIndex,
            {
                type: "menu",
                label: g_oButtonList[sBtnIndex].SelectedValue == null ? g_oButtonList[sBtnIndex].Label : g_oButtonList[sBtnIndex].SelectedValue,
                lazyloadmenu: false,
                menu: "BtnLst" + sBtnIndex,
                menuminscrollheight: 100,
                menumaxheight: 215
            });

            //Subscribe to menu click events
            oMenu = oButton.getMenu();
            oMenu.subscribe("click", hndlrOnMenuItemSelected, oButton);

            var oBtnMenuCallback =
                {
                    success: CBMenuItemsAvailable,
                    failure: CBProcessError,
                    argument: oButton
                };
            g_oButtonList[sBtnIndex].Callback = oBtnMenuCallback;

            //CSS Hooks
            if (!YAHOO.util.Config.alreadySubscribed(oMenu.showEvent, m_oUtils.MenuCSHdrFtr, oMenu)) {
                oMenu.showEvent.subscribe(m_oUtils.MenuCSHdrFtr, oMenu, true);
            }
        }

        m_oYDOM.setStyle("CSYMMS", "visibility", "visible");
    },

    CreateRadioBtn = function (deptType) {
        if (g_IsStockTypeRestricted) return;

        //Create Radio Button Div
        var oStockTypeGrp = new YAHOO.widget.ButtonGroup({ id: "CSRadio", name: "StockType", container: "CSStockType" });
        oStockTypeGrp.addButtons([
                 { id: "btnRadNew", label: "New", value: "1", checked: deptType == 1, onclick: { fn: CSSearch.HndlrRadNew} },
                 { id: "btnRadUsed", label: g_sUsedText, value: "2", checked: deptType == 2, onclick: { fn: CSSearch.HndlrRadUsed} }
               ]);
    },

    /*         
    *  Creates Slider Buttons and adds event handlers to them
    */
    CreateSliderBtns = function (type, args) {
        if (g_IsQuickSearch) return;

        var sLabel = null, oSliderMenu = null;

        for (var sBtnIndex in g_oButtonList) {
            if (g_oButtonList[sBtnIndex].Type != "SliderButton") continue;


            //Set the min or max price if it is passed through querystring
            if (g_oButtonList[sBtnIndex].SelectedValue == 0
              || g_oButtonList[sBtnIndex].SelectedValue == D_MAXLIST
              || g_oButtonList[sBtnIndex].SelectedValue == null)
                sLabel = g_oButtonList[sBtnIndex].Label;
            else
                sLabel = m_oUtils.Convert2PrettyString(g_oButtonList[sBtnIndex].SelectedValue + "");

            //Menu instance body element will house a slider instance
            // Menu width = Thumb Width + SLDR_RANGE
            oSliderMenu = new YAHOO.widget.Menu("menu" + sBtnIndex, { width: "170px" });

            oButton = new YAHOO.widget.Button({
                type: "menu",
                label: sLabel,
                lazyloadmenu: false,
                id: "Btn" + sBtnIndex,
                menu: oSliderMenu,
                container: g_oButtonList[sBtnIndex].ContainerID
            });

            //Once the new Button is created, "appendTo" event will be used 
            //  to render its Menu instance into the same DOM element specified as the containing element
            //  for the Button.
            oButton.on("appendTo", hndlrAppendSlider2Btn, oButton);

            //"beforeShow" event handler to the Menu instance 
            //  will instantiate the Slider.
            oSliderMenu.subscribe("beforeShow", hndlrOnMenuBeforeShow, oButton);
        }
        g_SliderBtnsCreated = true;
        //Set Max and Min values for the sliders only if the carlist is available
        if (!g_SliderValuesSet && g_HaveCarList & !g_IsTableFilteredBySlider)
            SetSliderMinMaxValues();
    },

    /*         
    *  Rebinds all buttons whose selected value is null 
    */
    RebindMenuBtns = function () {

        g_AvoidBackPreviousHndlr = true;
        var sSelVal = null, sReqParam = null;

        for (var sBtnIndex in g_oButtonList) {

            if (g_IsQuickSearch && g_oButtonList[sBtnIndex].Visible == false)
                continue;

            //Send request only when the button does not have a selected value
            sSelVal = g_oButtonList[sBtnIndex].SelectedValue;
            if (sSelVal == null && g_oButtonList[sBtnIndex].Type == "MenuButton") {
                sReqParam = CreateReqParam4MenuDSQuery(sBtnIndex);
                RequestData(g_oButtonList[sBtnIndex].Callback, sReqParam, g_oButtonList[sBtnIndex].DataSource, g_oRespSchema);
            }
        }
    },

    /*         
    * Sets the Max and Min values on the slider buttons
    */
    SetSliderMinMaxValues = function () {
        var iMinMaxValue = null, sBtnIndex = null, oSliderBtn = null;

        for (sBtnIndex in g_oButtonList) {
            if (g_oButtonList[sBtnIndex].Type == "MenuButton" || g_oButtonList[sBtnIndex].Type == "TextBox")
                continue;
            iMinMaxValue = sBtnIndex.indexOf("Min") < 0 ? g_iCurrentMax : g_iCurrentMin;

            //Don't allow excluded values (-99999.99 or negative values from YUI bugs)
            if (iMinMaxValue < 0) iMinMaxValue = sBtnIndex.indexOf("Min") < 0 ? D_MAXLIST : 0;

            oSliderBtn = YAHOO.widget.Button.getButton("Btn" + sBtnIndex);
            oSliderBtn.set("label", m_oUtils.Convert2PrettyString(iMinMaxValue.toString()));
        }

        if (g_IsTableFilteredBySlider)
            g_IsTableFilteredBySlider = false;
    },

    /*         
    *  Resets the lables and selected values of the buttons
    */
    ResetLabelsAndSelectedValuesOfBtns = function () {
        //Reset the selected values of all the buttons
        for (sBtnIndex in g_oButtonList) {
            if (g_IsQuickSearch && g_oButtonList[sBtnIndex].Visible == false)
                continue;
            oButton = YAHOO.widget.Button.getButton('Btn' + sBtnIndex);
            if (oButton)
                oButton.set("label", g_oButtonList[sBtnIndex].Label); //Reset the previous selected menuItem which is shown on the button

            if (g_oButtonList[sBtnIndex].Type === 'MenuButton') {
                g_oButtonList[sBtnIndex].SelectedValue = null; //Reset the SelectedValue property of g_oButtonList to null                       
            }
            else if (g_oButtonList[sBtnIndex].Type === 'SliderButton') {
                sBtnID = oButton._button.id;
                sThumbID = sBtnID.replace('Btn', "").replace('-button', 'thumb');
                var sMaxMinColumnName = sBtnID.indexOf("Min") < 0 ? "MaxValue" : "MinValue";
                g_oButtonList[sBtnIndex].SelectedValue = g_oButtonList[sBtnIndex][sMaxMinColumnName];
            }
            else if (g_oButtonList[sBtnIndex].Type === 'TextBox') {
                var oFTxtBox = m_oYDOM.get("txtFullTxt");
                if (oFTxtBox) {
                    oFTxtBox.value = g_oButtonList["FullText"].SelectedValue = "";
                }
            }
        }
        if (!g_IsQuickSearch) {
            //Clear the contents of textboxes in StockVin Div
            ClearStkVinSearch();
        }
    },

    ClearStkVinSearch = function () {
        try {
            m_oYDOM.get("txtStockID").value = "";
            m_oYDOM.get("txtVin").value = "";
            //Make the Vin/StockID lookup section invisible
            m_oYDOM.addClass(m_oYDOM.get("CSStockVinSearch"), "DfltHidden");
        } catch (e) { }
    },

    SetPrettyLbl4Btn = function (btn, btnType, value2Display) {
        if (btnType.indexOf("DFList") > -1)
            btn.set("label", m_oUtils.Convert2PrettyString(value2Display));
        else if (btnType.indexOf("Mileage") > -1)
            btn.set("label", value2Display + " MPG");
    },

    GetBaseUrl = function () {
        if (g_iStockType == 1) return "/new/search?dpt=1";
        return "/used/search?dpt=2";
    },

    GetSelValue = function (elementID) {
        var element = m_oYDOM.get(elementID);
        if (!element) return "";

        //DropDown
        if (element.options) {
            try {
                if (element.selectedIndex == 0) return "";

                return element.options[element.selectedIndex].innerHTML;
            } catch (e) { return element.options[0].innerHTML }
        }

        //Radio buttons
        var iRadLen = element.length;
        if (iRadLen && iRadLen > 1)
            for (var i = 0; i < iRadLen; i++)
                if (element[i].checked)
                    return element[i].value;

        //TextBox
        return element.value;
    },

    GetSelValsAsQs = function () {
        var sHttp = GetBaseUrl(),
            sYr = GetSelValue("BtnLstYear"),
            sMk = GetSelValue("BtnLstMake"),
            sMdl = GetSelValue("BtnLstModel"),
            sMinPrice = GetSelValue("BtnMinDFList"),
            sMaxPrice = GetSelValue("BtnMaxDFList"),
            sFullTxt = GetSelValue("txtFullTxt");

        if (sYr != null && sYr != "") sHttp += "&yr=" + sYr;
        if (sMk != null && sMk != "") sHttp += "&mk=" + CSUtils.EncodeString(sMk);
        if (sMdl != null && sMdl != "") sHttp += "&mdl=" + CSUtils.EncodeString(sMdl);
        if (sMinPrice != null && sMinPrice != "") sHttp += "&lsMn=" + CSUtils.Currency2Numb(sMinPrice);
        if (sMaxPrice != null && sMaxPrice != "") sHttp += "&lsMx=" + CSUtils.Currency2Numb(sMaxPrice);
        if (sFullTxt != null && sFullTxt != "") sHttp += "&q=" + CSUtils.EncodeString(sFullTxt);
        return sHttp;
    },

    ResetDropDown = function (id) {
        try {
            m_oYDOM.get(id).selectedIndex = 0;
        } catch (error) { }
    },

    ResetLtBtns = function () {
        ResetDropDown("BtnLstYear");
        ResetDropDown("BtnLstMake");
        ResetDropDown("BtnLstModel");
        ResetDropDown("CSRadio");
        return false;
    },

    /****************************** Event Handlers *******************************/

    /* 
    *  This function is triggered when the menuitem of the buttons is clicked or selected. 
    *    It filters datatable and rebinds other buttons
    *  
    *  @param {String} eventType - The name of the event that was fired.
    *  @param {Array} eventArgs - Collection of arguments sent when the event was fired. 
    *  @param {object} oBtn - The button object. 
    */
    hndlrOnMenuItemSelected = function (eventType, eventArgs, oBtn) {
        var oMenuItem = eventArgs[1];   //Menu Item instance that was the target of the event                
        if (oMenuItem) {
            var sMenuItemText = oMenuItem.cfg.getProperty("text");  //cfg represents MenuModule's Config object which can be used to get the properties of the object
            oBtn.set("label", sMenuItemText);
            g_oButtonList[oBtn._button.id.replace("Btn", "").replace("-button", "")].SelectedValue = sMenuItemText;
        }

        if (!g_IsQuickSearch) {
            g_IsInitiatedByPaginator = false;
            GetFilteredCarList();
        }
        RebindMenuBtns();
    },

    /*
    *   This function is triggered when slider button is clicked. It sets the slider constraints
    *       and initializes the slider if the button is clicked for the first time
    */
     hndlrOnMenuBeforeShow = function (eventType, eventArgs, oBtn) {
         var sBtnID = oBtn._button.id, oSlider = null, iScalingFactor = 0, iScalingFactorInverse = 0;
         var sMenuButtonType = sBtnID.replace(new RegExp("(Btn)|(-button)", "gi"), "");
         var sLabel = oBtn._configs.label.value.replace(',', '').replace('$', '') - 0;

         //The number of pixels the thumb can move on the slider
         var MinValue = g_oButtonList[sMenuButtonType].MinValue,
                    MaxValue = g_oButtonList[sMenuButtonType].MaxValue;
         g_oButtonList[sMenuButtonType].ScalingFactor = (SLDR_RANGE / (MaxValue - MinValue));
         iScalingFactor = g_oButtonList[sMenuButtonType].ScalingFactor;
         iScalingFactorInverse = (1 / iScalingFactor);

         var sBackgroundID = sMenuButtonType + 'bg', sThumbID = sMenuButtonType + 'thumb', oSlider = null;
         oSlider = g_oButtonList[sMenuButtonType].SliderObj;
         if (oSlider != null) {
             oSlider.thumb.resetConstraints();
             oSlider.setStartSliderState();
             oSlider.thumb.startOffset = [0, 0];
             oSlider.animate = false;
             oSlider.setValue(Math.round(iScalingFactor * (sLabel - MinValue)), true);
             return;
         }

         oSlider = YAHOO.widget.Slider.getHorizSlider(sBackgroundID, sThumbID, 0, SLDR_RANGE, 1);
         oSlider.animate = false;

         //oSlider.setValues(Math.round(m_iScalingFactor * MinValue), Math.round(m_iScalingFactor * MaxValue), true);
         // Set the initial value of the Slider instance. The default value for MinValue slider
         //  will be the min DFList and for MaxValue slider the value is max DFList
         if (sMenuButtonType.indexOf("Min") > -1) {
             if (YAHOO.lang.isNumber(sLabel)) {
                 oSlider.setValue(Math.round(iScalingFactor * (sLabel - MinValue - (iScalingFactorInverse))), true);
             }
             else {
                 SetPrettyLbl4Btn(oBtn, sMenuButtonType, MinValue + "");
                 oSlider.setValue(0, true);
             }
         }
         else {
             if (YAHOO.lang.isNumber(sLabel)) {
                 oSlider.setValue(Math.round(iScalingFactor * (sLabel - MinValue + (iScalingFactorInverse))), true);
             }
             else {
                 SetPrettyLbl4Btn(oBtn, sMenuButtonType, MaxValue + "");
                 oSlider.setValue(150, true);
             }
         }
         g_IsSliderInitialized = true; //Slider is initialized for the first time. 
         oSlider.subscribe("change", hndlrOnSliderChange, oBtn);
         oSlider.subscribe("slideEnd", hndlrOnSliderEnd, oBtn);
         g_oButtonList[sMenuButtonType].SliderObj = oSlider;
     },

    /*
    *  Apppends the slider to the button on the "appendTo" event of the button
    *  
    *  @param <String> e - Event Type
    *  @param {object} oBtn - Button object which fired this event.           
    */
    hndlrAppendSlider2Btn = function (e, oBtn) {
        // Add Slider markup to the Menu instance's body element
        var sBtnID = oBtn._button.id;
        var sMenuButtonType = sBtnID.replace(new RegExp("(Btn)|(-button)", "gi"), "");
        var sSliderBody = "<div id=\"XXXXXX\" title=\"Slider\" class=\"slider-bg\" height=\"15px\" tabindex=\"1\" ><div id=\"YYYYYY\" class=\"slider-thumb\" ><img src=\"/media/images/thumb-n.gif\" width =\"20px\" height=\"15px\" /></div></div>",
                        sSliderBody = sSliderBody.replace('XXXXXX', sMenuButtonType + "bg").replace('YYYYYY', sMenuButtonType + 'thumb');

        var oSliderMenu = oBtn.getMenu();
        oSliderMenu.setBody(sSliderBody);

        //Render the Menu instance into the element specified as the Button instance's container
        oSliderMenu.render(this.get("container"));
    },

    /*
    *   Event Handler for slideEnd event on the slider button. The datatable
    *       is filtered. It does not accept any parameters. 
    *   
    */
    hndlrOnSliderEnd = function () {
        //Avoids binding the datatable when the slider is first initialized   
        if (g_IsSliderInitialized) {
            g_IsSliderInitialized = false;
            return;
        }
        g_IsTableFilteredBySlider = true;

        GetFilteredCarList();
        RebindMenuBtns();

        g_IsSliderInitialized = false;
    },

    /*
    *   Event Handler for change event on the slider button. The new x offset is
    *       converted to relative DFList and is saved in g_oButtonList[sButtonType].SelectedValue. 
    *       The reason we save these values is the slideEnd event does not pass any parameters.
    * 
    *   @param <String> SelectedValue -  newOffset|x (pixel value)
    *   @param <object> oBtn - Button object
    */
    hndlrOnSliderChange = function (SelectedValue, oBtn) {
        var sButtonType = oBtn._button.id.replace(new RegExp("(Btn)|(-button)", "gi"), "");
        var sThumbID = "".concat(sButtonType, 'thumb');
        var iScalingFactorInverse = 1 / g_oButtonList[sButtonType].ScalingFactor;
        //Avoids binding the datatable when the slider is first initialized
        if (g_IsSliderInitialized) {
            return;
        }
        g_oButtonList[sButtonType].SelectedValue = String(Math.round((SelectedValue * iScalingFactorInverse) + g_oButtonList[sButtonType].MinValue));
        SetPrettyLbl4Btn(oBtn, sButtonType, g_oButtonList[sButtonType].SelectedValue);
        g_IsSliderInitialized = false;
    },

    hndlrHandlePagination = function (state) {
        if (g_BlockPaginationHndlr) {
            g_BlockPaginationHndlr = false;
            return;
        }

        //Find the current page, and create the data source parameters for the AJAX call
        g_iPageNum = state.newValue;
        var sParam = CreateReqParam4CarListFromBtns(g_iPageNum, false);

        g_IsInitiatedByPaginator = true;
        RequestData(g_oCarListDSCallback, sParam, g_sCarListDataSource, g_oCarListResponseSchema);
        g_AvoidBackPreviousHndlr = true;
    },

    hndlrRegisterHistoryForCellClick = function (e) {
        if (Event.target.innerHTML.indexOf("href") > -1) {
            g_AvoidBackPreviousHndlr = true;
            var sTmp = CreateReqParam4CarListFromBtns(g_iPageNum, false);
        }
    },

    /********************************* Callback functions *******************************/
    /*
    *  Call back function for button menu items. It fires an event onButtonsAvailable and creates Sort buttons
    *  
    *  @param {String} requestStr - Contains the request object that was sent.
    *  @param {object} oParsedResponse - Has the return data
    *  @param {object} oPayload - The button object which is passed as an argument
    */
    CBMenuItemsAvailable = function (requestStr, oParsedResponse, oPayload) {
        CreateMenu(oPayload, oParsedResponse.results);
    },

    /* 
    *  Call back function for button list datasource. It fires an event onButtonsAvailable and creates Sort buttons
    */
    CBProcessButtonsData = function () {
        g_SetLabels4Btns = false;
        SetBtnValuesFromQryString(g_sBookmarkedSection);
        g_onButtonsAvailable.fire();
    },

    /* 
    *  Call back function for grid config datasource. It creates g_oColumnDefs array
    *       and then creates the datatable
    */
    CBProcessGrdConfigData = function () {
        //Create a g_oColumnDefs which is required for fetching carlist data
        //Do not use g_oColumnDefs.push for it is wrong order in IE// g_oColumnDefs.push({ key: i+"Header", label: g_oSiteSearchColsData[i].HeaderText });
        for (var i in g_oSiteSearchColsData)
            g_oColumnDefs[i] = { key: i + "Header", label: g_oSiteSearchColsData[i].HeaderText };

        //Get car list from database
        g_oCarListDSCallback =
           {
               success: CBProcessCarData,
               failure: CBProcessError,
               scope: null
           };

        if (g_sBookmarkedSection != null)
            RequestData(g_oCarListDSCallback, g_sBookmarkedSection, g_sCarListDataSource, g_oCarListResponseSchema);
        else
            RequestData(g_oCarListDSCallback, CreateReqParam4CarListFromQueryString(false), g_sCarListDataSource, g_oCarListResponseSchema);
    },

    /* 
    *  Call back function for car list datasource. It creates the datatable
    *  
    *  @param {String} requestStr - Contains the request object that was sent.
    *  @param {object} oParsedResponse - Has the return data
    *  @param {object} oPayload - The same value as was passed in to the argument of the oCallback object literal
    */
    CBProcessCarData = function (requestStr, oParsedResponse, oPayload) {
        g_oCarList = oParsedResponse.results;
        CreateCustomColumns();
        g_HaveCarList = true;
        g_iTotalCount = oParsedResponse.meta.totalCount;
        g_iPageNum = oParsedResponse.meta.PageNum;
        g_iCurrentMin = oParsedResponse.meta.iMinPrice;
        g_iCurrentMax = oParsedResponse.meta.iMaxPrice;
        CreateDataTable();
        //Set Max and Min values for the sliders only if they are created
        if (g_SliderBtnsCreated && !g_IsTableFilteredBySlider) {
            SetSliderMinMaxValues();
            g_SliderValuesSet = true;
        }

        var oDiv = m_oYDOM.get("SearchResults");
        if (oDiv) oDiv.innerHTML = "<span>Search Results (<span class=\"TotalCount\">" + g_iTotalCount + "</span>)</span>";
    },

   CBProcessError = function (requestStr, oParsedResponse, oPayload) { };

    return {
        /*       
        *  Entry point for all code in the file     
        *   - Asynchronous requests are sent to fetch Grid Config data, Button data and Carlist from database using webservice methods
        *
        *   @param {string} deptTypeID
        *   @param {bool} IsQuickSearch - Avoids execution of datatable code
        *   @param {string} usedText         
        */
        MasterInit: function (deptTypeID, IsQuickSearch, usedText, forceLtSrch) {
            var iDeptType = null,
            BtnsExist = !YAHOO.lang.isUndefined(g_oButtonList);

            g_IsLt = forceLtSrch || (YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie <= 7);

            if (!deptTypeID) {
                try { iDeptType = YAHOO.util.History.getQueryStringParameter("dpt"); }
                catch (e) { }
                if (!iDeptType) iDeptType = 1;
                g_iStockType = iDeptType;  //default new
                g_IsStockTypeRestricted = false; //can be changed
            } else {
                g_iStockType = deptTypeID;
                g_IsStockTypeRestricted = true;
            }

            g_IsQuickSearch = IsQuickSearch;
            g_sUsedText = usedText;

            if (BtnsExist) {
                g_onButtonsAvailable = new YAHOO.util.CustomEvent("onButtonsAvailable");

                if (!g_IsLt) {
                    g_onButtonsAvailable.subscribe(CreateMenuBtns);
                    g_onButtonsAvailable.subscribe(CreateSliderBtns);
                    CreateRadioBtn(iDeptType);
                }
            }

            //Needs to be done before buttons are processed
            if (!IsQuickSearch) InitializeHistory();

            //Get Button data from database
            if (BtnsExist) CBProcessButtonsData();

            //Setup the grid
            if (!IsQuickSearch) CBProcessGrdConfigData();
        },

        /*         
        * Event handler for the click event on sort items. It uses g_SortFlags to store the current order
        *   of the records for a specified sSortItem. If the same sortitem is clicked again then the 
        *   records are displayed in reverse order.
        *  
        *  @param {String} sSortItem - Clicked SortItem        
        */
        HndlrSort: function (sortItem) {
            g_sSortItem = sortItem;

            for (var j = 0; j < g_SortFlags.length; j++) {
                if (g_SortFlags[j].key == sortItem) {
                    g_sSortType = g_SortFlags[j].value ? "ASC" : "DESC";
                    g_SortFlags[j].value = !(g_SortFlags[j].value);
                    break;
                }
            }

            //new sort starts at page 1
            var sParam = CreateReqParam4CarListFromBtns(1, true);
            RequestData(g_oCarListDSCallback, sParam, g_sCarListDataSource, g_oCarListResponseSchema);

            g_IsInitiatedByPaginator = false;
            g_AvoidBackPreviousHndlr = true;

            return false;
        },

        DataTblCreated: function () {
            if (!g_onDataTblCreated)
                g_onDataTblCreated = new YAHOO.util.CustomEvent("onDataTblCreated");
            return (g_onDataTblCreated);
        },

        DataTblFiltered: function () {
            if (!g_onDataTblFiltered)
                g_onDataTblFiltered = new YAHOO.util.CustomEvent("onDataTblFiltered");
            return (g_onDataTblFiltered);
        },

        /*         
        *  This is handler for radio Button. It will reload Button Menu for New Cars. 
        */
        HndlrRadNew: function () {
            if (g_iStockType != 1) {
                g_iStockType = 1;
                RebindMenuBtns();
            }
        },

        /*         
        *  This is handler for radio Button . It will reload Button Menu for Used Car. 
        */
        HndlrRadUsed: function () {
            if (g_iStockType != 2) {
                g_iStockType = 2;
                RebindMenuBtns();
            }
        },

        /*         
        * Event handler for "click" event on Reset button. It recreates the menu for the buttons
        *   and displays all the data in the datatable irrespective of the query string. 
        */
        HndlrReset: function (e) {
            //Light Search
            if (g_IsLt) {
                if (g_IsQuickSearch) return ResetLtBtns();
                return;  //don't return false, we want to follow the link
            }

            //After Reset when Non_Slider Button is click we can still get the min and max value for Slide Button.       
            g_IgnoreQS = true; //no longer care about QS values in CreateReqParam4CarListFromBtns
            g_IsSliderInitialized = false;
            g_IsInitiatedByPaginator = false;
            ResetLabelsAndSelectedValuesOfBtns();
            RebindMenuBtns();

            if (!g_IsQuickSearch)
                GetFilteredCarList();

            return false;
        },

        QuickLightSearch: function () {
            var sTmp = null;
            if (g_IsLt) {
                if (g_IsQuickSearch) {
                    sTmp = GetSelValue("CSRadio");
                    g_iStockType = sTmp != null && sTmp != "" ? sTmp : g_iStockType;
                }
                location.href = GetSelValsAsQs();
            }
            else {
                var sHttp = null;
                //Even with restrction g_iStockType will have a value (even if it is just the default)
                if (g_iStockType == 1) sHttp = "/new/search?dpt=1#QryString=";
                else sHttp = "/used/search?dpt=2#QryString=";
                sHttp = sHttp.concat(m_oUtils.EncodeString(CreateReqParam4CarListFromBtns(1, true)));
                location.href = sHttp;
            }
            return false;
        },

        FullTextSearch: function (e) {
            var sHttp = null, sVal = m_oYDOM.get("txtFullTxt").value;
            g_oButtonList["FullText"].SelectedValue = sVal;

            //Light search
            if (g_IsLt) {
                location.href = GetSelValsAsQs();
                return false;
            }
            //Ajax search
            g_IsSliderInitialized = false;
            g_IsInitiatedByPaginator = false;

            //Clear and hide stock#/vin search
            ClearStkVinSearch();

            RebindMenuBtns();
            GetFilteredCarList();

            return false;
        },

        ToggleStockVin: function () {
            var oToggleDiv = m_oYDOM.get("CSStockVinSearch");
            if (oToggleDiv.className == "DfltHidden") {
                m_oYDOM.removeClass(oToggleDiv, "DfltHidden");
            }
            else {
                //Clear the contents of textboxes in StockVin Div
                m_oYDOM.get("txtStockID").value = "";
                m_oYDOM.get("txtVin").value = "";
                m_oYDOM.addClass(oToggleDiv, "DfltHidden");
            }
            return false;
        },

        StockVinSearch: function () {
            //Get the StockNumber and Vin
            var sVin = m_oYDOM.get("txtVin").value.toUpperCase(), sStockId = m_oYDOM.get("txtStockID").value.toUpperCase(), sHttp = null;
            sVin = sVin.length == 0 ? "null" : "\"" + sVin.replace(/[" "]/g, "") + "\"";
            sStockId = sStockId.length == 0 ? "null" : "\"" + sStockId.replace(/[" "]/g, "") + "\"";
            if (sVin == "null" && sStockId == "null") return false;

            //Light Search
            if (g_IsLt) {
                sHttp = GetBaseUrl();
                if (sVin != "null") sHttp += "&vin=" + sVin.replace(/["]/g, "");
                if (sStockId != "null") sHttp += "&stk=" + sStockId.replace(/["]/g, "");
                location.href = sHttp;
                return false;
            }

            //Avoid pagination handler from requesting data again
            g_BlockPaginationHndlr = true;

            //Paginator is rebuilt when g_IsInitiatedByPaginator is set to false
            g_IsInitiatedByPaginator = false;

            //Ajax search
            var sCarListParameter = "?logSearch=true&stockType=" + g_iStockType + "&VIN=" + sVin + "&dealerStockID=" + sStockId + "&sortCol=null&sortType=null&year=null&make=null&model=null&subModel=null&minDFList=null&maxDFList=null&&minMileage=null&maxMileage=null&numOfDoors=null&certified=null&onLotAfter=null&onLotBefore=null&pageNum=1&carsPerPage=30&mpghmn=null&fullText=null&lotID=null&daysOnLotMin=null&output=json\"";
            RequestData(g_oCarListDSCallback, sCarListParameter, g_sCarListDataSource, g_oCarListResponseSchema);
            return false;
        }
    }
} ();
var CSSearch = YAHOO.CSSearch.AdvSearch;
