function HSL(a_szRGBColor) {
  var m_szRGBColor = a_szRGBColor;
  this.m_szRGBColor = m_szRGBColor;
  var m_oRGB = new Object();
  this.m_oRGB = m_oRGB;
  var hexHue = null;
  this.hexHue = hexHue;
  var hexSaturation = null;
  this.hexSaturation = hexSaturation;
  var hexLuminance = null;
  this.hexLuminance = hexLuminance;
  var hueRatio = null;
  this.hueRatio = hueRatio;
  var saturationRatio = null;
  this.saturationRatio = saturationRatio;
  var luminanceRatio = null;
  this.luminanceRatio = luminanceRatio;
  var hue = null;
  this.hue = hue;
  var saturation = null;
  this.saturation = saturation;
  var luminance = null;
  this.luminance = luminance;
  var m_bValid = false;
  var m_szHex = "0123456789abcdef";
if(m_szRGBColor) {
  m_szRGBColor = m_szRGBColor.replace(/\s/g,'');
if(0 == m_szRGBColor.search(/#[0-9a-fA-F]{6}/))
{
}
else if(0 == m_szRGBColor.search(/[rR][gG][bB][(]\d {1,3},\d {1,3},\d {1,3}[)]/) ) {
var red10 = m_szRGBColor.match(/[(]\d {1,3},/).toString().replace(/[(]/,'').replace(/,/,'');
var green10 = m_szRGBColor.match(/,\d {1,3},/) .toString().replace(/,/g,'');
var blue10 = m_szRGBColor.match(/,\d {1,3}[)]/).toString().replace(/,/,'').replace(/[)]/, '');
  var redHexHi = Math.floor(red10 / 16);
  var redHexLow = red10 % 16;
  var greenHexHi = Math.floor(green10 / 16);
  var greenHexLow = red10 % 16;
  var blueHexHi = Math.floor(blue10 / 16);
  var blueHexLow = blue10 % 16;
  m_szRGBColor = "#" + m_szHex.charAt(redHexHi) + m_szHex.charAt(redHexLow) + m_szHex.charAt(greenHexHi)+ m_szHex.charAt(greenHexLow) + m_szHex.charAt(blueHexHi) + m_szHex.charAt(blueHexLow);
  this.m_szRGBColor = m_szRGBColor;
}
if(null != m_szRGBColor) {
  m_bValid = true;
  init(this);
}
}
function isValid() {
  return m_bValid;
}
  this.isValid = isValid;
function getHexColor() {
  return m_szRGBColor;
}
  this.getHexColor = getHexColor;
function brightness(a_dRatio) {
  if(!isValid()) return null;
if(a_dRatio > 1.0 || a_dRatio < -1.0) {
  return null;
}
if( 0 == a_dRatio) {
  return m_szRGBColor;
}
  var __HSL = new HSL(m_szRGBColor);
if(a_dRatio >  0) {
  __HSL.luminanceRatio = this.luminanceRatio * (1 + parseFloat(a_dRatio));
if(__HSL.luminanceRatio > 1.0) {
  __HSL.luminanceRatio = 1;
}
}
else {
  __HSL.luminanceRatio = this.luminanceRatio * (-1 * a_dRatio);
}
  setRGBColor(__HSL);
  return __HSL.m_szRGBColor;
}
  this.brightness = brightness;
function contrast(a_dRatio) {
  if(!isValid()) return null;
if(a_dRatio > 1.0 || a_dRatio   < -1.0) {
  return null;
}
if( 0 == a_dRatio) {
  return m_szRGBColor;
}
  var __HSL = new HSL(m_szRGBColor);
if(a_dRatio >    0) {
  __HSL.saturationRatio = this.saturationRatio * (1 + parseFloat(a_dRatio));
if(__HSL.saturationRatio > 1.0) {
  __HSL.saturationRatio = 1;
}
}
else {
  __HSL.saturationRatio = this.saturationRatio * (-1 * a_dRatio);
}
  setRGBColor(__HSL);
  return __HSL.m_szRGBColor;
}
  this.contrast = contrast;
function setLuminance(a_dLuminance) {
if(a_dLuminance > 1) {
  luminance = 1;
}
else if(a_dLuminance < 0) {
  luminance = 0;
}
else {
  luminance = a_dLuminance;
}
  initHex(this);
  initDec(this);
  setRGBColor(this);
}
function setRGBColor(a_oParent) {
if( 0 == a_oParent.saturation ) {
  a_oParent.m_oRGB.red = a_oParent.luminanceRatio * 255;
  a_oParent.m_oRGB.green = a_oParent.luminanceRatio * 255;
  a_oParent.m_oRGB.blue = a_oParent.luminanceRatio * 255;
}
else {
  var temp1, temp2;
if( a_oParent.luminanceRatio < 0.5 ) {
  temp2 = a_oParent.luminanceRatio * ( 1 + a_oParent.saturationRatio );
}
else {
  temp2 = ( a_oParent.luminanceRatio + a_oParent.saturationRatio ) - ( a_oParent.saturationRatio * a_oParent.luminanceRatio );
}
  temp1 = 2 * a_oParent.luminanceRatio - temp2;
  a_oParent.m_oRGB.red = Math.floor(255 * __Hue_2_RGB( temp1, temp2, a_oParent.hueRatio + ( 1 / 3 ) ));
  a_oParent.m_oRGB.green = Math.floor(255 * __Hue_2_RGB( temp1, temp2, a_oParent.hueRatio ));
  a_oParent.m_oRGB.blue = Math.floor(255 * __Hue_2_RGB( temp1, temp2, a_oParent.hueRatio - ( 1 / 3 ) ));
}
  a_oParent.m_oRGB.szColor = '#' + __DecToHex(a_oParent.m_oRGB.red) + __DecToHex(a_oParent.m_oRGB.green) + __DecToHex(a_oParent.m_oRGB.blue);
  a_oParent.m_szRGBColor = a_oParent.m_oRGB.szColor;
  a_oParent.m_oRGB.szRed = a_oParent.m_oRGB.szColor.substr(1,2);
  a_oParent.m_oRGB.szGreen = a_oParent.m_oRGB.szColor.substr(3,2);
  a_oParent.m_oRGB.szBlue = a_oParent.m_oRGB.szColor.substr(5,2);
}
function init(a_oParent) {
  setRGB(a_oParent,m_szRGBColor);
  setHSL(a_oParent,a_oParent.m_oRGB);
}
function setRGB(a_oParent,a_szRGBColor) {
  a_oParent.m_oRGB.szColor = a_szRGBColor.toString();
  a_oParent.m_oRGB.szRed = '0x' + a_szRGBColor.toString().substr(1,2);
  a_oParent.m_oRGB.szGreen = '0x' + a_szRGBColor.toString().substr(3,2);
  a_oParent.m_oRGB.szBlue = '0x' + a_szRGBColor.toString().substr(5,2);
  a_oParent.m_oRGB.red = parseInt(m_oRGB.szRed);
  a_oParent.m_oRGB.green = parseInt(m_oRGB.szGreen);
  a_oParent.m_oRGB.blue = parseInt(m_oRGB.szBlue);
}
function setHSL(a_oParent,a_oRGB) {
  var redRatio = ( a_oRGB.red / 255 );
  var greenRatio = ( a_oRGB.green / 255 );
  var blueRatio = ( a_oRGB.blue / 255 );
  var dMin = Math.min( redRatio, greenRatio, blueRatio );
  var dMax = Math.max( redRatio, greenRatio, blueRatio );
  var dDelta = dMax - dMin;
  a_oParent.luminanceRatio = ( dMax + dMin ) / 2;
if( dDelta == 0 ) {
  a_oParent.hueRatio = 1;
  a_oParent.saturationRatio = 0;
}
else {
if( a_oParent.luminanceRatio < 0.5 ) {
  a_oParent.saturationRatio = dDelta / ( dMax + dMin );
}
else {
  a_oParent.saturationRatio = dDelta / ( 2 - dMax - dMin );
}
  var dDeltaRed = ( ( ( dMax - redRatio ) / 6 ) + ( dDelta / 2 ) ) / dDelta;
  var dDeltaGreen = ( ( ( dMax - greenRatio ) / 6 ) + ( dDelta / 2 ) ) / dDelta;
  var dDeltaBlue = ( ( ( dMax - blueRatio ) / 6 ) + ( dDelta / 2 ) ) / dDelta;
if( redRatio == dMax ) {
  a_oParent.hueRatio = dDeltaBlue - dDeltaGreen;
}
else if( greenRatio == dMax ) {
  a_oParent.hueRatio = ( 1 / 3 ) + dDeltaRed - dDeltaBlue;
}
else if( blueRatio == dMax ) {
  a_oParent.hueRatio = ( 2 / 3 ) + dDeltaGreen - dDeltaRed;
}
if( a_oParent.hueRatio < 0 ) {
  a_oParent.hueRatio += 1;
}
if( a_oParent.hueRatio >      1 ) {
  a_oParent.hueRatio -= 1;
}
}
  initHex(a_oParent);
  initDec(a_oParent);
}
function initHex(a_oParent) {
  a_oParent.hexHue = '0x' + __ratioToHex(a_oParent.hueRatio);
  a_oParent.hexSaturation = '0x' + __ratioToHex(a_oParent.saturationRatio);
  a_oParent.hexLuminance = '0x' + __ratioToHex(a_oParent.luminanceRatio);
}
function initDec(a_oParent) {
  a_oParent.hue = parseInt(a_oParent.hexHue);
  a_oParent.saturation = parseInt(a_oParent.hexSaturation);
  a_oParent.luminance = parseInt(a_oParent.hexLuminance);
}
function __ratioToHex(a_dRatio) {
  var hexHi = 255 * a_dRatio;
  var hexLow = Math.floor(hexHi % 16);
  var hexHi = Math.floor(hexHi / 16);
  return m_szHex.charAt(hexHi) + m_szHex.charAt(hexLow);
}
function __DecToHex(a_dec) {
  var hexLow = Math.floor(a_dec % 16);
  var hexHi = Math.floor(a_dec / 16);
  return m_szHex.charAt(hexHi) + m_szHex.charAt(hexLow);
}
function __Hue_2_RGB( a_temp1, a_temp2, a_hue ) {
if( a_hue       < 0 ) {
  a_hue += 1;
}
if( a_hue >        1 ) {
  a_hue -= 1;
}
if( ( 6 * a_hue )         < 1 ) {
  return ( a_temp1 + ( a_temp2 - a_temp1 ) * 6 * a_hue );
}
if( ( 2 * a_hue ) < 1 ) {
  return ( a_temp2 );
}
if( ( 3 * a_hue ) < 2 ) {
  return ( a_temp1 + ( a_temp2 - a_temp1 ) * ( ( 2 / 3 ) - a_hue ) * 6 )
}
  return a_temp1;
}
}
