
$(document).ready(function($){	
	$('.clean_text2').each(function(e){
			$(this).html(wbr2($(this).html(), 25));
	});
	$('#user_labels input[type=button]').click(function(){ labelcreate(); 	});
	$('#user_labels input.labelname').keydown(function(e){  });
	$('#que_faites_vous').elastic();
	$.fn.fancyzoom.defaultsOptions.imgDir='/images/ressources/'; //very important must finish with a /
	$('a.tozoom').fancyzoom({Speed:1000});
	
    $(".datagrid tr").mouseover(function(){
    	$(this).addClass("handon");
    }).mouseout(function(){
    	$(this).removeClass("handon");	
    });   
    setTimeout("$('#alert').hide()",5000); 
    
	$('#comment_textarea').keypress(function() {		   	
		   $("#char_title_left").html(500-(this.value.length+1)+" caractères <br /> restant");
		   ismaxlength(this);
	});
	
	
	$('#SettingUserDonFirst').change(function() {	
			if ($('#SettingUserDonFirst').val()== 1) $("#UserUserDonText").html("Insérer le lien de votre formulaire de don");
			if ($('#SettingUserDonFirst').val()== 2) $("#UserUserDonText").html("Insérer l’ adresse mail utilisée pour créer votre compte Paypal");
			if ($('#SettingUserDonFirst').val()== 3) $("#UserUserDonText").html("Insérer une adresse postale");		
	});	
	
	$('#SettingUserDonFirst').change(function() {	
		if ($('#SettingUserDonFirst').val()== 1) $("#SettingUserDon").html("Insérer le lien de votre formulaire de don");
		if ($('#SettingUserDonFirst').val()== 2) $("#SettingUserDon").html("Insérer l’ adresse mail utilisée pour créer votre compte Paypal");
		if ($('#SettingUserDonFirst').val()== 3) $("#SettingUserDon").html("Insérer une adresse postale");	
	
});

		
	

	
	//$(".points").corner();
	
	
	/*
	 * options[submit]    submit button value, empty means no button **
  * @param String  options[cancel]
	 * 
	 */
	/*
	$('#message_perso_edit').editable('/users/editstatus',{
		submit:'OK',
		cssclass:'editeinplace'
	});
	*/
    
    
    
    	$('.lire_suite').toggle(
    		function(){
    			var my_id = $(this).attr('id').split('_')[3];
    			$("#cut_to_show_" + my_id).hide();
    			$("#text_to_show_" + my_id).show();
    			$("#id_to_show_" + my_id).html("Réduire");
    		},
    		function(){
    			var my_id = $(this).attr('id').split('_')[3];
    			$("#text_to_show_" + my_id).hide();
    			$("#cut_to_show_" + my_id).show();
    			$("#id_to_show_" + my_id).html("Lire la suite");
    		}
    	);
    	
    	
    	$('.lire_suite_desc').toggle(
        		function(){        			
        			$("#cut_to_show").hide();
        			$("#text_to_show").show();
        			$("#id_to_show").html("Réduire");
        		},
        		function(){
        			$("#text_to_show").hide();
        			$("#cut_to_show").show();
        			$("#id_to_show").html("Lire la suite");
        		}
        	);
    	
    	
    	$('.lien_afficher_all_com_plus').toggle(
        		function(){        			
        			var my_id = $(this).attr('id');
        			$("#last_3_pluscomments_" + my_id).hide();
        			$("#all_plus_comments_" + my_id).show();
        			$("a.lien_afficher_all_com_plus").html("Les 3 derniers commentaires");
        		},
        		function(){
        			var my_id = $(this).attr('id');
        			$("#all_plus_comments_" + my_id).hide();
        			$("#last_3_pluscomments_" + my_id).show();
        			$("a.lien_afficher_all_com_plus").html("Afficher tout les commentaires");
        		}
        	);	
        
	
	//header
	$('#comment_textarea').focus(function() { $('#upload_file').slideDown(); return false; });
	$('#upload_file').hide();
	$('#comment_textarea').elastic();
	
	$('#close_flash').click(function() { $('#alert').fadeOut(500); return false; });

	$('#objet').keypress(function() {		   	
		   $("#char_title_left").html(71-(this.value.length+1)+" caractères restant");		   
	});
	$('a#parrainer_prod_link').click(function() { $('#parrainer_prod').toggle(400); return false; });
	$('a#clic_modif_donnees').click(function() { $('#modif_coordonnees').toggle(400); return false; });
	
	
	$('a#link_infos_personnelles').click(function() { $('#infos_personnelles').toggle();  $('#infos_generales').hide(); return false; });
	$('a#link_infos_generales').click(function() { $('#infos_generales').toggle();  $('#infos_personnelles').hide(); return false; });
	
	
	$('a#clic_envoyer_proprietaire').click(function() { $('#text_area_message').toggle(400); return false; });
	$('a#click-upload').click(function() { $('#upload-photo').toggle(400); return false; });	
	
	$('a#autre_lieu').click(function() { $('#div_autre_lieu').toggle(400); return false; });
	
	$('a#add_files').click(function() {  
		$('#div_video').hide();
		$('#div_file').show();
		$('#cancel_join').show();
		$('#confirm_join').hide();
		$('#valider_join').hide();
		return false;
	});
	$('a#add_videos').click(function() {
		$('#div_video').show();
		$('#div_file').hide();
		$('#cancel_join').show();
		$('#valider_join').show();
		$('#add_files_on').show();
		return false;
	});
	
	$('a#cancel_join').click(function() {
		var url = $('#input_video').val();
		var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
		if (urlRegxp.test(url) != true || url.indexOf("youtube") == -1) {
			$('#input_video').val("Insérer le lien d'une vidéo Youtube");
		}
		$('#div_video').hide();
		$('#div_file').hide();
		$('#cancel_join').hide();
		$('#valider_join').hide();	
		return false;
	});
	
	$('a#valider_join').click(function() {
		var url = $('#input_video').val();
		var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
		if (urlRegxp.test(url) != true || url.indexOf("youtube") == -1) {
			alert("Lien youtube non valide");
			return false;
		} else {
			$('#confirm_join').show();
			$('#div_video').hide();
			$('#div_file').hide();
			$('#cancel_join').hide();
			$('#valider_join').hide();	
			$('#add_videos_on').hide();	
			return false;
		}
	});

	
	
	$('#input_file').click(function() {
		$('#add_files_on').hide();				
	});	
	
	$('a#click_lien_cacher_photo').click(function() {
		$('#lien_cacher_photo').hide(); 
		$('.photo_obj').hide();
		$('.avtar_users').hide();
		$('.action-show').show();
		$('.action-hide').hide();
		$(".block-cliquable").addClass("block-cliquable-widhout-image");
		$(".block-cliquable-widhout-image").removeClass("block-cliquable");		
		$('#lien_afficher_photo').show(); return false;
	});
	$('a#click_lien_afficher_photo').click(function() { 
		$('#lien_afficher_photo').hide(); 
		$('.photo_obj').show();
		$('.avtar_users').show();
		$('.action-show').hide();
		$('.action-hide').show();
		$(".block-cliquable-widhout-image").addClass("block-cliquable");
		$(".block-cliquable").removeClass("block-cliquable-widhout-image");
		$('#lien_cacher_photo').show(); return false;
	});
	
	$('a#click_associations_uniquement').click(function() {
		$('.particulier').hide();		
		$('#lien_associations_uniquement').hide();
		$('#lien_tout_type_associations').show();
		return false;
	});
	
	$('a#click_entreprises_uniquement').click(function() {
		$('.particulier').hide();
		$('.association').hide();
		$('#lien_entreprises_uniquement').hide();
		$('#lien_tout_type_entreprises').show();
		return false;
	});
	
	
	$('a#click_lien_tout_type_associations').click(function() {
		$('.particulier').show();
		$('.entreprise').show();
		$('.association').show();
		$('#lien_associations_uniquement').show();
		$('#lien_tout_type_associations').hide();
		return false;
	});	
	$('a#click_lien_tout_type_entreprises').click(function() {
		$('.particulier').show();
		$('.entreprise').show();
		$('.association').show();
		$('#lien_entreprises_uniquement').show();
		$('#lien_tout_type_entreprises').hide();
		return false;
	});	
	
	//DD_roundies.addRule('.points, .points-win, .points-requis, .points-spend, .product-price', '5px', true);
	
	/*
	$('a#clic_repondre1').click(function() { $('#repondre_box').toggle(400); $('#detail_message').show(); $('#nouveau_box').hide(); return false; });
	$('a#clic_nouveau').click(function() {	$('#nouveau_box').toggle(400); $('#detail_message').hide(); $('#repondre_box').hide(); return false; });	
	$('a#clic_composer').click(function() {	$('#compose_box').toggle(400); $('#listing_messages').hide(); return false; });
	$('a#clic_retour').click(function() {	$('#listing_messages').toggle(400);  $('#compose_box').hide();  return false; });

    $("#tokenize2").tokenInput("/msgs/users.json", {
        classes: {
            tokenList: "token-input-list-facebook",
            token: "token-input-token-facebook",
            tokenDelete: "token-input-delete-token-facebook",
            selectedToken: "token-input-selected-token-facebook",
            highlightedToken: "token-input-highlighted-token-facebook",
            dropdown: "token-input-dropdown-facebook",
            dropdownItem: "token-input-dropdown-item-facebook",
            dropdownItem2: "token-input-dropdown-item2-facebook",
            selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
            inputToken: "token-input-input-token-facebook"
        }
    });

	*/
	$('#comment_textarea').focus(function() {		
		if ($('#comment_textarea').val() == "Exprimez vous!" || $('#comment_textarea').val() == "" || $("#comment_textarea").val() == "Contenu de l'article: "){
			this.value = '';
		}		
		$("#c_text").show();
	});
	
	$('#input_video').focus(function() {		
		if ($('#input_video').val()== "Insérer le lien d'une vidéo Youtube" || $('#input_video').val() == ""){
			this.value = '';
		}		
	});
	
	/*$('.value_reset_sentence').blur(function() {
		if ($('.value_reset_sentence').val()== "Titre de l'article: " || $('.value_reset_sentence').val() == ""){
			$("#c_text").hide();
			// si pas de titre on le cache
		}
	});
	*/	
	$('.value_reset').each(function() {
	    var default_value = this.value;
	    $(this).focus(function() {
	        if(this.value == default_value) {
	            this.value = '';
	        }
	    });
	    $(this).blur(function() {
	        if(this.value == '' && default_value!="Poster un article: " && default_value != "Contenu de l'article: ") {
	            this.value = default_value;
	        }
	        if(this.value == "Contenu de l'article: " || this.value == '') {
	            this.value = "Contenu de l'article: ";
	        }
	    });
	});	
	
	
	$('.reset_champ').each(function() {
	    var default_value = this.value;
	    $(this).focus(function() {
	        if(this.value == default_value) {
	            this.value = '';
	        }
	    });
	    $(this).blur(function() {
	        if(this.value == '') {
	            this.value = default_value;
	        }
	    });
	});	

	
	$('.contraintes').click(function() {			 
			$('#if_contraintes').toggle(400);		 
			return true;
	}); 
	
	$('.if_lieu').click(function() {			 
		$('#if_lieu').toggle(400);		 
		return true;
	});
	$('.in-edit').mouseover(function() {
		//$(".edit_in_line");
		//alert("Test");		
	});	
	

	
	$().ready(function() {	
		function formatItem(row) {
			return row[0] + " (<strong>id: " + row[1] + "</strong>)";
		}
	$("#cities").autocomplete(cities, {
			matchContains: true,
			minChars: 0
		});
	});
	
			 
	   $("#slide").mouseover(function(){
	    	$("#right").addClass("etiquette");
	    });
	   $("#slide").mouseout(function(){
	    	$("#right").removeClass("etiquette");	
	    }); 
	   
	   
	    
	
	
	$('.valider_produit_donner').click(function() {
		 var classtab =  $(this).attr('class').split(' ');
		 offre_produit(this.id, 'produitdonners');
		 document.getElementById("tout_le_div").innerHTML = "Vous avez validé cette offre";
		 var user = $(this).attr('name');
		// document.location.href = "/messages/newmess/"+user+"/pd";
		 $(this).remove();		 
	  });	
	  $('.valider_produit_donner').confirm({	
		  msg:'Etes-vous sûr de valider ce membre?',
		  wrapper: '<div></div>',		 
		  timeout:10000
	  });
	  
	  
		$('.valider_service_donner').click(function() {
			 var classtab =  $(this).attr('class').split(' ');
			 offre_produit(this.id, 'servicedonners');
			 document.getElementById("tout_le_div").innerHTML = "Vous avez validé cette offre";
			 var user = $(this).attr('name');
		//	 document.location.href = "/messages/newmess/"+user+"/ps";
			 $(this).remove();		 
		  });	
		  $('.valider_service_donner').confirm({		
			  msg:'Etes-vous sûr de valider cette offre?',
			  timeout:10000
		  }); 
	  
		  $("#objet").keyup(function (e) {
			  $("#find_photo").html('<a target="_blank" href="http://images.google.com/images?hl=en&q='+$("#objet").val()+' '+'">Trouver une photo sur '+$("#objet").val()+' </a>');
		  });
		  
		  $("a#text_add_photo").click(function (e) {
			  $("#add_picture").show();
			  return false;
		  });
		  

	$('.ex').click(function() {
		 var classtab =  $(this).attr('class').split(' ');
		 
		 valider_membre(this.id, 'produits');
		 document.getElementById("tout_le_div").innerHTML = "Vous avez validé ce produit";		 
		 var user = $(this).attr('name');
		 //document.location.href = "/messages/newmess/"+user+"/p";		 
		 $(this).remove();		 
	  });	
	  $('.ex').confirm({		
		  msg:'Etes-vous sûr de valider ce membre?',
		  timeout:10000
	  });
	  
	  
	  $('.valider_troc').click(function() {
			 var classtab =  $(this).attr('class').split(' ');
			 
			 valider_membre(this.id, 'trocs');
			 document.getElementById("tout_le_div").innerHTML = "Vous avez accepté cette proposition";		 
			 var user = $(this).attr('name');
			 //document.location.href = "/messages/newmess/"+user+"/p";		 
			 $(this).remove();		 
		  });	
		  $('.valider_troc').confirm({		
			  msg:'Etes-vous sûr de valider cette proposition?',
			  timeout:10000
		  });
	  

	  
		$('.valider_service').click(function() {
			 var classtab =  $(this).attr('class').split(' ');
			 offre_service(this.id, 'services');
			 document.getElementById("tout_le_div").innerHTML = "Vous avez validé ce service";
			 var user = $(this).attr('name');
			// document.location.href = "/messages/newmess/"+user+"/s";
			 $(this).remove();		 
		  });	
		  $('.valider_service').confirm({		
			  msg:'Etes-vous sûr de valider ce membre?',
			  timeout:10000
		  });
	  
	  
		$('.valider_offre_service').click(function() {
			 var classtab =  $(this).attr('class').split(' ');
			 offre_service(this.id, 'services');
			 document.getElementById("offre_choisi").innerHTML = "Vous avez validé cette offre";
			 var user = $(this).attr('name');
			// document.location.href = "/messages/newmess/"+user;
			 $(this).remove();		 
		  });	
		  $('.valider_offre_service').confirm({		
			  msg:'Etes-vous sûr d\'accepter cette offre?',
			  timeout:10000
		  });
		  
		  
			$('.valider_offre_produit').click(function() {
				 var classtab =  $(this).attr('class').split(' ');
				 valider_offre(this.id, 'produitdonners');
				 document.getElementById("tout_le_div").innerHTML = "Vous avez validé cette offre";
				 var user = $(this).attr('name');
				// document.location.href = "/messages/newmess/"+user;
				 $(this).remove();		 
			  });	
			  $('.valider_offre_produit').confirm({		
				  msg:'Etes-vous sûr d\'accepter cette offre?',
				  timeout:10000
			 });
			  
			  
		  
	  
		$('div.retirer_demande').click(function() {
			var classtab =  $(this).attr('class').split(' ');
			retirer_demande(classtab[1]);
			 document.getElementById("tout_le_div").innerHTML = "Demande annulée, si vous voulez redemander ce produit, actualiser la page";
			 $(this).remove();		 
		  });	
		  $('.retirer_demande').confirm({		
			  msg:'Etes-vous sûr de retirer votre demande?',
			  timeout:10000
		  });
		  
		  
			$('div.retirer_proposition').click(function() {
				var classtab =  $(this).attr('class').split(' ');
				retirer_demande(classtab[1]);
				 document.getElementById("tout_le_div").innerHTML = "Votre proposition a été annulée";
				 $(this).remove();		 
			  });	
			  $('.retirer_proposition').confirm({		
				  msg:'Etes-vous sûr de retirer votre proposition?',
				  timeout:10000
			  });
		  

		$('a[id^=show_more_]').click(
			function() {
				var com_id = $(this).attr('id').split('_')[2];
				var inp_order = $('#inp_order').val();
				var inp_filtre = $('#inp_filtre').val();
				$.ajax({
					type: 'post',
					url: '/home/showmore',
					cache: false,
					data: {'data[com_id]':com_id, 'data[inp_order]':inp_order, 'data[inp_filtre]':inp_filtre},
					dataType:'json',
					async: true,
					beforeSend: function(){
						$('#page_showmore').hide();
						$('#div_loading').show();
						return true;
					},
					success: function(data){
						$('#div_loading').hide();
						if (data.nomore == 0) {
							$('#allcomments').append(data.outhtml);
							$('#show_more_' + com_id).attr('id', 'show_more_' + data.lastid);
							$('#page_showmore').show();
						}
						else {
							$('#allcomments').append(data.outhtml);
							$('#no_show_more').show();
						}
						$.fn.fancyzoom.defaultsOptions.imgDir='/images/ressources/'; //very important must finish with a /
						$('a.tozoom').fancyzoom({Speed:1000});
					}
				});
			}	
		);
});


