function amz_js_PopWin(url,name,options){
  var ContextWindow = window.open(url,name,options);
  ContextWindow.focus();
  return false;
}
function fnDisplayASINClass(currentRowAsinIndex , currentCount) {
  var addedASINs = window.document.forms["comparison"].addedASINs.value;
  var removeASINs = window.document.forms["comparison"].removeASINs.value;
  var oldASINs = window.document.forms["comparison"].compareListASINs.value;
  var countOfOldASINs = 0;
  var countOfAddedASINs = 0;
  var countOfRemovedASINs = 0;
  var totalCount = 0;

  //decrement 1 from the count to compensate the first comma in the strings
  if(oldASINs != ''){
    countOfOldASINs = (oldASINs.indexOf(',') == 0) ? ((oldASINs).split(",")).length-1 : ((oldASINs).split(",")).length;
  }
  if(addedASINs){
    countOfAddedASINs = (addedASINs.indexOf(',') == 0) ?  (addedASINs.split(",")).length-1 : (addedASINs.split(",")).length;
  }
  if(removeASINs){
    countOfRemovedASINs = (removeASINs.indexOf(',') == 0) ? (removeASINs.split(",")).length-1 : (removeASINs.split(",")).length;
  }
  totalCount = countOfOldASINs + countOfAddedASINs - countOfRemovedASINs;

  if (currentRowAsinIndex%3 == 1){
   document.getElementById("floatedProduct."+currentRowAsinIndex).className =
       "floatedProductCenterCompare compareBoxTop";
   document.getElementById("floatedProductDetailsBtn."+currentRowAsinIndex).className
       = "floatedProductDetailsBtnCenterCompare compareBoxBottom";
  } else {
   document.getElementById("floatedProduct."+currentRowAsinIndex).className = "floatedProduct compareBoxTop";
   document.getElementById("floatedProductDetailsBtn."+currentRowAsinIndex).className = "floatedProductDetailsBtn compareBoxBottom";
  }    
  document.getElementById("addToCompare."+currentRowAsinIndex).className = "addedToCompare";
  document.getElementById("checkbox."+currentRowAsinIndex).className = "fifteen";
  document.getElementById("beforeComparison."+currentRowAsinIndex).style.display = "none"; 
  document.getElementById("afterComparison."+currentRowAsinIndex).style.display = "block";
  if ( currentCount == 1) { 
     if (totalCount == 5) {
       document.getElementById("compareNow."+currentRowAsinIndex).style.display = "block";
     }else if( totalCount < 5 && totalCount !=1 ) {
       document.getElementById("comparison."+currentRowAsinIndex).style.display = "block";
     }
  }
}  
//This function is called on click of checkbox for compare products
function fnCreateASINArray(obj,currentRowAsinIndex, displayItemEndIndex){
 
  var currentAsin = obj.value;
  var addedASINs = window.document.forms["comparison"].addedASINs.value;
  var removeASINs = window.document.forms["comparison"].removeASINs.value;
  var totalCount = 0;
  var input = 0;
  var countOfOldASINs = 0;
  var countOfAddedASINs = 0;
  var countOfRemovedASINs = 0;
  var oldASINs = window.document.forms["comparison"].compareListASINs.value;

  if(obj.checked == true)
  {
    if(removeASINs.indexOf(','+currentAsin)>=0){
      removeASINs = removeASINs.replace(','+ currentAsin ,'');
    } else if ( removeASINs.indexOf(currentAsin)>=0 ) {
      removeASINs = removeASINs.replace(currentAsin ,'');
    }

    if ( oldASINs.indexOf( currentAsin ) < 0 ) {
      addedASINs = addedASINs + ',' + currentAsin;
    }
   
  }
  if(obj.checked == false)
  {
    if(addedASINs.indexOf(','+currentAsin)>=0){
      addedASINs = addedASINs.replace(','+ currentAsin ,'');
    } else if ( addedASINs.indexOf(currentAsin)>=0) {
      addedASINs = addedASINs.replace(currentAsin ,'');
    } else {
      removeASINs =  removeASINs + ',' + currentAsin;
    }
  }

  //decrement 1 from the count to compensate the first comma in the strings
  if(oldASINs != ''){
     countOfOldASINs = ( oldASINs.indexOf(',') == 0 ) ? ((oldASINs).split(",")).length-1 : ((oldASINs).split(",")).length;
  }
  if(addedASINs){
     countOfAddedASINs = ( addedASINs.indexOf(',') == 0 ) ? ((addedASINs).split(",")).length-1 : ((addedASINs).split(",")).length;
  }
  if(removeASINs){
     countOfRemovedASINs = ( removeASINs.indexOf(',') == 0 ) ?  ((removeASINs).split(",")).length-1 : ((removeASINs).split(",")).length;
  }
  totalCount = countOfOldASINs + countOfAddedASINs - countOfRemovedASINs;

  if(obj.checked == false) {
      
  if (currentRowAsinIndex%3 == 1){
     document.getElementById("floatedProduct."+currentRowAsinIndex).className =
         "floatedProductCenterCompare";
     document.getElementById("floatedProductDetailsBtn."+currentRowAsinIndex).className
         = "floatedProductDetailsBtnCenterCompare";
  } else {
     document.getElementById("floatedProduct."+currentRowAsinIndex).className = "floatedProduct";
     document.getElementById("floatedProductDetailsBtn."+currentRowAsinIndex).className = "floatedProductDetailsBtn";
  }     
     document.getElementById("addToCompare."+currentRowAsinIndex).className = "addToCompare";
     document.getElementById("checkbox."+currentRowAsinIndex).className = "fifteen";
     document.getElementById("beforeComparison."+currentRowAsinIndex).style.display = "block";
     document.getElementById("afterComparison."+currentRowAsinIndex).style.display = "none";
     if (document.getElementById("comparison."+currentRowAsinIndex).style.display == 'block' || (totalCount == 4)){
        for ( var index = 0 ; index  < displayItemEndIndex ; ++index){
          input = index + 1;
          if (document.getElementById("ASIN."+input).checked && index != currentRowAsinIndex ){
             document.getElementById("comparison."+index).style.display = "block";
             break;
          }
        }
     }
     document.getElementById("comparison."+currentRowAsinIndex).style.display = "none";
     document.getElementById("compareNow."+currentRowAsinIndex).style.display = "none";
     for (var index=0 ; index < displayItemEndIndex ; ++index) {
       if (totalCount ==1) {
          document.getElementById("comparison."+index).style.display = "none";
       }
       document.getElementById("comparisonError."+index).style.display = "none";
       document.getElementById("compareNow."+index).style.display = "none";
     }
  }

  if (obj.checked == true) {
      
  if (currentRowAsinIndex%3 == 1){
    document.getElementById("floatedProduct."+currentRowAsinIndex).className =
        "floatedProductCenterCompare compareBoxTop";
    document.getElementById("floatedProductDetailsBtn."+currentRowAsinIndex).className
        = "floatedProductDetailsBtnCenterCompare compareBoxBottom";
  } else {
    document.getElementById("floatedProductDetailsBtn."+currentRowAsinIndex).className = "floatedProductDetailsBtn compareBoxBottom";
    document.getElementById("floatedProduct."+currentRowAsinIndex).className = "floatedProduct compareBoxTop";
  }     
    document.getElementById("addToCompare."+currentRowAsinIndex).className = "addedToCompare";
    document.getElementById("checkbox."+currentRowAsinIndex).className = "fifteen";
    for ( var index=0 ; index < displayItemEndIndex ; ++index) {
       if ( (totalCount<=5)) {
          document.getElementById("beforeComparison."+currentRowAsinIndex).style.display = "none";
          document.getElementById("afterComparison."+currentRowAsinIndex).style.display = "block";
          if (index == currentRowAsinIndex) {
             if (totalCount != 1 && totalCount !=5) {
                document.getElementById("comparison."+index).style.display = "block";
             }
             if (totalCount == 5){
                document.getElementById("compareNow."+index).style.display = "block";
             }
             document.getElementById("comparisonError."+index).style.display = "none";
          } else {
             document.getElementById("comparison."+index).style.display = "none";
             document.getElementById("comparisonError."+index).style.display = "none";
          }
       } 
       if ( totalCount > 5) {        
          input=currentRowAsinIndex+1;
          if (index == currentRowAsinIndex) {
             document.getElementById("comparison."+index).style.display = "none";
             document.getElementById("comparisonError."+index).style.display = "block";
             document.getElementById("ASIN."+input).checked = false;
           }else {
             document.getElementById("comparison."+index).style.display = "none";
             document.getElementById("comparisonError."+index).style.display = "none";
           }
       }
     }   
     if (obj.checked == false)
     {
         
        if (currentRowAsinIndex%3 == 1){
          document.getElementById("floatedProduct."+currentRowAsinIndex).className
              = "floatedProductCenterCompare";
          document.getElementById("floatedProductDetailsBtn."+currentRowAsinIndex).className
              = "floatedProductDetailsBtnCenterCompare";
        } else {
          document.getElementById("floatedProduct."+currentRowAsinIndex).className = "floatedProduct";
          document.getElementById("floatedProductDetailsBtn."+currentRowAsinIndex).className = "floatedProductDetailsBtn";
        }
        document.getElementById("addToCompare."+currentRowAsinIndex).className = "addToCompare";
        document.getElementById("checkbox."+currentRowAsinIndex).className = "fifteen";
        if (addedASINs.indexOf(currentAsin)>0){
           addedASINs = addedASINs.replace(','+ currentAsin ,'');
        }else{
           removeASINs =  removeASINs + ',' + currentAsin;
        }
      }
  }
  window.document.forms["comparison"].addedASINs.value = addedASINs;
  window.document.forms["comparison"].removeASINs.value = removeASINs;
}

