﻿var BMW = {
    Settings : {
        USCountryID : 1
    },
    productImagesPath : '/images/products/',
    productImagesTempPath: '/images/products/tmp/'
}

BMW.generateSlug = function(slug) {
    slug = slug.replace(/ /gi, '-');
    slug = slug.toLowerCase();
    slug = slug.replace(/[^A-Z0-9\-]/gi, '');
    return slug
}

BMW.clearValue = function(key) {
    $.cookie(key, null);
}

BMW.getValue = function(key) {
    return $.cookie(key);
}

BMW.Log = function (message) {
    if (window.console) {
        if (window.console.firebug != '') {
            console.info(message);
        }
    }
}

BMW.setValue = function(key, value) {
    //{ expires: 7, path: '/', domain: 'jquery.com', secure: true }
    $.cookie(key, value, {path: '/'});
}

$(document).ready(function () {

    // Prompt user for deletion of item
    $('.delete-confirm').click(function () {
        var ans = confirm("Are you sure you want to delete this item?");
        if (ans) return true;
        return false;
    });

    $('table.zebra tr:even').addClass('alt');

    // Show state or province
    $('.country-list').change(function () {
        toggleCountryDetail(this);
    });

    toggleCountryDetail($('.country-list'));

    function toggleCountryDetail(el) {
        if (($(el).val() == BMW.Settings.USCountryID) || ($(el).val() == '')) {
            $('.state-wrapper').show();
            $('.province-wrapper').hide();
        } else {
            $('.state-wrapper').hide();
            $('.province-wrapper').show();
        }
    }


    // Search
    $('#search-form').submit(function () {
        var query = $(this).children('#q').val().replace(' ', '+');
        query = escape(query);
        window.location = '/search/' + query;
        return false;
    });

});


