/*** COPYRIGHT 2009  BY CUTSEY BUSINESS SYSTEMS LTD. - ALL RIGHTS RESERVED ***/
/* product.js -- Product Page Javascript                                     */
/*****************************************************************************/
/*E020309 10/18/11 APY- Corrections to product review validation.            */
/*E020308 07/18/11 JKR Q13187 Always return available quantity for upsell    */
/*E020307 01/21/11 MS - Allow more ASCII chars, 32 thru 126 for prod reviews.*/
/*E020306 01/04/11 MS - Allow only ASCII characters in prod review comments. */
/*E020305 10/20/10 MS - Forgot to add the clearClick function.               */
/*E020304 10/20/10 MS - Add clearClick() after success msg of review comments*/ 
/*E020303 08/26/10 JD2- Don't override product image if already set.         */
/*E020302 08/25/10 JD2- Corrected timing issue with displayTabs() running    */
/*                      before loadStyle()                                   */
/*E020301 08/17/10 JD2- Added upsell specific conditions for new upsell      */
/*                      display changes.                                     */
/*E020300 07/22/10 DPK- Added java function to auto tab to next field.       */
/*E020200 06/29/10 DPK- Added logic to pass new phone# fields for review.    */
/*E020100 06/24/10 DPK- Moving Order Qty to orderProduct function inside     */
/*                      retail-upsell.w and pass the value along.            */
/*E020004 06/17/10 JD2- Only display tabs if there's data to display.        */
/*E020003 05/24/10 JD2- Updated getManuals() for display changes.            */
/*E020002 05/24/10 WH - Ensure userid is passed in ajax call.                */
/*E020001 05/12/10 JD2- Bring in showSection function. Added getFaqs()       */
/*                      Added getManuals().                                  */
/*E020000 04/05/10 JD2- Brought in base v040007.                             */
/*                    - Added functions for new widgets.                     */
/*                    - Merged Euro versions E010007,E010008,E010010,E010100 */
/*                      E010201.                                             */
/*****************************************************************************/
/*E010201 03/19/10 JD2- Pass "orf" to addToCart.                             */
/*E010100 02/11/10 PMS- Called global getCurrency function                   */
/*E010010 02/04/10 PMS- Updated for translation                              */
/*E010008 08/05/09 DPK- Changed to handle is_upsell flag.                    */
/*E010007 07/20/09 JD2- Updated for OFS mode.                                */
/*****************************************************************************/
/* 040007 03/10/10 APY- Remove hardcoded scroll to top in addToCart.         */
/* 040006 03/08/10 JD2- Last version closed without code changes.            */
/* 040005 03/04/10 JD2- Show/hide multiple divs for showVideo()/hideVideo(). */
/* 040004 03/03/10 JD2- OOS message was not hiding for in stock items.       */
/*                    - OOS message fix for multi size mode. Display the     */
/*                      stock message when qty is not passed to showOOSMsg() */
/* 040003 03/02/10 APY- OOS correction when selecting default style image.   */
/* 040002 03/01/10 JZ - Site option for defaulting selection of first color. */
/* 040001 02/22/10 JD2- Don't redisplay comparables here.                    */
/*                    - Updated goStyle to just call golink for short urls.  */
/* 040000 02/10/10 JD2- Merged changes from TEA. T010010,T010009,T010008,    */
/*                      T010007.                                             */
/*                    - T010006: Added validation for ttSize fullDesc/desc.  */
/*****************************************************************************/
/*T010010 10/06/09 APY- Update avail-sizes display when selecting color.     */
/*T010009 07/30/09 JD2- PERM - Unforce disclaimer display for all sales.     */
/*                      Fixed in super-get-price.                            */
/*T010008 07/01/09 APY- TEMP - Force disclaimer display for all sales untill */
/*                      disclaimer is fixed in super-get-price.              */
/*T010007 04/06/09 JZ - Tooltip for selecting size and scroll to top when    */
/*                      something is added to the bag.                       */
/*T010006 03/11/09 APY- Styling changes.                                     */
/*****************************************************************************/
/* 030205 02/02/10 APY- Add logic to set color from cookie or hash.          */
/* 030204 01/28/10 APY- Fix for when vMaxUnits is 0 / not set.               */
/* 030203 01/22/10 JD2- Updated flashembed for transparency.                 */
/* 030202 01/22/10 JD2- Update hideVideo to stop the video when playing.     */
/* 030201 01/10/10 JD2- Added showVideo and hideVideo functions.             */
/* 030200 01/17/10 JD2- Added product review functions.                      */
/* 030101 01/07/10 APY- Add max qty limit checks.                            */
/* 030100 12/21/09 JB - Changes to stock checking (E020000).                 */
/* 030000 12/17/09 JD2- Template changes. Build comparables on the server.   */
/*****************************************************************************/
/* 020000 11/16/09 APY- MagicZoom upgrade, add start/stop and alt image zoom.*/
/*****************************************************************************/
/* 010103 09/22/09 SB - Delete a stray line from last check-in.              */
/* 010102 09/22/09 SB - Allow setColor back to style (no-color) default.     */
/* 010101 05/15/09 JD2- Use ttItem.order-limit.                              */
/* 010100 05/01/09 JZ - Static catalog mods.                                 */
/* 010010 04/07/09 JB - Use new enviro vars, new swatch error type.          */
/*        04/14/09 APY- Fix pricing display on comparables.                  */
/* 010009 04/03/09 JB - Change "hide" to "swatch" for image replacement.     */
/* 010008 04/02/09 JB - Added conditions for product mode.                   */
/* 010007 03/30/09 JD2- Added default price.                                 */
/* 010006 03/17/09 APY- If only a single size select by default.             */
/* 010005 03/17/09 APY- Reduce avail qty when successfully adding to cart.   */
/* 010004 02/26/09 SB - Add color name under swatch display grid.            */
/* 010003 02/09/08 APY- Updated default multi dim size when on 1 detail rec. */
/* 010002 12/30/08 APY- Corrected swatchHex, add altView update Comparables  */
/* 010001 12/16/08 APY- Add Multi-view, nocache, use hostURL and appURL      */
/*                    - Add alternate comparables display location           */
/* 010000 12/03/08 APY- Created.                                             */
/*****************************************************************************/
/****** Globals JS Vars Defined in product.w ******
var allStylesObj = new Object();
var styleObj     = new Object();
var vLockedImg = "";
var vDefaultWhse  = "";
var vComparableDir = "";
var vSelectedProd = "";
var vSelectedSize  = "";
var vSelectedColor = "";
var vSelectedSizeDesc  = "";
var vSelectedColorDesc = "";
var vSelectedPrice = "";
var vSelectedMultiSize = new Array();
var vRegPriceLabel  = "";
var vRegOnSaleLabel = "";
var vIsRetail = true/false;
var vDispColorDesc = true/false;
var vBrowseParam = ""
var vSponsorCode = ""
var vProdType = "s" or "i"
var vOrderLimit = 0
var vOrderLimitMsg = ""
var vTotalOrderQty = 0
var vSelectFirstColor = get-option(v-select-first-color) - yes/no        040002
** - hostDomain and appPath js vars used from header **              010010
******************************************/
var vStyleList = new Array();
var zoomObj;
var vImgHtml = "";                                                 /* 030200 */
var vVideoEmbed = "";                                              /* 030202 */
var vReviewApi = null;                                            /* E010100 */
var vFirstHtml = "";                                              /* E020000 */
var vTabCount = 0;                                                /* E020004 */
var vTabs = "";                                                   /* E020004 */
var vTabLinks = "";                                               /* E020004 */

