curSub = 0;
curMain = 0;
defaultMain = 0;
curLeft = "0000";
timerID = null;
timermID = null;

curthisNav = 0;
curActDiv = 1;

function setSubNav(arg) {
	if (arg !=0) {
		document.getElementById("mn_"+arg).className = "over";
		if (document.getElementById("main_"+arg)) document.getElementById("main_"+arg).style.display = "block";
	}
}

function mainro(arg){
	if (curMain !=0) mainroff();
	document.getElementById("mn_"+arg).className = "over";
	if (defaultMain != 0 && defaultMain != arg) {
		document.getElementById("mn_"+defaultMain).className = "";
		if (document.getElementById("main_"+defaultMain)) document.getElementById("main_"+defaultMain).style.display = "none";
	}
	if (document.getElementById("main_"+arg)) document.getElementById("main_"+arg).style.display = "block";
	curMain = arg;
}
function mainroff(){
	document.getElementById("mn_"+curMain).className = "";
	if (defaultMain != 0) {
		document.getElementById("mn_"+defaultMain).className = "over";
		if (document.getElementById("main_"+defaultMain)) document.getElementById("main_"+defaultMain).style.display = "block";
	}
	if (document.getElementById("main_"+curMain)&&curMain!=defaultMain)document.getElementById("main_"+curMain).style.display = "none";
	clearInterval(timermID);
}
function mainTimer() {
	timermID = setTimeout("mainroff()", 100);
}
function clearmID() {
	clearTimeout(timermID);
}

function startTimer() {
	timerID = setTimeout("subroff()", 100);
}
function clearTimer() {
	clearTimeout(timerID);
}


function ranimage(argImgs, argPath) {
	var numImgs = (argImgs) ? argImgs : 1;
	var pathToImg = (argPath) ? argPath : "images/";
	imgArray = new StringArray(numImgs)
	for (i=0;i<numImgs;i++){
		imgArray[i]=pathToImg+i+".jpg";
	}
	var ran = 60/imgArray.length
	currentdate = new Date()
	core = currentdate.getSeconds()
	core = Math.floor(core/ran)
	return(imgArray[core])
}

var curImg = 1;

function showDrawing(argImg, imgNum) {
	if (imgNum != curImg) {
		document.getElementById("img_"+curImg).className = "";
		document.getElementById("main_image").src = "";
		document.getElementById("main_image").src = argImg;
		//alert("img_"+curImgDiv+"_"+imgNum);
		curImg = imgNum;
		document.getElementById("img_"+imgNum).className = "over";
	}
	return false;
}

var maxDivs = 6;
var curImgDiv = 1;

function showImage(argImg, imgNum) {
	if (imgNum != curImg) {
		document.getElementById("img_"+curImgDiv+"_"+curImg).className = "";
		document.getElementById("main_image").src = "";
		document.getElementById("main_image").src = argImg;
		//alert("img_"+curImgDiv+"_"+imgNum);
		curImg = imgNum;
		document.getElementById("img_"+curImgDiv+"_"+imgNum).className = "over";
	}
	return false;
}

function setImgs(dir) {
	document.getElementById('imgs_'+curImgDiv).style.display = "none";
	if (dir == 'next') {
		var myDiv = curImgDiv<maxDivs ? curImgDiv+1 : 1;
	} else if (dir=='prev') {
		var myDiv = curImgDiv>1 ? curImgDiv-1 : maxDivs;
	} else {
		var myDiv = dir
	}
	document.getElementById('imgs_'+myDiv).style.display = "block";
	document.getElementById("img_nav_"+curImgDiv).className = "";
	document.getElementById("img_nav_"+myDiv).className = "over";
	document.getElementById("img_"+curImgDiv+"_"+curImg).className = "";
	document.getElementById("img_"+curImgDiv+"_1").className = "over";
	curImg = 1;
	curImgDiv = myDiv;
	var newImg = document.getElementById("img_"+curImgDiv+"_"+curImg).href;
	document.getElementById("main_image").src = "";
	document.getElementById("main_image").src = newImg;
}

function isValidEmail(str) {
	return (str.lastIndexOf(".") > 2) && (str.indexOf("@") > 0) && (str.lastIndexOf(".") > (str.indexOf("@")+1)) && (str.indexOf("@") == str.lastIndexOf("@"));
}

function formSubmit(myForm, numChecks) {
	var allchecked = false;
	for (var i=1;i<=numChecks;i++) {
		if (document.getElementById("check_"+i).checked && allchecked==false) {
			allchecked = true;
		}
	}
	if (allchecked==false) {
		alert("Please choose at least one.");
		return false;
	} 
	
	var theForm = document.getElementById(myForm);
	var missingFields = "";
	for (var i=0;i<theForm.length;i++) {
		if (theForm.elements[i].title=="required" && theForm.elements[i].value ==""){
			missingFields += missingFields == "" ? theForm.elements[i].alt : ", "+theForm.elements[i].alt ;
		}
	}
	if (missingFields != "") {
		alert("Please fill in your "+missingFields+".");
		return false;
	}
	
	if (isValidEmail(theForm.email_text.value)==false){
		alert("Please provide a valid email");
		return false;
	} else {
		theForm.submit();
	}
}


