function refreshsession() {
   $.ajax({
	  url: '/index/refreshsession',
	  success: function(data) {
	  }
	});
   setTimeout("refreshsession()",60000);
}

$(document).ready(function() {
	 refreshsession();

	if ($("#tabs li a").length != 0)
	{
		$.featureList(
			$("#tabs li a"),
			$("#output li"), {
				start_item : 0,
				transition_interval : -1
			}
		);
	}

	if ($("#menu_button_matches").length != 0)
		setInterval(function() {
      	$("#menu_contact_broker").toggleClass("menu_style_match");
		}, 500);

	if ($("#presentation_part_2").length != 0)
		$("#presentation_part_2").corner();

	if ($("#page_match_part_3").length != 0)
		$("#page_match_part_3").corner();

	if ($("#modal_registration_1").length != 0 && !$.browser.msie)
		$("#modal_registration_1").corner();

	if ($("#modal_registration_ge_2").length != 0 && !$.browser.msie)
		$("#modal_registration_ge_2").corner();

	if ($("#modal_registration_me_2").length != 0 && !$.browser.msie)
		$("#modal_registration_me_2").corner();

	if ($("#modal_registration_tpe_2").length != 0 && !$.browser.msie)
		$("#modal_registration_tpe_2").corner();

	if ($("#modal_registration_pl_2").length != 0 && !$.browser.msie)
		$("#modal_registration_pl_2").corner();

	if ($("#modal_registration_ae_2").length != 0 && !$.browser.msie)
		$("#modal_registration_ae_2").corner();

	if ($("#input[name=go_to_registration]").length != 0 && !$.browser.msie)
		$("input[name=go_to_registration]").corner();

	if ($("#registration_step_1_map_1").length != 0 && !$.browser.msie)
		$("#registration_step_1_map_1").corner();

	if ($("#modal_contact").length != 0 && !$.browser.msie)
		$("#modal_contact").corner();

	if ($("#modal_password").length != 0 && !$.browser.msie)
		$("#modal_password").corner();

	if ($("#modal_contact_footer").length != 0 && !$.browser.msie)
		$("#modal_contact_footer").corner();

	if ($("#modal_mail").length != 0 && !$.browser.msie)
		$("#modal_mail").corner();

	//$("#home_not_registered").click(function () { if ($.browser.msie && $.browser.version == "8.0") window.location.href = window.location.href.replace("#", "")+"#"; }).colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_registration_1", scrolling: false, overlayClose: false});

	$("#subscription_button").click().colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_registration_1", scrolling: false, overlayClose: false});

	$("#resend_password").click(function() {
		resend_password();
	});

	$("input[name=radio_forme_sociale]").click( function () {
		$("#corporate_structure").val($(this).val());
		$.fn.colorbox({innerWidth:"640px", innerHeight:"700px", inline:true, href:"#modal_registration_"+$(this).val()+"_2", scrolling: false, overlayClose: false});
	});

	$("#presentation_register").click( function() { if ($.browser.msie && $.browser.version == "8.0") window.location.href = window.location.href.replace("#", "")+"#"; } ).colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_registration_1", scrolling: false, overlayClose: false});

	$("#to_register").click().colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_registration_1", scrolling: false, overlayClose: false});

	$("#to_register_2").click().colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_registration_1", scrolling: false, overlayClose: false});

	$("#to_register_top").click().colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_registration_1", scrolling: false, overlayClose: false});

	$("#contact_broker").click().colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_contact", scrolling: false, overlayClose: false});

	$("#forgotten_password").click().colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_password", scrolling: false, overlayClose: false});

	$("#contact_broker_2").click().colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_contact", scrolling: false, overlayClose: false});

	$("#contact_footer").click(function() {if ($.browser.msie && $.browser.version == "8.0") window.location.href = window.location.href.replace("#", "")+"#";} ).colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_contact_footer", scrolling: false, overlayClose: false});

	$("#faq_mail").click().colorbox({innerWidth:"500px", innerHeight:"500px", inline:true, href:"#modal_mail", scrolling: false, overlayClose: false});

	$("#region_see_map").click().colorbox({innerWidth:"670px", innerHeight:"800px", inline:true, href:"#registration_step_1_map_1", scrolling: false, overlayClose: false});

	$("#scope_see_map").click().colorbox({innerWidth:"670px", innerHeight:"800px", inline:true, href:"#registration_step_1_map_2", scrolling: false, overlayClose: false});

	$("input[name=go_to_registration]").click( function () {
		$("form[name=go_to_reg]").submit();
	});

	if ($("#registration_step_1").length != 0)
	{
		$("#registration_step_1").validationEngine({
			validationEventTriggers:"keyup blur",
			promptPosition: "topRight"
		});
	}

	$("#step_1_submit").click ( function () {
		if ($("#registration_step_1").validationEngine({returnIsValid:true}))
		{
			//if (EstSirenValide())
				$("#registration_step_1").submit();
			//else
			//	alert("Desole ce numero de SIREN n'est pas valide");
		}
		else
		{
			return false;
		}
	});

	$("#valider").click ( function () {
		$.ajax({
				  type: "POST",
				  url: "/matches/acceptmatch",
				  data: "username="+$("#username").val()+"&password="+$("#password").val(),
				  success: function(data) {
				  	if (data == "ok") {
				  		alert("Le broker a \351t\351 averti pour votre int\351r\352t dans l'un de ces matchs. Il vous contactera tr\350s prochainement.");
				  	}
				  	else
				  		alert("Votre identifiant et votre mot de passe n'ont pas \351t\351 reconnus");
				  }
		});
	});

	$("map[name=France_scope] area").click( function () {
		$("#scope").val($(this).attr("name"));
		$.fn.colorbox.close();
	});

	$("map[name=France_region] area").click( function () {
		$("#region").val($(this).attr("name"));
		$.fn.colorbox.close();
	});

	$("#lastname").change( function () {
		$(this).val($(this).val().toUpperCase());
	});

	$("#list_ape").change( function () {
		$("#ape").val($(this).val());
	});

	$("#banner").click ( function() {
		location.href = "/";
	});

	$("#faq_see_examples").click( function () {
		$("#faq_list").hide("slide");
		$("#faq_examples").show("slide");
		location.href = "#sample";
		return false;
	});

	$(".faq_hide_examples").click( function () {
		$("#faq_examples").hide("slide");
		$("#faq_list").show("slide");
		return false;
	});

	$("#btn_add_offer_product").click(function() {
		addTabProduct();
	});
	$("#btn_add_offer_service").click(function() {
		addTabService();
	});
	$("#btn_add_need").click(function() {
		addTabNeed();
	});

	if ($("#slider").length != 0)
	{
		$("#slider").slider({
				value:1,
				min: 1,
				max: 4,
				step: 1,
				slide: function(event, ui) {
					if (ui.value == 1)
						$("#slider_text").val('Urgent');
					if (ui.value == 2)
						$("#slider_text").val('Relativement urgent (2-4 mois)');
					if (ui.value == 3)
						$("#slider_text").val('6 mois');
					if (ui.value == 4)
						$("#slider_text").val('1 an et plus');
			}
		});
		$("#slider_text").val('Urgent');
	}

	function addTabProduct() {
		var next_id = $('#tabs_offers_products').tabs("length")+1;
		var tab_title = "Produit n&deg; "+next_id;
		$tabsproducts.tabs('add', '#tabs_offers_products-'+next_id, tab_title);
	}

	function addTabService() {
		var next_id = $('#tabs_offers_services').tabs("length")+1;
		var tab_title = "Service n&deg; "+next_id;
		$tabsservices.tabs('add', '#tabs_offers_services-'+next_id, tab_title);
	}

	function addTabNeed() {
		var next_id = $('#tabs_needs').tabs("length")+1;
		var tab_title = "Besoin n&deg; "+next_id;
		$tabsneeds.tabs('add', '#tabs_needs-'+next_id, tab_title);

		$("#product_type_input_with_dropdown-"+next_id).mcDropdown(
														"#service_type_menu",
														{
															screenPadding: 0,
															minRows: 16,
															allowParentSelect: true,
															delim: " > "
														}
		);
	}

	if ($('#tabs_offers_products').length != 0) {
		var $tabsproducts = $('#tabs_offers_products').tabs({
				tabTemplate: '<li><a href="#{href}">#{label}</a></li>',
				add: function(event, ui) {
					tmpi = $(ui.panel).attr("id").replace("tabs_offers_products-", "");
					$.ajax({
					  url: '/registration/offerproduct',
					  data: "tmpi="+tmpi+"&currenttype=product",
					  success: function(data) {
					  	$(ui.panel).append(data);
					  	$(ui.panel).find(".mdd_product_input").mcDropdown(
								"#product_type_menu",
								{
									screenPadding: 0,
									minRows: 16,
									allowParentSelect: true,
									delim: " > "
								}
							);
							$("#validate-product-"+tmpi).click ( function () {
								var id = $(this).attr("id").replace("validate-product-", "");
								$.ajax({
											type: "POST",
										  url: "/registration/saveoffer",
										  data: "category="+$("#category-product-"+id).val()+"&other_category="+$("#other_category-product-"+id).val()+"&description="+escape($("#description-product-"+id).val())+"&price_ht="+$("#price_ht-product-"+id).val()+"&decote="+$("#decote-product-"+id).val()+"&exchange_value="+$("#exchange_value-product-"+id).val()+"&unite="+$("#unite-product-"+id).val()+"&qmin="+$("#qmin-product-"+id).val()+"&qmax="+$("#qmax-product-"+id).val()+"&localisation="+$("#localisation-product-"+id).val()+"&modalite="+$("#modalite-product-"+id).val()+"&modalite_autre="+$("#modalite_autre-product-"+id).val()+"&region="+$("#region-product-"+id).val(),
										  success: function(data) {
										  	if ($('#oneoffer_store').length != 0) {
										  		$('#oneoffer_store').val(1);
										  	}
										  	alert("Offre sauvegardee");
										  	$('#tabs_offers_products').tabs("select", parseInt(id));
										  	$("#modalite-product-"+(parseInt(id)+1)).val($("#modalite-product-"+id).val());
										  	$("#modalite_autre-product-"+(parseInt(id)+1)).val($("#modalite_autre-product-"+id).val());
										  }
								});
							});
					  }
					});
				}
		});
	}

	if ($('#tabs_offers_services').length != 0) {
		var $tabsservices = $('#tabs_offers_services').tabs({
				tabTemplate: '<li><a href="#{href}">#{label}</a></li>',
				add: function(event, ui) {
					tmpi = $(ui.panel).attr("id").replace("tabs_offers_services-", "");
					$.ajax({
					  url: '/registration/offerservice',
					  data: "tmpi="+tmpi+"&currenttype=service",
					  success: function(data) {
					  	$(ui.panel).append(data);
					  	$(ui.panel).find(".mdd_service_input").mcDropdown(
								"#service_type_menu",
								{
									screenPadding: 0,
									minRows: 16,
									allowParentSelect: true,
									delim: " > "
								}
							);
							$("#validate-service-"+tmpi).click ( function () {
								var id = $(this).attr("id").replace("validate-service-", "");
								$.ajax({
											type: "POST",
										  url: "/registration/saveoffer",
										  data: "category="+$("#category-service-"+id).val()+"&other_category="+$("#other_category-service-"+id).val()+"&description="+escape($("#description-service-"+id).val())+"&price_ht="+$("#price_ht-service-"+id).val()+"&decote="+$("#decote-service-"+id).val()+"&exchange_value="+$("#exchange_value-service-"+id).val()+"&unite="+$("#unite-service-"+id).val()+"&qmin="+$("#qmin-service-"+id).val()+"&qmax="+$("#qmax-service-"+id).val()+"&localisation="+$("#localisation-service-"+id).val()+"&modalite="+$("#modalite-service-"+id).val()+"&modalite_autre="+$("#modalite_autre-service-"+id).val()+"&region="+$("#region-service-"+id).val(),
										  success: function(data) {
										  	if ($('#oneoffer_store').length != 0) {
										  		$('#oneoffer_store').val(1);
										  	}
										  	alert("Offre sauvegardee");
										  	$('#tabs_offers_services').tabs("select", parseInt(id));
										  	$("#modalite-service-"+(parseInt(id)+1)).val($("#modalite-service-"+id).val());
										  	$("#modalite_autre-service-"+(parseInt(id)+1)).val($("#modalite_autre-service-"+id).val());
										  }
								});
							});
					  }
					});
				}
		});
	}

	if ($('#tabs_needs').length != 0) {
		var $tabsneeds = $('#tabs_needs').tabs({
				tabTemplate: '<li><a href="#{href}">#{label}</a></li>',
				add: function(event, ui) {
					tmpi = $(ui.panel).attr("id").replace("tabs_needs-", "");
					$.ajax({
					  url: '/registration/need',
					  data: "tmpi="+tmpi,
					  success: function(data) {
					  	$(ui.panel).append(data);
					  	$(ui.panel).find(".mdd_product_input").mcDropdown(
								"#product_type_menu",
								{
									screenPadding: 0,
									minRows: 16,
									allowParentSelect: true,
									delim: " > ",
									'select': function(e, f, g) { var id = g.parent().children("input:hidden").attr("id").replace("product_type_input_with_dropdown-", ""); $("#span_quantite-"+id).show(); $(".span_prix-"+id).show(); $(".span_periodicite-"+id).hide(); $(".span_periodicite_2-"+id).hide(); if ($("#currentaction").val() != 'step2lp1') { $("#span_unite-"+id).parent().hide(); $("#unite-"+id).parent().hide(); }}
								}
							);
							$(ui.panel).find(".mdd_service_input").mcDropdown(
								"#service_type_menu",
								{
									screenPadding: 0,
									minRows: 16,
									allowParentSelect: true,
									delim: " > ",
									'select': function(e, f, g) { var id = g.parent().children("input:hidden").attr("id").replace("service_type_input_with_dropdown-", ""); $("#span_quantite-"+id).hide(); $(".span_prix-"+id).hide(); $(".span_periodicite-"+id).show(); $(".span_periodicite_2-"+id).show(); if ($("#currentaction").val() != 'step2lp1') { $("#span_unite-"+id).parent().show(); $("#unite-"+id).parent().show(); }}
								}
							);
							$("#validate-"+tmpi).click ( function () {
								var id = $(this).attr("id").replace("validate-", "");
								$.ajax({
											type: "POST",
										  url: "/registration/saveneed",
										  data: "product_type="+$("#product_type_input_with_dropdown-"+id).val()+"&service_type="+$("#service_type_input_with_dropdown-"+id).val()+"&description="+escape($("#description-"+id).val())+"&prixmin="+$("#prixmin-"+id).val()+"&prixmax="+$("#prixmax-"+id).val()+"&quantite="+$("#quantite-"+id).val()+"&unite="+$("#unite-"+id).val()+"&type_besoin="+$("#need_type-"+id+":checked").val()+"&periodicite="+$("#periodicite-"+id).val()+"&urgence="+$('input[type=radio][name=urgence-'+id +']:checked').attr('value'),
										  success: function(data) {
										  	if ($('#oneneed_store').length != 0) {
										  		$('#oneneed_store').val(1);
										  	}
										  	alert("Besoin sauvegarde");
										  	$('#tabs_needs').tabs("select", parseInt(id));
										  }
								});
							});
					  }
					});
				}
		});
	}

	// C'est ici que �a se passe, on dirait :) 21/07/2011
	// Les d�j� pr�sents dasn la BDD.
	$(".form_offer_service").click ( function () {
		var id = $(this).attr("id").replace("validate-service-", "");
		$.ajax({
					type: "POST",
				  url: "/registration/saveoffer",
				  data: "category="+$("#category-service-"+id).val()+"&other_category="+$("#other_category-service-"+id).val()+"&description="+escape($("#description-service-"+id).val())+"&price_ht="+$("#price_ht-service-"+id).val()+"&decote="+$("#decote-service-"+id).val()+"&exchange_value="+$("#exchange_value-service-"+id).val()+"&unite="+$("#unite-service-"+id).val()+"&qmin="+$("#qmin-service-"+id).val()+"&qmax="+$("#qmax-service-"+id).val()+"&localisation="+$("#localisation-service-"+id).val()+"&modalite="+$("#modalite-service-"+id).val()+"&modalite_autre="+$("#modalite_autre-service-"+id).val()+"&region="+$("#region-service-"+id).val()+"&id_offre="+$("#tabs_services_id-"+id).val(),
				  success: function(data) {
				  	if ($('#oneoffer_store').length != 0) {
										  		$('#oneoffer_store').val(1);
										  	}
				  	alert("Offre sauvegardee");
				  	$('#tabs_offers_services').tabs("select", parseInt(id));
				  	$("#modalite-service-"+(parseInt(id)+1)).val($("#modalite-service-"+id).val());
						$("#modalite_autre-service-"+(parseInt(id)+1)).val($("#modalite_autre-service-"+id).val());
				  }
		});
	});

	$(".form_offer_del_service").click ( function () {
		var id = $(this).attr("name").replace("delete-service-", "");
		// alert(id); // Identifiant de l'offre dans BDD
		if (confirm('Voulez-vous vraiment supprimer cette offre ?')) {
			$.ajax({
						type: "POST",
					  url: "/registration/deleteoffer",
					  data: "idoffer="+id,
					  success: function(data) {
					  	alert("Offre supprimee.");
					  	$(location).attr("href", "/registration/modifyoffer");
					  }
			});
		}
	});

	$(".form_offer_product").click ( function () {
		var id = $(this).attr("id").replace("validate-product-", "");
		$.ajax({
					type: "POST",
				  url: "/registration/saveoffer",
				  data: "category="+$("#category-product-"+id).val()+"&other_category="+$("#other_category-product-"+id).val()+"&description="+escape($("#description-product-"+id).val())+"&price_ht="+$("#price_ht-product-"+id).val()+"&decote="+$("#decote-product-"+id).val()+"&exchange_value="+$("#exchange_value-product-"+id).val()+"&unite="+$("#unite-product-"+id).val()+"&qmin="+$("#qmin-product-"+id).val()+"&qmax="+$("#qmax-product-"+id).val()+"&localisation="+$("#localisation-product-"+id).val()+"&modalite="+$("#modalite-product-"+id).val()+"&modalite_autre="+$("#modalite_autre-product-"+id).val()+"&region="+$("#region-product-"+id).val()+"&id_offre="+$("#tabs_products_id-"+id).val(),
				  success: function(data) {
				  	if ($('#oneoffer_store').length != 0) {
										  		$('#oneoffer_store').val(1);
										  	}
				  	alert("Offre sauvegardee");
				  	$('#tabs_offers_products').tabs("select", parseInt(id));
				  	$("#modalite-product-"+(parseInt(id)+1)).val($("#modalite-product-"+id).val());
						$("#modalite_autre-product-"+(parseInt(id)+1)).val($("#modalite_autre-product-"+id).val());
				  }
		});
	});
	
	$(".form_offer_del_product").click ( function () {
		var id = $(this).attr("name").replace("delete-product-", "");
		// alert(id); // Identifiant de l'offre dans BDD
		if (confirm('Voulez-vous vraiment supprimer cette offre ?')) {
			$.ajax({
						type: "POST",
					  url: "/registration/deleteoffer",
					  data: "idoffer="+id,
					  success: function(data) {
					  	alert("Offre supprimee.");
					  	$(location).attr("href", "/registration/modifyoffer");
					  }
			});
		}
	});	

	$(".form_need").click ( function () {
		
		var id = $(this).attr("id").replace("validate-", "");
		
		$.ajax({
					type: "POST",
				  url: "/registration/saveneed",
				  data: "product_type="+$("#product_type_input_with_dropdown-"+id).val()+"&service_type="+$("#service_type_input_with_dropdown-"+id).val()+"&description="+escape($("#description-"+id).val())+"&prixmin="+$("#prixmin-"+id).val()+"&prixmax="+$("#prixmax-"+id).val()+"&quantite="+$("#quantite-"+id).val()+"&unite="+$("#unite-"+id).val()+"&type_besoin="+$("#need_type-"+id+":checked").val()+"&id_besoin="+$("#tabs_needs_id-"+id).val()+"&periodicite="+$("#periodicite-"+id).val()+"&urgence="+$('input[type=radio][name=urgence-'+id +']:checked').attr('value'),
				  success: function(data) {
				  	if ($('#oneneed_store').length != 0) {
										  		$('#oneneed_store').val(1);
										  	}
				  	alert("Besoin sauvegarde");
				  	$('#tabs_needs').tabs("select", parseInt(id));
				  }
		});
	});

	$(".form_need_del").click ( function () {
		var id = $(this).attr("name").replace("delete-", "");
		// alert(id); // Identifiant de l'offre dans BDD
		if (confirm('Voulez-vous vraiment supprimer ce besoin ?')) {
			$.ajax({
						type: "POST",
					  url: "/registration/deleteneed",
					  data: "idneed="+id,
					  success: function(data) {
					  	alert("Besoin supprime.");
					  	$(location).attr("href", "/registration/modifyneed");
					  }
			});
		}
	});

	$("#show_services").click ( function () {
		$('#tabs_offers_services').show();
		$('#tabs_offers_services_asterisque').show();
		$('.service_div').show();
	});

	$("#show_products").click ( function () {
		$('#tabs_offers_products').show();
		$('#tabs_offers_products_asterisque').show();
		$('.product_div').show();
	});

	if ($('.mdd_product_input').length != 0) {
	$(".mdd_product_input").mcDropdown(
										"#product_type_menu",
										{
											screenPadding: 0,
											minRows: 16,
											allowParentSelect: true,
											delim: " > ",
											'select': function(e, f, g)
													  {
											
															var id = g.parent().children("input:hidden").attr("id").replace("category-product-", "");
															$("#span_quantite-"+id).show();
															$(".span_prix-"+id).show();
															$(".span_periodicite-"+id).hide();
															$(".span_periodicite_2-"+id).hide();
															if ($("#currentaction").val() != 'step2lp1')
															{
																$("#span_unite-"+id).parent().hide();
																$("#unite-"+id).parent().hide();
																var to_display = f.substring(f.lastIndexOf('>')+1, 100);
																if (to_display.length > 36) {
																	to_display = to_display.substring(1, 36)+"...";
																}
																$("#name-product-"+id.replace("category-product-", "")).html(to_display);
															}
														}
										}
	);
	}

	if ($('.mdd_service_input').length != 0) {
	$(".mdd_service_input").mcDropdown(
										"#service_type_menu",
										{
											screenPadding: 0,
											minRows: 16,
											allowParentSelect: true,
											delim: " > ",
											'select': function(e, f, g)
														{
															var id = g.parent().children("input:hidden").attr("id").replace("category-service-", "");
															$("#span_quantite-"+id).hide();
															$(".span_prix-"+id).hide();
															$(".span_periodicite-"+id).show();
															$(".span_periodicite_2-"+id).show();
															if ($("#currentaction").val() != 'step2lp1')
															{
																$("#span_unite-"+id).parent().show();
																$("#unite-"+id).parent().show();
																var to_display = f.substring(f.lastIndexOf('>')+1, 100);
																if (to_display.length > 36) {
																	to_display = to_display.substring(1, 36)+"...";
																}
																$("#name-service-"+id.replace("category-service-")).html(to_display);
															}
														}
										}
	);
	}

	$("input[name=line_of_business]").click( function () {
		if ($(this).val() == 1)	{
			$("#category_product").parent().parent().css("display", "block");
			$("input[rel=theinput_product]").width("250px");
			$("#category_service").parent().parent().css("display", "none");
			$("#category_both").parent().parent().css("display", "none");
		}
		else if ($(this).val() == 2) {
			$("#category_product").parent().parent().css("display", "none");
			$("#category_service").parent().parent().css("display", "block");
			$("input[rel=theinput_service]").width("250px");
			$("#category_both").parent().parent().css("display", "none");
		}
		else {
			$("#category_product").parent().parent().css("display", "none");
			$("#category_service").parent().parent().css("display", "none");
			$("#category_both").parent().parent().css("display", "block");
			$("input[rel=theinput_both]").width("250px");
		}
	});

/*
	$("input[name=line_of_business_md]").click( function () {
		if ($(this).val() == 1)
		{
			document.getElementById('cat_secteur_num_1').className = "plus_disparu"; 
			document.getElementById('cat_secteur_num_2').className = "disparu"; 
			document.getElementById('cat_secteur_num_1_et_2').className = "disparu";
		}
		else if ($(this).val() == 2)
		{
			document.getElementById('cat_secteur_num_1').className = "disparu"; 
			document.getElementById('cat_secteur_num_2').className = "plus_disparu"; 
			document.getElementById('cat_secteur_num_1_et_2').className = "disparu"; 
		}
		else
		{
			document.getElementById('cat_secteur_num_1').className = "disparu"; 
			document.getElementById('cat_secteur_num_2').className = "disparu"; 
			document.getElementById('cat_secteur_num_1_et_2').className = "plus_disparu"; 
		}
	});
*/
	if ($('#category_product').length != 0) {
	$("#category_product").mcDropdown(
														"#product_type_menu",
														{
															screenPadding: 0,
															minRows: 16,
															allowParentSelect: true,
															delim: " > "
														}
	);
	}

	if ($('#category_service').length != 0) {
	$("#category_service").mcDropdown(
														"#service_type_menu",
														{
															screenPadding: 0,
															minRows: 16,
															allowParentSelect: true,
															delim: " > "
														}
	).parent().parent().css("display", "none");
	}

	if ($('#category_both').length != 0) {
	$("#category_both").mcDropdown(
														"#both_type_menu",
														{
															screenPadding: 0,
															minRows: 16,
															allowParentSelect: true,
															delim: " > "
														}
	).parent().parent().css("display", "none");
	}

	if ($('#ape_select').length != 0) {
		$("#ape_select").mcDropdown(
															"#liste_ape",
															{
																screenPadding: 0,
																minRows: 30,
																allowParentSelect: false,
																delim: " > ",
																autoHeight: true,
																'select': function() { $("#ape_input").val($("#ape_select").val());}
															}
		);
	}

	if ($('.modify_needs').length != 0) {
		var $tabsmodifyneeds = $('.modify_needs').tabs();
	}

	if ($('.modify_offers').length != 0) {
		var $tabsmodifyoffers = $('.modify_offers').tabs();
	}

	$("a.btn_add_modifyneed").click( function() { abtn_add_modifyneed() });

	$("a.btn_add_modifyservice").click( function () { abtn_add_modifyservice() } );

	$("a.btn_add_modifyproduct").click( function() { abtn_add_modify_product(); } );

	$("#zipcode").change ( function () {
		if ($(this).val().length == 5)
		{
			$.ajax({
						type: "POST",
					  url: "/registration/getcityfromzip",
					  data: "zip="+$(this).val(),
					  success: function(data) {
					  	$("#city").val(data);
					  }
			});
		}
	});

	$("#cgvno").click ( function () {
		$("#cgv_not_accepted").dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				'Oui': function() {
					$("#cgv").val("no");
					$("#cgvform").submit();
				},
				'Non': function() {
					$(this).dialog('close');
				}
			}
		});
	});
	$("#cgvyes").click ( function () {
		if ($("#oneoffer_store").val() > 0)
		{
			if ($("#oneneed_store").val() > 0)
			{
				$("#cgv").val("yes");
				welcomemodal();
				$("#cgvform").submit();
			}
			else
			{
				$("#no_need_entered").dialog({
					resizable: false,
					height:140,
					modal: true,
					buttons: {
						'Rentrer un besoin d\350s maintenant': function() {
							$(this).dialog('close');
						},
						'Renseigner un besoin dans les 45 jours': function() {
							$("#cgv").val("yes");
							$("#submit_without_need").val("45days");
							$(this).dialog('close');
							welcomemodal();
							$("#cgvform").submit();
						},
						'Etre appel\351 par un broker dans les 10 jours pour d\351finir vos besoins': function() {
							$("#cgv").val("yes");
							$("#submit_without_need").val("10days");
							$(this).dialog('close');
							welcomemodal();
							$("#cgvform").submit();
						}
					}
				});
			}
		}
		else
			alert("Desole, vous devez renseigner au moins une Offre pour acceder a la Bourse aux Echanges");
	});

	$("#faq_send_mail").click (function () {
		$.ajax({
					type: "POST",
				  url: "/index/sendmail",
				  data: "email="+$("#email").val()+"&body="+$("#body").val(),
				  success: function(data) {
				  	alert("Question envoyee");
				  	$("#email").val("");
				  	$("#body").val("");
				  	$.fn.colorbox.close();
				  }
		});
	});

	$("#index_avantage").click ( function () {
		$("#market_right").hide();
		$("#market_right_avantage").show();
	});

	$("#close_avantage_link").click ( function () {
		$("#market_right").show();
		$("#market_right_avantage").hide();
	});

	function EstSirenValide() {
		siren = $("#siren").val().replace(/ /g, "");
    var estValide;
    if ( (siren.length != 9) || (isNaN(siren)) )
      return false;
    else
    	return true;
  }

  $("select[name*=unite-]").change( function() {
  	var id = $(this).attr("id").replace("unite-", "");
  	if ($(this).val() == "1")
		{
			$("#quantite-"+id).val("1");
			$(".span_periodicite-"+id).hide();
			$(".span_periodicite_2-"+id).hide();
		}
		else
		{
			$("#periodicite-"+id).val($(this).val()-1);
			$(".span_periodicite_2-"+id).text($("#periodicite-"+id+" :selected").text());
			$(".span_periodicite-"+id).show();
			$(".span_periodicite_2-"+id).show();
		}
	});

	$("select[name*=periodicite-]").change( function() {
  	var id = $(this).attr("id").replace("periodicite-", "");
		$(".span_periodicite_2-"+id).text($("#"+$(this).attr("id")+" :selected").text());
	});

	$('#contactLink').click(function()
	{
		$("#contactFormClicked").val(1);
	    if ($('#contactForm').is(':hidden'))
	    {
	    	$("#contactFormContainer").css("z-index", 10000);
	    	$("#contactForm").animate({width:'toggle'});
	    }
	    else
	    {
	    	$("#contactFormContainer").css("z-index", 0);
	       $("#contactForm").animate({width:'toggle'});
	    }
	});

  $(window).scroll(function(){ // On ajoute une fonction quand on d�file dans le site

		// On r�cup�re la position de la barre de d�filement par rapport � notre fen�tre
		var scrollTop = $(window).scrollTop();
    if ($.browser.msie && $.browser.version == "8.0")
    	var scrollTop = $("html").scrollTop();
		// On r�cup�re notre �l�ment
		var div = $('#contactFormContainer');

		div.css("top", 200+scrollTop);
	});

	$("#se_desinscrire").click ( function () {
		if (confirm('Voulez-vous vraiment vous desinscrire ?')) {
			$.ajax({
						type: "POST",
					  url: "/registration/inactive",
					  data: "",
					  success: function(data) {
					  	alert("Vous etes desinscrits de la Bourse aux Echanges.");
					  	$(location).attr("href", "/index/logout");					  	
					  }
			});
		}
	});

	setTimeout('assistance()', 14000);
	setTimeout('assistance()', 18000);
	
	if($('#cgvform').length != 0) {
		$('.del_red_x_mark').next().remove();
		$('.del_red_x_mark').remove();
	}	
	
});

