if(top.location!=location){top.location=self.location;}
function displayValue(value,currency)
{var currencySymbol='';switch(currency)
{case'GBP':currencySymbol='&pound;';break;case'USD':currencySymbol='$';break;case'EUR':currencySymbol='&euro;';break;}
var Mycurrency=' '+currency;if(currencySymbol){Mycurrency='';}
dblValue=parseFloat(value);dblValue=Math.floor(dblValue*100+0.50000000001);intCents=dblValue%100;strCents=intCents.toString();value=Math.floor(dblValue/100).toString();if(intCents<10){strCents="0"+strCents;}
formattedValue=currencySymbol+value+'.'+strCents+Mycurrency;return formattedValue;}
function refreshHomeUpdate(JSONdata)
{var bgColor;list=JSONdata.featuredOffers;for(var i in list){if(list.hasOwnProperty(i)){id=list[i].id;time=list[i].endDateDelta;price=displayValue(list[i].currentPrice,JSONdata.defaultCurrency);DOMPrice=$('#featuredOffer'+id+'Price');htmlText=DOMPrice.html();if(htmlText){htmlText=htmlText.replace('\u00a3','&pound;');}
if(htmlText){htmlText=htmlText.replace('\u0080','&euro;');}
bgColor=DOMPrice.closest('td').css('backgroundColor');if(DOMPrice.length&&price!=htmlText){DOMPrice.animate({backgroundColor:"lightgreen"},1000).html(price).animate({backgroundColor:"transparent"},1000);var periods=0;if(time/(3600*24)>1)periods=3;DOMTime=$('#featuredOffer'+id+'Time span.countdown');DOMTime.countdown('destroy').animate({backgroundColor:"lightgreen"},1000).countdown({until:time,significant:periods,expiryUrl:window.location.href}).animate({backgroundColor:"transparent"},1000);}}}
list=JSONdata.lastOffers;for(var j in list){if(list.hasOwnProperty(j)){id=list[j].id;price=displayValue(list[j].currentPrice,JSONdata.defaultCurrency);DOMPrice=$('#lastOffer'+id+'Price');htmlText=DOMPrice.html();if(htmlText){htmlText=htmlText.replace('\u00a3','&pound;');}
if(htmlText){htmlText=htmlText.replace('\u0080','&euro;');}
bgColor=DOMPrice.closest('td').css('backgroundColor');if(DOMPrice.length&&price!=htmlText){DOMPrice.animate({backgroundColor:"lightgreen"},1000).html(price).animate({backgroundColor:bgColor},1000);}}}
list=JSONdata.nextEndOffers;for(var k in list){if(list.hasOwnProperty(k)){id=list[k].id;time=list[k].endDateDelta;price=displayValue(list[k].currentPrice,JSONdata.defaultCurrency);bestBidder=list[k].bestBidder;DOMPrice=$('#nextEndOffer'+id+'Price');htmlText=DOMPrice.html();if(htmlText){htmlText=htmlText.replace('\u00a3','&pound;');}
if(htmlText){htmlText=htmlText.replace('\u0080','&euro;');}
var bgColor=DOMPrice.closest('td').css('backgroundColor');if(DOMPrice.length&&price!=htmlText){DOMPrice.animate({backgroundColor:"lightgreen"},1000).html(price).animate({backgroundColor:bgColor},1000);var periods=0;if(time/(3600*24)>1)periods=3;DOMTime=$('#nextEndOffer'+id+'Time span.countdown');DOMTime.countdown('destroy').animate({backgroundColor:"lightgreen"},1000).countdown({until:time,significant:periods,expiryUrl:window.location.href}).animate({backgroundColor:bgColor},1000);DOMBidder=$('#gridBidder'+id);if(DOMBidder.length){DOMBidder.animate({backgroundColor:"lightgreen"},1000).text(bestBidder).animate({backgroundColor:bgColor},1000);}
DOMGrid=$('#nextEndOffer'+id+'Time').parent('.gridPicture');if(DOMGrid.length){DOMGrid.animate({backgroundColor:"lightgreen"},1000).animate({backgroundColor:bgColor},1000);}}}}
list=JSONdata.highestBids;var bidCount=0;for(var l in list){if(list.hasOwnProperty(l)){id=list[l].offerId;var item=list[l].item;var user=list[l].user;var value=displayValue(list[l].value,JSONdata.defaultCurrency);var relativePath=JSONdata.relativePath;htmlText='<strong>'+value+'</strong><br/><a href="'+relativePath+'offer/details/'+id+'">'+item+'</a><br/><a class="mostActiveUser" href="'+relativePath+'user/profile/'+user+'">'+user+'</a>';DOMBid=$('#latestBid'+bidCount);DOMBid.html(htmlText);bidCount++;}}}
function refreshDetailsUpdate(JSONData){active=JSONData.active;if(!JSONData.active){clearInterval(refreshDP);}
DOMPrice=$('#currentPrice');var price=JSONData.currentPriceText;if(JSONData.currentPriceText!=DOMPrice.text()){DOMPrice.animate({backgroundColor:"#4ED"},1000).text(price).animate({backgroundColor:"white"},1000);var timeDelta=JSONData.endDateDelta;DOMTime=$('span.countdown');DOMTime.countdown('destroy').animate({backgroundColor:"#4ED"},1000).countdown({until:timeDelta,expiryUrl:window.location.href}).animate({backgroundColor:"white"},1000);var bestBidder=JSONData.bestBidder;DOMBidder=$('#bestBidder');if(DOMBidder.length){DOMBidder.animate({backgroundColor:"#4ED"},1000).text(bestBidder).animate({backgroundColor:"white"},1000);}
var bidsCount=JSONData.bidsCount;DOMBidder=$('#bidsCount');if(DOMBidder.length){DOMBidder.animate({backgroundColor:"#4ED"},1000).text(bidsCount).animate({backgroundColor:"white"},1000).next('A').attr('href',window.location.href).attr('onclick','');}}}
function refreshDetails(){$.ajax({url:'offer/bidDetails/'+id+'?v=JSON',cache:false,success:refreshDetailsUpdate,dataType:"json"});}
function refreshHome(){$.ajax({url:relativePath+'index.php?v=JSON',success:refreshHomeUpdate,cache:false,dataType:"json"});}
function closeAllTabsOpenFirst(){$(".tab_content").hide();$("ul.tabs li:first").addClass("active").show();$(".tab_content:first").show();}
function showMap(address)
{if(GBrowserIsCompatible()){var con=document.getElementById("map");var map=new GMap2(con);var geocoder=new GClientGeocoder();geocoder.getLatLng(address,function(point){if(point){map.setCenter(point,13);var marker=new GMarker(point);map.addOverlay(marker);marker.openInfoWindowHtml(address);setTimeout(closeAllTabsOpenFirst,800);}});}}
$(function(){var $li=$('li');$li.filter(':first-child').addClass('first');$li.filter(':last-child').addClass('last');$('dt:first-child').addClass('first');$('dd:last-child').addClass('last');$('tr').each(function(){var $this=$(this);var $a=$this.find('a, input, select');if(1==$a.length){$this.css({cursor:'pointer'}).click(function(){document.location=$a.get(0).href;}).hover(function(){$this.addClass('hover');},function(){$this.removeClass('hover');});}});if($.browser.msie){var correctMW=function(){if($(window).width()*0.9>900){$('#wrap').width('auto');}else{$('#wrap').width('900px');}};correctMW();$(window).resize(correctMW);}
$('#menu li').mouseenter(function(){$(this).addClass('hover');}).mouseleave(function(){$(this).removeClass('hover');});$('span.countdown').each(function(){var $t=$(this);var oDate=$t.find('input').val();var periods=0;if(oDate/(3600*24)>1)periods=3;$t.countdown({until:oDate,significant:periods,expiryUrl:window.location.href});});if($('textarea').length){$('textarea:not(.simple)').tinymce({theme:"advanced",plugins:"safari,layer,table,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",theme_advanced_buttons1:"bold,italic,underline,strikethrough,|,bullist,numlist,|,outdent,indent,blockquote,formatselect,fontselect,fontsizeselect, |,justifyleft,justifycenter,justifyright,justifyfull",theme_advanced_buttons2:"cut,copy,paste,pastetext,pasteword,|,search,replace,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,preview,|,forecolor,backcolor",theme_advanced_buttons3:"hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,advhr,|,fullscreen, |,cite,abbr,acronym,ins,attribs,|,visualchars,nonbreaking",theme_advanced_toolbar_location:"top",theme_advanced_toolbar_align:"left",theme_advanced_statusbar_location:"bottom",theme_advanced_resizing:true,convert_urls:false,external_link_list_url:"js/link_list.js",external_image_list_url:"js/image_list.js",media_external_list_url:"js/media_list.js"});}
$.tablesorter.addParser({id:"enuukMoney",is:function(s){var sp=s.replace(/,/,'.');var test=(/([A-Z]{3} ?\d+\.?\d*|\d+\.?\d* ?[A-Z]{3})/.test(sp))||(/([£$€] ?\d+\.?\d*|\d+\.?\d* ?[£$€])/.test(sp));return test;},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/[^\d\.]/g),""));},type:"numeric"});$.tablesorter.addParser({id:"enuukCountdown",is:function(s){var test=/^(\d{1,3}\w+)?\d{1,2}\w+\d{1,2}\w+\d{1,2}\w+$/.test(s);return test;},format:function(s){var fields=s.match(/\d{1,3}/g);var acc=0;for(var i=0;i<fields.length;i++){acc=acc*100+parseInt(fields[i]);}
return acc;},type:"numeric"});$('table.tablesorter').tablesorter({widgets:['zebra'],textExtraction:function(node){return $(node).text();}});if(typeof(address)!="undefined"){showMap(address);}
$('#bidHistory').hide();$('a.newWindow').click(function(){window.open(this.href);return false;});if(typeof(address)=="undefined"){closeAllTabsOpenFirst();}
$("ul.tabs li").click(function(){$("ul.tabs li").removeClass("active");$(this).addClass("active");$(".tab_content").hide();var activeTab=$(this).find("a").attr("href");$(activeTab).fadeIn();return false;});$("#filter").change(function(){$("#filterForm").submit();});if(typeof(refreshTime)!="undefined"){if(/index|index2/.test(template)){refreshH=setInterval(refreshHome,refreshTime*1000);}else if(/offerDetailsPenny/.test(template)&&active){refreshDP=setInterval(refreshDetails,refreshTime*1000);}}
if(/offerForm|offerUpdateForm/.test(template)){function updateSpecificFields(url)
{var delay=400;$('#ajaxIcon').show();$('#specificFields').fadeOut(delay);$.ajax({url:url,cache:false,success:function(html){$('#ajaxIcon').hide();$('#specificFields').html(html);$('#specificFields').fadeIn(delay);},dataType:"html"});}
function updateShipping(type){if(usesShipping[type]){$('#shipping').show();}else{$('#shipping').fadeOut(400);}}
var useUrl='offer/specificFields/'+(id||'0/'+defType);updateSpecificFields(useUrl);updateShipping(defType);$('#auctionTypes input').click(function(){var type=$(this).val();updateSpecificFields('offer/specificFields/0/'+type);updateShipping(type);});$("#content-offerAdd").submit(validateOfferForm());}
if(/userForm/.test(template)){$("#content-login").submit(validateUserForm());}
$('.categories li').hover(function(){$(this).animate({marginLeft:'5px'},200)},function(){$(this).animate({marginLeft:'0'},200)});});$(function(){$('ul.tagList').each(function(){var $list=$(this).find('a');var $details=$(this).next().children();if(1!=$list.filter('.active').length){$list.removeClass('active').eq(0).addClass('active');}
$list.each(function(index){var $t=$(this);if(!$t.hasClass('active')){$details.eq(index).hide();}
$t.click(function(){if(!$details.eq(index).length){return true;}
if($t.hasClass('active')){return false;}
$list.removeClass('active');$t.addClass('active');$details.filter(':visible').slideUp();$details.eq(index).slideDown();$(':checkbox').hide().fadeIn("slow");return false;});});});$('#content-messages div.messageActions').each(function(){var $this=$(this);var $messages=$this.closest('li').find('tr');var checkLinks=function(){var checked=$messages.find('input:checked').length;var unread=$messages.filter('.unread').find('input:checked').length;if(checked){$this.find('a.delete').removeClass('disabled');}else{$this.find('a.delete').addClass('disabled');}
if(checked!=unread){$this.find('a.markAsUnread').removeClass('disabled');}else{$this.find('a.markAsUnread').addClass('disabled');}
if(unread){$this.find('a.markAsRead').removeClass('disabled');}else{$this.find('a.markAsRead').addClass('disabled');}};$messages.find('input').change(checkLinks);$this.find('select').change(function(){switch($('option:selected',this).attr('class')){case'all':$messages.find('input').attr('checked','checked');break;case'none':$messages.find('input').attr('checked',false);break;case'unread':$messages.find('input').attr('checked',false);$messages.filter('.unread').find('input').attr('checked','checked');break;case'read':$messages.find('input').attr('checked',false);$messages.not('.unread').find('input').attr('checked','checked');break;}
checkLinks();});});});function displayError(errorText,container)
{var $c=$(container);if($c.find('div.ko').length){$c.find('div.ko').html(errorText).fadeOut().fadeIn();}else{$('<div class="ko" style="display:none">'+errorText+'</div>').prependTo($c).slideDown('fast');}}
function validateOfferForm(){var inputItemTitle=$("#inputItemTitle");var reqItemTitle=$("#reqItemTitle");var selectCategoryId=$("#selectCategoryId");var reqCategoryId=$("#reqCategoryId");var inputStartPrice=$("#inputStartPrice");var reqStartPrice=$("#reqStartPrice");var checkPayMethods=$("#checkPayMethod input");var reqPayMethod=$("#reqPayMethod");function validateTitle(){if(inputItemTitle.val().length<6){reqItemTitle.addClass("error");return false;}
else{reqItemTitle.removeClass("error");return true;}}
function validateCategory(){if(selectCategoryId.val()==null){reqCategoryId.addClass("error");return false;}
else{reqCategoryId.removeClass("error");return true;}}
function validateStartPrice(){if(inputStartPrice.val()<=0){reqStartPrice.addClass("error");return false;}
else{reqStartPrice.removeClass("error");return true;}}
function validatePayMethod(){var atLeastOne=false;for(var i in checkPayMethods.toArray()){if(checkPayMethods[i].checked){atLeastOne=true;reqPayMethod.removeClass("error");break;}}
if(!atLeastOne){reqPayMethod.addClass("error");}
return atLeastOne;}
inputItemTitle.blur(validateTitle);inputStartPrice.blur(validateStartPrice);inputItemTitle.keyup(validateTitle);selectCategoryId.keyup(validateCategory);inputStartPrice.keyup(validateStartPrice);$("#content-offerAdd").submit(function(e){if(validateTitle()&&validateCategory()&&validateStartPrice()&&validatePayMethod()){return true;}else{window.scrollTo(0,0);displayError("<div class=\"fullBox\">"+redAlert+"</div>",'#content');return false;}});}
function validateUserForm(){var inputUsername=$("#id");var reqUsername=$("#reqUsername");var inputPassword=$("#password");var inputPassword2=$("#password2");var reqPassword=$("#reqPassword");var reqPassword2=$("#reqPassword2");var inputEmail=$("#email");var reqEmail=$("#reqEmail");var inputName=$("#name");var reqName=$("#reqName");var textAreaAddress=$("#address");var reqAddress=$("#reqAddress");var inputZip=$("#zip");var reqZip=$("#reqZip");var selectCountry=$("#countryId");var reqCountry=$("#reqCountry");function validateUsername(){if(inputUsername.val().length<5){reqUsername.addClass("error");return false;}
else{reqUsername.removeClass("error");return true;}}
function validatePassword(){if(inputPassword.val().length<6){reqPassword.addClass("error");return false;}else{reqPassword.removeClass("error");if(inputPassword.val()!=inputPassword2.val()){reqPassword2.addClass("error");return false;}else{reqPassword2.removeClass("error");return true;}}}
function validateEmail(){if(/^(.+\@.+\..+)$/.test(inputEmail.val())){reqEmail.removeClass("error");return true;}else{reqEmail.addClass("error");return false;}}
function validateName(){if(!inputName.val()){reqName.addClass("error");return false;}
else{reqName.removeClass("error");return true;}}
function validateAddress(){if(textAreaAddress.attr('value').length<=7){reqAddress.addClass("error");return false;}else{reqAddress.removeClass("error");return true;}}
function validateZip(){if(!inputZip.val()){reqZip.addClass("error");return false;}
else{reqZip.removeClass("error");return true;}}
function validateCountry(){if(!selectCountry.attr('value')){reqCountry.addClass("error");return false;}else{reqCountry.removeClass("error");return true;}}
inputUsername.blur(validateUsername);inputPassword.blur(validatePassword);inputEmail.blur(validateEmail);inputName.blur(validateName);inputZip.blur(validateZip);inputUsername.keyup(validateUsername);inputPassword.keyup(validatePassword);inputPassword2.keyup(validatePassword);inputEmail.keyup(validateEmail);inputName.keyup(validateName);inputZip.keyup(validateZip);$("#content-login").submit(function(e){if(validateUsername()&&validatePassword()&&validateEmail()&&validateName()&&validateAddress()&&validateZip()&&validateCountry()){return true;}else{window.scrollTo(0,0);displayError("<div class=\"fullBox\">"+redAlert+"</div>",'#content');return false;}});}