//this function is called on mouseover and mouseout events. 
//on mouseover a differnt image is displayed and on mouseout the original image is displayed
function swapImage(tagID,imageURL)
{
  var imgTag=document.getElementById(tagID);
  imgTag.src=imageURL;
}

// This function is called on click of page number
// while going to next page
function constructASINList(output){
  var allAddedASINs;
  var allRemoveASINs;
  
  allAddedASINs = window.document.forms["comparison"].addedASINs.value;
  allRemoveASINs = window.document.forms["comparison"].removeASINs.value;
  path = output.href + '&addedASINs=' + allAddedASINs + '&removeASINs=' + allRemoveASINs;
  output.setAttribute("href",path);
}

//This function is called on click of compare products button
function compare() {
   var count = 0;
   var countOfOldASINs = 0;
   var countOfAddedASINs = 0;
   var countOfRemovedASINs = 0;

   var oldASINs = window.document.forms["comparison"].compareListASINs.value;
   var allAddedASINs =  window.document.forms["comparison"].addedASINs.value;
   var allRemoveASINs =  window.document.forms["comparison"].removeASINs.value;


   //decrement 1 from the count to compensate the first comma in the strings
   if(oldASINs != ''){
     countOfOldASINs = ( oldASINs.indexOf(',') == 0)  ? ((oldASINs).split(",")).length-1 : ((oldASINs).split(",")).length;
   }
   if(allAddedASINs){
     countOfAddedASINs = ( allAddedASINs.indexOf(',') == 0) ? (allAddedASINs.split(",")).length-1 : (allAddedASINs.split(",")).length;
   }
   if(allRemoveASINs){
     countOfRemovedASINs = ( allRemoveASINs.indexOf(',') == 0) ? (allRemoveASINs.split(",")).length-1 : (allRemoveASINs.split(",")).length;
   }

   count = countOfOldASINs + countOfAddedASINs - countOfRemovedASINs;
   if(count == 0) {
       alert('Please select the products to compare');
       return false;
    } else if (count > 5) {
       alert('Please limit your comparison to no more than 5 products');
       return false;
    } else {
       window.document.forms["comparison"].submit();
       return true;
    }

}


//This function is submitting the "add to wishlist" link on the compare product page to the desired action page.
function addToWishListCompare (element) {
  var formName = "handleBuy"+element;
  eval('document.'+formName).submit();
}

