﻿/*!
 * Filename:		Utility.js
 * Project:		    www.BuckeyeCorrugated.com/js
 * Description:	    General JavaScript utilities used throughout the website.
 * Dependencies:    jquery-1.4.4.min.js, javascript variables: 'bciCompanyCount', 'currentFontSize'
 */

// BCI company Location list open/close event
// Dependencies: variable 'bciCompanyCount'
function ToggleBCILocationsList()
{
    var fadeSpeed = 250;
    var slideSpeed = 750;
    var defaultHeight = "0px";
    var calculatedHeight = parseInt(bciCompanyCount * 30);
    var targetHeight = ($.browser.mozilla) ? (calculatedHeight + 7) + "px" : calculatedHeight + "px";
	// Open or close the list by setting height
	var $siteSearchBCIList = $(".SiteSearchBCIList");
	var fadeInList = ($siteSearchBCIList.css("height") == defaultHeight) ? true : false;

	if (fadeInList)
	{
	    $siteSearchBCIList.css("height", defaultHeight);
	    $siteSearchBCIList.fadeIn(fadeSpeed, function ()
	    {
	        $siteSearchBCIList.animate({ height: targetHeight }, slideSpeed, function ()
	        {
	            // For IE, clear the css filter property that was added during the animation
	            $siteSearchBCIList.css("filter", "");
	            $siteSearchBCIList.css(" overflow", "auto");
	        });
	    });
	}
	else
	{
	    $siteSearchBCIList.animate({ height: defaultHeight }, slideSpeed, function ()
	    {
	        $siteSearchBCIList.fadeOut(fadeSpeed, function ()
	        {
	            // For IE, clear the css filter property that was added during the animation
	            $siteSearchBCIList.css("filter", "");
	            $siteSearchBCIList.css(" overflow", "hidden");
	        });
	    });
    }
}

// Font-size adjustment
// Dependencies: variable 'currentFontSize'
function AdjustFontSize(sizeDirection)
{
    var sizeID = new Number();
    sizeID = (sizeDirection == 1) ? currentFontSize + 1 : currentFontSize - 1;

    if (sizeID < 1 )
    {
        sizeID = 1;
    }
    else if (sizeID > 4)
    {
        sizeID = 4;
    }

    currentFontSize = sizeID;

    if (objContent = document.getElementById("FontSizeContentPanel"))
    {
        objContent.className = "ContentSize" + sizeID;
    }
}

// Site search click event
function SearchSite()
{
    if (objTerms = document.getElementById("SiteSearchTextBox"))
    {
        if (objTerms.value == "")
        {
            alert("Please provide your search criteria.");
            return;
        }
        window.location = "/search/search.pl?terms=" + objTerms.value;
    }
}

// Textbox focus event
function TextBoxControlFocus(strControlID, strDefaultText)
{
    if (objText = document.getElementById(strControlID))
    {
        objText.value = (objText.value == strDefaultText) ? "" : objText.value;
    }
}

// Textbox blur event
function TextBoxControlBlur(strControlID, strDefaultText)
{
    if (objText = document.getElementById(strControlID))
    {
        objText.value = (objText.value == "") ? strDefaultText : objText.value;
    }
}
