/*********************************************************************************
Variations
*********************************************************************************/

var variationSetupArray = new Array();
var variationSelectBoxNames = new Array();
var selectedIndexes = new Array();
var maxOfferHeight = 500;
var WBA_isStoreFront = WBA_getStoreFront();
var WBA_hasFlash = WBA_hasFlashChecker();
var priceRange;
var totalVariationOffers = 0;

function WBA_getStoreFront(){
	var url = window.location.href;
	if(url.indexOf('/iws-merchant/pageEditor.htm?pageId=') > -1){
		return false;
	}else{
		return true;
	}
}

function initVariations(bundleAsin,totalUsedOffers)
{
	totalVariationOffers = totalUsedOffers;
	if (document.getElementById('variationPrice')) {
		var priceSpan = document.getElementById('variationPrice');
		priceRange = priceSpan.innerHTML;
	}
	debug("initting");
	var sBox = bundleAsin ? document.getElementById(variationSelectBoxNames[bundleAsin][0]) : document.getElementById(variationSelectBoxNames[0]);
	removeOptions(sBox,1);
	addOptions(0,bundleAsin);	
	//selectVariationValue(0,0,false,bundleAsin); // start with default selection of instructional first options ("First select..."). "false" will select one option dropdowns
	populateDropdown(0,0,bundleAsin);
	addListener(window, 'load', function(){selectOneOptionDropdowns(bundleAsin);}, false);
}

function selectOneOptionDropdowns(bundleAsin)
{
	// just go down the line of drop down boxes and select any option singletons
	var variationSelectBoxNamesLength = bundleAsin ? variationSelectBoxNames[bundleAsin].length : variationSelectBoxNames.length;
	for(var i = 0; i < variationSelectBoxNamesLength; i++){
		var sBox = bundleAsin ? document.getElementById(variationSelectBoxNames[bundleAsin][i]) : document.getElementById(variationSelectBoxNames[i]);
		if(
			sBox.length == 2 // 2 = 1 instructional option + 1 real option
			&& sBox.selectedIndex == 0 // haven't already selected an option (don't want this to undo selections)
		){
			sBox.selectedIndex = 1;
			selectVariationValue(i,1,true,bundleAsin);
		}
	}
}