//========--------   Load / Display   --------========\\
function loadStyle(vStyle,vSponsor){
 var vFoundStyle = false;
 zoomObj = document.getElementById('zoom1');
 $.each(vStyleList,function(j){
   if(vStyleList[j] != null && vStyleList[j].styleCode == vStyle &&
      vStyleList[j].styleColor && vStyleList[j].styleColor[0] != null &&
      vStyleList[j].styleSize  && vStyleList[j].styleSize[0] != null)
   { styleObj = vStyleList[j]; vFoundStyle = true; }
 });
 if(vFoundStyle){
  displayStyle();

  if (vSelectFirstColor)                                           /* 040002 */
   setColor(vSelectedColor,"","");                                 /* 040002 */
 }
 else{
  var vCurrTime = new Date();
  var vCurrSecs  = (((vCurrTime.getHours() * 60) + vCurrTime.getMinutes()) * 60) + vCurrTime.getSeconds();
  var vNoCache = "&nocache=" + vCurrSecs;
  $.ajax({
    type: "GET",
    url: hostDomain + appPath + "/olc/get-style.w?style=" + vStyle + "&frames=no&target=main&sponsor=" + vSponsor + "&lang=" + clientLang + vNoCache,  /* 010010 */ /* E010010 */
    dataType: "xml",
    complete: function(data) {
       allStylesObj = $.xmlToJSON(data.responseXML); // Save XML in JSON
       //Return a single style Object
       $.each(allStylesObj.ttStyle,function(i){
          var vAddMe = true;
          $.each(vStyleList,function(j){
            if(vStyleList[j] != null && vStyleList[j].styleCode == allStylesObj.ttStyle[i].styleCode)
            { vAddMe = false; return; }
          });
          if (vAddMe)
          { vStyleList[vStyleList.length] = allStylesObj.ttStyle[i];}
          if (allStylesObj.ttStyle[i].styleCode == vStyle) {
            styleObj = allStylesObj.ttStyle[i];
            if (vSelectedProd != vStyle) {
              vSelectedProd = vStyle;
              vSelectedColor = "";
              vSelectedSize = "";
              vLockedImg = "";
              vSelectedSizeDesc = "";
              vSelectedColorDesc = "";
              vSelectedPrice = "";
              vSelectedMultiSize = new Array();
            }
          }
       });
       /***vv 030205 vv***/
       var hashCheck = getHash();
       var vHasHashColor = false;
       $(hashCheck).each(function(){
         if(this.name=="color" && this.value){
            vSelectedColor = this.value;
            vHasHashColor = true;
         }
       });
       if (!vHasHashColor){
        var vCookieColor = getCookie("prodColor");
        vCookieColor = vCookieColor.split(",");
        if (vCookieColor.length==2 && vCookieColor[0].toLowerCase() == vSelectedProd)
          vSelectedColor = vCookieColor[1];
       }
       /***^^ 030205 ^^***/
       displayStyle();

       if (vSelectFirstColor)                                      /* 040002 */
        setColor(vSelectedColor,"","");                            /* 040002 */
    }
  });
 }

}
function displayStyle(){
  var vZoomInit;
  if (vSelectedColor != ""){
    $.each(styleObj.ttColor,function(i){
      if (styleObj.ttColor[i].colorCode == vSelectedColor && styleObj.ttColor[i].imageLg != "" ) {
        $(".imageCell").attr("src",styleObj.ttColor[i].imageLg);
        vLockedImg = styleObj.ttColor[i].imageLg;
        if(styleObj.ttColor[i].imageZm != "")
          vZoomInit = styleObj.ttColor[i].imageZm;
      }
    });
  }
  if (vLockedImg == "" || vLockedImg == null){
    if (styleObj.ttColor!=null&&styleObj.ttColor[0].imageLg != "" && styleObj.ttColor[0].imageLg != null){  /* 010008 */
      $(".imageCell").attr("src",styleObj.ttColor[0].imageLg);
      vLockedImg = styleObj.ttColor[0].imageLg;
      if (styleObj.ttColor[0].imageZm != "" && styleObj.ttColor[0].imageZm != null)
        vZoomInit = styleObj.ttColor[0].imageZm;
    }
    else if (styleObj.imageLg != "" && $(".imageCell").attr("src") == "") /* E020303 */
    {
      $(".imageCell").attr("src",styleObj.imageLg);
      vLockedImg = styleObj.imageLg;
      if (styleObj.imageZm != "" && styleObj.imageZm != null)
        vZoomInit = styleObj.imageZm;
    }
  }                                                               /* T010006 */
  if ((".prodTitle") != null)
  {
	$(".prodTitle").html(styleObj.description);
  }
  if (styleObj.imageMill != "" && styleObj.imageMill != null)
    $(".prodMillImg").html("<img src=\"" + styleObj.imageMill + "\" alt=\"\">");

  displayColors();
  if(styleObj.ttSizeScale && styleObj.ttSizeScale[1] != null){
    styleObj.ttSizeScale.sort(function(a,b){ return a.sortIndex - b.sortIndex }); //Ensure array is Sorted by sortIndex
    $.each(styleObj.ttSizeScale,function(i){
       if(styleObj.ttSizeScale[i].ttSizeScaleValue.length == 1)  /* 010003 */
         vSelectedMultiSize[i] = styleObj.ttSizeScale[i].ttSizeScaleValue[0].dimValue;
       else
         vSelectedMultiSize[i] = "";
    });
    displayMultiSizes();
  }
  else if(styleObj.ttSize!=null)  /* 010008 */
    displaySizes();
  displayFeatIcons();
  if(styleObj.ttAltView)
    showAltViews('');

  /* 030000 - removed call to displayComprables() */
  /* 040001 - removed second call to displayComprables() */

  if(vZoomInit != "" && vZoomInit != null)
     $(".MagicZoomBigImageCont > div > img").attr("src",vZoomInit);

  if($(".prodDisplay").css("display")=="none"){
    $(".prodDisplay").fadeIn(250);
  }
  if (vShowImgLib)
     showImgLib(vSelectedProd,vSelectedColor);

  if (typeof vDefaultPrice == "boolean") /* 010007 */
  {
	  if (vDefaultPrice)
	     priceItem("","",styleObj.ttItem[0].itemNumber);
  }

  /******v 010101 v******/

  if ( styleObj.ttItem.length == 1 && vSelectedProd == styleObj.ttItem[0].itemNumber  ) {

     if (isNaN(styleObj.ttItem[0].orderLimit) == false)
        vOrderLimit = parseFloat(styleObj.ttItem[0].orderLimit);

     if (isNaN(styleObj.ttItem[0].orderQty) == false)
        vTotalOrderQty = parseFloat(styleObj.ttItem[0].orderQty);

     if (vOrderLimit == 1) {
        $("#qty").val("1");
        $(".prodQty").hide();
        $(".prodOrder").show();
     }
     else if (vOrderLimit == -1)
        $(".prodOrder").hide();
     else
        $(".prodOrder").show();
  }
  else
     $(".prodOrder").show();
  /******^ 010101 ^******/
  displayTabs();                                                  /* E020302 */
}