function cacher_message () {
	$('#flashmessage').hide(50);
}

function addFormField() {
	var id = document.getElementById("id").value;
	$("#divTxt").append("<p id='row" + id + "'><label for='txt" + id + "'>Membre " + id + "&nbsp;&nbsp;<input type='text' size='20' name='txt[]' id='txt" + id + "'>&nbsp;&nbsp<a href='#' class='font_marron' style='text-decoration:none' onClick='removeFormField(\"#row" + id + "\"); return false;'><img src=\"/images/delete.png\"> supprimer</a><p>");
	
	
	$('#row' + id).highlightFade({
		speed:1000
	});
	
	id = (id - 1) + 2;
	document.getElementById("id").value = id;
}

function removeFormField(id) {
	$(id).remove();
}

function labelcreate(){
	var newlabel = $('#user_labels input.labelname').val();
	//alert(newlabel);
	$.post('/labels/create', { data:newlabel }, function success(data){
		insertLabel(data);
	});
	return false;
}

	function send_email_facebook() {
		  var getdate = new Date();  //Used to prevent caching during ajax call
		  if(xmlhttp) {
		    xmlhttp.open("POST","/users/send_email_facebook",true); 
		    xmlhttp.onreadystatechange  = update_facebook_send;
		    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		    xmlhttp.send("user_email=" + "ok");	    
		  }
		  document.location = "/inscription-3-groupes";
	}

	function je_prends(id, type){
		var txt = '<div style="width:600px; height:350px"><iframe src="/'+type+'/prendre/'+id+'/" height="350" width="600" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}
	
	function je_troc(id){
		var txt = '<div style="width:600px; height:350px"><iframe src="/trocs/prendre/'+id+'/" height="350" width="600" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}	
	
	function poster_recycler(id, type){
		var txt = '<div style="width:600px; height:350px"><iframe src="/produits/question/'+id+'/'+type+'" height="350" width="600" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}	
	
	
	function faire_promotion(id, type){
		var txt = '<div style="width:650px; height:780px;"><iframe src="/promotion-recycler/'+type+'/'+id+'/" height="780" width="650" scrolling="auto" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' },
			  top: '2%'
		});	
	}
	
	function poster_troc(id, type){
		var txt = '<div style="width:640px; height:810px;"><iframe src="/ajouter-un-troc" height="810" width="625" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' },
			  top: '2%'
		});	
	}
	
	function signup_temp_entreprise(id, type){
		var txt = '<div style="width:600px; height:300px"><iframe src="/users/signup_temp_entreprise" height="300" width="600" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}	
	
	function facebook_connect(){
		var txt = '<div style="width:650px; height:450px"><iframe src="/pagefacebook" height="450" width="650" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}	
	
	function poster_article(type, id){
		var txt = '<div style="width:600px; height:350px"><iframe src="/participer/poster/'+id+'/" height="350" width="600" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: ' ', Bye: ' ' }
		});	
	}
	
	function closePopUp(){
		$.prompt.close();
	}
	
	function feedback(){
		var txt = '<div style="width:500px; height:300px"><iframe src="/feedback" height="300" width="500" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}
	
	
	function je_negocie(id, type){
		var txt = '<div style="width:600px; height:350px"><iframe src="/'+type+'/negocier/'+id+'/" height="350" width="600" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}
	
	function received(id, type){
		var txt = '<div style="width:600px; height:350px"><iframe src="/'+type+'/received/'+id+'" height="350" width="600" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}
	
	function not_received(id, type){
		var txt = '<div style="width:600px; height:400px"><iframe src="/'+type+'/not_received/'+id+'" height="300" width="500" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}	
	
	function repondre_question(id, type){
		var txt = '<div style="width:500px; height:300px"><iframe src="/'+type+'/repondre/'+id+'/" height="300" width="500" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}
	
	function repondre_offre(id, type){
		var txt = '<div style="width:500px; height:300px"><iframe src="/'+type+'/repondre_offre/'+id+'/" height="300" width="500" scrolling="no" frameborder="no" align="center"></div><br/>';
		function mycallbackform(){
		}
		$.prompt(txt,{
		      callback: mycallbackform,
		      buttons: { Hey: 'Hello', Bye: 'Good Bye' }
		});	
	}
	


function insertLabel(data) {
	//Append le nouveau label créé
	var thespan = '<span class="white"><img class="handle" border="0" alt="" src="/img/move.png"/><input type="checkbox"/></span>';
	var thehtml = '<li>'+thespan+data+'</li>';
	//$thehtml.prependTo("#newLabel");
	$('#user_labels .next_label').before(thehtml);
	// vider le input de newLabel pour la suite 
	$('#newLabel').hide();
	$('#user_labels .next_label img').show();
	return false;	
}

var time_variable;

function getXMLObject()  //XML OBJECT
{
	var xmlHttp=null;
	try
	{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	// Internet Explorer
	try
	{
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	}
	return xmlHttp;
}

var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object

	
	
function handleServerResponse() {
	   if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	      document.getElementById("message").innerHTML=xmlhttp.responseText;
	      document.getElementById("sous_categorie").innerHTML=xmlhttp.responseText;	      
	     }

	   }
	}

function update_sous_categorie() {
	   if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	      document.getElementById("sous_categorie").innerHTML=xmlhttp.responseText;   
	     }
	   }
	}

function update_facebook_send() {
	   if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	      document.getElementById("user_email").innerHTML=xmlhttp.responseText;   
	     }
	   }
	}