function selectVariationValue(boxIndex, selectedIndex, notDoOneOptionDropdowns,bundleAsin) {
	
	populateDropdown(boxIndex,selectedIndex,bundleAsin);
	debug('priceIsRange: ' + priceIsRange);
	swapVariationImage(boxIndex, selectedIndex,bundleAsin);	
	var parentSku = document.getElementById('parentSku');
	var parentAvailability = document.getElementById('parentAvailability');
	var varListPrice = document.getElementById('listPrice');
	var varSavingsAmount = document.getElementById('savingsAmount');
	var varSavingsPercent = document.getElementById('savingsPercent');
	var varSku = document.getElementById('variationSku');
	var varAvailability = document.getElementById('variationAvailability');
	var listPriceLabel = document.getElementById('listPriceLabel');
	var savingsAmountLabel = document.getElementById('savingsAmountLabel');
	var priceSpan = document.getElementById('variationPrice');
	var key = "";
	var asin;
	var variationSelectBoxNamesLength = bundleAsin ? variationSelectBoxNames[bundleAsin].length : variationSelectBoxNames.length;
	var selectsHaveValue = bundleAsin ? allSelectsHaveValue() : true;
	for(var i = 0 ; i < variationSelectBoxNamesLength ; i++) {
		var sBox = bundleAsin ? document.getElementById(variationSelectBoxNames[bundleAsin][i]) : document.getElementById(variationSelectBoxNames[i]);
		key += "|" + sBox.value;
	}
	asin = bundleAsin ? bundleAsins[bundleAsin][key] : asins[key];
	if(priceIsRange) {
		var price; 
		if(bundleAsin) selectBundleItem(bundleAsin,asin);
		price = bundleAsin ? selectedBundleItemInfo('$','price') : prices[asin];
		if(origPrice == null) origPrice = priceSpan.innerHTML;
		if(price == null) price = origPrice;
		if(wba_iscc) price = wba_swapCurrency(price, true);
		if(selectsHaveValue){
			priceSpan.innerHTML = price;
		}else{
			if(bundleAsin) priceSpan.innerHTML = wba_iscc ? wba_swapCurrency(priceRange, true) : priceRange;
		}
	}

	if(asin == null) {
		if(totalVariationOffers){
			for (x in asins) {
				if(document.getElementById(asins[x]+"Offers")) document.getElementById(asins[x]+"Offers").style.display = 'none';
				if(document.getElementById(asins[x]+"Prices")) document.getElementById(asins[x]+"Prices").style.display = 'none';	
			}
			if(document.getElementById("seeAllBuyingOptions")) document.getElementById("seeAllBuyingOptions").style.display = 'none';
			if(document.getElementById("AllUsedPrices")) document.getElementById("AllUsedPrices").style.display = 'block';
		}
		if(parentSku != null) parentSku.style.display = '';
		if(parentAvailability != null) parentAvailability.style.display = '';
		if(varListPrice != null) varListPrice.style.display = 'none';
		if(varSavingsAmount != null) varSavingsAmount.style.display = 'none';
		if(varSku != null) varSku.style.display = 'none';
		if(varAvailability != null) varAvailability.style.display = 'none';
		if(listPriceLabel != null) listPriceLabel.style.display = 'none';
		if(savingsAmountLabel != null) savingsAmountLabel.style.display = 'none';
	} else {
		if(selectsHaveValue){
			if(totalVariationOffers){
				for (x in asins) {
					if(document.getElementById(asins[x]+"Offers")) document.getElementById(asins[x]+"Offers").style.display = 'none';
					if(document.getElementById(asins[x]+"Prices")) document.getElementById(asins[x]+"Prices").style.display = 'none';
				}
				if(document.getElementById(asin+"Offers")) document.getElementById(asin+"Offers").style.display = 'block';
				if(document.getElementById(asin+"Prices")) document.getElementById(asin+"Prices").style.display = 'block';
				if(document.getElementById("seeAllBuyingOptions")) document.getElementById("seeAllBuyingOptions").style.display = 'block';
				if(document.getElementById("AllUsedPrices")) document.getElementById("AllUsedPrices").style.display = 'none';
			}
			var listPrice = bundleAsin ? selectedBundleItemInfo('$','listPrice') : variationInfo[asin].listPrice;
			var savingsAmount = bundleAsin ? selectedBundleItemInfo('$','savingsAmount') : variationInfo[asin].savingsAmount;
			var savingsPercent = bundleAsin ? bundleSavingsPercent() : variationInfo[asin].savingsPercent;
			var sku = bundleAsin ? bundleVariationInfo[bundleAsin][asin].sku : variationInfo[asin].sku;
			var availability = bundleAsin ? bundleVariationInfo[bundleAsin][asin].availability : variationInfo[asin].availability;
			
			if(varListPrice && listPrice) varListPrice.innerHTML = listPrice;
			if(varSavingsAmount && savingsAmount) varSavingsAmount.innerHTML = savingsAmount + ' (' + savingsPercent + ')';
			if(varSku) varSku.innerHTML = sku;
			if(varAvailability) varAvailability.innerHTML = availability;
			if(parentSku) parentSku.style.display = 'none';
			if(parentAvailability) parentAvailability.style.display = 'none';
			if(varSku) varSku.style.display = '';
			if(varAvailability) varAvailability.style.display = '';
			
			if(listPrice == ''){
				if(varListPrice) varListPrice.style.display = 'none';
				if(listPriceLabel) listPriceLabel.style.display = 'none';
			}else{
				if(varListPrice) varListPrice.style.display = '';
				if(listPriceLabel) listPriceLabel.style.display = '';
			}
			
			if(savingsAmount == '' || !savingsPercent){
				if(varSavingsAmount) varSavingsAmount.style.display = 'none';
				if(savingsAmountLabel) savingsAmountLabel.style.display = 'none';
			}else{
				if(varSavingsAmount) varSavingsAmount.style.display = '';
				if(savingsAmountLabel) savingsAmountLabel.style.display = '';
			}
		}
		
	}
	
	// select any new one option dropdowns
	if (!notDoOneOptionDropdowns) {
		//alert("select 1")
		selectOneOptionDropdowns(bundleAsin, selectOneOptionDropdowns);
	}
}
function allSelectsHaveValue(){
	for(var i in variationSelectBoxNames){
		for(var x in variationSelectBoxNames[i]){
			if(!document.getElementById(variationSelectBoxNames[i][x]).value){
				return false;		
			}
		}
	}
	return true;
}
function selectBundleItem(bundleAsin,asin){
	for(var i in bundleVariationInfo[bundleAsin]){
		if(bundleAsin != i)
			bundleVariationInfo[bundleAsin][i].selected = false;
	}
	if(asin) bundleVariationInfo[bundleAsin][asin].selected = true;
}
function selectedBundleItemInfo(format,attribute){
	var temp = 0;
	for(var bundleAsin in bundleVariationInfo){
		bundleVariationInfo[bundleAsin];
		for(var asin in bundleVariationInfo[bundleAsin]){
			if(bundleVariationInfo[bundleAsin][asin].selected == true){
				var value = bundleVariationInfo[bundleAsin][asin][attribute];
				if(value.indexOf('$') == -1) return value;
				temp += parseFloat(value.replace(format,""));
			}
		}
	}
	var finalValue = format+temp.toFixed(2);
	finalValue = finalValue=='$0.00' ? priceRange : finalValue;
	finalValue = wba_iscc ? wba_swapCurrency(finalValue, true) : finalValue;
	return finalValue;
}
function bundleSavingsPercent(){
	var listPrice = selectedBundleItemInfo('$','listPrice');
	var savingsAmount = selectedBundleItemInfo('$','savingsAmount');
	var format = "$";
	if(!listPrice || !savingsAmount) return false;
	savingsAmount = parseFloat(savingsAmount.replace(format,""));
	listPrice = parseFloat(listPrice.replace(format,""));
	var savingsPercent = (savingsAmount/listPrice)*100;
	return parseInt(savingsPercent)+"%";
}
function swapVariationImage(boxIndex, selectedIndex, bundleAsin) {
	var key = "";
	var keyValue = "";
	var variationSelectBoxNamesLength = bundleAsin ? variationSelectBoxNames[bundleAsin].length : variationSelectBoxNames.length;
	for(var i = 0 ; i < variationSelectBoxNamesLength ; i++) {
		var sBox = bundleAsin ? document.getElementById(variationSelectBoxNames[bundleAsin][i]) : document.getElementById(variationSelectBoxNames[i]);
		key += "|" + sBox.value;
		keyValue += sBox.value;
	}
	if(keyValue && (variationSelectBoxNamesLength-1) == boxIndex){
		var asin = bundleAsin ? bundleAsins[bundleAsin][key] : asins[key];
		if(bundleAsin){
			var variationBundleImage = bundleImages[bundleAsin][asin][key];
			variationBundleImage = !variationBundleImage ? bundleFallbackImage : variationBundleImage ;
			if(variationBundleImage) {
				var productImage = document.getElementById('bundleThumb'+bundleAsin);
				productImage.src = variationBundleImage;
			}
		}else{
			variationImage = variationImages[key];
			variationImage = !variationImage ? mediumImageUrl : variationImage ;
			variationPopupImage = variationPopupImages[key];
			if(variationImage) {
				var productImage = document.getElementById('productImage');
				productImage.src = variationImage;
				popUpImgSrc = variationPopupImage;
			}
		}
	}
}

