// JavaScript Document
/*DEFINICION DE OPCIONES*/
var estuchado_1=new Array([">>>Cakebox<<<","CAKEBOX 25 UNIDADES","CAKEBOX 50 UNIDADES", ">>>Estuches CD<<<","ESTUCHE CD JEWELBOX BANDEJA NEGRA", "ESTUCHE CD JEWELBOX BANDEJA TRANSPARENTE", "ESTUCHE CD JEWELBOX BANDEJA COLOR", "ESTUCHE CD JEWELBOX SLIM BANDEJA NEGRA", "ESTUCHE CD JEWELBOX SLIM BANDEJA BLANCA","ESTUCHE CD JEWELBOX SLIM BANDEJA TRANSPARENTE",">>>Estuches DVD<<<", "ESTUCHE DVD SIMPLE NEGRO 14 mm","ESTUCHE DVD SIMPLE BLANCO 14 mm","ESTUCHE DVD SIMPLE TRANSPARENTE 14 mm", "ESTUCHE DVD SIMPLE SLIM NEGRO 7 mm","ESTUCHE DVD SIMPLE SLIM TRANSPARENTE 7 mm","ESTUCHE BLU-RAY SIMPLE AZUL",">>>Especiales<<<","FUNDA DE PVC TRANSPARENTE CON SOLAPA","SOBRE DE PAPEL CON VENTANA","SOBRE DE CART\xd3N BLANCO SIN SOLAPA","SOBRE DE CART\xd3N BLANCO CON SOLAPA","BOT\xd3N DE GOMA-ESPUMA BLANCO O NEGRO", "SHELLBOX NEGRO", "SHELLBOX TRANSPARENTE", "SHELLBOX AMARILLO, NARANJA, AZUL Y VERDE" ],["optgroup",0.25,0.50,"optgroup",0.33, 0.35, 0.35, 0.30, 0.32, 0.32,"optgroup", 0.38, 0.40, 0.42, 0.38, 0.38, 0.45,"optgroup", 0.12, 0.12, 0.20, 0.20, 0.12, 0.37, 0.37,0.39]);
var estuchado_2=new Array([">>>Estuches CD<<<","ESTUCHE CD JEWELBOX BANDEJA NEGRA DOBLE","ESTUCHE CD JEWELBOX BANDEJA TRANSPARENTE DOBLE",">>>Estuches DVD<<<","ESTUCHE DVD DOBLE NEGRO 14 mm","ESTUCHE DVD DOBLE TRANSPARENTE 14 mm", "ESTUCHE DVD DOBLE SLIM NEGRO 7 mm","ESTUCHE DVD DOBLE SLIM TRANSPARENTE 7 mm"],["optgroup",0.40, 0.35,"optgroup",0.47,0.56, 0.44, 0.44]);
var grabaDVD = new Array(["SIN GRABAR","GRABACION DE DVD-5(4.7 GB)"],[0,0.22]);
var grabaCD = new Array(["SIN GRABAR","GRABACION DE CD-R(700 MB)"],[0,0.17]);
/*OPCIONES GRAFICAS 1*/

var dvd1cara = new Option("CARATULA ESTUCHE DVD UNA CARA", 0.46, false, false);
var dvd2cara = new Option("CARATULA ESTUCHE DVD DOBLE CARA", 0.81, false, false);
var folleto1cara = new Option("FOLLETO DELANTERO UNA CARA", 0.29, false, false);
var folleto2cara = new Option("FOLLETO DELANTERO DOBLE CARA", 0.47, false, false);
var diptico2cara = new Option("DIPTICO DELANTERO DOBLE CARA", 0.86, false, false);
var libreto2cara = new Option("LIBRETO DELANTERO DOBLE CARA", 1.77, false, false);
/*FIN OPCIONES GRAFICAS 1*/
/*OPCIONES GRAFICAS 2*/

