﻿// © Rögg Corporation - All rights reserved

function searchCarsF1Changed(pathPrefix, mid, indicatorName, resultsto) {

	var updatingIndicator = document.getElementById(indicatorName);

    updatingIndicator.style.display = '';
    Sys.Net.WebServiceProxy.invoke(pathPrefix + 'Functions.aspx', 'GetModelsFromMake', false, { mid: mid, rto: resultsto }, onSearchCarsF1ChangedSucceeded, onSearchCarsF1ChangedFailed, indicatorName);
}

function searchCarsF1ChangedXlat(pathPrefix, mid, indicatorName, resultsto, txtall, txtunk) {

	var updatingIndicator = document.getElementById(indicatorName);

	updatingIndicator.style.display = '';

	Sys.Net.WebServiceProxy.invoke(pathPrefix + 'Functions.aspx', 'GetModelsFromMakeXlat', false, {  mid: mid, rto: resultsto, all: txtall, unk: txtunk }, onSearchCarsF1ChangedSucceeded, onSearchCarsF1ChangedFailed, indicatorName);
}

function removeAllOptions(selectbox) {

    var i;
    
    for (i = selectbox.options.length - 1; i >= 0; i--) {
        selectbox.remove(i);
    }
}

function addOption(selectbox, value, text) {

    var optn = document.createElement("OPTION");
    
    optn.text = text;
    optn.value = value;
    
/*    if (value == "Accord") {
        optn.setAttribute("selected", "selected");
    }*/
    
    selectbox.options.add(optn);
}


function onSearchCarsF1ChangedSucceeded(result, userContext, methodName) {

    var updatingIndicator = document.getElementById(userContext);

    var currentIndex = 1;
    var models = new Array();

    models = result;
    
    var comboBox = document.getElementById(models[0]);

    removeAllOptions(comboBox);

    while (currentIndex < models.length) {

        addOption(comboBox, models[currentIndex], models[currentIndex + 1]);

        currentIndex += 2;
    }

    /* Use this to auto-select if only two items are returned from the called function (~ Veldu framleiðanda and Óþekktur framleiðandi for instance)
    if (5 == models.length) {
		comboBox.value = "0";
    }*/
    updatingIndicator.style.display = 'none';
}

function onSearchCarsF1ChangedFailed(error, userContext, methodName) {

    var updatingIndicator = document.getElementById(userContext);

    updatingIndicator.style.display = 'none';
}