function populateDropdown(boxIndex, selectedIndex,bundleAsin)
{
	selectedIndexes[boxIndex] = selectedIndex;
	for (var i = boxIndex + 1; i < selectedIndexes.length; i++)
	{
      selectedIndexes[i] = 0;	
	}
	var variationSelectBoxNamesLength = bundleAsin ? variationSelectBoxNames[bundleAsin].length : variationSelectBoxNames.length ;
	for (var k = boxIndex + 1; k < variationSelectBoxNamesLength; k++)
	{
		var sBox = bundleAsin ? document.getElementById(variationSelectBoxNames[bundleAsin][k]) : document.getElementById(variationSelectBoxNames[k]);
		if (sBox)
		{
			removeOptions(sBox, 1);
		}
	}
	var variationSelectBoxNamesBoxIndex = bundleAsin ? variationSelectBoxNames[bundleAsin][boxIndex + 1] : variationSelectBoxNames[boxIndex + 1] ;
    if (variationSelectBoxNamesBoxIndex)
    {
    	addOptions(boxIndex + 1,bundleAsin);
    }
}

function addOptions(boxIndex,bundleAsin) {
  var boxKey = "0";
  for (var j = 0; j < boxIndex; j++)
  {
    boxKey = boxKey + "_" + selectedIndexes[j];
  }
  debug("boxkey: " + boxKey);
  if(bundleAsin){
  	debug("arr: " + variationSetupArray[bundleAsin][boxKey]);
  }else{
  	debug("arr: " + variationSetupArray[boxKey]);
  }
  
 	selectBox = bundleAsin ? document.getElementById(variationSelectBoxNames[bundleAsin][boxIndex]) : document.getElementById(variationSelectBoxNames[boxIndex]);
 	if (selectBox) 
 	{
 		var counter = 1;
 		var hasMoreElements = true;
 		var dataKey;
 		while (hasMoreElements)
 		{
 			dataKey = boxKey + "_" + counter++;
 			var val = bundleAsin ? variationSetupArray[bundleAsin][dataKey] : variationSetupArray[dataKey];
 			debug("dataKey: " + dataKey + " val: " + val);
			if (val)
 			{
 				var variationSelectBoxNamesLength = bundleAsin ? variationSelectBoxNames[bundleAsin].length - 1 : variationSelectBoxNames.length - 1 ;
 				if(boxIndex == variationSelectBoxNamesLength) {
					var key = "";
					var keyValue = "";
					for(var i = 0 ; i < variationSelectBoxNamesLength ; i++) {
						var sBox = bundleAsin ? document.getElementById(variationSelectBoxNames[bundleAsin][i]) : document.getElementById(variationSelectBoxNames[i]);
						key += "|" + sBox.value;
						keyValue += sBox.value;
					}
					key += "|" + val;


					var asin = bundleAsin ? bundleAsins[bundleAsin][key] : asins[key];
					
					var price = bundleAsin ? bundlePrices[bundleAsin]['prices'][asin] : prices[asin];
					if(price != null){
						if(wba_iscc && bundleAsin) price = wba_swapCurrency(price, true);
						val += ": " + price;
						}
				}				
				var variationSetupArrayDataKey = bundleAsin ? variationSetupArray[bundleAsin][dataKey] : variationSetupArray[dataKey] ;
 				addOption(selectBox, val, variationSetupArrayDataKey,counter);
		} else {
			hasMoreElements = false;
		}
 		}
 	}
}

