var store = new Array();

store[0] = new Array(
        'Please Select Your Needs', ''
        );

store[1] = new Array(
        'Please Select', '',
        'Asset Finance', '/assetfinance/index.htm',
        'Buy to Let Mortgages', '/dorfq/lfm_buytoletmortgages/1.htm',
        'Commercial mortgages', '/dorfq/lfm_commercialmortgages/1.htm',
        'Credit Cards', '//content/business_credit_cards/index.htm',
        'Factoring', '/dorfq/factoring/1.htm',
        'Invoice Discounting', '/dorfq/invoicediscounting/1.htm',
        'Trade Finance', '/tradefinance/index.htm'
        );
store[2] = new Array(
        'Please Select', '',
        'Business Insurance', '/insurance/index.htm',
        'Commercial Vehicle', '/dorfq/imp_commercial_vehicle/1.htm',
        'Landlords', '/dorfq/imp_landlords/1.htm',
        'Personal Insurance', 'http://www.insurancewide.co.uk/cms.php?tag1=XB-000',
        'Professional Indemnity', '/dorfq/imp_tradesmen/1.htm'
        );


function populate(formId) {
    if (formId == null || formId == "") return;
    var formName = document.getElementById(formId);
    if (formName != null && formName.yourNeeds != null) {               // check that this form object is a product selector one
        var box = formName.yourNeeds;
        var number = box.selectedIndex;
        var list = store[number];
        var box2 = formName.chooseProduct;
        box2.options.length = 0;
        for (var i = 0; i < list.length; i += 2) {
            box2.options[i / 2] = new Option(list[i], list[i + 1]);
        }
    }
}
function init() {
    for (var i = 0; i < document.forms.length; i++) {
        populate(document.forms[i].id);
    }

}

function onChangeRedirect(formId) {
    var formName = document.getElementById(formId);
    go(formId);
    formName.submit();
}

function go(formId) {
    var formName = document.getElementById(formId);
    var box = formName.chooseProduct;
    var address = box.options[box.selectedIndex].value;
    formName.action = address;
    if (address != '') {
        return true;
    } else if (formName.yourNeeds.selectedIndex != 0) {
        formName.action = box.options[1].value;
        return true;
    }
    else {
        return false;
    }
}
