jSRCP=['SRCP',53.08,'CABLE CONVERSOR DE RS-232 A SR-CP PARA PROGRAMACIÓN DE CPU’s CON EL SOFTWARE SuperCAD2005 ',0,18];
jSRHMIB=['SRHMIB',42.61,'PLC PANTALLA RETRO ILUMINADA HMI DE 4 FILAS POR 10 CARACTERES PANTALLAS Y BOTONES PROGRAMABLES ',0,18];
jSRRCA=['SRRCA',276.25,'MÓDULO CONTROL REMOTO POR RADIO FRECUENCIA PROGRAMABLES EN EL SISTEMA ALIMENTACIÓN 100 A 240VAC ',0,18];
jSRRDC=['SRRDC',276.25,'MÓDULO CONTROL REMOTO POR RADIO FRECUENCIA PROGRAMABLE EN EL SISTEMA ALIMENTACIÓN 12-24VDC  ',0,18];
jSRTC=['SRTC',133.61,'MANDO A DISTANCIA POR RADIO FRECUENCIA  433Mhz 6 BOTONES PROGRAMABLES EN EL SISTEMA',0,18];
jSRVPD=['SRVPD',280,'PLC MÓDULO TELEFÓNICO CONTROL REMOTO Y MENSAJES DE VOZ DE ALARMA ALIMENTACIÓN 12 A 24VDC  ',0,18];

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()));
}}