// This function is for the 'continue shopping' dropdown on wish list and cart huc page.
function categoryCheck( )
{
  var category = document.getElementById('shoppingFor').value;
  if( category != -1 )
  {
    document.continueShopping.action = category;
    document.continueShopping.submit();
  }
  return false;
}

// This function is used for submitting the email Optin form and to open a Popup for the same.
function openEmailSignUpPopupWindow(url,popup_options,name) {
   var userEmail = document.getElementById(name).value;
   win = window.open( url + "&userEmail=" + userEmail, 'popup', popup_options );

   if (win) {
       win.focus();
   }

}

// this function opens a new popup
function popup(url,name,options){
   window.open(url,name,options);
}

// This function is used for defaulting the quantity to 1 or to make the quantity positive incase the user enters it wrong by mistake
function quantityChanged( thisBox )
{
  var regExp = /\D/g;
  var hasNonDigits = thisBox.value.match(regExp);

  if ((hasNonDigits != null) && (hasNonDigits.length > 0) || (thisBox.value == 0)) {
    thisBox.value = 1;
  }
}  

// This function is for displaying the blocked contents when the user clicks on the read more link and to hide the contents when the user clicks
// on the See Less link in customer reviews section on the detail page.  
function readMore(display, divDecider) {
  if (display == 1) {        
      document.getElementById("readmore."+divDecider).style.display = "block";
      document.getElementById("seeless."+divDecider).style.display = "none";
  }
  else {

      document.getElementById("readmore."+divDecider).style.display = "none";
      document.getElementById("seeless."+divDecider).style.display = "block";

  }
}

//Function repaint() is used to repaint the detail page during color swatch and drop down changes
function repaintInfo (thisDropDownValue,url,nextKey,thisKey) {
  var finalValue = '';
  var finalAsin;
  var selectedValue;
  var dimensionCount;

  if (thisKey == 'color_name') {
    var colorDropDownOptions = document.handleBuy['color_name'];
    var allColors = colorDropDownOptions.options;
    for( var i = 1; i < allColors.length; i++ ) { 
      if(allColors[i].value == thisDropDownValue) {
        allColors[i].selected = true;
        if (document.getElementById(("image"+allColors[i].value)) != null) {
          document.getElementById(("image"+allColors[i].value)).style.border = '1px solid #000';
          showColorName(allColors[i].value);
        }   
      } else if (document.getElementById(("image"+allColors[i].value)) != null) {
        document.getElementById(("image"+allColors[i].value)).style.border = '1px solid #FFF';
        hideColorName(allColors[i].value);  
      }   
    }
  }
  
if (thisDropDownValue == 'Select Color' || thisDropDownValue == 'Select Colour' || thisDropDownValue == 'Select Size') {
  finalValue = 'Select';
} else {
  dimensionCount = variationDimensionKeys.length;
  for (var i = 0; i < dimensionCount; i++) {
    var dropDownOptions= document.handleBuy[variationDimensionKeys[i]];
    if(dropDownOptions) {
      var allOptions = dropDownOptions.options;
      if (allOptions) {
        for (var j=0;j<allOptions.length;j++) {
          if(allOptions[j].value == thisDropDownValue) {
            allOptions[j].selected = true;
            selectedValue = thisDropDownValue;
          } else {
            selectedValue = dropDownOptions.value;
          }
        }
      } else {
        selectedValue = dropDownOptions.value;
      }
    } else {
      selectedValue = '';
    }
    
    finalValue = finalValue+selectedValue;
  }
}

if (priceOptions[thisDropDownValue] == undefined && priceOptions[finalValue] == undefined) {
    saleOptions[thisDropDownValue] = saleOptions[''][0];
    priceOptions[thisDropDownValue] = priceOptions[''][0];
  }
  if (saleOptions[thisDropDownValue]) {
    document.getElementById("displayPrice").innerHTML = "<span class='oldPrice'>was&nbsp;"+priceOptions[thisDropDownValue]+
                                                        "</span><div class='productSalePrice'>now&nbsp;"+saleOptions[thisDropDownValue]+"</div>";
  } else if (priceOptions[thisDropDownValue]) {
    document.getElementById("displayPrice").innerHTML = "<span class=\"productPrice\">"+priceOptions[thisDropDownValue]+"</span>";
  } else if (saleOptions[finalValue]) {
    document.getElementById("displayPrice").innerHTML = "<span class='oldPrice'>was&nbsp;"+priceOptions[finalValue]+
                                                        "</span><br /> <div class='productSalePrice'>now&nbsp;"+saleOptions[finalValue]+"</div>";
  } else if (priceOptions[finalValue]) {
    document.getElementById("displayPrice").innerHTML = "<span class=\"productPrice\">"+priceOptions[finalValue]+"</span>";
  }

  if (availOptions[thisDropDownValue]) {
     document.getElementById("dpAvailMsg").innerHTML = "<p>"+availOptions[thisDropDownValue].msg+"</p>";
       if (availOptions[thisDropDownValue].msg.match(/out of stock/) ) {
         document.getElementById("dpQty").style.display = "none";
         document.getElementById("dpCartButton").style.display = "none";
         // Fix for TT 3479537
         if (document.getElementById("dpEmwaButton")) {
             document.getElementById("dpEmwaButton").style.display = "none";
         }
         if (availOptions[thisDropDownValue].imagesrc) {
             //an additional check to verify that link is actually EMWA TT#0003449003 
             if (availOptions[thisDropDownValue].imagesrc.match(/email me when available/)){
              document.getElementById("dpEmwaButton").innerHTML = availOptions[thisDropDownValue].imagesrc; 
              document.getElementById("dpEmwaButton").style.display = "block";
             } 
         }
       } else {
         document.getElementById("dpQty").style.display = "block";
         if (availOptions[thisDropDownValue].imagesrc) {
             document.getElementById("dpCartButton").src = availOptions[thisDropDownValue].imagesrc;
         }
         // width and height of pre-order button is different then add to basket button
         // hence need to set the correct width and height for each button
         if (availOptions[thisDropDownValue].width) {
             document.getElementById("dpCartButton").style.width = availOptions[finalValue].width;
         }
         if (availOptions[thisDropDownValue].height) {
             document.getElementById("dpCartButton").style.height = availOptions[finalValue].height;
         }

         document.getElementById("dpCartButton").style.display = "block";
         document.getElementById("dpEmwaButton").style.display = "none";
       }
  } else if (availOptions[finalValue]){
     document.getElementById("dpAvailMsg").innerHTML = "<p>"+availOptions[finalValue].msg+"</p>";
       if (availOptions[finalValue].msg.match(/out of stock/) ) {
         document.getElementById("dpQty").style.display = "none";
         document.getElementById("dpCartButton").style.display = "none";
         // Fix for TT 3479537
         if (document.getElementById("dpEmwaButton")) {
             document.getElementById("dpEmwaButton").style.display = "none";
         }
         if (availOptions[finalValue].imagesrc) {
             document.getElementById("dpEmwaButton").innerHTML = availOptions[finalValue].imagesrc; 
             document.getElementById("dpEmwaButton").style.display = "block";
         }
       } else {
         document.getElementById("dpQty").style.display = "block";
         if (availOptions[finalValue].imagesrc) {
             document.getElementById("dpCartButton").src = availOptions[finalValue].imagesrc;
         }
         // width and height of pre-order button is different then add to basket button
         // hence need to set the correct width and height for each button
         if (availOptions[finalValue].width) {
             document.getElementById("dpCartButton").style.width = availOptions[finalValue].width;
         }
         if (availOptions[finalValue].height) {
             document.getElementById("dpCartButton").style.height = availOptions[finalValue].height;
         }
         document.getElementById("dpCartButton").style.display = "block";
         document.getElementById("dpEmwaButton").style.display = "none";
       }
  }

 for (var count in asinToColor) {
   if(asinToColor[count] == (finalValue)) {
       finalAsin = count;
   }
 }
// swap the item image with selected color or clicked swatch
  changeImage('mainImage', asinToImages[finalAsin]);
if (nextKey) {
      populateDropDown(nextKey,thisDropDownValue);
 }

}


