///////////////////////////////////////////////////////////////////////////////////////
function format(the_string){
	/*return a well formated string 3000 => 3 000*/
	var str = ''+the_string;
	var step = 3;
	var tmp = '';
	var i;
	var nbspace=0;
	for(i=str.length-1;i>=0;i--){
		tmp=str.charAt(i)+tmp;
		if(((tmp.length-nbspace)%step==0)&&(i>0)){tmp=' '+tmp;nbspace++;}
	}	
	return tmp;
}
///////////////////////////////////////////////////////////////////////////////////////
function min_price(the_price_min){
	/*fill min price combo*/
	var combo = document.formulaire.prix_mini;
	var min = 3000;
	var max = 100500;
	var step = 1500;	
	combo.options[combo.options.length] = new Option ( 'Prix min' , '-1');
	if(the_price_min=='0')combo.options[combo.options.length-1].selected=true;
	for(i=min;i<=max;i+=step)
	{
		combo.options[combo.options.length] = new Option ( format(i) + ' €' , i );
		if((the_price_min!='')&&(i==the_price_min))combo.options[combo.options.length-1].selected=true;
	}
}
///////////////////////////////////////////////////////////////////////////////////////
function max_price(){
	/*fill max price combo*/
	var combo = document.formulaire.prix_maxi;
	var min_price = document.formulaire.prix_mini[document.formulaire.prix_mini.selectedIndex].value;
	var step = 1500;
	var min = (min_price>0)?parseInt(min_price,10) + step:3000;
	
	var max = 100500;
	if(parseInt(min_price,10)==0)
		{
			combo.selectedIndex=0;
			combo.disabled=true;
		}else combo.disabled=false;
	
	if( (combo.selectedIndex>-1)&&(combo[combo.selectedIndex].value>parseInt(min_price,10)) )
		 prefered_max_price = combo[combo.selectedIndex].value;
	
	while((i = combo.options.length)>0)
			combo.options[i-1]=null;
			
	combo.options[combo.options.length] = new Option ( 'Prix maxi' , '-1');
	/*build list starting from price min + step and trying to restore old value*/
	for(i=min;i<=max;i+=step)
	{
		combo.options[combo.options.length] = new Option ( format(i) + ' €' , i );
		if(i == prefered_max_price)combo.options[combo.options.length-1].selected=true;
	}
}
///////////////////////////////////////////////////////////////////////////////////////
function max_year(){
	var combo = document.formulaire.Year_to;
	var min_price = document.formulaire.qq[document.formulaire.qq.selectedIndex].value;
	var step = 1;
	var min = (min_price>0)?parseInt(min_price,10) + step:1980;
	var max = 2007;
	if(parseInt(min_price,10)==0)
		{
			combo.selectedIndex=0;
			combo.disabled=true;
		}else combo.disabled=false;
	
	if( (combo.selectedIndex>-1)&&(combo[combo.selectedIndex].value>parseInt(min_price,10)) )
		 prefered_max_year = combo[combo.selectedIndex].value;
	
	while((i = combo.options.length)>0)
			combo.options[i-1]=null;
			
	combo.options[combo.options.length] = new Option ( 'et' , '-1');
	/*build list starting from price min + step and trying to restore old value*/
	for(i=min;i<=max;i+=step)
	{
		combo.options[combo.options.length] = new Option ( i, i );
		if(i == prefered_max_year)combo.options[combo.options.length-1].selected=true;
	}
}
///////////////////////////////////////////////////////////////////////////////////////
function min_year(the_year_min){
	/*fill min price combo*/
	var combo = document.formulaire.qq;
	var min = 1980;
	var max = 2007;
	var step = 1;	
	combo.options[combo.options.length] = new Option ( 'Année entre' , '-1');
	if(the_year_min=='0')combo.options[combo.options.length-1].selected=true;
	for(i=min;i<=max;i+=step)
	{
		combo.options[combo.options.length] = new Option ( i , i );
		if((the_year_min!='')&&(i==the_year_min))combo.options[combo.options.length-1].selected=true;
	}
}
///////////////////////////////////////////////////////////////////////////////////////
function openPopup(url, width, height, scrollbars, resizeable){
    window.open(url,'popup','width='+width+', height='+height+', scrollbars='+scrollbars+', resizeable='+resizeable+'')
}
function isCP(obj) {
	if (isNaN(obj.value)==false && obj.value.length==5)  return true;
	else return false;
}
function isEmail(obj) 
{
       if (obj.value.indexOf(" ") + "" == "-1"
       && obj.value.indexOf("@") + "" != "-1"
       && (obj.value.lastIndexOf(".") > obj.value.indexOf("@"))
       && obj.value != "") return true;
       else return false;
}
function TestParam()
{
	var Form = document.forms["FormContact"]; //forms = tous les formulaires du document
	if (Form.eNom.value == "")
		{ alert("Attention, le champ 'Nom' doit être renseigné"); Form.eNom.focus(); return false; }
	if (Form.ePrenom.value == "")
		{ alert("Attention, le champ 'Prénom' doit être renseigné"); Form.ePrenom.focus(); return false; }
	if (Form.eCodePostal.value != "" && !isCP(Form.eCodePostal))
		{ alert("Merci de renseigner le champ 'Code postal' correctement"); Form.eCodePostal.focus(); return false; }
	if (Form.eEmail.value == "" || !isEmail(Form.eEmail))
		{ alert("Merci de renseigner le champ 'Email' correctement"); Form.eEmail.focus(); return false; }
	if (Form.eMessage.value == "")
		{ alert("Attention, le champ 'Message' doit être renseigné"); Form.eMessage.focus(); return false; }
	if (Form.eCaptcha.value == "")
		{ alert("Merci de saisir les caractères indiqués par l'image"); Form.eCaptcha.focus(); return false; }
	return true;
}
function checkForInt(evt) {
	var charCode = ( evt.which ) ? evt.which : event.keyCode;
	return (charCode < 32 || (charCode >= 48 && charCode <= 57));
}
//------------------------------------------------------------------------------------
// Script Notice légale
//------------------------------------------------------------------------------------
function showCPR(s) {
       var y = new Date().getYear();
       if (y<1900) y+=1900;
       if (s!=y)
          document.write(s + " - " + y);
	       else
          document.write(y);
}
//------------------------------------------------------------------------------------
// Fonction CacheMail
//------------------------------------------------------------------------------------

function CacheMail(mail,domain) {
	this.location = 'mailto:' + mail + '@'+ domain;
	}
	
//-------------------------------------------------------------------------------
// Fonction Captcha()
//-------------------------------------------------------------------------------
function RefreshCaptcha() {
	var i = new Image();
	var d = new Date();
	i.src = 'Includes/modCaptcha.asp?Type=4&Dt=' + d.getHours().toString() + d.getMinutes().toString() + d.getSeconds().toString() ;
	$("Captcha").src =  i.src;
}

function openPopup(url, width, height, scrollbars, resizeable){
    window.open(url,'popup','width='+width+', height='+height+', scrollbars='+scrollbars+', resizeable='+resizeable+'')
}