var folletoint1cara = new Option("FOLLETO INTERIOR UNA CARA", 0.29, false, false);
var folletoint2cara = new Option("FOLLETO INTERIOR DOBLE CARA", 0.47, false, false);
var dipticoint2cara = new Option("DIPTICO INTERIOR DOBLE CARA", 0.86, false, false);
var libretoint2cara = new Option("LIBRETO INTERIOR DOBLE CARA", 1.77, false, false);
var inlay1cara = new Option("INLAY UNA CARA", 0.39, false, false);
var inlay2cara = new Option("INLAY DOBLE CARA", 0.57, false, false);
/*FIN OPCIONES GRAFICAS 2*/
/*OPCIONES GRAMAJE*/
var estucado135 = new Option("Estucado 135 gr/m2  (por defecto)", 135, false, false);
var estucado170 = new Option("Estucado 170 gr/m2", 170, false, false);
var estucado200 = new Option("Estucado 200 gr/m2", 200, false, false);  
/*FIN OPCIONES GRAMAJE*/
var descuento;
var cantidad;
var texto ;
var estuchado;
/*FIN DEFINICION DE OPCIONES*/
function init(){
	document.getElementById('masters').options.selectedIndex=0;
	masterSelect('1');
	grabarDVD('grabacion1');
	grabarDVD('grabacion2');
	document.getElementById('graficas1').options.length = 1;
	document.getElementById('graficas2').options.length = 1;
	document.getElementById('encelofanado').disabled=true;
	descuento= 0;
	document.getElementById('resultado').innerHTML= "Pulse &quot;Calcular Precio&quot; para obtener el precio total correspondiente a su selecci&oacute;n";
	document.getElementById('gramaje').disabled = false;
	document.getElementById('gramaje').options.selectedIndex=0;
	estuchado="";
	document.getElementById('graficas1').disabled=true;
	document.getElementById('graficas2').disabled=true;
	document.getElementById('gramaje').disabled=true;
}

function escribirEstuchado(master){
	mi_estuchado=eval("estuchado_" + master) ;
	
		num_estuchado = mi_estuchado[0].length;
		//alert("cantidad de estuchados: "+num_estuchado);
       document.getElementById('estuchado').options.length = num_estuchado;
       for(i=0;i<num_estuchado;i++){
		  
		   document.getElementById('estuchado').options[i].text=mi_estuchado[0][i]; 
          document.getElementById('estuchado').options[i].value=mi_estuchado[1][i];
		 
         
	   }
}


function grabarDVD(dondegrabo){
		//calculo el numero de opciones
       num_grabacion = grabaDVD[0].length;
	  
       //marco el número de provincias en el select
       document.getElementById(dondegrabo).options.length = num_grabacion;
       //para cada provincia del array, la introduzco en el select
       for(i=0;i<num_grabacion;i++){
		   document.getElementById(dondegrabo).options[i].text=grabaDVD[0][i]; 
          document.getElementById(dondegrabo).options[i].value=grabaDVD[1][i];
         
	   }
	
}
function grabarCD(dondegrabo){
	//calculo el numero de opciones
       num_grabacion = grabaCD.length;
	  
       //marco el número de provincias en el select
       document.getElementById(dondegrabo).options.length = num_grabacion;
       //para cada provincia del array, la introduzco en el select
       for(i=0;i<num_grabacion;i++){
		   document.getElementById(dondegrabo).options[i].text=grabaCD[0][i]; 
          document.getElementById(dondegrabo).options[i].value=grabaCD[1][i];
         
	   }
}


/*document.getElementById('estuchado').options.length= 0;*/
function masterSelect(master){
	if (master == '1'){
		/*deshabilitar info segundo master*/
		document.getElementById('disco2').disabled = true;
		document.getElementById('grabacion2').disabled = true;
		document.getElementById('impresion2').disabled = true;
		/*fin deshabiliar info segundo master*/
		/*opciones de estuchado para un master*/
		escribirEstuchado(master);
	}else	if (master == '2'){
		/*habilitar la informacion sobre master 2*/
		document.getElementById('disco2').disabled = false;
		document.getElementById('grabacion2').disabled = false;
		document.getElementById('impresion2').disabled = false;
		/*opciones de estuchado para dos masters*/
		escribirEstuchado(master);
 
	}else if(master == '3'){
		/*IR A FORMULARIO DE CONTACTO*/
		document.location.href= "contacto.php";
	}
}

