var nb_piece = new Array();	
var nb_ch = new Array();	
var nb_dep = new Array();	
var nb_sec = new Array();
var nb_zip = new Array();

function validation() 
{
	surf_min = document.getElementById('surf_min').value;
	if (surf_min == '') surf_min ='0';
	document.getElementById('surface').value = surf_min+'-999999';
	
	var sNombre = document.getElementById('prix').value;
	 
	 while(sNombre.indexOf(" ") > 0){
		sNombre = sNombre.replace(" ", "");
	 };
	 	if (document.getElementById('bedrooms').value)  document.getElementById('bedrooms').value = document.getElementById('bedrooms').value + '+';

	document.getElementById('prix').value = sNombre;
	document.formulaire_rapide.submit();
}

function check_form(lang,liste_input,goto)
{
var a_liste = new Array();
a_liste = liste_input.split(',');

        for (input_a in a_liste)
        {
                in_val = document.getElementById(a_liste[input_a]);
                if (in_val.value == '') {in_val.style.backgroundColor='#B71814';var alerte_modal = true;}
                else in_val.style.backgroundColor='green'
        }
        if (alerte_modal) 
		{
			if (lang == 'fr')	alert ('Remplir tout les champs obligatoire');
			else 	alert ('Fill all the mandatory fields');
		}
        else 
		{
		if (goto == 'alert') validation_alerte();
		else if (goto == 'modal') validation_modal();
		else if (goto == 'contact') validation_contact();
		else  validation();
		}
}

function unset(array, valueOrIndex){
        var output=[];
        for(var i in array){
                if (array[i]!=valueOrIndex)
                {
                        output[i]=array[i];
                }
        }
        return output;
}
function array_dep(combien_dep)
{
        if (nb_dep.join().indexOf(combien_dep)>=0) nb_dep = unset(nb_dep, combien_dep);
        else
        {
        nb_dep.push(combien_dep);
        nb_dep.sort();
        }
        document.getElementById('departement').value = nb_dep.join(',');
		document.getElementById('choix_secteur').value = nb_dep.join(',');
}
function array_secteur(checked, combien_sec)
{
        if (checked == 'true') checked = true;
        if (checked == 'false') checked = false;

        if (checked)
                {
                        nb_sec_o = document.getElementById('sector').value;
                       
                        if (nb_sec_o != '')  nb_sec = nb_sec_o.split(',');
                        nb_sec.push(combien_sec);
                        nb_sec.sort();
                        document.getElementById('sector').value = nb_sec.join(',');
                        document.getElementById('choix_secteur').value = nb_sec.join(' ');
                }
        else
        {
                        list_ss_cb = unset(nb_sec, combien_sec);
                        document.getElementById('sector').value =  list_ss_cb.join(',');
                        document.getElementById('choix_secteur').value = list_ss_cb.join(' ') ;
        }

}

function array_zip(checked, combien_zip)
{
		if (checked == 'true') checked = true;
	if (checked == 'false') checked = false;
	
        if (checked) 
		{
			nb_zip_o = document.getElementById('postcode').value;
			nb_zip = nb_zip_o.split(',');
			nb_zip.push(combien_zip);
			nb_zip.sort();
			document.getElementById('postcode').value = nb_zip.join(',');
		}
        else
        {
			document.getElementById('sector').value =  document.getElementById('postcode').value.replace(combien_zip, "");
			nb_zip_before = document.getElementById('postcode').value;
        }
}
function array_piece(combien)
{
        if (nb_piece.join().indexOf(combien)>=0) nb_piece.splice(nb_piece.indexOf(combien),1);
        else
        {
        nb_piece.push(combien);
        nb_piece.sort();
        }
        document.getElementById('rooms').value = nb_piece.join(',');
}
function array_ch(combien_ch)
{
        if (nb_ch.join().indexOf(combien_ch)>=0) nb_ch.splice(nb_ch.indexOf(combien_ch),1);
        else
        {
        nb_ch.push(combien_ch);
        nb_ch.sort();
        }
        document.getElementById('bedrooms').value = nb_ch.join(',');
}
function display(faux_menu)
{
	document.getElementById(faux_menu).style.visibility='visible';
}
function hide(faux_menu)
{
	document.getElementById(faux_menu).style.visibility='hidden';
}

function change_langue(lang)
{
	url_z = document.URL;
	tab_url = url_z.split('?');
	if (tab_url[1])	window.location.href = window.location + '&lang=' + lang; 
		else window.location.href = window.location + '?lang=' + lang; 
}
