var ajaxMail = new sack();
var tipo;

function whenCompleted(){
	var e = document.getElementById('respuesta'); 
	
	var botonenviar = document.getElementById('botonenviar');	
	botonenviar.style.display = "block";
	
	if (e.innerHTML == "1")
	{
		alert("SE HA PRODUCIDO UN ERROR EN EL ENVÍO. POR FAVOR, VERIFIQUE SU E-MAIL.");		
	}
	else if (e.innerHTML == "2")
	{
		alert("SE HA PRODUCIDO UN ERROR EN EL ENVÍO. INTÉNTELO DE NUEVO Y SI EL ERROR PERSISTE, PRUEBE DENTRO DE UNOS MINUTOS.");
	}
	else if (e.innerHTML == "3")
	{
		alert("EL ENVÍO SE HA REALIZADO CORRECTAMENTE.");
		if (tipo==1)
		{
			window.document.Formu.pSuNombre.value = "";
			window.document.Formu.pSuEmail.value = "";
		}
		else
		{
			iCont = 0;
			while(iCont<formu.length)
			{
				if (formu.elements[iCont].type == "text" || formu.elements[iCont].type == "textarea")
					formu.elements[iCont].value = "";
				
				iCont ++;
			}
		}
	}
	e.innerHTML == ""
}

function enviarMailRecomendar(fichero)
{
	var botonenviar = document.getElementById('botonenviar');	
	botonenviar.style.display = "none";
	
	tipo = 1;
	var form = document.getElementById('form');	
	ajaxMail.setVar("pTuNombre", window.document.Formu.pTuNombre.value); 
	ajaxMail.setVar("pTuEmail", window.document.Formu.pTuEmail.value); 
	ajaxMail.setVar("pSuNombre", window.document.Formu.pSuNombre.value); 
	ajaxMail.setVar("pSuEmail", window.document.Formu.pSuEmail.value); 
	ajaxMail.setVar("pComentarios", window.document.Formu.pComentarios.value.replace("\n","<br>"));
	ajaxMail.setVar("pIdVehiculo", window.document.Formu.pIdVehiculo.value); 
	ajaxMail.setVar("pNombreVehiculo", window.document.Formu.pNombreVehiculo.value); 
	ajaxMail.requestFile = fichero;
	ajaxMail.element = 'respuesta';
	ajaxMail.onCompletion = whenCompleted;		
	ajaxMail.runAJAX("");		
}

function enviarMailFormulario(fichero)
{
	var botonenviar = document.getElementById('botonenviar');	
	botonenviar.style.display = "none";
	
	tipo = 2;
	var form = document.getElementById('form');	
	
	if (window.document.Formu.pTratamiento[0].checked)
		valorTratamiento = window.document.Formu.pTratamiento[0].value
	else
		valorTratamiento = window.document.Formu.pTratamiento[1].value
	ajaxMail.setVar("pTratamiento", valorTratamiento); 
	ajaxMail.setVar("pNombre", window.document.Formu.pNombre.value); 
	ajaxMail.setVar("pApellido1", window.document.Formu.pApellido1.value); 
	ajaxMail.setVar("pApellido2", window.document.Formu.pApellido2.value); 
	ajaxMail.setVar("pNombreVia", window.document.Formu.pNombreVia.value);
	ajaxMail.setVar("pNumVia", window.document.Formu.pNumVia.value); 
	ajaxMail.setVar("pPiso", window.document.Formu.pPiso.value); 
	ajaxMail.setVar("pCodigoPostal", window.document.Formu.pCodigoPostal.value); 
	ajaxMail.setVar("pLocalidad", window.document.Formu.pLocalidad.value); 
	ajaxMail.setVar("pProvincia", window.document.Formu.pProvincia.value); 
	ajaxMail.setVar("pTelefonoContacto", window.document.Formu.pTelefonoContacto.value); 
	ajaxMail.setVar("pTelefonoParticular", window.document.Formu.pTelefonoParticular.value); 
	ajaxMail.setVar("pMovil", window.document.Formu.pMovil.value); 
	ajaxMail.setVar("pFax", window.document.Formu.pFax.value); 
	ajaxMail.setVar("pEmail", window.document.Formu.pEmail.value); 
	ajaxMail.setVar("pComoContactar", window.document.Formu.pComoContactar.value); 
	ajaxMail.setVar("pMarca", window.document.Formu.pMarca.value); 
	ajaxMail.setVar("pSerie", window.document.Formu.pSerie.value); 
	ajaxMail.setVar("pMatricula", window.document.Formu.pMatricula.value); 
	ajaxMail.setVar("pComentarios", window.document.Formu.pComentarios.value.replace("\n","<br>")); 
	ajaxMail.requestFile = fichero;
	ajaxMail.element = 'respuesta';
	ajaxMail.onCompletion = whenCompleted;		
	ajaxMail.runAJAX("");		
}
