function accordion(clicked,tab)
{
	var theDiv = $(clicked);
	var arrowUpSpans = YAHOO.util.Dom.getElementsByClassName('arrowUpSpan','span',tab);
	var arrowDownSpans = YAHOO.util.Dom.getElementsByClassName('arrowDownSpan','span',tab);			
	if (theDiv.style.display == 'none')
	{
		var otherDivs = YAHOO.util.Dom.getElementsByClassName('slider','div',tab);
		for (i=0; i<otherDivs.length; i++){
			if (otherDivs[i].style.display != 'none'){
				var openDiv = otherDivs[i];
			}
		}
		if (typeof openDiv != 'undefined'){
			new Effect.Parallel(
				[	new Effect.SlideUp(openDiv),
					new Effect.SlideDown(theDiv) ],
				{ duration: 0.1}
			)
			arrowDownSpans.each(Element.hide);
			arrowUpSpans.each(Element.show);
		}
		else{
			new Effect.SlideDown(theDiv);
		}
	}
	else
	{
		new Effect.SlideUp(theDiv, {duration: 0.1});
	}
}

function edit(hide,show)
{
	$(hide).style.display = 'none';
	$(show).style.display = 'inline';
}

// JLD 12/14/06 getElementsByClassName
function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('(^| )'+classname+'( |$)' );
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

// RRM - 09/07/06 - VTL-443 - Got java off internet to handle dollarformat
function dollarFormat(valuein){
  valuein = valuein.toString();
  var formatStr="";
  var Outdollars="";
  var decipos=valuein.indexOf(".");
  if (decipos==-1)
    decipos=valuein.length;
  var dollars=valuein.substring(0,decipos);
  var dollen=dollars.length;
  
  if (dollen>3) {
    while (dollen>0) {
      tDollars=dollars.substring(dollen-3,dollen);
      if (tDollars.length==3) {
        Outdollars=","+tDollars+Outdollars;
        dollen=dollen-3;
      } else {
          Outdollars=tDollars+Outdollars;
          dollen=0;
      }
  }
  if (Outdollars.substring(0,1)==",")
    dollars=Outdollars.substring(1,Outdollars.length);
  else
    dollars=Outdollars;
  }
  var cents=valuein.substring(decipos+1,decipos+3)
  if (cents=="")
    cents="00";
  var formatStr="$"+dollars+"."+cents;
  if (cents.length==1)
  	var formatStr=formatStr+"0";
  return formatStr;
}  

// JLD 4/28/06 - AJAX
function loadXMLDoc(url,resultFunction) 
{
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = eval(resultFunction);
		req.open("POST", url, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = eval(resultFunction);
			req.open("POST", url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.send();
		}
	}
}	

