//***********************************************************
//AREG-CSS site
//	Template for CSS sites built with the SiteBuilder tool
//
//	Javascript Functionality for the ELS Login Module in:
//		modules/ incModELSLogin.asp
//
//	NOTE: gfunIsValidEmailAddress From: gbinc/jsfiles/incValidationAPI.js
//
//	-scott 9/29/06
//***********************************************************

function funValLogin()
{
	var objForm = g_getRawObject("elsLoginForm");
	var isOK = true;
	if (isOK && !gfunIsValidEmailAddress(objForm.fldUserName.value, false)) {
		alert("Please enter a valid Email Address.\n\r A valid email address should look like yourname@yourdomain.com");
		objForm.fldUserName.focus();
		isOK = false;
	}
	if (isOK && (objForm.fldPassword.value.length < 1)) {
		alert("Please enter a valid Password.");
		objForm.fldPassword.focus();
		isOK = false;
	}
	return isOK;
}

function gosubmit(){
      
   if (funValLogin()) {     
         var objForm = g_getRawObject("elsLoginForm");
         objForm.submit();
    }
}

function funLoginPass() {

	var objForm = g_getRawObject("elsLoginForm");

	if (objForm.fldUserName.value.length < 1) {
		alert("Please enter a valid Email Address to send your password to.");
		objForm.fldUserName.focus();
	}
	else {
		objForm.Action.value = "mailpass";
		objForm.submit();
	}
}



//***********************************************************
//AREG-CSS site
//	Template for CSS sites built with the SiteBuilder tool
//
//	Javascript Functionality for the Search Module in:
//		modules/ incModSearchForm.asp
//	Requires: gbinc/jsfiles/incCommonAPI.js
//	-scott 9/29/06
//	-drs   8/10/07 Added functionality to allow pressing the enter key to submit forms in IE
//                 See: http://www.thefutureoftheweb.com/blog/submit-a-form-in-ie-with-enter
//***********************************************************

function letgo(sFormID)
{
   if (funValidateSearchForm(sFormID))
   var objForm = g_getRawObject(sFormID);
   objForm.submit();
}

function funValidateSearchForm(sFormID)
{

	var objForm = g_getRawObject(sFormID);

	var sSearchFor = objForm.searchFor.value;
	
	if (sSearchFor.length < 1) {
		alert("Please enter something to search for.");
		objForm.searchFor.focus();
		return false;
	}
	else {
		objForm.LOOKFOR.value = sSearchFor;
		objForm.keyword.value = sSearchFor;
		objForm.action = objForm.FormAction.options[objForm.FormAction.selectedIndex].value;

		return true;
	}
	
}

function funCheckEnter(e){
var characterCode

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(e.keyCode == 13){ //if generated character code is equal to ascii 13 (if enter key)\
	letgo(document.searchForm);
	return true;
	}
else {
	return false;
}

}


//***********************************************************
//AREG-CSS site
//	Template for CSS sites built with the SiteBuilder tool
//
//	Javascript Functionality for the Search Module in:
//		modules/ incModHomeSectional.asp
//	Requires: gbinc/jsfiles/incCommonAPI.js
//	-scott 9/29/06
//***********************************************************

// Global Variable for Rotating Stories Timer
var gnRotateDelay = 5000; // 5 Seconds

function getCurLayer(sModuleID) {
	return eval("sCurLayer" + sModuleID);
}

function setCurLayer(sModuleID, sLayerID) {
	eval("sCurLayer" + sModuleID + " = \"" + sLayerID + "\";");
}

function getIndex(sModuleID) {
	return eval("nCurIndex" + sModuleID);
}

function setIndex(sModuleID, i) {
	eval("nCurIndex" + sModuleID + " = " + i + ";");
}

function funGetNumStories(sModuleID) {
	return eval("nNumStories" + sModuleID);
}

function swapLayers(sModuleID, sLayerID) {
	if (getCurLayer(sModuleID)) hideLayer(getCurLayer(sModuleID));
	showLayer(sLayerID);
	setCurLayer(sModuleID, sLayerID);
}


function showLayer(sLayerID) {
	var lyr = g_getObject(sLayerID);
	if (lyr) {
		if (lyr.css != null) lyr = lyr.css;
		if (lyr.visibility != null) lyr.visibility = "visible";
	}
}

function hideLayer(sLayerID) {
	var lyr = g_getObject(sLayerID);
	if (lyr) {
		if (lyr.css != null) lyr = lyr.css;
		if (lyr.visibility != null) lyr.visibility = "hidden";
	}
}

function initRotatingStories(sModuleID) {
	if (getCurLayer(sModuleID)) hideLayer(getCurLayer(sModuleID));
	var sLayerID = sModuleID + "_story0";
	showLayer(sLayerID);
	setCurLayer(sModuleID, sLayerID);
	setIndex(sModuleID, 0);
}