function discoSelect(disco, grabacion){
	if (disco=="DISCO DVD (4.7 GB)"){
		grabarDVD(grabacion);
	}else{
		grabarCD(grabacion);
	}
}


function estuchadoSelect(estuchadoForm){
	estuchado=estuchadoForm;
/*SEGUN SELECCIONADO EN ESTUCHADO, HABILITO UNAS OPCIONES PARA EL SELECT GRAFICAS1 U OTRAS*/
document.getElementById('graficas1').disabled=false;
document.getElementById('graficas2').disabled=false;
var graficas1 = document.getElementById('graficas1');
graficas1.options.length = 1;
if(estuchado=="SOBRE DE PAPEL CON VENTANA"||estuchado=="SOBRE DE CARTÓN BLANCO SIN SOLAPA"||estuchado=="SOBRE DE CARTÓN BLANCO CON SOLAPA"||estuchado=="BOTÓN DE GOMA-ESPUMA BLANCO O NEGRO"){
	document.getElementById('graficas1').disabled=true;
	document.getElementById('graficas2').disabled=true;
}
if(estuchado=='ESTUCHE DVD DOBLE SLIM NEGRO 7 mm'||estuchado=='ESTUCHE DVD SIMPLE SLIM NEGRO 7 mm'||estuchado=='ESTUCHE DVD SIMPLE SLIM TRANSPARENTE 7 mm'||estuchado=='ESTUCHE DVD SIMPLE NEGRO 14 mm'||estuchado=='ESTUCHE DVD SIMPLE BLANCO 14 mm'||estuchado=='ESTUCHE BLU-RAY SIMPLE AZUL'||estuchado=="ESTUCHE DVD SIMPLE TRANSPARENTE 14 mm"||estuchado=='ESTUCHE DVD DOBLE NEGRO 14 mm'||estuchado=="ESTUCHE DVD DOBLE TRANSPARENTE 14 mm"){
	graficas1.options[graficas1.options.length]= dvd1cara;
}

if(estuchado=="ESTUCHE DVD SIMPLE TRANSPARENTE 14 mm"||estuchado=="ESTUCHE DVD DOBLE TRANSPARENTE 14 mm"||estuchado=='ESTUCHE DVD DOBLE SLIM TRANSPARENTE 7 mm'){
	graficas1.options[graficas1.options.length]= dvd2cara;
}

if(estuchado=='ESTUCHE CD JEWELBOX BANDEJA TRANSPARENTE DOBLE'||estuchado=="ESTUCHE CD JEWELBOX BANDEJA NEGRA"||estuchado=="ESTUCHE CD JEWELBOX BANDEJA TRANSPARENTE"||estuchado=="ESTUCHE CD JEWELBOX BANDEJA COLOR"||estuchado=="ESTUCHE CD JEWELBOX BANDEJA NEGRA DOBLE"||estuchado=="ESTUCHE CD JEWELBOX SLIM BANDEJA NEGRA"||estuchado=="ESTUCHE CD JEWELBOX SLIM BANDEJA BLANCA"||estuchado=="ESTUCHE CD JEWELBOX SLIM BANDEJA TRANSPARENTE"){
	graficas1.options[graficas1.options.length]= folleto1cara;
	graficas1.options[graficas1.options.length]= folleto2cara;
	graficas1.options[graficas1.options.length]= diptico2cara;
	graficas1.options[graficas1.options.length]= libreto2cara;
}

if(estuchado=="FUNDA DE PVC TRANSPARENTE CON SOLAPA"){
	graficas1.options[graficas1.options.length]= folleto1cara;
	graficas1.options[graficas1.options.length]= folleto2cara;
}

/*SEGUN SELECCIONADO EN ESTUCHADO, HABILITO UNAS OPCIONES PARA EL SELECTO GRAFICAS2 U OTRAS*/
var graficas2 = document.getElementById('graficas2');
graficas2.options.length = 1;
if(estuchado=='ESTUCHE DVD DOBLE SLIM NEGRO 7 mm'||estuchado=='ESTUCHE DVD DOBLE SLIM TRANSPARENTE 7 mm'||estuchado=="ESTUCHE DVD SIMPLE NEGRO 14 mm"||estuchado=="ESTUCHE DVD SIMPLE BLANCO 14 mm"||estuchado=='ESTUCHE BLU-RAY SIMPLE AZUL'||estuchado=="ESTUCHE DVD SIMPLE TRANSPARENTE 14 mm"||estuchado=="ESTUCHE DVD DOBLE NEGRO 14 mm"||estuchado=="ESTUCHE DVD DOBLE TRANSPARENTE 14 mm"||estuchado=="ESTUCHE DVD SIMPLE SLIM NEGRO 7 mm"||estuchado=='ESTUCHE DVD SIMPLE SLIM TRANSPARENTE 7 mm'){
	graficas2.options[graficas2.options.length]= folletoint1cara;
	graficas2.options[graficas2.options.length]= folletoint2cara;
	graficas2.options[graficas2.options.length]= dipticoint2cara;
	graficas2.options[graficas2.options.length]= libretoint2cara;
}
if(estuchado=="ESTUCHE CD JEWELBOX BANDEJA NEGRA"||estuchado=="ESTUCHE CD JEWELBOX BANDEJA COLOR"||estuchado=="ESTUCHE CD JEWELBOX BANDEJA NEGRA DOBLE"){
	graficas2.options[graficas2.options.length]= inlay1cara;
	/*graficas2.options[graficas2.options.length]= inlay2cara;*/
}
if(estuchado=='ESTUCHE CD JEWELBOX BANDEJA TRANSPARENTE DOBLE'||estuchado=="ESTUCHE CD JEWELBOX BANDEJA TRANSPARENTE"){
	graficas2.options[graficas2.options.length]= inlay1cara;
	graficas2.options[graficas2.options.length]= inlay2cara;
}

/*SEGUN SELECCIONADO EN ESTUCHADO, HABILITO UNAS OPCIONES PARA EL SELECT ENCELOFANADO U OTRAS*/
if(estuchado=="SOBRE DE PAPEL CON VENTANA"||estuchado=="SOBRE DE CARTÓN BLANCO SIN SOLAPA"||estuchado=="SOBRE DE CARTÓN BLANCO CON SOLAPA"||estuchado=="BOTÓN DE GOMA-ESPUMA BLANCO O NEGRO"||estuchado=="CAKEBOX 25 UNIDADES"||estuchado=="CAKEBOX 50 UNIDADES"||estuchado=="FUNDA DE PVC TRANSPARENTE CON SOLAPA"   ||estuchado=="SHELLBOX NEGRO"||estuchado=="SHELLBOX TRANSPARENTE"||estuchado=="SHELLBOX AMARILLO, NARANJA, AZUL Y VERDE"){
	document.getElementById('encelofanado').disabled=true;
}else{
	document.getElementById('encelofanado').disabled=false;
}
}

