//GENERATE RANDOM NUMBER: This function generates a random number between 1 and a user-specified top value - DDD 1/14/08
function randomNumber(limit) {
    var seed = (Math.ceil(Math.random()*limit));
    return seed;
}

//GENERIC DROP DOWN NAVIGATION
function goDropDown(strForm,strElement) {
    var objElement = eval('document.' + strForm + '.' + strElement);
    var objElementValue = objElement[objElement.selectedIndex].value;
    if (objElementValue != "") {
        window.location = objElementValue;
    }
}

//RETURN FROM CHILD WINDOW
function returnParent(strURL) {
    if(window.opener) {
        window.opener.location = strURL;
    }
    else if(window.parent) {
        window.parent.location = strURL;
    }
    window.close();
}

//GLOBAL POPUP
var objChildWindow;
function doChildWindow(strURL, objWin, strOptions) {
    //check for open windows and close them
    if (objChildWindow && objChildWindow.closed == false) {
        objChildWindow.close();

        objChildWindow = window.open(strURL, objWin, strOptions);
        objChildWindow.focus();
    }
    else {
        objChildWindow = window.open(strURL, objWin, strOptions);
        objChildWindow.focus();
    }
}

function openPrintPage(strURL) {
    var strOptions;
    strOptions = "toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,left=100,top=100,width=620,height=500";

    doChildWindow(strURL, 'child_window', strOptions);
    objChildWindow.focus();
}

//GLOBAL NEW WINDOW
function openNewWin(strURL, intWidth, intHeight) {
    var strOptions;
    //check for parameters and set defaults
    if ((intWidth == '') || (intHeight == '')) {
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=615,height=345";
    }
    else {
        intWidth += 45;
        intHeight += 45;
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=" + intWidth + ",height=" + intHeight;
    }
    doChildWindow(strURL, 'child_window', strOptions);
    objChildWindow.focus();
}

// GLOBAL NEW WINDOW With Toolbars
function openNewWinwithTool(strURL, intWidth, intHeight) {
    var strOptions;
    //check for parameters and set defaults
    if ((intWidth == '') || (intHeight == '')) {
        strOptions = "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,left=100,top=100,width=615,height=345";
    }
    else {
        intWidth += 45;
        intHeight += 45;
        strOptions = "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,left=100,top=100,width=" + intWidth + ",height=" + intHeight;
    }
    doChildWindow(strURL, 'child_window', strOptions);
    objChildWindow.focus();
}

//GLOBAL NEW WINDOW WITHOUT SCROLLBAR
function openNewWinNoScroll(strURL, intWidth, intHeight) {
    var strOptions;
    //check for parameters and set defaults
    if ((intWidth == '') || (intHeight == '')) {
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=100,top=100,width=615,height=345";
    }
    else {
        intWidth += 45;
        intHeight += 45;
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=100,top=100,width=" + intWidth + ",height=" + intHeight;
    }
    doChildWindow(strURL, 'child_window', strOptions);
    objChildWindow.focus();
}

//VIEW LARGE IMAGE
function openNewImgWin(strImg, strTitle, intWidth, intHeight) {
    var strOptions;
    //check for parameters and set defaults
    if ((intWidth == '') || (intHeight == '')) {
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=400,height=400";
    }
    else {
        intWidth += 45;
        intHeight += 45;
        strOptions = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=100,top=100,width=" + intWidth + ",height=" + intHeight;
    }
    //check for browser and execute
    if (!(objBrowser.bMacNN4)) {
        doChildWindow('', 'child_window', strOptions);
        var strHTML;
        strHTML  = '<html><head><title>Bose ' + strTitle + '</title></head><body marginwidth="10" marginheight="10" leftmargin="10" topmargin="10" alink="#999999" vlink="#666666" bgcolor="#ffffff"><font face="verdana" size="1">';
        strHTML += '<div align="center"><img src="' + strImg + '" /></div>';
        strHTML += '<div align="right"><a title="Close window" href="javascript:window.close();"><font color="#000000">Close window</font></a></div></font></body></html>';
        objChildWindow.document.open();
        objChildWindow.document.write(strHTML);
        objChildWindow.document.close();
    }
    else {
        doChildWindow(strImg, 'child_window', strOptions);
    }
    //focus the new window
    objChildWindow.focus();
}

