
function loadPhoneFilter() {
	doGet('index?cmd=phonelist','manufacturerListHandle');
}

function manufacturerListHandle(responseText) {
	
	// cria o objeto a partir do json
	var phonelist = eval('(' + responseText + ')');
	
	// lista de fabricantes
	var manufacturers = phonelist.manufacturers;
	
	for (j = 0; j < document.forms.length; j++) {
		var select = document.forms[j].manufacturer;
		if (select != null) {
			select.options.length = 1;
			
			// percorre as pastas
			for (i = 0; i < manufacturers.length; i++) {
				
				// cria um novo option
				var option = document.createElement("option");
				select.options.add(option);
				option.text = manufacturers[i].manufacturer;
				option.value = manufacturers[i].manufacturer;
				if (manufacturers[i].manufacturer == paramManufacturer) {
					option.selected = true;
					doGet('index?cmd=phonelist&manufacturer=' + escape(sessionManufacturer),'modelListHandle');
				} else if (manufacturers[i].manufacturer == sessionManufacturer) {
					option.selected = true;
					doGet('index?cmd=phonelist&manufacturer=' + escape(sessionManufacturer),'modelListHandle');
				}		
			}
		}
	}
}

function changeManufacturer(select) {
	
	var manufacturer = select[select.selectedIndex].value;
	
	doGet('index?cmd=phonelist&manufacturer=' + escape(manufacturer),'modelListHandle');
}

function modelListHandle(responseText) {

	// cria o objeto a partir do json
	var phonelist = eval('(' + responseText + ')');
	
	// lista de modelos
	var models = phonelist.models;
	
	for (j = 0; j < document.forms.length; j++) {
		
		var select = document.forms[j].model;
		if (select != null) {
			select.options.length = 1;
		
			// percorre as pastas
			for (i = 0; i < models.length; i++) {
				// cria um novo option
				var option = document.createElement("option");
				select.options.add(option);
				option.text = models[i].model;
				option.value = models[i].userAgent;
				if (models[i].model == paramModel) {
					option.selected = true;
				} else if (models[i].model == sessionModel) {
					option.selected = true;
				}
			}
		}
	}
	if (document.getElementById('btSeeAll') != null) {
		if ((sessionModel == null) || (sessionModel == "")) {
			document.getElementById('btSeeAll').style.display = 'none';
		} else {
			document.getElementById('btSeeAll').style.display = '';
		}
	}
}

function setUserDevice() {

	var maselect = document.formPhoneSelect.manufacturer;
	var manufacturer = maselect[maselect.selectedIndex].value;
	
	var moselect = document.formPhoneSelect.model;
	var model = moselect[moselect.selectedIndex].text;
	var useragent = moselect[moselect.selectedIndex].value;
	
	doGet('index?cmd=phonefilter&manufacturer=' + escape(manufacturer) + '&model=' + escape(model) + '&useragent=' + escape(useragent),'setUserDeviceHandle');
}

function clearUserDevice() {
	doGet('index?cmd=phonefilter','setUserDeviceHandle');
}

function setUserDeviceHandle(responseText) {
	// cria o objeto a partir do json
	var result = eval('(' + responseText + ')');
	
	if (result.errorMsg == null) {
		document.location.reload();
	}
}