﻿function $obj(id) {
    return document.getElementById(id);
}
function CarregaCidade2(key, obj) {
    if (obj != null) {
        PageMethods.CarregaCidade2(key, OnSucceededCUF2, OnFailedCUF2, obj);
    }
    else {
        PageMethods.CarregaCidade2(key, OnSucceededCUF2, OnFailedCUF2, 'ddlCidade'+PF);
    }
}

function OnSucceededCUF2(result, userContext, methodName) {
    if (methodName == "CarregaCidade2") {
        while ($obj(userContext).length > 0) {
            $obj(userContext).remove(0);
        }
        for (cc = 0; cc < result.length; cc++) {
            opt = document.createElement("OPTION")
            opt.value = result[cc];
            opt.text = result[cc];
            if (result[cc] == $obj('hfCidade'+PF).value) {
                opt.selected = true;
            }
            $obj(userContext).options.add(opt);
        }
        try {
            $obj('hfCidade').value = $obj('ddlCidade').value;
        } catch (e) { }
        if ($obj('addlCidade' + PF)) {
            if ($obj('ddlUF' + PF).value == 'EX') {
                $obj('addlCidade' + PF).style.visibility = 'visible';
                $obj('addlCidade' + PF).style.display = 'block';

                $obj('ddlCidade' + PF).style.visibility = 'hidden';
                $obj('ddlCidade' + PF).style.display = 'none';
            } else {
            $obj('addlCidade' + PF).style.visibility = 'hidden';
            $obj('addlCidade' + PF).style.display = 'none';
            $obj('addlCidade' + PF).value = '';

            $obj('ddlCidade' + PF).style.visibility = 'visible';
            $obj('ddlCidade' + PF).style.display = 'block';
            }
        }
    }
}

function OnFailedCUF2(error, userContext, methodName) {
    if (methodName == "CarregaCidade2") {
        alert(error.get_message());
    }
}

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

var PF = 'Contato';
function CIDADE2() {
    CarregaCidade2($obj('ddlUF' + PF).value, 'ddlCidadeContato');
}

function pageLoad() {
    window.setTimeout("CIDADE2();", 1000);
}

//window.onload = function() {
//    CarregaCidade($obj('ddlUF').value, 'ddlCidade');
//};