function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}








// Adjust the backgorund of an object
function background_set (item, val)
{
    var el  = getStyleObj(item); 
    if (document.all) {el.backgroundColor = val;}
    else if (document.getElementById) {el.backgroundColor = val;}
    else {el.bgColor = val;}
}

function border_color_set (item, val)
{
    var el  = getStyleObj(item); 
    if (document.all) {el.borderColor = val;}
    else if (document.getElementById) {el.borderColor = val;}
    else {el.borderColor = val;}
}



// Get a reference to an object
function getObj(id) 
{
    //alert (id);
    if (document.getElementById) {return document.getElementById(id);}
	else if (document.all) 		 {return document.all[id];}
	else 		 {return false;}
}


// Get a reference to the style definition of an object
function getStyleObj(id) 
{
   // alert (id);
    if (document.getElementById) {return getObj(id).style;} 
	else {return getObj(id);}
}

// Set visibility
function vis_set (item, val) 
{
	//alert ("setting visibility of " + item + " to " + val);
	var el  = getStyleObj(item); 
	el.visibility = val;
}

// Adjust the alpha of an object
function alpha_set (item, val)
{
	//alert ("setting alpha of " + item + " to " + val);
	var el  = getStyleObj(item);
	if (document.all) {el.filter = "alpha(opacity=" + val +");";}
	else if (document.getElementById) {el.opacity = parseFloat (val/100);}
}











// This allows the user to show/hide bio information
function toggle(link, divId, imageChange, itemChange) 
{
	var lText = link.innerHTML; 
	var d = getObj(divId);
	
	if (lText == 'Read Bio') 
	{ 
		link.innerHTML = 'Hide Bio'; 
		d.style.display = 'block'; 
		background_set (itemChange, "#dcecf9");
		objCurrentImage = document.getElementById(imageChange);
		//objCurrentImage.src = "/extension/ezwebin/design/ezwebin/images/bio_read_less.gif";
	}
	else 
	{ 
		link.innerHTML = 'Read Bio'; 
		d.style.display = 'none';
		background_set (itemChange, "#ffffff");
		objCurrentImage = document.getElementById(imageChange);
		//objCurrentImage.src = "/extension/ezwebin/design/ezwebin/images/bio_read_more.gif";
	}
}





// Calculators
function commuteCalcu(form) 
{
	miles = eval(form.miles.value);
	
	// Number of miles times 20 (avg. work days a month) times 54.1 cents (est. cost of operation per mile)
	sov = parseInt(((miles*22)*.541));  

	carpool = parseInt(((miles*22)*.3907));  
	
	vanpool =  parseInt(((miles*22)*.10364)); 

	form.sov.value = sov;
	form.carpool.value = carpool;
	form.vanpool.value = vanpool;
}




function teleWork(form) 
{
	hours = eval(form.hours.value);
	days = eval(form.days.value);
	saved = (((hours*days)*52)/8);
	form.telework.value = saved;
}






/* USER FORMS */
function submit_user_form( user_form )
{
	document.forms[user_form].submit();
}



/* FORM VALIDATION HELPERS */



function stripCharsInBag (s, bag)

{   
    var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}


var defaultEmptyOK = false;

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";

var iUSPhone = "This field must be a 10 digit U.S. phone number (like 415 555 1212). Please reenter it now."

// BOI, followed by one or more digits, followed by EOI.
var reInteger = /^\d+$/

// U.S. phone numbers have 10 digits.
// They are formatted as 123 456 7890 or (123) 456-7890.
var digitsInUSPhoneNumber = 10;


function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}



function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber)
}


function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    return reInteger.test(s)
}





// checkUSPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid US Phone.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkUSPhone (theField, emptyOK)
{
    valid = false;

    if (checkUSPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) valid=true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false))
       { 
          warnInvalid (theField, iUSPhone);
	  valid=false;
       }
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          //theField.value = reformatUSPhone(normalizedPhone)
          valid=true;
       }
    }
	
    return valid;
}


function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "(", 3, ") ", 3, "-", 4))
}


function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    //return false
}

