/*

roll() handles the image rollovers.

*/

function roll(node,status)
{ nodeImg = node.firstChild.firstChild
  srcImage = nodeImg.getAttribute("src")
  
  if (status)
  { navState = srcImage.substring(srcImage.length - 7,srcImage.length - 4)
    if (navState == "off")
    { srcImage = srcImage.substring(0,srcImage.length - 7)
      srcImage = srcImage + "on.gif"
      nodeImg.setAttribute("src",srcImage)
    }
  }
  else
  {  navState = srcImage.substring(srcImage.length - 7,srcImage.length - 4)
    if ((navState != "sel") && (navState != "off"))
    {  srcImage = srcImage.substring(0,srcImage.length - 6)
      srcImage = srcImage + "off.gif"
      nodeImg.setAttribute("src",srcImage)
    }
  }
}




/*

these functions begin and maintain the automatic cycling of the slideshow.

*/

var currentSlide = 1
var previousSlide = 3
var slideFading = false
var opcty = 0

function nextSlide()
{ 
	slideFading = true
	previousSlide = currentSlide

	currentSlide++;
	var mySlideCount = getSlideCount()+1;
	if (currentSlide == mySlideCount)
	{
			currentSlide = 1
	}

	slideUpdate()
}




/*

slideRoll() and slideUpdate() handles the slideshow functionality and image swapping.

*/

function slideRoll(which)
{ 
	if (slideFading)
	  { 
		return
	  }
  
	if (which == currentSlide)
	  { 
		return
	  }

	  slideFading = true
    
	  previousSlide = currentSlide

	  currentSlide = which

	  slideUpdate()
}

function slideUpdate()
{
	setOpacity("slide" + currentSlide,0)
	var myCurrentSlide = document.getElementById("slide" + currentSlide);
	if ( myCurrentSlide )
		myCurrentSlide.style.visibility = "visible"
  
	var mySlideCount = getSlideCount();
	for(i=1;i<=mySlideCount;i++)
	{
		if (i == currentSlide)
		{
			var myCurrentOptionOff = document.getElementById("option" + i + "off");
			if ( myCurrentOptionOff )
				myCurrentOptionOff.style.visibility = "hidden";
			var myCurrentOptionOn = document.getElementById("option" + i + "on");
			if ( myCurrentOptionOn )
				myCurrentOptionOn.style.visibility = "visible"
		}
		else
		{
			var myCurrentOptionOff = document.getElementById("option" + i + "off");
			if ( myCurrentOptionOff )
				myCurrentOptionOff.style.visibility = "visible";
			var myCurrentOptionOn = document.getElementById("option" + i + "on");
			if ( myCurrentOptionOn )
				myCurrentOptionOn.style.visibility = "hidden";
		}
	}
    
	opcty = 0
	fadeSlides()
}

function fadeSlides()
{ opcty = opcty + 10
  setOpacity("slide" + currentSlide,opcty)
  setOpacity("slide" + previousSlide,(100 - opcty))
  if (opcty < 100)
  { setTimeout("fadeSlides()",30)
  }
  else
  {
	  var myPrevSlide = document.getElementById("slide" + previousSlide);
	  if ( myPrevSlide )
	  {
		  myPrevSlide.style.visibility = "hidden";
		slideFading = false;
	  }
  }
}



function setOpacity(layr,num)
{
	var mySlideObj = document.getElementById(layr);
	if ( mySlideObj )
	{
		obj = mySlideObj.style
		obj.MozOpacity = (num/100)
		obj.opacity = (num/100)
		obj.filter = "alpha(opacity=" + num + ")"
	}
}

function getNumberOfPages(theListCtrlID)
{
//alert("getNumberOfPages("+theListCtrlID+")");
	var myNumberOfPages = 0;
	var myListCtrl = document.getElementById(theListCtrlID);
	if (myListCtrl != null)
	{
		var myItemList = myListCtrl.getElementsByTagName("li");
//		if (myItemList != null && myItemList.length > 0)
		if (myItemList != null )
		{
//			myNumberOfPages = myItemList.length;
			var myItem = null;
			for (var  i=0; i < myItemList.length; i++ )
			{
				myItem = myItemList[i];
				if ( myItem != null )
				{
//alert("myItem.id = " + myItem.id );
					if (  myItem.id != null && myItem.id.indexOf("PAGE_") > -1  )
					{
						myNumberOfPages++;
//alert("myNumberOfPages="+myNumberOfPages);
					}
				}
			}
/*			
			var myItem = null;
			myItem = myItemList[myItemList.length-1];
			myNumberOfPages = myItem.id;
*/
		}
	}
	return myNumberOfPages;
}