//EMAIL NEWS LETTER EMAIL VALIDATE
function checkInputEmail(theForm) {
    if ((theForm.enews.value=="") || (theForm.enews.value.indexOf("@") == -1) || (theForm.enews.value.indexOf(".") == -1)) {
        alert("Please enter a valid email address");
        return false;
    }
    return true;
}

//SEARCH FIELD VALIDATE
function checkInputSearch(theForm) {
    if ((theForm.words) && (theForm.words.value=="")) {
        alert("Please enter your search criteria.");
        return false;
    }
    return true;
}

//PRINT FUNCTION
function doPrint() {
    window.print();
}

//IMAGE PRELOAD
//imgObj - the name of the object associated with the image 
//imgSrc - the source filename (url) of the image
function doPreload(imgObj,imgSrc) {
    if (document.images) {
        eval(imgObj + ' = new Image()');
        eval(imgObj + '.src = "' + imgSrc + '"');
    }
}

//IMAGE EVENT FUNCTION
//layer - layer name if provided otherwise blank ''
//imgName - name or id of event image
//imgObj -  name or id of the preloaded image object
var glayer;
var gimgName;
var gimgObj;

function imgSwap(layer,imgName,imgObj) {
var layer;
var imgName;
var imgObj;
glayer = layer;
gimgName = imgName;
gimgObj = imgObj;
    if(document.images) {
        //NN 4.x DOM
        if(document.layers && layer != "") {
            eval('document.' + layer + '.document.images["' + imgName + '"].src = ' + imgObj + '.src');
        }
        //NN6 Gecko subroutine
        else if((objClient.application == "nn") && (objClient.version >= 5)) {
            //setTimeout("imgSwapTimeOut()",1);
            imgSwapTimeOut();
        }
        else {
            document.images[imgName].src = eval(imgObj + ".src");
        }
    }
}
//NN Gecko subroutine
function imgSwapTimeOut() {
    document.images[gimgName].src = eval(gimgObj + ".src");
}

//SUBMIT A FORM FUNCTION
//theForm - the name or id of the form to be submitted
//validateFunction - the name of the client side validation function to be called.
function submitForm(theForm, validateFunction) {
    document.forms[theForm].submit();
    if (validateFunction != "") {
        eval(validateFunction + '(' + theForm + ')');
    }
}

//HISTORY NAVIGATION
//i - the place in the history array ( can be a negative | positive number )
function goHistory(i) {
    var i;
    history.go(i);
}

//CONFIRM WINDOW GENERIC
//strMessage - the confirmation message to be displayed
function confirmDialogue(strMessage) {
        if (window.confirm(strMessage)) {
            return true;
        }
    return false;
}

// DISABLE SUBMIT BUTTON ON FORM SUBMISSION
// bFormSubmitted - indicates whether user has already submitted the form
var bFormSubmitted = false;

function disableSubmitButton() {
    if (bFormSubmitted) {
        return false;
    } 
    else {  
        bFormSubmitted = true;
        return true;
    }
}

//GENERIC METHOD FOR SETTING/UPDATING SITE CATALYST GLOBAL VARIABLES
//@ author - MPL
//@ param strPropertyName - the string name of the global Site Catalyst variable to be set
//@ param strPropertyValue - the string representation of the value the global Site Catalyst variable is set to
//@ see /jsp/includes/tracking/tracking_values.jsp for a listing of all Site Catalyst variables
function updateSiteCatalystProperty(strPropertyName, strPropertyValue) {

    var strLocalPropName = strPropertyName;
    var strLocalPropValue = strPropertyValue;
        
    if ((strLocalPropName == null || strLocalPropName.length == 0) || (strLocalPropValue == null || strLocalPropValue.length == 0)) {
        //do nothing and leave early - property name or property value is null or empty...
        
        return;
    }
    else {
        //OK to execute...
        
        if (eval(strLocalPropName) == '') {
           //property value has not been set already, so just set it to property value passed in 
           eval(strLocalPropName + ' = "' + strLocalPropValue + '"');
        }
        else {
           //property value has been set already, so must concatenate ";" + property value passed in
           eval(strLocalPropName + ' += ";' + strLocalPropValue + '"');
        }
    }
}

