//PRECIOS FIJOS
var precioBasico = 0;
var envioNormal = 0;
var envioEspecial = 0;
var extraTintados = 0;
var extraPolarizados = 0;
var extraTransition = 0;
var extraNormal = 0;
var extraFinos = 0;
var extraMasFinos = 0;
var extraMedioFinos = 0;
var extraAntirreflejante = 0;
var extraEndurecido = 0;
var fundaDura = 0;
var fundaMetal = 0;
var fundaCuero = 0;

//PRECIOS VARIABLES
var envio = 0;
var uso = 0;
var tintados = 0;
var polarizados = 0;
var transition = 0;
var grosor = 9999;
var antirreflejante = 0;
var endurecido = 0;
var funda = 0;

function inicia(precioBa,precioN,precioE,precioT,precioP,precioTran,precioNormal,precioFinos,precioMasFinos,precioMedioFinos,precioA,precioEnd,precioFundaD,precioFundaM,precioFundaC){

precioBasico = precioBa;
envioNormal = precioN;
envioEspecial = precioE;
extraTintados = precioT;
extraPolarizados = precioP;
extraTransition = precioTran;
extraNormal = precioNormal;
extraFinos = precioFinos;
extraMasFinos = precioMasFinos;
extraMedioFinos = precioMedioFinos;
extraAntirreflejante = precioA;
extraEndurecido = precioEnd;
fundaDura = precioFundaD;
fundaMetal = precioFundaM;
fundaCuero = precioFundaC;
grosor = 0;
funda = 0;

/*if (extraNormal==-1){
  if (extraFinos==-1){
    if (extraMasFinos==-1){
      grosor=0;
    }else{
      grosor=extraMasFinos;
    }
  }else{
    if
    grosor=extraFinos;
  }
}else{
  grosor=extraNormal;
}

if ((extraNormal < grosor) && (extraNormal!=-1)){
    grosor = extraNormal;
}
if ((extraFinos < grosor) && (extraFinos!=-1)){
    grosor = extraFinos;
}
if ((extraMasFinos < grosor) && (extraMasFinos!=-1)){
    grosor = extraMasFinos;
}   */

}

function cambiaEnvio(form){
    if (form.options[form.selectedIndex].text == 'Especial'){
        envio = envioEspecial;
    }else{
        envio = envioNormal;
    }
    actualiza();
}

function cambiaEnvioTryAtHome(form,precioNormal,precioEspecial){
    if (form.options[form.selectedIndex].text == 'Especial'){
        envio = precioEspecial;
    }else{
        envio = precioNormal;
    }
	document.getElementById('envio').innerHTML = envio;
    document.getElementById('tot').value = redondear(parseFloat(document.getElementById('basico').innerHTML) + envio,2);
	document.getElementById('total').innerHTML = redondear(parseFloat(document.getElementById('basico').innerHTML) + envio,2);
}

function setEnvio(valor){
    envio = parseFloat(valor);
}

function cambioUso(form){
    var indice = document.getElementById('uso').selectedIndex;
    if (indice == 0){
        uso = 0;
    }else{
        var idPrecio = "uso_"+document.getElementById('uso')[indice].value;
        uso = parseFloat(document.getElementById(idPrecio).value);
    }
    actualiza();
}

function setUso(valor){
    uso = parseFloat(valor);
}

function cambiaTintado(form){
    if (form.options[form.selectedIndex].text != "Nada"){
        tintados = extraTintados;
        document.getElementById('lentes_polarizados').disabled = true;
        document.getElementById('lentes_transition').disabled = true;
    }else{
        tintados = 0;
        document.getElementById('lentes_polarizados').disabled = false;
        document.getElementById('lentes_transition').disabled = false;
    }       
    actualiza();
}

function setTintado(valor){
    tintados = parseFloat(valor);
    document.getElementById('lentes_polarizados').disabled = true;
    document.getElementById('lentes_transition').disabled = true;
}

