//Position horizontale popin
function getInitPosition(largeur_popin){
		var posx = ( window.document.body.offsetWidth - largeur_popin) / 2;
		return posx+'px';
}
//Combo dynamique : action onchange
function actionOnchangeCountry(form,label,label2,tab){
	form.citiespropvalue.options.length=0;
	var o = new Option(label, '');
    form.citiespropvalue.options[form.citiespropvalue.options.length] = o;
    if(label2!=null){
	    form.centerspropvalue.options.length=0;
		var o = new Option(label2, '');
	    form.centerspropvalue.options[form.centerspropvalue.options.length] = o;
    }

	var selectedvalue = '';
	if(form.countriespropvalue.selectedIndex!=null && form.countriespropvalue.selectedIndex>0){
		selectedvalue = form.countriespropvalue.options[form.countriespropvalue.selectedIndex].value;
	}

	var tab2 = tab.split('][');
	var lignes = new Array();
	for(j=0; j< tab2.length; j++){
		var tab3 = tab2[j].replace('[','').replace(']','').split(',');
		var ligne = new Array();
		for(k=0; k< tab3.length; k++){
			ligne.push(tab3[k]);
		}
		lignes.push(ligne);
	}

	for(i=0; i<lignes.length; i++){
		var ligne = lignes[i];
		if(ligne[0]==selectedvalue){
			var o = new Option(ligne[2],ligne[1]);
    		form.citiespropvalue.options[form.citiespropvalue.options.length] = o;
		}
	}
}
function actionOnchangeCity(form,label,tab){
	form.centerspropvalue.options.length=0;
	var o = new Option(label, '');
    form.centerspropvalue.options[form.centerspropvalue.options.length] = o;


	var selectedvalue = '';
	if(form.citiespropvalue.selectedIndex>0){
		selectedvalue = form.citiespropvalue.options[form.citiespropvalue.selectedIndex].value;
	}

	var tab2 = tab.split('][');
	var lignes = new Array();
	for(j=0; j< tab2.length; j++){
		var tab3 = tab2[j].replace('[','').replace(']','').split(',');
		var ligne = new Array();
		for(k=0; k< tab3.length; k++){
			ligne.push(tab3[k]);
		}
		lignes.push(ligne);
	}

	for(i=0; i<lignes.length; i++){
		var ligne = lignes[i];
		if(ligne[0]==selectedvalue){
			var o = new Option(ligne[2],ligne[1]);
    		form.centerspropvalue.options[form.centerspropvalue.options.length] = o;
		}
	}
}
// fonction pour le champ capacité du form de rech cp
function cursorValue(toto){
    if(window.document.getElementById("formfield_capacity")!=null){
    	//alert('value = ' + toto);
    	var field = window.document.getElementById("formfield_capacity");
    	field.value = toto;
    	//alert(field.value);
    }else{
    	//alert('formfield_capacity non trouvé');
    }
}

//function pour les valeurs locatives
function showMe(display, id, secteurs){
    if(display){
    	try{
	       	var table = document.getElementById('TVL');
	       	var rowCount = table.rows.length;
	       	var row = table.insertRow(rowCount);
	       	row.id = 'TVL_' + id;
	       	i = 0;
	       	for(i = 0 ; i < 6 ; i++){
	          	var cell1 = row.insertCell(i);
	          	cell1.innerHTML = secteurs[id][i];
	       	}
	       	var cell1 = row.insertCell(i);
	       	cell1.innerHTML = '<div class="case lastcase"><a href="javascript:showMe(false, ' + id + ')" class="rental_value_delete"></a></div>';
	    	rowCount = table.rows.length;
	    	if(rowCount > 1){
	    		table.className = 'rental_values_list_wrapper tableshow';
	    	}else{
	    		table.className = 'rental_values_list_wrapper tablehide';
	    	}
    	}catch(e) {
            alert(e);
        }
    } else {
        try {
       		var table = document.getElementById('TVL');
            var rowCount = table.rows.length;
            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                if(row.id == 'TVL_' + id){
                  table.deleteRow(i);
                  rowCount--;
                  i--;
                }
             }
             var inputs = document.getElementsByName('city');
             for(var i=0; i<inputs.length; i++) {
                var input = inputs[i];
                if(input.value == id){
                  input.checked=false;
                }
             }
             rowCount = table.rows.length;
             if(rowCount > 1){
    			table.className = 'rental_values_list_wrapper tableshow';
    		 }else{
    			table.className = 'rental_values_list_wrapper tablehide';
    		 }
        }catch(e) {
            alert(e);
        }
    }
}