//UPDATES SITE CATALYST s.prop5 VARIABLE FROM CLICKABLE NON-TEMPLATED AVBs WITH INTCMP VALUES IN LINKS
//NOTE: calls to this method MUST be placed in footers so that it runs AFTER calls
//      to updateSiteCatalystProperty() for s.prop5 in <body>
//NOTE: this only updates s.prop5 for NON-redundant intcmp values
//NOTE: variable s.prop5 has global scope (page scope)
function updateS_prop5FromLinkIntcmpValues() {
    
    var bln_s_prop5_isEmptyString = true;
    var arrIntcmpKeyVal = new Array();
    var sLink = new String("");
    var sIntcmpKeyVal = new String("");
    var sIntcmpVal = new String("");
    var numStart = 0;
    var numEnd = 0;
    
    //set flag for s.prop5 based on its existing value
    if (s.prop5.length > 0) {
        bln_s_prop5_isEmptyString = false;
    }
    
    //test all links in document for intcmp url param
    for (var i = 0; i < document.links.length; i++) {
    
        //get link
        sLink = document.links[i].href;
        
        /* IMPORTANT: Disregard any link that points to the current page!
         * NOTE: This avoids logging a false impression on current page for case if link clicked on previous page 
         * (that sent you to current page) has an intcmp url param in it. The false impression occurs when current 
         * page has an href such as href="#" (because # = the original link clicked on previous page). The resulting 
         * link contains an intcmp url param from the PREVIOUS page - NOT from the current page. Therefore, it should
         * not be considered for impression tracking.
         */
        if(sLink.indexOf(window.location.href) != -1) {
            //alert("contains original link: \n" + sLink);
            continue;
        }
        
        //test for intcmp url param
        if (sLink.indexOf("intcmp=") != -1) {
            //NOTE: intcmp url param IS present in link - OK to process...
            
            //get intcmp url param (key/value pair) from query string
            //NOTE: There should be only one intcmp url param in query string.
            numStart = sLink.indexOf("intcmp=");
            numEnd = sLink.indexOf("&", numStart);
            
            //if there is not another trailing key-value pair in query string...
            //see if there is a double quote (") char which signals the end of intcmp url param value in link
            if (numEnd == -1) {
                numEnd = sLink.indexOf("\"", numStart);
            }
            
            //if there is no double quote...
            //see if there is a single quote (') char which signals the end of intcmp url param value in link
            if (numEnd == -1) {
                numEnd = sLink.indexOf("\'", numStart);
            }
            
            //else, just take everything to the end of the link
            if (numEnd == -1) {
                numEnd = sLink.length;
            }
            
            sIntcmpKeyVal = sLink.slice(numStart,numEnd);
            
            //split into key and value components
            arrIntcmpKeyVal = sIntcmpKeyVal.split("=");
            
            //test for expected number of components
            if (arrIntcmpKeyVal.length == 2) {
                //NOTE: intcmp key and value components are present - OK to process...
                
                //get intcmp value component
                sIntcmpValue = arrIntcmpKeyVal[1];
                
                //decode (replace any wonky hexadecimal escape sequences with actual characters)
                sIntcmpValue = decodeURI(sIntcmpValue);
                
                //remove whitespace from value component if it exists
                sIntcmpValue = Trim(sIntcmpValue);
                
                //test to see if value component has an actual value
                if (sIntcmpValue.length > 0) {
                    //NOTE: intcmp value is NOT an empty string - OK to process...
                    
                    if (s.prop5.indexOf(sIntcmpValue) == -1) {
                        //NOTE: THIS intcmp value is NOT already present in s.prop5 - MUST add it to s.prop5...
                        
                        // update s.prop5 global variable...
                        if (bln_s_prop5_isEmptyString) {
                            s.prop5 = sIntcmpValue;
                            
                            //set flag - NOW s.prop5 is NOT an empty string
                            bln_s_prop5_isEmptyString = false; 
                        }
                        else {
                            s.prop5 += ";" + sIntcmpValue;
                        }
                    }
                }
            }
        }
    }//end for loop
}

