onMenu = false;
menuItem = null;

function setCursor(who,what){
	document.getElementById(who).style.cursor = what;
}

function menu(which, id){
	if(which && id != null){
		if(menuItem != null && menuItem != id){
			onMenu = false;
			menuCheck();
		}
		onMenu = true;
		menuItem = (id.indexOf('_dd') != -1) ? id : id+'_dd';
		document.getElementById(menuItem.slice(0,-3)).src = 'images/'+menuItem.slice(0,-3)+'_on.gif';
		if(document.getElementById(menuItem) != null){
			document.getElementById(menuItem).style.visibility = 'visible';
		}
	}
	else{
		onMenu = false;
		setTimeout('menuCheck(menuItem)',2000);
	}
}

function menuCheck(id){
	if(onMenu == false && menuItem != null){
		document.getElementById(menuItem.slice(0,-3)).src = 'images/'+menuItem.slice(0,-3)+'.gif';
		if(document.getElementById(menuItem) != null){
			document.getElementById(menuItem).style.visibility = 'hidden';
		}
	}
}

onShow = "content-home";
function show(which){
	if(onShow != null && which != onShow){
		document.getElementById(onShow).style.visibility = 'hidden';
		document.getElementById(onShow+'_subnav').style.visibility = 'hidden';
	}
	document.getElementById(which).style.visibility = 'visible';
	document.getElementById(which+'_subnav').style.visibility = 'visible';
	onShow = which;
	randomImage();
}

onRandom = [1,2];
function randomImage(){
	newRandom = onRandom;
	randI = 1;
	while(randI < 3){
		newRand = Math.floor(Math.random()*9)+1;
		randCheck = false;
		for(i=0; i<newRandom.length; i++){
			if(parseInt(newRandom[i]) == newRand){
				randCheck = true;
			}
		}
		if(randCheck == false){
			newRandom[newRandom.length] = newRand;
			randI++;
		}
	}
	onRandom = newRandom.slice(-2);
	for(i=1; i<=onRandom.length; i++){
		document.getElementById('img'+i).src = 'images/img_rand_'+onRandom[i-1]+'.jpg';
	}
}

it = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
is = new Array(3,15,0);
iss = new Array(3,15,0);

which = 2;
dir = '+';
function flavor(){
	if((is[which] < 15 || (is[which] == 15 && iss[which] < 15)) && dir == '+'){
		if(iss[which] < 15) iss[which]++;
		else{
			is[which]++;
			iss[which] = 0;
		}
	}
	else if(dir == '+'){
		dir = '-';
		which = (which > 0) ? which - 1 : 2;
		iss[which]--;
	}
	if((is[which] > 0 || (is[which]== 0 && iss[which] > 0)) && dir == '-'){
		if(iss[which] > 0) iss[which]--;
		else{
			is[which]--;
			iss[which] = 15;
		}
	}
	else if(dir == '-'){
		dir = '+';
		which = (which > 0) ? which - 1 : 2;
		iss[which]++;
	}
	document.getElementById('content-back').style.backgroundColor = it[is[0]]+it[iss[0]]+it[is[1]]+it[iss[1]]+it[is[2]]+it[iss[2]];
	document.getElementById('content').style.borderColor = it[is[0]]+it[iss[0]]+it[is[1]]+it[iss[1]]+it[is[2]]+it[iss[2]];
	setTimeout('flavor(which,dir)',50);
}

function formFlavor(which,where,color){
	eval("which.style."+where+"=color");
}
function superTrim(what){
	return what.replace(/ /g,'');
}
function emailValid(email){
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(email);
}
function formCheck(){
	cntctForm = document.cntct;
	isOK = true;
	if(superTrim(cntctForm.fname.value).length==0) isOK = false;
	if(superTrim(cntctForm.lname.value).length==0) isOK = false;
	if(superTrim(cntctForm.email.value).length==0 || !emailValid(cntctForm.email.value)) isOK = false;
	if(superTrim(cntctForm.phone.value).length==0) isOK = false;
	if(superTrim(cntctForm.time.value).length==0) isOK = false;
	if(superTrim(cntctForm.etc.value).length==0) isOK = false;
	if(isOK){
		document.getElementById('contact-submit').style.visibility='visible';
		return true;
	}
	else{
		alert("You need to fill in all the fields."+((!emailValid(cntctForm.email.value))?"\nPlease make sure you enter a valid email address":""));
		return false;
	}
}