function displayColors(){
       var vColorHTML = "";
       var vColorDesc ="";
       var vClass;
       var vStockQty=-1;                                           /* E020000 */
       var vSwitchImgLg;   /* 020000 */
       var vSwitchImgZm; /* 020000 */

       var vHexPercent2 = "75,25";
       var vHexPercent3 = "50,25,25";
       var vHexPercent4 = "25,25,25,25";

       if(styleObj.ttColor!=null)  /* 010008 */
       for(var i=0; i<styleObj.ttColor.length; i++){
         if(vSelectedSize == "" || checkItem(styleObj.ttColor[i].colorCode,vSelectedSize) ) {

           if(vSelectedColor=='' && i==0 && document.getElementById("color" + vSelectedProd))
                document.getElementById("color" + vSelectedProd).value = ''; /* 010102 */

           if(vSelectedColor==styleObj.ttColor[i].colorCode) {
             vSelectedColorDesc = styleObj.ttColor[i].description;

             if (styleObj.ttColor[i].fabDesc != "" && styleObj.ttColor[i].fabDesc != null)
             { vSelectedColorDesc += " " + styleObj.ttColor[i].fabDesc; }

             $(".selectedColor").html(vSelectedColorDesc);
             /********************v E020000 v********************/

             vStockQty=checkStock(styleObj.ttColor[i].colorCode,vSelectedSize,vDefaultWhse)
             if(vSelectedSize == "" || vStockQty > 0 || vStockQty==-1)
              vClass = "colorOuterSelected";
             else
              vClass = "colorOuterOOSSelected";
           } else {
             if(vSelectedSize == "" || vStockQty > 0 || vStockQty==-1)
               vClass = "colorOuter";
             else
               vClass = "colorOuterOOS";

               /********************^ E020000 ^********************/
           }
           vColorDesc = styleObj.ttColor[i].description;
           if (styleObj.ttColor[i].fabDesc != "" && styleObj.ttColor[i].fabDesc != null)
             { vColorDesc += " " + styleObj.ttColor[i].fabDesc; }
           /***v 020000 v***/
           if (styleObj.ttColor[i].imageLg != ""){
              vSwitchImgLg = styleObj.ttColor[i].imageLg;
              vSwitchImgZm = styleObj.ttColor[i].imageZm;
           }
           else{
             vSwitchImgLg = styleObj.imageLg;
             vSwitchImgZm = styleObj.imageZm;
           }
           /***^ 020000 ^***/
           vColorHTML += '<a href="' + vSwitchImgZm + '" rel="zoom-id:zoom1;" rev="' + vSwitchImgLg + '" ' +
                         'onmouseover="swapImg(\'' + vSwitchImgLg + '\');' +
                         '$(\'.selectedColor\').html(\'' + vColorDesc + '\'); ';

           if(vClass == "colorOuterOOS" || vClass == "colorOuterOOSSelected")
           /********************v E020000 v********************/
           {
             var vStockQty=checkStock(styleObj.ttColor[i].colorCode,vSelectedSize,vDefaultWhse);
             vColorHTML += 'showOOSMsg(\'' + styleObj.ttColor[i].description + '\',vSelectedSizeDesc,'+vStockQty+');';
           }
           /********************^ E020000 ^********************/

           vColorHTML += ' " onmouseout="restoreImg();$(\'.selectedColor\').html(vSelectedColorDesc); ';

           if(vClass == "colorOuterOOS" || vClass == "colorOuterOOSSelected")
             vColorHTML += 'hideOOSMsg();';

           vColorHTML += ' " onclick="setColor(\'' + styleObj.ttColor[i].colorCode + '\',\'\'); return false;">';

           if (vDispColorDesc) {                                   /* 010004 */
             vColorHTML += '<div class="swatchbox">';
             vColorHTML += '<div class="swatchcenter">';
           }

           vColorHTML += '<div class="' + vClass + '" colorcode="' + styleObj.ttColor[i].colorCode + '">';

           if (styleObj.ttColor[i].imageSw == "" || styleObj.ttColor[i].imageSw == null ){
             if (styleObj.ttColor[i].hexColor != "" && styleObj.ttColor[i].hexColor != null && styleObj.ttColor[i].hexColor.indexOf(",") != -1){ //Check for multiple hex values
               vHexArray = styleObj.ttColor[i].hexColor.split(",");
               switch(vHexArray.length){
                 case 2:
                   vHexPerArray = vHexPercent2.split(",");
                   break;
                 case 3:
                   vHexPerArray = vHexPercent3.split(",");
                   break;
                 case 4:
                   vHexPerArray = vHexPercent4.split(",");
                   break;
                 default:
                   vHexPerArray = vHexPercent2.split(",");
               }
               vColorHTML += '<div class="colorInner">';
               for(var j=0; j<vHexArray.length; j++){
                  vColorHTML += '<div style="margin:0px;padding:0px;float:left;height:100%;width:' + vHexPerArray[j] + '%;background-color:#' + vHexArray[j] + ';"></div>';
               }
               vColorHTML += '</div>';
             }
             else
               vColorHTML += '<div class="colorInner" style="background-color:#' + styleObj.ttColor[i].hexColor + ';"></div>';
           }
           else
             vColorHTML += '<img src="' + styleObj.ttColor[i].imageSw + '" onerror="top.ImageError(this,\'swatch\')" alt="" class="colorImg"/>';  /* 010009 */

           if (vDispColorDesc) {                                   /* 010004 */
             vColorHTML += '</div>'; // colorOuter
             vColorHTML += '</div>'; // swatchcenter
             vColorHTML += '<span class="swatchboxtxt">' + styleObj.ttColor[i].description + '</span>';
           }

           vColorHTML += '</div></a>'; // swatchbox || colorOuter
         }
       }
       $(".prodColors").html(vColorHTML);
}
function displaySizes(){
   var vSizeHTML = "";
   var vClass;
   var vStockQty=-1;                                               /* 030100 */
   var vSizeDesc="";                                               /* 040000 */
   if (styleObj.ttSize.length==1){
     vSelectedSize = styleObj.ttSize[0].sizeCode;
     vSelectedSizeDesc = styleObj.ttSize[0].description;
     $(".selectedSize").html(vSelectedSizeDesc);
   }
   // $(".sizeHeading").html("Size:"); /* 010007 */                /* 030100 */
   $.each(styleObj.ttSize,function(i){
     if( checkItem(vSelectedColor,styleObj.ttSize[i].sizeCode) )
     {
      vStockQty=checkStock(vSelectedColor,styleObj.ttSize[i].sizeCode,vDefaultWhse);  /* E020000 */
      if(vSelectedSize==styleObj.ttSize[i].sizeCode){
         if(vStockQty==-1 || vStockQty > 0)                        /* E020000 */
          vClass = "sizeOuterSelected";
         else
          vClass = "sizeOuterOOSSelected";
       }
       else{
       if(vStockQty==-1 || vStockQty > 0 || vSelectedColor == "") /* E020000 */ /* 040003 */
        vClass = "sizeOuter";
       else
        vClass = "sizeOuterOOS";
       }
       if (styleObj.ttSize[i].fullDesc != "") vSizeDesc = styleObj.ttSize[i].fullDesc; /* 040000 */
       else vSizeDesc = styleObj.ttSize[i].description; /* 040000 */

       vSizeHTML += '<div class="' + vClass + '" sizecode="' + styleObj.ttSize[i].sizeCode + '"' +
                    'onmouseover="$(\'.selectedSize\').html(\'' + vSizeDesc + '\'); '; /* 040000 */

       vSizeHTML += 'showOOSMsg(vSelectedColorDesc,\'' + vSizeDesc + '\','+vStockQty+');';   /* E020000 */ /* 040000 */

       vSizeHTML += '" onmouseout="$(\'.selectedSize\').html(vSelectedSizeDesc); ';

         vSizeHTML += 'hideOOSMsg();';                             /* E020000 */
       if (!vIsRetail) { vClass += " sizeb2b"; }
       vSizeHTML += '" onclick="setSize(\'' + styleObj.ttSize[i].sizeCode + '\',this)" class="' + vClass + '" >' +
                    '<div class="sizeInner">' + styleObj.ttSize[i].description + '</div>' +
                    '</div>';
     }
   });
   if(vSelectedColor == "") displayColors(); /* 040003 */
   if(vSizeHTML!="") $(".prodSizes").html(vSizeHTML);              /* 030100 */
}
function displayMultiSizes(){
   var vSizeHTML = "";
   var vClass;
   var vSizeDesc="";                                               /* 040000 */
   if (styleObj.ttSizeScale.length == 1 && styleObj.ttSizeScale[0].ttSizeScaleValue.length == 1)
   { vSelectedMultiSize = styleObj.ttSizeScale[0].ttSizeScaleValue[0].dimValue; }
   if ($("#mainSizeHeading"))       /* 010007 */
      $("#mainSizeHeading").hide(); /* 010007 */
   $.each(styleObj.ttSizeScale,function(i){
      vSizeHTML += "<div class='sizeHeading'>" + styleObj.ttSizeScale[i].description + "</div><div class='prodSizes'>";
      $.each(styleObj.ttSizeScale[i].ttSizeScaleValue,function(j){
         if(multiSizeCheckItem(i,styleObj.ttSizeScale[i].ttSizeScaleValue[j].dimValue)){
            if(vSelectedMultiSize[i]==styleObj.ttSizeScale[i].ttSizeScaleValue[j].dimValue){
              if(multiSizeCheckStock(i,styleObj.ttSizeScale[i].ttSizeScaleValue[j].dimValue) > 0)
                vClass = "sizeOuterSelected" + i;
              else
                vClass = "sizeOuterOOSSelected" + i;
            }
            else{
              if(multiSizeCheckStock(i,styleObj.ttSizeScale[i].ttSizeScaleValue[j].dimValue) > 0)
                vClass = "sizeOuter" + i;
              else
                vClass = "sizeOuterOOS" + i;
            }
            if (styleObj.ttSize[i].fullDesc != "") vSizeDesc = styleObj.ttSize[i].fullDesc; /* 040000 */
            else vSizeDesc = styleObj.ttSize[i].description; /* 040000 */

            vSizeHTML += '<div class="' + vClass + '" dimValue="' + styleObj.ttSizeScale[i].ttSizeScaleValue[j].dimValue + '"' +
                         'onmouseover="$(\'.selectedSize' + i + '\').html(\'' + vSizeDesc + '\'); '; /* 040000 */
            if(vClass == "sizeOuterOOS" + i || vClass == "sizeOuterOOSSelected" + i)
              vSizeHTML += 'showMultiSizeOOSMsg(vSelectedColorDesc,' + i + ',\'' + styleObj.ttSizeScale[i].ttSizeScaleValue[j].dimValue + '\');';

            vSizeHTML += '" onmouseout="$(\'.selectedSize' + i + '\').html(vSelectedSizeDesc); ';

            if(vClass == "sizeOuterOOS" + i || vClass == "sizeOuterOOSSelected" + i)
              vSizeHTML += 'hideOOSMsg();';

            vSizeHTML += '" onclick="setMultiSize(' + i + ',\'' + styleObj.ttSizeScale[i].ttSizeScaleValue[j].dimValue + '\',this)">' +
                         '<div class="sizeInner">' + styleObj.ttSizeScale[i].ttSizeScaleValue[j].description + '</div>' +
                         '</div>';
         }
      });
      vSizeHTML += "</div>";
   });
   if(vSelectedColor == "") displayColors(); /* 040003 */
   if(vSizeHTML!="") $(".prodSizes").html(vSizeHTML);              /* 030100 */
}
function switchComp(vType,curObj){
 $(".compTypeContainerH").hide();
 $(".compSelected").removeClass("compSelected");
 $(curObj).addClass("compSelected");
 vType = "#" + vType;
 $(vType).fadeIn(250);
}