// JS version of getPageId() using Regular Expressions
function getPageId(strURL) {

        var pathTranslated = "";
        
        // Remove the leading http:/.../
        // ("/home_entertainment/index.html")
        pathTranslated = strURL.replace(/https?:\/\/[a-zA-Z _.0-9-]*:?\d*\/*/i, "");
        
        // Remove the ending extension
        // ("/home_entertainment/index")
        pathTranslated = pathTranslated.replace(/\..*$/, "");

        // Replace all forward-slashes with colons
        // ("home_entertainment:index")
        pathTranslated = pathTranslated.replace(/\//g, ":");

        // Replace all underscores with spaces ("home entertainment:index")
        pathTranslated = pathTranslated.replace(/_/g, " ");

        pathTranslated = pathTranslated.replace(/((^\w)|(\:\w)|(\s\w))/g, function(w){return w.toUpperCase()});           

        return pathTranslated;
}


//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
//      STRING UTILITY FUNCTIONS: START
//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @

// JavaScript Functions Written by:
//    Scott Mitchell
//    mitchell@4guysfromrolla.com
//    http://www.4GuysFromRolla.com

//Trim(string) : Returns a copy of a string without leading or
//               trailing spaces
//=============================================================
function Trim(str)
/***
        PURPOSE: Remove trailing and leading blanks from our string.
        IN: str - the string we want to Trim

        RETVAL: A Trimmed string!
***/
{
        return RTrim(LTrim(str));
}

//LTrim(string) : Returns a copy of a string without leading spaces.
//==================================================================
function LTrim(str)
/***
        PURPOSE: Remove leading blanks from our string.
        IN: str - the string we want to LTrim

        RETVAL: An LTrimmed string!
***/
{
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(0)) != -1) {
            // We have a string with leading blank(s)...

            var j=0, i = s.length;

            // Iterate from the far left of string until we
            // don't have any more whitespace...
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;

            // Get the substring from the first non-whitespace
            // character to the end of the string...
            s = s.substring(j, i);
        }

        return s;
}

//RTrim(string) : Returns a copy of a string without trailing spaces.
//==================================================================
function RTrim(str)
/***
        PURPOSE: Remove trailing blanks from our string.
        IN: str - the string we want to RTrim

        RETVAL: An RTrimmed string!
***/
{
        // We don't want to trip JUST spaces, but also tabs,
        // line feeds, etc.  Add anything else you want to
        // "trim" here in Whitespace
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            // We have a string with trailing blank(s)...

            var i = s.length - 1;       // Get length of string

            // Iterate from the far right of string until we
            // don't have any more whitespace...
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;

            // Get the substring from the front of the string to
            // where the last non-whitespace character is...
            s = s.substring(0, i+1);
        }

        return s;
}


//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
//      STRING UTILITY FUNCTIONS: END
//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @



//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
//      COOKIE UTILITY FUNCTIONS: START
//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @

function setCookie (name,value,expires,path,domain,secure) {
    //test for params and set if provided
    document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function checkForCookie(strCookieName) {
    var objAllCookies = document.cookie;
    var checkPos = objAllCookies.indexOf(strCookieName);
    if (checkPos != -1) {
        return true;
    }
    return false;
}

function getCookieValue (offset) {
    var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1) {
            endstr = document.cookie.length;
        }
        return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    if((document.cookie == null) || (document.cookie.length == null)) {
        return null;
    }
    var i = 0;
    while (i < clen) {
        var j = i + alen;

        if (document.cookie.substring(i,j) == arg) {
        return getCookieValue(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) {
            break;
        }
    }
    return null;
}

function deleteCookieNow(strName) {
    document.cookie=strName + "=;expires=-1;path=/";
}

//Survey Cookie Functions: Start

function setSurveyShownCookie() {
    // BUSINESS RULE: Do NOT show survey if ANY survey has been served to user within one year.
    // NOTE: ALL surveys now use the same generic survey shown cookie.
    // This cookie should persist for one year and should be available to all paths 
    // within the domain specified by server that serves this cookie for non-secure and secure.
    
    //lifespan = one year (expressed in milliseconds)
    var lifeSpan = 365 * 24 * 60 * 60 * 1000;
    
    //get current time in milliseconds
    var now = new Date();
    now.setTime(now.getTime());
    
    //set expiration date
    var expiryDate = new Date(now.getTime() + lifeSpan);
    
    setCookie("SurveyShown","true",expiryDate,"/","","");
}

function processLegacySurveyCookie(strLegacySurveyName) {
    //BUSINESS RULE: If a legacy survey shown cookie exists (user saw a survey within one year), 
    //delete old cookie and replace with new generic survey shown cookie (persists for one year). 
    //The decision is to "under serve" rather than "over serve" a survey.

    //new generic survey shown cookie name
    var surveyShownCookieName = "SurveyShown";

    //legacy survey shown cookie names
    var dtcSurveyShownCookieName = "DTCShopSurveyShown";
    var foreseeSurveyShownCookieName = "ForeseeSurveyShown_wkpxs8EF00";

    switch (strLegacySurveyName) {
        case dtcSurveyShownCookieName:
            deleteCookieNow(dtcSurveyShownCookieName);
            break;
        case foreseeSurveyShownCookieName:
            deleteCookieNow(foreseeSurveyShownCookieName);
            break;
        default : //ignore
    }
    
    //if new generic survey shown cookie does not exist yet, then create it
    if(getCookie(surveyShownCookieName) == null) {
        setSurveyShownCookie();
    }
}

function isSurveyShown() {

    var blnSurveyShown = false;

    //new generic survey shown cookie name
    var surveyShownCookieName = "SurveyShown";

    //legacy survey shown cookie names
    var dtcSurveyShownCookieName = "DTCShopSurveyShown";
    var foreseeSurveyShownCookieName = "ForeseeSurveyShown_wkpxs8EF00";

    //all legacy survey shown cookies will expire by this time
    var intLegacySurveyCookieMaxExpireTime = (new Date(2008,2,1)).getTime();
    var intNow = (new Date()).getTime();

    //check for new generic survey shown cookie...

    if(getCookie(surveyShownCookieName) != null) {
        blnSurveyShown = true;
    }

    //check for legacy survey shown cookies...

    if(intNow < intLegacySurveyCookieMaxExpireTime) {

        if(getCookie(dtcSurveyShownCookieName) != null) {
            blnSurveyShown = true;
            processLegacySurveyCookie(dtcSurveyShownCookieName);
        }

        if(getCookie(foreseeSurveyShownCookieName) != null) {
            blnSurveyShown = true;
            processLegacySurveyCookie(foreseeSurveyShownCookieName);
        }
    }

    return blnSurveyShown;
}

//Survey Cookie Functions: End

//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
//      COOKIE UTILITY FUNCTIONS: END
//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @



// MapQuest js functions
function imageMapDirection(direction){
  if(direction =='north' || direction =='northeast' || direction =='east' || direction =='southeast' || direction =='south' || direction =='southwest' || direction =='west' || direction =='northwest'){
    document.nav_form.direction.value = direction;
  }
  if(direction =='default'){
    document.nav_form.direction.value = direction;
  }
  document.nav_form.event.value='LOCATOR_MAP_POSITION_EVENT';
  document.nav_form.submit();
}

function imageMapZoom(level){
  if(level =='in' || level =='out' || level =='1' || level =='2' || level =='3' || level =='4' || level =='5' || level =='6' || level =='7' || level =='8' || level =='9' || level =='10' ){
    var currZoom =  2 ;
    currZoom =  document.zoom_form.zoom.value  ; 
		    if(level =='in'){
			    document.zoom_form.zoom.value = currZoom - 1 + 2;			 
			}else if(level =='out')  {
			 	document.zoom_form.zoom.value = currZoom - 1;
		 	}else{
	 		   document.zoom_form.zoom.value = level;	 	
	 	    }      
  }
  if(level =='default'){
    document.zoom_form.zoom.value = level;
  }
   
  document.zoom_form.event.value='LOCATOR_MAP_ZOOM_EVENT';
  
  document.zoom_form.submit();
}

function isblank(s) {
  for (var i=0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) {
      return false;
    }
  }
  return true;
}

