function correctPNG()
{
    for(var i=0; i<document.images.length; i++)
    {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()

        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText

            if (img.align == "left") imgStyle = "float:left;" + imgStyle

            if (img.align == "right") imgStyle = "float:right;" + imgStyle

            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle

            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
        }
    }
}

if ( window.attachEvent ) window.attachEvent("onload", correctPNG);

function clearMe(objInput)
{
    strBgColor = objInput.style.backgroundColor;

       if (( ( objInput.value.toUpperCase() == "FIRST NAME" ) && ( objInput.name == "name_first" ) ) ||
           ( ( objInput.value.toUpperCase() == "LAST NAME" ) && ( objInput.name == "name_last" ) ) ||
           ( ( objInput.value.toUpperCase() == "FIRST NAME" ) && ( objInput.name == "firstname" ) ) ||
           ( ( objInput.value.toUpperCase() == "LAST NAME" ) && ( objInput.name == "lastname" ) ) ||
           ( ( objInput.value.toUpperCase() == "ADDRESS" ) && ( objInput.name == "street_address_" ) ) ||
           ( ( objInput.value.toUpperCase() == "CITY" ) && ( objInput.name == "city_" ) ) ||
           ( ( objInput.value.toUpperCase() == "ZIP CODE" ) && ( objInput.name == "zip_code_" ) ) ||
           ( ( ( objInput.value.toUpperCase() == "EMAIL ADDRESS*" ) || ( objInput.value.toUpperCase() == "" ) ) && ( objInput.name == "email" ) ))
           {
               objInput.value = "";
               objInput.style.color = "#000000";
               objInput.style.backgroundColor = "#E2D481";
           }
}

function refillMe(objInput)
{
    if ( objInput.value == "" && ( objInput.name == "name_first" || objInput.name == "firstname" ) )
    {
        objInput.value = "First Name";
        objInput.style.color = "#999";
    }

    if ( objInput.value == "" && ( objInput.name == "name_last" || objInput.name == "lastname" ) )
    {
        objInput.value = "Last Name";
        objInput.style.color = "#999";
    }

    if ( objInput.value == "" && objInput.name == "email" )
    {
        objInput.value = "Email Address*";
        objInput.style.color = "#999";
    }

    if ( objInput.value == "" && objInput.name == "street_address_" )
    {
        objInput.value = "Address";
        objInput.style.color = "#999";
    }

    if ( objInput.value == "" && objInput.name == "city_" )
    {
        objInput.value = "City";
        objInput.style.color = "#999";
    }

    if ( objInput.value == "" && objInput.name == "zip_code_" )
    {
        objInput.value = "Zip Code";
        objInput.style.color = "#999";
    }

    objInput.style.backgroundColor = strBgColor;
}

function hideShow(obj)
{
    for ( n = 0; n < document.getElementById("resource_list").childNodes.length; n++ )
    {
        if ( document.getElementById("resource_list").childNodes[n].nodeType == 1 )
        {
            document.getElementById("resource_list").childNodes[n].className = "off";
            document.getElementById("resource_list").childNodes[n].childNodes[2].style.display = "none";
        }
    }

    obj.parentNode.className = "";
    obj.className = "on";
    objElement = obj.parentNode.childNodes[2];
    objElement.style.display = ( objElement.style.display != "block" ? "block" : "none" );
}

function unhide(n)
{
    if ( n == 0 ) return;

    str = "r" + n;
    obj = document.getElementsByName(str)[0];
    objElement = obj.parentNode.childNodes[2].style.display = "block";
}


/*** functions for the rotating testimonials on the home page ***/
function shuffleArray(aArray)
{
  var i = aArray.length;

  if ( i == 0 ) return false;

  while ( --i )
  {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = aArray[i];
     var tempj = aArray[j];
     aArray[i] = tempj;
     aArray[j] = tempi;
   }
}

function rotateTestimonial()
{
    shuffleArray(aTestimonial);
    document.getElementById("testimonial_img").src = "/img/testimonial_" + aTestimonial[aTestimonial.length - 1] + ".jpg";
    n = 0;
    setInterval("doRotate()", 10 * 1000); // switch picture every 10 seconds
}

function doRotate()
{
    document.getElementById("testimonial_img").src = "/img/testimonial_" + aTestimonial[n] + ".jpg";
    n++;

    if ( n == aTestimonial.length ) n = 0;
}

function goTestimonial()
{
    if ( n == 0 ) n = aTestimonial.length;

    location.href = "/testimonials/?sn=" + aTestimonial[n - 1];
    return true;
}

// try to add an event handler to any button on the page
window.onload = function()
{
    if (document.getElementsByTagName)
    {
        inputs = document.getElementsByTagName('input');

        // loop through all anchor tags
        for ( i = 0; i < inputs.length; i++ )
        {
            inpt = inputs[i];

            if ( inpt.getAttribute('type') == "image" )
            {
                // these do not work in IE - uses attachEvent
                inpt.setAttribute("onmouseover", "btnOvr(this)");
                inpt.setAttribute("onmouseout", "btnOut(this)");
            }
        }
    }
}

function btnOvr(that)
{
    // does not work in IE
    //that.style.position = "relative";
    //that.style.top = "-1px";

    strSourceOrig = that.src;
    strSource = strSourceOrig.replace(/.gif/, "-h.gif");
    that.src = strSource;
}

function btnOut(that)
{
    // does not work in IE
    //that.style.position = "relative";
    //that.style.top = "0";

    that.src = strSourceOrig;
}

function excludeOthers(objSelect)
{
    if ( objSelect.value )
    {
        var strValue = objSelect.value;
    }
    else
    {
        var strValue = objSelect.options[objSelect.selectedIndex].value;
    }

    var strName = objSelect.name;

    if ( objSelect.form )
    {
        var objForm = objSelect.form;
    }
    else
    {
        var objForm = document.forms[document.forms.length - 1];
    }

    for ( n = 0; n < objForm.elements.length; n++ )
    {
        objElement = objForm.elements[n];

        if ( objElement.selectedIndex && ( objElement.name != strName ) )
        {
            if ( objElement.value )
            {
                strThisValue = objElement.value;
            }
            else
            {
                strThisValue = objElement.options[objElement.selectedIndex].value;
            }

            if ( strThisValue == strValue )
            {
                objElement.selectedIndex = 0;
            }
        }
    }

    return true;
}