/*SEGUN SELECCIONADO EN GRAFICAS1 y 2, HABILITO UNAS OPCIONES PARA EL TIPO DE PAPEL*/
//var gramaje = document.getElementById('gramaje');
function graficasSelected(){
	document.getElementById('gramaje').disabled=false;
	var gramaje = document.getElementById('gramaje');
	gramaje.options.length = 1;
	graf11=document.getElementById('graficas1');
	graf1=graf11.options[graf11.selectedIndex].text;
	//alert(graf1);
	graf22=document.getElementById('graficas2');
	graf2=graf22.options[graf22.selectedIndex].text;
	//alert(graf2);
	//var gramaje = document.getElementById('gramaje');
	//gramaje.options.length = 2;
	if(graf1=="FOLLETO DELANTERO UNA CARA"||graf1=="FOLLETO DELANTERO DOBLE CARA"||graf2=="FOLLETO INTERIOR UNA CARA"||graf2=="FOLLETO INTERIOR DOBLE CARA"){
		alert("entro en 200 gr");
		//gramaje.options[gramaje.options.length]= estucado135;
		gramaje.options[gramaje.options.length]= estucado170;
		gramaje.options[gramaje.options.length]= estucado200;
	}else{
		//gramaje.options[gramaje.options.length]= estucado135;
		gramaje.options[gramaje.options.length]= estucado170;
	}
}
function graficas2Selected(grafica2Select){
	
	if(grafica2Select=="INLAY UNA CARA"||grafica2Select=="INLAY DOBLE CARA"){
		document.getElementById('gramaje').options.selectedIndex=0;
		document.getElementById('gramaje').disabled = true;
	}else{
		document.getElementById('gramaje').disabled = false;
		}
}
/*DESCUENTO SEGUN NUMERO DE UNIDADES*/

