
$(document).ready(function(){ 
   /*attribution des valeur de prix*/
			selprices=new Array(
    {value1:'0',value2:'99999', nom:'Moins de 100.000 &euro;'},
    {value1:'100000',value2:'199999', nom:'100.000 &euro; &agrave; 200.000 &euro;'},
    {value1:'200000',value2:'299999', nom:'200.000 &euro; &agrave; 300.000 &euro;'},
    {value1:'300000',value2:'499999', nom:'300.000 &euro; &agrave; 500.000 &euro;'},
    {value1:'500000',value2:'999999', nom:'500.000 &euro; &agrave; 1000.000 &euro;'}

    );
				
				locprices=new Array(
    {value1:'0',value2:'999', nom:'Moins de 1000 &euro;'},
    {value1:'1000',value2:'1999', nom:'1000 &euro; &agrave; 2000 &euro;'},
    {value1:'2000',value2:'2999', nom:'2000 &euro; &agrave; 3000 &euro;'},
    {value1:'3000',value2:'4999', nom:'3000 &euro; &agrave; 5000 &euro;'},
    {value1:'5000',value2:'9999', nom:'5000 &euro; &agrave; 10000 &euro;'}
    );
								
				moreChoice = '                 <li class="manual"><div class="moreSelect"><div style="float:left">De <input style="width:32px" type="text" id="minprice" value="min" inputtarget="price" num="1" /></div><div style="float:left"> &agrave; <input style="width:32px" type="text" id="maxprice" value="max" inputtarget="price"  num="2"/></div> <div style="float: left;"><a class=" " href="javascript: void(0) ">ok</a></div></div></li>';
								

				priceupdate =function (tableau) {
									ielem=0;
								var block =$(".price_form  div.inputsSelect ul");
								block.empty();

								for (var elemt in tableau )
								{

											var text_el = tableau[ielem]["nom"];
											var price_el1 = tableau[ielem]["value1"];
											var price_el2 = tableau[ielem]["value2"];
											var item_el = '<li><a href="" inputtarget="price" send1="'+price_el1+'" send2="'+price_el2+'">'+text_el+'</a></li>'

											block.prepend(item_el);
											ielem+=1;
											if  (ielem == tableau.length ) { 
															block.append(moreChoice);
												}
											
								}
														
								
				}
				
				priceupdate(selprices);


					
					
					
   /*attribution des classes et des value*/
			
   $('input[type="text"]').addClass("idleField");
			$('input[type="text"]').attr("valeurbase", function() { return this.value });;
				
			$('input[type="text"]').focus(function() {
					$(this).removeClass("idleField").addClass("focusField");
						if ($(this).attr("value") == $(this).attr("valeurbase")){
													this.value = '';
									}
									

							
								});
								
								
								
					$('input[type="text"]').blur(function() {
					
								$(this).removeClass("focusField").addClass("idleField");
									
									if ($(this).attr("value") == ""){
													this.value = $(this).attr("valeurbase");
									}else { return false}
						});
						
						
						
					$('form#search_form div.inputsSelect').click(
					function() {														
					$(this).addClass("showField");
					});
					
					$('form#search_form div.inputsSelect p a').click(
					function() {	
					$(this).parents(".inputsSelect").addClass("showField");
					return false;
					}
					);
					
					
					$('form#search_form div.inputsSelect').bind(" mouseleave  ", function(){							$(this).removeClass("showField");					});
								
					$linkcharger	=function	() {
							$('form#search_form div.inputsSelect ul a').click (
							
							
									function() {
									$(this).parents(".inputsSelect").removeClass("showField");
									var inputTarget=$(this).attr("inputtarget");
									
									var reponse=$(this).attr("send");
									
									var reponse1=$(this).attr("send1");
									var reponse2=$(this).attr("send2");
									
									var inputlabel=$(this).text();	
									if (reponse1 != null || reponse1 != null ) {

											$('input#'+inputTarget+"1").attr("value", reponse1);
											$('input#'+inputTarget+"2").attr("value", reponse2);
											$("."+inputTarget).html(inputlabel);	
											
											} else {
											
											$('input#'+inputTarget).attr("value", reponse);
											$("."+inputTarget).html(inputlabel);	
											
											};
											

									
									return false;
		
								}	);
					}
					
					$linkcharger();
			
				
				
				/* evenements loc achat */

				$("#location_button").click(function () {				
					priceupdate(locprices);
					$(this).addClass("selected");
					$("#sel_button").removeClass("selected");
					$('input#action').attr("value", "rent");
					$linkcharger();
					$(".price_form a.price").html("Montant");	
    });
					
				$("#sel_button").click(function () {
					priceupdate(selprices);
					$(this).addClass("selected");$("#location_button").removeClass("selected");
					$('input#action').attr("value", "sale");
					$linkcharger();
					$(".price_form a.price").html("Montant");	

					
    });
				$("#search_form input").keypress(function (e) {
					if (e.which == 13 ) {
					return false;
					} 
					
	});
				$("div.moreSelect input").change( function() { 
					
					var inputTarget=$(this).attr("inputtarget");
					var num=$(this).attr("num");
					
					var reponse=$(this).attr("value");
					$('input#'+inputTarget+num).attr("value", reponse); 
					
					var entree=[$("#"+inputTarget+"1" ).attr("value"),$("#"+inputTarget+"2" ).attr("value")]
					$(" a."+inputTarget+"").html("de "+entree[0]+" &agrave; &nbsp;"+entree[1]+"&nbsp; <span class='euro'>&euro;</span><span class='metre'>m2</span>")
					
					
	} );


     
    
 }); 

