jSHA620=['SHA620',15,'SENSOR/DETECTOR DE HUMO AUTÓNOMO CON SEÑAL ACÚSTICA MONTAJE EN SUPERFICIE ALIMENTACIÓN PILA 9V',0,16];
jSHA9659V=['SHA9659V',24.14,'SENSOR/DETECTOR DE HUMO AUTÓNOMO CON SEÑAL ACÚSTICA MONTAJE EN SUPERFICIE ALIMENTACIÓN PILA 9V ',0,16];
jSHA965R12=['SHA965R12',36.4,'DETECTOR DE HUMO ÓPTICO PARA DOMÓTICA CON SOPORTE ALIMENTACIÓN 12V A 24VDC SALIDA RELÉ C/NA/NC  ',0,16];

var maximo1=0;
opciones='';
function carga_opciones()
{
for (j=0; j<document.forms.length;j++)
{
precio_opciones(document.forms[j].name);
}
}
function precio_opciones(formulario){
var precio=0;
var opciones='';
var op=0;
var preciototal=precio+eval(formulario)[1];
maximo1=maxima_cifra(preciototal);
maximo1=maxima_cifra(formato_numeros(eval(formulario)[1],2));
maximo1=maxima_cifra(formato_numeros((preciototal*eval(formulario)[4])/100,2));
maximo1=maxima_cifra(formato_numeros((preciototal+((preciototal*eval(formulario)[4])/100)),2));
for (x=0; x<document.forms[formulario].length; x++){
nombre = document.forms[formulario].elements[x];
if (nombre.name.indexOf('op_')==0){
valor = eval("window.document.forms[formulario]." + nombre.name + ".options[window.document.forms[formulario]." + nombre.name + ".selectedIndex]")
if (isNaN(valor.value)==0 && valor.value!=""){
preciototal = eval(preciototal)+ eval((valor.value));
op=op+1
maximo1=maxima_cifra(formato_numeros(valor.value,2));
opciones = opciones + compone_linea(valor.text + ":",formato_numeros(valor.value,2) ,"€");
};
};
};
//Ahora sumarle el precio de producto y mostrarlo
var texto='';
texto = texto + compone_linea("Precio:",formato_numeros(eval(formulario)[1],2),"€");
texto = texto + opciones;
texto=texto + compone_linea("Subtotal:",formato_numeros(preciototal,2),"€");
texto = texto + compone_linea("Impuestos " + eval(formulario)[4] + " %: ",formato_numeros((preciototal*eval(formulario)[4])/100,2),"€");
texto = texto + "___________________________________\n"
texto = texto + compone_linea("Total:",formato_numeros((preciototal+((preciototal*eval(formulario)[4])/100)),2),"€");
window.document.forms[formulario].subtotal.value=preciototal;
window.document.forms[formulario].cuenta.value=texto;
};
function pone_miles(num) {
    var re = /(-?\d+)(\d{3})/
    while (re.test(num)) {
        num = num.replace(re,"$1.$2")
}
    return(num);
}
function maxima_cifra(cifra)
{
    if (maximo1.length>=cifra.length)
    {
        return(maximo1);
    }
    else
    {
        return(cifra);
    }
}
function compone_linea(titulo, valor, moneda)
{
    var espacios="";
    var linea="";
    var i;
    for (i=titulo.length;i<30;i++)
    {
        espacios = espacios + " ";
    }
    if (maximo1.length>valor.length)
    {
        for(i=valor.length;i<maximo1.length;i++)
        {
            espacios = espacios + " ";
        }
    }
    return (titulo + espacios + valor + " " + moneda + "\n");
}
function corregir_decimales(n, d)
{  d = (d>10?10:d);
   d = (d<0?0:d);
   var r = "" + Math.round(n * Math.pow(10,d));
   return (d==0?r:r.substring(0,r.length-d)+"."+r.substring(r.length-d,r.length));
}
function formato_numeros(valor,decimales)
{
    var numero=corregir_decimales(valor,decimales);
if (numero.charAt(0)=='.')
{
        numero = "0" + numero;
}
if (decimales!=0) {
    var pos= numero.indexOf('.',0);
    if (pos!=0)
    {
        var entero=numero.substring(0,pos);
        return(pone_miles(entero)+ ',' + numero.substring(pos+1,numero.length));
    }
}else{
        return(pone_miles(numero.toString()));
}}

