function start_loading(){$('.login_ajax_loading').show(0,function(){$('.loading_txt').delay(1000).show(0)})}function stop_loading(){$('.jquerybubblepopup').hide();$('.login_ajax_loading').hide();$('.loading_txt').stop(true,true).hide()}function disable_btn(btn,w,src){btn.attr('disabled','disabled')}function enable_btn(btn,val,width){btn.removeAttr('disabled')}function in_array(array,p_val){for(var i=0,l=array.length;i<l;i++){if(array[i]==p_val){return true}}return false}function isset(){var a=arguments;var l=a.length;var i=0;if(l===0){throw new Error('Empty isset');}while(i!==l){if(typeof(a[i])=='undefined'||a[i]===null){return false}else{i++}}return true}function closeModal(){$('#mask').fadeOut("fast");$('#mini_mask').fadeOut("fast");$('.window').fadeOut("fast");return false}function launchModal(w,h){var id='#dialog';$(id).width(w);$(id).height(h);var maskHeight=$(document).height();var maskWidth=$(window).width();$('#mask').css({'width':maskWidth,'height':maskHeight,'top':'0px','left':'0px'});$('#mask').fadeTo("fast",0.8);var winH=$(window).height();var winW=$(window).width();var winST=$(window).scrollTop();$(id).css('top',winST+(winH/2-$(id).height()/2));$(id).css('left',winW/2-$(id).width()/2);$(id).fadeIn("fast");$('#mini_mask').fadeOut("fast")}function update_dom(response,flat){if(isset(response)){var $out='';if(isset(response.page_title)){$.address.title(response.page_title)}for(var i in response.html){if(!flat){$(i).html(response.html[i]).show()}else{$out=$out+response.html[i]}}for(var u in response.htmlnoshow){if(!flat){$(u).html(response.htmlnoshow[u])}else{$out=$out+response.htmlnoshow[u]}}for(var t in response.innerhtml){document.getElementById(t).innerHTML=response.innerhtml[t]}for(var p in response.css){$(p).css(response.css[p].name,response.css[p].value)}for(var o in response.prepend){$(o).prepend(response.prepend[o]).fadeIn('fast')}for(var r in response.cssclass){$(r).addClass(response.cssclass[r])}for(var k in response.append){$(k).append(response.append[k]).fadeIn('fast')}for(var n in response.after){$(n).after(response.after[n]).fadeIn('fast')}for(var n in response.before){$(n).before(response.before[n]).fadeIn('fast')}if(flat)return $out}else{if(!flat)$('#search_results').html('Un probl&egrave;me est survenu.');else return'Un probl&egrave;me est survenu.'}}$(window).scroll(function(){var id='#msg_box';var winW=$(window).width();var winH=$(window).height();var winST=$(window).scrollTop();var src_error='';$(id).css('bottom',0-winST+10);$(id).css('left',winW-$(id).width()-50)});function launchMsg(txt,error,refresh){var id='#msg_box';var winW=$(window).width();var winH=$(window).height();var winST=$(window).scrollTop();var src_error='';$(id).css('bottom',0-winST+10);$(id).css('left',winW-$(id).width()-50);if(error){src_error='<img src="http://www.trocdejeux.com/public/images/pictos/exclamation.png" alt="!" style="float:left;margin-right:5px;"/>';$(id).removeClass().addClass('red')}else{src_error='<img src="http://www.trocdejeux.com/public/images/pictos/tick_ok.png" alt="ok" style="float:left;margin-right:5px;"/>';$(id).removeClass().addClass('default')}$(id).html(src_error+txt);$(id).stop(true,true).hide(0).fadeTo(1000,1).fadeTo(5000,1).fadeOut(2000);var cur_add=$.address.value();cur_add=cur_add.replace('/','');if(refresh){$('#login_ajax_loading').show();$.ajax({type:'POST',url:cur_add,cache:false,dataType:'json',data:''}).success(function(response){update_dom(response,false)}).success(function(response){execute_dom(response)}).complete(function(){stop_loading()}).error(function(request,error){stop_loading();ajx_error(error)});return false}}function ajx_error(error){if(error=='timeout'){launchMsg('La r&eacute;ponse du serveur tarde &agrave; venir. Veuillez r&eacute;essayer.',true,false)}else{launchMsg('Un probl&egrave;me de connexion est survenu. Veuillez r&eacute;essayer.',true,false)}}function login(){$.ajax({type:"POST",url:"auth/login",cache:false,dataType:"json"}).success(function(response){update_dom(response,false)}).success(function(response){execute_dom(response)}).complete(function(){stop_loading()}).error(function(request,error){stop_loading();ajx_error(error)})}function clean_log_out_session(prompt){if($('#nav_pane').length>0){$('#nav_pane').hide()}$("ul#nav").html('<li id="home"><a href="#!/home/highlights" class="bigger" title="Page d\'accueil troc de jeux">Accueil</a></li><li id="subscribe"><a href="#!/home/inscription" class="bigger">Echanger vos jeux</a></li><li id="how"><a href="#!/home/comment_ca_marche" class="bigger">Comment &ccedil;a marche ?</a></li><li id="new_games"><a href="#!/home/nouveaux_jeux" class="bigger" title="les derniers trocs">Les derniers trocs</a></li><li id="blog"><a href="http://blog.trocdejeux.com" title="le blog de troc de jeux" class="bigger">Blog</a></li>');$('#login_form').show();$('#logout_form').hide();$("#generic_message").hide();$('span#login_scarab').html('');$('div#map_container').hide();if(prompt){uri=encodeURIComponent($.address.path());load_ajax('auth/re_login/?uri='+uri,'')}$.address.value('home/highlights');load_ajax('home/highlights','')}function update_menu_nav(my_troc,my_page,my_library,my_profile,my_s_troc,my_r_troc){if($('li#my_page').length==0){$("#login_form").hide();$("#logout_form").show();$("#actual_form").hide();$("#catalog_search").show();$('ul#nav').html('<li id="my_home"><a href="#!/home/highlights" >Accueil</a></li><li id="my_troc"><a href="#!/member/troquer_alentours" >'+my_troc+'</a></li><li id="my_page"><a href="#!/home/my_space" >'+my_page+'</a></li><li id="deals"><a href="#!/member/echange_ideal" title="Les meilleurs plans d\'&eacute;change">Bons Plans</a></li><li id="my_library"><a href="#!/member/my_library" >'+my_library+'</a></li><li id="my_r_troc"><a href="#!/member/my_transactions_received" >'+my_r_troc+'</a></li><li id="my_s_troc"><a href="#!/member/my_transactions_sent" >'+my_s_troc+'</a></li><li id="my_blog"><a href="#!/member/messages_received" title="Les messages">Messages</a></li>')}}function clean_content_boxes(){if($('#nav_pane').length>0)$('#nav_pane').hide()}function load_ajax(url,sub_response){start_loading();$.ajax({type:"POST",url:url,cache:true,dataType:"json"}).success(function(response){update_dom(response,false);if(sub_response!=''){start_loading();update_dom(sub_response,false)}}).success(function(response){execute_dom(response);if(sub_response!=''){start_loading();execute_dom(sub_response)}}).complete(function(){stop_loading()}).error(function(request,error){stop_loading();ajx_error(error)})}var map=[];function createMap(map_id,id,latitude,longitude,zoom,limit){is_loaded=0;timer=0;delay=(function(){timer=0;return function(callback,ms){clearTimeout(timer);timer=setTimeout(callback,ms)}})();center=new google.maps.LatLng(latitude,longitude);var myOptions={zoom:zoom,center:center,mapTypeControl:false,scrollwheel:false,mapTypeId:google.maps.MapTypeId.ROADMAP};map[map_id]=new google.maps.Map(document.getElementById(id),myOptions);infowindow=new google.maps.InfoWindow({content:"C'est vous !"});bounds=new Array();bounds[map_id]=new google.maps.LatLngBounds();marker=new Array();cmarker=new Array();point=new Array();bubble_content=new Array();image=[];shadow=[];shape=[];image['home']=new google.maps.MarkerImage('http://google-maps-icons.googlecode.com/files/home.png',new google.maps.Size(32,37),new google.maps.Point(0,0),new google.maps.Point(16,37));shadow['home']=new google.maps.MarkerImage('http://www.trocdejeux.com/public/images/pictos/map/game_shadow.png',new google.maps.Size(54,37),new google.maps.Point(0,0),new google.maps.Point(16,37));shape['home']={coord:[30,0,31,1,31,2,31,3,31,4,31,5,31,6,31,7,31,8,31,9,31,10,31,11,31,12,31,13,31,14,31,15,31,16,31,17,31,18,31,19,31,20,31,21,31,22,31,23,31,24,31,25,31,26,31,27,31,28,31,29,31,30,30,31,24,32,23,33,22,34,21,35,20,36,11,36,10,35,9,34,8,33,7,32,1,31,0,30,0,29,0,28,0,27,0,26,0,25,0,24,0,23,0,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,0,2,0,1,1,0,30,0],type:'poly'};image['man']=new google.maps.MarkerImage('http://www.trocdejeux.com/public/images/pictos/map/image.png',new google.maps.Size(24,37),new google.maps.Point(0,0),new google.maps.Point(12,37));shadow['man']=new google.maps.MarkerImage('http://www.trocdejeux.com/public/images/pictos/map/shadow.png',new google.maps.Size(46,37),new google.maps.Point(0,0),new google.maps.Point(12,37));shape['man']={coord:[16,0,18,1,19,2,20,3,21,4,22,5,22,6,23,7,23,8,23,9,23,10,23,11,23,12,23,13,23,14,23,15,23,16,22,17,22,18,21,19,20,20,20,21,18,22,18,23,18,24,18,25,19,26,19,27,19,28,19,29,17,30,16,31,16,32,16,33,16,34,16,35,16,36,7,36,7,35,7,34,7,33,6,32,6,31,6,30,4,29,4,28,4,27,4,26,4,25,5,24,5,23,5,22,3,21,3,20,2,19,1,18,1,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,1,6,1,5,2,4,3,3,4,2,5,1,7,0,16,0],type:'poly'};image['game']=new google.maps.MarkerImage('http://www.trocdejeux.com/public/images/pictos/map/game_image.png',new google.maps.Size(32,37),new google.maps.Point(0,0),new google.maps.Point(16,37));shadow['game']=new google.maps.MarkerImage('http://www.trocdejeux.com/public/images/pictos/map/game_shadow.png',new google.maps.Size(54,37),new google.maps.Point(0,0),new google.maps.Point(16,37));shape['game']={coord:[30,0,31,1,31,2,31,3,31,4,31,5,31,6,31,7,31,8,31,9,31,10,31,11,31,12,31,13,31,14,31,15,31,16,31,17,31,18,31,19,31,20,31,21,31,22,31,23,31,24,31,25,31,26,31,27,31,28,31,29,31,30,30,31,24,32,23,33,22,34,21,35,20,36,11,36,10,35,9,34,8,33,7,32,1,31,0,30,0,29,0,28,0,27,0,26,0,25,0,24,0,23,0,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,0,2,0,1,1,0,30,0],type:'poly'};markers=[];if(limit!=''){var populationOptions={strokeColor:"#FF0000",strokeOpacity:0.8,strokeWeight:2,fillOpacity:0,map:map[map_id],center:center,radius:limit};cityCircle=new google.maps.Circle(populationOptions)}}function addHomeMarker(map_id,latitude,longitude,txt){pos=new google.maps.LatLng(latitude,longitude);var marker0=new google.maps.Marker({position:pos,map:map[map_id],icon:'http://google-maps-icons.googlecode.com/files/home.png'});google.maps.event.addListener(marker0,"click",function(){infowindow.close();infowindow.setContent(txt);infowindow.open(map,marker0)});markers.push(marker0);bounds[map_id].extend(pos)}function load_bubble(url,id){$.ajax({type:"POST",url:url,cache:false,dataType:"json",success:function(response){var contenu=update_dom(response,true);infowindow.setContent(contenu);execute_dom(response)},complete:function(){$('#loading_item_'+id).hide()}})}var bubble_wait_content='<div style="width:350px;height:200px;"><center><br/><br/><img src="http://www.trocdejeux.com/public/images/ajax/ajax_loader.gif" style="margin:0;padding:0;vertical-align:middle;" alt="loading"/><br/>Chargement de la liste de jeux...</center></div>';function addMarker(map_id,id,login,oo,bubble,type,label,extendbounds){if(label){marker[id]=new MarkerWithLabel({position:point[id],map:map[map_id],icon:image[type],shape:shape[type],labelContent:login,labelClass:"marker_label",labelInBackground:false,labelVisible:true,labelAnchor:new google.maps.Point(30,32)})}else{marker[id]=new MarkerWithLabel({position:point[id],map:map[map_id],icon:image[type],shape:shape[type]})}markers.push(marker[id]);if(extendbounds=="true"){bounds[map_id].extend(point[id])}if(bubble){$('#list_'+id+', #marker_pointer_'+id).die("click");google.maps.event.addListener(marker[id],'click',function(){infowindow.close();infowindow.setContent(bubble_wait_content);infowindow.open(map[map_id],marker[id]);load_bubble('member/load_marker/'+id,id)});$('#list_'+id+', #marker_pointer_'+id).live('click',function(){$('#loading_item_'+id).show();infowindow.close();infowindow.setContent(bubble_wait_content);infowindow.open(map[map_id],marker[id]);load_bubble('member/load_marker/'+id,id);return false})}}function ClusterMap(map_id){var mcOptions={gridSize:30,zoomOnClick:false};markerCluster=new MarkerClusterer(map[map_id],markers,mcOptions)}function effacerLigne(array,value){var output=[];var j=0;for(var i in array){if(array[i]!=value){output[j]=array[i];j++}}return output}function clearMarkers(){if(markers){for(i in markers){markerCluster.removeMarker(markers[i]);markers[i].setMap(null)}markers.length=0}}function execute_dom(response){if(isset(response)){for(var j in response.display){if($(j).length>0){if(response.display[j]==0){$(j).hide()}else{$(j).show()}}}if(isset(response.map)){var init=response.map['init'].split(',');createMap(init[0],init[1],init[2],init[3],parseFloat(init[4]),parseFloat(init[5]));var home_marker=response.map['home_marker'].split(',');addHomeMarker(init[0],home_marker[0],home_marker[1],home_marker[2]);for(var x in response.map.markers){var marker_a=response.map.markers[x].split(',');point[marker_a[0]]=new google.maps.LatLng(marker_a[1],marker_a[2]);addMarker(init[0],marker_a[0],marker_a[3],x,marker_a[4],marker_a[5],marker_a[6],marker_a[7])}}if(isset(response.execute)){$.each(response.execute,function(q,qv){jQuery.globalEval(qv)})}}}$(document).ready(function(){var loading_src='http://www.trocdejeux.com/public/images/ajax/ajax_loader.gif';$.ajaxSetup({timeout:120000});$.address.externalChange(function(event){var add=$.address.path();if(add!='/'&&add!='home/highlights'){clean_content_boxes();var do_load_ajax=true}else{$.address.value('home/highlights');var do_load_ajax=false}if(do_load_ajax){start_loading();var data_str='';var params=$.address.pathNames();var variables=new Array('Keywords','ItemPage','country_search','dispo','console','view','region','want_game_id','want_owner','want_asin');var pos=add.indexOf("catalog/search/");if(pos>0){for(i=2;i<=params.length;i++)data_str+=variables[i-2]+'='+params[i]+'&'}var url=$.address.baseURL()+$.address.path();$.ajax({type:'POST',url:url,cache:true,dataType:'json',data:data_str}).success(function(response){in_ajax=false;for(var i in response){if(i=='subpage'){in_ajax=true}}if(in_ajax){in_url=url.substr(0,url.lastIndexOf('/'));load_ajax(in_url,response)}else{update_dom(response,false)}}).success(function(response){if(!in_ajax){execute_dom(response)}}).complete(function(){stop_loading()}).error(function(request,error){stop_loading();ajx_error(error)})}return false});$('.ajx_form').live('submit',function(e){start_loading();if($(this).attr('id')=='catalog_search'||$(this).attr('id')=='catalog_search_wizard'||$(this).attr('id')=='quick_search'){clean_content_boxes();var key_post=$('input[name=Keywords]',this).val();var key_itempage=$('input[name=ItemPage]',this).val();var key_country=$('select[name=country_search], input[name=country_search]',this).val();var key_dispo=$('input[name=dispo]',this).val();var key_console=$('select[name=console], input[name=console]',this).val();var key_view=$('input[name=view]',this).val();var key_region=$('select[name=region], input[name=region]',this).val();$.address.value($(this).attr('action')+'/'+encodeURIComponent(key_post)+'/'+encodeURIComponent(key_itempage)+'/'+encodeURIComponent(key_country)+'/'+encodeURIComponent(key_dispo)+'/'+encodeURIComponent(key_console)+'/'+encodeURIComponent(key_view)+'/'+encodeURIComponent(key_region))}else{var old_address=$.address.path()}var form_id=$(this).attr('id');var elt_id=$(this).attr('id');var elt_val=$("input[type*='submit']",this).attr('value');disable_btn($("input[type*='submit']",this),$("input[type*='submit']",this).css('width'),loading_src);var data_str;data_str=$(this).serializeArray();$.ajax({type:"POST",url:$(this).attr('action'),cache:true,dataType:"json",data:data_str}).success(function(response){update_dom(response,false);$("input[type=password]").val('')}).success(function(response){execute_dom(response)}).complete(function(){enable_btn($("#"+elt_id+" input[type*='submit']"),elt_val);stop_loading();$("input[type=password]").val('')}).error(function(request,error){stop_loading();$("input[type=password]").val('');ajx_error(error)});return false});$('.ajx_link').live('click',function(){start_loading();$.address.value($(this).attr('href'));clean_content_boxes();var data_str='';var add=$.address.path();var params=$.address.pathNames();var pos=add.indexOf("catalog/search/");if(pos>0){data_str='Keywords='+params[2]+'&'+'ItemPage='+params[3]+'&country_search='+params[4]+'&dispo='+params[5]+'&console='+params[6]+'&view='+params[7]+'&region='+params[8]}$.ajax({type:'POST',url:$(this).attr('href'),cache:true,dataType:'json',data:data_str}).success(function(response){update_dom(response,false)}).success(function(response){execute_dom(response)}).complete(function(){stop_loading()}).error(function(request,error){stop_loading();ajx_error(error)});return false});$('.ajx_command').live('click',function(){if($(this).hasClass('delete')){if(!confirm($(this).attr('title'))){return false}}start_loading();if($(this).children('img').length>0&&$(this).hasClass('button')){var obj_id=$(this).attr('id');var old_src=$(this).children('img').attr('src');$(this).children('img').attr('src',loading_src);$(this).children('img').css('margin','2px')}var maskHeight=$(this).parent().parent().outerHeight();var maskWidth=$(this).parent().parent().outerWidth();var maskoffset=$(this).parent().parent().offset();$('#mini_mask').css({'width':maskWidth,'height':maskHeight,'top':maskoffset.top,'left':maskoffset.left});$('#mini_mask').fadeTo('fast',0.1);var data_str='';var add=$(this).attr('href');var pos=add.indexOf("catalog/search/");if(pos>0){var pathsplit=add.split('catalog/');var pathnames=pathsplit[1];var params=pathnames.split('/');data_str='Keywords='+params[1]+'&'+'ItemPage='+params[2]+'&country_search='+params[3]+'&dispo='+params[4]+'&console='+params[5]+'&view='+params[6]+'&region='+params[6]}var l_this=$(this);$.ajax({type:'POST',url:$(this).attr('href'),cache:true,dataType:'json',data:data_str}).success(function(response){update_dom(response,false)}).success(function(response){execute_dom(response)}).complete(function(){stop_loading();$('#mini_mask').fadeOut('fast');if(isset(old_src)){$('#'+obj_id).children('img').attr('src',old_src)}}).error(function(request,error){stop_loading();ajx_error(error)});return false});$('.window .close').click(function(e){e.preventDefault();$('#mask').fadeOut();$('.window').fadeOut()});$('#mask').click(function(){$(this).fadeOut();$('.window').fadeOut()})});jQuery(function($){$.datepicker.regional['fr']={closeText:'Fermer',prevText:'&#x3c;Préc',nextText:'Suiv&#x3e;',currentText:'Aujourd\'hui',monthNames:['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],monthNamesShort:['Jan','Fév','Mar','Avr','Mai','Jun','Jul','Aoû','Sep','Oct','Nov','Déc'],dayNames:['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],dayNamesShort:['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],dayNamesMin:['Di','Lu','Ma','Me','Je','Ve','Sa'],weekHeader:'Sm',dateFormat:'dd/mm/yy',firstDay:1,isRTL:false,showMonthAfterYear:false,yearSuffix:''};$.datepicker.setDefaults($.datepicker.regional['fr'])});
