// JavaScript Document

favoritos = function (elem, foto, tabela) {
	var caminho =  elem.src.substr(0, elem.src.lastIndexOf("/") + 1);
	var imgs = document.getElementsByTagName("img");
	
	for (x = 0; x < imgs.length; x++) {
		if (imgs[x].id.indexOf("_fav") >= 0)
			imgs[x].src = caminho + "nk.gif";
	}
	var ref = foto.substr(0, foto.indexOf("_"));

	elem.src = caminho + "ok.gif";
	
	resposta = negop.AjaxService.fotoFavorita(ref, foto, tabela);
}

var estado = {
	qualId: function(obj) {
		$find('cidadeAutoComplete').set_contextKey(obj.value);
		
		$get("txtCidade").value = '';
		$get("hidCidade").value = 0;
		$get("txtBairro").value = '';
		$get("hidBairro").value = 0;
	}
}

var cidade = {
	qualId: function(obj) {
		negop.AjaxService.qualIdCidade(obj.value, $get("cboEstado").value,
			cidade.sucesso, cidade.falha);
	},
	
	sucesso: function(arg) {
		$get("txtBairro").value = '';
		$get("hidBairro").value = 0;

		$get('hidCidade').value = arg;
		$find('bairroAutoComplete').set_contextKey(arg);
		
		$get('txtBairro').select();
	},
	
	falha: function(erro) {
		//alert(erro._message);
	}
}

var bairro = {
	qualId: function(obj) {
		negop.AjaxService.qualIdBairro(obj.value, $get("hidCidade").value,
			bairro.sucesso, bairro.falha);
	},
	
	sucesso: function(arg) {
		$get('hidBairro').value = arg;
	},
	
	falha: function(erro) {
		//alert(erro._message);
	}
}