//Function changeImage() changes the image by overwriting the src of the image
function changeImage(element, newImg) {
    if(document.images[element] && newImg) {
        document.images[element].src = newImg;
    }
}

// Function displayDottedOnMouseOver() displays dotted border for the selected image
// and no border for rest and solid border the image which was last selected.
function displayDottedOnMouseOver(total, selectedIndex) {
for( var i=0;i<total;i++ ) {
    var index="thumb"+i;
    if (index != selectedIndex){
      if(document.getElementById(index)){
        document.getElementById(index).style.border = '1px solid #CDCDCD';
      }
    }
   else{
      if (document.getElementById(selectedIndex)){
        document.getElementById(selectedIndex).style.border = '1px dotted #F00';
      }
    }
  }
if (document.getElementById("selectedThumb")){
  var selectedThumb = document.getElementById("selectedThumb").value;
  if(document.getElementById(selectedThumb)){
    document.getElementById(selectedThumb).style.border = '1px solid #F00';
  }
}
}

// Function displaySolidOnClick() dislays solid border for selected image 
// and no border for rest of the images. It also sets the selected image id in
// the hidden field.
function displaySolidOnClick(total, selectedIndex) {
if (document.getElementById("selectedThumb")){
  document.getElementById("selectedThumb").value = selectedIndex;
}
for( var i=0;i<total;i++ ) {
    var index="thumb"+i;
    if (index != selectedIndex){
      if(document.getElementById(index)){
        document.getElementById(index).style.border = '1px solid #CDCDCD';
      }
    }
    else{
      if(document.getElementById(selectedIndex)){
        document.getElementById(selectedIndex).style.border = '1px solid #F00';
      }
    }
  }
}

// Function displayNoneOnMouseOut() removes the dotted border on mouse out
// and maintains the solid border
function displayNoneOnMouseOut (total){
  for( var i=0;i<total;i++ ) {
    var index="thumb"+i;
    if(document.getElementById(index)){
      document.getElementById(index).style.border = '1px solid #CDCDCD';
    }
  }

  if(document.getElementById("selectedThumb")){
    var selectedThumb = document.getElementById("selectedThumb").value;
    if(document.getElementById(selectedThumb)){
      document.getElementById(selectedThumb).style.border = '1px solid #F00';
    }
  }
}

// Function highlightAltView() highlights the default selected image
function highlightAltView(){
  if(document.getElementById("selectedThumb")){
    var selectedThumb = document.getElementById("selectedThumb").value;
    if(document.getElementById(selectedThumb)){
      document.getElementById(selectedThumb).style.border = '1px solid #F00';
    }
  }
}

//Function showColorName shows color name on mouse over of swatches on
//Detail Page
function showColorName(obj) {
  var el = document.getElementById(obj);
  if(el && el.style && el.style.display != "inline") {
    el.style.display = "inline";
  }
}

//Function hideColorName hides color name on mouse out of swatches on
//Detail Page

function hideColorName(obj) {
  var el = document.getElementById(obj);
  if(el && el.style && el.style.display != "none") {
    el.style.display = "none";
  }
}

//This function will apply dotted outline on mouse over of swatch images
//and displays color name on mouse over of swatches on Detail Page.

function dottedOutline (thisDropDownValue) {
  var colorObj;
  var colorDropDownOptions;
  var selectedColor = "";
  colorDropDownOptions = document.handleBuy['color_name'];
  var allColors = colorDropDownOptions.options;
  for( var i=1;i<allColors.length;i++ ) {
      if (allColors[i].selected == true) {
        selectedColor = allColors[i].value;
        document.getElementById(("image"+allColors[i].value)).style.border = '1px solid #000';
        showColorName(allColors[i].value);
      }
   }
  for( var j=1;j<allColors.length;j++) {
      if(allColors[j].value == thisDropDownValue) {
        if (selectedColor != "") {
          hideColorName(selectedColor);
        }
        document.getElementById(("image"+allColors[j].value)).style.border = '1px dotted #F00';
        showColorName(allColors[j].value);
      } else if (allColors[j].selected == false) {
        document.getElementById(("image"+allColors[j].value)).style.border = '1px solid #FFF';
        hideColorName(allColors[j].value);
      }
  }
}


