function getForm(formName) {
    // Test if is IE or Netscape (document.layers)
    if(document.all)
        return eval(formName);
    else
        return document.forms[formName];
}

function submitPos(pos) {
    var searchForm = getForm("empreendFRM");

    searchForm.pos.value = pos;
    searchForm.submit();
}

function populateSelectWithNM(updateSelect, arrVal, arrTxt, strSelec) {
    for(var i = updateSelect.options.length; i >= 0; i--)
        updateSelect.options[i] = null;

    var optElem = document.createElement("option");
    optElem.value = -1;
    optElem.text = strSelec;
    updateSelect.options[0] = optElem;

    if(arrTxt != null && arrVal != null) {
        for(var i = 0; i < arrTxt.length; i++) {
            var optElem = document.createElement("option");
            optElem.value = arrVal[i];
            optElem.text = arrTxt[i];
            updateSelect.options[i + 1] = optElem;
        }
    }
}

function OnChangeSelectLocal() {
    var empreendForm = getForm("empreendFRM");

    if(empreendForm.distrito_id.options[empreendForm.distrito_id.selectedIndex].value == -1) {
        populateSelectWithNM(document.getElementsByName("empreend_id")[0], new Array(), new Array(), ":: Empreendimento");
    }
    else {
        var head    = document.getElementsByTagName("head").item(0);
        var old     = document.getElementById("lastLoadedEmpreendimentos");
        if(old)
            head.removeChild(old);

        script = document.createElement("script");
        script.src = "/js/empreendimentos/" + empreendForm.distrito_id.options[empreendForm.distrito_id.selectedIndex].value+ ".js";
        script.type = "text/javascript";
        script.defer = true;
        script.id = "lastLoadedEmpreendimentos";
        void(head.appendChild(script));
    }
}

function OnChangeSelectEmp(){
	var box2 = document.empreendFRM.empreend_id;
	destination2 = box2.options[box2.selectedIndex].value;
	if (destination2) window.open("/servlet/Empreendimentos?id="+destination2,"Empreendimentos"); 
}




