var PageCache_RecentlyViewedProduct=Class.create({initialize:function(sku){this.cookie_name='recently_viewed';this.block_recent='block-recent-id';if(sku){this.addProductSkuToVisited(sku);}else{this.populateRecentlyViewedBlock('recently_content');}},addProductSkuToVisited:function(sku){var cookie_value=new String(PageCache.getCookie(this.cookie_name));var s=new Array();if(cookie_value!=''){s=cookie_value.split(';');}
if(s.last()!=sku){s.push(sku);var new_s=new Array();if(s.length>20){new_s=[s[s.length-4],s[s.length-3],s[s.length-2],s[s.length-1]];s=new_s;}
var str=new String();str=s.join(';');PageCache.setCookie(this.cookie_name,str,1,'/');}},populateRecentlyViewedBlock:function(element_id){$('block-recent-id').hide();var cookie_value=new String(PageCache.getCookie(this.cookie_name));var s=new Array();if(cookie_value.indexOf(';')){s=cookie_value.split(';');}else{s=[cookie_value];}
if(s.last()){new Ajax.Request('/auction/index/populateRecentlyViewedBlock',{parameters:{products:s.toJSON()},onSuccess:function(response){$(element_id).innerHTML=response.responseText;Effect.Appear('block-recent-id',{duration:1.0});}});}}});var PageCache={getCookie:function(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'';},setCookie:function(c_name,value,expiredays,path){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+"="+escape(value)+
((expiredays==null)?"":";expires="+exdate.toGMTString())+"; path="+path;}}
function fillNoncacheData(){if(document.cookie.indexOf('_cache_customer_id=')!=-1&&$('bluepart_logged')){$('bluepart').hide();$('bluepart_logged').show();}
if(document.cookie.indexOf('_cache_customer_id=')!=-1&&document.cookie.indexOf('_cache_customer_fb=')!=-1&&$('fb_disconnect_btn')){$('fb_connect_btn').hide();$('fb_disconnect_btn').show();}
if(typeof productListSkus!=='undefined'&&productListSkus!=""){if(productListInfo==''){var url="/esi/get_bids.php?skus="+productListSkus+"&nocache="+Math.ceil(Math.random()*1000000);new Ajax.Request(url,{method:'get',asynchronous:false,onSuccess:function(transport){productListInfo=transport.responseText;}});}
var listSkus=productListSkus.split(",");var listInfo=productListInfo.split("|");for(var i=0;i<listSkus.length;++i){if(listInfo[i]){var item=listInfo[i].split(";");$$('.bid-num-'+listSkus[i]).each(function(el){el.innerHTML=item[0];});$$('.bid-price-'+listSkus[i]).each(function(el){el.innerHTML="&pound;"+item[1];});}}}
if(typeof CometDelivery!=='undefined')CometDelivery.fillDelivery();}
Event.observe(window,'load',fillNoncacheData);function updateMessageBiddingZone(){$('bid_buy_message').update(loading_zone);new Ajax.Updater('bid_buy_message','/get_product_detail.php',{method:'get',evalScripts:true,parameters:{sku:product_sku,nocache:Math.ceil(Math.random()*1000000)}});}
var minimalBid=1;function confirmSetLocation(message,url){$('bidding_form').action=url;$('bidding_form').submit();return false;}
function validateBidJs(){if($('bid').value<minimalBid){$('bid-too-small').show();$('bid').value=minimalBid;return false;}
if($('bid').value>9999.99){$('bid-too-high').show();$('bid').value=minimalBid;return false;}
return true;}
function validateFormBid(){$('bid-too-small').hide();$('bid-too-high').hide();if(!validateBidJs()){return;}
new Ajax.Request('/validate_bid.php',{method:'post',parameters:{'bid':$('bid').value,'sku':product_sku},onSuccess:function(transport){if(transport.responseText=='OK'){$('bidding_form').action='/auction/bid/confirmPage/';$('bidding_form').submit();return;}
window.location.reload(true);},onFailure:function(transport){window.location.reload(true);}});}
function trackWatchlistAdd(){try{_gaq.push(['_trackPageview','/watchlistadd']);}catch(err){}
return true;}
function trackConfirmBid(){try{_gaq.push(['_trackPageview','/confirmbid']);}catch(err){}
return true;}
function trackEnquiry(){try{_gaq.push(['_trackPageview','/enquiry']);}catch(err){}
return true;}
function trackRegistration(){try{_gaq.push(['_trackPageview','/registration']);}catch(err){}
return true;}
function setLocation(url){window.location.href=url;}
function prepareSubmit(filterCode){var from=$('from_'+filterCode).value;var to=$('to_'+filterCode).value;if(!validatePriceParam(from)||!validatePriceParam(to)){alert('Enter a valid positive number');return false;}else{if(window.location.pathname.split("/").length-1>1){setLocation(window.location.pathname.replace(/.html/i,"-p-"+from+"-"+to+".html"));}else{setLocation(window.location.pathname.replace(/.html/i,"/p-"+from+"-"+to+".html"));}
return false;}}
function validatePriceParam(v){for(var i=0;i<v.length;++i)
{var new_key=v.charAt(i);if(new_key<"0"||new_key>"9")return false;}
return v.length>0;}