function closeForm()
{
	$.ajax({
				type: "POST",
			  url: "/index/sendmail",
			  data: "email="+$("#contact_email").val()+"&body=Rappeler client telephone: "+$("#contact_telephone").val()+"&dest=samuel.cohen@b2b-en-trade.com"
	});
  $('#messageSent').show('slow');
  setTimeout('$("#messageSent").hide(); $("#contactFormContainer").css("z-index", 0); $("#contactForm").animate({width:"toggle"})', 2000);
}

function assistance()
{
	if ($("#contactFormClicked").val() == 0)
	{
		if ($('#contactForm').is(':hidden'))
	    {
	    	$("#contactFormContainer").css("z-index", 10000);
	    	$("#contactForm").animate({width:'toggle'});
	    }
	    else
	    {
	    	$("#contactFormContainer").css("z-index", 0);
	       $("#contactForm").animate({width:'toggle'});
	    }
	}
}

function abtn_add_modifyneed () {
	tmpi = $(".modify_needs").length + 1;
	$.ajax({
	  url: '/registration/getnewneed',
	  data: "tmpi="+tmpi,
	  success: function(data) {
	  	$("#registration").append(data);
	  	$("#product_type_input_with_dropdown-"+tmpi).mcDropdown(
				"#product_type_menu",
				{
					screenPadding: 0,
					minRows: 16,
					allowParentSelect: true,
					delim: " > ",
					'select': function(e, f, g) { var id = g.parent().children("input:hidden").attr("id").replace("product_type_input_with_dropdown-", ""); $("#span_quantite-"+id).show(); $(".span_prix-"+id).show(); $(".span_periodicite-"+id).hide(); $(".span_periodicite_2-"+id).hide(); if ($("#currentaction").val() != 'step2lp1') { $("#span_unite-"+id).parent().hide(); $("#unite-"+id).parent().hide(); }}
				}
			);
			$("#service_type_input_with_dropdown-"+tmpi).mcDropdown(
				"#service_type_menu",
				{
					screenPadding: 0,
					minRows: 16,
					allowParentSelect: true,
					delim: " > ",
					'select': function(e, f, g) { var id = g.parent().children("input:hidden").attr("id").replace("service_type_input_with_dropdown-", ""); $("#span_quantite-"+id).hide(); $(".span_prix-"+id).hide(); $(".span_periodicite-"+id).show(); $(".span_periodicite_2-"+id).show(); if ($("#currentaction").val() != 'step2lp1') { $("#span_unite-"+id).parent().show(); $("#unite-"+id).parent().show(); }}
				}
			);
			$("#validate-"+tmpi).click ( function () {
				var id = $(this).attr("id").replace("validate-", "");
				$.ajax({
							type: "POST",
						  url: "/registration/saveneed",
						  data: "product_type="+$("#product_type_input_with_dropdown-"+id).val()+"&service_type="+$("#service_type_input_with_dropdown-"+id).val()+"&description="+escape($("#description-"+id).val())+"&prixmin="+$("#prixmin-"+id).val()+"&prixmax="+$("#prixmax-"+id).val()+"&quantite="+$("#quantite-"+id).val()+"&unite="+$("#unite-"+id).val()+"&type_besoin="+$("#need_type-"+id+":checked").val()+"&periodicite="+$("#periodicite-"+id).val()+"&urgence="+$('input[type=radio][name=urgence-'+id +']:checked').attr('value'),
						  success: function(data) {
						  	if ($('#oneneed_store').length != 0) {
									  		$('#oneneed_store').val(1);
									  	}
						  	alert("Besoin sauvegarde");
						  	//window.location.href = window.location.href.replace("#", "")
						  }
				});
			});
			$("#btn_add_modifyneed-"+tmpi).click( function() { abtn_add_modifyneed() });
			$("#tabs_needs_container-new"+tmpi).tabs();
			$("#tabs_needs_container-new"+tmpi).css("border", "0px");
			$("#tabs_needs_container-new"+tmpi+".ui-tabs .ui-tabs-nav li a").css("text-decoration", "none").css("font-weight", "bold").css("color", "#000000");
			$("#tabs_needs_container-new"+tmpi+".ui-tabs .ui-tabs-nav li").css("border-bottom", "0px");
		}
	});
	window.location.href = '/registration/modifyneed#modifyneed_add_need';
}