/* 040001 - removed displayComprables(). */

function goStyle(vStyleCode,vStyleColor){
   golink("b2c/product.w?product=" + vStyleCode + "&color=" + vStyleColor + vBrowseParam,"main"); /* 040001 */
}

//========--------   Color/Size Selection   --------========\\

function setSize(vSizeCode,vThis){
  var vStockQty=-1;                                                /* E020000 */
  if(vSizeCode=="none" || !vIsRetail ) { return; }
  $(".cartError").html("");
  vSelectedSize = vSizeCode;
  if(document.getElementById("size" + vSelectedProd))
    document.getElementById("size" + vSelectedProd).value = vSizeCode;
  $(".sizeOuterSelected").attr("class","sizeOuter");
  $(".sizeOuterOOSSelected").attr("class","sizeOuterOOS");
  vStockQty=checkStock(vSelectedColor,vSelectedSize,vDefaultWhse); /* E020000 */
  if(vStockQty > 0 || vStockQty==-1)                               /* E020000 */
    vClass="sizeOuterSelected";
  else
    vClass="sizeOuterOOSSelected";
  if(vThis == "")
    $("div[sizeCode='" + vSizeCode + "']").addClass(vClass);
  else
    vThis.className=vClass;

  $.each(styleObj.ttSize,function(i){
    if (styleObj.ttSize[i].sizeCode == vSizeCode) {
      if (styleObj.ttSize[i].fullDesc != "") vSelectedSizeDesc = styleObj.ttSize[i].fullDesc; /* 040000 */
      else vSelectedSizeDesc = styleObj.ttSize[i].description;             /* 040000 */
      $(".selectedSize").html(vSelectedSizeDesc);
    }
  });

  if (vSelectedSize != "" && vSelectedColor != "")
  {
   /********************v T010007 v********************/
   if (vTooltipSettings != "") {                                   /* 040000 */

      /* Hide the tool tip for selected a size. */
      $("#tip").remove();
      $(".btnShoppingBag").cluetip({});
      $(".btnWishlist").cluetip({});
   }                                                               /* 040000 */

   /********************^ T010007 ^********************/

   priceItem(vSelectedColor,vSelectedSize);
  }

  displayColors();
}
function setColor(vColorCode,vThis,vImgSwitch){

  resetFlash();                                                    /* 030200 */
  var vStockQty=-1;                                                /* 030100 */
  var newLgImg;
  var newZmImg;
  var vColorObj;                                                   /* 010102 */

  $(".cartError").html("");
  if(vColorCode=="none") { return; }
  if(document.getElementById("#imgLibDiv")) $("#imgLibDiv").hide();
  vSelectedColor = vColorCode;

  if(document.getElementById("color" + vSelectedProd))
    document.getElementById("color" + vSelectedProd).value = vColorCode;

  if(vColorCode == '') {                                           /* 010102 */
    newLgImg = styleObj.imageLg;
    newZmImg = styleObj.imageZm;
  }

  $(styleObj.ttColor).each(function(i){
      if(styleObj.ttColor[i].colorCode == vColorCode){

         if (styleObj.ttColor[i].imageLg != "" && styleObj.ttColor[i].imageLg != null ){
           newLgImg = styleObj.ttColor[i].imageLg;
           newZmImg = styleObj.ttColor[i].imageZm;
         }else{
           newLgImg = styleObj.imageLg;
           newZmImg = styleObj.imageZm;
         }
         $(".prodSizeRange").html(styleObj.ttColor[i].availSizes); /* T010010 */
         return;
      }
  });
  if(vImgSwitch)
     swapImg(newLgImg);

  if(newZmImg != "" && newZmImg != null){
    MagicZoom.stop(zoomObj);
    MagicZoom.update(zoomObj,newZmImg,newLgImg); /* 020000 */
    MagicZoom.start(zoomObj);
  }
  else
    MagicZoom.stop(zoomObj);

  vLockedImg = $(".imageCell").attr("src");

  $(".colorOuterSelected").attr("class","colorOuter");
  $(".colorOuterOOSSelected").attr("class","colorOuterOOS");
  vStockQty=checkStock(vSelectedColor,vSelectedSize,vDefaultWhse);
  if(vSelectedSize == "" || vStockQty > 0 || vStockQty==-1)        /* E020000 */
    vClass="colorOuterSelected";
  else
    vClass="colorOuterOOSSelected";
  if(vThis == "")
    $("div[colorCode='" + vColorCode + "']").addClass(vClass);
  else
    vThis.className=vClass;

  $.each(styleObj.ttColor,function(i){
    if (styleObj.ttColor[i].colorCode == vColorCode) {
      vColorObj = styleObj.ttColor[i];
    }
  });

  /*vvv 010102 vvv*/

  vSelectedColorDesc = '';
  if (vColorObj != null) {
    vSelectedColorDesc = vColorObj.description;
    if (vColorObj.fabDesc != '' && vColorObj.fabDesc != null)
      vSelectedColorDesc += ' ' + vColorObj.fabDesc;
  }

  $(".selectedColor").html(vSelectedColorDesc);

  /*^^^ 010102 ^^^*/

  if (vSelectedSize != "" && vSelectedColor != "")
  { priceItem(vSelectedColor,vSelectedSize); }

  if(styleObj.ttSizeScale && styleObj.ttSizeScale[1] != null)
    displayMultiSizes();
  else if(styleObj.ttSize!=null)  /* 010008 */
    displaySizes();
  if(styleObj.ttAltView)
    switchAltViews(vColorCode);
}

function setMultiSize(vIndex,vDimValue,vThis){
  if(!vIsRetail ) { return; }
  var vFullSizeCode = "";
  var vFullSize = true;

  vSelectedMultiSize[vIndex] = vDimValue;
  $(".sizeOuterSelected" + vIndex).attr("class","sizeOuter" + vIndex);
  vThis.className="sizeOuterSelected" + vIndex;
  $.each(vSelectedMultiSize, function(i){
     vFullSizeCode += vSelectedMultiSize[i];
     if(vSelectedMultiSize[i] == "")
       vFullSize = false;
  });

  if(vFullSize){
    vSelectedSize = vFullSizeCode;
    $.each(styleObj.ttSize,function(i){
      if (styleObj.ttSize[i].sizeCode == vSelectedSize) {
        if (styleObj.ttSize[i].fullDesc != "") vSelectedSizeDesc = styleObj.ttSize[i].fullDesc; /* 040000 */
        else vSelectedSizeDesc = styleObj.ttSize[i].description;             /* 040000 */
        $(".selectedSize").html(vSelectedSizeDesc);
      }
    });
    displayColors();
  }
  else
    vSelectedSize = "";

  if (vSelectedSize != "" && vSelectedColor != "")
  { priceItem(vSelectedColor,vSelectedSize); }
  displayMultiSizes();
}
//========--------   size / stock checking   --------========\\

/********************v E020000 v********************/

function checkStock(vColorCode,vSizeCode,vWhse){
  var vAvailQty = -1;

  $.each(styleObj.ttItem,function(i){
    if(styleObj.ttItem[i].colorCode == vColorCode && styleObj.ttItem[i].sizeCode == vSizeCode) {
      if (styleObj.ttItem[i].availQty == null)
        vAvailQty = -1;
      else
        vAvailQty = styleObj.ttItem[i].availQty;
      return; // returns from $.each function
    }
  });

  /********************^ E020000 ^********************/
  return vAvailQty;
}

function checkStockItem()
{
 var vAvailQty = 0;
   
  /******v E020301 v******/     
  
  if (typeof vUpsells == "object") {
    $.each(vUpsells.ttUpsell,function(i) {
      if (vUpsells.ttUpsell[i].upsellProdCode == vSelectedProd) {
         vAvailQty = parseInt(vUpsells.ttUpsell[i].availQty);
      }
    });
   
    return vAvailQty; /* E020308 Always return */
  }

  /******^ E020301 ^******/

  $.each(styleObj.ttItem,function(i)
  {
      if (styleObj.ttItem[i].availQty == null)
        vAvailQty = 1;
      else
        vAvailQty = styleObj.ttItem[i].availQty;
      return; // returns from $.each function
  });

  return vAvailQty;
}

function setStock(vColorCode,vSizeCode,vQty){
  var vAvailQty = 0;
  $.each(styleObj.ttItem,function(i){
    if(styleObj.ttItem[i].colorCode == vColorCode && styleObj.ttItem[i].sizeCode == vSizeCode) {
      styleObj.ttItem[i].availQty -= vQty;
      return; // returns from $.each function
    }
  });
}

