function PartnerSearch_onLoad() {
    var submit = document.getElementById( "adsk91-submit" );
    if( submit ) {
        var value = core_getCookie( "ADSKVISCNTRY" );
        if( value ) {
            var id = g_ci[value];
            if( id ) {
                var form = submit.form;
                if( form.country && form.country.type.indexOf("select") > -1 ) {
                    core_setSelectedOptionValue( form.country, id.toString() );
                    if( form.country.selectedIndex == -1 ) {
                        form.country.selectedIndex = 0;
                    }
                }
            }
        }
    }
    PartnerSearch_updateCountryStates();
    PartnerSearch_updateSubmit();
}

function PartnerSearch_updateSubmit( bEnabled ) {
    // set state of form submit button based on value of 'bEnabled'
    // if bEnabled == null, disable submit button unless all required fields are popluated
    var bDisable = ( bEnabled != null ? ! bEnabled : ! PartnerSearch_checkReqdFields() );
    var submit = document.getElementById( "adsk91-submit" );
    submit.disabled = bDisable;
    submit.className = (submit.disabled ? "btn_submit_disabled" : "btn_submit" );
}

function PartnerSearch_processSubmit() {
    // return true only if all required fields are popluated; otherwise return false
    if ( ! PartnerSearch_checkReqdFields() ) return false;
    // disable submit button to prevent multiple submittals
    PartnerSearch_updateSubmit( false );
    return true;
}

function PartnerSearch_checkReqdFields() {
    // return true only if all required fields are popluated; otherwise return false
    var bPopluated = true;
    var submit = document.getElementById( "adsk91-submit" );
    if( submit ) {
        var form = submit.form;
        if ( form ) {
            for (var i=0; i<g_fields.length; i++) {
                if ( 1 == Number(g_fields[i][1]) ) {
                    var fieldName = g_fields[i][0];
                    if ( fieldName && form[fieldName] && ! form[fieldName].disabled ) {
                        if ( form[fieldName].type.indexOf("select") > -1 ) {
                            if ( form[fieldName].selectedIndex == 0 ) bPopluated = false;
                        } else {
                            var val = form[fieldName].value;
                            if ( val == null || core_trimString(val) == "" ) bPopluated = false;
                        }
                    }
                }
            }
        }
    }
    return bPopluated;
}

function PartnerSearch_updateCountryStates() {
    var submit = document.getElementById( "adsk91-submit" );
    if ( ! submit ) return;
    var form = submit.form;
    if ( ! form ) return;
    var objCountry = form["country"];
    var objState = form["state"];
    if ( ! objCountry || ! objState ) return;
    var countryID = null;
    if ( objCountry.type.indexOf("select") > -1 ) {
        if ( objCountry.selectedIndex == null || objCountry.selectedIndex < 0 ) {
            PartnerSearch_disableObject(objState);
            return;
        }
        countryID = objCountry.options[objCountry.selectedIndex].value;
    } else {
        countryID = objCountry.value;
    }
    if ( countryID == null || countryID == "" ) {
        PartnerSearch_disableObject(objState);
        return;
    }

    PartnerSearch_updateStatesSelector(countryID, objState);
}

function PartnerSearch_updateStatesSelector(countryID, objStates) {
    objStates.options.length = 1;

    if ( g_csAry == null ) return;
    for (var i=0; i<g_csAry.length; i++) {
        if ( countryID == g_csAry[i][0] ) {
            objStates.options[objStates.length] = new Option(g_csAry[i][1], g_csAry[i][2]);
        }
    }
    if ( objStates.options.length > 1 ) {
        objStates.disabled = false;
    } else {
        objStates.disabled = true;
    }
}

function PartnerSearch_disableObject(obj) {
    if ( obj != null ) obj.disabled = true;
}

function PartnerSearch_enableObject(obj) {
    if ( obj != null ) obj.disabled = false;
}