function addOption(selectBox, text, value,counter)
{
	// added to support Safari on MAC platform
	// selectBox.options.add(option);
	selectBox.options[(counter - 1)] = new Option(text,value);
}

function removeOptions(selectBox, startIndex)
{
	var i;
	for(i = selectBox.options.length-1; i >= startIndex; i--)
	{
		selectBox.remove(i);
	}
}


/*********************************************************************************
End Variations
*********************************************************************************/

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57) && !(charCode == 37 || charCode == 39)) {
        return false;
    }
    return true;
}

var originalImage;
var originalWidth;
var originalHeight;
function mouseoverSwapImage(id,imgSrc){ 
	originalImage = document.getElementById(id).getAttribute('src');
	document.getElementById(id).setAttribute('src',imgSrc);
}

function mouseoutSwapImage(id){
	document.getElementById(id).setAttribute('src',originalImage);
}

function swapImage(id,imgSrc,popUpSrc){ 
	document.getElementById(id).setAttribute('src',imgSrc);
	popUpImgSrc = popUpSrc;
}
var popUpImgSrc;
function zoom(imgSrc){
	if(!popUpImgSrc)
		popUpImgSrc = popUpImageUrl;
	if(imgSrc)
		showPopup(imgSrc);
	else
		showPopup(popUpImgSrc);
}

var largeImage;
function showPopup(src) {
	largeImage = new Image;
	largeImage.src = src;
	openLargeImage();
}

var openLargeImage = function openWithFallback() {
	var spec = 'toolbar=no,location=no,status=yes,scrollbars=no,resizable=1,width=660,height=530';
	var zoomWindow = window.open('/shared/viewProductImage.html?' + largeImage.src,'zoom',spec);
	zoomWindow.focus();
}



function debug(str) {
	/*var debug = document.getElementById('debug');
	if(!debug) {
		var div = document.createElement('div');
		div.setAttribute('id','debug');
		document.body.appendChild(div);
		debug = document.getElementById('debug');
		div.innerHTML = "<input type='button' value='Clear' onclick='this.parentNode.parentNode.removeChild(this.parentNode)'/><br/>";
	}
	debug.innerHTML += str + "<br/>";*/
}