//This function will apply dotted outline on mouse over of swatch images
//and displays color name on mouse over of swatches on Collections Page.
// Fix for TT 3176765: javascript error was showing on collection detail page
function dottedOutlineCollection (thisDropDownValue, ASIN) {
  var colorObj;
  var colorDropDownOptions;
  var allColors;
  var selectedColor = "";
  if (thisDropDownValue != '') {
    colorObj = document.getElementById(ASIN+'.'+thisDropDownValue);
  }
  colorDropDownOptions = document.handleBuy['dimensions.' + ASIN + '.color_name'];
  if (colorDropDownOptions != null) {
    allColors = colorDropDownOptions.options;
  }
  if (allColors != null) {
  for( var i=1;i<allColors.length;i++ ) {

      if (document.getElementById(ASIN+'.'+allColors[i].value) && (document.getElementById(ASIN+'.'+allColors[i].value).style)) {
        document.getElementById(ASIN+'.'+allColors[i].value).style.display = "none";
      }
      if(colorObj && colorObj.style && colorObj.style.display != "inline") {
        colorObj.style.display = "inline";
      }

      if ((document.getElementById(allColors[i].value)) && (document.getElementById(allColors[i].value).style) && (allColors[i].selected == true)) {
        document.getElementById(allColors[i].value).style.border = '1px solid #000';
        showColorName(ASIN+allColors[i].value);
        selectedColor = ASIN+allColors[i].value;
      }
 }
 for ( var j=1;j<allColors.length;j++ ) {
     if(allColors[j].value == thisDropDownValue) {
        if (selectedColor != "") {
          hideColorName(selectedColor);
        }
        if ((document.getElementById(allColors[j].value)) && (document.getElementById(allColors[j].value).style)) {
            document.getElementById(allColors[j].value).style.border = '1px dotted #F00';
            showColorName(ASIN+allColors[j].value);
        }
      } else if (allColors[j].selected == false) {
        if ((document.getElementById(allColors[j].value)) && (document.getElementById(allColors[j].value).style)) {
            document.getElementById(allColors[j].value).style.border = '1px solid #FFF';
            hideColorName(ASIN+allColors[j].value);
        }
      }
  }
  }
}

//Function hideColorName hides color name on mouse out of swatches on
//Collection Page

function hideColorNameCollection(thisDropDownValue, ASIN) {
  var colorObj = document.getElementById(ASIN+'.'+thisDropDownValue);
  if(colorObj && colorObj.style && colorObj.style.display != "none") {
    colorObj.style.display = "none";
  }
  var colorDropDownOptions = document.handleBuy['dimensions.' + ASIN + '.color_name'];
  var allColors = colorDropDownOptions.options;
  for( var i=1;i<allColors.length;i++ ) { 
    if (allColors[i].selected == true)  {
      if ((document.getElementById(allColors[i].value)) && (document.getElementById(allColors[i].value).style)) {
        document.getElementById(ASIN+allColors[i].value).style.display = "inline";
      }
    } else {
        document.getElementById(allColors[i].value).style.border = '1px solid white';
        document.getElementById(ASIN+allColors[i].value).style.display = "none";
    }
  }
} 

//Function collectionSwatches selects the respective dropdown and changes main
//Image accordingly

function collectionSwatches (thisDropDownValue, ASIN, itemIndex) {
  var selectedColor;
  var colorDropDownOptions = document.handleBuy['dimensions.' + ASIN + '.color_name'];
  var sizeDropDownOptions = document.handleBuy['dimensions.'+ASIN+'.size_name'];
  var allColors = colorDropDownOptions.options;
  for( var i=1;i<allColors.length;i++ ) {
    if ((document.getElementById(allColors[i].value)) && (document.getElementById(allColors[i].value).style)) {
      if(allColors[i].value == thisDropDownValue) {
        allColors[i].selected = true;
        document.getElementById(allColors[i].value).style.border = '1px solid #000';
      } else {
        document.getElementById(allColors[i].value).style.border = '1px solid #FFF';
      }
    }
  }
  collectionSelectUpdated( itemIndex, ASIN, sizeDropDownOptions, thisDropDownValue , colorDropDownOptions );
}

function fnOpenWin(link,height,width) {
  win = window.open(link,'PopUp','toolbar=no,resizable=yes,status=no,left=100,top=30,height='+ height +',width='+width);
  if (win) {
    win.focus();
  }
}

function deliveryTabFocus() {
        document.getElementById('deliveryTabFocus').style.display = 'block';
        document.getElementById('productInfoTabFocus').style.display = 'none';
        document.getElementById('productInfoTabDisplay').style.display = 'none';
        document.getElementById('deliveryInfoTabDisplay').style.display = 'block';
}


function productDetailsTabFocus() {
        document.getElementById('deliveryTabFocus').style.display = 'none';
        document.getElementById('productInfoTabFocus').style.display = 'block';
        document.getElementById('productInfoTabDisplay').style.display = 'block';
        document.getElementById('deliveryInfoTabDisplay').style.display = 'none';
}

function videoTabFocus() { // video
        document.getElementById('videoTabFocus').style.display = 'block';
        document.getElementById('productImageTabFocus').style.display = 'none';
        document.getElementById('productImageTabDisplay').style.display = 'none';
        document.getElementById('videoInfoTabDisplay').style.display = 'block';
        document.getElementById('toggleDiv').style.display = 'none';
}


function productImageDetailsTabFocus() { //image
        document.getElementById('videoTabFocus').style.display = 'none';
        document.getElementById('productImageTabFocus').style.display = 'block';
        document.getElementById('productImageTabDisplay').style.display = 'block';
        document.getElementById('videoInfoTabDisplay').style.display = 'none';
        document.getElementById('toggleDiv').style.display = 'block';
}

function toggleDiv() {
        document.getElementById('toggleDiv').style.display = 'block';
}

function expandPromoBox() {
        document.getElementById('extraPromo').style.display = 'block';
        document.getElementById('viewAllLink').style.display = 'none'; 
}

function collapsePromoBox() {
        document.getElementById('extraPromo').style.display = 'none'; 
        document.getElementById('viewAllLink').style.display = 'block';
}

