//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();
}

//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="../Bose Professional Products_archivos/' + 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 COOKIE CHECK
function checkForCookie(strCookieName) {
    
    //get all cookies
    var objAllCookies = document.cookie;

    //does cookie exist?
    var checkPos = objAllCookies.indexOf(strCookieName);
    
    if (checkPos != -1) {
        return true;
    }
    
    return false;
}

//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
}




//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
//      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
//@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @

//PVA-2904 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 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;
}
//PVA-2904 Ends

