/*******************************************
* Macromedia Default javascript
*
**/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*******************************************
* Form validator
*
* Instructions: Pass in the form id
*
**/
function validateForm(form) {
	errorMsg = "Your submission had the following errors:\n\n";
	errorMsgLength = errorMsg.length;
	
	// Login Form
	if (form == "loginForm") {
		if(isEmpty('userId'))					 																	errorMsg = errorMsg + " - User ID is a required field.\n";
		if(isEmpty('userPassword')) 																		errorMsg = errorMsg + " - Password is a required field.\n";
	}
	// Search Form
	if (form == "searchForm") {
		if(isEmpty('searchCriteria')) 																	errorMsg = errorMsg + " - Please enter some search criteria and click Search.\n";
	}
	
	// Check if errorMsg.length = errorMsgLength
	// if not, throw alert and return false to halt submission
	if (errorMsg.length != errorMsgLength) {
		alert(errorMsg);
		return false;
	} else {
		return true;
	}	
}

/*******************************************
* Form Validation Package
*
* Includes:
*    - isEmpty : Check for empty or null value
*    - isEmail : Check for valid email address
*    - isNumeric : Check for numeric field
*    - isPhoneNbr : Check for phone number in ###-###-#### format
*    - isZipCode : Check for 5-digit or 5+4 digit zip code
*    - isEqual : Checks two field values for equality
**/

function isEmpty(id) {
	value = document.getElementById(id).value;
	if (value == null || value == "") return true; // value is empty
	return false; // value is not empty
}

function isEmail(id) {
	value = document.getElementById(id).value;
	idxAt = value.indexOf("@");
	idxDot = value.indexOf(".");
	if (idxAt == -1 || idxAt == 0 || idxAt == value.length) return false;
	if (idxDot == -1 || idxDot == 0 || idxDot == value.length) return false;
	if (value.indexOf("@", idxAt + 1) != -1 || value.indexOf("@", idxDot + 2) != -1) return false;
	if (value.indexOf(" ") != -1) return false;
	return true;
}

function isNumeric(id) {
	value = document.getElementById(id).value;
	if (isNaN(parseInt(value))) return false; // value is not a number
	return true; // value is a number
}

function isPhoneNbr(id) {
	value = document.getElementById(id).value;
	array = value.split("-")
	
	if (array.length > 3) { // check for 3 values (area code, prefix, and number)
		return false;
	} else {
		areaCode = array[0];
		prefix = array[1];
		phoneNumber = array[2];
		if (areaCode.length > 3 || prefix.length > 3 || phoneNumber.length > 4) { // check for length of fields
			return false;
		} else if (!isNumeric(areaCode) || !isNumeric(prefix) || !isNumeric(phoneNumber)) { // check for only numbers
			return false;
		}
	}
	return true;
}

function isZipCode(id) {
	value = document.getElementById(id).value;
	if (value.indexOf("-") > 1) {
		return false;
	} else if (value.indexOf("-") == 1) {
		array = value.split("-");
		if (!isNumeric(array[0]) || !isNumeric(array[1])) return false;
	} else {
		if (!isNumeric(value)) return false;
	}
	return true;
}

function isEqual(id1, id2) {
	value1 = document.getElementById(id1).value;
	value2 = document.getElementById(id2).value;
	
	if (value1 == value2) {
		return true;
	} else {
		return false;
	}
}