//  EyeCreate's Javascript code, copyright 1999
//  Colour Converter Wizard script 
//  Feel free to borrow and modify this javascript, 
//  but be sure leave this credit in the source!  
//                    -Ken Tuck-    
//        http://www.eye-create.com/
 
//colour conversion
function GiveDec(Hex) {
   if(Hex == "A")
      Value = 10;
   else  if(Hex == "B")
      Value = 11;
   else  if(Hex == "C")
      Value = 12;
   else  if(Hex == "D")
      Value = 13;
   else  if(Hex == "E")
      Value = 14;
   else  if(Hex == "F")
      Value = 15;
   else
      Value = eval(Hex);
   return Value;
}

function GiveHex(Dec) {
   if(Dec == 10)
      Value = "A";
   else  if(Dec == 11)
      Value = "B";
   else  if(Dec == 12)
      Value = "C";
   else  if(Dec == 13)
      Value = "D";
   else  if(Dec == 14)
      Value = "E";
   else  if(Dec == 15)
      Value = "F";
   else
      Value = "" + Dec;
   return Value;
}

function HexToDec(){
   len = document.ConvertHEX.HexInput.value.length
   Input = document.ConvertHEX.HexInput.value;
   Input = Input.toUpperCase();
   IndexChar=document.ConvertHEX.HexInput.value

   a = GiveDec(Input.substring(0, 1));
   b = GiveDec(Input.substring(1, 2));
   c = GiveDec(Input.substring(2, 3));
   d = GiveDec(Input.substring(3, 4));
   e = GiveDec(Input.substring(4, 5));
   f = GiveDec(Input.substring(5, 6));

   x = (a * 16) + b;
   y = (c * 16) + d;
   z = (e * 16) + f;

if (len<6){
alert("You need to put 6 characters in the input box.");
document.ConvertHEX.HexInput.focus();
return false
	} else {
   document.ConvertHEX.RedOutput.value = x;
   document.ConvertHEX.GreenOutput.value = y;
   document.ConvertHEX.BlueOutput.value = z;
   document.getElementById('compone').style.backgroundColor = Input;
    	}
    return true
	}

function sumHexValues(a,b) {
var resultBin=GiveDec(a)+GiveDec(b);
return GiveHex(resultBin);
}	
	
function DecToHex(){
   Red = document.ConvertHEX.RedOutput.value;
   Green = document.ConvertHEX.GreenOutput.value;
   Blue = document.ConvertHEX.BlueOutput.value;
	
   a = GiveHex(Math.floor(Red / 16));
   b = GiveHex(Red % 16);
   c = GiveHex(Math.floor(Green / 16));
   d = GiveHex(Green % 16);
   e = GiveHex(Math.floor(Blue / 16));
   f = GiveHex(Blue % 16);

   colcompone = a + b + c + d + e + f;
   colcomptwo = e + f + a + b + c + d;
   colcompthree = c + d + e + f + a + b;
      
   if (Red.length<1 || Red >255){
	alert("You need to put a number in the Red input box \n or the value you put in is greater than 255.");
	document.ConvertHEX.RedOutput.focus();
	return false
	}
   if (Green.length<1 || Green >255){
	alert("You need to put a number in the Green input box \n or the value you put in is greater than 255.");
	document.ConvertHEX.GreenOutput.focus();
	return false
	}
   if (Blue.length<1 || Blue >255){
	alert("You need to put a number in the Blue input box \n or the value you put in is greater than 255.");
	document.ConvertHEX.BlueOutput.focus();
	return false
	} else {
	document.ConvertHEX.HexInput.value = colcompone;
	document.comp_one.HexInput.value = colcompone;
	document.getElementById('compone').style.backgroundColor = colcompone;
	document.comp_two.HexInput.value = colcomptwo;
	document.getElementById('comptwo').style.backgroundColor = colcomptwo;
	document.comp_three.HexInput.value = colcompthree;
	document.getElementById('compthree').style.backgroundColor = colcompthree;
    }
    return true
}

// puts colours from the colour bar into the compone to be converted and executes to hex to dec code

function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

lck=0;
function r(hex){
if ( lck == 0 ){
document.getElementById('compone').style.backgroundColor = hex;
document.ConvertHEX.HexInput.value=hex;
HexToDec();
DecToHex();
showLayer('compone');
showLayer('comptwo');
showLayer('compthree');
//showLayer('secone');
//showLayer('sectwo');
//showLayer('secthree');
    	}
	}

// -->