function abtn_add_modify_product () {
	tmpi = $(".modify_offers").length + 1;
	$.ajax({
	  url: '/registration/getnewoffer',
	  data: "tmpi="+tmpi+"&currtype=product",
	  success: function(data) {
	  	$("#registration").append(data);
	  	$("#product_type_input_with_dropdown-"+tmpi).mcDropdown(
				"#product_type_menu",
				{
					screenPadding: 0,
					minRows: 16,
					allowParentSelect: true,
					delim: " > ",
					'select': function(e, f, g)
								{
									var id = g.parent().children("input:hidden").attr("id").replace("product_type_input_with_dropdown-", "").replace("category-product-", "");
									$("#span_quantite-"+id).show();
									$(".span_prix-"+id).show();
									$(".span_periodicite-"+id).hide();
									$(".span_periodicite_2-"+id).hide();
									if ($("#currentaction").val() != 'step2lp1')
									{
										$("#span_unite-"+id).parent().hide();
										$("#unite-"+id).parent().hide();
										var to_display = f.substring(f.lastIndexOf('>')+1, 100);
										if (to_display.length > 36) {
											to_display = to_display.substring(1, 36)+"...";
										}
										$("#name-product-"+id.replace("category-product-", "")).html(to_display);
									}
								}
				}
			);
			$("#validate-product-"+tmpi).click ( function () {
				var id = $(this).attr("id").replace("validate-product-", "");
				$.ajax({
							type: "POST",
						  url: "/registration/saveoffer",
						  data: "category="+$("#product_type_input_with_dropdown-"+id).val()+"&other_category="+$("#other_category-product-"+id).val()+"&description="+escape($("#description-product-"+id).val())+"&price_ht="+$("#price_ht-product-"+id).val()+"&decote="+$("#decote-product-"+id).val()+"&exchange_value="+$("#exchange_value-product-"+id).val()+"&unite="+$("#unite-product-"+id).val()+"&qmin="+$("#qmin-product-"+id).val()+"&qmax="+$("#qmax-product-"+id).val()+"&localisation="+$("#localisation-product-"+id).val()+"&modalite="+$("#modalite-product-"+id).val()+"&modalite_autre="+$("#modalite_autre-product-"+id).val()+"&region="+$("#region-product-"+id).val(),
						  success: function(data) {
						  	if ($('#oneoffer_store').length != 0) {
									  		$('#oneoffer_store').val(1);
									  	}
						  	alert("Offre sauvegardee");
						  	window.location.href = window.location.href.replace("#", "")
						  }
				});
			});
			$("#btn_add_modifyproduct-"+tmpi).attr("href", "#footer");
			$("#btn_add_modifyproduct-"+tmpi).click( function() { abtn_add_modify_product() });
			$("#btn_add_modifyservice-"+tmpi).click( function() { abtn_add_modify_service() });
			$("#tabs_product_container-new"+tmpi).tabs();
			$("#tabs_product_container-new"+tmpi).css("border", "0px");
			$("#tabs_product_container-new"+tmpi+".ui-tabs .ui-tabs-nav li a").css("text-decoration", "none").css("font-weight", "bold").css("color", "#000000");
			$("#tabs_product_container-new"+tmpi+".ui-tabs .ui-tabs-nav li").css("border-bottom", "0px");
		}
	});
}

