
function actualizar_pagina(enlace){
	var enlace= enlace;
	opener.location.href=enlace;
	window.close();
}

function actualizar_pagina_producto(enlace){
	var enlace= enlace;
	document.location.href = enlace;
	return false;
}

function mirarCompatibilidad(objeto,pedido_id){
	/* llamo al ajax	*/
	ajax = nuevoAjax();
	ajax.open("GET", "../ajax/devuelveIncompatibilidades.php?id="+objeto.value+"&pedido_id="+pedido_id,true);

	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		   //contenedor2.innerHTML = ajax.responseText
		}else{
		   //contenedor2.innerHTML = ''
		}
	}
	ajax.send(null);
	if(pedido_id!="")
		window.location = "index.php?modulo=pedido&accion=edicion&pedido_id="+pedido_id;
	else
		window.location = "index.php?modulo=pedido&accion=edicion";
}

function borrarProducto(orden,pedido_id){
	ajax = nuevoAjax();
	ajax.open("GET","../ajax/borrarProductoSesion.php?orden="+orden,false);
	ajax.onreadystatechange = function(){
		if (ajax.readyState==4) {
		   //contenedor2.innerHTML = ajax.responseText
		}else{
		   //contenedor2.innerHTML = ''
		}
	}
	ajax.send(null);
	if(pedido_id!="")
		window.location = "index.php?modulo=pedido&accion=edicion&pedido_id="+pedido_id;
	else
		window.location = "index.php?modulo=pedido&accion=edicion";
}

function actualizarUnidades(orden,unidades,pedido_id){
	ajax = nuevoAjax();
	ajax.open("GET","../ajax/actualizoUnidadesSesion.php?orden="+orden+"&unidades="+unidades,false);
	ajax.onreadystatechange = function(){
		if (ajax.readyState==4) {
		   //contenedor2.innerHTML = ajax.responseText
		}else{
		   //contenedor2.innerHTML = ''
		}
	}
	ajax.send(null);
	if(pedido_id!="")
		window.location = "index.php?modulo=pedido&accion=edicion&pedido_id="+pedido_id;
	else
		window.location = "index.php?modulo=pedido&accion=edicion";
}


function confirmaBorrar(pregunta, orden,objeto){
	if (confirm(pregunta)){
		borrarProducto(orden);
	}else{
		objeto.checked = false;
	};
}

function actualizarDescuento(orden,descuento,pedido_id){
	ajax = nuevoAjax();
	ajax.open("GET","../ajax/actualizoDescuentoSesion.php?orden="+orden+"&descuento="+descuento,false);
	ajax.onreadystatechange = function(){
		if (ajax.readyState==4) {
		   //contenedor2.innerHTML = ajax.responseText
		}else{
		   //contenedor2.innerHTML = ''
		}
	}
	ajax.send(null);
	if(pedido_id!="")
		window.location = "index.php?modulo=pedido&accion=edicion&pedido_id="+pedido_id;
	else
		window.location = "index.php?modulo=pedido&accion=edicion";
}

function calcularSubtotal(pedido_id){
	ajax = nuevoAjax();
	ajax.open("GET","../ajax/calcularSubtotal.php",false);
	ajax.onreadystatechange = function(){
		if (ajax.readyState==4) {
		   document.formpedido.PRECIO_SUBTOTAL.value = '';
		   document.formpedido.PRECIO_SUBTOTAL.value = formatoPostgresDecimal(ajax.responseText);
		}
	}
	ajax.send(null);
	if(pedido_id!="")
		window.location = "index.php?modulo=pedido&accion=edicion&pedido_id="+pedido_id;
	else
		window.location = "index.php?modulo=pedido&accion=edicion";
}

function guardarAccesorioSesion(orden, valor){
	ajax = nuevoAjax();
	ajax.open("GET","../ajax/guardarAccesorioSesion.php?orden="+orden+"&valor="+valor,false);
	ajax.onreadystatechange = function(){
		if (ajax.readyState==4) {
		}
	}
	ajax.send(null);
}

function calculoPVPFormaPago(valor){
	ajax = nuevoAjax();
	ajax.open("GET","../ajax/leoFormaPago.php?valor="+valor,true);

	ajax.onreadystatechange = function(){
		if (ajax.readyState==4) {
			document.formpedido.PRECIO_FORMA_PAGO.value = formatoPostgresDecimal(ajax.responseText);
		}
	}
	ajax.send(null);
}

