
    function toHex(decimal_number)
    //feed it a decimal number and it spits back a 2 digit hex number
    {
       var prefix = (decimal_number < 16) ? '0' : '';
       hex_number = decimal_number.toString(16);
       hex_number = hex_number.toUpperCase();
       return prefix + hex_number;
    }


    function toDecimalr(hexcode) { hexr = hexcode.substring(0,2); return parseInt(hexr,16); }
    function toDecimalg(hexcode) { hexg = hexcode.substring(2,4); return parseInt(hexg,16); }
    function toDecimalb(hexcode) { hexb = hexcode.substring(6,4); return parseInt(hexb,16); }


    function fillHexes(cFondo,cLetra,cLink)
    {
       //Valores Iniciales
       window.document.FormUsuario.txtbgcolor.value = cFondo;
       cambiar_color(document.getElementById("ColFondo"),cFondo); 
       
       window.document.FormUsuario.txttext.value = cLetra;
       cambiar_color(document.getElementById("ColTexto"),cLetra);
       
       window.document.FormUsuario.txtlink.value = cLink;
       cambiar_color(document.getElementById("ColLink"),cLink);

       previsualizar();
    }


    function SendColor(sentcolor)
    {
       current_radio_flag = getRadioButtonSelectedValue(document.FormUsuario.flag);
       
       if(current_radio_flag == "Fondo")
       {
          window.document.FormUsuario.txtbgcolor.value = "#" + sentcolor; 
          cambiar_color(document.getElementById("ColFondo"),"#" + sentcolor); 
       }
       else if(current_radio_flag == "Letra")
       {
          window.document.FormUsuario.txttext.value = "#" + sentcolor;
          cambiar_color(document.getElementById("ColTexto"),"#" + sentcolor);      
       }
       else if(current_radio_flag == "Link")
       {
          window.document.FormUsuario.txtlink.value = "#" + sentcolor;
          cambiar_color(document.getElementById("ColLink"),"#" + sentcolor);      
       }
       
       previsualizar();
    }

    function getRadioButtonSelectedValue(ctrl)
    {
        for(i=0;i<ctrl.length;i++)
            if(ctrl[i].checked) return ctrl[i].value;
    }
    
    function cambiar_color(celda,color)
    { 
        celda.style.backgroundColor = color;         
    }
    
    function cambiar_color_link(celda,color)
    { 
        celda.style.color = color;         
    }
    
    function cambiar_color_letra(celda,color)
    { 
        celda.style.color = color;         
    }
    


    function previsualizar()
    {
        celda = document.getElementById("tblPrevisualizar");
        cambiar_color(celda,window.document.FormUsuario.txtbgcolor.value);

        celda = document.getElementById("pre_text");
        cambiar_color_letra(celda,window.document.FormUsuario.txttext.value);

        celda = document.getElementById("pre_link");
        cambiar_color_link(celda,window.document.FormUsuario.txtlink.value);
    }
