//header feature image swap
var currentimg = 1;
var imgcount = 7;
var imgpath = "/images/anim_0";
var imgext = ".jpg";

// rollover stuff
var iDir = "/images/";
var iExt = "gif";
var iList = "nav_camera_,nav_iam_,nav_whats_,nav_links_,nav_contact_,nav_sms_,nav_home_,head_06";


// DO NOT TOUCH ANYTHING BELOW THIS POINT

function popIt(filePath, winName, thisWidth, thisHeight) {
window.open(filePath,
	winName,
	'status=no,scrollbars=no,width=' + 
	thisWidth 
	+ ',height=' + 
	thisHeight 
	+ ',left=100,top=100,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0'
	);
}

function refreshheader() {
			if (currentimg > imgcount) {
				currentimg = 1;
			}
			document.images["headerfeature"].src = "/images/anim_0" + currentimg + imgext;
			currentimg = currentimg + 1;
			setTimeout("refreshheader()", 7000);
}

var d = document;
var iA = iList.split(',');
if 	(d.images) { 
	var iO = new Array();
	for	(j = 0; j < iA.length; j++) {
		iO[j] = new Image();
		iO[j].src = iDir + iA[j] + "b." + iExt;
	 	}
	}
	
function 	out(iName,newDir,newType) { 
			i = eval("d." + iName);
			i.src = iDir + iName + "a." + iExt;
			}
			
function 	over(iName,newDir,newType) { 
			i = eval("d." + iName);
			i.src = iDir + iName + "b." + iExt;
			}

function swapType(type){
	iExt = type;
}

var errMsg;
var thisForm;
var fieldsArray = new Array();;
var errorSwitch;

//master function
function valForm(){
	errorSwitch = 0;
	initValForm();
	testVals();
	outputMsg();
	if 	(errorSwitch){
		alert(errMsg);
		return false
		}
	}

// set up function for second level arrays
function fieldRecord(fieldName, logicalName, test) {
	this.fieldName = fieldName;
	this.logicalName = logicalName;
	this.test = test;
	this.error = 0; //default error to false
	}

//loop through fieldsArray and run the appropriate test for each field
//update the error status for each field
function testVals(){
	for (i=0;i<fieldsArray.length;i++){
		var thisType = eval("thisForm." + fieldsArray[i].fieldName + ".type");
		var thisError = fieldsArray[i].error;
		var thisTest = fieldsArray[i].test;
		
		if 	(thisType == "select-one") {
			var thisVal = eval("thisForm." + fieldsArray[i].fieldName + ".options[thisForm." + fieldsArray[i].fieldName + ".selectedIndex].value")
			} else {
			var thisVal = eval("thisForm." + fieldsArray[i].fieldName + ".value")
			}
		
		if 	(thisTest == "str") {
				thisError = strTest(thisVal);
			} else if	(thisTest == "int") {
				thisError = intTest(thisVal);			
			} else if	(thisTest == "eml") {
				thisError = emlTest(thisVal);
			} else {
				alert('unknown test');
				break
			}
			
		fieldsArray[i].error = thisError;
		}
	}

//strTest tests that the field is not blank
function strTest(thisVal){
	thisError = 0;
	if 	(thisVal == "") {
		thisError = 1;
		}
	return thisError;
	}

//intTest tests that the field is not blank and that it is a number
function intTest(thisVal){
	thisError = 0;
	if 	(thisVal == "" || isNaN(thisVal)) {
		thisError = 1;
		}
	return thisError;
	}

//emlTest tests that the field is not blank and that it contains @ & .
function emlTest(thisVal){
	thisError = 0;
	if 	((thisVal == "" || thisVal.indexOf('@', 0) == -1) || thisVal.indexOf('.') == -1) {
		thisError = 1;
		}
	return thisError;
	}

//check the error code on each field and build error message
function outputMsg(){
	for (i=0;i<fieldsArray.length;i++){
	 if (fieldsArray[i].error){
	 		errorSwitch = 1;
	 		errMsg = errMsg + "- " + fieldsArray[i].logicalName + "\n";
	 		}
		}
	}
