﻿// JScript File
Event.observe(window, 'load', function () {
    $('year').selectedIndex = 0;
    $('make').selectedIndex = 0;
    $('model').selectedIndex = 0;
});
function getMakes() {
    var year = $('year').value;//this.options[this.selectedIndex].value;
    if(year != 'Select Year') {
        new Ajax.Request("makes.aspx?year="+year, {
	            method: 'get',
	            onSuccess: function(transport) {
    	        
	                var select = $('make');
                   
                    // clear previous data
                    select.options.length = 1;
                     
                    //alert(transport.responseText);
                    var makes = transport.responseText.split("~~");
                    for(var i=0; i<makes.length; i++) {
                        if(makes[i] != '' || makes[i] != ' ' || makes[i] != null) {
                            var option = document.createElement('option');
                            //alert(window.parent.location.pathname);
                            if(window.parent.location.pathname == '/ford/default.aspx' || window.parent.location.pathname == '/ford/') {
                                if(makes[i] == 'Ford' || makes[i] == 'Lincoln' || makes[i] == 'Mercury') {
                                    option.text = makes[i];
                                    option.value = makes[i];
                                    
                                    try
                                    {
                                        select.add(option,null); // standards compliant
                                    }
                                    catch(ex)
                                    {
                                        select.add(option); // IE only
                                    }
                                }
                            } 
                            if(window.parent.location.pathname == '/honda/default.aspx' || window.parent.location.pathname == '/honda/') {
                                if(makes[i] == 'Honda') {
                                    option.text = makes[i];
                                    option.value = makes[i];
                                    
                                    try
                                    {
                                        select.add(option,null); // standards compliant
                                    }
                                    catch(ex)
                                    {
                                        select.add(option); // IE only
                                    }
                                }
                            } 
                            if(window.parent.location.pathname == '/chrysler/default.aspx' || window.parent.location.pathname == '/chrysler/') {
                                if(makes[i] == 'Chrysler' || makes[i] == 'Dodge' || makes[i] == 'Jeep' || makes[i] == 'Ram') {
                                    option.text = makes[i];
                                    option.value = makes[i];
                                    
                                    try
                                    {
                                        select.add(option,null); // standards compliant
                                    }
                                    catch(ex)
                                    {
                                        select.add(option); // IE only
                                    }
                                }
                            } 
                            if(window.parent.location.pathname == '' || window.parent.location.pathname == '/default.aspx' || window.parent.location.pathname == '/brochures/requestabrochure.aspx' || window.parent.location.pathname == '/vehicles.aspx') {
                                option.text = makes[i];
                                option.value = makes[i];
                                
                                try
                                {
                                    select.add(option,null); // standards compliant
                                }
                                catch(ex)
                                {
                                    select.add(option); // IE only
                                }
                            }
                        }
                    }
    	            
                }/*,
                onFailure: function(transport) {
                    alert(transport.responseText);
                }*/
        });
    } else {
        $('make').selectedIndex = 0;
        $('model').selectedIndex = 0;
    }
}