function getDisplayedPageIndex(theListCtrlID)
{
//alert("getDisplayedPageIndex("+theListCtrlID+")");	
	var myDisplayedPageIndex = 0;
	var myListCtrl = document.getElementById(theListCtrlID);
	if (myListCtrl != null)
	{
		var myItemList = myListCtrl.getElementsByTagName("li");
		if (myItemList != null)
		{
			var myItem = null;
			for (var i = 0; i < myItemList.length; i++)
			{
				myItem = myItemList[i];
				if (  	myItem != null && 
						myItem.id != null && 
						myItem.id.indexOf("PAGE_") > -1 && 
						myItem.style.display != "none" 
					)
				{
					var myStartIndex = myItem.id.indexOf("_");
					var myEndIndex = myItem.id.length;
					myDisplayedPageIndex = myItem.id.substring( myStartIndex+1 );;
//alert("myStartIndex= "+myStartIndex +". myEndIndex="+myEndIndex + ", myDisplayedPageIndex ="+myDisplayedPageIndex );
					break;
				}
			}
		}
	}
	return myDisplayedPageIndex ;
}

function Paginate(thePageIndex, theListCtrlID, thePaginationCtrlID)
{

//alert("Paginate("+thePageIndex+", "+theListCtrlID+", "+thePaginationCtrlID+")");

	var myPageIndex = thePageIndex;
	var myListCtrl = document.getElementById(theListCtrlID);
	if (myListCtrl != null)
	{
		var myNumberOfPages = getNumberOfPages( theListCtrlID );
//alert("myNumberOfPages ="+myNumberOfPages );			

		var myItemList = myListCtrl.getElementsByTagName("li");
		if (myItemList != null)
		{
			var displayedPageIndex = getDisplayedPageIndex(theListCtrlID);
//alert("displayedPageIndex ="+displayedPageIndex );			
//			if ( displayedPageIndex == -1 )
//				displayedPageIndex = 1;
			if (myPageIndex == 0)
			{
				myPageIndex = displayedPageIndex-1;
			}
			
			if (myPageIndex-1 == myNumberOfPages )
			{
				myPageIndex= displayedPageIndex;
				myPageIndex++;
			}

//			if ( myPageIndex != displayedPageIndex )
			{
				var myItem = null;
				for (var i = 0; i < myItemList.length; i++)
				{
					myItem = myItemList[i];
				if (myItem != null && myItem.id != "")
				{
//var myPageID = "PAGE_" + myPageIndex;
//alert("myItem.id="+myItem.id+", myPageIndex="+myPageIndex+", myPageID="+myPageID +", myItem.name="+myItem.name);
					if ( myItem.id == "PAGE_" + myPageIndex)
					{
//alert("MATCH");
						myItem.style.display = "block";
					}
					else
					{
//alert("NO MATCH");
						myItem.style.display = "none";
					}
				}
				}

//alert("myPageIndex="+myPageIndex);			
				
				var myPaginationCtrl = document.getElementById(thePaginationCtrlID);
				if (myPaginationCtrl != null)
				{
					var myPageList = myPaginationCtrl.getElementsByTagName("li");
					if (myPageList != null)
					{
						var myPage = null;
						var myPrevPage = myPageList[0];
						var myNextPage = myPageList[myPageList.length-1];
						for (var j = 0; j < myPageList.length; j++)
						{
							myPage = myPageList[j];
							if ( myPage.id == myPageIndex )
							{
								myPage.className="selected";
			//					myPage.setAttribute("classname", "selected");
							}
							else
							{
								myPage.className="";
			//					myPage.setAttribute("classname", "");
							}
						}
						if (myPageIndex <= 1)
						{
							myPrevPage.style.display = "none";
						}
						else
						{
							myPrevPage.style.display = "block";
						}
						if (myPageIndex >= myPageList.length-2)
						{
							myNextPage.style.display = "none";
						}
						else
						{
							myNextPage.style.display = "block";
						}
					}
				}
				
			}
		}
	}
}

function FilterList_ItemCtrl(theListCtrlID, theItemID)
{
	var myListCtrl = document.getElementById(theListCtrlID);
	if (myListCtrl != null)
	{
		var myItemList = myListCtrl.getElementsByTagName("li");
		if (myItemList != null)
		{
			var myItem = null;
			for (var i = 0; i < myItemList.length; i++)
			{
				myItem = myItemList[i];
				if (myItem.id == theItemID || theItemID == '')
				{
					myItem.style.display = "block";
				}
				else
				{
					myItem.style.display = "none";
				}
			}
		}
	}
}

