function borra_grabacion(id_prod,grabacion_a_borrar,lang,esdistribuidor){
	id_prod=parseInt(id_prod);
	grabacion_a_borrar=parseInt(grabacion_a_borrar);
	llamadasin('carrito_grabaciones.php?id_prod='+id_prod+'&accion=del&posicion_a_borrar='+grabacion_a_borrar+'&lang='+lang+'&esdistribuidor='+esdistribuidor,'muestra_carrito');
	}
	
function anade_grabacion(id_prod,lang,esdistribuidor){
	cantidad_grabaciones=document.getElementById('cantidad_gra['+id_prod+']').value;
	cantidad_grabaciones=parseInt(cantidad_grabaciones);
	texto_grabaciones=document.getElementById('texto_gra['+id_prod+']').value;
	texto_grabaciones= texto_grabaciones.replace(/\n/g, "<br />"); 
	llamadasin('carrito_grabaciones.php?id_prod='+id_prod+'&lang='+lang+'&accion=add&cantidad_grabaciones='+cantidad_grabaciones+'&texto_grabaciones='+texto_grabaciones+'&esdistribuidor='+esdistribuidor+'','muestra_carrito');
	}


function calcula_iva(cantidad,iva){
	calculo=(cantidad*iva)/100;
	return calculo;
}

	
function Comprueba_hay_cantidad(valor){
	
	if(valor=='0'){
		alert("Especifique cantidad de grabaciones primero");
		}
	}

///EMPIEZA COMPROBACION
function Metodo_Pago(forma_de_pago,valor_de_iva)
{

	switch(forma_de_pago)
	{
		case 'Tarjeta de credito':
		document.getElementById('contrareembolso').innerHTML = moneda(0)+' &#8364';
		incremento=0;
		break;
		
		case 'Transferencia Bancaria':
		document.getElementById('contrareembolso').innerHTML = moneda(0)+' &#8364';
		incremento=0;
		break;

		case 'Contrareembolso':
		document.getElementById('contrareembolso').innerHTML = moneda(4)+' &#8364';
		incremento=4;

		break;
		}
	total_carrito=document.getElementById('total_carrito_oculto').value;
	total_carrito=parseFloat(total_carrito);
	total_carrito=total_carrito+incremento;
	document.getElementById('total_carrito').innerHTML=moneda(total_carrito)+' &#8364';
	
	
	}
	
function checkMyUser(EW_this) {
/*if (EW_this.usuario && !EW_hasValue(EW_this.usuario, "TEXT" )) {
	if (!EW_onError(EW_this, EW_this.usuario, "TEXT", "Por favor introduzca los campos requeridos - Usuario"))
		return false;
}*/
correo = mail(EW_this.usuario.value);
if(correo==false){
	mensaje=document.getElementById("mensaje_email_incorrecto").value;
	alert(mensaje);
	return false;}
if(EW_this.passworda.value.length<4){
	mensaje=document.getElementById("contrasena_corta").value;
	alert(mensaje);
	return false;
}
return true;
}
function checkMyForm(EW_this) {
correo = mail(EW_this.user.value);
if(correo==false){
	mensaje=document.getElementById("mensaje_email_incorrecto").value;
	alert(mensaje);
	return false;}


if(EW_this.passwordb.value.length<4){
	mensaje=document.getElementById("contrasena_corta").value;
	alert(mensaje);
	return false;
}

if(EW_this.nombre.value.length<6){
	mensaje=document.getElementById("nombre_completo").value;
	alert(mensaje);
	return false;
}

if(EW_this.nif.value.length<9){
	mensaje=document.getElementById("nif_completo").value;
	alert(mensaje);
		return false;
}

if(EW_this.tel.value.length<9){
	mensaje=document.getElementById("telefono_completo").value;
	alert(mensaje);
	return false;
}

if(EW_this.cp.value.length<parseInt(document.getElementById("longitud_cp_completo").value)){
	mensaje=document.getElementById("cp_completo").value;
	alert(mensaje);
	return false;
}


if(EW_this.direccion.value.length<5){
	mensaje=document.getElementById("direccion_completa").value;
	alert(mensaje);
	return false;
}


if (!EW_this.condiciones.checked){
	mensaje=document.getElementById("condiciones_acepta").value;
	alert(mensaje);
	return false;
}

return true;
}
////ACABA COMPROBACION
function mail(texto){
    var mailres = true;            
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
    
    var arroba = texto.indexOf("@",0);
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
    
    var punto = texto.lastIndexOf(".");
                
     for (var contador = 0 ; contador < texto.length ; contador++){
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
            mailres = false;
            break;
     }
    }

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 2 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
     mailres = true;
    else
     mailres = false;
                
    return mailres;
} 


