function busca_sequencia(estado) {
	uf = estado.value;
	if(uf=='*') {
		busca_todos_uf();
	} else {
		nome = estado.options[estado.selectedIndex].text;
		document.getElementById('tab_seq').caption.innerHTML = "Seqüências de Placas do Estado: <br />"+nome;
		url = "uf="+uf;
		//window.alert(url);
		startHttpReq("/include/busca_sequencia.php",url,"XMLHttpRequestChangeSequencia");
	}
}

function busca_todos_uf() {
	url = "uf="+'*';
	document.getElementById('tab_seq').caption.innerHTML = "Seqüências de Placas de Todos os Estados Brasileiros";
	startHttpReq("/include/busca_sequencia.php",url,"XMLHttpRequestChangeSequencia");	
}

function busca_uf(placa) {
	var re = new RegExp(/^[a-zA-Z]+\d{4}$/);
	//alert(placa);
	//alert(placa.search(/0000$/ig)+1);
	if ((!(placa.search(/0000$/ig)+1))&&((re.exec(placa))!= null)) {
		url = "placa="+placa;
		//window.alert(url);
		placa = placa.toUpperCase();
		document.getElementById('tab_seq').caption.innerHTML = "Estado de origem da placa "+placa;
		startHttpReq("/include/busca_sequencia.php",url,"XMLHttpRequestChangeSequencia");
	} else {
		window.alert('Placa Inválida!');
	}
}

function XMLHttpRequestChangeSequencia() { //Controla as mudanças do objeto XMLHttpRequest.
	/*alert(xmlhttp.readyState);
	if (xmlhttp.readyState == 4) {
		alert(xmlhttp.status);
	}*/
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200){  //Verifica se o arquivo foi carregado com sucesso.
        //alert(xmlhttp.responseText);
        var result = xmlhttp.responseText; //Armazena a resposta XML.
       	//document.getElementById('seq_placas').innerHTML = result;
		tableJSON(result);
    }
}

function tableJSON(v_JSON) {
	var tabJSON = document.getElementById('seq_placas');
	while (tabJSON.rows.length>0) //deletes all rows of a table
		tabJSON.deleteRow(0)
	//alert(v_JSON);
	var v_JSON = eval(v_JSON);
	//alert(v_JSON);
	var v_row = null;
	var cell = null;
	var tabela = "";
	for (x=0;x<v_JSON.length;x++) {
		v_row = tabJSON.insertRow(-1);
		for (y=0;y<v_JSON[x].length;y++) {
			cell = v_row.insertCell(-1);
			if (y == 2) {
				cell.setAttribute("class","uf");
			}
			cell.appendChild(document.createTextNode(v_JSON[x][y]));
		}
	}
}