function FilterList_SelectCtrl(theListCtrlID, theSelectCtrlID)
{
	var mySelectCtrl = document.getElementById(theSelectCtrlID);
	if (mySelectCtrl != null)
	{
		var mySelectedItem = mySelectCtrl.options[mySelectCtrl.selectedIndex];
		if (mySelectedItem != null)
		{
			FilterList_ItemCtrl(theListCtrlID, mySelectedItem.value);
		}
	}
}

function showCtrl(theID, status)
{
	var myCtrl = document.getElementById(theCtrlID);
	if (myCtrl != null)
	{
		if (status)
		{
			myCtrl.style.display = "block";
		}
		else
		{
			myCtrl.style.display = "none";
		}
	}
}

function showCtrl(theCtrlID)
{
	var myCtrl = document.getElementById(theCtrlID);
	if (myCtrl != null)
	{
		if (myCtrl.style.display == "none")
			myCtrl.style.display = "block";
		else
			myCtrl.style.display = "none";

	}
}

function openEmail(path)
{
	var url = window.location;
	path += url	
	window.location.href = (path);
}
/*

handles the Our Services landing page.

*/

function rollService(obj)
{ yy = document.getElementById("servicesNav").getElementsByTagName("li")
  zz = document.getElementById("servicesNav").getElementsByTagName("li").length
  
  for (i=0;i<zz;i++)
  { if (obj == yy[i])
    { document.getElementById("servicesContent" + i).style.display = "block"
      if (i == 0)
      { yy[i].className = "firstSelected"
      }
      else if (i == (zz - 1))
      { yy[i].className = "lastSelected"
      }
      else
      { yy[i].className = "selected"
      }
    }
    else
    { document.getElementById("servicesContent" + i).style.display = "none"
      if (i == 0)
      { yy[i].className = "first"
      }
      else if (i == (zz - 1))
      { yy[i].className = "last"
      }
      else
      { yy[i].className = ""
      }
    }
  }
}

function showServSearch(status)
{ if (status)
  { document.getElementById("servicesDrop").style.display = "block"
  }
  else
  { document.getElementById("servicesDrop").style.display = "none"
  }
}
function showServSearch()
{ 
	var status = document.getElementById("servicesDrop").style.display == "block";
	if (status)
	{
		document.getElementById("servicesDrop").style.display = "none"
	}
	  else
	{
		document.getElementById("servicesDrop").style.display = "block"
	}
}


// This function determines if strInput is empty:
//        Example usage: if (isEmpty(form.login.value)) { ...
//
function isEmpty(strInput)
{
	if (strInput == "" || strInput == null)
	{
		return true;
	}
	return false;
}


