// JavaScript Document
function carregarSelect(varNomeASP,varNomeEdit,varResultado){

var tela, rs, array_conteudo;

	//limparFilhosDiv(varResultado);
	document.getElementById(varResultado).value = '';
	tela = document.getElementById(varResultado);	
	if (window.XMLHttpRequest) 		xmlhttp = new XMLHttpRequest();
	else if (window.ActiveXObject)	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	else  {
		window.alert('Seu navegador não aceita AJAX.');
		return false;
	}
	  
	xmlhttp.open("GET","ajax/ajax_cidade.asp?idSelect="+varNomeASP+"&idNome=" + varNomeEdit.options[varNomeEdit.selectedIndex].value,true);
	xmlhttp.onreadystatechange=function()  {
		if (xmlhttp.readyState==4)  {
			if(xmlhttp.status==200)  {
				rs = xmlhttp.responseText;
				var novo_option;
				novo_option = document.createElement("option");     
				novo_option.setAttribute ("selected", "selected");
				novo_option.text = "";     
				//document.forms[0].elements[varResultado].options.add(novo_option);
				
document.getElementById(varResultado).options.add(novo_option);


				//novo_option = document.createElement("option");     
				//novo_option.setAttribute ("value", "0");
				//novo_option.text = "Aguardando...";     
				//document.forms[0].elements[varResultado].options.add(novo_option);
				
				if(rs.toLowerCase()!="error")  {
					array_conteudo = rs.split(";");
					for(i=0;i<array_conteudo.length-1;i++)  {
						pos	= array_conteudo[i].split("#");		
						novo_option = document.createElement("option");     
						novo_option.setAttribute ("value", pos[0]);
						novo_option.text = pos[1];     
						//document.forms[0].elements[varResultado].options.add(novo_option);
							document.getElementById(varResultado).options.add(novo_option);					
}
				}else{
					return false;
				}
			}
		}
	}
	xmlhttp.send(null);	
}

function carregarNome(varNomeASP,varNomeEdit,varResultado)  {
var tela, resultado, array_conteudo;

	limparFilhosDiv(varResultado);
	tela = document.getElementById(varResultado);
	if(document.forms[0].elements[varNomeEdit].value=="")  {
		tela.style.display='none';
		return false;
	}
	if (window.XMLHttpRequest) 		xmlhttp = new XMLHttpRequest();
	else if (window.ActiveXObject)	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	else  {
		window.alert('Seu navegador não aceita AJAX.');
		return false;
	}
	xmlhttp.open("GET","../ajax/ajax_EditBox.asp?idSelect="+varNomeASP+"&idNome=" + document.forms[0].elements[varNomeEdit].value,true);
	xmlhttp.onreadystatechange=function()  {
		if (xmlhttp.readyState==4)  {
			if(xmlhttp.status==200)  {
				resultado = xmlhttp.responseText;
				tela = document.getElementById(varResultado);
				if(resultado.toLowerCase()=="error")  {
					tela.style.display='none';
				}
				else  {
					array_conteudo = resultado.split(";");
					if(array_conteudo=="")
						tela.style.display='none';
					else  {
						for(i=0;i<array_conteudo.length;i++)  {
							novo_div = document.createElement("div");
							novo_div.id = "NovoDiv" + i;
							novo_div.className="linha_off";
							novo_div.innerHTML = array_conteudo[i];
							novo_div.onmouseover=function () { document.getElementById(this.id).className = 'linha_on'; }
							novo_div.onmouseout =function() { document.getElementById(this.id).className = 'linha_off'; }
							novo_div.onclick =function() {
								document.forms[0].elements[varNomeEdit].value = this.innerHTML;
								tela.style.display='none';
							}
							tela.appendChild(novo_div);
						}
						tela.style.display='inline';
					}
				}
			}
			else  {
				retirarTela(varResultado);
			}
		}
	}
	xmlhttp.send(null);
}

function limparFilhosDiv(varResultado)  {
var tamanho, tela;	
	tela = document.getElementById(varResultado);
	tamanho = tela.childNodes.length;
	for(i=0;i<tamanho;i++)
		tela.removeChild(tela.childNodes[0]);
}

function retirarTela(varResultado)  {
	
	tela = document.getElementById(varResultado);
	tela.style.display='none';
}
