var themakes = new Array('Select Make','ANY MAKE','HYUNDAI');

var themodels = new Array();
themodels[0] = new Array('Select Model','ANY MODEL');
themodels[1] = new Array('Select Model','ANY MODEL');
themodels[2] = new Array('ANY MODEL','i10','i20','AMICA','ACCENT','i30','i30 ESTATE','ATOZ','COUPE','COUPE SIII','ELANTRA','GETZ','i-30','MATRIX','S COUPE','SANTA FE','SONATA','TERRACAN','TRAJET','TUCSON','GRANDEUR');

function getMakes(rmake) {
    var dropDown = document.getElementById("make");
    selectedIndex = 0;

    if (dropDown) {
        dropDown.length = 0;
        for (i = 0; i < themakes.length; i++) {
            dropDown[i] = new Option(themakes[i], themakes[i]);

            if (themakes[i] == "ANY MAKE") {
                dropDown[i] = new Option(themakes[i], "");
            }

            if (themakes[i].toUpperCase() == rmake){
                selectedIndex = i;
            }
        }
        dropDown.options[selectedIndex].selected = true;
    }
    selectMake(rmake);
}

function getModels(makeindex, reqmodel) {
    var dropDown = document.getElementById("model");
    selectedIndex = 0;

    if (dropDown) {
        var tmods = themodels[makeindex];
        //alert(tmods);
        dropDown.length = 0;
        for (i = 0; i < tmods.length; i++) {
            dropDown[i] = new Option(tmods[i], tmods[i]);

            if (tmods[i] == "ANY MODEL") {
                dropDown[i] = new Option(tmods[i], "");
            }

            if (tmods[i].toUpperCase() == reqmodel) {
                selectedIndex = i;
            } else if (tmods[i].toUpperCase() == "ANY MODEL" && reqmodel == "") {
                selectedIndex = i;
            }
        }
        dropDown.options[selectedIndex].selected = true;
    }
}

function selectMake(rmake)  {
    var dropDown = document.getElementById("make");
    if (dropDown) {
        for (x = 0; x < dropDown.length; x++) {
            var mk = dropDown.options[x].value;
            if (mk.toUpperCase() == rmake) {
                if (dropDown.options[x].selected == false) {
                    dropDown.options[x].selected = true;
                }
            }
        }
    }
}

function validateSearch(f) {
    if (f.make.value == "Select Make") {
        alert('Please select a make');
        f.make.focus();
        return false;
    } else if (f.model.value == "Select Model") {
        alert('Please select a model');
        f.model.focus();
        return false;
    }
    f.submit.disabled=true;
    return true;
}

function swapImage(target, imgsrc) {
    document.getElementById(target).src = imgsrc;
}

function showSummary(id) {
    if (document.getElementById("summary-" + id)) {
        var ele = document.getElementById("summary-" + id);
        var plus = document.getElementById("plus-" + id);
        var minus = document.getElementById("minus-" + id);
        if (ele.style.display == "none") {
            ele.style.display = "";
            plus.style.display = "none";
            minus.style.display = "";
        } else {
            ele.style.display = "none";
            plus.style.display = "";
            minus.style.display = "none";
        }
    }
}

function selectValue(id, value)  {
    var dropDown = document.getElementById(id);
    if (dropDown) {
        for (x = 0; x < dropDown.length; x++) {
            var val = dropDown.options[x].value;
            if (val == value) {
                dropDown.options[x].selected = true;
            }
        }
    }
}