var incompleto = false;

function getSelectedValue(id)
{
		seleccion = document.getElementById('formLibro_'+id);
		valor = seleccion.options[seleccion.selectedIndex].value;

		if(valor=="-1")
		{
			idd='ast_'+id;
			document.getElementById('ast_'+id).innerHTML="**";
			incompleto = true;
		} else	
		{	
			if(document.getElementById('ast_'+id)!=null) document.getElementById('ast_'+id).innerHTML="";
			return valor;
		}
}

function runComprarLibro(producto)
{
	setActiveItem('demo_nav_compra');
	llamarasincrono('sections/comprarLibro/main.php?producto='+producto, 'content');
}

function cambiarFormaDePago(tipo)
{
	if(tipo==0)
	llamarasincrono('sections/comprarLibro/formTarjeta.php', 'formSegunTipoDePago');
	else if(tipo==1)
	llamarasincrono('sections/comprarLibro/formTransferencia.php', 'formSegunTipoDePago');
	else if(tipo==2)
	llamarasincrono('sections/comprarLibro/formCheque.php', 'formSegunTipoDePago');
	else if(tipo==3)
	document.getElementById('formSegunTipoDePago').innerHTML = "";
}

function getValorFromInput(id)
{	
	valor = document.getElementById('formLibro_'+id).value;
	if(valor == "")
	{
		document.getElementById('ast_'+id).innerHTML="**";
		incompleto = true;	
	}
	else document.getElementById('ast_'+id).innerHTML="";
	return valor;
}

function comprarLibro()
{
	incompleto = false;
	
	nombre = getValorFromInput('Nombre');
	apellido = getValorFromInput('Apellido');
	profesion = getValorFromInput('Profesion');
	especialidad = getValorFromInput('Especialidad');
	matricula = getValorFromInput('Matricula');
	direccion = getValorFromInput('Direccion');
	ciudad = getValorFromInput('Ciudad');
	codigoPostal = getValorFromInput('CodigoPostal');
	telefono = getValorFromInput('Telefono');
	fax = getValorFromInput('Fax');
	eMail = getValorFromInput('eMail');
/*
	revisarCompletitud("Apellido");
	revisarCompletitud("Profesion");
	revisarCompletitud("Especialidad");
	revisarCompletitud("Matricula");
	revisarCompletitud("Direccion");
	revisarCompletitud("Ciudad");
	revisarCompletitud("CodigoPostal");
	revisarCompletitud("Telefono");
	revisarCompletitud("eMail");
*/
	post = "";	
	post += "?nombre="+nombre;
	post += "&apellido="+apellido;
	post += "&profesion="+profesion;
	post += "&especialidad="+especialidad;
	post += "&matricula="+matricula;
	post += "&direccion="+direccion;
	post += "&ciudad="+ciudad;
	post += "&codigoPostal="+codigoPostal;
	post += "&telefono="+telefono;
	post += "&fax="+fax;
	post += "&eMail="+eMail;	
	/*
	// si es tarjeta
	if(document.getElementById('formLibro_PagoTarjeta').checked)
	{		
		formaDeEnvio = getSelectedValue("FormaDeEnvio");
		cantidadDeCuotas = getSelectedValue("CantidadDeCuotas");
		tarjetaDePago = getSelectedValue("TarjetaDePago");
		tipoDeDocumento = getSelectedValue("TipoDeDocumento");
		numeroDeDocumento = getValorFromInput("NumeroDeDocumento");	
											   			
		post += "&formaDePago=Tarjeta";
		post += "&formaDeEnvio=" + formaDeEnvio;
		post += "&cantidadDeCuotas=" + cantidadDeCuotas;
		post += "&tarjetaDePago=" + tarjetaDePago;
		post += "&tipoDeDocumento=" + tipoDeDocumento;
		post += "&numeroDeDocumento=" + numeroDeDocumento;
	}
	else 
	if(document.getElementById('formLibro_PagoTransferencia').checked)		
	{
		formaDeEnvio = getSelectedValue("formLibro_FormaDeEnvio");	
		post += "&formaDePago=Transferencia";
		post += "&formaDeEnvio=" + formaDeEnvio;	
	}
	else
	*/ 
	
	if(document.getElementById('formLibro_producto1').checked)		
	{
		post+="&producto=Libro grande, chico, y CD";
	}
	else if(document.getElementById('formLibro_producto2').checked)
	{
		post+="&producto=Medik";
	}		
	else if(document.getElementById('formLibro_producto3').checked)
	{
		post+="&producto=Interdrugs para Celulares";
	}		
	else if(document.getElementById('formLibro_producto4').checked)
	{
		post+="&producto=Libro para Celulares";
	}		
	else if(document.getElementById('formLibro_producto5').checked)
	{
		post+="&producto=Solo CD";
	}		

	
	if(document.getElementById('formLibro_PagoCheque').checked)		
	{		
		formaDeEnvio = getSelectedValue("FormaDeEnvio");	
		post += "&formaDePago=Cheque";
		post += "&formaDeEnvio=" + formaDeEnvio;	
	}

	if(document.getElementById('formLibro_PagoEfectivo').checked)		
	{
		post += "&formaDePago=Efectivo";
	}
	
	
	if(incompleto==true) 
	{
		alert("Algunos campos del formulario no han sido correctamente completados");	
		return;
	}
	
    if(!document.getElementById('formLibro_PagoEfectivo').checked &&
	   !document.getElementById('formLibro_PagoCheque').checked)
	   {
		alert("Por favor, indique la forma de pago con la que desea abonar el monto del libro.");			   
		return;
	   }
		llamarasincrono('sections/comprarLibro/sendNotificacionDeCompra.php'+post, 'content');
	
}


