function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

var type = "IE";	//Variable used to hold the browser name
BrowserSniffer();
function validateSubmit() {
    var formName = document.Submit;
	if (validateEmail(formName.userEmail.value) == false) {
		alert("Email is empty/invalid. Please provide a valid email.");		
		return false;
	} else {
		if (validateEmpty(formName.userName.value) == false) {
			alert("The name entry is empty. Please provide a first name.");			
			return false;
		} else {
			return true;
		}
	}
}

//detects the capabilities of the browser
function BrowserSniffer() {
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";		//Opera
	else if (document.all) type="IE";														//Internet Explorer e.g. IE4 upwards
	else if (document.layers) type="NN";													//Netscape Communicator 4
	else if (!document.all && document.getElementById) type="MO";							//Mozila e.g. Netscape 6 upwards
	else type = "IE";		//I assume it will not get here
}

function ChangeMessage(id, str) {
	if (type=="IE") {
		document.all[id].innerHTML = str;
	}
	if (type=="NN") { 
		document.layers[id].document.open();
		document.layers[id].document.write(str);
		document.layers[id].document.close();
	}
	if (type=="MO" || type=="OP") {
		document.getElementById(id).innerHTML = str;
	}
}

function ShowIt(current) {			
	if (type=="IE") {
		ms=document.all[current];
		ms.style.visibility = "visible";				
	}
	if (type=="NN") {
		ms=document.layers[current];
		ms.visibility = "visible";				
	}
	if (type=="MO" || type=="OP") {
		ms=document.getElementById(current);
		ms.style.visibility = "visible";				
	}	
}

function HideIt(current) {
	if (type=="IE") {
		ms=document.all[current];		
		ms.style.visibility = "hidden";
	}
	if (type=="NN") {
		ms=document.layers[current];
		ms.visibility = "hidden";
	}
	if (type=="MO" || type=="OP") {
		ms=document.getElementById(current);
		ms.style.visibility = "hidden";
	}		
}

// Trim leading and trailing white space
function trim(str) {
  return str.replace(/^\s+|\s+$/g, '')
};

// Validate the email address
function validateEmail(userEmail) {
	var re = false;        
	var ea = trim(userEmail);        
	var pattern = /^[a-zA-Z][\w\-\.]{0,19}\@[a-zA-Z][\-\w]+(\.[a-zA-Z\-][\-\w]+)+$/;
	if (ea != "" && pattern.test(ea)) {
		re = true;
	}
	return re;
}

// Validate the name
function validateName(userName) {
	var re = false;        
	var na = trim(userName);        
	var pattern = /^[a-zA-Z][a-zA-Z\d_\s\.\'\-]{1,49}$/;
	if (na != "" && pattern.test(na)) {
		re = true;
	}
	return re;
}

// Check whether it is empty or not
function validateEmpty(nm){
	var userName = trim(nm);
	return userName==""? false : true;
}


// This code taken from 
//  http://www.brucelawson.co.uk/2005/opening-links-in-new-windows-in-xhtml-strict-2/
// to make sure that links that used to use target="_blank"(which is not Strict XHTML)
// now comply and also are accessible.
// NOTE - you must use the target="_blank" attribute of the anchor tag for this to work.

//window.onload = externalLinks;

function externalLinks()
{
 var objCurrent, objReplacement;

 if (document.getElementsByTagName)
 {
  var objAnchors = document.getElementsByTagName('a');
  for (var iCounter=0; iCounter<objAnchors.length; iCounter++)
  {
   if (objAnchors[iCounter].getAttribute('href') &&objAnchors[iCounter].getAttribute('rel') == 'external')
   {
    objAnchors[iCounter].onclick = function(event){return launchWindow(this, event);}
    objAnchors[iCounter].onkeypress = function(event){return launchWindow(this, event);}
    objAnchors[iCounter].title = (objAnchors[iCounter].title != "") ? objAnchors[iCounter].title+" (opens in a new window)" : "opens in a new window";

    if (document.replaceChild)
    {
     objCurrent = objAnchors[iCounter].firstChild;
     if (objCurrent.nodeType == 3) // Text node
     {
      //objReplacement = document.createTextNode(objCurrent.data + ' (opens in a new window)');
      //objAnchors[iCounter].replaceChild(objReplacement, objCurrent);
     }
     else if (objCurrent.alt) // Current element is an image
     {
      objReplacement = objCurrent;
      objReplacement.alt = objCurrent.alt + ' (opens in a new window)';
      try
      {
       objAnchors[iCounter].replaceChild(objReplacement, objCurrent);
      }
      catch(e){}
     }
    }
   }
  }
 }
}

function launchWindow(objAnchor, objEvent)
{
var iKeyCode;

if (objEvent && objEvent.type == 'keypress')
{
 if (objEvent.keyCode)
  iKeyCode = objEvent.keyCode;
 else if (objEvent.which)
  iKeyCode = objEvent.which;

 if (iKeyCode != 13 && iKeyCode != 32)
  return true;
}

return !window.open(objAnchor);
}