$(function(){
	//Roll Over sur le Menu 1 (header)
	//---------------------------------------------
	if($("#header_center .commons_navmenu .level1 li").length>0){
		$("#header_center .commons_navmenu .level1 li").each(function(){
			$(this).hover(
				function(){
					$(this).addClass("hover");
					// open submenu
				},
				function(){
					$(this).removeClass("hover");
					// close submenu
				}
			);
		});
	}
	$last_level1 = $("#header_center .commons_navmenu .level1 li.last ul.level2");
	$last_level1.css('margin-left', ($last_level1.parent().width()-142));
	$("#header_center .commons_navmenu .level1 li ul.level2").each(function() {
		$(this).find("li:last").css('background-image', 'none');
		$(this).find("li:last").css('border-bottom', '1px solid #525355');
	});

	//Roll Over sur les liens .link .linkedpage
	//---------------------------------------------
	if($(".link a").length>0){
		$(".link a").each(function(){
			$(this).hover(
				function(){
					$(this).addClass("hover");
				},
				function(){
					$(this).removeClass("hover");
				}
			);
		});
	}
	if($(".linkedpage a").length>0){
		$(".linkedpage a").each(function(){
			$(this).hover(
				function(){
					$(this).addClass("hover");
				},
				function(){
					$(this).removeClass("hover");
				}
			);
		});
	}

	//Popin Envoyer a un ami
	//---------------------------------------------
	if($(".send").length>0 && $("#popin_send").length>0){
		var x = getInitPosition($("#popin_send").width());
		$("#popin_send").attr("style",$("#popin_send").attr("style")+" left:"+x + ";");
	}
	/*if($(".send").length>0){
		$(".send").each(function(){
			var href = $(this).attr("href");
			//alert(href);
			$(this).attr("href","#");
			$(this).click(function(){
				if($("#popin_send").length>0){
					$("#popin_send").show();
				}
			});
		});			//TODO : non termine
	}*/
	if($("#popin_send").length>0){
		$("#popin_send").each(function(){
			var popin = $(this);
			var case_buttons = $(this).children().children().children().children("#popin_send_wrapper_content").children().children().children().children(".line_submit_buttons").children();
			var close = case_buttons.children(".closebutton");
			close.click(function(){
				popin.hide();
				return false;
			});
		});
	}


	//Popin PicturePopinViewer
	//---------------------------------------------
	if($(".picpopinviewer_popin").length>0){
		var x = getInitPosition($(".picpopinviewer_popin").width());
		$(".picpopinviewer_popin").attr("style","left:"+x);
	}
	if($(".model_picpopinviewer").length>0){
		$(".model_picpopinviewer").each(function(){
			var popin = $(this).children(".picpopinviewer_popin");
			var galery = $(this).children(".picpopinviewer_imagesgallery");
			var max = galery.children().children().children(".thb").size();
			var btns = popin.children().children().children().children().children(".picpopinviewer_popin_btns");
			btns.children(".link").children("a").css("cursor","pointer");
			btns.children(".link").children("a").click(function(){
				popin.hide();
			});
			var previous = btns.children(".navform").children(".previousbutton");
			var next = btns.children(".navform").children(".nextbutton");
			previous.click(function(){
				var current = -1;
				popin.children().children().children().children().children(".pic").each(function(k){
					if($(this).css("display")=='block'){
						current = k;
					}
				});
				popin.children().children().children().children().children(".pic_"+(current-1)).show();
				popin.children().children().children().children().children(".pic_"+current).hide();
				if(current=='1'){
					previous.hide();
				}else{
					previous.show();
				}
				if(current==parseInt(max-2)){
					next.hide();
				}else{
					next.show();
				}
			});
			next.click(function(){
				var current = -1;
				popin.children().children().children().children().children(".pic").each(function(j){
					if($(this).css("display")=='block'){
						current = j;
					}
				});
				popin.children().children().children().children().children(".pic_"+(current+1)).show();
				popin.children().children().children().children().children(".pic_"+current).hide();
				if(current=='1'){
					previous.hide();
				}else{
					previous.show();
				}
				if(current==parseInt(max-2)){
					next.hide();
				}else{
					next.show();
				}
			});
			galery.children().children().children(".thb").each(function(i){
				$(this).css("cursor","pointer");
				$(this).click(function(){
					popin.toggle();
					popin.children().children().children().children().children(".pic").hide();
					popin.children().children().children().children().children(".pic_"+i).show();
					if(i==0){
						previous.hide();
					}else{
						previous.show();
					}
					if(i==(max-1)){
						next.hide();
					}else{
						next.show();
					}
				});
			});
		});
	}

	//News : visionneur a onglets
	//---------------------------------------------
	if($(".list_news_tabs").length>0){
		$(".list_news_tabs").each(function(){
			$(this).children().children(".list_news_tabs_tabs").show();
			$(this).children().children(".list_news_tabs_tabs").children(".list_news_tabs_tab_1").addClass("selected");
			$(this).children().children(".list_news_tabs_items").children(".list_news_tabs_item_2").hide();
			$(this).children().children(".list_news_tabs_items").children(".list_news_tabs_item_3").hide();
			$(this).children().children(".list_news_tabs_tabs").children(".formbutton").each(function(){
				$(this).hover(
					function(){
						$(this).addClass("hover");
					},
					function(){
						$(this).removeClass("hover");
					}
				);
				$(this).click(function(){
					$(this).parent(".list_news_tabs_tabs").children(".list_news_tabs_tab_1").removeClass("selected");
					$(this).parent(".list_news_tabs_tabs").children(".list_news_tabs_tab_2").removeClass("selected");
					$(this).parent(".list_news_tabs_tabs").children(".list_news_tabs_tab_3").removeClass("selected");
					$(this).addClass("selected");
				});
			});
			$(this).children().children(".list_news_tabs_tabs").children(".list_news_tabs_tab_1").each(function(){
				$(this).click(function(){
					$(this).parent().next(".list_news_tabs_items").children(".list_news_tabs_item_1").show();
					$(this).parent().next(".list_news_tabs_items").children(".list_news_tabs_item_2").hide();
					$(this).parent().next(".list_news_tabs_items").children(".list_news_tabs_item_3").hide();
				});
			});
			$(this).children().children(".list_news_tabs_tabs").children(".list_news_tabs_tab_2").each(function(){
				$(this).click(function(){
					$(this).parent().next(".list_news_tabs_items").children(".list_news_tabs_item_1").hide();
					$(this).parent().next(".list_news_tabs_items").children(".list_news_tabs_item_2").show();
					$(this).parent().next(".list_news_tabs_items").children(".list_news_tabs_item_3").hide();
				});
			});
			$(this).children().children(".list_news_tabs_tabs").children(".list_news_tabs_tab_3").each(function(){
				$(this).click(function(){
					$(this).parent().next(".list_news_tabs_items").children(".list_news_tabs_item_1").hide();
					$(this).parent().next(".list_news_tabs_items").children(".list_news_tabs_item_2").hide();
					$(this).parent().next(".list_news_tabs_items").children(".list_news_tabs_item_3").show();
				});
			});
			var timeIncr = 1;
			var nb = $(this).children().children(".list_news_tabs_tabs").children().length;
			$(this).everyTime(3000, function(i) {
			  	//alert('timer ! ' + i);
			  	$(this).children().children(".list_news_tabs_tabs").children(".list_news_tabs_tab_1").removeClass("selected");
				$(this).children().children(".list_news_tabs_tabs").children(".list_news_tabs_tab_2").removeClass("selected");
				$(this).children().children(".list_news_tabs_tabs").children(".list_news_tabs_tab_3").removeClass("selected");
				$(this).children().children(".list_news_tabs_tabs").children(".list_news_tabs_tab_"+timeIncr).addClass("selected");

			  	$(this).children().children(".list_news_tabs_items").children(".list_news_tabs_item_1").hide();
			  	$(this).children().children(".list_news_tabs_items").children(".list_news_tabs_item_2").hide();
			  	$(this).children().children(".list_news_tabs_items").children(".list_news_tabs_item_3").hide();
			  	//alert('i = ' + i + ' et timeIncr = ' + timeIncr);
			  	$(this).children().children(".list_news_tabs_items").children(".list_news_tabs_item_"+timeIncr).show();
			  	timeIncr = timeIncr + 1;
			  	if(timeIncr == nb +1 ){
			  		timeIncr = 1;
			  	}
			},0);
		});
	}

	//Galerie d'images (Centre et Centre-produit) avec rollover et timer
	//--------------------------------------------------------------------
	if($(".dynamic_photogallery").length>0){
		$(".dynamic_photogallery").each(function(){
			var photo = $(this).children("tbody").children("tr").children(".dynamic_photogallery_photo");
			photo.children(".img").hide();
			photo.children(".img_0").show();
			var description_imggal = $(this).children("tbody").children("tr").children(".dynamic_photogallery_description").children(".dynamic_photogallery_imagesgallery");
			description_imggal.children(".thb").each(function(i){
				$(this).attr("style","cursor:pointer;");
				$(this).hover(
					function(){
						photo.children(".img").hide();
						photo.children(".img_"+i).show();},
					function(){}
				);
			});
			var timeIncr = 0;
			var nb = photo.children(".img").length;
			$(this).everyTime(3000, function(i) {
			  	//alert('timer ! ' + i);
			  	photo.children(".img").hide();
			  	//alert('i = ' + i + ' et timeIncr = ' + timeIncr);
			  	photo.children(".img_"+timeIncr).show();
			  	timeIncr = timeIncr + 1;
			  	if(timeIncr == nb){
			  		timeIncr = 0;
			  	}
			},0);
		});
	}

	//Diaporama avec rollover et timer
	//--------------------------------------------------------------------
	if($(".model_diaporama").length>0){
		$(".model_diaporama").each(function(){
			var photos = $(this).children("tbody").children("tr").children(".model_diaporama_photo");
			var thumbs = $(this).children("tbody").children("tr").children(".model_diaporama_thumbs");
			photos.children(".img").hide();
			photos.children(".img_0").show();
			thumbs.children(".thb").each(function(i){
				$(this).attr("style","cursor:pointer;");
				$(this).hover(
					function(){
						photos.children(".img").hide();
						photos.children(".img_"+i).show();},
					function(){}
				);
			});
			var timeIncr = 0;
			var nb = photos.children(".img").length;
			$(this).everyTime(3000, function(i) {
			  	//alert('timer ! ' + i);
			  	photos.children(".img").hide();
			  	//alert('i = ' + i + ' et timeIncr = ' + timeIncr);
			  	photos.children(".img_"+timeIncr).show();
			  	timeIncr = timeIncr + 1;
			  	if(timeIncr == nb){
			  		timeIncr = 0;
			  	}
			},0);
		});
	}

	//Onglets de Centre
	//----------------------------
	if($(".center_btntags").length>0){
		$(".center_btntags").each(function(){
			$(this).show();
			$(this).children("ul").children("li.first").addClass("selected");
			$(this).next(".center_tags_header").hide();
			$(this).next(".center_tags_header").next(".center_tags").children(".center_tag").hide();
			$(this).next(".center_tags_header").next(".center_tags").children(".center_tag_1").show();
			$(this).children("ul").children("li").children("a").each(function(i){
				$(this).hover(
					function(){	$(this).parent("li").addClass("hover");		},
					function(){	$(this).parent("li").removeClass("hover");	}
				);
				$(this).click(function(){
					$(this).parent("li").parent("ul").children("li").removeClass("selected");
					$(this).parent("li").addClass("selected");
					$(this).parent("li").parent("ul").parent(".center_btntags").next(".center_tags_header").next(".center_tags").children(".center_tag").hide();
					$(this).parent("li").parent("ul").parent(".center_btntags").next(".center_tags_header").next(".center_tags").children(".center_tag_"+(i+1)).show();
				});
			});
		});
	}




	//Recherche centres : champs dynamiques dependants
	//--------------------------------------------------------
	if($(".centers_search_form").length>0){
		$(".centers_search_form").each(function(){
			var form = $(this);
			$(this).children(".centers_search_field_loc").hide();
			$(this).children(".centers_search_field_countries").show();
			$(this).children(".centers_search_field_cities").show();
		});
	}
	//Recherche centres : disabled sur options
	//-----------------------------------------------
	if($(".centers_search_form").length>0){
		$(".centers_search_form").each(function(){
			var form = $(this);
			$(this).children().children(".citiespropvalue").attr("disabled","disabled");
			$(this).children().children(".countriespropvalue").each(function(){
				if($(this).val()!=null && $(this).val()!=''){
					form.children().children(".citiespropvalue").removeAttr("disabled");
				}else{
					form.children().children(".citiespropvalue").attr("disabled","disabled");
				}
				$(this).change(function(){
					if($(this).val()!=null && $(this).val()!=''){
						form.children().children(".citiespropvalue").removeAttr("disabled");
					}else{
						form.children().children(".citiespropvalue").attr("disabled","disabled");
					}
				});
			});
		});
	}



	//Recherche centre-produit : datepicker
	//----------------------------------------
	/*if($("#formfield_date").length>0){
		$("#formfield_date").each(function(){
			$(this).datepick({
				showOn: 'both',
				buttonImage: 'http://www.test4.spr:8080/opencms/opencms/system/modules/com.multiburo.opencms.commons/resources/images/default/picto_search_date.jpg',
				buttonImageOnly: true,
				gotoCurrent: true,
				closeAtTop: false,
				navigationAsDateFormat: true,
				prevText: '< M', currentText: 'M y', nextText: 'M >',
				changeMonth: false, changeYear: false
			});
		});
	}*/
	//Recherche centre-produit : disabled sur options
	//-----------------------------------------------
	if($(".center_products_search_form").length>0){
		$(".center_products_search_form").each(function(){
			var form = $(this);
			//$(this).children().children().children().children().children().children("#formfield_date").attr("disabled","disabled").datepick('disable');
			$(this).children().children().children().children().children().children(".formfield_type").attr("disabled","disabled");
			$(this).children().children().children().children().children(".centers_search_field_option2").show();
			$(this).children().children().children().children().children().children(".citiespropvalue").attr("disabled","disabled");
			$(this).children().children().children().children().children().children(".centerspropvalue").attr("disabled","disabled");
			$(this).children().children().children().children().children().children(".countriespropvalue").each(function(){
				if($(this).val()!=null && $(this).val()!=''){
					form.children().children().children().children().children().children(".citiespropvalue").removeAttr("disabled");
				}else{
					form.children().children().children().children().children().children(".citiespropvalue").attr("disabled","disabled");
					form.children().children().children().children().children().children(".centerspropvalue").attr("disabled","disabled");
				}
				$(this).change(function(){
					if($(this).val()!=null && $(this).val()!=''){
						form.children().children().children().children().children().children(".citiespropvalue").removeAttr("disabled");
					}else{
						form.children().children().children().children().children().children(".citiespropvalue").attr("disabled","disabled");
						form.children().children().children().children().children().children(".centerspropvalue").attr("disabled","disabled");
					}
				});
			});
			$(this).children().children().children().children().children().children(".citiespropvalue").each(function(){
				if($(this).val()!=null && $(this).val()!=''){
					form.children().children().children().children().children().children(".centerspropvalue").removeAttr("disabled");
				}else{
					form.children().children().children().children().children().children(".centerspropvalue").attr("disabled","disabled");
				}
				$(this).change(function(){
					if($(this).val()!=null && $(this).val()!=''){
						form.children().children().children().children().children().children(".centerspropvalue").removeAttr("disabled");
					}else{
						form.children().children().children().children().children().children(".centerspropvalue").attr("disabled","disabled");
					}
				});
			});
		});
	}
	//Recherche centre-produit : champs dynamiques dependants
	//--------------------------------------------------------
	if($(".center_products_search_form").length>0){
		$(".center_products_search_form").each(function(){
			var form = $(this);
			$(this).children().children().children().children().children(".centers_search_field_loc").hide();
			$(this).children().children().children().children().children(".centers_search_field_countries").show();
			$(this).children().children().children().children().children(".centers_search_field_cities").show();
			$(this).children().children().children().children().children(".centers_search_field_centers").show();
		});
	}


	//Recherche centre Locartis : disabled sur city
	//-----------------------------------------------
	if($(".locartis_references_search_form").length>0){
		$(".locartis_references_search_form").each(function(){
			var form = $(this);
			form.children().children().children().children().children(".centers_search_field_loc").hide();
			form.children().children().children().children().children(".locartis_references_search_form_js").show();
			/*var citiespropvalue = form.children().children().children().children().children().children().children(".citiespropvalue");
			var countriespropvalue = form.children().children().children().children().children().children().children(".countriespropvalue");
			citiespropvalue.attr("disabled","disabled");
			countriespropvalue.each(function(){
				if($(this).val()!=null && $(this).val()!=''){
					citiespropvalue.removeAttr("disabled");
				}else{
					citiespropvalue.attr("disabled","disabled");
				}
				$(this).change(function(){
					if($(this).val()!=null && $(this).val()!=''){
						citiespropvalue.removeAttr("disabled");
					}else{
						citiespropvalue.attr("disabled","disabled");
					}
				});
			});*/
		});
	}

	//Locales dropdown images
	//-----------------------------------------------
	if($("#headlocales_locale").length>0){
		$("#headlocales_locale").each(function(){
			$(this).msDropDown();
		});
	}

	//Locales : selectbox
	//----------------------------
	if($(".headlocales_form").length>0){
		$(".headlocales_form").each(function(){
			var form = $(this);
			if ($.browser.msie && $.browser.version.substr(0,1)<7){
				//alert('IE6');
				var largeur_select = document.getElementById('headlocales_locale_title').offsetWidth;
				$("#headlocales_locale_child").attr("style","margin-left:-"+largeur_select+"px;width:"+largeur_select+"px;");

			}else{
				//alert('pas IE6');
				$(this).children().children().children().children().children("#headlocales_locale").each(function(){
					$(this).change(function(){
						form.submit();
					});
				});
				$(this).children().children().children().children().children(".submitbutton").hide();
				$(this).children().children().children().children().children("#headlocales_locale_msdd").children("#headlocales_locale_child").children("a").each(function(){
					$(this).click(function(){
						form.submit();
					});
				});
			}

		});
	}

	//Liste de centres : selectbox
	//----------------------------
	/*if($(".centers_list_selectbox_form").length>0){
		$(".centers_list_selectbox_form").each(function(){
			var form = $(this);
			$(this).children().children().children().children(".right").hide();
			$(this).children().children().children().children().children().children(".formfield_center").each(function(){
				$(this).change(function(){
					form.submit();
				});
			});
		});
	}*/

	//Centers list selectbox
	//-----------------------------------------------
	if($("#centers_list_selectbox_formfield_center").length>0){
		$("#centers_list_selectbox_formfield_center").each(function(){
			$(this).msDropDown();
		});
	}
	if($(".centers_list_selectbox_form").length>0){
		$(".centers_list_selectbox_form").each(function(){
			var form = $(this);
			if ($.browser.msie && $.browser.version.substr(0,1)<7){
				//alert('IE6');
				//var largeur_select = document.getElementById('centers_list_selectbox_formfield_center_title').offsetWidth;
				//$("#centers_list_selectbox_formfield_center_child").attr("style","margin-left:-"+largeur_select+"px;width:"+largeur_select+"px;");

			}else{
				//alert('pas IE6');
				$(this).children().children().children().children().children().children(".formfield_center").each(function(){
					$(this).change(function(){
						form.submit();
					});
				});
				$(this).children().children().children().children(".right").hide();
				$(this).children().children().children().children().children().children("#centers_list_selectbox_formfield_center_msdd").children("#centers_list_selectbox_formfield_center_child").children("a").each(function(){
					$(this).click(function(){
						form.submit();
					});
				});
			}

		});
	}

	//Login footer : image
	//----------------------------
	if($(".foot_utils_login").length>0){
		$(".foot_utils_login").each(function(){
			var div = $(this);
			if(div.children(".footlogin_image").length>0){
				if(div.children(".error_message").length>0){
					div.children(".login_form").show();
					div.children(".footlogin_image").hide();
				}else{
					div.children(".login_form").hide();
					div.children(".footlogin_image").show();
				}
				$(div.children(".footlogin_image")).click(function(){
					div.children(".login_form").show();
					div.children(".footlogin_image").hide();
				});
			}
		});
	}
	//Login footer : Vider les champs sur un click/focus
	//---------------------------------------------
	if($("#footlogin_username").length>0){
		var already_erase = false;
		$("#footlogin_username").click(function(){
			if(!already_erase){
				$(this).val("");
				already_erase = true;
			}
		});
		$("#footlogin_username").focus(function(){
			if(!already_erase){
				$(this).val("");
				already_erase = true;
			}
		});
	}
	if($("#footlogin_password").length>0){
		var already_erase2 = false;
		$("#footlogin_password").click(function(){
			if(!already_erase2){
				$(this).val("");
				already_erase2 = true;
			}
		});
		$("#footlogin_password").focus(function(){
			if(!already_erase2){
				$(this).val("");
				already_erase2 = true;
			}
		});
	}

	//Teasers image : rollover
	//----------------------------
	if($(".imageover").length>0){
		$(".imageover").each(function(){
			var over = $(this);
			over.prev(".imageon").hover(
				function(){
					over.show();
					over.prev(".imageon").hide();
				},
				function(){ }
			);
			over.hover(
				function(){ },
				function(){
					over.hide();
					over.prev(".imageon").show();
				}
			);
		});
	}

	//Valeurs locatives
	//----------------------


	//Pays : liste de centres : selectbox sans bouton
	//-------------------------------------------------
	if($(".city_selection_form").length>0){
		$(".city_selection_form").each(function(){
			var form = $(this);
			$(this).children().children().children().children(".right").hide();
			$(this).children().children().children().children().children(".formfield").each(function(){
				$(this).change(function(){
					form.submit();
				});
			});
		});
	}


	$('.hiddenDiv').css('display', 'block');
	$('.hiddenSpan').css('display', 'inline');

});

