/* TEXT */
function changeText(e,index){
	var key;
	if(isIE()){
		key = window.event.keyCode;
	}else{
		key = e.which;
	}
	if(validChar(key)){
		shtuffText[index] = String.fromCharCode(key);
		if(index==5){
			letter0.focus();
		}
		else{
			eval("letter" + (index + 1) + ".focus()");
		}
		runPretties(patternType);
	}
}

function checkGoBack(e,index){
	var key;
	if(isIE()){
		key = window.event.keyCode;
	}else{
		key = e.which;
	}
	if((key==8)||(key==127)){
		if(index==0){
			letter5.focus();
		}
		else{
			eval("letter" + (index - 1) + ".focus()");
		}
	}
}

function randomText(){
	letter0.value = shtuffText[0] = String.fromCharCode((Math.floor(Math.random()*96)+31));
	letter1.value = shtuffText[1] = String.fromCharCode((Math.floor(Math.random()*96)+31));
	letter2.value = shtuffText[2] = String.fromCharCode((Math.floor(Math.random()*96)+31));
	letter3.value = shtuffText[3] = String.fromCharCode((Math.floor(Math.random()*96)+31));
	letter4.value = shtuffText[4] = String.fromCharCode((Math.floor(Math.random()*96)+31));
	letter5.value = shtuffText[5] = String.fromCharCode((Math.floor(Math.random()*96)+31));
}

/* TIME */
function runBeat(){
	clearInterval(intervalID);
	intervalID = setInterval("runPretties(patternType)",dabeat.value);
}

function runBeatRandom(){
	clearInterval(intervalID);
	intervalID = setInterval("randomText(); runPretties(patternType);",dabeat.value);
}

/* COLOR */
function activeShade(newshade){
	shade = newshade;
	redlink.className = "normal";
	greenlink.className = "normal";
	bluelink.className = "normal";
	doglink.className = "normal";
	rgblink.className = "normal";
	switch(newshade){
		case red:
			redlink.className = "normal bold";
			break;
		case green:
			greenlink.className = "normal bold";
			break;
		case blue:
			bluelink.className = "normal bold";
			break;
		case dog:
			doglink.className = "normal bold";
			break;
		case rgb:
			rgblink.className = "normal bold";
			break;
	}
}

function getColor(){
	var i,randnum;
	var ret="#";
	if(shade==6){
		var blue;
		var primary = getHex();
		var secondary = getHex();
		if(getHex().charCodeAt(0)>57){
			if(primary.charCodeAt(0)<69){
				if(primary.charCodeAt(0)==56){
					blue = 'A' + secondary;
				}
				else if(primary.charCodeAt(0)==57){
					blue = 'B' + secondary;
				}
				else{
					blue = String.fromCharCode((primary.charCodeAt(0)+2).toString()) + secondary;
				}
			}
			else{
				blue="FF"
			}
		}
		else{
			blue = primary + secondary;
		}
		ret += primary + secondary + primary + secondary + blue;
	}
	else{
		for(i=0; i<6; i++){
			if(shade==i){
				ret += 'F';
			}
			else{
				ret += getHex();
			}
		}
	}
	return ret;
}

function changeShade(newshade){
	activeShade(newshade);
	runPretties(patternType);
}
