/*color selector copywrite 2003 Techier.com. All rights reserved. You can put up a link to this site to use the color selector as a free service, but please don't copy this to other sites without permission. The menu itself is from cooljsmenu at http://javascript.cooldev.com/scripts/coolmenu/
*/
function getStyleBySelector( selector )
{
    var sheetList = document.styleSheets;
    var ruleList;
    var i, j;

    /* look through stylesheets in reverse order that
       they appear in the document */
    for (i=sheetList.length-1; i >= 0; i--)
    {
        ruleList = sheetList[i].cssRules;
        for (j=0; j<ruleList.length; j++)
        {
            if (ruleList[j].type == CSSRule.STYLE_RULE &&
ruleList[j].selectorText == selector)
            {
                return ruleList[j].style;
            }   
        }
    }
    return null;
}	
var IE = document.all?true:false;
if (document.getElementById) {
	brwser=(window.opera)? "opera":(document.all)?"ie5":"ns6";
	} else brwser="X";

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

var Color= new Array("00","33","66","99","CC","FF");
//var IDLevel1 = new Array("cmimenu1_0b", "cmimenu1_0n", "cmimenu1_0o","cmimenu1_0e","cmimenu1_8b","cmimenu1_8n","cmimenu1_8o","cmimenu1_8e");//Top menu level div ID numbers assigned by menu_test.js

// Set-up to use getMouseXY function onMouseMove

obj="rainbow";


document.getElementById(obj).onmousemove = getMouseXY;
document.getElementById(obj).onmouseout = mouseout;
document.getElementById(obj).onclick = selectMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;
var bluem ; var redm; var greenm; var blueredm; var redarraym; var greenkeym;
var movingcolor="#FFFFFF";
// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX
    tempY = event.clientY
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
 // if (tempX < 0){tempX = 0}
 // if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
    moveX=tempX -352;
  moveY=tempY - 225;
   if (moveX < 2) moveX = 1 ;
  if (moveY < 2) moveY = 1  ;
    if (moveX >430) moveX =430 ;
  if (moveY >71 ) moveY =71  ;
 // document.Show.MouseX.value = moveX;
//  document.Show.MouseY.value = moveY;
  //which color square is the mouse over? each square is 12 x 12 pixels. m means moving
  greenkeym = Math.round((moveY -6)/12);
  if (greenkeym<0) greenkeym=0;
	blueredm = Math.round((moveX -6)/12);
	  if (blueredm<0) blueredm=0;
	redarraym = 0;
	while (blueredm > 5) {
	blueredm-=6;
	redarraym+=1;
	}
	colortotalm =blueredm+redarraym+greenkeym;
	
	bluem = Color[blueredm];
	redm = Color[redarraym];
	greenm = Color[greenkeym];
	movingcolor="#"+redm+greenm+bluem;
	if (typeof movingcolor=="string") {
	//netscape error - fails to display value and never recovers.
	if (movingcolor.substring(0,1)!="#") movingcolor="#FFFFFF";
	//didn't help
	document.getElementById("Colormove2").value=movingcolor;
	document.getElementById("Colormove2").style.backgroundColor=movingcolor;
	//document.Show.Colormove.value = movingcolor;
	//document.Show.Colormove.style.backgroundColor=movingcolor;
	document.getElementById("colorme").style.backgroundColor=movingcolor;
	}
	
document.getElementById("colorme").style.color=(colortotalm<5)? "#ffffff":"000000";
	document.Show.Colormove.style.color=(colortotalm<5)? "#ffffff":"000000";
 	return true
	}
function switchnum(nm) {
		
		switch(nm) {
		case 0: return "0";
		case 1: return "1";
		case 2: return "2";
		case 3: return "3";
		case 4: return "4";
		case 5: return "5";
		case 6: return "6";
		case 7: return "7";
		case 8: return "8";
		case 9: return "9";
		case 10: return "A";
		case 11: return "B";
		case 12: return "C";
		case 13: return "D";
		case 14: return "E";
		case 15: return "F";
		default:  return "F";
		}
	}
function switchsinglecolor(colr){
	var firstdigit;var seconddigit;var output;
	seconddigit=eval(colr)%16;
	firstdigit=(eval(colr) - seconddigit)/16; 
	output=switchnum(firstdigit)+switchnum(seconddigit);//string "0"!
	return output;
	}
function switchcolorformat(rrr,ggg,bbb) {
var newcol;
newcol="#"+switchsinglecolor(rrr)+switchsinglecolor(ggg)+switchsinglecolor(bbb);
return newcol;
}	
function mouseout () {
	var bkg=document.getElementById("Bodytextarea2").style.backgroundColor;
 if (bkg.substring(0,3)=="rgb"){
	//find the 2 commas and use that info go get the numbers
	var j=0;
	var comma = new Array(0,1);
		var lg=bkg.length;
		
		for (i=5;i<lg;i++) {
			if (bkg.substring(i,i+1)==",") {
			comma[j]=i;
			j++;
			}
		}
	
	
	var rr=bkg.substring(4,comma[0]);
	var gg=bkg.substring((comma[0]+1),comma[1]);
	var bb=bkg.substring((comma[1]+1),lg-1);
	
	bkg2=switchcolorformat(rr,gg,bb);
	
	} else {
	bkg2=bkg;
	}
	document.getElementById("Colormove2").value=bkg2;
	document.getElementById("Colormove2").style.backgroundColor=bkg;
	document.getElementById("colorme").style.backgroundColor=bkg;
	document.getElementById("colorme").style.color="000000";
	document.getElementById("Colormove2").style.color="000000";
	//document.Show.Colormove.style.color="000000";
	return true;
}	
	
function whatsup() {
alert (document.Show.Colormove.value);
}

function selectMouseXY(e) {

  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX
    tempY = event.clientY
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  clickedX=tempX -352;
  clickedY=tempY - 225;
  //document.Show.MouseX2.value =  clickedX;
 // document.Show.MouseY2.value = clickedY;
  //document.Show.Colormove.value = document.Show.Idtarget.value;
 	greenkey = Math.round((clickedY -6)/12);
	if (greenkey<0) greenkey=0;
	bluered = Math.round((clickedX -6)/12);
	if (bluered<0) bluered=0;
	redarray = 0;
	while (bluered > 5) {
	bluered-=6;
	redarray+=1;
	}
	colortotal = greenkey + bluered+redarray;
	
	green = Color[greenkey];
	blue = Color[bluered];
	red = Color[redarray];
	selnewcol="#"+red+green+blue;
//rgbnewcol=convertformat(red,green,blue);

 	document.Show.Colorselected.value = selnewcol;
    document.Show.Colorselected.style.backgroundColor=selnewcol;
    document.Show.Colorselected.style.color=(colortotal<5)? "#ffffff":"000000";
  
//combine 2 drop downs targets here
   lvl = levelwhich();
   tgt=document.Show.Idtarget.value;
	if (lvl!=3)  tgt+=document.Show.targetval.value;
	changeColor(selnewcol,tgt);
   

   
   
   return true
	}

//-->
 
