
function Modelos() {
	
	this.carregar = function(id) {
		if (id == '')
			return;
		$('edtModelo').length = 0;
		option = document.createElement('option');
		option.appendChild(document.createTextNode('Carregando...'));
		$('edtModelo').appendChild(option);
		
		ajax = new sack('../xml/assistencia-tecnica-modelos/'+id);
		ajax.setVar('id',id);
		ajax.onCompletion = modelos.mostrar;
		ajax.method = "POST";
		ajax.runAJAX();
	}
	
	this.mostrar = function() {
		$('edtModelo').childNodes[0].innerHTML = 'Selecione um modelo..';
		obj = ajax.responseXML;
		campos = obj.getElementsByTagName('modelo');
		
		for (var i=0;i<campos.length;i++) {
			var id       = campos[i].getElementsByTagName('id')[0].firstChild.nodeValue;
			var nome     = campos[i].getElementsByTagName('nome')[0].firstChild.nodeValue;
			
			option = document.createElement('option');
			option.appendChild(document.createTextNode(nome));
			option.value = id;
			$('edtModelo').appendChild(option);
		}
		
	}
}

modelos = new Modelos;


function validacaoAssistencia() {
	if ($('edtProduto').selectedIndex == 0) {
		alert('Selecione um produto.');
		$('edtProduto').focus();
		return false;
	}
	if ($('edtEmpresa').value.length == 0) {
		alert('Digita a empresa.');
		$('edtEmpresa').focus();
		return false;
	}
	if ($('edtEmpresaContato').value.length == 0) {
		alert('Digite o contato.');
		$('edtEmpresaContato').focus();
		return false;
	}
	if ($('edtEndereco').value.length == 0) {
		alert('Digite seu endereço.');
		$('edtEndereco').focus();
		return false;
	}
	if ($('edtTelefone').value.length == 0) {
		alert('Digite seu telefone.');
		$('edtTelefone').focus();
		return false;
	}
	if (!validacaoEmail($('edtEmail').value)) {
		alert('Digite um email válido.');
		$('edtEmail').focus();
		return false;
	}
	if ($('edtMensagem').value.length == 0) {
		alert('Digite sua mensagem.');
		$('edtMensagem').focus();
		return false;
	}
}