function update_sous_categoriecequejeveux() {
	   if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	      document.getElementById("sous_categorie_cequejeveux").innerHTML=xmlhttp.responseText;   
	     }
	   }
	}


function update_sous_categoriecequejepeux() {
	   if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	      document.getElementById("sous_categorie_cequejepeux").innerHTML=xmlhttp.responseText;   
	     }
	   }
	}



function update_departement() {
	   if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	      document.getElementById("departement").innerHTML=xmlhttp.responseText;   
	     }
	   }
	}

function updatePoints() {
	   if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	    	 document.getElementById("nb_points").innerHTML=xmlhttp.responseText;	   	  
	     }
	   }
}



function profil_set_points() {
	  var getdate = new Date();
	  if(xmlhttp) {
		var user_nom = document.getElementById("user_nom");
		var user_prenom = document.getElementById("user_prenom");
		var user_date_naissance = document.getElementById("datepicker");
		var user_telephone = document.getElementById("user_telephone");
		var user_site = document.getElementById("user_site");
		var user_presentation = document.getElementById("user_presentation");
		var user_adresse = document.getElementById("user_adresse");
		var user_region = document.getElementById("user_region");
		var user_code_postale = document.getElementById("user_code_postale");
		var user_ville = document.getElementById("user_ville");
		var user_avatar = document.getElementById("user_avatar");

	    xmlhttp.open("POST","/users/printpoint",true);
	    xmlhttp.onreadystatechange  = updatePoints;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("user_nom=" + user_nom.value+ "&user_prenom=" + user_prenom.value + "&user_date_naissance=" + user_date_naissance.value + "&user_telephone=" + user_telephone.value + "&user_site=" + user_site.value + "&user_presentation=" + user_presentation.value + "&user_adresse=" + user_adresse.value + "&user_region=" + user_region.value + "&user_code_postale=" + user_code_postale.value + "&user_ville=" + user_ville.value + "&user_prenom=" + user_prenom.value + "&user_avatar=" + user_avatar.value); 
	  }
}