function RotateLayer(sModuleID) {
	var nIndex = getIndex(sModuleID);
	nIndex++;
	if (nIndex > funGetNumStories(sModuleID)) nIndex = 0;
	swapLayers(sModuleID, sModuleID + "_story" + nIndex );
	eval("objTimer" + sModuleID + " = setTimeout(\"RotateLayer('" + sModuleID + "')\",gnRotateDelay);");
	setIndex(sModuleID, nIndex);
}

function StopRotation(sModuleID) {
	if (window["objTimer" + sModuleID]) {
		clearTimeout(window["objTimer" + sModuleID]);
	}
}

function Prev(sModuleID) {
	StopRotation(sModuleID);
	var nIndex = getIndex(sModuleID);
	nIndex--;
	if (nIndex == -1) nIndex = funGetNumStories(sModuleID);
	swapLayers(sModuleID, sModuleID + "_story" + nIndex );
	setIndex(sModuleID, nIndex);
}
						
function Next(sModuleID) {
	StopRotation(sModuleID);
	var nIndex = getIndex(sModuleID);
	nIndex++;
	if (nIndex > funGetNumStories(sModuleID)) nIndex = 0;
	swapLayers(sModuleID, sModuleID + "_story" + nIndex );
	setIndex(sModuleID, nIndex);
}		



/*
JAVASCRIPT FUNCTIONS FOR HOME PAGE ROTATING STORIES
-scott 3/20/07
*/
/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/
			
var isRotating = true;

var gnNumPodLayers = 5;

// onresize for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr = 1;	// holds id of currently visible layer
function swapLayersX(id, nNumLayers) {
	if (nNumLayers != null) gnNumPodLayers = nNumLayers;
	if (cur_lyr != id) {
		hideLayerX(cur_lyr);
		showLayerX(id);
		cur_lyr = id;
	}
}

function showLayerX(id) {
	var lyr = getElemRefs("lyr" + id);
	var btn = getElemRefs("btn" + id);
	if (lyr && lyr.css) {
		lyr.css.visibility = "visible";
		btn.src = "/images/btn"+id+"_up.gif"
	}
}

function hideLayerX(id) {
	var lyr = getElemRefs("lyr" + id);
	var btn = getElemRefs("btn" + id);
	if (lyr && lyr.css) {
		lyr.css.visibility = "hidden";
		btn.src = "/images/btn"+id+".gif"
	}
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

function initLayers(id) {
	if (cur_lyr) hideLayerX(cur_lyr);
	showLayerX(id);
	cur_lyr = id;
	thetimer = setTimeout("RotateLayerX()",5000);
	index1 = 1;
}

function RotateLayerX() {
	index1 = index1 + 1
	if (index1 == gnNumPodLayers+1) {
		index1 = 1;
	}
	swapLayersX(index1 );
	thetimer = setTimeout("RotateLayerX()",5000);
}

function StartRotation() {
	if (isRotating == false) {
		thetimer = setTimeout("RotateLayerX()",5000);
		isRotating = true;
	}
}

function StopRotationX() {
	isRotating = false;
	clearTimeout(thetimer);
}

function PrevRotation() {
	index1 = index1 - 1
	if (index1 == 0) {
		index1 = gnNumPodLayers;
	}
	swapLayersX(index1);
}
			
function NextRotation() {
	index1 = index1 + 1
	if (index1 == gnNumPodLayers+1) {
		index1 = 1;
	}
	swapLayersX(index1);
}			
	
	
/*This file contains JavaScript for special animations in the content
  Created by Des Kerrigan 9-3-2004 */

var count=0;
var nudi_top=50;
var nudi_left=50;
var nCount = 0;
var fade_started=0;


function fadeTrans(id1, id2, t1)
{
  if(fade_started==0)
  {
    fade_started=1;
    opacity(id1,100,0,t1);
    setTimeout("fadeTrans('"+id1+"', '"+id2+"', "+t1+")",t1);
  }
  else
  {
    document.getElementById(id1).src = document.getElementById(id2).src;
    opacity(id1, 0, 100, t1);
    setTimeout("fadeTransComplete()",t1);
  }
}
function fadeTransComplete()
{
  fade_started=0;
}

//This script comes from http://www.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++;
			}
		}
	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 visible
	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 = 00;
	
	//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)
	}



function print_new_slide()
{
  var fwdImage = new Image;
  document['imgHidden'].src=picsrc[num];
  if(bStart>0)
  {
      fadeTrans(imgName, imgHidden, 2000);
      if (num < numpics-1)
        fwdImage.src = picsrc[num];
  }
  else
  {
    bStart=1;
	document[imgName].src=document['imgHidden'].src;
  }
}

function start_slideshow()
{
  if(bSlide==false)
  {
    bSlide = true;
    slideshow();
  }
}
function slideshow()
{
  if (bSlide==true)
  {
    num++;
    if (num>numpics)
    {
      num=1;
    }
   print_new_slide();
    setTimeout('slideshow()',8000);
  }
}	