/* =========================================================================
AUTHOR: JNJG , Team Wolfguard Design
DATE  : 2/19/2006
============================================================================ */
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   return retValue; // Return trimmed string
}

function checkEmail(m) {
	var blnResult = true;
	if (/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(m)){
		//Email address is valid
	}
	else {
		blnResult = false
	}
	return blnResult
}

function validateContact(c) {
	var msg;
	msg='';
	if (trim(c.elements['strEmail'].value)==''){
		msg += "- You must enter an email address for this message.\n";
		c.strEmail.style.backgroundColor="#FFFF80";
	}
	if (trim(c.elements['strEmail'].value)!=''){
		if (checkEmail(trim(c.elements['strEmail'].value))==false){
			msg += "- Please enter a valid EMail address.(ie: name@company.com)\n";
			c.strEmail.style.backgroundColor="#FFFF80";
		}
	}
	if (trim(c.elements['strComments'].value)==''){
		msg += "- You must enter comments for this message.\n";
		c.strComments.style.backgroundColor="#FFFF80";
	}
	if (msg.length>0){
		c.elements['strName'].focus();
		alert(msg);
		return false;
	}
	else {
		return true;
	}
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") &&
				anchor.getAttribute("rel") == "external"){
				anchor.target = "_blank";
			}
		}
}
window.onload = externalLinks; 