function set_code_postal() {
	   if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	    	 document.getElementById("user_cp").innerHTML=xmlhttp.responseText;	      
	     }
	   }
}
function ge_code_postal() {
	  if(xmlhttp) {
		var user_ville = document.getElementById("cities");
	    xmlhttp.open("POST","/users/get_code_postal",true); 
	    xmlhttp.onreadystatechange  = set_code_postal;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("user_ville=" + user_ville.value); 
	  }
	
}
function profil_set_points_insc() {
	  var getdate = new Date();
	  if(xmlhttp) {
		var user_nom = document.getElementById("UserUserNom");
		var user_ville = document.getElementById("CityLocal");
		var user_state = document.getElementById("UserFkCountrieId");
		var user_date_naissance = document.getElementById("datepicker");
	    xmlhttp.open("POST","/users/printpointinsc",true); 
	    xmlhttp.onreadystatechange  = updatePoints;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("user_nom=" + user_nom.value+ "&user_ville=" + user_ville.value + "&user_date_naissance=" + user_date_naissance.value+"&user_state=" + user_state.value); 
	  }
}

function getSubCategories() {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {
		var categorie = document.getElementById("categorie");
	    xmlhttp.open("POST","/produits/getsubcategories",true); 
	    xmlhttp.onreadystatechange  = update_sous_categorie;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("categorie=" + categorie.value);	    
	  }	  
	  
}