function readmore(id){
	if(document.getElementById(id+"_short").style.display == ''){
		var textWidth = document.getElementById(id+"_short").offsetWidth;
		document.getElementById(id+"_full").style.width=textWidth+"px";
		document.getElementById(id+"_full").width=textWidth;
		document.getElementById(id+"_short").style.width=textWidth+"px";
		document.getElementById(id+"_short").width=textWidth;
		document.getElementById(id+"_buttonHolder").style.width=textWidth+"px";
		document.getElementById(id+"_buttonHolder").width=textWidth;
		document.getElementById(id+"_short").style.display = 'none';
		document.getElementById(id+"_full").style.display = '';
		document.getElementById(id+"_button").innerHTML = 'show less';
	}else{
		var textWidth = document.getElementById(id+"_full").offsetWidth;
		document.getElementById(id+"_full").style.width=textWidth+"px";
		document.getElementById(id+"_full").width=textWidth;
		document.getElementById(id+"_short").style.width=textWidth+"px";
		document.getElementById(id+"_short").width=textWidth;
		document.getElementById(id+"_buttonHolder").style.width=textWidth+"px";
		document.getElementById(id+"_buttonHolder").width=textWidth;
		document.getElementById(id+"_short").style.display = '';
		document.getElementById(id+"_full").style.display = 'none';
		document.getElementById(id+"_button").innerHTML = 'show all';
	}
}

function sureImage(el, url, fallback, variationImageUrl){
	var testImage = new Image;
	testImage.src=el.src;
	if (testImage.width == 1 && testImage.height == 1) {
		//busted image
		if(variationImageUrl && testImage.src != variationImageUrl){
			el.removeAttribute("width");
			el.removeAttribute("height");
			el.src = variationImageUrl;
		}else{
			el.removeAttribute("onload");//kill the loop
			el.removeAttribute("width");
			el.removeAttribute("height");
			el.src = fallback;
		}
		
	}
}

function IWSMetricsTracker(){return null;}

function getPN(){
	var pn_ = window.location.pathname;
	var pns_ = pn_.split('/');
	if(pns_.length >0){
		var pn_ = pns_[pns_.length-1];
		if(pn_.indexOf('orderConfirmation.htm') >=0){
			var _href = window.location.href;
			var hn = _href.substring(_href.indexOf('&merchant')+1, _href.length);
			hn = hn.substring(hn.indexOf('=')+1, hn.indexOf('&'));
			pn_ = '/' +hn + '/' + pn_;
		}else{
			pn_ = '/' + window.location.hostname;
		}
		return pn_;
	}
}

function toggleOffers(id,asin){
	var activeOffer = document.getElementById(id);
	for(var i=0; i<=totalSupportedOfferConditions; i++){
		var offers = document.getElementById(asin+'offers_'+i);
		var offerTab = document.getElementById(asin+'offerTab_'+i);
		if ( offers ) offers.style.display='none';
		if ( offerTab ) offerTab.className='tab-off';
	}
	document.getElementById(asin+'offers_'+id).style.display='';
	adjustOfferHeight(asin+'offers_'+id);
	document.getElementById(asin+'offerTab_'+id).className='tab';
	document.getElementById(asin+'offerTab_'+id).blur();
	
}

function toggleComment(id){
	var more = document.getElementById(id+'_more');
	var less = document.getElementById(id+'_less');
	var moreLink = document.getElementById(id+'_more_link');
	var lessLink = document.getElementById(id+'_less_link');
	if(less.style.display == 'none'){
		more.style.display = 'none';
		less.style.display = '';
		moreLink.style.display = '';
		lessLink.style.display = 'none';
		less.blur();
	}else{
		more.style.display = '';
		less.style.display = 'none';
		moreLink.style.display = 'none';
		lessLink.style.display = '';
		more.blur();
	}
	
}

function adjustOfferHeight(id){
	document.getElementById(id).style.height ='';
	var loadedHeight = document.getElementById(id).offsetHeight;
	if(loadedHeight > maxOfferHeight){
		document.getElementById(id).style.height=maxOfferHeight+'px';
		document.getElementById(id).style.overflow = 'auto';
	}
}

function initOfferTable(){
	if (typeof asins != 'undefined') {
		for(x in asins){
			adjustOfferHeight(asins[x]+'offers_0');
		}
	}
	else {
		adjustOfferHeight('offers_0');
	}
}

