var iframes = new Array(10);
var point = 0;

function existeIframe(nome_iframe){
	for(x=0;x<point;x++){
		if (iframes[x]==nome_iframe) {
			return true;
		}
	}
	return false;
}

function pesquisaCombo( acao_sql, param, frm, destino, ifrm ){
	if ( param == "" ){
		//alert("Selecione um valor para buscar.");
		return false;
	}else{
		if ( getGrupo(window.location.pathname)=="rel" ){
			var url = "../../lib/php/pesquisa_combo.php?acaosql=" + acao_sql + "&parametro=" + param + "&form=" + frm + "&destino=" + destino;
			
		}else{
			var url = "../../lib/php/pesquisa_combo.php?acaosql=" + acao_sql + "&parametro=" + param + "&form=" + frm + "&destino=" + destino;
//			alert(url);
		}
		if (point == 0) {
			iframes[point] = ifrm;
			//Descomentando esta linha comentando a debaixo, aparecerá um iframe na tela onde esta chamando a função
//			document.getElementById("dinamicvalues").innerHTML = "<iframe id=\"" + iframes[point] + "\" src=\"" + url + "\" width=\"800\" height=\"200\"style=\"\"></iframe>";
			document.getElementById("dinamicvalues").innerHTML = "<iframe id=\"" + iframes[point] + "\" src=\"" + url + "\" width=\"200\" height=\"200\"style=\"position: absolute;visibility: hidden; \" ></iframe>";
			point++;
		}else{
			if ( existeIframe( ifrm ) ) {
				document.getElementById(ifrm).src = url;
			}else{
				iframes[point] = ifrm;
				//Descomentando esta linha comentando a debaixo, aparecerá um iframe na tela onde esta chamando a função
//				document.getElementById("dinamicvalues").innerHTML = document.getElementById("dinamicvalues").innerHTML + "<iframe id=\"" + iframes[point] + "\" src=\"" + url + "\" width=\"800\" height=\"200\" style=\"\" ></iframe>";
				document.getElementById("dinamicvalues").innerHTML = document.getElementById("dinamicvalues").innerHTML + "<iframe id=\"" + iframes[point] + "\" src=\"" + url + "\" width=\"200\" height=\"200\" style=\"position: absolute;visibility: hidden; \" ></iframe>";
				point++;
			}
		}
	}
}

function InsereElemento(dest,val,txt){
	proximo = dest.length;
	valor = val;
	texto = txt;
	var novoitem = new Option(texto,valor);
	eval('dest.options[proximo]=novoitem');
	val.value = '';
}

function resetCombo( destino ){
	destino.length = 1;
	destino.options[0].text = "AGUARDE...";
	destino.selectedIndex = 0;
	destino.focus();
}

function doneCombo(destino){
	destino.options[0].text = ".:: Selecione ::.";
	destino.selectedIndex = 0;
	destino.focus();
}

function pesquisaValor(acao_sql, param, frm, destino, ifrm ){
	if (param=="") {
		alert("Informe um valor para buscar.");
		return false;
	}else{

		var url = "../lib/pesquisa_valor.asp?acaosql=" + acao_sql + "&parametro=" + param + "&form=" + frm + "&campos=" + destino;

		if (point == 0) {
			iframes[point] = ifrm;
			//document.getElementById("dinamicvalues").innerHTML = "<iframe id=\"" + iframes[point] + "\" src=\"" + url + "\" width=\"200\" height=\"200\" style=\"position: absolute;\" ></iframe>";
			document.getElementById("dinamicvalues").innerHTML = "<iframe id=\"" + iframes[point] + "\" src=\"" + url + "\" width=\"200\" height=\"200\" style=\"position: absolute;visibility: hidden;\" ></iframe>";
			point++;
		}else{
			if (existeIframe(ifrm)) {
				document.getElementById(ifrm).src=url;
			}else{
				iframes[point] = ifrm;
				//document.getElementById("dinamicvalues").innerHTML = document.getElementById("dinamicvalues").innerHTML + "<iframe id=\"" + iframes[point] + "\" src=\"" + url + "\" width=\"200\" height=\"200\" style=\"position: absolute;\"></iframe>";
				document.getElementById("dinamicvalues").innerHTML = document.getElementById("dinamicvalues").innerHTML + "<iframe id=\"" + iframes[point] + "\" src=\"" + url + "\" width=\"200\" height=\"200\" style=\"position: absolute;visibility: hidden;\"></iframe>";
				point++;
			}
		}
	}
}

function InsereValor( dest, val ){
	dest.value = val;
}

function alerta(msg){
	alert(msg);
}

function getGrupo(destino){
	var teste;
	var x,y;
	teste = destino;
	x = teste.split("/");
	y = x[x.length-2];
	return y;
}