function getSubCategories_troc() {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {
		var categorie = document.getElementById("categorie");
	    xmlhttp.open("POST","/trocs/getsubcategories",true); 
	    xmlhttp.onreadystatechange  = update_sous_categorie;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("categorie=" + categorie.value);	    
	  }
}

function getSubCategories_service() {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {
		var categorie = document.getElementById("categorie");
	    xmlhttp.open("POST","/services/getsubcategories",true); 
	    xmlhttp.onreadystatechange  = update_sous_categorie;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("categorie=" + categorie.value);
	  }	  
}

function getSubCategories_cequejeveux() {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {
		var categorie_cequejeveux = document.getElementById("categoriecequejeveux");
	    xmlhttp.open("POST","/services/getsubcategories",true); 
	    xmlhttp.onreadystatechange  = update_sous_categoriecequejeveux;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("categorie=" + categorie_cequejeveux.value);
	  }		
}

function getSubCategories_cequejepeux() {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {
		var categorie_cequejepeux = document.getElementById("categoriecequejepeux");
	    xmlhttp.open("POST","/services/getsubcategories",true); 
	    xmlhttp.onreadystatechange  = update_sous_categoriecequejepeux;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("categorie=" + categorie_cequejepeux.value);
	  }		
}



function getSubCategories_donner() {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {
		var categorie = document.getElementById("categorie");
	    xmlhttp.open("POST","/produitdonners/getsubcategories",true); 
	    xmlhttp.onreadystatechange  = update_sous_categorie;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("categorie=" + categorie.value);
	  }	  
}

