/*
getCidade - busca cidades com base no estado | objeto select estado - id do objeto select cidade
getCidadeR - retorno getCidade
*/
function getCidade(getCidadeEstado,getCidadeId){
	var $estado = getCidadeEstado;
	if($estado=='-1'||$estado==''){
		return null;
	}else{
		getCidadeObj = $$(getCidadeId);
		getCidadeObj.setAttribute('disabled','disabled');
		while(getCidadeObj.hasChildNodes()){
			getCidadeObj.removeChild(getCidadeObj[0]);
		}
		var $dom = new Dom();
		var $loading = $dom.obj('option');
		$loading.value = '-1';
		var $textLoading = $dom.text('Carregando . . .');
		$loading.appendChild($textLoading);
		getCidadeObj.appendChild($loading);
		
		getCidadeAjax = ajaxRequest();
		ajaxCon(getCidadeAjax,getCidadeR,ROOT_HTTP+'atributos/ajax/getCidade.php','codEstado='+$estado,'get');
	}
}
function getCidadeR(){
	var $dom = new Dom();
	if(getCidadeAjax.readyState==4){
		if(getCidadeAjax.status==200){
			var $docxml = getCidadeAjax.responseXML;
			if($docxml.hasChildNodes()){
				while(getCidadeObj.hasChildNodes()){
					getCidadeObj.removeChild(getCidadeObj[0]);
				}
				var $cidades = $$$($docxml,'cidade');
				for(var $i=0;$i<$cidades.length;$i++){
					var $node = $cidades[$i];
					$option = $dom.obj('option');
					$option.value = $node.getAttribute('value');
					$optionText = $dom.text($node.childNodes[0].nodeValue);
					$option.appendChild($optionText);
					getCidadeObj.appendChild($option);
				}
				getCidadeObj.removeAttribute('disabled');
				getCidadeObj.focus();
			}else{
				while(getCidadeObj.hasChildNodes()){
					getCidadeObj.removeChild(getCidadeObj[0]);
				}
				var $error = $dom.obj('option');
				$error.value = '-1';
				var $textLoading = $dom.text('Erro ao listar cidades.');
				$error.appendChild($textLoading);
				getCidadeObj.appendChild($error);
			}
		}else{
			while(getCidadeObj.hasChildNodes()){
				getCidadeObj.removeChild(getCidadeObj[0]);
			}
			var $error = $dom.obj('option');
			$error.value = '-1';
			var $textLoading = $dom.text('Página nao encontrada, contate o adminstrador para mais informaçoes.');
			$error.appendChild($textLoading);
			getCidadeObj.appendChild($error);
		}
	}
}
