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];}
}
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_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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function showDiv(id) {
	if (document.getElementById) {
		document.getElementById(id).style.display = "";
	} else {
		d=eval("document."+id+"display");
		d = "";
	}
}

function hideAllDivs() {
	var divAry = new Array("ced", "acd", "acf", "led", "xstop", "md", "ta");
	for (i=0; i<divAry.length; i++) {
		if (document.getElementById) {
			document.getElementById(divAry[i]).style.display = "none";
		} else {
			d=eval("document."+divAry[i]+"display");
			d = "none";
		}
	}
}

function swapDiv(d1, d2) {
	if (document.getElementById) {
		document.getElementById(d1).style.display = "none";
		document.getElementById(d2).style.display = "";
	} else {
		d=eval("document."+d1+"display");
		d = "none";
		d=eval("document."+d2+"display");
		d = "";
	}

}

function writeDate() {
	var mydate=new Date();
	var year=mydate.getYear();
	var day=mydate.getDay();
	var month=mydate.getMonth()+1;
	var daym=mydate.getDate();
	if (year < 1000) year+=1900;
	if (daym<10) daym="0"+daym;
	if (month<10) month="0"+month;
	document.write("<span class='homeDate'>"+month+"/"+daym+"/"+year);
}

function copyRight() {
	var mydate=new Date();
	var y=mydate.getYear();
	if (y < 1000) y+=1900;
	document.write(y);
}


function openDefWin(title,subTitle,img) {
	title=escape(title);
	subTitle=escape(subTitle);
	//set window positions
	var top = 50;
	var left = Math.floor( (screen.width -450) );
	//set url + queryString
	var urlStr="/popUp.html?title="+title+"&subTitle="+subTitle+"&img="+img;
	var featuresStr="toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=410,height=400,top="+top+",left="+left;
	window.open(urlStr,"popUp",featuresStr)
}


// function that validates the form
//
function validateForm() {
	var contactForm = document.forms["contactForm"];
	
	// get the required fields.
	//
	var firstName	= contactForm.FirstName;
	var lastName	= contactForm.LastName;
	var email		= contactForm.email;
	var email2		= contactForm.email2;
	
	// now let's run through them, and alert if there's and error.
	//
	if(firstName.value=="" || firstName.value == " ") {
		AlertAndFocus("Please enter your first name.", firstName);
		return;
	}
	
	if(lastName.value=="" || lastName.value == " ") {
		AlertAndFocus("Please enter your last name.", lastName);
		return;
	}
	
	if(!ValidEmail(email.value)) {
		AlertAndFocus("Please provide a valid email address.", email);
		return;
	}
	
	if(!ValidEmail(email2.value)) {
		AlertAndFocus("Please enter your email address again.", email2);
		return;
	}
	
	if(email.value != email2.value) {
		AlertAndFocus("Your email addresses don't match. Please verify they're the same.", email2);
		return;
	}
	
	// finally, let's submit the form
	//
	contactForm.submit();
	
}

// function that (as it says) alerts and focuses
//
function AlertAndFocus(msg, e) {
	alert(msg);
	e.focus();
}

// function that validates (in a basic form) a string as
// an email address.
//
function ValidEmail(str) {
	if ((str.indexOf('@') < 0) || ((str.charAt(str.length-4) != '.') && (str.charAt(str.length-3) != '.'))) {return false;}
	return true;
}


// attaches the mouseover and mouseout commands to the navigation
//
var gNavItems;
function generateTopNav() {
    if (gNavItems == undefined) {
        gNavItems = new Array($('homeNav_about'), 
                     $('homeNav_different'), 
                     $('homeNav_proced'), 
                     $('homeNav_facilities'), 
                     $('homeNav_forms'),
                     $('homeNav_contact'), 
                     $('homeNav_myspace'),
                     $('nav_home')
                    );
    }
    for (var i=0; i < gNavItems.length; i++) {
        gNavItems[i].observe('mouseover', function() {
            this.src = '/images/' + this.id + '_f2.gif';
        });
        gNavItems[i].observe('mouseout', function() {
            this.src = '/images/' + this.id + '.gif';
        });
    };
}

function setMainSection(section) {
    var e = $('homeNav_' + section);
    e.stopObserving();
    e.src = '/images/' + e.id + '_f3.gif';
}

// highlights the nav element, so we can keep the HTML in a dreamweaver library object. 
// this is used for activating both the procedures subnav, as well as the xStop sub-subNav.
// id: the HTML id of the element to hightlight (usually and anchor)
//
function ActivateNav(id) {
	if (document.getElementById) {
		var active = document.getElementById(id);
		active.className += "active";
	}
}

