// Change row background color when rolling over a data table row
function rowMO(rowElem,ovr)
{
	if(ovr)
	{
		rowElem.origClass = rowElem.className;
		rowElem.className = "hovered";
	}
	else
		rowElem.className = rowElem.origClass;
}

// Change image on rollover (off/ovr)
function imgRO(imgElem,ovr)
{
	if(ovr)
	{
		imgElem.origSrc = imgElem.src;
		imgElem.src = imgElem.src.replace("_off.","_ovr.");
	}
	else
		imgElem.src = imgElem.origSrc;
}

// Form Error Checking Functions
function hasValue(theField){var fieldType; if(theField[0] && theField[0].type)fieldType = theField[0].type; else fieldType = theField.type; if(fieldType=="text" || fieldType=="password" || fieldType=="textarea" || fieldType=="file" || fieldType=="hidden"){if(theField.value.length==0) return false; else return true;} else if(fieldType.indexOf("select") > -1){var hasAVal = 0; for(i=0;i<theField.options.length;i++){if(theField.options[i].selected && theField.options[i].value != "") hasAVal = 1;} if (hasAVal) return true; else return false;}else if(fieldType=="radio"){var r_ok=0;var fieldlen=theField.length;if(isNaN(fieldlen)){fieldlen = 1; r_ok = theField.checked;}else{for(i=0;i<fieldlen;i++){if(theField[i].checked) r_ok=1;}}if(!r_ok)return false;else return true;}else if(fieldType=="checkbox"){if(theField.checked) return true; else return false;}}
function isNumeric(theValue){if(isNaN(theValue) || theValue == "") return false; else return true;}
function isInteger(theValue){if(isNumeric(theValue) && theValue.indexOf('.') < 0) return true; else return false;}
function isFullName(theValue){if(/[a-z\.]+\s+[a-z\.]+/i.test(theValue)) return true; else return false;}
function isEmail(theValue){if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i.test(theValue)) return true; else return false;}
function isAbsoluteURL(theValue){if(/^.+:\/\/.+\..+$/i.test(theValue)) return true; else return false;}
function isMonth(theValue){if(isInteger(theValue) && theValue>0 && theValue<=12) return true; else return false;}
function isDay(theValue){if(isInteger(theValue) && theValue>0 && theValue<=31) return true; else return false;}
function isYear(theValue){if(isInteger(theValue) && theValue.length==4 && theValue.charAt(0) != '0') return true; else return false;}
function isDate(theMonth,theDay,theYear){var validDateParts=0, isValidDate=0; if(isMonth(theMonth) && isDay(theDay) && isYear(theYear)) validDateParts = 1; enteredDate = new Date(); enteredDate.setMonth(theMonth-1); enteredDate.setDate(theDay); enteredDate.setYear(theYear); if(enteredDate.getDate() == theDay) isValidDate = 1; if(validDateParts && isValidDate) return true; else return false;}
function isAlphaNumPW(theValue){if(/^[a-z_][a-z0-9_]*$/i.test(theValue)) return true; else return false;}
function isSSNum(theValue){if(/^\d{3}[- ]*\d{2}[- ]*\d{4}$/.test(theValue)) return true; else return false;}
function isCCNum(theValue){if(/^((4\d{3})|(5[1-5]\d{2})|(6011))[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}|3[4,7]\d{13}$/.test(theValue)) return true; else return false;}
function isLocalPhoneNum(theValue){var numCount=0;for(j=0; j<theValue.length; j++){if(isInteger(theValue.charAt(j))) numCount++;} if(/^[0-9\-\s\(\)\*#ext\.]+$/i.test(theValue) && numCount>=7) return true; else return false;}
function isPhoneNum(theValue){var numCount=0;for(j=0; j<theValue.length; j++){if(isInteger(theValue.charAt(j))) numCount++;} if(/^[0-9\-\s\(\)\*#ext\.]+$/i.test(theValue) && numCount>=10) return true; else return false;}
function isZip(theValue){if(/^\d{5}(-\d{4})?$/.test(theValue)) return true; else return false;}
function hasFileExtension(theValue,theExtensionList){var reg = new RegExp("\\.(" + theExtensionList.replace(/( |\.)/gi,"").replace(/,/gi,"|") + ")$","gi"); if(reg.test(theValue)) return true; else return false;}
function isHexColor(theValue){if(/^[A-F0-9]{6}$/i.test(theValue)) return true; else return false;}
function onlyUsesCharacters(theValue,theCharList){var reg = new RegExp("^[" + theCharList + "]*$","g"); if(reg.test(theValue)) return true; else return false;}
function usesAnyCharacters(theValue,theCharList){var reg = new RegExp("^\.*[" + theCharList + "]+\.*$","g"); if(reg.test(theValue)) return true; else return false;}

// Help Popup Window
function helpMe(subjct,hlptxt)
{
   if(!window.helpwin); else
      window.helpwin.close();
   helpwin = window.open("about:blank","","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=230");
   helpwin.document.write(""
      + "<html>\n"
      + "<he" + "ad>\n"
      + "	<ti" + "tle>HELP - " + subjct.toUpperCase() + "</ti" + "tle>\n"
      + "	<style type=\"text/css\">\n"
      + "	<!--\n"
	  + "	body {margin:0px; padding:0px;}\n"
      + "	body, td {color:#000000; background:#ffffff; font-size:12px; font-family:Arial, Helvetica, sans-serif;}\n"
      + "	-->\n"
      + "	</style>\n"
      + "</he" + "ad>\n"
      + "<body>\n"
      + "<div align=\"center\" style=\"width:100%; color:#ffffff; background:#000066; padding:3px; font-size:16px; font-weight:bold;\">" + subjct.toUpperCase() + "</div>\n"
      + "<div style=\"width:100%; padding:4px;\">" + hlptxt + "</div>\n"
      + "</body>\n"
      + "</html>");
   helpwin.document.close();
   helpwin.location.reload();
   helpwin.focus();
}

// Topic Selection Form Check
function checkTopicListForm(formElem)
{
	var errmsg = "";
	if (!hasValue(formElem.tid)) errmsg += "A topic has not been selected.";
	if(errmsg != ""){alert("Error: " + errmsg); return false;}else return true;
}

// Request Submission Form Check
function checkNewRequestForm(formElem)
{
	var errmsg = "";
	if (!hasValue(formElem.submitter_firstname)) errmsg += "Your first name is required." + "\n";
	if (!hasValue(formElem.submitter_lastname)) errmsg += "Your last name is required." + "\n";
	if (!hasValue(formElem.submitter_phone) && !hasValue(formElem.submitter_email)) errmsg += "A phone number OR email address must be entered." + "\n";
	if (hasValue(formElem.submitter_phone) && !isPhoneNum(formElem.submitter_phone.value)) errmsg += "The phone number you entered is not valid.  Include an area code if you have not." + "\n";
	if (hasValue(formElem.submitter_email) && !isEmail(formElem.submitter_email.value)) errmsg += "The email address you entered is not valid." + "\n";
	if (!hasValue(formElem.note_message)) errmsg += "A request has not been entered." + "\n";
	var notifyval = "never";
	for(i=0;i<formElem.submitter_notifyon.length;i++)
	{
		if(formElem.submitter_notifyon[i].checked)
			notifyval = formElem.submitter_notifyon[i].value;
	}
	if (notifyval != "never" && !hasValue(formElem.submitter_email)) errmsg += "\n\nYou must specify an email address if you wish to receive completion or update notifications.\n\nIf you do not want to receive notifications, select the \"do not notify me...\" option." + "\n";
	if(errmsg != ""){alert("Please correct the following errors:\n\n" + errmsg); return false;}else return confirmNewRequestForm(formElem);
}

// Request Submission Form Confirmation
function confirmNewRequestForm(formElem)
{
	if(!hasValue(formElem.submitter_phone) && !hasValue(formElem.submitter_email))
	{
		return confirm("Because you have not specified an email address or phone number, we will not be able to contact you if we need additional information.\n\nClick OK to continue or Cancel to enter your contact information.");
	}
	else
		return true;
}