function checkInput(City)
{
var strCity = City;

// Check if values are blank. If so, prompt user for action
// and cancel submission of form
if (isblank(strCity))
  {
  alert("Please enter a city");
  document.address_form.city.focus();
  return false;
  }

}

function checkZipInput(zipCode) {
	var strZipCode = zipCode;
	
	if(isblank(strZipCode)) {
		alert("Please enter a zipcode");
		document.address_form.postalcode.focus();
		return false;
	}
}

/***
** loacation.querystring[]
** Returns an associative array with the key value pairs parsed from the url search string.
** Example:
** value = window.location.querystring["key"];
** Added by IC - 05/08
***/

location.querystring = (function() {   
    // The return is a collection of key/value pairs   
    var result = {};   
  
    // Gets the query string with a preceeding '?'   
    var querystring = location.search;   
  
    // document.location.search is empty if a query string is absent   
    if (!querystring)   
        return result;   
  
    // substring(1) to remove the '?'   
    var pairs = querystring.substring(1).split("&");   
    var splitPair;   
  
    // Load the key/values of the return collection   
    for (var i = 0; i < pairs.length; i++) {   
        splitPair = pairs[i].split("=");   
        result[splitPair[0]] = splitPair[1];   
    }   
  
    return result;   
})();

/* addEvent() - used to attach event listeners for Live Person eChat functionality */
/* This version taken from Christian Heilmanns book; isbn 1-59059-680-3 */
/* addEvent() is also located in global.js for headers that don't include scriplib.js *
/* DAC 6/12/2006 */
function addEvent(elm, evType, fn, useCapture)
  {
    if (elm.addEventListener)
    {
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } 
    else if (elm.attachEvent)
    {
      var r = elm.attachEvent('on' + evType, fn);
      return r;
    }
    else
    {
      elm['on' + evType] = fn;
    }
  }

/*--------------------------------------------------------------------------------------------------------*/

/***
** title: Get Event Target
** author: Isaac Chellin
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 6/6/2008
** description: Returns the target of a javascript event. 
***/

function getEventTarget(e){ 
		e = e || window.event;
		return e.target || e.srcElement;
	}

/*--------------------------------------------------------------------------------------------------------*/

/***
** title: Popup Window Script
** author: Dan DeRose
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 6/6/2008
** description: Creates a popup window that can refer back to its parent. The popup behavior is keyed off the class "popup". If this class is applied to a normal href then it will instantiate the popup behavior. The rel attribute is used to specify the width and height, in that order.
***/