// This function will attempt to validate an e-mail address, if it is given
// It assumes that the email field on the form is called "email".
// It will take 2 parameters: the email address object and true/false if
//  the field is required.
//        Example usage:  if (!isValidEmailAddress(form.email, true)) { ...
//
function isValidEmailAddress(email, blnRequired)
{
   var allValid = true;
   var strInput = email.value;
	
   // Check if the email address exists and if it is required:
	if (isEmpty(strInput))
	{
	     if (!blnRequired) { return true; }
	     else {
	      alert("Please enter your e-mail address.");
	      email.focus();
	      return false;
	     } // else
	    } //if
	
	   var strLen = strInput.length;
	
	   // CHECK IF EMAIL ADDRESS HAS A '@' CHARACTER:
	     if (strInput.indexOf("@") == -1) {
	      alert("The e-mail address you entered was not valid because it does not have a '@'.  Please re-enter your \"e-mail address\".");
	      email.focus();
	      email.select();
	      return false;
	     } //if
	
	   // CHECK IF EMAIL ADDRESS HAS A '.' CHARACTER:
	     	if (strInput.indexOf(".") == -1) {
	       		alert("The e-mail address you entered was not valid because it does not have a '.'.  Please re-enter your \"e-mail address\".");
	          email.focus();
	          email.select();
	          return false;
	     	} //if
	
	   // CHECK IF EMAIL ADDRESS STARTS WITH A '.':
	     	if (strInput.indexOf('.') == 0) {
	       		alert("The e-mail address you entered was not valid because it starts with '.'  Please re-enter your \"e-mail address\".");
	         email.focus();
	         email.select();
	       	 return false;
	     	} //if
	
	   // CHECK IF EMAIL ADDRESS STARTS WITH A '@':
	     	if (strInput.indexOf('@') == 0) {
	       		alert("The e-mail address you entered was not valid because it starts with '@'  Please re-enter your \"e-mail address\".");
	         email.focus();
	         email.select();
	       	 return false;
	     	} //if
	
	   // Check for any invalid characters in the address:
	     	for (var i = 0; i < strLen; i++) {
	         	ch = strInput.charAt(i)
	         	if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
	                 	|| (ch == "@") || (ch == ".") || (ch == "_")
	               	  	|| (ch == "-") || (ch >= "0" && ch <= "9")
				|| (ch == ",")) { ; }
	         	else { allValid = false; }
	     	} //for
	
	     	if (!allValid) {
	       		alert("The e-mail address you entered was not valid because it contains an illegal character.  Valid characters are letters, numbers, dashes or underscores.  Please re-enter your \"e-mail address\".");
	         email.focus();
	         email.select();
	       	 return false;
	     	} //if
	
	   //It has a . adjacent to the @:
	         var atpos=strInput.indexOf('@')
	     	if (strInput.charAt(atpos-1)=='.'){
	       		alert("The e-mail address you entered was not valid because it contains a '.' adjacent to the '@'  Please re-enter your \"e-mail address\".");
	         email.focus();
	         email.select();
	       	 return false;
	     	} // if
	
	         var copy=strInput.substring(atpos+1,strInput.length);
	   //It contains more than one @:
	  	/*if (copy.indexOf('@')!=-1){
	       		alert("The e-mail address you entered was not valid because it contains more than one '@'.  Please re-enter your \"e-mail address\".");
	         email.focus();
	         email.select();
	       	 return false;
	     	}*/
	
	   // It has a . adjacent to the @:
	  	if (copy.indexOf(".")<1){
	       		alert("The e-mail address you entered was not valid because it contains a '.' adjacent to the '@'.  Please re-enter your \"e-mail address\".");
	         email.focus();
	         email.select();
	       	 return false;
	     	}
	
	   // It ends with a . or an @:
	  	if (copy.lastIndexOf(".")+1==copy.length){
	       		alert("The e-mail address you entered was not valid because it ends with '.' or an '@'.  Please re-enter your \"e-mail address\".");
	         email.focus();
	         email.select();
	       	 return false;
	     	}
	
	   // Invalid top level domain length:
	  	copy = strInput.substring(strInput.lastIndexOf('.')+1,strLen);
	  	var len = copy.length;
	   	if (len == 2 || len == 3 || len == 4) { ; }
	   	else {
	       	 alert("The e-mail address you entered was not valid since the top-level domain (after the last .) should only be 2 or 3 characters in length.  Please re-enter your \"e-mail address\".");
	          email.focus();
	          email.select();
	       	 return false;
	 	} //else
	
	   // It contains two adjacent .:
	  	copy = strInput;
	  	while (copy.indexOf('.') != -1) {
	         copy = copy.substring(copy.indexOf('.') + 1, copy.length);
	         if (copy.indexOf('.') == 0) {
	       	  alert("The e-mail address you entered was not valid because it contains two adjacent periods.  Please re-enter your \"e-mail address\".");
	          email.focus();
	          email.select();
	       	  return false;
	     	 } //if
	  	} //while
	
	     	return true;
	
	  } //isValidEmailAddress

