function linkparse () {
	if (document.getElementById && document.getElementById("current_nav_item")) {
		var item=document.getElementById("current_nav_item");		
		var section=item.innerHTML;
		var link=item.getAttribute("href");		
		var h3=document.getElementById("dynamic");
		h3.innerHTML = section;		
		h3.href=link;
	}
	if (document.getElementById) {
		document.getElementById("footer").style.display="block";
	}
}
if (window.attachEvent) {
	window.attachEvent("onload", linkparse)
} else {
	window.onload=linkparse;
}


function emailCheck (fieldname,blankOK,emailStr) {

var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

if(emailStr=="") {
	if (blankOK==true) {
		return true;
	} else {
		alert(fieldname + " cannot be blank");
		return false;
	}
}
	emailStr = emailStr.replace(/\s/g,"");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
	alert(fieldname + ": Seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert(fieldname + ": The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert(fieldname + ":Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert(fieldname + ":The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   two or more letter domain or country (allowing for new >3 domains), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ) {
   // the address must end in a two or more letter domain name .
   alert(fieldname + ":The address must end in a two or more letter domain (e.g., com, edu, org).")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr=": This address is missing a hostname!"
   alert(fieldname + errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

function notBlank(fieldname,value){

if (value == "") {
	alert(fieldname + " can't be blank");
	return false;
}
return true;
}
function notNull(fieldname,value){

if (value == null) {
	alert(fieldname + ": a value must be selected");
	return false;
}
return true;
}


$(document).ready(function(){

	/*check for  a newsletter signup contact form*/
	if ($("#ContactForm"))
	{
		/*alert("yep -- there is a contact form");*/
		
		/*check for a querystring*/
		if (window.location.search)
		{			
			/*alert("yep -- there is a querystring");*/
			
			/*check for an email address name/value pair*/
			if (window.location.search.indexOf("em")>-1)
			{			
				/*alert("yep -- there is an email address in the querystring");*/		
				
				/*extract the email address from the querystring by splitting it into substrings*/
				
				var email = window.location.search.split("em=")[1]; 
				/*alert(email);*/
				
				/*check for additional name value pairs, chop them if they exist, and de-urlencode email address*/
				if (email.indexOf("&")>0)
				{
					var email = email.split("&")[0];
					var email = unescape(email);
					/*alert(email);*/
					
					
					/*Now find the email input field, and populate with the extracted, properly formatted email address*/
					
					$("input[name='email_address']").val(email)
					
				}
				
			}	
			
		}
		
	}
				
	/*Here's the above code in one line.		
		
	if ($("#ContactForm")&&window.location.search.indexOf("em")>-1) $("input[name='email_address']").val(unescape(window.location.search.split("em=")[1].split("&")[0]))    
	*/	
				
						   
})