function abtn_add_modifyservice () {
	tmpi = $(".modify_offers").length + 1;
	$.ajax({
	  url: '/registration/getnewoffer',
	  data: "tmpi="+tmpi+"&currtype=service",
	  success: function(data) {
	  	$("#registration").append(data);
	  	$("#service_type_input_with_dropdown-"+tmpi).mcDropdown(
				"#service_type_menu",
				{
					screenPadding: 0,
					minRows: 16,
					allowParentSelect: true,
					delim: " > ",
					'select': function(e, f, g)
								{
									var id = g.parent().children("input:hidden").attr("id").replace("category-service-", "").replace("service_type_input_with_dropdown-", "");
									$("#span_quantite-"+id).hide();
									$(".span_prix-"+id).hide();
									$(".span_periodicite-"+id).show();
									$(".span_periodicite_2-"+id).show();
									if ($("#currentaction").val() != 'step2lp1')
									{
										$("#span_unite-"+id).parent().show();
										$("#unite-"+id).parent().show();
										var to_display = f.substring(f.lastIndexOf('>')+1, 100);
										if (to_display.length > 36) {
											to_display = to_display.substring(1, 36)+"...";
										}
										$("#name-service-"+id.replace("category-service-")).html(to_display);
									}
								}
				}
			);
			$("#validate-service-"+tmpi).click ( function () {
				var id = $(this).attr("id").replace("validate-service-", "");
				$.ajax({
							type: "POST",
						  url: "/registration/saveoffer",
						  data: "category="+$("#service_type_input_with_dropdown-"+id).val()+"&other_category="+$("#other_category-service-"+id).val()+"&description="+escape($("#description-service-"+id).val())+"&price_ht="+$("#price_ht-service-"+id).val()+"&decote="+$("#decote-service-"+id).val()+"&exchange_value="+$("#exchange_value-service-"+id).val()+"&unite="+$("#unite-service-"+id).val()+"&qmin="+$("#qmin-service-"+id).val()+"&qmax="+$("#qmax-service-"+id).val()+"&localisation="+$("#localisation-service-"+id).val()+"&modalite="+$("#modalite-service-"+id).val()+"&modalite_autre="+$("#modalite_autre-service-"+id).val()+"&region="+$("#region-service-"+id).val(),
						  success: function(data) {
						  	if ($('#oneoffer_store').length != 0) {
									  		$('#oneoffer_store').val(1);
									  	}
						  	alert("Offre sauvegardee");
						  	window.location.href = window.location.href.replace("#", "")
						  }
				});
			});
			$("#btn_add_modifyservice-"+tmpi).attr("href", "#footer");
			$("#btn_add_modifyservice-"+tmpi).click( function() { abtn_add_modifyservice() });
			$("#btn_add_modifyproduct-"+tmpi).click( function() { abtn_add_modify_product() });
			$("#tabs_service_container-new"+tmpi).tabs();
			$("#tabs_service_container-new"+tmpi).css("border", "0px");
			$("#tabs_service_container-new"+tmpi+".ui-tabs .ui-tabs-nav li a").css("text-decoration", "none").css("font-weight", "bold").css("color", "#000000");
			$("#tabs_service_container-new"+tmpi+".ui-tabs .ui-tabs-nav li").css("border-bottom", "0px");
		}
	});
		
}

function welcomemodal() {
	$("#modal_welcome").dialog({
		modal: true,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
}

function resend_password() {

	$.ajax({
				type: "POST",
			  url: "/registration/resendpassword",
			  data: "email="+$("#forgotten_password_mail").val()
	});
  $('#passwordSent').show('slow');
}


