//Site wide javascript
function chkSearch (strVal,msg) {
	if(strVal.length == 0){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

////////////////////> roll over script </////////////////////////
///////// place the following style script in header page ///////
/*///////////////////////////////////////////////////////////////
<script language="JavaScript1.2" type="text/javascript">
//////////////////////> CONFIGURATION <//////////////////////////
var iDir = "images/"; 					//path to images
var iExt = "gif"; 						//extension of image files
var iList = "nav01,nav02,nav03"; 		//list of image names
/////////////////////////////////////////////////////////////////
</script>
*////////////////////////////////////////////////////////////////
///////// and then place the following in the <a> tags //////////
///// EG: onmouseover="over('nav01'); onmouseout="out('nav01'); //////
/////////////////////////////////////////////////////////////////
if (typeof(iList) == "undefined") var iList = "";
if (typeof(iDir) == "undefined") var iDir = "../images/";
if (typeof(iExt) == "undefined") var iExt = "gif";

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;
			}
/////////////////////////////////////////////////////////////////



///////////////> swapType - swap img type script <///////////////
///// this allows you to swap image type from the default////////
//EG:onmouseover="swapType('jpg');b('image01');swapType('gif');//
//this swaps type to jpg does roll over and swaps back to gif ///
/////////////////////////////////////////////////////////////////
function swapType(type){
	iExt = type;
}
/////////////////////////////////////////////////////////////////



//////////////> valForm - form validation script <///////////////
///////// place the following style script in form page /////////
/////////// the fields array can be as long as required /////////
/*///////////////////////////////////////////////////////////////
<script language="JavaScript" type="text/javascript">
function initValForm(){
	thisForm = document.forms[0];
	errMsg = "You have not filled out all the required fields \ncorrectly. Please double check the following \nfields: \n\n";	
	fieldsArray[0] = new fieldRecord("entrantFname","First Name","str");
	fieldsArray[1] = new fieldRecord("stateId","State","int");
	fieldsArray[2] = new fieldRecord("entrantEmail","Email","eml");
	}
</script>
*////////////////////////////////////////////////////////////////
////////// and then place the following in the form tag /////////
///////////////// onsubmit="return valForm()" ///////////////////
/////////////////////////////////////////////////////////////////

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";
	 		}
		}
	}
/////////////////////////////////////////////////////////////////