//	esta funci�n, lo que hace es calcular el precio total en funci�n de la suma mediante javascript de lo que hay en los inputs
function calculoPrecioTotal(pedido_id){
	if (document.formpedido.PRECIO_SUBTOTAL.value!="0,00"){
		var p_subtotal = ((formatoDecimalPostgres(document.formpedido.PRECIO_SUBTOTAL.value)*100)/100);
	}else
		var p_subtotal = 0;

	if(document.formpedido.DESCUENTO.value!="0,00")
		var descuento = (Math.ceil(formatoDecimalPostgres(document.formpedido.DESCUENTO.value)*100)/100);
	else
		var descuento = 0;

	if (document.formpedido.PRECIO_PORTES.value!="0,00")
		var precio_portes = (Math.ceil(formatoDecimalPostgres(document.formpedido.PRECIO_PORTES.value)*100)/100);
	else
		var precio_portes = 0;

	if ((document.formpedido.PRECIO_FORMA_PAGO.value!="0,00") && (document.formpedido.PRECIO_FORMA_PAGO.value!=""))
		var precio_forma_pago = (Math.ceil(formatoDecimalPostgres(document.formpedido.PRECIO_FORMA_PAGO.value)*100)/100);
	else
		var precio_forma_pago = 0;

	//	aqu� a cada uno de los inputs, le sumo y resto 1 para convertilo a num�rico y que sume correctamente y no concatene
	var numerito = (Math.ceil((p_subtotal + descuento + precio_portes + precio_forma_pago)*100)/100);
	document.formpedido.PRECIO_TOTAL.value = formatoPostgresDecimal(numerito);

	var ajax = nuevoAjax();
	ajax.open("GET","../ajax/guardarTotal.php?valor="+numerito,true);

	ajax.onreadystatechange = function(){
		if (ajax.readyState==4) {

			document.formpedido.PRECIO_TOTAL.value = (ajax.responseText);
		}
	}
	ajax.send(null);

	if(pedido_id!="")
		window.location = "index.php?modulo=pedido&accion=edicion&pedido_id="+pedido_id;
	else
		window.location = "index.php?modulo=pedido&accion=edicion";
}

function validar_pedido(){
	if (!document.pedido.CIF.value)        
	{          
		alert ("Por favor, introduzca su NIF / CIF.");
		document.pedido.CIF.select();
		return false;        
	}
	
	if (!document.pedido.NOMBRE_FACTURA.value)        
	{          
		alert ("Por favor, introduzca su nombre.");
		document.pedido.NOMBRE_FACTURA.select();
		return false;        
	}
	
	if (!document.pedido.DIRECCION_FACTURA.value)        
	{          
		alert ("Por favor, introduzca su direccion .");
		document.pedido.DIRECCION_FACTURA.select();
		return false;        
	}
		
	if (!document.pedido.POBLACION_FACTURA.value)        
	{          
		alert ("Por favor, introduzca su poblacion .");
		document.pedido.POBLACION_FACTURA.select();
		return false;        
	}
	if (!document.pedido.CODIGO_POSTAL_FACTURA.value)        
	{          
		alert ("Por favor, introduzca su codigo postal .");
		document.pedido.CODIGO_POSTAL_FACTURA.select();
		return false;        
	}	
		
	if (!document.pedido.PROVINCIA_FACTURA.selectedIndex){
		alert ("Por favor, seleccione una provincia .");
		document.pedido.PROVINCIA_FACTURA.focus();
		return false;                   
	}			
		
	if (document.pedido.EMAIL_FACTURA.value)        
	{ 	
		if (document.pedido.EMAIL_FACTURA.value.indexOf("@",1)==-1)        
		{          
			alert ("Por favor, introduzca una direcci\xf3n E-Mail correcta.");
			document.pedido.EMAIL_FACTURA.select();
			return false;        
		}        
		if (document.pedido.EMAIL_FACTURA.value.indexOf(".",1)==-1)
		{          
			alert ("Por favor, introduzca una direcci\xf3n E-Mail correcta.");
			document.pedido.EMAIL_FACTURA.select();
			return false;        
		}	
	}
	//validamos los datos de envío si el check esta activado
	if (document.pedido.VER_DATOS_FACTURACION.checked){
		if (!document.pedido.NOMBRE.value)        
		{          
			alert ("Por favor, introduzca un nombre en los datos de envío.");
			document.pedido.NOMBRE.select();
			return false;        
		}
		
		if (!document.pedido.DIRECCION.value)        
		{          
			alert ("Por favor, introduzca una direccion en los datos de envío.");
			document.pedido.DIRECCION.select();
			return false;        
		}
		
		if (!document.pedido.POBLACION.value)        
		{          
			alert ("Por favor, introduzca su poblacion en los datos de envío.");
			document.pedido.POBLACION.select();
			return false;        
		}
		if (!document.pedido.CODIGO_POSTAL.value)        
		{          
			alert ("Por favor, introduzca su codigo postal en los datos de envío.");
			document.pedido.CODIGO_POSTAL.select();
			return false;        
		}	
		
	    if (!document.pedido.PROVINCIA.selectedIndex){
			alert ("Por favor, seleccione una provincia en los datos de envío.");
			document.pedido.PROVINCIA.focus();
			return false;                   
	    }			
		
		if (document.pedido.EMAIL.value)        
		{ 	
			if (document.pedido.EMAIL.value.indexOf("@",1)==-1)        
			{          
				alert ("Por favor, introduzca una direcci\xf3n E-Mail correcta en los datos de envío.");
				document.pedido.EMAIL.select();
				return false;        
			}        
			if (document.pedido.EMAIL.value.indexOf(".",1)==-1)
			{          
				alert ("Por favor, introduzca una direcci\xf3n E-Mail correcta en los datos de envío.");
				document.pedido.EMAIL.select();
				return false;        
			}	
		}
	}
	
}