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";
         if (availOptions[thisDropDownValue].imagesrc) {
             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";
         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 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(eEvent, mImgSrc) {
  
  imgObj = document.getElementById('product_img_id');
  
  imgObj.removeAttribute('style');
  
  imgObj.style.visibility = 'hidden';

  imgObj.src = mImgSrc;

  thumbAreaO = document.getElementById('thumbArea');

  imgA = thumbAreaO.getElementsByTagName('img');

  for( var i=0; i<imgA.length; i++ ) {
  	if ( eEvent != imgA[i] ) imgA[i].removeAttribute('style');
  }

  eEvent.style.border = 'red 1px solid';

  if (imgObj.complete && !Browser.isIE) {
	setTimeout("rePosition()",1000);
  }
}


//
function control_pos(obj,w,h)
{	
	resizepics(obj,w,h);
}

//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.

function dottedOutlineCollection (thisDropDownValue, ASIN) {
  var colorObj;
  var colorDropDownOptions;
  var selectedColor = "";
  if (thisDropDownValue != '') {
    colorObj = document.getElementById(ASIN+'.'+thisDropDownValue);
  }
  colorDropDownOptions = document.handleBuy['dimensions.' + ASIN + '.color_name'];

  var allColors = colorDropDownOptions.options;
  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 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 = createAccount.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 = createAccount.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 = createAccount.email.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 ( createAccount.email.value != createAccount.ConfirmEmail.value ) {
        document.getElementById('emailMisMatchError').style.display   = "block";
        success = false;
     } else {
        document.getElementById('emailMisMatchError').style.display   = "none";
     }
 }     
 
 // Check password
 inputvalue = createAccount.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 = createAccount.confirmPassword.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 != createAccount.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 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';
     }
}

/* *
 * 预读取图片程序
 */
function preLoadingImg(imgSrc){
	var pImage = new Image();
	pImage.src = imgSrc;
}

function rePosition(eEvent){
	if (!eEvent) eEvent = document.getElementById('product_img_id');
	
	eEvent.style.visibility = 'hidden';
	
	try {
		if (!eEvent) eEvent = window.event.srcElement || window.event.target;
		

		var imgHeight = parseInt(eEvent.height);
	  	var imgWidth = parseInt(eEvent.width);

	  	var maxIn = ( imgHeight > imgWidth )? 'h':'w';
	  	var ratio = imgHeight / imgWidth;
		
		var standardValue = 400; 
		
		if(imgHeight > standardValue)
		{
			imgHeight= standardValue;
			imgWidth = parseInt(imgHeight/ratio);	
		}
		
		if(imgWidth > standardValue)  
		{
			imgWidth = standardValue;
			imgHeight= parseInt(imgWidth*ratio);
		}
		
		eEvent.style.height = parseInt(imgHeight) + 'px' ;
		eEvent.style.width = parseInt(imgWidth) + 'px';
		
		var marginTopValue = parseInt((standardValue - imgHeight)/2);
		var marginLeftValue = parseInt((standardValue - imgWidth)/2);
		
		eEvent.style.marginTop = marginTopValue + "px";
		eEvent.style.marginBottom = marginTopValue + "px"; 
		eEvent.style.marginLeft = marginLeftValue + "px";
	    eEvent.style.marginRight = marginLeftValue + "px";
		eEvent.style.visibility = 'visible';
	}
	catch(eExpection){
		alert (eExpection.toString());
		return false;
	}
	
}


