//---------------------------
function testBox(toTest, reqLength) {
//---------------------------
	var iLength = toTest.value.length;
	if (iLength >= reqLength) {
		document.getElementById(toTest.name).style.backgroundColor = "#66ff66";
	}
	else {
		document.getElementById(toTest.name).style.backgroundColor = "#ffcccc";
	}
}

//---------------------------
function resetReqFields(reqForm, reqItems, reqLength) {
//---------------------------
	var i = 0;
	var j = 0;
	
	for (i = 0; i < reqForm.length; ++i) {
		for (j = 0; j < reqLength; ++j) {
			if (reqForm.elements[i].name == reqItems[j]) {
				document.getElementById(reqItems[j]).style.backgroundColor="#ffcccc";
			}
		}
	}
}

//---------------------------
function testEmailForm (toTest) {
//---------------------------		
		var str=toTest.value;
		var at = "@";
		var dot = ".";
		var lat = str.indexOf(at);
		var lstr = str.length;
		var ldot = str.indexOf(dot);

		if (str.indexOf(at)==-1){
		   document.getElementById(toTest.name).style.backgroundColor = "#ffcccc";
		}

		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
		   document.getElementById(toTest.name).style.backgroundColor = "#ffcccc";
		}

		else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    document.getElementById(toTest.name).style.backgroundColor = "#ffcccc";
		}

		else if (str.indexOf(at,(lat+1))!=-1){
				document.getElementById(toTest.name).style.backgroundColor = "#ffcccc";
		}

		else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
				document.getElementById(toTest.name).style.backgroundColor = "#ffcccc";
		}

		else if (str.indexOf(dot,(lat+2))==-1){
		   document.getElementById(toTest.name).style.backgroundColor = "#ffcccc";
		}

		else if (str.indexOf(" ")!=-1){
		   document.getElementById(toTest.name).style.backgroundColor = "#ffcccc";
		}
		
		else {
			document.getElementById(toTest.name).style.backgroundColor = "#66ff66";
		}
}

//Keep in mind that if you back-tab into a field that has already
//been filled, it will kick you back out it.  
//---------------------------
function advancePhone(currentField,nextField,reqLength) {
//---------------------------
	if (currentField.value.length == reqLength) {
    document.getElementById(nextField.name).focus();
  }
  else {
  	document.getElementById(currentField.name).focus();
  }
}