function getSubCategories_service_donner() {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {
		var categorie = document.getElementById("categorie");
	    xmlhttp.open("POST","/servicedonners/getsubcategories",true); 
	    xmlhttp.onreadystatechange  = update_sous_categorie;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("categorie=" + categorie.value);
	  }	  
}


function getDepartements() {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {
		var r = document.getElementById("r");
	    xmlhttp.open("POST","/recevoir-produit/departements",true); 
	    xmlhttp.onreadystatechange  = update_departement;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("r=" + r.value);	    
	  }	  
	  
}


function no_high_price() {
	document.getElementById("no_high_price").innerHTML="Attention! Vous ne pouvez pas augmenter le prix";	
}

function valider_membre(id, type) {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {		
		var id_produit = document.getElementById("id_produit");
	    xmlhttp.open("POST","/"+type+"/validerajax",true); 
	    xmlhttp.onreadystatechange  = handleServerResponse;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("user_id=" + id);	  

	  } 
	  
}

function offre_service(id, type) {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {		
		var id_service = document.getElementById("id_service");
	    xmlhttp.open("POST","/"+type+"/validerajax",true); 
	    xmlhttp.onreadystatechange  = handleServerResponse;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("user_id=" + id);	  

	  } 
	  
}

function offre_produit(id, type) {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {		
		var id_produit = document.getElementById("id_produit");
	    xmlhttp.open("POST","/"+type+"/validerajax",true); 
	    xmlhttp.onreadystatechange  = handleServerResponse;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("user_id=" + id);	  

	  } 
	  
}