function setStockItem(vQty){
  var vAvailQty = 0;

  /******v E020301 v******/     

  var upsellMode = false;
  if (typeof vUpsells == "object") {
    $.each(vUpsells.ttUpsell,function(i) {
      if (vUpsells.ttUpsell[i].upsellProdCode == vSelectedProd) {
        upsellMode = true;
        vUpsells.ttUpsell[i].availQty -= vQty;
        return;  // returns from $.each function
      }
    });
    if (upsellMode)
      return;
  }

  /******^ E020301 ^******/

  $.each(styleObj.ttItem,function(i){

      styleObj.ttItem[i].availQty -= vQty;
      return; // returns from $.each function

  });
}


function multiSizeCheckStock(vIndex,vDimValue,vWhse){
  var vAvailQty = 0;
  var vTempSize = "";
  var vSize     = "";
  
  //Return if no color is selected
  if(vSelectedColor == "") return 1; /* 040003 */
  //return true if no other size dimension is selected
  $.each(vSelectedMultiSize,function(k){
     if (k != vIndex)
        vTempSize += vSelectedMultiSize[k];
     if (k == vIndex)
        vSize += vDimValue;
     else
        vSize += vSelectedMultiSize[k];
  });
  if (vTempSize == "")
  { return 1; }

  $.each(styleObj.ttItem,function(i){
    if(styleObj.ttItem[i].colorCode == vSelectedColor && styleObj.ttItem[i].sizeCode == vSize) {
      if (styleObj.ttItem[i].availQty == null)
        vAvailQty = 1;
      else
        vAvailQty = styleObj.ttItem[i].availQty;
      return; // returns from $.each function
    }
  });
  return vAvailQty;
}
function checkItem(vColorCode,vSizeCode){
  var vFound = false;
  $.each(styleObj.ttItem,function(k){
    if(styleObj.ttItem[k].colorCode == vColorCode && styleObj.ttItem[k].sizeCode == vSizeCode)
    { vFound = true; return; }
  });
  return vFound;
}
function multiSizeCheckItem(vIndex,vDimValue){
  var vFound = false;
  var vTempSize = "";
  var vSize     = "";

  //return true if no color or other size dimension is selected
  if(vSelectedColor == "")
  { return true; }
  $.each(vSelectedMultiSize,function(k){
     if (k != vIndex)
        vTempSize += vSelectedMultiSize[k];
     if (k == vIndex)
        vSize += vDimValue;
     else
        vSize += vSelectedMultiSize[k];
  });
  if (vTempSize == "")
  { return true; }
  return checkItem(vSelectedColor,vSize);
}
//========----   Feature Icon Display  ----========\\
function displayFeatIcons(){
  if(styleObj.ttFeatIcon){
    $.each(styleObj.ttFeatIcon,function(i){
     $(".prodIcons").append("<img src='" + styleObj.ttFeatIcon[i].icon + "' class='featureIcon' alt='" + styleObj.ttFeatIcon[i].description + "' />");
    });
  }
}
//========--------   Update Price   --------========\\
function priceItem(vColorCode,vSizeCode,vItemNumber){ /* 010007 */
  var newPrice = "";
  $.each(styleObj.ttItem,function(k){
    if((styleObj.ttItem[k].colorCode == vColorCode && styleObj.ttItem[k].sizeCode == vSizeCode) || vItemNumber == styleObj.ttItem[k].itemNumber){ /* 010007 */
      if(styleObj.ttItem[k].salePrice <= 0 ){
        $(".disclaimer").hide();
        $(".salePriceDiv").hide();
        $(".regPriceStrike").addClass("regPrice");
        $(".regPriceStrike").removeClass("regPriceStrike");
        newPrice = parseFloat(styleObj.ttItem[k].regPrice); /* E010100 */
        $(".regPrice").html( getCurrency(newPrice,currencyJS) );
        $(".regPriceLabel").html(vRegPriceLabel);
        vSelectedPrice = newPrice.toFixed(2);
      }
      else{
        newPrice = parseFloat(styleObj.ttItem[k].regPrice);
        $(".regPriceLabel").html(vRegOnSaleLabel);
        $(".regPrice").html( getCurrency(newPrice,currencyJS) ); /* E010100 */
        $(".regPrice").addClass("regPriceStrike");
        $(".regPrice").removeClass("regPrice");
        newPrice = parseFloat(styleObj.ttItem[k].salePrice);
        vSelectedPrice = newPrice.toFixed(2);
        $(".salePrice").text(getCurrency(newPrice,currencyJS) ); /* E010100 */
        $(".salePriceDiv").show();
        if(styleObj.ttItem[k].disclaimer == "true") /* T010008 */ /* T010009 */
         $(".disclaimer").show();
        else
         $(".disclaimer").hide();

      }
      return;
    }
  });
}
//========--------   MouseOvers   --------========\\
function swapImg(vNewImg,vNoLock){
  resetFlash();                                                    /* 030200 */
  if(vNewImg != "" ){
    if(!vNoLock)
      vLockedImg = $(".imageCell").attr("src");
    $(".imageCell").attr("src",vNewImg);
  }
}
function restoreImg(){
  if(vLockedImg != "" && $(".imageCell").attr("src") != vLockedImg)
  { $(".imageCell").attr("src",vLockedImg); }
}
function showOOSMsg(vColor,vSize,vQty){
  if (vQty==-1) return;
  var vPosition   = $(".imgUpper").position();

  if (vQty>0) { $("#imgMessage").hide(); return; }                 /* 040004 */

  if(vQty==0 || vQty == undefined)                    /* 030100 */ /* 040004 */
  $(".imgMessageText").html(vColor + " is currently out of stock in " + vSize);
  else                                                             /* 030100 */
  if(!vIsRetail)                                                   /* 030100 */
    $(".imgMessageText").html(vColor + " currently has " + vQty + " available in " + vSize);

  var vTopOffset  = ( $(".prodImgInner").outerHeight() - $("#imgMessage").outerHeight() - ( $("#imgMessage").outerHeight()/2) );
  var vLeftOffset = ( $(".imgUpper").outerWidth() - $("#imgMessage").outerWidth() )/2;

  $("#imgMessage").css("top",vPosition.top + vTopOffset);
  $("#imgMessage").css("left",vPosition.left + vLeftOffset);
  $("#imgMessage").show();
}
function showMultiSizeOOSMsg(vColor,vIndex,vDimValue){
  var vSize     = "";
  var vSizeDesc = "";
  $.each(vSelectedMultiSize,function(k){
     if (k == vIndex)
        vSize += vDimValue;
     else
        vSize += vSelectedMultiSize[k];
  });
  $.each(styleObj.ttSize,function(i){
     if(styleObj.ttSize[i].sizeCode == vSize){
        if (styleObj.ttSize[i].fullDesc != "") vSizeDesc = styleObj.ttSize[i].fullDesc; /* 040000 */
        else vSizeDesc = styleObj.ttSize[i].description;           /* 040000 */
        return;
     }
  });
  showOOSMsg(vColor,vSizeDesc);
}
function hideOOSMsg(){
  $("#imgMessage").hide();
}
/****** Retail Add to Cart ******/
function retailAddToCart(vProduct,vColor,vSize,vOrderQty,vOrderType,vOFS,vUpsell,vOrf,vFreightAmt,vSalesAmt){  /* E010007 */ /* E010008 */ /* E010009 */ /* E010201 */
  /* E020100 - Remove QTY Grab, it's passed in */
  if(vProdType=="S")  /* 010008 */
  {
   if(vColor == "" || vColor == "none" || vColor == null){
     $(".cartError").html("Please choose a color to continue.");
     return;  }
   if(vSize == "" || vSize == "none" || vSize == null) {
     $(".cartError").html("Please choose a size to continue.");
     return;  }
  }
  if (vOrderQty == "" ) {
    $(".cartError").html("Please enter a quantity before adding item(s) to shopping bag.");
    return;  }
  if (isNumeric(vOrderQty) == false) {
    $(".cartError").html("Please enter a numeric quantity before adding item(s) to shopping bag.");
    $("#qty").attr("value","")
    
    return;  }
  if (vOrderQty <= 0)  {
    $(".cartError").html("Please enter a quantity before adding item(s) to shopping bag.");
    return;  }

  /******v 010101 v******/

  if (vOrderLimit > 1 && (vTotalOrderQty + parseFloat(vOrderQty))  > vOrderLimit) {
   if (vOrderLimitMsg.indexOf("<qty>") != -1){
     vOrderLimitMsg = vOrderLimitMsg.replace("<qty>",vOrderLimit);
   }
   else{ 
     vOrderLimitMsg = vOrderLimitMsg.replace(/\d/, vOrderLimit);
   }

     $(".upsellCartError").html(" ");                             /* E020301 */
     $(".cartError").html(" ");
     $("#qty").focus();
     alert(vOrderLimitMsg); 
     return;
  }
  else{
     $(".cartError").html("");
  }

  /******^ 010101 ^******/

  var invAvail=0;  /* 010008 */
  if(vProdType=="S") invAvail = parseInt(checkStock(vColor,vSize));  /* 010008 */
  if(vProdType=="I") invAvail = parseInt(checkStockItem());
 
  /***vv 030101 vv***/
  if (vMaxUnits > 0 && vOrderQty > vMaxUnits) /* 030204 */
  {
    alert("The maximum number of units that may be purchased at one time is " + vMaxUnits.toString() + ".  Please contact our customer service department to order more than " + vMaxUnits.toString() + ".");
    invAvail = vMaxUnits;
    $("#qty").attr("value",invAvail)
    $("#qty").focus();
    return;
  }
  /***^^ 030101 ^^***/
  if(invAvail < vOrderQty)  {
    if (invAvail <= 0)
     $(".cartError").html("The selected item is currently out of stock.");
    else{
     var alertMsg = "You have ordered " + vOrderQty + " however only ";
     if (invAvail == 1)
       alertMsg += "1 is available.";
     else
       alertMsg += invAvail + " are available.";
     alert(alertMsg);
    }
    if (invAvail <= 0 )
       invAvail = 1;
    $("#qty").attr("value",invAvail)
    $("#qty").focus();
    return;
  }
  addToCart(vProduct,vColor,vSize,vOrderQty,vOrderType,false,vOFS,vUpsell,vOrf,vFreightAmt,vSalesAmt);     /* E010007 */ /* E010008 */ /* E010009 */ /* E010201 */
  if(vProdType=="S") setStock(vColor,vSize,vOrderQty);  /* 010008 */
  if(vProdType=="I") setStockItem(vOrderQty);  /* 010008 */
  vTotalOrderQty += + parseFloat(vOrderQty); /* 010101 */

}
/*===---- Retail Functions ----===*/
function clearmessage(){
  $(".cartError").html("");
}
function enterCheck(event,id)
{
  if(event.keyCode == 13)
  {
    $("#retailAddToCart").click();
    return false;
  }
  return true;
}