function getInfoBulle(v_name,v_adress,v_code,v_city,v_country,v_email,v_phone,v_data,v_fax,v_url,imgPath){

	var myHtml = '';
	myHtml = '<div class="info_bulle" style="width:100px">';
	myHtml += '<p class="name">' + v_name + '</p>';

	myHtml += '<div class="coord">';
	if ((v_adress != undefined && v_adress != '' && v_adress != ' ')
			|| (v_code != undefined && v_code != '' && v_code != ' ')
			|| (v_city != undefined && v_city != '' && v_city != ' ')
			|| (v_country != undefined && v_country != '' && v_country != ' ')) {
		myHtml += '<table><tr class="adress"><td class="picto">';
		myHtml += '<img src="' + imgPath + 'book_open.gif" alt="address"/>';
		myHtml += '</td><td class="value">';
		myHtml += v_adress + '<br/>' + v_code + '&nbsp;' + v_city + '<br/>'
				+ v_country;
		myHtml += '</td></tr></table>';
	}
	if (v_email != undefined && v_email != '' && v_email != ' ') {
		myHtml += '<table><tr class="email"><td class="picto">';
		myHtml += '<img src="' + imgPath + 'email_edit.gif" alt="email"/>';
		myHtml += '</td><td class="value">';
		myHtml += v_email;
		myHtml += '</td></tr></table>';
	}
	if (v_phone != undefined && v_phone != '' && v_phone != ' ') {
		myHtml += '<table><tr class="phone"><td class="picto">';
		myHtml += '<img src="' + imgPath + 'phone.gif" alt="phone"/>';
		myHtml += '</td><td class="value">';
		myHtml += v_phone;
		myHtml += '</td></tr></table>';
	}
	if (v_fax != undefined && v_fax != '' && v_fax != ' ') {
		myHtml += '<table><tr class="phone"><td class="picto">';
		myHtml += '<img src="' + imgPath + 'fax.gif" alt="phone"/>';
		myHtml += '</td><td class="value">';
		myHtml += v_fax;
		myHtml += '</td></tr></table>';
	}
	if (v_url != undefined && v_url != '' && v_url != ' ') {
		var urlToDisplay = getURLToDiplay(v_url);
		myHtml += '<table><tr class="url"><td class="picto">';
		myHtml += '<img src="' + imgPath + 'page_world.gif" alt="Url"/>';
		myHtml += '</td><td class="value">';
		myHtml += '<a target="_blank" href="' + v_url + '">' + urlToDisplay
				+ '</a>';
		myHtml += '</td></tr></table>';
	}
	myHtml += '</div>';
	if ((v_data != undefined && v_data != '' && v_data != ' ')) {
		myHtml += '<div class="data">' + v_data + '</div>';
	}
	myHtml += '</div>';
	return myHtml;
}
function getMarkerOptions(imagePath,shadowImagePath,shadowIsDisabled,imageSize,shadowImageSize,offsetSize){
	var options = null;
	//alert('imagePath '+imagePath+' \n imageSize '+ imageSize+' \n'+shadowIsDisabled+' '+shadowImagePath+' '+shadowImageSize+' '+offsetSize);
	if(	(imagePath!=null && imagePath!='' && imagePath!=' ') ||
		(shadowImagePath!=null && shadowImagePath!='' && shadowImagePath!=' ') ||
		(shadowIsDisabled!=null && shadowIsDisabled!='' && shadowIsDisabled!=' ') ||
		(imageSize!=null && imageSize!='' && imageSize!=' ') ||
		(shadowImageSize!=null && shadowImageSize!='' && shadowImageSize!=' ') ||
		(offsetSize!=null && offsetSize!='' && offsetSize!=' ') 						){

		var imgW = null;
		var imgH = null;
		if(imageSize!=null && imageSize!='' && imageSize!=' '){
  			if(imageSize.indexOf(",")!=-1){
  				imgW = imageSize.substring(0,imageSize.indexOf(","));
  				if(imgW.indexOf(":")!=-1){
  					imgW.substring(imgW.indexOf(","),imgW.length);
   				}
  				imgH = imageSize.substring(imageSize.indexOf(","),imageSize.length);
  				if(imgH.indexOf(":")!=-1){
  					imgH.substring(imgH.indexOf(","),imgH.length);
   				}
   			}
		}

		var simgW = null;
		var simgH = null;
		if(shadowImageSize!=null && shadowImageSize!='' && shadowImageSize!=' '){
  			if(shadowImageSize.indexOf(",")!=-1){
  				simgW = shadowImageSize.substring(0,shadowImageSize.indexOf(","));
  				if(simgW.indexOf(":")!=-1){
  					simgW.substring(simgW.indexOf(","),simgW.length);
   				}
  				simgH = shadowImageSize.substring(shadowImageSize.indexOf(","),shadowImageSize.length);
  				if(simgH.indexOf(":")!=-1){
  					simgH.substring(simgH.indexOf(","),simgH.length);
   				}
   			}
		}

		var oW = null;
		var oH = null;
		if(offsetSize!=null && offsetSize!='' && offsetSize!=' '){
  			if(offsetSize.indexOf(",")!=-1){
  				oW = offsetSize.substring(0,offsetSize.indexOf(","));
  				if(oW.indexOf(":")!=-1){
  					oW.substring(oW.indexOf(","),oW.length);
   				}
  				oH = offsetSize.substring(offsetSize.indexOf(","),offsetSize.length);
  				if(oH.indexOf(":")!=-1){
  					oH.substring(oH.indexOf(","),oH.length);
   				}
   			}
		}

		options = [imagePath,shadowImagePath,shadowIsDisabled,imgW,imgH,simgW,simgH,oW,oH];
		//alert(options);
	}
	return options;
}
// cree un pack d'options marqueur personnalise selon les proprietes du centre.
// imagepath : image de la bulle, a definir dans la prop... des centres
// shadowpath : meme principe
// shadowIsDisabled : meme principe
// imageWidth imageHeight shadowWidth shadowHeight offsetWidth offsetHeight
function createMarkerOptions(markerOptions) {
	var imagepath = markerOptions[0];
	var shadowpath = markerOptions[1];
	var shadowIsDisabled = markerOptions[2];
	var imageWidth = markerOptions[3];
	var imageHeight = markerOptions[4];
	var shadowWidth = markerOptions[5];
	var shadowHeight = markerOptions[6];
	var offsetWidth = markerOptions[7];
	var offsetHeight = markerOptions[8];

	var customImagePath = 'http://'+location.host+imagepath;
	var customShadowPath = 'http://'+location.host+shadowpath;
	var customIcon = new GIcon(G_DEFAULT_ICON);
	alert(customImagePath);

	if(customImagePath!=null && customImagePath!=''){
		customIcon.image = customImagePath;
	}
	if(customShadowPath!=null && customShadowPath!=''){
		customIcon.shadow = customShadowPath;
	}
	if(imageWidth!=null && imageWidth!='' && imageHeight!=null && imageHeight!=''){
		customIcon.iconSize = new GSize(parseFloat(imageWidth),parseFloat(imageHeight));
	}
	if(shadowWidth!=null && shadowWidth!='' && shadowHeight!=null && shadowHeight!=''){
		customIcon.shadowSize = new GSize(parseFloat(shadowWidth),parseFloat(shadowHeight));
	}
	if(shadowIsDisabled!=null && shadowIsDisabled!=''){
		if(String(shadowIsDisabled) == 'true'){
			customIcon.shadow = '';
			if(imageWidth!=null && imageWidth!='' && imageHeight!=null && imageHeight!=''){
				customIcon.shadowSize = new GSize(parseFloat(imageWidth),parseFloat(imageHeight));
			}
		}
	}
	if(imageWidth!=null && imageWidth!='' && offsetWidth!=null && offsetWidth!='' &&
		imageHeight!=null && imageHeight!='' && offsetHeight!=null && offsetHeight!=''){
		var anchorWidth = parseInt(imageWidth)/2+parseInt(offsetWidth);
		var anchorHeight = parseInt(imageHeight)+parseInt(offsetHeight);
		customIcon.iconAnchor  = new  GPoint(anchorWidth,anchorHeight);
	}
	markerOptions = { icon:customIcon };
	return markerOptions;
}
// charge et initialise la map.
function loadCountry(map,geocoder,address,zoom,label) {
	if (GBrowserIsCompatible()) {
		map.setCenter(new GLatLng(48.8948986, 2.2006881), 10);
		map.setUIToDefault();
		if (geocoder) {
			geocoder.getLatLng(address, function(point) {
				if (!point) {
					if (label && label != '') {
				    alert(label);
					}
					map.setCenter(new GLatLng(48.8948986, 2.2006881), zoom);
				} else {
					map.setCenter(point, zoom);
				}
			});
		}
	}
}
// place le marqueur sur la map.
// point : x y du point
// label : contenu de l'info bulle
// options : options marqueur
function addMultiburoMarker(map,point,label,options){
	if(map!=null){
		if(point!=null){
			var overlay = null;
			if(options!=null){
				var marker = new GMarker(point, createMarkerOptions(options));
				marker.value = label;
				GEvent.addListener(marker, "click", function() {map.openInfoWindowHtml(point, label);});
				map.addOverlay(marker);
			}else{
				var marker = new GMarker(point);
			  	marker.value = label;
			  	GEvent.addListener(marker, "click", function() {map.openInfoWindowHtml(point, label);});
				map.addOverlay(marker);
			}
		}
	}
}

function popin_basket(id, title, url_redirect) {
	$('#'+id).dialog({bgiframe: true, title: title, modal: true, closeOnEscape: false});
	$('#'+id).bind('dialogbeforeclose', function(event, ui) {
		window.location.replace(url_redirect);
	});
	return false;
}

function check_email(email, divAlert, divSubmit) {
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		$(divAlert).css('display', 'block');
		return false;
	} else {
		$(divSubmit).submit();
		return true;
	}
}

function emptyField(defaultText, input) {
  if(input.val() == defaultText)
    input.val('');
}