// Josh Dutcher
// 2/23/06
function left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function right(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else
	{
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function trim(str)
{
	while (str.substring(0,1) == ' ')
		{ str = str.substring(1, str.length); }
	while (str.substring(str.length-1, str.length) == ' ')
		{ str = str.substring(0,str.length-1); }
	return str;
}
// Bill Morris
// 30 September, 2000
// AKC - 3/22/2004 - Added scrollbar property
function popWindow (href,w,h, allowDebug, s){
	if (!s) {
		s = "yes";
	} else {
		if (s != "yes" && s != "no" && s != "auto") { s = "yes"; }
	}
	
	if (allowDebug == 1){
		popWin = window.open(href,"PopupWindow","toolbars=yes,top=0,left=0,status=yes,scrollbars=" + s + ",resizable=yes,width=" + w + ",height=" + h)
	} else {
		popWin = window.open(href,"PopupWindow","toolbars=no,top=0,left=0,scrollbars=" + s + ",resizable=yes,width=" + w + ",height=" + h)
	}
}


// Bill Morris
// 28 October, 2000
function validateDate (fieldname, mm, dd, yy, isRequired, dateType){

	var errMsg = ""

	if (dateType != "small"){
		if (yy < "1901" || yy > "3000"){
			return fieldname + ' does not fall into an acceptable date range\n'
		}
	}
	else{
		if (yy < "1901" || yy > "2079"){
			return fieldname + ' does not fall into an acceptable date range\n'
		}
	}

	// if date is required then there must be a value in every field
	if (isRequired && (mm.length == 0 || dd.length == 0 || yy == 0)){
		errMsg = errMsg + fieldname + ": A date is required and must take the form of mm/dd/yyyy\n"
		return errMsg;
	}
	else {
		// if the date is not required and all the fields are blank, return nothing
		if (mm.length == 0 && dd.length == 0 && yy == 0) {
			return "";
		}
	}

	Day1 = dd.charAt(0);
	Day2 = dd.charAt(1);
	if (Day1 < "0" || Day1 > "9"){
		return fieldname + ' - The first position of the day is not numeric\n'
	}
	if (Day2 < "0" || Day2 > "9"){
		return fieldname + ' - The second position of the day is not numeric\n'
	}

	Month1 = mm.charAt(0);
	Month2 = mm.charAt(1);
	if (Month1 < "0" || Month1 > "9"){
		return fieldname + ' - The first position of the month is not numeric\n'
	}
	if (Month2 < "0" || Month2 > "9"){
		return fieldname + ' - The second position of the month is not numeric\n'
	}
	
	Year1 = yy.charAt(0);
	Year2 = yy.charAt(1);
	Year3 = yy.charAt(2);
	Year4 = yy.charAt(3);
	if (Year1 < "0" || Year1 > "9"){
		return fieldname + ' - The first position of the year is not numeric\n'
	}
	if (Year2 < "0" || Year2 > "9"){
		return fieldname + ' - The second position of the year is not numeric\n'
	}
	if (Year3 < "0" || Year3 > "9"){
		return fieldname + ' - The third position of the year is not numeric\n'
	}
	if (Year4 < "0" || Year4 > "9"){
		return fieldname + ' - The fouth position of the year is not numeric\n'
	}
	
	// now that we're past all that, start validating field values
	if (mm < 1 || mm > 12){
		errMsg = errMsg + fieldname + ": The month value is invalid\n"
	}
	else {
		if (mm == 01 || mm == 03 || mm == 05 || mm == 07 || mm == 08 || mm == 10 || mm == 12) {
			if (dd < 1 || dd > 31){
				errMsg = errMsg + fieldname + ": The day value is invalid\n"
			}	
		}
		else {
			if (mm == 04 || mm == 06 || mm == 09 || mm == 11) {
				if (dd < 1 || dd > 30){
					errMsg = errMsg + fieldname + ": The day value is invalid\n"
				}	
			}	
			else {
				if (yy % 4 == 0){
					if (dd < 1 || dd > 29){
						errMsg = errMsg + fieldname + ": The day value is invalid\n"
					}	
				}
				else {
					if (dd < 1 || dd > 28){
						errMsg = errMsg + fieldname + ": The day value is invalid\n"
					}	
				}
			}
		}
	}
	return errMsg
}


// Bill Morris
// 28 October, 2000
function displayError (errMsg){
	var tmp = "";
	tmp = "The following errors were encountered while processing the form.\n\n" + errMsg;
	tmp = tmp + "\nPlease check your values and re-key.";
	alert (tmp);
}

// Bill Morris
// 28 October, 2000
function validateDate1 (fieldname, mm, dd, yy, isRequired, fieldObject, dateType){

	var errMsg = ""

	if (dateType != "small"){
	// RRM - 05/10/01 - Added check for empty b/c it may not be required		
		if (yy.length != 0 &&(yy < "1754" || yy > "3000")){
			return fieldname + ' does not fall into an acceptable date range\n'
		}
	}
	else{
	// RRM - 05/10/01 - Added check for empty b/c it may not be required
		if (yy.length != 0 &&(yy < "1900" || yy > "2079")){
			return fieldname + ' does not fall into an acceptable date range\n'
		}
	}

	// if date is required then there must be a value in every field
	if (isRequired && (mm.length == 0 || dd.length == 0 || yy == 0)){
		return  fieldname + ": A date is required and must take the form of mm/dd/yyyy\n"
	}
	// if the date is not required and all the fields are blank, return nothing
	if (mm.length == 0 && dd.length == 0 && yy.length == 0) {
		fieldObject.value = "null"
		return "";
	}

	Day1 = dd.charAt(0);
	Day2 = dd.charAt(1);
	if (Day1 < "0" || Day1 > "9"){
		return fieldname + ' - The first position of the day is not numeric\n'
	}
	if (Day2 < "0" || Day2 > "9"){
		return fieldname + ' - The second position of the day is not numeric\n'
	}

	Month1 = mm.charAt(0);
	Month2 = mm.charAt(1);
	if (Month1 < "0" || Month1 > "9"){
		return fieldname + ' - The first position of the month is not numeric\n'
	}
	if (Month2 < "0" || Month2 > "9"){
		return fieldname + ' - The second position of the month is not numeric\n'
	}
	
	Year1 = yy.charAt(0);
	Year2 = yy.charAt(1);
	Year3 = yy.charAt(2);
	Year4 = yy.charAt(3);
	if (Year1 < "0" || Year1 > "9"){
		return fieldname + ' - The first position of the year is not numeric\n'
	}
	if (Year2 < "0" || Year2 > "9"){
		return fieldname + ' - The second position of the year is not numeric\n'
	}
	if (Year3 < "0" || Year3 > "9"){
		return fieldname + ' - The third position of the year is not numeric\n'
	}
	if (Year4 < "0" || Year4 > "9"){
		return fieldname + ' - The fouth position of the year is not numeric\n'
	}

	// now that we're past all that, start validating field values
	// RRM - 11/14/01 - Added month and day checks including leap year		
	if (mm < 1 || mm > 12){
		errMsg = errMsg + fieldname + ": The month value is invalid\n"
	}
	else {
		if (mm == 01 || mm == 03 || mm == 05 || mm == 07 || mm == 08 || mm == 10 || mm == 12) {
			if (dd < 01 || dd > 31){
				errMsg = errMsg + fieldname + ": The day value is invalid\n"
			}	
		}
		else {
			if (mm == 04 || mm == 06 || mm == 09 || mm == 11) {
				if (dd < 01 || dd > 30){
					errMsg = errMsg + fieldname + ": The day value is invalid\n"
				}	
			}	
			else {
				if (yy % 4 == 0){
					if (dd < 01 || dd > 29){
						errMsg = errMsg + fieldname + ": The day value is invalid\n"
					}	
				}
				else {
					if (dd < 01 || dd > 28){
						errMsg = errMsg + fieldname + ": The day value is invalid\n"
					}	
				}
			}
		}
	}
	if (yy.length < 4){
		errMsg = errMsg + fieldname + ": The year must be four digits long\n"
	}
	if (errMsg==""){
		fieldObject.value=mm + '-' + dd + '-' + yy
	}
	else{
		fieldObject.value="null"
	}
	return errMsg
}


function validateField(fieldname, fieldObject,required, mode) {
	/* mode specifies what sort of data, numeric; decimal; email, etc
	if field is required, we test for to see if there is a value.  If field is not required, then
	the only thing that invalidates the field is incorrect characters */
	// alert (mode)
	var invalidChars = " /:,;"	
	var errMsg=""
	var invalidValue=false;

	if (required){
		// if the value is required and blank, no further tests are required
		if (fieldObject.value == ""){
			return fieldname + ' must have a value.\n'
		}
	}
	<!--- RRM - 02/20/01 - Changed validatenumber to validatenumeric --->
	if (mode == "numeric"){
		errMsg += validateNumeric(fieldname, fieldObject)
	}

	if (mode == "decimal"){
		errMsg += validateDecimal(fieldname, fieldObject)
	}

	if (mode == "email"){
		errMsg += validateEmail(fieldname, fieldObject)
	}

	if (mode == "phone"){
		errMsg += validatePhone(fieldname, fieldObject, required, mode)
	}	
		
	if (mode == "zip"){
		errMsg += validateZip(fieldname, fieldObject, required)
	}

	return errMsg;		
}


function validateZip(fieldname, fieldObject, required){
	var invalidValue=false;  
	// first, we'll check to see if there's a value that just doesn't work...
	for (i = 0; i < fieldObject.value.length; i++){
		if ((fieldObject.value.charAt(i) < "0" || fieldObject.value.charAt(i) > "9") && fieldObject.value.charAt(i) != "-"){
			return fieldname + " contains invalid characters\n"
		} 
	}
	<!--- DJR - 04/22/09 - Changed the values that are acceptable from "10" and "6" to "10" and "5" --->
	//RRM - 5/27/09 - Added "6" back into checks b/c some add the dash
	if (invalidValue == false){
		//we're okay so far, so continue checking
		if (required){
			if (fieldObject.value == "-"){
				return fieldname + ' is required.\n'
			}
			if (fieldObject.value.length != 10 && fieldObject.value.length != 5 && fieldObject.value.length != 6){
				return fieldname + ' is invalid.\n'
			}
		}
		else {
			// not required.  Let's see if there's anything in the fieldobject
			if (fieldObject.value.length > 0 && fieldObject.value != "-"){
				if (fieldObject.value.length != 10 && fieldObject.value.length != 5 && fieldObject.value.length != 6){
					return fieldname + ' is invalid.\n'
				}
			}
		}
	}
	return ''
}


function validatePhone(fieldname, fieldObject, required, mode){
	var invalidValue=false;  // initialize the value
	for (i = 0; i < fieldObject.value.length; i++){
		if ((fieldObject.value.charAt(i) < "0" || fieldObject.value.charAt(i) > "9") && fieldObject.value.charAt(i) != "-"){
			return fieldname + ' contains invalid characters\n'
		} 
	} // for
	
	var aPhone = fieldObject.value.split('-')
	
	if (required){
		// make sure we have an area code
		if (aPhone[0].length != 3){
			return fieldname + ' must include an area code\n'
		} 

		if (aPhone.length == 4){
			// number w/ extension
			if (aPhone[1].length != 3 || aPhone[2].length != 4){
				return fieldname + ' is not a valid number\n';
			}
		} 
		else {
			if (aPhone.length == 3){
				// number without extension
				if (aPhone[1].length != 3 || aPhone[2].length != 4){
					return fieldname + ' is not a valid number\n';
				}
			}
		}

	} //required
	else {
		if (aPhone[0].length != 0 || aPhone[1].length != 0 || aPhone[2].length != 0){
			return validateField(fieldname, fieldObject,true, mode)
		}
	} //else required							
	return ''
} 

function validateEmail (fieldname, fieldObject){
	var invalidChars = " /:,;"	
	var invalidValue=true;
	// check for the @ symbol
	for (i = 0; i < fieldObject.value.length; i++){
		if (fieldObject.value.charAt(i) == "@"){
			invalidValue=false;
		} 
	}
	invalidValue=true;
	// check for a dot
	for (i = 0; i < fieldObject.value.length; i++){
		if (fieldObject.value.charAt(i) == "."){
			invalidValue=false;
		} 
	}
	// check for invalid characters	
	for (i = 0; i < invalidChars.length; i++){
		badChar=invalidChars.charAt(i);
		if (fieldObject.value.indexOf(badChar,0) > -1) {
			invalidValue=true;
		} 
	}
	if (invalidValue){
		return fieldname + ' is not a valid email address or contains invalid characters.\n'
	}
	return ''
}


function validateDecimal (fieldname, fieldObject){
	var invalidValue=false; 	// initialize the value
	for (i = 0; i < fieldObject.value.length; i++){
		if (fieldObject.value.charAt(i) < "0" || fieldObject.value.charAt(i) > "9"){
			if (fieldObject.value.charAt(i) != "."){
				return fieldname + ' must be numeric or decimal.\n'
			}
		} 
	}
	return ''
}

function validateNumeric (fieldname, fieldObject) {
	var invalidValue = false;
	for (i = 0; i < fieldObject.value.length; i++){
		if (fieldObject.value.charAt(i) < "0" || fieldObject.value.charAt(i) > "9"){
			return fieldname + ' must be numeric.\n'
		} 
	}
	return ''
}


// Bill Morris
// December 28, 2000
function Date1GTDate2(y1, m1, d1, y2, m2, d2){

	// compares two dates
	// returns true if second date is <= first date

	var SECOND = 1000
	var MINUTE = SECOND * 60; // the number of milliseconds in a minute
	var HOUR = MINUTE * 60; // the number of milliseconds in an hour
	var DAY = HOUR * 24; // the number of milliseconds in a day
	var WEEK = DAY * 7; // the number of milliseconds in a week
	
	var Time1 = Date.UTC(y1, m1 -1, d1)
	var Time2 = Date.UTC(y2, m2 -1, d2); // specified time (UTC)
	var bTime = (Time1 - Time2)  // time difference
	return (( bTime / DAY ) < 0);
 
}
