﻿var searchUrl = 'Inventory';
var first = true;

function insertParam(key, value) {
    key = escape(key); value = escape(value);
    if (first) { searchUrl += '?'; first = false; } else { searchUrl += '&'; }
    searchUrl += key;
    searchUrl += '=';
    searchUrl += value;
}

function insertSearchParam(key) {
    var value = $.trim($('#' + key).val());
    if (value != '') {
        insertParam(key, value);
    }
}

function submitSearch() {
    var ref = $.trim($('#Ref').val());
    if (ref != '' && ref != 'Stock/VIN') {
        insertParam("Ref", ref);
    } else {
        insertSearchParam("Make");
        insertSearchParam("Model");
        insertSearchParam("Trim");
        insertSearchParam("Body");
        insertSearchParam("Engine");
    }
    document.location.href = searchUrl;
}

$(document).ready(function () {
    $("#Ref").focus(function () {
        $(this).filter(function () {
            return $(this).val() == "" || $(this).val() == "Stock/VIN"
        }).removeClass("watermarkOn").val("");
    });

    $("#Ref").blur(function () {
        $(this).filter(function () {
            return $(this).val() == ""
        }).addClass("watermarkOn").val("Stock/VIN");
    });
});