/*	  
	 function ValidateForm(form) 
	 {
	
	   	// The friend's name is a required field:
	   if (isEmpty(form.toname.value)) {
	   		alert("Please enter your Friend's name.");
	   		form.toname.focus();
	   		return false;
	   }
	   	// The friend's email address is required and must be valid:
	   if (!isValidEmailAddress(form.toemail, true)) {
	       return false;
	   }
	   	// The sender's name is a required field:
	   if (isEmpty(form.fromname.value)) {
	   		alert("Please enter your name.");
	   		form.fromname.focus();
	   		return false;
	   }
	    // The sender's email address is required and must be valid:
	   if (!isValidEmailAddress(form.fromemail, true)) {
	       return false;
	   }
	}
*/
	function PreProcessForm(theForm)
	{
		var isValid = ValidateForm( theForm );
		if ( isValid == false )
			return isValid;

		var isSenderEmailValid = new Boolean(false);
		var isRecipientEmailValid = new Boolean(false);
		var myShowFormElement = null;

		if (theForm != null)
		{
			var myFormElement = null;
			var i=0;
			while ( i < theForm.elements.length && isValid )
			{
				myFormElement = theForm.elements[i];
				if (myFormElement != null)
				{
					myFormElement.name = unescape(myFormElement.name);
					if ( (myFormElement.type == "text") && !isEmpty( myFormElement.value) )
					{
						myFormElement.value = unescape( myFormElement.value );
					}
					else if ( (myFormElement.type == "textarea") && !isEmpty( myFormElement.value) )
					{
						myFormElement.value = unescape( myFormElement.value );
					}
					else if ( (myFormElement.type == "select-one") && (myFormElement.selectedIndex >= 0) )
					{
						myFormElement.value = unescape( myFormElement.options[myFormElement.selectedIndex].value );
					}
					else if ( (myFormElement.type == "select-multiple") && (myFormElement.selectedIndex >= 0) )
					{
						for (var j = 0; j < myFormElement.options.length; j++)
							if ( myFormElement.options[ j ].selected )
								myFormElement.value = unescape( myFormElement.options[ j ].value );
					}
					else if ( (myFormElement.type == "radio") && (myFormElement.selectedIndex >= 0) )
					{
						myFormElement.value = unescape( myFormElement.options[myFormElement.selectedIndex].value );
					}


					if ( myFormElement.name == "senderEmail" && isEmpty( myFormElement.value) )
					{
						isSenderEmailValid = true;

					}
					
					if ( myFormElement.name == "recipientEmail" && isEmpty( myFormElement.value) )
					{
						isRecipientEmailValid = true;
					}
					if ( myFormElement.name == "showForm")
					{
						myShowFormElement = myFormElement;
					}

					
				}
				i++;
			}
			if ( !isSenderEmailValid )
			{
				alert( "Sender Email is missing.");
				isValid = false;
			}
			if ( !isRecipientEmailValid )
			{
				alert( "Recipient Email is missing.");
				isValid = false;
			}

		}

		if ( myShowFormElement != null )
		{
			if ( isValid )
			{
				myShowFormElement.value = "false";
			}
			else
			{
				myShowFormElement.value = "true";
			}
		}
		
		return isValid;
	}


	function ValidateForm(theForm)
	{
		var isValid = new Boolean(true);
		if (theForm != null)
		{
			var myFormElement = null;
			var i=0;
			while ( i < theForm.elements.length && isValid )
			{
				myFormElement = theForm.elements[i];
				if (myFormElement != null)
				{
					if ( !isEmpty(myFormElement.id) && (myFormElement.id.toUpperCase().indexOf("_REQUIRED") >= 0) )
					{
						if ( (myFormElement.type == "text") && isEmpty( myFormElement.value) )
						{
							isValid = false;
						}
						else if ( (myFormElement.type == "textarea") && isEmpty( myFormElement.value) )
						{
							isValid = false;
						}
						else if ( (myFormElement.type == "select-one") && (myFormElement.selectedIndex <= 0) )
						{
							isValid = false;
						}
						else if ( (myFormElement.type == "select-multiple") && (myFormElement.selectedIndex <= 0) )
						{
							isValid = false;
						}
						else if ( (myFormElement.type == "radio") && (myFormElement.selectedIndex <= 0) )
						{
							isValid = false;
						}
					}
					else
					{
					}
					
					if (!isValid)
					{
						alert(myFormElement.name + " is required");
						myFormElement.focus();
					}
				}
				i++;
			}
		}
		
		return isValid;
	}



	var addthis_config =
	{
	   data_track_linkback: true
	}
	
	
	var more_toggle_flag = 0;
	function toggle_more(){
		if(more_toggle_flag == 0){
			document.getElementById("more-menu").style.display = "inline";
			document.getElementById("social-nav").style.height = "70px";
			document.getElementById("more-link").className = "less";
			more_toggle_flag = 1;
		}
		else{
			document.getElementById("more-menu").style.display = "none";
			document.getElementById("social-nav").style.height = "35px";
			document.getElementById("more-link").className = "more";
			more_toggle_flag = 0;
		}
	}






window.onload = init

function init()
{ if (document.getElementById("slideshow"))
  { startSlideShow()
  }
}

function startSlideShow()
{
	var mySlideCount = getSlideCount();
	if ( mySlideCount > 1)
	{
		ss = setInterval("nextSlide()",7000)
	}
}

function getSlideCount()
{
	var count = 0;
	if ( document.getElementById("slideshow") )
	{
		var mySlide = null;
		do
		{
			count++;
			mySlide = document.getElementById("slide"+count);
		}
		while ( mySlide )
		count--;
	}
	return count;
}



/*

show and hide by date/type.

*/

function showByDate()
{ document.getElementById("infoBlockDate").style.display = "block"
  document.getElementById("infoBlockType").style.display = "none"
  document.getElementById("byDate").style.display = "block"
  document.getElementById("byType").style.display = "none"
}

function showByType()
{ document.getElementById("infoBlockDate").style.display = "none"
  document.getElementById("infoBlockType").style.display = "block"
  document.getElementById("byDate").style.display = "none"
  document.getElementById("byType").style.display = "block"
}

