function isCorrectLength(inputVal, correctlength){
	if(inputVal.value.length != correctlength){
		alert("Value is invalid length. It should be "+correctlength);
		inputVal.focus();
		inputVal.select();
		return false;
	}
	return true;
}

function isEmail(email){
	val = email.value;
	invalidChars = " /:,;";
	msg = "Invalid email address! Must be in format user@domain.ext";
	for(i=0; i < invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if( val.indexOf(badChar, 0) > -1){
			alert(msg);
			email.focus();
			email.select();
			return false;
		}
	}

	atPos = val.indexOf("@", 1);
	if( atPos == -1){
		alert(msg);
		email.focus();
		email.select();
		return false;
	}

	if(val.indexOf("@", atPos+1)>-1){
		alert(msg);
		email.focus();
		email.select();
		return false;
	}

	periodPos = val.indexOf(".", atPos);
	if(periodPos == -1){
		alert(msg);
		email.focus();
		email.select();
		return false;
	}

	if(periodPos+3 > val.length){
		alert(msg);
		email.focus();
		email.select();
		return false;
	}
	return true;
}

function isNotEmpty(inputVal, type){
	if(inputVal.value == ""){
		alert("Required field; cannot be blank");
		inputVal.focus();
		if(type == "T"){
			inputVal.select();
		}
		return false;
	}
	return true;
}


function isNum(inputNum){
	val = inputNum.value;
	for(i=0; i < val.length; i++){
		if( (val.charAt(i) < "0" || val.charAt(i) > "9") && val.charAt(i) != "." ){
			alert("Input must be numeric");
			inputNum.focus();
			inputNum.select();
			return false;
		}
	}
	return true;
}


function stripLeadingDigit(inputNum){
  if( inputNum.value.charAt(0) =="1" )
  inputNum.value = inputNum.value.substring(1);
}

function stripPhoneDelimiters(inputNum){
    unformattednum="";
    for(i=0; i<inputNum.value.length;i++)
    {
        if(inputNum.value.charAt(i) >= "0" && inputNum.value.charAt(i) <= "9" )
        unformattednum+=inputNum.value.charAt(i);
    }
    inputNum.value=unformattednum;
}

function changeStyle(id, newClass) {

identity=document.getElementById(id);

identity.className=newClass;

}
function toggleHeadings(checked)
{
    var secCount = 4;
    var infoEntryCount = 14;
    for(var j=1; j<=secCount; j++)
    {
        for (var i=1; i<=infoEntryCount; i++)
        {
            var title = document.getElementById("title" + j + i);
            if(checked == true)
                expandHeading("title" + j + i, "heading" + j +i, "information" + j + i);
            else
                collapseHeading("title" + j + i, "heading" + j +i, "information" + j + i);
        }
    }
}

function toggleHeading(tName, hName, iName)
{
    var title = document.getElementById(tName);
    if (title == null) return;
    var info = document.getElementById(iName);
    if (info == null) return;
    var head = document.getElementById(hName);
    if (info.style.display == '')
    {
        if (head != null) head.style.display = 'none';
        info.style.display = 'none';
    }
    else
    {
        if (head != null) head.style.display = '';
	                    info.style.display = '';
    }
}

function expandHeading(tName, hName, iName)
{
    var title = document.getElementById(tName);
    if (title == null) return;
    var info = document.getElementById(iName);
    if (info == null) return;
    var head = document.getElementById(hName);
    if (head != null) head.style.display = '';
    info.style.display = '';
}

function collapseHeading(tName, hName, iName)
{
    var title = document.getElementById(tName);
    if (title == null) return;
    var info = document.getElementById(iName);
    if (info == null) return;
    var head = document.getElementById(hName);
    if (head != null) head.style.display = 'none';
    info.style.display = 'none';
}

function getRelatedValues(thislist){
  relatedIds = '';
  
  for (i=0;i<thislist.options.length;i++){
    relatedIds += thislist.options[i].value+',';
  }
  return relatedIds;
  
}

function moveOption(thislist, direction){
  sel = false;
  for (i=0;i<thislist.options.length && !sel;i++)
  {
    var current = thislist.options[i];
    if (current.selected)
    {
      sel = true;
      if(direction == -1 && i != 0){
        tmp1txt = current.text;
        tmp1val = current.value;
        tmp2txt = thislist.options[i-1].text;
        tmp2val = thislist.options[i-1].value;
        thislist.options[i-1] = new Option(tmp1txt, tmp1val);
        thislist.options[i] = new Option(tmp2txt, tmp2val);
        thislist.options[i-1].selected = true;
      }
      
      if(direction == 1 && i != thislist.options.length-1 ){
        tmp1txt = current.text;
        tmp1val = current.value;
        tmp2txt = thislist.options[i+1].text;
        tmp2val = thislist.options[i+1].value;
        thislist.options[i+1] = new Option(tmp1txt, tmp1val);
        thislist.options[i] = new Option(tmp2txt, tmp2val);
        thislist.options[i+1].selected = true;
      }
    }
  
  }
}
function copyToList(from,to)
{
  fromList = eval('document.forms[0].' + from);
  toList = eval('document.forms[0].' + to);
  if (toList.options.length > 0 && toList.options[0].value == 'temp')
  {
    toList.options.length = 0;
  }
  var sel = false;
  for (i=0;i<fromList.options.length;i++)
  {
    var current = fromList.options[i];
    if (current.selected)
    {
      sel = true;
      if (current.value == 'temp')
      {
        alert ('You cannot move this text!');
        return;
      }
      txt = current.text;
      val = current.value;
      toList.options[toList.length] = new Option(txt,val);
      fromList.options[i] = null;
      i--;
    }
  }
  if (!sel) alert ('You haven\'t selected any options!');
}

var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'popupWindow','width=615,height=615,scrollbars=no,status=no,titlebar=no,toolbar=no,resizable=no,menubar=no,hotkeys=no');
	if (window.focus) {newwindow.focus()}
}

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);



// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header
// NS4-6,IE4-6
// Fade effect only in IE; degrades gracefully

// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000

// Duration of crossfade (seconds)
var crossFadeDuration = 3

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = 'images/1.gif'
Pic[1] = 'images/2.gif'
Pic[2] = 'images/3.gif'
Pic[3] = 'images/4.gif'
Pic[4] = 'images/5.gif'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}

function runSlideShow(){
   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)"
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.SlideShow.filters.blendTrans.Apply()      
   }
   document.images.SlideShow.src = preLoad[j].src
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play()
   }
   j = j + 1
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', slideShowSpeed)
}