function expandAttribute(asin) {
        document.getElementById('extraAttribute_'+asin).style.display = 'block';
        document.getElementById('seeMore_'+asin).style.display = 'none';
}

function collapseAttribute(asin) {
        document.getElementById('extraAttribute_'+asin).style.display = 'none';
        document.getElementById('seeMore_'+asin).style.display = 'block';
}

function openPopupWindow(url,popup_options) {
        var widthParam = popup_options.match(/width\s*=\s*\d+\s*/ig);
        if (widthParam !== null) { 
          popup_options = popup_options.replace(widthParam[0],"width = "+800); 
        }       
        win = window.open(url,'popup',popup_options);
        if (win) { 
          win.focus();
        }       
}

function fnOmniturePopWin(link,height,width,pageName,channel,prop1,events,evar16,products){
  omnitureClick(pageName,channel,prop1,events,evar16,products);
  fnOpenWin(link,height,width);
}

function openPopupWithOmnitureTracking(pageType,channel,url,name,options){
    omnitureClick(pageType,channel);
    openPopupWindow(url,options);
}     

// Function to check for textarea Max length limit
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

<!-- for showing/hiding resouce centre bubble
function showBubble() {
        document.getElementById('resourceBubble').style.visibility = 'visible';
}
function hideBubble() {
        document.getElementById('resourceBubble').style.visibility = 'hidden';
}
// -->

function validateEmail(email) {
  var at  = '@';
  var dot = '.';
  var lat  = email.indexOf(at);
  var lstr = email.length;
  var ldot = email.indexOf(dot);
  
  if (email.indexOf(at) == -1) {
    return false;
  }

  if (email.indexOf(at) == -1 || email.indexOf(at) == 0 || email.indexOf(at) == lstr) {
    return false;
  }

  if (email.indexOf(dot) == -1 || email.indexOf(dot) == 0 || email.indexOf(dot) == (lstr - 1)) {
    return false;
  }

  if (email.indexOf(at,(lat+1)) != -1){
     return false;
  }

  if (email.substring(lat-1,lat) == dot || email.substring(lat+1,lat+2) == dot) {
     return false;
  }

  if (email.indexOf(dot,(lat+2)) == -1) {
     return false;
  }

  if (email.indexOf(" ") != -1) {
     return false;
  }

  return true;
}


function validateForm() {  
    var errorfield;
    var inputvalue;
    var success = true;

 // Check firstname
 inputvalue = trimAll(document.getElementById('firstName').value);
 if ( inputvalue.length < 1 ) {
    document.getElementById('fnameError').style.display = "block";
    success = false;
 } else {
    document.getElementById('fnameError').style.display = "none";
 }


 // Check surname/lastname
 inputvalue = trimAll(document.getElementById('lastName').value);
 if ( inputvalue.length < 1 ) {
    document.getElementById('lnameError').style.display = "block";
    success = false;
 } else {
    document.getElementById('lnameError').style.display = "none";
 }
 
 // Check email address
 inputvalue = trimAll(document.getElementById('emailAddress').value);
 if (inputvalue.length < 1) {
    document.getElementById('emailEmptyError').style.display   = "block";
    document.getElementById('emailInvalidError').style.display = "none";
    success = false;
 } else if (!validateEmail(inputvalue)) {
    document.getElementById('emailEmptyError').style.display   = "none";
    document.getElementById('emailInvalidError').style.display = "block";
    success = false;
 } else {
    document.getElementById('emailEmptyError').style.display   = "none";
    document.getElementById('emailInvalidError').style.display = "none";
 }
 
      
 // Check if email addresses match only if the first one is valid
 if ( document.getElementById('emailEmptyError').style.display  == "none" || document.getElementById('emailInvalidError').style.display == "none" ) {
     if ( trimAll(document.getElementById('emailAddress').value) != trimAll(document.getElementById('emailConfirm').value )) {
        document.getElementById('emailMisMatchError').style.display   = "block";
        success = false;
     } else {
        document.getElementById('emailMisMatchError').style.display   = "none";
     }
 }     
 
 // Check password
 inputvalue = trimAll(document.getElementById('password').value);
 if ( inputvalue.length < 1 ) {
    document.getElementById('pwdEmptyError').style.display = "block";
    success = false;
 } else {
    document.getElementById('pwdEmptyError').style.display = "none";
 }

 // Check if password2 given and if it matches
 inputvalue = trimAll(document.getElementById('passwordConfirm').value);
 if ( document.getElementById('pwdEmptyError').style.display == "none" ) {
     if ( inputvalue.length < 1 ) {
        document.getElementById('pwd2EmptyError').style.display    = "block";
        document.getElementById('pwd2MisMatchError').style.display = "none";
        success = false;
     } else if ( inputvalue != trimAll(document.getElementById('password').value) ) {
        document.getElementById('pwd2EmptyError').style.display    = "none";
        document.getElementById('pwd2MisMatchError').style.display = "block";
        success = false;
     } else {
        document.getElementById('pwd2EmptyError').style.display    = "none";
        document.getElementById('pwd2MisMatchError').style.display = "none";
     }
 }
 return success;
}