function bookmarkMe(){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(location.href,document.title);
  }
  else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(document.title,location.href,"");
  }
  else {
   if(agt.indexOf("opera")!= -1)
    alert("Press CTRL-T to bookmark this page.");
   else
    alert("Press CTRL-D to bookmark this page.");
  }
}

function openBlogText(vDescription,vImgPth,vFullDesc){
 if (styleObj){
   if (styleObj.description)
     vDescription = styleObj.description;
   if (styleObj.fullDesc != "" && styleObj.fullDesc != null)
     vFullDesc = styleObj.fullDesc;
   if (styleObj.imageTh != "" && styleObj.imageTh != null)
     vImgPth = styleObj.imageTh;
 }
 var vBlogHTML = "<table cellspacing='0' cellpadding='0' border='0' class='blogTable'>" +
                 "<tr><td colspan='2' style='font-weight:bold;font-size:12pt;'>" + document.title +
                 "</td></tr><tr><td rowspan='2'><img src='" + vImgPth + "' alt=''></td>" +
                 "<td style='text-align:center;vertical-align:top;height:25px;'><a style='font-weight:bold;font-size:11pt;' href='" + appPath + "/site.w?location=b2c/product.w&product=" + vSelectedProd +   /* 010010 */
                 "&frames=no&target=main&sponsor=" + vSponsorCode + "'>" + vDescription + "</a>" +
                 "</td><tr><td style='vertical-align:top;'>" + vFullDesc + "</td></tr></table>";
 vBlogHTML = "<div style='width:400px;text-align:center;margin:none;pading:none;'><table cellspacing='0' cellpadding='0' border='0' style='width:400px'><tr><td class='blogInstructions' style='text-align:center;'>Copy and paste the HTML text below to share this product on your blog or online profile.</td></tr></table>" + vBlogHTML + "<br/> <textarea>" + vBlogHTML + "</textarea></div>";
 if(!document.getElementById("blogPost")){
   $("body").append("<div id='blogPost' title='Blog HTML' style='width:400px;' />");
   $("#blogPost").html(vBlogHTML);
   $("#blogPost").dialog({width:450,height:475,resizable:false} );
 }
 else
   $("#blogPost").dialog("open");
}

function showAltViews(vColorCode){
 var vAltViewHTML = "";
 var vAlt;
 if(document.getElementById("altViews")){
   $("#altViews").html('');
   $.each(styleObj.ttAltView,function(i){
     if(styleObj.ttAltView[i].colorCode == vColorCode){
        vAlt = $($(document.createElement("div")));
        vAlt.attr("id","altView" + styleObj.ttAltView[i].altId)
            .attr("colorCode",vColorCode)
            .attr("rel","zoom-id:zoom1")
            .attr("rev",styleObj.ttAltView[i].imageLg)
            .attr("href",styleObj.ttAltView[i].imageZm)
            .mouseover(function(){ swapImg(styleObj.ttAltView[i].imageLg,true); })
            .mouseout(function(){ restoreImg(); })
            .click(function(){
                vLockedImg=styleObj.ttAltView[i].imageLg;
                if(styleObj.ttAltView[i].imageZm != ""){
                  MagicZoom.stop(zoomObj);
                  MagicZoom.update(zoomObj,styleObj.ttAltView[i].imageZm,styleObj.ttAltView[i].imageLg);
                  MagicZoom.start(zoomObj);
                }
                else{
                  MagicZoom.stop(zoomObj);
                }
             })
            .html("<img src='" + styleObj.ttAltView[i].imageSm + "' alt='' />");

        $("#altViews").append(vAlt);
     }
   });
   if ($(".altViewSide"))
     $(".prodDesc").width($(".prodDesc").width() - $(".altViewSide").outerWidth() );
   $("#altViews").css("display","block");
 }
}
/***vv 020000 vv***/
function switchAltViews(vColorCode){
 var vAltViewHTML = "";
 var vAltViewId;
 if(document.getElementById("altViews")){
   $("#altViews").html('');
   $.each(styleObj.ttAltView,function(i){
     if(styleObj.ttAltView[i].colorCode == vColorCode){
        vAlt = $($(document.createElement("div")));
        vAlt.attr("id","altView" + styleObj.ttAltView[i].altId)
            .attr("colorCode",vColorCode)
            .attr("rel","zoom-id:zoom1")
            .attr("rev",styleObj.ttAltView[i].imageLg)
            .attr("href",styleObj.ttAltView[i].imageZm)
            .mouseover(function(){ swapImg(styleObj.ttAltView[i].imageLg,true); })
            .mouseout(function(){ restoreImg(); })
            .click(function(){
                vLockedImg=styleObj.ttAltView[i].imageLg;
                if(styleObj.ttAltView[i].imageZm != ""){
                  MagicZoom.stop(zoomObj);
                  MagicZoom.update(zoomObj,styleObj.ttAltView[i].imageZm,styleObj.ttAltView[i].imageLg);
                  MagicZoom.start(zoomObj);
                }
                else{
                  MagicZoom.stop(zoomObj);
                }
             })
            .html("<img src='" + styleObj.ttAltView[i].imageSm + "' alt='' />");

        $("#altViews").append(vAlt);
     }
   });
   //reset all non color specific altViews to defaults
   $.each(styleObj.ttAltView,function(i){
     if(styleObj.ttAltView[i].colorCode == "" && !document.getElementById("altView" + styleObj.ttAltView[i].altId) ){
        vAlt = $($(document.createElement("div")));
        vAlt.attr("id","altView" + styleObj.ttAltView[i].altId)
            .attr("colorCode",vColorCode)
            .attr("rel","zoom-id:zoom1")
            .attr("rev",styleObj.ttAltView[i].imageLg)
            .attr("href",styleObj.ttAltView[i].imageZm)
            .mouseover(function(){ swapImg(styleObj.ttAltView[i].imageLg,true); })
            .mouseout(function(){ restoreImg(); })
            .click(function(){
                vLockedImg=styleObj.ttAltView[i].imageLg;
                if(styleObj.ttAltView[i].imageZm != ""){
                  MagicZoom.stop(zoomObj);
                  MagicZoom.update(zoomObj,styleObj.ttAltView[i].imageZm,styleObj.ttAltView[i].imageLg);
                  MagicZoom.start(zoomObj);
                }
                else{
                  MagicZoom.stop(zoomObj);
                }
             })
            .html("<img src='" + styleObj.ttAltView[i].imageSm + "' alt='' />");

        $("#altViews").append(vAlt);
     }
   });

 }
}
/***^^ 020000 ^^***/

/***vv 030200 vv***/

function productFlash(vFlash) {
  vImgHtml = $(".prodImg").html();
  $(".prodImg").html("");
  $(".prodImg").flashembed({                                       /* 030203 */
     src: vFlash,
     wmode: "transparent"
  });
}
function resetFlash() {
   if (vImgHtml != "") {
      $(".prodImg").html(vImgHtml);
      vImgHtml = "";
   }
}

