//------------------------------------------------------------------------------------
// Script Anti-flash
//------------------------------------------------------------------------------------
function fixFlash(s) { document.write(s); }

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 verifCode(obj) {
       return (obj.value == "") || (obj.value.length == 5 && !isNaN(obj.value));
	   //si le champ est vide, je retourne vrai (parce que ca n est pas un champ obligatoire)
	   // ou si le champ a une longueur de 5 caractères et que c'est un nombre, je returne vrai
}

function toFieldLen(val, fld, len) {
  if (val.length==len) {
	eval("document." + fld + ".focus();");
  }
}

function checkKeyFull(field, evt, fld, len) {
	if (checkKey(field, evt)) {
		if ((field.value).length==len) {
			eval("document." + fld + ".focus();");
		}
		return true;
	} else return false;
}

function checkKey(field, evt) {
  var keyCode = 
    document.layers ? evt.which :
    document.all ? event.keyCode :
    document.getElementById ? evt.keyCode : 0;
  //alert(keyCode);
  if ((document.all || document.getElementById) && evt.shiftKey) {
    if (keyCode == 9) return true;
	return false;
  }
  if (document.layers && evt.modifiers & event.SHIFT_MASK) {
    if (keyCode == 9) return true;
	return false;
  }
  // 0 .. 9, 0 .. 9 on right keyboard, Backspace, Tab, End, Home, Left Arrow, Right Arrow, Del button
  if ((keyCode > 47 && keyCode < 58) || (keyCode > 95 && keyCode < 106) || keyCode == 8 || keyCode == 9 || keyCode == 35 || keyCode == 36 || keyCode == 37 || keyCode == 39  || keyCode == 46) return true;
  return false;
}

function setChkBtn(fldName,setIndex,maxIndex) {
 var i, t;
 t = eval("document." + fldName + setIndex + ".checked");
 if (t) {
  for (i=1; i<=maxIndex; i++) 
   if (i!=setIndex) eval("document." + fldName + i + ".checked = false;");
 }
}

function TestParam(Form) 
{
	if (Form.eNom.value == "") 
		{ alert("Attention, le nom est nécessaire"); Form.eNom.focus(); return }
	if (Form.ePrenom.value == "") 
		{ alert("Attention, le prénom est nécessaire"); Form.ePrenom.focus(); return }
	if (!isEmail(Form.eEmail))
		{ alert("Merci d'indiquer un email correct"); Form.eEmail.focus(); return }
	//if (Form.eSociate.value=="")
	//	{ alert("Attention, le profession est nécessaire"); Form.eEmail.focus(); return }	
	if (Form.eTel.value != "" && (Form.eTel.value).length!=10)
		{ alert("Attention, le téléphone est nécessaire"); Form.eTel.focus(); return }	
	if (!verifCode(Form.eCodePostal))
		{ alert("Merci d'indiquer un code postal correct"); Form.eCodePostal.focus(); return }
	if (Form.eMessage.value == "")
		{ alert("Attention, le champ 'Message' doit être renseigné."); Form.eMessage.focus();
			return }

	Form.submit();															
}

function openPopup(url, width, height, scrollbars, resizeable){
    window.open(url,'popup','width='+width+', height='+height+', scrollbars='+scrollbars+', resizeable='+resizeable+'')
}

	function OpenClose(id)
	{
		f = 0;
		if (document.getElementById(id).style.display == "none") 
		{
			f=1;
			document.getElementById(id).style.display='block';
		}
		if ((document.getElementById(id).style.display == "block")&&(f==0)) document.getElementById(id).style.display='none';
	}
	
	function showCPR(s) {
       var y = new Date().getYear();
       if (y<1900) y+=1900;
       if (s!=y)
          document.write(s + " - " + y);
	       else
          document.write(y);
}
function CacheMail(mail,domain) {
 this.location = 'mailto:' + mail + '@'+ domain;
}

//YEARS
var d = new Date();
function max_year(){
	var combo = document.formulaire.Year_to;
	var min_price = document.formulaire.min_year[document.formulaire.min_year.selectedIndex].value;
	min_price = min_price - 1;
	var step = 1;
	var min = (min_price>0)?parseInt(min_price,10) + step:1980;
	var max = d.getFullYear();
	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 ( 'Année' , '-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.min_year;
	var min = 1980;
	var max = d.getFullYear();
	var step = 1;	
	combo.options[combo.options.length] = new Option ( 'Année' , '-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;
	}
}

//KILOMETRAGE

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_km(the_km_min){
	/*fill min price combo*/
	var combo = document.formulaire.km_min;
	var min = 0;
	var max = 500000;
	var step = 10000;	
	combo.options[combo.options.length] = new Option ( 'Kilométrage' , '-1');
	if(the_km_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) + ' km' , i );
		if((the_km_min!='')&&(i==the_km_min))combo.options[combo.options.length-1].selected=true;
	}
}
///////////////////////////////////////////////////////////////////////////////////////
function max_km(){
	/*fill max price combo*/
	var combo = document.formulaire.km_max;
	var min_km = document.formulaire.km_min[document.formulaire.km_min.selectedIndex].value;
	var step = 10000;
	var min = (min_km>0)?parseInt(min_km,10) + step:10000;
	
	var max = 500000;
	if(parseInt(min_km,10)==0)
		{
			combo.selectedIndex=0;
			combo.disabled=false;
		}else combo.disabled=false;
	
	if( (combo.selectedIndex>-1)&&(combo[combo.selectedIndex].value>parseInt(min_km,10)) )
		 prefered_max_km = combo[combo.selectedIndex].value;
	
	while((i = combo.options.length)>0)
			combo.options[i-1]=null;
			
	combo.options[combo.options.length] = new Option ( 'Kilométrage' , '-1');
	/*build list starting from price min + step and trying to restore old value*/
	i1 = 0;
	for(i=min;i<=max;i+=step)
	{	i1 = i;
		combo.options[combo.options.length] = new Option ( format(i) + ' km' , i );
		if(i == prefered_max_km)combo.options[combo.options.length-1].selected=true;
	}
	combo.options[combo.options.length] = new Option ( 'pas de max.' , '-2');
	if(-2 == prefered_max_km)combo.options[combo.options.length-1].selected=true;
}
//PRICE

///////////////////////////////////////////////////////////////////////////////////////
function min_price(the_price_min){
	/*fill min price combo*/
	var combo = document.formulaire.prix_mini;
	var min = 0;
	var max = 100000;
	var step = 1500;	
	combo.options[combo.options.length] = new Option ( 'Prix' , '-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 = 100000;
	if(parseInt(min_price,10)==0)
		{
			combo.selectedIndex=0;
			combo.disabled=false;
		}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' , '-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;
	}
	combo.options[combo.options.length] = new Option ( 'pas de max.' , '-2');
	if(prefered_max_price == -2)combo.options[combo.options.length-1].selected=true;
}
///////////////////////////////////////////////////////////////////////////////////////
//SCROLLING TEXT

i = 0
var speed = 1
function scroll() {
i = i + speed
var div = document.getElementById("news")
div.scrollTop = i
if (i > div.scrollHeight - 80) {i = 0}
t1=setTimeout("scroll()",50)
}