function trimAll(sString)
{
    while (sString.substring(0,1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ') {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

function defaultCCDisplay()
{
    var moreOptions = document.getElementById('switchCC');
    var morePadding = document.getElementById('noSwitchPadding');
    moreOptions.style.display = 'none';
    morePadding.style.display = 'block';
}


function changeCC()
{
    var moreOptions = document.getElementById('switchCC');
    var morePadding = document.getElementById('noSwitchPadding');
    var drop        = document.getElementById('newCreditCardIssuer');
    var option      = drop.options[drop.selectedIndex].value;

     if (option == 'S|0')
     {
         moreOptions.style.display = 'block';
         morePadding.style.display = 'none';
     } else {
         moreOptions.style.display = 'none';
         morePadding.style.display = 'blocK';
     }
}

// Functions to display and hide "why this product was recommended" on your store page

var displayWhyRecommended = 0;
var whyThisRecommendedID = '';
function hideBodyRecs() {
    if (displayWhyRecommended == 0) {
        if (document.getElementById(whyThisRecommendedID) && document.getElementById(whyThisRecommendedID).style.visibility == 'visible') {
            document.getElementById(whyThisRecommendedID).style.visibility = "hidden";
            whyThisRecommendedID = '';
        }
    }
    displayWhyRecommended = 0;
    return false;
}

function showrecs(id) {
    if (document.getElementById(id) && document.getElementById(id).style) {
        if (whyThisRecommendedID != '' && document.getElementById(whyThisRecommendedID) && document.getElementById(whyThisRecommendedID).style) {
            document.getElementById(whyThisRecommendedID).style.visibility = "hidden";
        }
        whyThisRecommendedID = id;
        var whyLinkObj = document.getElementById('whyLinkBlock'+count);
        var whyLinkTop = offsetTop(whyLinkObj);
        document.getElementById(id).style.visibility = "visible";
        document.getElementById(id).style.top = (whyLinkTop-100)+'px';
        displayWhyRecommended = 1;
    }
    return false;
}

// Function to display product image if user mouseover on recently viewed Items on detail Page
function displayRviImage (asin) {
  var ifrm = document.getElementById('iMask'); 
  var rviLink = document.getElementById('rviLink'+asin);
  var rviImg = document.getElementById('rvi'+asin);

  if (rviImg && rviLink) {
    var rviTop = offsetTop(rviLink);
    var rviLeft = offsetLeft(rviLink);
    rviImg.style.top=(rviTop-24)+'px';
    rviImg.style.left=(rviLeft-245)+'px';
    rviImg.style.display="block"; 
    var frmwidth = rviImg.offsetWidth-40;
    var frmheight = rviImg.offsetHeight; 
    ifrm.style.top=(rviTop-24)+'px';
    ifrm.style.left=(rviLeft-245)+'px';
    ifrm.style.width=frmwidth;
    ifrm.style.height=frmheight; 
  }
}

// Function to hide product Image
function hideRviImage (asin) {
  var ifrm = document.getElementById('iMask'); 
  ifrm.style.top=0+'px';
  ifrm.style.left=0+'px';
  ifrm.style.width=0;
  ifrm.style.height=0; 
  var rviImg = document.getElementById('rvi'+asin);
  if (rviImg) {
    rviImg.style.display="none";
  }
}

// Functions to display and hide "why this product was recommended" on your store page

var displayWhyRecommended = 0;
var whyThisRecommendedID = '';
function hideBodyRecs() {
    if (displayWhyRecommended == 0) {
        if (document.getElementById(whyThisRecommendedID) && document.getElementById(whyThisRecommendedID).style.visibility == 'visible') {
            document.getElementById(whyThisRecommendedID).style.visibility = "hidden";
            whyThisRecommendedID = '';
        }
    }
    displayWhyRecommended = 0;
    return false;
}

function showrecs(id) {
    if (document.getElementById(id) && document.getElementById(id).style) {
        if (whyThisRecommendedID != '' && document.getElementById(whyThisRecommendedID) && document.getElementById(whyThisRecommendedID).style) {
            document.getElementById(whyThisRecommendedID).style.visibility = "hidden";
        }
        whyThisRecommendedID = id;
        var whyLinkObj = document.getElementById('whyLinkBlock'+count);
        var whyLinkTop = offsetTop(whyLinkObj);
        document.getElementById(id).style.visibility = "visible";
        document.getElementById(id).style.top = (whyLinkTop-100)+'px';
        displayWhyRecommended = 1;
    }
    return false;
}

// Function to display product image if user mouseover on recently viewed Items on detail Page
function displayRviImage (asin) {
  var ifrm = document.getElementById('iMask'); 
  var rviLink = document.getElementById('rviLink'+asin);
  var rviImg = document.getElementById('rvi'+asin);

  if (rviImg && rviLink) {
    var rviTop = offsetTop(rviLink);
    var rviLeft = offsetLeft(rviLink);
    rviImg.style.top=(rviTop-24)+'px';
    rviImg.style.left=(rviLeft-245)+'px';
    rviImg.style.display="block"; 
    var frmwidth = rviImg.offsetWidth-40;
    var frmheight = rviImg.offsetHeight; 
    ifrm.style.top=(rviTop-24)+'px';
    ifrm.style.left=(rviLeft-245)+'px';
    ifrm.style.width=frmwidth;
    ifrm.style.height=frmheight; 
  }
}

// Function to hide product Image
function hideRviImage (asin) {
  var ifrm = document.getElementById('iMask'); 
  ifrm.style.top=0+'px';
  ifrm.style.left=0+'px';
  ifrm.style.width=0;
  ifrm.style.height=0; 
  var rviImg = document.getElementById('rvi'+asin);
  if (rviImg) {
    rviImg.style.display="none";
  }
}

//Function to show number of character that can be still entered.
function textCharacterCount(inpBox,msgCount) {
  var msg = document.getElementById(msgCount);
  if (msg && inpBox) {
   msg.innerHTML= inpBox.maxLength - inpBox.value.length;  
  }
}

//Function to handle checkbox events
function handleCheckboxclick(chkBox,inpBox, msgCount) {
   if (chkBox) {
    if (chkBox.checked){
     disableInputbox(inpBox);
     inpBox = document.getElementById(inpBox);
     textCharacterCount (inpBox, msgCount);
    }else {
     enableInputbox(inpBox);
    }
   }
} 


//Function to make input box empty and disabled based on checkbox checked
function disableInputbox(inpBoxId){
  var inpBox = document.getElementById(inpBoxId);
  if (inpBox) {
   inpBox.value = '';
   inpBox.disabled = true; 
  }
} 

//Function to make input box empty and enabled based on checkbox unchecked
function enableInputbox(inpBoxId){
  var inpBox = document.getElementById(inpBoxId);
  if (inpBox) {
   inpBox.value = '';
   inpBox.disabled = false; 
  }
}

//Function for validating due date for tens product and other personalized items.
function isPersonalizedItem () {
  if (document.getElementById('isTENSItemCheck') && (document.getElementById('isTENSItemCheck').value == 1)) {
    return validateDueDate();
  } else if (document.getElementById('nameRequired') && (document.getElementById('nameRequired').value == 1)) {
    return validatecustomizeName();
  } else if (document.getElementById('customizeStokke') && (document.getElementById('customizeStokke').value == 1)) {
    return validateStokke();
  } else {
    return true;
  }
}

// Function to validate stokke
function validateStokke() {
    var stokkeChkBox = document.getElementById('stokkeRequired');
  if (stokkeChkBox && stokkeChkBox.checked) {
    return true;
  } else { 
    document.getElementById('errorMsgPer').style.display = 'block';
    return false;
  }
}

// Function to calidate customizeName
function validatecustomizeName () {
  var customizeValue = document.getElementById('customizeName').value;
  var customizeChkBox = document.getElementById('validateCustomName');
  if ((customizeChkBox && customizeChkBox.checked) || (customizeValue != '')) {
    return true;
  } else { 
    document.getElementById('errorMsgPer').style.display = 'block';
    if (customizeChkBox) {
      document.getElementById('dueDateErrorContent').innerHTML = 'Please enter name or tick "I do not wish to personalise" below.';
    } else {
      document.getElementById('dueDateErrorContent').innerHTML = 'Please enter name below.';
    }
    return false;
  } 
}

// Function to validate due date for TENS items
var monthNumber = 0;
function validateDueDate () {
    var day = document.getElementById('day').options[document.getElementById('day').selectedIndex].value;
    var month = document.getElementById('month').options[document.getElementById('month').selectedIndex].value;
    var year = document.getElementById('year').options[document.getElementById('year').selectedIndex].value;
    var notSelectedError = '';
    if (day == 'day') {
      notSelectedError = 'day';
      if (month == 'month') {
        if (year == 'year') {
          notSelectedError = notSelectedError + ', month and year';
        } else {
          notSelectedError = notSelectedError + ' and month';
        }
      } else if (year == 'year') {
        notSelectedError = notSelectedError + ' and year';
      }
    } else if (month == 'month') {
      if (year == 'year') {
        notSelectedError = notSelectedError + 'month and year';
      } else {
        notSelectedError = notSelectedError + 'month';
      }
    } else if (year == 'year') {
      notSelectedError = notSelectedError + 'year';
    }
    if (notSelectedError != '') {
      document.getElementById('errorMsgPer').style.display = 'block';
      document.getElementById('dueDateErrorContent').innerHTML = 'Please select the '+ notSelectedError + ' of your due date.';
    } 
    var dateIncorrect = 0;
    if (month=='Feb') {
      monthNumber = 2;
      if (day>daysInFebruary(year)) {
        dateIncorrect = 1;
      }
    } else if (day > DaysArray(month)) {
      dateIncorrect = 1;
    }
    if (dateIncorrect == 1) {
      document.getElementById('errorMsgPer').style.display = 'block';
      document.getElementById('dueDateErrorContent').innerHTML = 'The date '+day+' '+month+' '+year+' does not exist. Please select another date.';
    }
    if ((notSelectedError == '') && (dateIncorrect == 0)) {
      document.getElementById('errorMsgPer').style.display = 'none';
      var pastFutureError = '';
      pastFutureError = checkDate(day,month,year);
      if (pastFutureError != '') {
        document.getElementById('errorMsgPer').style.display = 'block';
        document.getElementById('dueDateErrorContent').innerHTML = pastFutureError;
      } else {
        //alert('Correct Date');
        return true;
      }
    }
    return false;
} 

var strMonthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function DaysArray(n) {
  var days = 31;
  for (var i=1; i <=strMonthArray.length; i++) {
    if (strMonthArray[i-1] == n) {
      monthNumber = i;
      break;
    }
  }
  if (monthNumber==4 || monthNumber==6 || monthNumber==9 || monthNumber==11) {days = 30};
  return days;
}

function daysInFebruary (year){
  // February has 29 days in any year evenly divisible by four,
  // EXCEPT for centurial years which are not also divisible by 400.
  return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); }


// To check the past and future due dates 
function checkDate(day,month,year) {
  month = monthNumber;
  var now = new Date();
  var startDueDate = addDuration(now, 'DAY', 1);
  var endDueDate = addDuration(now, 'MONTH', 6);
  startDueDate = startDueDate.getTime();
  endDueDate = endDueDate.getTime();
  now.setYear(year);
  now.setMonth(month-1);
  now.setDate(day);
  now = now.getTime();
  var pastFutureError = '';
  if (now > endDueDate) {
    pastFutureError = 'Sorry, but we are unable to accept due dates that are more than 6 months in the future. Please choose another date';
  } else if (now < startDueDate) {
    pastFutureError = 'Invalid due date, please choose a due date in the future';
  }
  return pastFutureError;
}

function addDuration(startDate, durationUnit, durationValue) {
  var numMonths;
  if (durationUnit == "MONTH")
    numMonths = durationValue;
  else
    if (durationUnit == "DAY") {
      return addDaysToDate(startDate, durationValue);
    }
  else
      return startDate();   // invalid durationUnit
  return addMonthsToDate(startDate, numMonths); }


function addMonthsToDate(startDate, numMonths) {
  var addYears = Math.floor(numMonths/12);
  var addMonths = numMonths - (addYears * 12);
  var newMonth = startDate.getMonth() + addMonths;
  if (startDate.getMonth() + addMonths > 11) {
    ++addYears;
    newMonth = startDate.getMonth() + addMonths - 12;
  }
  var newDate = new Date(y2k(startDate.getYear())+addYears,newMonth,startDate.getDate(),startDate.getHours(),startDate.getMinutes(),startDate.getSeconds());

  // adjust to correct month
  while (newDate.getMonth() != newMonth) {
    newDate = addDaysToDate(newDate, -1);
  }

  return newDate;
}

function addDaysToDate(myDate,days) {
  return new Date(myDate.getTime() + days*24*60*60*1000); }

var months = new makeArray('January','February','March','April',
                           'May','June','July','August','September',
                           'October','November','December');

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function makeArray() {
  for (i = 0; i<makeArray.arguments.length; i++)
    this[i + 1] = makeArray.arguments[i]; 
} 