function recibo_pedido(){
	if(document.getElementById("misma_direccion").checked==1 ){
	document.getElementById("nombre_envio").value='';
	document.getElementById("nombre_envio").disabled=true;
	
	document.getElementById("direccion_envio").value='';
	document.getElementById("direccion_envio").disabled=true;
		
	document.getElementById("cp_envio").value='';
	document.getElementById("cp_envio").disabled=true;
		
	document.getElementById("poblacion_envio").value='';
	document.getElementById("poblacion_envio").disabled=true;
		
	document.getElementById("provincia_envio").value='';
	document.getElementById("provincia_envio").disabled=true;
	
	}else{
	document.getElementById("nombre_envio").disabled=false;
	document.getElementById("direccion_envio").disabled=false;
	document.getElementById("cp_envio").disabled=false;
	document.getElementById("poblacion_envio").disabled=false;
	document.getElementById("provincia_envio").disabled=false;
		
		
		}
	
	}
		
function cantidades(formulario,stock){
	total=document.getElementById("total").value;
	total=parseInt(total);
	for(x=0;x<total;x++){
		elemento=document.getElementById("cantidad["+x+"]").value;
		if(elemento==''){elemento='0';}
		elemento=parseInt(elemento);
		
		if(isNaN(elemento)==true)
		{
		alert("Compruebe las cantidades");
		return (false);
			}
		if(document.getElementById("stock["+x+"]")){
			stock=document.getElementById("stock["+x+"]").value;
			if(elemento>stock){
				alert("La cantidad solicitada supera el stock disponible");
			return(false);
			}
			
			}

			}
		
		}

	
		
function es_numero(valor,pos){
	valor=parseInt(valor);
	if(isNaN(valor)==true){

		
		}else{
			
			}
	}
function es_stock(valor,pos,stock){
	valor=parseInt(valor);
	if(isNaN(valor)==true){
		alert("Cantidad Incorrecta");
		document.getElementById("cantidad["+pos+"]").value='';
		
		}else{
			if(valor>stock){
				alert("La cantidad escogida supera el stock disponible");
				document.getElementById("cantidad["+pos+"]").value='';
				}else{
					}
			}
	}
	
function moneda(amount) {
var val = parseFloat(amount);
if (isNaN(val)) { return "0.00"; }
if (val <= 0) { return "0.00"; }
val += "";

val=val*100;
val=Math.round(val);
val=val/100;
val += "";

// Next two lines remove anything beyond 2 decimal places
if (val.indexOf('.') == -1) { return val+".00"; }
else { val = val.substring(0,val.indexOf('.')+3); }
val = (val == Math.floor(val)) ? val + '.00' : ((val*10 ==
Math.floor(val*10)) ? val + '0' : val);

return val;
} 
	
function comprueba_acc() {
	return true;
	}

function comprueba_todo(aplique,cinta) {
	if(cantidades(aplique)==false){return false;}
	
	if(!cinta){
		aplique=document.getElementById("aplique").value;
		if(!aplique){
			mensaje=document.getElementById("mensaje_error_comprueba_accesorios").value;
			alert(mensaje);
			return false;}
	}
	cinta=document.getElementById("cinta").value;

	aplique=document.getElementById("aplique").value;

	if(cinta==''){
			mensaje=document.getElementById("mensaje_error_comprueba_accesorios").value;
			alert(mensaje);
			return false;}
	if(aplique==''){
		mensaje=document.getElementById("mensaje_error_comprueba_accesorios").value;
		alert(mensaje);
		return false;}

	
	}
function comprueba_cinta(cinta) {
	if(cantidades(cinta)==false){return false;}
	cinta=document.getElementById("cinta").value;
	if(cinta==''){
		mensaje=document.getElementById("mensaje_error_comprueba_accesorios").value;
		alert(mensaje);
		return false;}
	
	}
	

function sumame(total,descuento)
{
	total=total-((total*descuento)/100);
	total=moneda(total);
	return total;
	}
function checkMyPass(EW_this) {
if(EW_this.nuevo_password.value.length<4){
	alert("La contraseña debe contener como minimo 4 carácteres");
		return false;
}
return true;
}

function vacia_texto(id_prod,texto_por_defecto,texto){
	if (texto==texto_por_defecto){
	document.getElementById("texto_gra["+id_prod+"]").value='';
	}
	}