/***^^ 030200 ^^***/

/***vv 030201 vv***/
/***vv 040006 vv***/

function showVideo(vVideo,vHideSections) {
   vHideSections = vHideSections.split(",");
   if ($("#" + vVideo).html() == "")                               /* 030202 */
      $("#" + vVideo).html(vVideoEmbed);                           /* 030202 */
   $("#" + vVideo).show();
   vVideoEmbed = $("#" + vVideo).html();                           /* 030202 */
   $.each(vHideSections,function(i) {
      $("#" + vHideSections[i]).hide();
   });
}
function hideVideo(vVideo,vShowSections) {
   vShowSections = vShowSections.split(",");
   $("#" + vVideo).html("");                                       /* 030202 */
   $("#" + vVideo).hide();
   $.each(vShowSections,function(i) {
      $("#" + vShowSections[i]).show();
   });
}

/***^^ 040006 ^^***/
/***^^ 030201 ^^***/

/***vv E010100 vv***/

function sendFriendEmail(product) {
  var toEmail = $("#toemail").val();
  var yourEmail = $("#youremail").val();
  if ($("#subject").val() == "") {
     alert("Please enter a subject.");
     $("#subject").focus();
     return;
  }
  if ($("#toname").val() == "") {
     alert("Please enter your friend's name.");
     $("#toname").focus();
     return;
  }
  if (toEmail == "") {
     alert("Please enter your friend's email address.");
     $("#toemail").focus();
     return;
  }
  if (!echeck(toEmail))
  {
     alert("Please a valid email address.");
     $("#toemail").focus();
     $("#toemail").select();
     return;
  }
  if ($("#yourname").val() == "") {
     alert("Please enter your name.");
     $("#yourname").focus();
     return;
  }
  if (yourEmail == "") {
     alert("Please enter your email address.");
     $("#youremail").focus();
     return;
  }
  if (!echeck(yourEmail))
  {
     alert("Please a valid email address.");
     $("#youremail").focus();
     $("#youremail").select();
     return;
  }
  var queryString = $("#efForm").serialize();
  $(":input").attr("disabled",true);
  $("#emailSubmit").hide();
  $("#emailProcessing").show();
  $.ajax({
    type: "GET",
    url: hostDomain + appPath + '/b2c/product-email.w?' + queryString + "&product=" + vSelectedProd + "&sponsor=" + fdmSponsor,
    complete: function(data) {
      $(":input").attr("disabled",false);
      $("#efInner").hide();
      $("#efSuccess").show();
    }
  });
}

function closeEmailFriend() {
  $("#efSuccess").hide();
  $("#efInner").show();
  $("#emailSubmit").show();
  $("#emailProcessing").hide();
}

function showVideoOverlay(vFileName) {
  if(vFileName!=""){
    $("#videoOverlayInner").flashembed({                            
         src: vFileName,
         wmode: "transparent"
    });
  }
  else{
   $('#video').html("<img src='" + imgPath + "/noVideo.jpg' alt='' />");
  }
}

function hideVideoOverlay() {
   $("#videoOverlayInner").html("");
}

function showFeatImg(vDetailCode){
  if(styleObj.ttFeatIcon){
     $.each(styleObj.ttFeatIcon,function(i){
        if(styleObj.ttFeatIcon[i].featDetailCode == vDetailCode && styleObj.ttFeatIcon[i].iconLg != "" ){
           $("#featureImgLarge").html('<img src="' + styleObj.ttFeatIcon[i].iconLg + '">');
           $("#featureImgDesc").html(styleObj.ttFeatIcon[i].description);
        }
     });
  }
}

function hideFeatImg() {
   $("#featureImgLarge").html('');
   $("#featureImgDesc").html('');
}

/* vvv E020305 vvv */
function clearClick() {
  clearTimeout(errorFlag);
  clickFlag = false;
  refreshed = true;
}
/* ^^^ E020305 ^^^ */

function readAllReviews() {
   $("#readReviewOverlay").overlay({
     effect: 'apple',
     onBeforeLoad: function(event) { 
        readReviews(vSelectedProd); 
     },
     api: true
   }).load();
}

function readReviews(vProduct,vPage,vUpdateDiv,vFirst,vTabDiv) {  /* E020004 */
  if (vUpdateDiv == null) 
     vUpdateDiv = "readReviews";
  if (vFirst == null)
     vFirst = 0;
  if (vPage == null)
     vPage = 1;
  if (vFirst > 0 && vFirstHtml != "") { // only fire AJAX once, we do not want unnecessary http requests
     $("#" + vUpdateDiv).html(vFirstHtml);
     return false;
  }
  $.ajax({
  url: hostDomain + appPath + "/b2c/prod-read-review.w?product=" + vProduct + "&page=" + vPage + "&first=" + vFirst + "&frames=no&target=main&sponsor=" + fdmSponsor + getNoCache(),  
  success: function(html){
    $("#" + vUpdateDiv).html(html);
    /******v E020004 v******/
    if (vFirst > 0) {
      if (html.indexOf("no results") == -1) {
         vFirstHtml = html;   
         if (vTabDiv != null)
           setTab(true,vUpdateDiv,vTabDiv);
      }  
      else
        setTab(false,vUpdateDiv,vTabDiv);
    }
    /******^ E020004 ^******/
  }
 });
 return false;
}

function AutoTab( charLimit, currentControl, nextControlID ) {

	/* Can check for other types later, assumes and input of type text for now */
	var maxLength = currentControl.maxLength;
	var currentLength = currentControl.value.length;

	/* if maxlength is present we are using it */
	if( maxLength > 0 )
			charLimit = maxLength;

	if( currentLength >= charLimit ){
		var field = document.getElementById(nextControlID);

		if( field == null ){
			alert( "Next Focusable control with ID: " + nextControlID + " could not be found." );
			return;
		}

		field.focus();
		field.select();
	}
}

function writeReview(vProduct,vUpdateDiv) {
  $.ajax({
  url: hostDomain + appPath + "/b2c/prod-write-review.w?product=" + vProduct + "&frames=no&target=main&sponsor=" + fdmSponsor + getNoCache(),  
  success: function(html){
    $("#" + vUpdateDiv).html(html); 
  }
 });
 return false;
}

/********************v E020306 v********************/ 
function asciiCheck(vCheck) {
  var vReturn = ""; 
  var vCode = 0; 
   for (i=0; i<vCheck.length; i++) { 
      vCode = vCheck.charCodeAt(i); 
	  if(vCode >= 32 && vCode <= 126)
      { 
         vReturn = vReturn + vCheck.charAt(i);  /* E020307 */
      } 
   } 
   return vReturn; 
}
/********************^ E020306 ^********************/ 

function postReview(vProduct,vUpdateDiv) {
  var rating = $("input[name^=revrating]:checked").val();
  var postedBy = $("#revpostedby").val();
  var email = $("#revemail").val();
  var comment = $("#revcomment").val();
  var guestID = "GUEST-";                                          /* E020002 */
  var areaCode = $("#revareacode").val();
  var phoneP1 = $("#revphonep1").val();
  var phoneP2 = $("#revphonep2").val();
  var extn = $("#revext").val();
  var phone = phoneP1 + phoneP2;

  comment = asciiCheck(comment);                                  /* E020306 */
  comment = encodeURIComponent(comment);                          /* E020307 */

  if (rating == undefined) {
     alert("Please select a rating to continue.");
     clearClick(); // E020309 
     return false; // E020309
  }

  if (postedBy == "") {
     alert("Please enter your name.");
     clearClick(); // E020309 
     $("#revpostedby").focus();
     $("#revpostedby").select();
     return false; // E020309
  }

  if (email == "") {
     alert("Please enter your email address.");
     clearClick(); // E020309 
     $("#revemail").focus();
     $("#revemail").select();
     return false; // E020309
  }

  if (areaCode != "" || phoneP1 != "" || phoneP2 != "" || extn != "") {

     if (areaCode == "" || areaCode.length != 3 || isNaN(areaCode)){
        alert("A valid 3 digit Area Code must be entered.");
        clearClick(); // E020309 
        $("#revareacode").focus();
        $("#revareacode").select();
        return false; // E020309
	    }

     if (phoneP1 == "" || phoneP1.length != 3 || isNaN(phoneP1)){
        alert("A valid Phone # must be entered.");
        clearClick(); // E020309 
        $("#revphonep1").focus();
        $("#revphonep1").select();
        return false; // E020309
     }

     if (phoneP2 == "" || phoneP2.length != 4 || isNaN(phoneP2)){
        alert("A valid Phone # must be entered.");
        clearClick(); // E020309 
        $("#revphonep2").focus();
        $("#revphonep2").select();
        return false; // E020309
     }

     if (extn != "" && isNaN(extn)){
        alert("The Extension entered was not valid.");
        clearClick(); // E020309 
        $("#revext").focus();
        $("#revext").select();
        return false; // E020309
     }

  }

  if (!echeck(email)){
     alert("Please enter a valid email address.");
     clearClick(); // E020309 
     $("#revemail").focus();
     $("#revemail").select();
     return false; // E020309
  }

  if (comment == "") {
     alert("Please enter a comment before submitting.");
     clearClick(); // E020309 
     $("#revcomment").focus();
     $("#revcomment").select();
     return false; // E020309
  }

  guestID += postedBy;                                             /* E020002 */

  $.ajax({
    type: "POST",
    url: hostDomain + appPath + "/b2c/product-review-ajax.w?product=" + vProduct + "&rating=" + rating + "&userid=" + guestID + "&comment=" + comment + "&email=" + email + "&areacode=" + areaCode + "&phone=" + phone + "&extn=" + extn + "&frames=no&target=main&sponsor=" + fdmSponsor + getNoCache(), /* E020002 */
    success: function(html){
      $("#" + vUpdateDiv).html('<div class="reviewPosted">Thank you for posting your review.</div>'); 
      clearClick();    /* E020304*/
    },
    error: function (request, status, error) {
      $("#" + vUpdateDiv).html('<div class="reviewPosted">There was a problem processing your request. If this problem persists, contact customer service.</div>');  /* E020306 */
      clearClick(); // E020309 
    }
  });
  return false; // E020309 
}