function calculardescuento(){
	cantidad = parseFloat(document.getElementById('cantidad').value);
	//alert(cantidad);
	if ((cantidad>49)&(cantidad<100)){
		//alert("entro en 600");
		document.getElementById('descuento').value = "4%";
		descuento = 4;
	}else if ((cantidad>99)&(cantidad<200)){
		//alert("entro en 600");
		document.getElementById('descuento').value = "12%";
		descuento = 12;
	}else if ((cantidad>199)&(cantidad<300)){
		//alert("entro en 600");
		document.getElementById('descuento').value = "18%";
		descuento = 18;
	}else if ((cantidad>299)&(cantidad<400)){
		//alert("entro en 600");
		document.getElementById('descuento').value = "20%";
		descuento = 20;
	}else if ((cantidad>399)&(cantidad<500)){
		//alert("entro en 600");
		document.getElementById('descuento').value = "22%";
		descuento = 22;
	}else if ((cantidad>499)&(cantidad<1000)){
		//alert("entro en 600");
		document.getElementById('descuento').value = "35%";
		descuento = 35;
	}else if ((cantidad>999)&(cantidad<1501)){
		//alert("entro en 600");
		document.getElementById('descuento').value = "40%";
		descuento = 40;
	}else if(cantidad>1500){
		//alert("entro en 1000");
		document.getElementById('descuento').value = "Consultar";
		descuento = "consultar";
		
	}else{
		descuento=0;
		document.getElementById('descuento').value = "No corresponde.";
	}
}
/*FINAL FUNCION DESCUENTO*/

