// These functions require prototype, which should be enabled site-wide.

function clearTextBox(id, msg)
{
    var text_value = $(id).value;
    if (msg == text_value)
    {
        $(id).value = '';
    }
    return;
}

function resetTextBox(id, msg)
{
    if ($(id).value == '')
    {
        $(id).value = msg;
    }
    return;
}

function detailImagesPopup(url)
{
    window.open(url, '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=638,height=596');
}

/**** Misc. JavaScript code  Requires jQuery ****/

/* Launches a popup window. */
function launchPopup(url,w,h)
{
    if(w == undefined || w == ""){w=730;}
    if(h == undefined || h == ""){h=498;}
    window.open(url, '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+w+',height='+h);
}

function loadSidebarManufacturers(ajaxUrl) {
    $.getJSON(ajaxUrl, {}, function (json) {
        var manufacturerList = document.getElementById('simple_manufacturer');
        $(manufacturerList).empty();
        
        for (var key in json) {
            var tmp = document.createElement('option');
            var txt = document.createTextNode(json[key]);
            tmp.value = key;
            tmp.appendChild(txt);
            manufacturerList.appendChild(tmp);
        }
    });
}

function loadSidebarModels(ajaxUrl) {
    $.getJSON(ajaxUrl, {
            make : $('#simple_manufacturer').children("[@selected]").attr('value')
        },
        function (json) {
            var modelList = document.getElementById('simple_model');
            $(modelList).empty();

            for (var key in json) {
                var tmp = document.createElement('option');
                var txt = document.createTextNode(json[key]);
                tmp.value = key;
                tmp.appendChild(txt);
                modelList.appendChild(tmp);
            }
            $(this).change();
        });
}

