function aceptar(cod)
{
	http = getHTTPObject(); // We create the HTTP Object
	var nocache = Math.random();
	http.open('POST', 'consulta.asp', true);
	http.onreadystatechange = aceptado;
	valor = "cod=" + cod + "&nocache=" + nocache;
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send(valor);	
}

function aceptado()
{
	if (http.readyState == 1) //Si esta consultado, coloco la animacion
		document.getElementById("respuesta").innerHTML = '<br><br><br><br><br><center><img src="../img/site/loading.gif">&nbsp;<b>Cargando Planilla...</b></center>';
	else if (http.readyState == 4) //Si ya consultó la pagina php, muestro el resultado
		document.getElementById("respuesta").innerHTML = http.responseText;
}

function aceptar2(cod)
{
	var nocache = Math.random();
	http = getHTTPObject();
	http.open('POST', '/PagAm/consulta.asp', true);
	http.onreadystatechange = aceptado2;
	valor = "cod=" + cod + "&nocache=" + nocache;
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send(valor);	
}

function aceptado2()
{
	if (http.readyState == 1) //Si esta consultado, coloco la animacion
		document.getElementById("respuesta").innerHTML = '<br><br><br><br><br><img src="img/site/loading.gif">&nbsp;Cargando Planilla...';
	else if (http.readyState == 4) //Si ya consultó la pagina php, muestro el resultado
		document.getElementById("respuesta").innerHTML = http.responseText;
}

function enviar()
{
	if (Validar(document.getElementById("nombre").value, "tu Nombre", "nombre"))
	{
		var nombre = document.getElementById("nombre").value;
		if (Validar(document.getElementById("email").value, "tu Email", "email"))
		{
			band = 1;
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("email").value))
				band = 1;
			else
			{
				alert("El E-mail que ha Ingresado es Incorrecta");
				band = 0;
			}
			if(band == 1)
			{
				var email = document.getElementById("email").value;
				if (Validar(document.getElementById("telefono").value, "el Telefono", "tel"))
				{
					var telefono = document.getElementById("telefono").value;
					if (Validar(document.getElementById("mensaje").value, "el Mensaje", "mensaje"))
					{
						var mensaje = document.getElementById("mensaje").value;
						var cliente = document.getElementById("cod_cli").value;
						var empresa = document.getElementById("empresa").value;
						var nocache = Math.random();
						http = getHTTPObject();
						http.open('POST', 'envioempresa.asp', true);
						http.onreadystatechange = enviado;
						valor = "cliente=" + escape(cliente) + "&nombre=" + escape(nombre) + "&email=" + escape(email) + "&telefono=" + escape(telefono) + "&empresa=" + escape(empresa) + "&mensaje=" + escape(mensaje) + "&nocache=" + nocache;
						http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
						http.send(valor);
					}
				}
			}
		}
	}
}	

function enviado()
{
	if (http.readyState == 1) //Si esta consultado, coloco la animacion
		document.getElementById("nuevo").innerHTML = '<br><br><br><br><br><img src="../img/site/loading.gif">&nbsp;Enviando...';
	else if (http.readyState == 4) //Si ya consultó la pagina php, muestro el resultado
	{
		document.getElementById("boton1").innerHTML = '&nbsp;';
		document.getElementById("boton2").innerHTML = '&nbsp;';
		var respuesta = http.responseText;
		var salida;
		if(respuesta == "1")
			salida = "<br><br><br><b>Usted se Encuentra Inhabilitado para usar este Servicio por violar las Reglas AntiSpam.<br>El Email No Puede ser Enviado.<br><br>Si desea que su caso sea considerado, puede enviar un email a abuse@infoguia.net<br><br><br>";
		else if(respuesta == "2")
			salida = "<br><br><br><br><b>El Email que Intenta Enviar no Cumple con las Normas AntiSpam.<br><br>El Email No puede ser Enviado</b><br><br><br><br>";
		else
			salida = "<br><br><br><br><b>El Email se ha Enviado Satisfactoriamente!!!</b><br><br><br><br><br><br>";
		document.getElementById("nuevo").innerHTML = salida;
		botonfinal();
	}
}

function botonfinal()
{
	var tbody = document.getElementById("tablefin").getElementsByTagName("tbody")[0];
	var fila = document.createElement("tr");
	var celda = document.createElement("td");
	var boton = document.createElement("input");
	boton.type = 'button';
	boton.id = 'botonfinal';
	boton.value = 'Aceptar';
	boton.onclick = function () {tb_remove()};
	celda.appendChild(boton);
	fila.appendChild(celda);
	tbody.appendChild(fila); 
}