﻿function $obj(id) {
    return document.getElementById(id);
}
function Contatos(key) {
        PageMethods.Contatos(key, OnSucceeded, OnFailed);
}

function OnSucceeded(result, userContext, methodName) {
    if (methodName == "Contatos") {
        while ($obj('ddlSetor').length > 0) {
            $obj('ddlSetor').remove(0);
        }
        for (cc = 0; cc < result.length; cc++) {
            opt = document.createElement("OPTION")
            opt.value = result[cc].Valor;
            opt.text = result[cc].Texto;
            if (result[cc] == $obj('hfSetor').value) {
                opt.selected = true;
            }
            $obj('ddlSetor').options.add(opt);
        }
        try {
            $obj('hfSetor').value = $obj('ddlSetor').value;
            $obj('hfSetorNome').value = $obj('ddlSetor').options[$obj('ddlSetor').selectedIndex].text;
        } catch (e) { }
    }
}

function OnFailed(error, userContext, methodName) {
    if (methodName == "Contatos") {
        $obj('rbTC2').checked = true;
        alert(error.get_message());
    }
}

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

function pageLoad() {
    if ($obj('rbTC1').checked)
        Contatos(1);
    else if ($obj('rbTC2').checked)
        Contatos(2);
}