function retirer_demande(type) {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  if(xmlhttp) {		
		 
		var id_interesses = document.getElementById("id_interesses");
	    xmlhttp.open("POST","/"+type+"/retirer_demande",true);	    
	    xmlhttp.onreadystatechange  = handleServerResponse;
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send("id_interesses=" + id_interesses.value);
	  } 
	  
}

function value_reset(e,o){
	if(o.firstTime){return;}
	o.firstTime=true;
	o.value="";
	}

function surligner(val){
	var tr = document.getElementById(val);
	tr.style.background = "#E6E6E6";
}
function desurligner(val){
	var tr = document.getElementById(val);
	tr.style.background = "#FFFFFF";
}


function wbr2(str, num) {	
	 var debut = false;
	 v = str.replace(/;/g, "; ");
	  return v.replace(RegExp("(\\w{" + num + "})(\\w)", "g"), function(all,text,char){
		  
		  if (text.indexOf("<") != -1 )
			 debut = true; 
		  if (text.indexOf(">") != -1)
			  debut = false; 
		  if (debut)
			  return text +  char;
			  
		  return text + "<wbr>\n" + char;
	  });
	}

function add_files() {
	//document.getElementById('add_files').style.display = 'block'; 
	//document.getElementById('add_files_on').style.display = 'none';	
	return false;
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength);
}

function add_points() {
	$(document).ready(function() {
	 	 $("#nb_points").load("/users/getpoint_");
	});

}








