﻿// JScript File

function changeHeaderColor(button,txBoxID,lblID)
{
    //var a = "";
//    document.getElementById(txBoxID).value = button.style.backgroundColor;
    //var currentColor = document.getElementById("txSelectedColor");
    //currentColor.value = button.style.backgroundColor;
    var el = button;//document.getElementById(button);

    if(document.defaultView && document.defaultView.getComputedStyle){ // IS MOZILLA BASED BROWSER //;
        var bg = document.defaultView.getComputedStyle(el, '').getPropertyValue("background-color");
        
        var colorValue= document.defaultView.getComputedStyle(el,'').getPropertyCSSValue("background-color").getRGBColorValue();
        
        var hexcolor='#'+colorValue.red.getFloatValue(1).toString(16).replace(/^.$/,'0$&')+colorValue.green.getFloatValue(1).toString(16).replace(/^.$/,'0$&')+colorValue.blue.getFloatValue(1).toString(16).replace(/^.$/,'0$&');
        //alert('DOM way: '+hexcolor);
        document.getElementById(txBoxID).value = hexcolor;
        document.getElementById(lblID).style.backgroundColor = hexcolor;
    }

    else if(document.uniqueID && el.currentStyle){ // IS INTERNET EXPLORER //;
        //alert('IE way: '+el.currentStyle.backgroundColor);
        document.getElementById(txBoxID).value = el.currentStyle.backgroundColor;
        document.getElementById(lblID).style.backgroundColor = el.currentStyle.backgroundColor;
    }
}

function changeHeader(txBox,lblID)
{
    try
    {       
        document.getElementById(lblID).style.backgroundColor = txBox.value;
    }
    catch(err)
    {
        txBox.value = "#B2B4BF";
        document.getElementById(lblID).style.backgroundColor = txBox.value;
        alert('Invalid hexa color!');
    }
}

function changeFontColor(button,txBoxID,lblID)
{
    //var a = "";
    //alert(getEltBackgroundColor (button.style.backgroundColor))
//    document.getElementById(txBoxID).value = button.style.backgroundColor;
    //var currentColor = document.getElementById("txSelectedColor");
    //currentColor.value = button.style.backgroundColor;
    var el = button;//document.getElementById(button);

    if(document.defaultView && document.defaultView.getComputedStyle){ // IS MOZILLA BASED BROWSER //;
        var bg = document.defaultView.getComputedStyle(el, '').getPropertyValue("background-color");
        
        var colorValue= document.defaultView.getComputedStyle(el,'').getPropertyCSSValue("background-color").getRGBColorValue();
        
        var hexcolor='#'+colorValue.red.getFloatValue(1).toString(16).replace(/^.$/,'0$&')+colorValue.green.getFloatValue(1).toString(16).replace(/^.$/,'0$&')+colorValue.blue.getFloatValue(1).toString(16).replace(/^.$/,'0$&');
        //alert('DOM way: '+hexcolor);
        document.getElementById(txBoxID).value = hexcolor;
        document.getElementById(lblID).style.color = hexcolor;
    }

    else if(document.uniqueID && el.currentStyle){ // IS INTERNET EXPLORER //;
        //alert('IE way: '+el.currentStyle.backgroundColor);
        document.getElementById(txBoxID).value = el.currentStyle.backgroundColor;
        document.getElementById(lblID).style.color = el.currentStyle.backgroundColor;
    }
    //alert(document.getElementById(lblID).style.backgroundColor);
}

function changeFont(txBoxID,lblID)
{
    try
    {
        document.getElementById(lblID).style.color = txBoxID.value;
    }
    catch(err)
    {
        txBoxID.value = "#000000";
        document.getElementById(lblID).style.color = txBoxID.value;
        alert('Invalid hexa color!');
    }
}

function RGB2Color(r,g,b)
{
    return '#' + byte2Hex(r) + byte2Hex(g) + byte2Hex(b);
}