function popupWindow(t,e) {

	// Kill the event and stop the href action
	e = e ||  window.event;
	e.cancelBubble = true;
	e.returnValue = false;
	try
	{
		e.preventDefault();
		e.stopPropagation();
	}
	catch (err){ }

	// Set a default height and width
	var iWidth = '600';
	var iHeight = '600';

	// Check to see if the element has the "rel" attribute. If it does, assign the values to the iWidth and iHeight variables. 
	if((t.getAttribute('rel') != null) && (t.getAttribute('rel') != '')) {
		var sPopupSettings = t.getAttribute('rel');
		var aPopupSettings = sPopupSettings.split(',');
		
		if(aPopupSettings[0] != 'undefined') {
			iWidth = aPopupSettings[0];
		}
		if(aPopupSettings[1] != 'undefined') {
			iHeight = aPopupSettings[1];
		}
	}

	// Set the features for the popup window
	var sPopupFeatures = 'menubar=no,toolbar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=' + iWidth + ',height=' + iHeight;

	// Spawn the popup
	// Detect if this is an email a friend link by reading the class
	if(t.up().hasClassName('email')) {
		emailFriend(t,e,sPopupFeatures);
	}
	// If not email to a friend, simply spawn the popup
	else {
		window.open(t,'childWindow',sPopupFeatures);
	}
}
/*--------------------------------------------------------------------------------------------------------*/

/***
** title: GlobalFrontController
** author: Isaac Chellin -- Modifying code placed here by RI per BOSEUS-8507
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 10/21/2009
** description: Adds Event Listners to DOM Elements. Delegates events to the approriate command function. 
***/

GlobalFrontController = {

		/* Constants */

		CONTAINER:"",  // Reference to the container element

		/* Methods */

		init: function(){

			/* Set Constants */

			GlobalFrontController.CONTAINER = document.getElementsByTagName("body")[0];

			/* Global Event Listeners */

			/* Delegate onclick events */
			GlobalFrontController.CONTAINER.onclick = function(e)
			{
				GlobalFrontCommands.clickEvent(e);
			},
			
			/* Delegate onmouseover events */
			GlobalFrontController.CONTAINER.onmouseover = function(e)
			{
				GlobalFrontCommands.mouseOverEvent(e);
			},

			/* Delegate onmouseout events */
			GlobalFrontController.CONTAINER.onmouseout = function(e)
			{
				GlobalFrontCommands.mouseOutEvent(e);
			}
		},
		
		/* Lets you disable the controller to improve performance. Used by Media Showcase. */
		disable: function()
		{
			GlobalFrontController.CONTAINER.onclick = null;
			GlobalFrontController.CONTAINER.onmouseover = null;
			GlobalFrontController.CONTAINER.onmouseout = null;
		}

}

/*--------------------------------------------------------------------------------------------------------*/

/***
** title: GlobalFrontCommands
** author: Isaac Chellin --  Modifying code placed here by RI per BOSEUS-8507
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 10/21/2009
** description: Object contains commands that will execute functions depending upon the class or id of the element that 
** dispatched the event. Called from the FrontController.
***/

GlobalFrontCommands = {

		/* Execute onclick commands */
		clickEvent: function(e)
		{
			var t = getEventTarget(e);
			Element.extend(t); // Add prototype methods
			
			/* Execute popup */
			// Check if target has a class of popup or is an image with a parent with the a class of popup.
			if (t.hasClassName("popup") || ( t.tagName.match(/(IMG|STRONG|EM|B|I)/) && t.up().hasClassName("popup")))
			{
				if (t.tagName.match(/(IMG|STRONG|EM|B|I)/))
				{
					t = t.up();
				}
				popupWindow(t,e);
			}
			
			if (t.hasClassName("popup_compare"))
			{
				popupCompareWindow(t,e);
			}
			
			
			
			/* Execute email to a friend script */
			if (t.up().hasClassName("email"))
			{
				emailFriend(t,e);
			}
		},

		/* Exectute onmouseover commands */
		mouseOverEvent: function(e)
		{
			var t = getEventTarget(e);
			Element.extend(t);
			/* Execute the roll over image swap */
			if (t.hasClassName("rollover"))
			{
				RollOverImageSwap.rollover(t);
			}
		},

		/* Exectute onmouseout commands */
		mouseOutEvent: function(e)
		{
			var t = getEventTarget(e);
			Element.extend(t);
			/* Execute the roll over image swap */
			if (t.hasClassName("rollover"))
			{
				RollOverImageSwap.rollout(t);
			}
		}

}
/*--------------------------------------------------------------------------------------------------------*/