function cambiaPolarizado(form){
    if (form.options[form.selectedIndex].text != "Nada"){
        polarizados = extraPolarizados;
        document.getElementById('cristales_tintados').disabled = true;
        document.getElementById('lentes_transition').disabled = true;
    }else{
        polarizados = 0;
        document.getElementById('cristales_tintados').disabled = false;
        document.getElementById('lentes_transition').disabled = false;
    }       
    actualiza();
}

function setPolarizado(valor){
    polarizados = parseFloat(valor);
    document.getElementById('cristales_tintados').disabled = true;
    document.getElementById('lentes_transition').disabled = true;
}

function cambiaTransition(form){
    if (form.options[form.selectedIndex].text != "Nada"){
        transition = extraTransition;
        antirreflejante = 0;
        document.getElementById('cristales_tintados').disabled = true;
        document.getElementById('lentes_polarizados').disabled = true;
        document.getElementById('antirreflejante').checked = true;
        document.getElementById('antirreflejante').disabled = true;
        document.getElementById('precioAntirreflejante').innerHTML = "GRATIS";
    }else{
        transition = 0;
        antirreflejante = extraAntirreflejante;
        document.getElementById('cristales_tintados').disabled = false;
        document.getElementById('lentes_polarizados').disabled = false;
        document.getElementById('antirreflejante').disabled = false;
        document.getElementById('precioAntirreflejante').innerHTML = extraAntirreflejante+"&euro;";
    }       
    actualiza();
}

function setTransition(valor){
    transition = parseFloat(valor);
    document.getElementById('cristales_tintados').disabled = true;
    document.getElementById('lentes_polarizados').disabled = true;
    document.getElementById('antirreflejante').checked = true;
    document.getElementById('antirreflejante').disabled = true;
    document.getElementById('precioAntirreflejante').innerHTML = "GRATIS";
}

function cambiaGrosor(form){
    var indice = document.getElementById('grosor').selectedIndex;
    var valor = document.getElementById('grosor').options[indice].value;
    if (valor == 0){
        grosor=0;
    }
    if (valor == 1){
        grosor=extraNormal;
    }
    if (valor == 2){
       grosor=extraFinos;
    }
    if (valor == 3){
        grosor=extraMasFinos;
    }
    if (valor == 4){
        grosor=extraMedioFinos;
      }
    actualiza();
}

function setGrosor(valor){
    grosor = parseFloat(valor);
}

function cambiaAntirreflejante(form){
    if (form.checked == true){
        antirreflejante = extraAntirreflejante;
    }else{
        antirreflejante = 0;
    }
    actualiza(); 
}

function setAntirreflejante(valor){
    antirreflejante = parseFloat(valor);
}

function cambiaEndurecido(form){
    if (form.checked == true){
        endurecido = extraEndurecido;
    }else{
        endurecido = 0;
    }       
    actualiza();
}

function setEndurecido(valor){
    endurecido = parseFloat(valor);
}

function cambiaFunda(form){
    if (form.value == "funda_dura"){
        funda = fundaDura;
    }
    if (form.value == "funda_metal"){
        funda = fundaMetal;
    }
    if (form.value == "funda_cuero"){
        funda = fundaCuero;
    }
    actualiza();
}

function setFunda(tipo){
    if (tipo == "funda_dura"){
        funda = fundaDura;
    }
    if (tipo == "funda_metal"){
        funda = fundaMetal;
    }
    if (tipo == "funda_cuero"){
        funda = fundaCuero;
    }
}

//*******************************************//
//* ACTUALIZA LOS VALORES EN LA CALCULADORA *//
//*******************************************//

function actualiza(){
    var extra = tintados + polarizados + transition + grosor + antirreflejante + endurecido;
    var opcionales = uso + extra + funda;
    document.getElementById('opciones').innerHTML = redondear(opcionales,2);
    document.getElementById('opc').value = document.getElementById('opciones').innerHTML;
    document.getElementById('envio').innerHTML = redondear(envio,2);
    document.getElementById('total').innerHTML =  redondear(precioBasico + opcionales + envio,2);
    document.getElementById('tot').value = document.getElementById('total').innerHTML;
}
