// JavaScript Document


//opens external links in a new window with standards-compliant mark-up

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;

//site credits popup window
function siteCredit() {
	var win = window.open("siteCredit.php","","width=380,height=350,menubar=0,resizable=1,status=0,toolbar=0,scrollbars=1,dependent=1");
	win.focus();
}				
			
//for dropdown menus in IE-- changes the class to the same as ":hover" in css

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



//highlight current link in main navigation...called manually from each page right now.

function highlightLink(LinkId) {
	document.getElementById(LinkId).style.color = "#990000";
	//document.getElementById(LinkId).style.cursor = "text";
}



//Rotating Banner

var BannerArray = new Array("banner1", "banner2", "banner3", "banner4", "banner5", "banner6", "banner7", "banner8", "banner9", "banner10");

var CurrentContainer = "none";
var NewContainer = "none";
var OldContainer = "none";

function RandomBanner() {
	var MaxValue = BannerArray.length;
	var RandomNum = Math.floor(Math.random()*MaxValue);
	return BannerArray[RandomNum];
}

function RotateBanner() {
	
	if (NewContainer == "none") {
		NewContainer = RandomBanner();
		FadeIn(NewContainer);
		CurrentContainer = NewContainer;
		NewContainer = RandomBanner();
		while (NewContainer == CurrentContainer) {
			NewContainer = RandomBanner();
		}
	} else {
		FadeIn(NewContainer);
		FadeOut(CurrentContainer);
		CurrentContainer = NewContainer;
		NewContainer = RandomBanner();
		while (NewContainer == CurrentContainer) {
			NewContainer = RandomBanner();
		}
		
	}
	
	//interval for rotating banner
	//var t=setTimeout("RotateBanner();",8000);
	
}

function SelectBanner(banner){
			if (CurrentContainer == banner){}
			else{
				NewContainer = banner;
				FadeIn(NewContainer);
				if (CurrentContainer=="none"){}
				else{FadeOut(CurrentContainer);}
				CurrentContainer = NewContainer;
				NewContainer = RandomBanner();
				while (NewContainer == CurrentContainer) {
					NewContainer = RandomBanner();
				}
			}
		}
		 

function FadeOut(container) {
	//time is how long is takes to fade in or out (milliseconds)
	var time = 1000;
	opacity(container, 99, 0, time);
	//using 99 instead of 100 fixes a flicker glitch in older versions of mozilla
	var t=setTimeout("DisplayOff(OldContainer);",time);
	
}

function FadeIn(container) {
	document.getElementById(container).style.display = "inline";
	opacity(container, 0, 99, 1000);
	//using 99 instead of 100 fixes a flicker glitch in older versions of mozilla
}
 function DisplayOff(container){
	 document.getElementById(container).style.display = "none";
 }



/****************************************************************************/
//fade scripts from http://brainerror.net/scripts_js_blendtrans.php

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
		//In order to turn off the display of this element:
		OldContainer = id;
		
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

/****************************************************************************/

//******************FORM VALIDATION************************************************

function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="")
		  {alert(alerttxt);return false}
		else {return true}
	}
}

function validate_email(field,alerttxt) {
	with (field) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) 
		  {alert(alerttxt);return false}
		else {return true}
	}
}

//request information form
function validate_form1(thisform) {

	with (thisform) {
		if (validate_required(name,"Please enter your name.")==false)
		  {name.focus();return false}
	}
	with (thisform) {
		if (validate_required(address,"Please enter your address.")==false)
		  {address.focus();return false}
	}
	with (thisform) {
		if (validate_required(address2,"Please enter your complete address.")==false)
		  {address2.focus();return false}
	}
	with (thisform) {
		if (validate_email(email,"Please enter valid e-mail address.")==false)
		  {email.focus();return false}
	}
	with (thisform) {
		if (validate_required(phone,"Please enter your daytime phone number.")==false)
		  {phone.focus();return false}
	}
	
}
//email form
function validate_form2(thisform) {

	with (thisform) {
		if (validate_required(name,"Please enter your name.")==false)
		  {name.focus();return false}
	}
	with (thisform) {
		if (validate_email(email,"Please enter valid e-mail address.")==false)
		  {email.focus();return false}
	}
	with (thisform) {
		if (validate_required(message,"Please enter a message.")==false)
		  {message.focus();return false}
	}
	
}

//employee 30/60/90 form
function validate_form3(thisform) {

	with (thisform) {
		if (validate_required(name,"Please enter your name.")==false)
		  {name.focus();return false}
	}
	with (thisform) {
		if (validate_email(email,"Please enter valid e-mail address.")==false)
		  {email.focus();return false}
	}
	with (thisform) {
		if (validate_required(empid,"Please enter your employee ID #.")==false)
		  {empid.focus();return false}
	}
	with (thisform) {
		if (validate_required(dept,"Please enter the department.")==false)
		  {dept.focus();return false}
	}
	with (thisform) {
		if (validate_required(dept_address,"Please enter the dept. address.")==false)
		  {dept_address.focus();return false}
	}
	with (thisform) {
		if (validate_required(dept_ext,"Please enter the dept. ext.")==false)
		  {dept_ext.focus();return false}
	}
	with (thisform) {
		if (validate_required(signature,"Please enter your signature.")==false)
		  {signature.focus();return false}
	}
	
	
}




