function searchTypeChange(type){
	if(type == "C"){
		document.getElementById("pesq_cmr").style.display = "block";
		document.getElementById("pesq_nome").style.display = "none";
	} else {
		document.getElementById("pesq_cmr").style.display = "none";
		document.getElementById("pesq_nome").style.display = "block";
	}
}

function minimoSelecionado(){
	var categoria = document.getElementById("categoriaConvenio").value;
	var municipio = document.getElementById("municipio").value;
	if(categoria == "" && municipio == ""){
		alert("Selecione uma categoria e/ou um município");
		return false;
	}

	return true;
}

function getXMLHttpObject(){
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	}
	return xmlhttp;
}

function changeCombo(comboObj, matrix){
	while(comboObj.options.length > 0)
		comboObj.options[0] = null;

	comboObj.options[0] = new Option(" -- Selecione -- ", "");

	if(matrix){
		for(var i = 0; i < matrix.length; i++) {
			var arr = matrix[i];
               comboObj.options[ comboObj.options.length ] = new Option(arr[1], arr[0]);
           }
	}
}

function comboRegioes(municipio){
	var modc = document.getElementById("regiao");
	changeCombo(modc, [["Aguarde", "Aguarde"]]);

	try{
		var aj = getXMLHttpObject();

		aj.open("GET", "regioes.jsp?municipio=" + municipio);
		aj.onreadystatechange=function() {
			if (aj.readyState == 4) {
				var modc = document.getElementById("regiao");
				var matrix = eval((aj.responseText));
				changeCombo(modc, matrix);
			}
		}

		aj.send(null);
	} catch(err) {
		if(err.description){
			alert("ERRO: " + err.description);
		} else {
			alert("ERRO: " + err);
		}
	}
}

function orderBy(order){
	var form = document.getElementById("convForm");
	var asc = true;
	if(form.order.value = order && form.ascending.value == "true"){
		asc = false;
	}

	form.ascending.value = asc;
	form.order.value = order;
	form.submit();

}