// JavaScript Document
var ajax;

function IniciaAjax(){
	var ajax;
	if(window.XMLHttpRequest){	  // Mozilla, Safari,...
		ajax = new XMLHttpRequest();
	} else if (window.ActiveXObject){	// IE
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
		if (!ajax) {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}
    } 
	else {
        alert("Seu navegador não possui suporte a essa aplicação!");
	}
	return ajax;
}
function papel()
{
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					document.getElementById("resultado").value += ajax.responseText;
				} else {
					alert(ajax.statusText);
				}
			}
		}
		
		material = document.getElementById("material").value;
		dimensao = document.getElementById("dimensao").value;
		tubet = document.getElementById("tubet").value;
		marca = document.getElementById("marca").value;
		outra = document.getElementById("marca_outra").value;
		modelo = document.getElementById("modelo").value;
		quantidade = document.getElementById("quantidade").value;
		dados = "material="+material+"&dimensao="+dimensao+"&tubet="+tubet+"&marca="+marca+"&outra="+outra+"&modelo="+modelo+"&quantidade="+quantidade;
	
		ajax.open('POST', 'processa_papel.asp', true);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		ajax.send(dados);
	}
}
function aluminio()
{
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					document.getElementById("resultado").value += ajax.responseText;
				} else {
					alert(ajax.statusText);
				}
			}
		}
		
		material = document.getElementById("material").value;
		material_outro = document.getElementById("material_outro").value;
		dimensao = document.getElementById("dimensao").value;
		dimensao_outro = document.getElementById("dimensao_outro").value;
		aluminio_adesivo = document.getElementById("aluminio_adesivo").value;
		aluminio_furos = document.getElementById("aluminio_furos").value;
		quantidade = document.getElementById("quantidade").value;
		if(material == "outro"){
			material = "Outro:&nbsp;";
		}
		if(dimensao == "outro"){
			dimensao = "Outro:&nbsp;";
		}
		dados = "material="+material+material_outro+"&dimensao="+dimensao+dimensao_outro+"&aluminio_adesivo="+aluminio_adesivo+"&aluminio_furos="+aluminio_furos+"&quantidade="+quantidade;
	
		ajax.open('POST', 'processa_aluminio.asp', true);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		ajax.send(dados);
	}
}

function Processa3()
{
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					document.getElementById("resultado").value += ajax.responseText;
				} else {
					alert(ajax.statusText);
				}
			}
		}
		
		material = document.getElementById("material").value;
		material_outro = document.getElementById("material_outro").value;
		dimensao = document.getElementById("dimensao").value;
		dimensao_outro = document.getElementById("dimensao_outro").value;
		aluminio_adesivo = document.getElementById("aluminio_adesivo").value;
		aluminio_furos = document.getElementById("aluminio_furos").value;
		quantidade = document.getElementById("quantidade").value;
		dados = "material="+material+material_outro+"&dimensao="+dimensao+dimensao_outro+"&aluminio_adesivo="+aluminio_adesivo+"&aluminio_furos="+aluminio_furos+"&quantidade="+quantidade;
	
		ajax.open('POST', 'processa_aluminio.asp', true);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		ajax.send(dados);
	}
}
function ribbons(){
	ajax = IniciaAjax();
	if(ajax)
	{
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					document.getElementById("resultado").value += ajax.responseText;
				} else {
					alert(ajax.statusText);
				}
			}
		}
		
		material = document.getElementById("material").value;
		dimensao = document.getElementById("dimensao").value;
		sentido = document.getElementById("sentido").value;
		quantidade = document.getElementById("quantidade").value;
		marca = document.getElementById("marca").value;
		outra = document.getElementById("marca_outra").value;
		modelo = document.getElementById("modelo").value;
		dados = "material="+material+"&dimensao="+dimensao+"&marca="+marca+"&outra="+outra+"&modelo="+modelo+"&sentido="+sentido+"&quantidade="+quantidade;
	
		ajax.open('POST', 'processa_ribbons.asp', true);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		ajax.send(dados);
	}
}
// Função para mostrar OUTROS em opções de formulários
function mostrar(id){
	valor = document.getElementById(id).value;
	
		if (valor =="outro"){
		document.getElementById("outro"+id).style.display= "block"; 
		}
		else{
		document.getElementById("outro"+id).style.display="none";
		}
}

//Validação do formulário
function validar(){
	erro = "";
	if(document.getElementById("resultado").value == ""){erro = "Descreva seu pedido\n";}
	if(document.getElementById("empresa").value == ""){erro += "Digite um nome de Empresa\n";}
	if(document.getElementById("contato").value == ""){erro += "Digite um nome de contato\n";}
	if(document.getElementById("cep").value == ""){erro += "Digite um CEP\n";}
	if(document.getElementById("telefone").value == ""){erro += "Informe seu telefone com DDD\n";}
	if(document.getElementById("email").value == ""){erro += "Escreva seu e-mail\n";}
	
	if(erro != ""){
		alert(erro);
		return false;
	} else {
		formulario.submit();
	}
}

///FUncao MENU