function addListener(element, type, expression, bubbling)
{
	bubbling = bubbling || false;
	
	if(window.addEventListener)	{ // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else return false;
}
function promotionsPopUp(id){
	window.open("/promotionTerms.htm?id="+id,"promotions","width=450,height=600,resizable=1,scrollbars=1,toolbar=1,status=1");
}

function saveCookie(c_name,value,expiredays,path){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==0) ? " ;path="+path : ";expires="+exdate + " ;path="+path);
}
function openCookie(c_name){
  if (document.cookie.length>0){ 
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1){ 
      c_start=c_start + c_name.length+1 
      c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
       return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
  return ""
}

function WBA_hasFlashChecker() {
    var hasFlash = false;
    if (WBA_isIE()) {
        for (var i = 7; i > 0; i--) {
            try {
                var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
                hasFlash = true;
                break;
            }
            catch (e) {
            }
        }
    } else {
        if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
            hasFlash = true;
        }
    }
    if (hasFlash) {
        return true;
    } else {
    	return false;
   }
}
// functions for determining user agent
function WBA_isIE() {
    return WBA_isAgent("IE");
}
function WBA_isGecko() {
    return WBA_isAgent("Gecko");
}
function WBA_isOpera() {
    return WBA_isAgent("Opera");
}
/**
 * function to check if a browser is of a specified type
 * and of at least the version specified.
 * @param appName the name of the browser type to check for.
 *        valid types are 'IE', 'Gecko', 'Opera'.
 * @returns true if this browser is of a the specified type and
 *          and has a version greater than or equal to version.
 */
function WBA_isAgent(appName) {
    return WBA_isAgentAndVersion(appName, 0);
}
/**
 * function to check if a browser is of a specified type
 * and of at least the version specified.
 * @param appName the name of the browser type to check for.
 *        valid types are 'IE', 'Gecko', 'Opera'.
 * @param version the version number to check if this browser
 *        is greater than.
 * @returns true if this browser is of a the specified type and
 *          and has a version greater than or equal to version.
 */
function WBA_isAgentAndVersion(appName, version) {
    var isAgent = false;
    var userAgent = navigator.userAgent;
    if (appName == "IE") {
        if (userAgent.indexOf("MSIE") > 0) {
            var versionRegExp = new RegExp("MSIE ((\\d+\\.?){1,2})");
            var result = versionRegExp.exec(userAgent);
            if (result.length > 0) {
                if (result[1] >= version) {
                    isAgent = true;
                }
            }
        }
    }
    if (appName == "Gecko") {
        if (userAgent.indexOf("MSIE") < 0) {
            var versionRegExp = new RegExp("Mozilla/((\\d+\\.?){1,2})");
            var result = versionRegExp.exec(userAgent);
            if (result.length > 0) {
                if (version <= result[1]) {
                    isAgent = true;
                }
            }
        }
    }
    if (appName == "Opera") {
        if (userAgent.indexOf("Opera") > 0) {
            var versionRegExp = new RegExp("Opera(/|\\s)((\\d+\\.?){1,2})");
            var result = versionRegExp.exec(userAgent);
            if (result.length > 0) {
                if (version <= result[2]) {
                    isAgent = true;
                }
            }
        }
    }
    return isAgent;
}
function popSafeAndSecure(el){
		var windowName="safeandsecure";
		var windowProps="width=900,height=660,resizable=yes,scrollbars=yes,titlebar=yes,toolbar=no,location=yes";
		window.open(el.href,windowName,windowProps);
}

function toggleSeeMore(el){
	if(el.parentNode.className == 'seeMore')
		el.parentNode.className = 'seeLess';
	else
		el.parentNode.className = 'seeMore';
}
///////////////////////////CURRENCY CONVERT//////////////////////////////////////////
function wba_getQueryVar(v) {
  var q = window.location.search.substring(1);
  var vs = q.split("&");
  for (var i=0;i<vs.length;i++) {
	var p = vs[i].split("=");
	if (p[0].toLowerCase() == v) {
	  return p[1];
    }
  }
  return null; 
}

function wba_createCookie(name,value,days) {
	document.cookie = name+"="+value+expires+"; path=/";
}

function wba_readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

var wba_ccqid = wba_getQueryVar('id');
var wba_cccid = wba_readCookie('id');
var wba_iscc = false;
if((wba_ccqid!=null  && (wba_ccqid=='uk'||wba_ccqid=='de')) || (wba_ccqid==null && wba_cccid!=null && (wba_cccid=='uk'||wba_cccid=='de'))){
	wba_iscc = true;
}
function bundleZoom(asin,imageCode){
	var imageUrl = document.getElementById('bundleThumb'+asin).src;
	var popupUrl = imageUrl.replace(imageCode,'SL500');
	zoom(popupUrl);
}