function calcular(){
	//alert("entro en calcular");
	var texto = "";
		var precio = 0;
	form = document.forms[0];
	cantidad = parseInt(form.cantidad.value);
	var disco1Selected = parseFloat(form.disco1.value);
	var grabacion1Selected = parseFloat(form.grabacion1.value);
	var impresion1Selected = parseFloat(form.impresion1.value);
	var disco2Selected = parseFloat(form.disco2.value);
	var grabacion2Selected = parseFloat(form.grabacion2.value);
	var impresion2Selected = parseFloat(form.impresion2.value);
	
	
	if (document.getElementById('masters').value=="1"){
	var disco2Selected = 0;
	var grabacion2Selected = 0;
	var impresion2Selected = 0;
	}
	/*ESTUCHADO*/
	var estuchadoSelected = parseFloat(form.estuchado.value);
	/*calculo precio de 25 o 50 y divido entre la cantidad para al multiplicar por cantidad al calcular el precio final que salga bien*/
	if (estuchado=="CAKEBOX 25 UNIDADES"){
		numCajas = cantidad/25;
		 numCajasEnt = parseInt(numCajas);
		 if((numCajas - numCajasEnt)>0) {
			 numCajasEnt=numCajasEnt+1;
			 //alert(numCajasEnt);
		 }
		estuchadoSelected= (estuchadoSelected*numCajasEnt)/cantidad;
	}else if(estuchado=="CAKEBOX 50 UNIDADES"){
		numCajas = cantidad/50;
		 numCajasEnt = parseInt(numCajas);
		 if((numCajas - numCajasEnt)>0) {
			 numCajasEnt=numCajasEnt+1;
			 //alert(numCajasEnt);
		 }
		estuchadoSelected= (estuchadoSelected*numCajasEnt)/cantidad;
	}
	/*FIN ESTUCHADO*/	
		
	var encelofanadoSelected = parseFloat(form.encelofanado.value);
	var depositoSelected = 0;
	if (form.deposito.checked){
		depositoSelected = parseFloat(form.deposito.value);
	}
	var almacenajeSelected = 0 ;
	
	if (form.almacenaje.checked){
		almacenajeSelected= parseFloat(form.almacenaje.value);
	}

	/*var envioSelected = parseFloat(form.envio.value);*/
	var graficas1Selected = parseFloat(form.graficas1.value);
	var graficas2Selected = parseFloat(form.graficas2.value);
	
	/*//alert("hola"+graficas1Selected);*/
	
	/*AUMENTO DE GRAFICAS */
	if (graficas1Selected != 0){
		//alert(graficas1Selected);
		/*POR GRAMAJE. Miramos si hay graficas y si hay gramaje para sumar el 0.05*/
		if (document.getElementById('gramaje').value=="170"){
		
		graficas1Selected += 0.05; 
		//alert("con el plus de gramaje ");
		}
		if (document.getElementById('gramaje').value=="200"){
		
		graficas1Selected += 0.06; 
		//alert("con el plus de gramaje ");
		}
		/*POR BRILLO. Miramos si hay graficas y si hay sumamos el 22%*/
		/*if (document.getElementById('brillo').value=="true"){
			//alert((graficas1Selected * 22)/100);
		graficas1Selected = graficas1Selected+((graficas1Selected * 22)/100);
		}*/
			
	}
	if (graficas2Selected != 0){
		//alert(graficas2Selected);
		if (document.getElementById('gramaje').value=="170"){
		graficas2Selected += 0.05;
		}
		if (document.getElementById('gramaje').value=="200"){
		graficas2Selected += 0.06;
		}
		/*if (document.getElementById('brillo').value=="true"){
			
			//alert((graficas2Selected * 22)/100);
		graficas2Selected =graficas2Selected+((graficas2Selected * 22)/100);
		
		}*/
	}
	/*fin aumento de graficas por gramaje*/
	if(descuento=="consultar"){
	   precio = 0;
	   }else{
	precio = disco1Selected +grabacion1Selected+impresion1Selected +disco2Selected +grabacion2Selected;
	precio+= impresion2Selected + estuchadoSelected + encelofanadoSelected ;
	precio+=   graficas1Selected +graficas2Selected ;
	precioUNIDAD = precio;
	precio = precio * cantidad;
	preciobruto = precio;
	valordescuento = (precio*descuento)/100;
	precio = precio - valordescuento;
	preciosoloproducto = precio;
	/*calcular los gastos de envio segun cantidad*/
	/*gastosEnvio = (parseInt(cantidad/50))*envioSelected;
	if((cantidad%50)!=0){
		////alert("no es multiplo")
		gastosEnvio+=envioSelected;
	}*/
	precio += almacenajeSelected + depositoSelected/*+gastosEnvio*/;
	/*a dos decimales*/
	precio=precio*100;
	precio=Math.floor(precio);
	precio=precio/100;
	iva = (precio*16)/100;
	iva=Math.round(iva*100) / 100; 
	total = precio + iva;
	}
	/*cuando seleccionan un titulo como estuche, aparece nan. */
	if(descuento=="consultar"){
		texto = "Para esta cantidad de unidades consulte con nosotros el descuento que corresponde ya sea por tel\xe9fono, email o a trav\xe9s del formulario de contacto. ";
	}else if(isNaN(precio)){
			texto = "Seleccione un tipo de estuchado y pulse de nuevo 'Calcular'.";
	}else{
	texto = "NETO: " +precio+" euros.<br/>IVA 16%: "+iva+" euros.<br/><strong>TOTAL: "+total+" euros. </strong><br/>Incluido descuento por cantidad.";
	}
	document.getElementById('resultado').innerHTML= texto;	
}

