function calculaprecios(){

		var preciotramo = parseFloat((document.getElementById("PedidoPreciotramo").value));
		var iva =  parseFloat((document.getElementById("PedidoIva").value));
		var contrareembolso =  parseFloat((document.getElementById("PedidoPreciocontrareembolso").value));
		document.getElementById("PedidoMetodoescogido").value= document.getElementById("PedidoMetodo").options[document.getElementById("PedidoMetodo").selectedIndex].text;

		if(document.getElementById("PedidoMetodo").selectedIndex == 0){
			document.getElementById("numtarjeta").style.display = "inline";
			var envio_valor= Math.round((preciotramo*((iva/100)+1))*100)/100;
			var aux = parseFloat(envio_valor);
			var aux1 = parseFloat(document.getElementById("PedidoSubtotal").value);
			document.getElementById("valorenvio").innerHTML = envio_valor+ " &euro;";
			document.getElementById("valortotal").innerHTML = Math.round((aux+aux1)*100)/100;
			document.getElementById("PedidoTotal").value = document.getElementById("valortotal").innerHTML;
			document.getElementById("valortotal").innerHTML += " &euro;";
		}
		else{
			var envio_valor= Math.round((preciotramo+contrareembolso)*((iva/100)+1)*100)/100;
			var aux = parseFloat(envio_valor);
			var aux1 = parseFloat(document.getElementById("PedidoSubtotal").value);
			document.getElementById("valorenvio").innerHTML = envio_valor+ " &euro;";
			document.getElementById("valortotal").innerHTML = Math.round((aux+aux1)*100)/100;
			document.getElementById("numtarjeta").style.display = "none";
			document.getElementById("PedidoTotal").value = document.getElementById("valortotal").innerHTML;
			document.getElementById("valortotal").innerHTML += " &euro;";
			
		}
	}



	function calculapreciosprov(){
		var preciotramo = parseFloat((document.getElementById("PedidoPreciotramo").value));
		var preciotramocanarias = parseFloat((document.getElementById("PedidoPreciotramocanarias").value));
		var iva =  parseFloat((document.getElementById("PedidoIva").value));
		var contrareembolso =  parseFloat((document.getElementById("PedidoPreciocontrareembolso").value));

		document.getElementById("PedidoProvinciaescogida").value= document.getElementById("PedidoProvincia").options[document.getElementById("PedidoProvincia").selectedIndex].text


		if(document.getElementById("PedidoProvincia").value!=35	&& document.getElementById("PedidoProvincia").value!=38){
			document.getElementById("PedidoMetodoescogido").value=document.getElementById("PedidoMetodo").options[document.getElementById("PedidoMetodo").selectedIndex].text;
			document.getElementById("pago1").style.display = "inline";
			document.getElementById("pago2").style.display = "none";
			document.getElementById("lugar1").style.display = "inline";
			document.getElementById("lugar2").style.display = "none";


			if(document.getElementById("PedidoMetodo").selectedIndex == 0){
				document.getElementById("numtarjeta").style.display = "inline";
				var envio_valor= Math.round((preciotramo*((iva/100)+1))*100)/100;
				var aux = parseFloat(envio_valor);
				var aux1 = parseFloat(document.getElementById("PedidoSubtotal").value);
				document.getElementById("valorenvio").innerHTML = envio_valor+ " &euro;";
				document.getElementById("valortotal").innerHTML = Math.round((aux+aux1)*100)/100;
				document.getElementById("PedidoTotal").value = document.getElementById("valortotal").innerHTML;
				document.getElementById("valortotal").innerHTML += " &euro;";
			}
			else{
				var envio_valor= Math.round((preciotramo+contrareembolso)*((iva/100)+1)*100)/100;
				var aux = parseFloat(envio_valor);
				var aux1 = parseFloat(document.getElementById("PedidoSubtotal").value);
				document.getElementById("valorenvio").innerHTML = envio_valor+ " &euro;";
				document.getElementById("valortotal").innerHTML = Math.round((aux+aux1)*100)/100;
				document.getElementById("numtarjeta").style.display = "none";
				document.getElementById("PedidoTotal").value = document.getElementById("valortotal").innerHTML;
				document.getElementById("valortotal").innerHTML += " &euro;";
			}
		}
		else{
				document.getElementById("PedidoMetodoescogido").value="Transferencia";
				document.getElementById("lugar1").style.display = "none";
				document.getElementById("lugar2").style.display = "inline";
				document.getElementById("numtarjeta").style.display = "inline";
				var envio_valor= Math.round((preciotramocanarias*((iva/100)+1))*100)/100;
				var aux = parseFloat(envio_valor);
				var aux1 = parseFloat(document.getElementById("PedidoSubtotal").value);
				document.getElementById("valorenvio").innerHTML = envio_valor+ " &euro;";
				document.getElementById("valortotal").innerHTML = Math.round((aux+aux1)*100)/100;	
				document.getElementById("pago1").style.display = "none";	
				document.getElementById("pago2").style.display = "inline";
				document.getElementById("PedidoTotal").value = document.getElementById("valortotal").innerHTML;
				document.getElementById("valortotal").innerHTML += " &euro;";
		}
	}


		function changePrecioPedido(sel) {
			if(sel.value == 1){
				masprecio = 7.20;
				document.getElementById('genvio').innerHTML = '+ Gastos de Envio: 7.20 &euro; | Peninsula (España) con MRW';
			}
			else {
				masprecio = 7;
				document.getElementById('genvio').innerHTML = '+ Gastos de Envio: 7.00 &euro; | Baleares y Canarias (España) con Correos';
			}
			var total = parseFloat(document.getElementById('PedidoLibroPrecio').value) + masprecio;
			var result = total.toFixed(2);
			document.getElementById('totalp').innerHTML = 'Total Pedido: <b>'+result+' &euro;</b>';
			
		}
		function validaFormCompra(formu) {			
			var error = false;
			var caderror = "Se han producido los siguientes Errores:\n";
			
			if($('PedidoNombre').value == ""){
				error = true;
				caderror +=  "* Debe introducir un Nombre.\n";
			}

			if($('PedidoDireccion').value == ""){
				error = true;
				caderror +=  "* Debe introducir una Dirección.\n";
			}

			if($('PedidoLocalidad').value == ""){
				error = true;
				caderror +=  "* Debe introducir una Localidad.\n";
			}

			
			if($('PedidoCp').value == ""){
				error = true;
				caderror +=  "* Debe introducir un código postal.\n";
			}
			else{
				if(!(isInteger($('PedidoCp').value)) ){
					error = true;
					caderror +=  "* El código postal debe ser un número.\n";
				}
				else{
					if(($('PedidoCp').value.length)!=5 ){
						error = true;
						caderror +=  "* El código postal debe tener 5 cifras.\n";
					}
					else{

						if( ($('PedidoCp').value.substring(0,2))!= ($('PedidoProvincia').options[$('PedidoProvincia').selectedIndex].value ) ){
							error = true;
							caderror +=  "* El código postal NO coincide con la provincia seleccionada.\n";
						}
					}
				}
			}
			
			if($('PedidoMovil').value == ""){
				error = true;
				caderror +=  "* Debe introducir un número de móvil.\n";
			}
			else{
				if(!(isInteger($('PedidoMovil').value)) ){
					error = true;
					caderror +=  "* El movil debe ser un número .\n";
				}
				else{
					if(($('PedidoMovil').value.length)!=9 ){
						error = true;
						caderror +=  "* El número de móvil debe tener 9 cifras.\n";
					}
					else{

						if( ($('PedidoMovil').value.substring(0,1))!=6 ){
							error = true;
							caderror +=  "* Número de móvil incorrecto .\n";
						}
					}
				}
			}

			if($('PedidoFijo').value != ""){
				if(!(isInteger($('PedidoFijo').value)) ){
					error = true;
					caderror +=  "* El teléfono fijo debe ser un número .\n";
				}
				else{
					if(($('PedidoFijo').value.length)!=9 ){
						error = true;
						caderror +=  "* El número de teléfono fijo debe tener 9 cifras.\n";
					}
					else{
						if(($('PedidoFijo').value.substring(0,1))!=9 ){
							error = true;
							caderror +=  "* Número de teléfono fijo incorrecto .\n";
						}
					}
				}
			}
			else{
			}

			if(!validarEmail($('PedidoEmail').value)){
				error = true;
				caderror +=  "* Debe introducir una dirección Email válida.\n";
			}
			
			if($('PedidoTerms').checked == false){
				error = true;
				caderror +=  "* Debe leer y aceptar las Condiciones de Uso.\n";
			}
			
			if(error == true) {
				alert(caderror);
				return false;
			}
			else{
				return confirm('¿Desea realizar el pedido?');
			}
		}
		function validarEmail(valor) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){				
				return (true);
			} else {				
				return (false);
			}
		}
	 