/******v E020004 v******/

function displayTabs() {
   $("#tabProcess").show();
   if ($("#detailsCont").children().length != 0) 
      setTab(true,"detailsCont","detailsContLink");
   else
      setTab(false,"detailsCont","detailsContLink");
   getCompAdd('ACC','accessoriesCont','accessoriesContLink');
   getCompAdd('PAR','partsCont','partsContLink');
   getFaqs(vSelectedProd,'faqsCont','faqsContLink');
   readReviews(vSelectedProd,1,'reviewsCont',3,'reviewsContLink');   
   if($(".compTypeTitle").length != 0)                           /* E020302 */
      $("#detailRight").css("background-color","#F3F3F3");       /* E020302 */
   else /* don’t show the grey box if no Comps */                /* E020302 */
      $("#detailLeft").css("border", "none");                    /* E020302 */

}

function setTab(displayTab,vTab,vTabLink) {
  var vShowTab = "";
  vTabCount += 1;
  if (displayTab) {
    if (vTabs == "")
       vTabs = vTab;
    else
       vTabs += "," + vTab;
    if (vTabLinks == "")
       vTabLinks = vTabLink;
    else
       vTabLinks += "," + vTabLink;
  }
  if (vTabCount == 5) { // display all tabs
    if (vTabs != "") {
      var vTabsArr = vTabs.split(",");
      var vTabLinksArr = vTabLinks.split(",");
      $.each(vTabsArr,function(i) {
        if (vShowTab == "") vShowTab = vTabsArr[i];
        $("#" + vTabLinksArr[i]).show();
      });
    }
    $("#manualsContLink").show();
    $("#tabContainer").show();
    // manuals is always available 
    if (vShowTab != "")
       showSection(vShowTab);   
    else
       showSection('manualsCont');    
    $("#tabProcess").hide();
  }
}

/******^ E020004 ^******/

function getCompAdd(vRelCode,vUpdateDiv,vTabDiv) {  
  $.ajax({
  url: hostDomain + appPath + "/b2c/prod-comp-add.w?product=" + vSelectedProd + "&relcode=" + vRelCode + "&frames=no&target=main&sponsor=" + fdmSponsor + getNoCache(),  
    success: function(html){
      /******v E020004 v******/
      if (html.indexOf("no results") == -1) {
         $("#" + vUpdateDiv).html(html); 
         if (vTabDiv != null)
           setTab(true,vUpdateDiv,vTabDiv);
      }  
      else
        setTab(false,vUpdateDiv,vTabDiv);
      /******^ E020004 ^******/
    }
  });  
}
function compAddToCart() {
   var itemList = "";
   var qtyList = "";
   var itemNumber = "";
   var itemQty = "";
   var formError = false;
   $("input:checked").each(function(i) {
      itemNumber = this.id;
      if (itemNumber.indexOf("cas_") != -1) {
         itemNumber = itemNumber.replace("cas_","");
         itemQty = $("#caq_" + itemNumber).val(); 
         if (isNaN(itemQty)) {
            alert("Quantities must be numeric. Please re-enter.");
            $("#caq_" + itemNumber).focus();
            $("#caq_" + itemNumber).select();
            formError = true;
            return false;
         }
         if (itemQty == "" || parseInt(itemQty) <= 0) {
            alert("Please enter a quantity to continue.");
            $("#caq_" + itemNumber).focus();
            $("#caq_" + itemNumber).select();
            formError = true;
            return false;
         }
         if (itemList == "") itemList = itemNumber;
         else itemList += "," + itemNumber;
         if (qtyList == "") qtyList = itemQty;
         else qtyList += "," + itemQty;         
      }     
   });
   if (formError) return;
   addToCart(itemList,'','',qtyList,'C');
}

function getNoCache() {
  var vCurrTime = new Date();
  var vCurrSecs  = (((vCurrTime.getHours() * 60) + vCurrTime.getMinutes()) * 60) + vCurrTime.getSeconds();
  var vNoCache = "&nocache=" + vCurrSecs;
  return vNoCache;
}

/***^^ E010100 ^^***/
/***vv E020001 vv***/

 var vSectionList = "detailsCont,accessoriesCont,partsCont,faqsCont,reviewsCont,manualsCont";
 var vClassOn = "tabOn";
 var vClassOff = "tabOff";
 var vCurrClassOn = "";
 var vCurrClassOff = "";
 function showSection(vSection,vAnchor) {
    var vSectionArr = vSectionList.split(",");
    $.each(vSectionArr,function(i) {
        vCurrClassOn = vClassOn;
        vCurrClassOff = vClassOff;
        if($("#" + vSectionArr[i] + "Link").hasClass(vClassOff + "Long") || $("#" + vSectionArr[i] + "Link").hasClass(vClassOn + "Long")) {
           vCurrClassOn += "Long";
           vCurrClassOff += "Long";
        }
        if (vSectionArr[i] == vSection) {
           $("#" + vSectionArr[i]).show();
           $("#" + vSectionArr[i] + "Link").removeClass(vCurrClassOff);
           $("#" + vSectionArr[i] + "Link").addClass(vCurrClassOn);
        }
        else {
           $("#" +vSectionArr[i]).hide(); 
           $("#" + vSectionArr[i] + "Link").removeClass(vCurrClassOn);
           $("#" + vSectionArr[i] + "Link").addClass(vCurrClassOff);
        }
     });  
    if (vAnchor != null && vAnchor != "")
       document.location.href = "#" + vAnchor;    
 }
var faqDisplayed = false;
function getFaqs(product,vSection,vTabDiv)                                 /* E020004 */
 {
  if (faqDisplayed) return;
  $("#faqsCont").empty();
  $.ajax(
  {
   type: "GET",
   url: hostDomain + appPath + "/b2c/prod-manuals.w?product=" + product + "&sponsor=" + fdmSponsor + getNoCache(),
   dataType: "xml",
   complete: function(data)
   {
    /******v E020004 v******/
    faqDisplayed = true;
    var vTmpObj = $(data.responseXML).find("[type=faq]");
    if(vTmpObj.length >= 1) {
        $("#faqsCont").load( $(vTmpObj).attr("specDetail") ); 
        setTab(true,vSection,vTabDiv);
    }
    else
      setTab(false,vSection,vTabDiv);
    /******^ E020004 ^******/
   }
  });
 } // getFaqs()

function getManuals(vProdNum)
{
 /******v E020003 v******/
 $.ajax({
   type: "GET",
   url: hostDomain + appPath + "/b2c/prod-manuals.w?product=" + vProdNum + "&frames=no&target=main&sponsor=" + fdmSponsor + getNoCache(),
   dataType: "xml",
   complete: function(data) { 
     var vManualHtml = "";
     var vFaqHtml = "";
     var vTmpObj = $(data.responseXML).find("[type=manual]");

     if(vTmpObj.length >= 1) { vManualHtml = "<h3 class='manFaqTitle'>Manual(s)</h3>"; }
     $.each(vTmpObj,function(){
       vManualHtml += "<p><a class='manFaqLink' target='_blank' href='" + $(this).attr("specDetail") + "' >" + $(this).attr("detailDesc") + "</a></p>";
     });

     $("#prodResults").html(vManualHtml);
     
     if (vManualHtml == "" && vFaqHtml == "")
     
     { $("#prodResults").html("<h3 class='manFaqTitle'>No manuals found for entered Model/Part #</h3>");  }
   }
 });
 /******^ E020003 ^******/
} //getManuals()


 /***^^ E020001 ^^***/

