/*
* loadAccordions
*/
function loadAccordions() {
    if($('accordion') != null) {
        var pageAccordion = new accordion('accordion');
        pageAccordion.activate($$('#accordion .accordion-toggle')[0]);
    }
}

/*
* loadTips
*/
function loadTips() {
    if ($('hybrid')) {
        new Tip('hybrid', '<a href="javascript:;" class="close">Close</a> <p>A vehicle that typically pairs a gasoline engine with a combination of an electric motor and a series of batteries.</p>', {
            className: 'silver',
            showOn: 'click',
            hideOn: {element: '.close', event: 'click' },
            hook: {target: 'topRight', tip: 'bottomLeft'}
        })
    };
    if ($('crossover')) {
        new Tip('crossover', '<a href="javascript:;" class="close">Close</a> <p>A vehicle that typically combines a car-based platform with SUV-type benefits.</p>', {
            className: 'silver',
            showOn: 'click',
            hideOn: {element: '.close', event: 'click' },
            hook: {target: 'bottomRight', tip: 'topLeft'}
        })
    };
    if ($('zip-help')) {
        new Tip('zip-help', '<a href="javascript:;" class="close">Close</a> <p>You don\'t have to enter a ZIP code. However, if you see a vehicle you\'d like to purchase, we can use your ZIP code to find one near you.</p>', {
            className: 'silver',
            showOn: 'click',
            hideOn: {element: '.close', event: 'click' },
            hook: {target: 'bottomRight', tip: 'topLeft'}
        })
    };
}

function validateVin() {
    var vinField = document.vhr_search.vin;

    if (!vinField.value){
        alert ('Please enter a VIN.');
        return false;
    }

    if (trim(vinField.value).length < 17) {
         alert ('Please enter a valid 17 character VIN.');
         return false;
    } else {
         return true;
    }

}

function trim(str) {
    return str.replace(/^\s+|\s+$/g, '');

}

function logAsisImage(src) {
    var asisImage       = new Image();
    asisImage.src   = src;
}

// Adds the ability to do logAsisImage along with validating the vin
function vinValidator(src){
    logAsisImage(src);
    return validateVin();
}

// SEE: http://prototypejs.org/api/event/observe
Event.observe(window, 'load', init);
function init(){
    loadAccordions();
    loadTips();
}
